[prev in list] [next in list] [prev in thread] [next in thread] 

List:       batik-users
Subject:    Re: org.xml.sax.SAXParseException: Invalid encoding name "HP-ROMAN8"
From:       jonathan wood <jonathanshawwood () gmail ! com>
Date:       2011-11-30 18:07:27
Message-ID: CAKiJDQRz_9W6UPsP-LvQjkRBnsMdnWJ1G72mLkCks2esTGX=+A () mail ! gmail ! com
[Download RAW message or body]

Saw this today and thought I'd drop it here for reference ... a java5
solution to programmatic lookup:

"This class handles looking up service providers on the class path. It
implements the Service Provider section of the JAR File
Specification<http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider>
                
.

The Service Provider programmatic lookup was not specified prior to Java 6
so this interface allows use of the specification prior to Java 6."
http://docs.jboss.org/seam/3/solder/latest/api/org/jboss/solder/util/service/ServiceLoader.html




On Fri, Nov 25, 2011 at 3:12 AM, jonathan wood
<jonathanshawwood@gmail.com>wrote:

> Note that the linked second form of newInstance(...) seems to bo 1.6
> specific
> 
> 
> On Fri, Nov 25, 2011 at 3:06 AM, jonathan wood <jonathanshawwood@gmail.com
> > wrote:
> 
> > 
> > I believe you are experiencing a ServiceLoader in your xerces jar file.
> > You can test this by looking for the file
> > /META-INF/services/javax.xml.parsers.SAXParserFactory.  If it exists, you
> > have a few choices....
> > 
> > Brute force...remove the file from the xerces jar and repackage (relies
> > on classpath and a one-off jar...not a good solution).
> > 
> > You can manipulate the load of the "service" implementation by iterating
> > over the options...
> > 
> > ServiceLoader<SAXParserFactory> serviceLoader =
> > ServiceLoader.load(SAXParserFactory.class);
> > serviceLoader.iterator();
> > for (SAXParserFactory spf : serviceLoader) {
> > // spf.???
> > }
> > 
> > Directly load the impl you want ...   \
> > SAXParserFactory.html#newInstance(java.lang.String, \
> > java.lang.ClassLoader)<http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance(java.lang.String,%20java.lang.ClassLoader)>
> >  
> > 
> > I'd advise reading the javadoc for both forms of newInstance
> > 
> > 
> > Hope this helps
> > 
> > 
> > 
> > On Thu, Nov 24, 2011 at 5:05 AM, Alex Geller <ag@4js.com> wrote:
> > 
> > > Hi,
> > > I am not sure if this is a Batik only issue but since I encountered it
> > > using
> > > Batik I will share the problem and the solution I have found so far.
> > > 
> > > Description of the problem:
> > > If you have a program that reads XML files and you add
> > > "xerces_2_5_0.jar" to
> > > your CLASSPATH on a HP-UX machine (or any other machine that has
> > > proprietary
> > > XML encodings) then the program may fail with the exception
> > > "org.xml.sax.SAXParseException: Invalid encoding name "HP-ROMAN8"".
> > > 
> > > Note that the existence of this jar in the CLASSPATH is sufficient to
> > > make
> > > this happen. The following test program illustrates the issue (forgive
> > > the
> > > deprecation warning):
> > > 
> > > import org.xml.sax.InputSource;
> > > import javax.xml.parsers.SAXParserFactory;
> > > import java.io.StringBufferInputStream;
> > > public class EncodingTest
> > > {
> > > public static void main(String[] args) throws Exception
> > > {
> > > 
> > > SAXParserFactory.newInstance().newSAXParser().getXMLReader().parse(new
> > > InputSource(new StringBufferInputStream("<?xml version=\"1.0\"
> > > encoding=\"HP-ROMAN8\"?> ")));
> > > }
> > > }
> > > 
> > > Consider the following invocations:
> > > Example 1:
> > > $(unset CLASSPATH;java -Djaxp.debug=1 EncodingTest)
> > > JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
> > > JAXP: loaded from fallback value:
> > > com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
> > > JAXP: created new instance of class
> > > com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using
> > > ClassLoader: null
> > > $
> > > 
> > > Example 2:
> > > $(export CLASSPATH=.:$BATIKDIR/batik-1.7/lib/xerces_2_5_0.jar;java
> > > -Djaxp.debug=1 EncodingTest)
> > > JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
> > > JAXP: found jar
> > > resource=META-INF/services/javax.xml.parsers.SAXParserFactory using
> > > ClassLoader: sun.misc.Launcher$AppClassLoader@df6ccd
> > > JAXP: found in resource,
> > > value=org.apache.xerces.jaxp.SAXParserFactoryImpl
> > > JAXP: created new instance of class
> > > org.apache.xerces.jaxp.SAXParserFactoryImpl using ClassLoader:
> > > sun.misc.Launcher$AppClassLoader@df6ccd
> > > [Fatal Error] :1:43: Invalid encoding name "HP-ROMAN8".
> > > Exception in thread "main" org.xml.sax.SAXParseException: Invalid
> > > encoding
> > > name "HP-ROMAN8".
> > > at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
> > > Source)
> > > at EncodingTest.main(EncodingTest.java:9)
> > > $
> > > 
> > > Now, the issue can be fixed by forcing the JVM to use the default
> > > factory by
> > > settings the property javax.xml.parsers.SAXParserFactory as described in
> > > 
> > > http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance()
> > >  as follows:
> > > 
> > > Example 3:
> > > 
> > > $(export CLASSPATH=.:$BATIKDIR/batik-1.7/lib/xerces_2_5_0.jar;java
> > > 
> > > -Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
> > >                 
> > > -Djaxp.debug=1 EncodingTest)
> > > JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
> > > JAXP: found system property,
> > > value=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
> > > JAXP: created new instance of class
> > > com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using
> > > ClassLoader: null
> > > $
> > > 
> > > Questions:
> > > 1) Is it necessary to include xerces_2_5_0.jar in the CLASSPATH?
> > > 2) If yes, how can I load documents with local encodings and use Batik at
> > > the same time.
> > > 
> > > Thanks,
> > > Alex
> > > 
> > > ~
> > > 
> > > --
> > > View this message in context:
> > > http://batik.2283329.n4.nabble.com/org-xml-sax-SAXParseException-Invalid-encoding-name-HP-ROMAN8-tp4103307p4103307.html
> > >  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
> > > 
> > > 
> > 
> 


