You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by javaNoob <no...@yahoo.com> on 2007/08/20 19:36:48 UTC

how to load an external stylesheet?

how can i load an external stylesheet?
-- 
View this message in context: http://www.nabble.com/how-to-load-an-external-stylesheet--tf4300368.html#a12240396
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: how to load an external stylesheet?

Posted by javaNoob <no...@yahoo.com>.


thomas.deweese wrote:
> 
> 
>    One other thing that occurs to me, are you
> calling canvas.SVGDocument with the document returned
> from the loadMap method?  Or are you setting the
> URL to the same 'fileName' that you pass to the loadMap 
> method?
> 
> 

sir, i did not understand this question.. 

i changed my code. i load the svg file as text then pass it to an applet.

    protected String loadFile(String fileName) throws FileNotFoundException,
IOException {
        String tile = "";
        BufferedReader inputStream = null;

        try {
            String mapsFolder =
getServletContext().getRealPath("/WEB-INF/maps");
            inputStream = new BufferedReader(new FileReader(mapsFolder + "/"
+ fileName));
            String line;
            while ((line = inputStream.readLine()) != null) {
                tile = tile + line + "\n";
            }
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
        return tile;
    }

the applet receives the string and converts it to svg using this function

    protected SVGDocument stringToSVG(String DOMString){
        SAXSVGDocumentFactory f;
        Document doc = null;
        StringReader sr;

        try {
            String parser = XMLResourceDescriptor.getXMLParserClassName();
            f = new SAXSVGDocumentFactory(parser);
            sr = new StringReader(DOMString);
            doc = f.createDocument(null, sr);
        } catch (java.io.IOException ex) {
            ex.printStackTrace();
        }
        return (SVGDocument)doc;
    }

then i apply this code in the returned SVGDocument

        ProcessingInstruction pi =
doc.createProcessingInstruction("xml-stylesheet", "type=\"text/css\"
href=\"" + styleSheetURL + "\"");
        doc.insertBefore(pi, doc.getDocumentElement());

and just to be sure, if i want to use the class, i will only set the class
attribute right? like element.setAttribute("class", "cssClass")
-- 
View this message in context: http://www.nabble.com/how-to-load-an-external-stylesheet--tf4300368.html#a12614023
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: how to load an external stylesheet?

Posted by th...@kodak.com.
Hi JavaNoob,

javaNoob <no...@yahoo.com> wrote on 09/04/2007 07:36:06 AM:

> i placed the css file in the root of my webapp. what i mean is the 
location
> of the css file is in the correct folder, i set the class of the element 
but
> it's still not loading.

   It's really easy to get a wrong URL, and for style sheets we have
to ignore the errors.

> i also tried what you suggested.. thanks for
> pointing that out.. but i can't make it load..

   One other thing that occurs to me, are you
calling canvas.SVGDocument with the document returned
from the loadMap method?  Or are you setting the
URL to the same 'fileName' that you pass to the loadMap 
method?

   Without more to go (e.g. standalone example) on I can't 
really help you.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: how to load an external stylesheet?

Posted by javaNoob <no...@yahoo.com>.
sir, there is no stacktrace/exception

i placed the css file in the root of my webapp. what i mean is the location
of the css file is in the correct folder, i set the class of the element but
it's still not loading. i also tried what you suggested.. thanks for
pointing that out.. but i can't make it load..
-- 
View this message in context: http://www.nabble.com/how-to-load-an-external-stylesheet--tf4300368.html#a12476391
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: how to load an external stylesheet?

Posted by th...@kodak.com.
Hi JavaNoob,

javaNoob <no...@yahoo.com> wrote on 09/03/2007 03:06:37 AM:

> it's not working.. can anyone take a look?

   What's happening?  Any stack trace/Exception?

> this snippet is from a servlet that loads the svg.. i am sure that the
> styleSheetURL is correct

   Why are you sure of that?  (also see below for possible typo).

>     protected SVGDocument loadMap(String fileName) {
>         Document doc = null;
>         try {
>             String parser = 
XMLResourceDescriptor.getXMLParserClassName();
>             SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
>             String uri = fileName;
>             doc = f.createDocument(uri);
> 
>             ProcessingInstruction pi =
> doc.createProcessingInstruction("xml-stylesheet", 
                                  "type=\"text/css\"href=\"" + 
styleSheetURL + "\"");
 
     I think there should be a space between the close quote for
'type' and the 'href' attribute.  That could probably cause the problem...

>             doc.insertBefore(pi, doc.getDocumentElement()); 
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         return (SVGDocument)doc;
>     }


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: how to load an external stylesheet?

Posted by javaNoob <no...@yahoo.com>.
it's not working.. can anyone take a look?

this snippet is from a servlet that loads the svg.. i am sure that the
styleSheetURL is correct

    protected SVGDocument loadMap(String fileName) {
        Document doc = null;
        try {
            String parser = XMLResourceDescriptor.getXMLParserClassName();
            SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
            String uri = fileName;
            doc = f.createDocument(uri);
            
            ProcessingInstruction pi =
doc.createProcessingInstruction("xml-stylesheet", "type=\"text/css\"href=\""
+ styleSheetURL + "\"");
            doc.insertBefore(pi, doc.getDocumentElement()); 
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return (SVGDocument)doc;
    }
-- 
View this message in context: http://www.nabble.com/how-to-load-an-external-stylesheet--tf4300368.html#a12456428
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: how to load an external stylesheet?

Posted by Dylan Browne <db...@mango-solutions.com>.
If your stylesheet is accessible via a URL, you can do something similar
to this.....

ProcessingInstruction pi =
doc.createProcessingInstruction("xml-stylesheet", "type=\"text/css\"
href=\"" + styleSheetURL + "\"");
doc.insertBefore(pi, doc.getDocumentElement());


-----Original Message-----
From: javaNoob [mailto:noypi_baller@yahoo.com] 
Sent: 20 August 2007 18:37
To: batik-users@xmlgraphics.apache.org
Subject: how to load an external stylesheet?


how can i load an external stylesheet?
-- 
View this message in context:
http://www.nabble.com/how-to-load-an-external-stylesheet--tf4300368.html
#a12240396
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org