Loading ...
Sorry, an error occurred while loading the content.
 

Could I use Apache Batik in Servlets?

Expand Messages
  • alex_philippi
    Hi, one question: I want to use a servlet to show SVG-Data via IE 5.5. Could I use the batik lib for this or is batik applications or applets -only and I have
    Message 1 of 7 , Jan 28, 2005
      Hi,
      one question:
      I want to use a servlet to show SVG-Data via IE 5.5. Could I use the
      batik lib for this or is batik "applications or applets"-only and I
      have to write all this svg code manually.
      THnx
    • Thomas DeWeese
      ... Most of the pieces of Batik will work just fine in a servlet. So you can use the SVG Generator to turn Graphics2D calls into SVG content, use the font
      Message 2 of 7 , Jan 30, 2005
        alex_philippi wrote:

        > I want to use a servlet to show SVG-Data via IE 5.5. Could I use the
        > batik lib for this or is batik "applications or applets"-only and I
        > have to write all this svg code manually.

        Most of the pieces of Batik will work just fine in a servlet.
        So you can use the SVG Generator to turn Graphics2D calls into
        SVG content, use the font converter, the rasterizer etc.
        You can even use Batik to provide a 'live' SVG DOM on the
        server so you can ask about BBox, intersection etc.
      • alex_philippi
        ... the ... I ... Do u have any links to simple (to get into it) Batik examples (e.g. how I could draw a rectangle with Batik (App. or Servlet)).
        Message 3 of 7 , Feb 1, 2005
          --- In svg-developers@yahoogroups.com, Thomas DeWeese <thomas.
          deweese@k...> wrote:
          > alex_philippi wrote:
          >
          > > I want to use a servlet to show SVG-Data via IE 5.5. Could I use
          the
          > > batik lib for this or is batik "applications or applets"-only and
          I
          > > have to write all this svg code manually.
          >
          > Most of the pieces of Batik will work just fine in a servlet.
          > So you can use the SVG Generator to turn Graphics2D calls into
          > SVG content, use the font converter, the rasterizer etc.
          > You can even use Batik to provide a 'live' SVG DOM on the
          > server so you can ask about BBox, intersection etc.

          Do u have any links to simple (to get into it) Batik examples (e.g.
          how I could draw a rectangle with Batik (App. or Servlet)).
        • Thomas DeWeese
          Hi Alex, Sure check out: http://xml.apache.org/batik/svggen.html It gives an overview of the SVGGraphics2D with sample code.
          Message 4 of 7 , Feb 1, 2005
            Hi Alex,

            Sure check out: http://xml.apache.org/batik/svggen.html

            It gives an overview of the SVGGraphics2D with sample code.


            alex_philippi wrote:

            >
            > --- In svg-developers@yahoogroups.com, Thomas DeWeese <thomas.
            > deweese@k...> wrote:
            >
            >>alex_philippi wrote:
            >>
            >>
            >>>I want to use a servlet to show SVG-Data via IE 5.5. Could I use
            >
            > the
            >
            >>>batik lib for this or is batik "applications or applets"-only and
            >
            > I
            >
            >>>have to write all this svg code manually.
            >>
            >> Most of the pieces of Batik will work just fine in a servlet.
            >>So you can use the SVG Generator to turn Graphics2D calls into
            >>SVG content, use the font converter, the rasterizer etc.
            >>You can even use Batik to provide a 'live' SVG DOM on the
            >>server so you can ask about BBox, intersection etc.
            >
            >
            > Do u have any links to simple (to get into it) Batik examples (e.g.
            > how I could draw a rectangle with Batik (App. or Servlet)).
            >
            >
            >
            >
            >
            > -----
            > To unsubscribe send a message to: svg-developers-unsubscribe@yahoogroups.com
            > -or-
            > visit http://groups.yahoo.com/group/svg-developers and click "edit my membership"
            > ----
            > Yahoo! Groups Links
            >
            >
            >
            >
            >
            >
            >
          • alex_philippi
            ... Thnx a lot. Now I know that i will use batik only for create pdf or image files and code the rest manually because I dont use in a servlet the graphic
            Message 5 of 7 , Feb 1, 2005
              --- In svg-developers@yahoogroups.com, Thomas DeWeese <thomas.
              deweese@k...> wrote:
              > Hi Alex,
              >
              > Sure check out: http://xml.apache.org/batik/svggen.html
              >
              > It gives an overview of the SVGGraphics2D with sample code.

              Thnx a lot. Now I know that i will use batik only for create pdf or
              image files and code the rest manually because I dont use in a
              servlet
              the graphic classes (e.g. drawrect). Perhaps I could use the DOM
              Model
              for my Project but the output stream of a servlet seems to be the
              better solution(e.g. below).

              <DOM BATIK example>
              // set the width and height attribute on the root svg element
              svgRoot.setAttributeNS(null, "width", "400");
              svgRoot.setAttributeNS(null, "height", "450");

              // create the rectangle
              Element rectangle = doc.createElementNS(svgNS, "rect");
              rectangle.setAttributeNS(null, "x", "10");
              rectangle.setAttributeNS(null, "y", "20");
              rectangle.setAttributeNS(null, "width", "100");
              rectangle.setAttributeNS(null, "height", "50");
              rectangle.setAttributeNS(null, "style", "fill:red");

              // attach the rectangle to the svg root element
              svgRoot.appendChild(rectangle);
              </DOM BATIK example>

              <OUTPUT STREAM SERVLET>
              PrintWriter out = response.getWriter();
              out.println("<svg width=\"400\" height=\"450\">
              <rect x=\"10\" y=\"20\" width=\"100\" height=\"50\" style=\"fill:
              red\"/>
              </svg>");
              </OUTPUT STREAM SERVLET>
            • Thomas DeWeese
              ... For simple projects println is a fine solution, the learning curve is tiny, but the drawback is that there is nothing checking what you are doing. By
              Message 6 of 7 , Feb 2, 2005
                alex_philippi wrote:
                >
                > --- In svg-developers@yahoogroups.com, Thomas DeWeese wrote:

                >> Sure check out: http://xml.apache.org/batik/svggen.html
                >>
                >> It gives an overview of the SVGGraphics2D with sample code.
                >
                > Thnx a lot. Now I know that i will use batik only for create pdf or
                > image files and code the rest manually because I dont use in a
                > servlet the graphic classes (e.g. drawrect). Perhaps I could use
                > the DOM Model for my Project but the output stream of a servlet
                > seems to be the better solution(e.g. below).

                For simple projects println is a fine solution, the learning
                curve is tiny, but the drawback is that there is nothing checking
                what you are doing. By using the SVGGraphics2D when you draw a rect
                it makes sure you provide the proper parameters, in other words
                it gives you a strongly typed interface (DOM BTW is little better
                than println, because everything is still strings, except that
                the final XML is machine generated so silly things like missing
                quotes, or not using XML entities won't happen).

                The only other advantage of using DOM (or potentially graphics2D)
                is that with Batik you can have access to the SVG DOM so you can get
                things like the bounding box of elements. This isn't a big deal
                for simple things like lines & boxes, but is _really_ nice for
                things like text.

                Also you might want to check out the Batik mailing lists:

                http://xml.apache.org/batik/mailList.html

                > <DOM BATIK example>
                > // set the width and height attribute on the root svg element
                > svgRoot.setAttributeNS(null, "width", "400");
                > svgRoot.setAttributeNS(null, "height", "450");
                >
                > // create the rectangle
                > Element rectangle = doc.createElementNS(svgNS, "rect");
                > rectangle.setAttributeNS(null, "x", "10");
                > rectangle.setAttributeNS(null, "y", "20");
                > rectangle.setAttributeNS(null, "width", "100");
                > rectangle.setAttributeNS(null, "height", "50");
                > rectangle.setAttributeNS(null, "style", "fill:red");
                >
                > // attach the rectangle to the svg root element
                > svgRoot.appendChild(rectangle);
                > </DOM BATIK example>
                >
                > <OUTPUT STREAM SERVLET>
                > PrintWriter out = response.getWriter();
                > out.println("<svg width=\"400\" height=\"450\">
                > <rect x=\"10\" y=\"20\" width=\"100\" height=\"50\" style=\"fill:
                > red\"/>
                > </svg>");
                > </OUTPUT STREAM SERVLET>
              • alex_philippi
                Thnx for your statement :) My Servlet will be high dynamic e.g. I draw 100 rects (with content) in a for loop and I place them with an algorithm (and so i
                Message 7 of 7 , Feb 2, 2005
                  Thnx for your statement :)
                  My Servlet will be high dynamic e.g. I draw 100 rects (with content)
                  in a "for loop" and I place them with an algorithm (and so i have not
                  much code and i could validate the result) :)

                  An other advantage to use "out" is that I can use javascript for
                  tooltips.

                  And with Graphics2d (I think that) I have to do the same job twice. I
                  draw the graphical result in Java (g.paint...) and then I have to
                  transcode(?) the java result to my output stream of my servlet.

                  Baba :)
                Your message has been successfully submitted and would be delivered to recipients shortly.