[Attachment #3 (text/html)]

<div><br></div><div>Saw this today and thought I&#39;d drop it here for reference ... \
a java5 solution to programmatic lookup:</div><div><br></div><div>&quot;<span \
class="Apple-style-span" style="font-family: Times; background-color: rgb(255, 255, \
255); font-size: medium; ">This class handles looking up service providers on the \
class path. It implements the</span><span class="Apple-style-span" \
style="font-family: Times; background-color: rgb(255, 255, 255); font-size: medium; \
"> </span><a href="http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider" \
style="font-family: Times; background-color: rgb(255, 255, 255); font-size: medium; \
">Service Provider section of the JAR File Specification</a><span \
class="Apple-style-span" style="font-family: Times; background-color: rgb(255, 255, \
255); font-size: medium; ">.</span></div>

<p style="font-family: Times; background-color: rgb(255, 255, 255); font-size: \
medium; ">The Service Provider programmatic lookup was not specified prior to Java 6 \
so this interface allows use of the specification prior to Java 6.&quot;</p>

<div><a href="http://docs.jboss.org/seam/3/solder/latest/api/org/jboss/solder/util/ser \
vice/ServiceLoader.html">http://docs.jboss.org/seam/3/solder/latest/api/org/jboss/solder/util/service/ServiceLoader.html</a><br><br><br>


<br><div class="gmail_quote">On Fri, Nov 25, 2011 at 3:12 AM, jonathan wood <span \
dir="ltr">&lt;<a href="mailto:jonathanshawwood@gmail.com">jonathanshawwood@gmail.com</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex;">

Note that the linked second form of newInstance(...) seems to bo 1.6 specific<div \
class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">On Fri, Nov 25, 2011 \
at 3:06 AM, jonathan wood <span dir="ltr">&lt;<a \
href="mailto:jonathanshawwood@gmail.com" \
target="_blank">jonathanshawwood@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div><br></div>I believe you are experiencing a ServiceLoader \
in your xerces jar file.  You can test this by looking for the file \
/META-INF/services/javax.xml.parsers.SAXParserFactory.  If it exists, you have a few \
choices....<div>



<br></div><div>Brute force...remove the file from the xerces jar and repackage \
(relies on classpath and a one-off jar...not a good \
solution).</div><div><br></div><div>You can manipulate the load of the \
&quot;service&quot; implementation by iterating over the options...<br>



<div><br></div><div><div>        ServiceLoader&lt;<span>SAXParserFactory</span>&gt; \
serviceLoader = ServiceLoader.load(<span>SAXParserFactory</span>.class);</div> <div>  \
serviceLoader.iterator();</div><div>        for (<span>SAXParserFactory</span> spf : \
serviceLoader) {</div> <div>              // spf.???</div><div><div>        \
}</div></div><div><br></div><div>Directly load the impl you want ...   <a \
href="http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance(java.lang.String,%20java.lang.ClassLoader)" \
target="_blank">SAXParserFactory.html#newInstance(java.lang.String, \
java.lang.ClassLoader)</a> </div>



<div><br></div><div>I&#39;d advise reading the javadoc for both forms of \
newInstance</div><div><br></div><div><br></div><div>Hope this \
helps</div><div><div><div><br></div><div><br></div><br><div class="gmail_quote"> On \
Thu, Nov 24, 2011 at 5:05 AM, Alex Geller <span dir="ltr">&lt;<a \
href="mailto:ag@4js.com" target="_blank">ag@4js.com</a>&gt;</span> wrote:<br> \
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Hi,<br> I am not sure if this is a Batik only issue but since \
I encountered it using<br> Batik I will share the problem and the solution I have \
found so far.<br> <br>
Description of the problem:<br>
If you have a program that reads XML files and you add &quot;xerces_2_5_0.jar&quot; \
to<br> your CLASSPATH on a HP-UX machine (or any other machine that has \
proprietary<br> XML encodings) then the program may fail with the exception<br>
&quot;org.xml.sax.SAXParseException: Invalid encoding name \
&quot;HP-ROMAN8&quot;&quot;.<br> <br>
Note that the existence of this jar in the CLASSPATH is sufficient to make<br>
this happen. The following test program illustrates the issue (forgive the<br>
deprecation warning):<br>
<br>
import org.xml.sax.InputSource;<br>
import javax.xml.parsers.SAXParserFactory;<br>
import java.io.StringBufferInputStream;<br>
public class EncodingTest<br>
{<br>
    public static void main(String[] args) throws Exception<br>
    {<br>
<br>
SAXParserFactory.newInstance().newSAXParser().getXMLReader().parse(new<br>
InputSource(new StringBufferInputStream(&quot;&lt;?xml version=\&quot;1.0\&quot;<br>
encoding=\&quot;HP-ROMAN8\&quot;?&gt; &quot;)));<br>
    }<br>
}<br>
<br>
Consider the following invocations:<br>
Example 1:<br>
$(unset CLASSPATH;java -Djaxp.debug=1 EncodingTest)<br>
JAXP: find factoryId =javax.xml.parsers.SAXParserFactory<br>
JAXP: loaded from fallback value:<br>
com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl<br>
JAXP: created new instance of class<br>
com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using<br>
ClassLoader: null<br>
$<br>
<br>
Example 2:<br>
$(export CLASSPATH=.:$BATIKDIR/batik-1.7/lib/xerces_2_5_0.jar;java<br>
-Djaxp.debug=1 EncodingTest)<br>
JAXP: find factoryId =javax.xml.parsers.SAXParserFactory<br>
JAXP: found jar<br>
resource=META-INF/services/javax.xml.parsers.SAXParserFactory using<br>
ClassLoader: sun.misc.Launcher$AppClassLoader@df6ccd<br>
JAXP: found in resource, value=org.apache.xerces.jaxp.SAXParserFactoryImpl<br>
JAXP: created new instance of class<br>
org.apache.xerces.jaxp.SAXParserFactoryImpl using ClassLoader:<br>
sun.misc.Launcher$AppClassLoader@df6ccd<br>
[Fatal Error] :1:43: Invalid encoding name &quot;HP-ROMAN8&quot;.<br>
Exception in thread &quot;main&quot; org.xml.sax.SAXParseException: Invalid \
encoding<br> name &quot;HP-ROMAN8&quot;.<br>
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)<br>
        at EncodingTest.main(EncodingTest.java:9)<br>
$<br>
<br>
Now, the issue can be fixed by forcing the JVM to use the default factory by<br>
settings the property javax.xml.parsers.SAXParserFactory as described in<br>
<a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance()" \
target="_blank">http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance()</a><br>





as follows:<br>
<br>
Example 3:<br>
<br>
$(export CLASSPATH=.:$BATIKDIR/batik-1.7/lib/xerces_2_5_0.jar;java<br>
-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl<br>
                
-Djaxp.debug=1 EncodingTest)<br>
JAXP: find factoryId =javax.xml.parsers.SAXParserFactory<br>
JAXP: found system property,<br>
value=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl<br>
JAXP: created new instance of class<br>
com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using<br>
ClassLoader: null<br>
$<br>
<br>
Questions:<br>
1) Is it necessary to include xerces_2_5_0.jar in the CLASSPATH?<br>
2) If yes, how can I load documents with local encodings and use Batik at<br>
the same time.<br>
<br>
Thanks,<br>
Alex<br>
<br>
~<br>
<span><font color="#888888"><br>
--<br>
View this message in context: <a \
href="http://batik.2283329.n4.nabble.com/org-xml-sax-SAXParseException-Invalid-encoding-name-HP-ROMAN8-tp4103307p4103307.html" \
target="_blank">http://batik.2283329.n4.nabble.com/org-xml-sax-SAXParseException-Invalid-encoding-name-HP-ROMAN8-tp4103307p4103307.html</a><br>





Sent from the Batik - Users mailing list archive at Nabble.com.<br>
<br>
---------------------------------------------------------------------<br>
To unsubscribe, e-mail: <a \
href="mailto:batik-users-unsubscribe@xmlgraphics.apache.org" \
target="_blank">batik-users-unsubscribe@xmlgraphics.apache.org</a><br> For additional \
commands, e-mail: <a href="mailto:batik-users-help@xmlgraphics.apache.org" \
target="_blank">batik-users-help@xmlgraphics.apache.org</a><br> <br>
</font></span></blockquote></div><br></div></div></div></div>
</blockquote></div><br>
</div></div></blockquote></div><br></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic