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

List:       xerces-j-dev
Subject:    Re: custom XIncludeHandler
From:       Michael Glavassevich <mrglavas () ca ! ibm ! com>
Date:       2010-08-26 2:56:52
Message-ID: OFCF31BC09.AFBE1870-ON8525778B.000F8DEB-8525778B.0010325A () ca ! ibm ! com
[Download RAW message or body]

Steve,

The EntityResolver2 flavour of resolveEntity() passes you the base URI.
"Expanding" the system ID is just resolving it against the base URI. As for
a public API, you can use java.net.URI to do this.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Steve Ebersole <steven.ebersole@gmail.com> wrote on 08/25/2010 12:38:22 PM:

> Ok, I got this aspect of it work now.  I do run into a related problem
> though.  I actually am using a "chain" of entity resolvers.  So I ended
> up needing to have my chain implement EntityResolver2 also:
>
> http://github.com/sebersole/jdocbook-core/blob/master/src/main/java/
> org/jboss/jdocbook/xslt/EntityResolverChain.java
>
> I am having trouble getting the delegation from
> EntityResolver2#resolveEntity to EntityResolver#resolveEntity correct
> given the need to manually account for the "expanded system id" much
> like y'all do in
> com.sun.org.apache.xerces.internal.impl.XMLEntityManager#expandSystemId
>
> Is there a "public API" version of this method around?  Is it kosher to
> cal that method directly in my code?
>
>
> On Fri, 2010-08-20 at 13:50 -0500, Steve Ebersole wrote:
> > So given the DOCTYPE I described:
> > <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
> > "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
> >     <!ENTITY % BOOK_ENTITIES SYSTEM
> > "Hibernate_Getting_Started_Guide.ent">
> >     %BOOK_ENTITIES;
> > ]>
> >
> > I see the following:
> > (1) resolveEntity( "%BOOK_ENTITIES", ... );
> > (2) resolveEntity( "[dtd]", ... );
> >
> > I tried adding my "extra" entities during call (1).  Essentially, I
load
> > the contents of the referenced file
> > (Hibernate_Getting_Started_Guide.ent), prepend my custom entities and
> > wrap that whole thing up in a InputStream.  However that does not
> > "work"; it does not seem to pick up my entities.  Found that a bit
> > counter-intuitive.
> >
> > If I delay this process until (2), I am not exactly sure what I am
> > supposed to return.  As I understand it, I am being asked to resolve
the
> > actual DTD file
> > (http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd)?
> >
> >
> > On Fri, 2010-08-20 at 08:41 -0400, Michael Glavassevich wrote:
> > > Steve Ebersole <steven.ebersole@gmail.com> wrote on 08/20/2010
> > > 08:26:19 AM:
> > >
> > > > On Fri, 2010-08-20 at 08:19 -0400, Michael Glavassevich wrote:
> > > > > Perhaps EntityResolver2.getExternalSubset() is only part of the
> > > > > solution. Can you show concrete examples where this wouldn't work
> > > on
> > > > > its own?
> > > >
> > > > Based on what you said, I had assumed that something like this
would
> > > not
> > > > work:
> > > > http://anonsvn.jboss.org/repos/hibernate/core/trunk/documentation/
> > > > manual/src/main/docbook/en-US/HIBERNATE_-
> > > > _Relational_Persistence_for_Idiomatic_Java.xml
> > > >
> > > > Because we have:
> > > > <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
> > > > "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
> > > > <!ENTITY % BOOK_ENTITIES SYSTEM "HIBERNATE_-
> > > > _Relational_Persistence_for_Idiomatic_Java.ent">
> > > > %BOOK_ENTITIES;
> > > > ]>
> > > >
> > > > So essentially we reference an external set of entities:
> > > > http://anonsvn.jboss.org/repos/hibernate/core/trunk/documentation/
> > > > manual/src/main/docbook/en-US/HIBERNATE_-
> > > > _Relational_Persistence_for_Idiomatic_Java.ent
> > >
> > > So instead of getExternalSubset() you'll get a call to resolveEntity
()
> > > and can do what I said below.
> > >
> > > > > Note that if a document already has an external subset your
> > > instance
> > > > > of EntityResolver2 will get a call to resolveEntity() and you can
> > > tell
> > > > > by the entity name "[dtd]" that the parser is asking you to
> > > resolve
> > > > > it. That's also an opportunity to inject whatever entity
> > > declarations
> > > > > you want to add and could include the DTD you were asked to
> > > resolve
> > > > > through a parameter entity.
> > > > >
> > > > > > Which takes me back to the question of a custom XIncludeHandler
> > > and
> > > > > (a)
> > > > > > whether that is a valid option and (b) how to properly make
sure
> > > my
> > > > > > custom XIncludeHandler gets used in the pipeline.
> > > > >
> > > > > There's no supported way of doing that. You would have to reach
> > > into
> > > > > the implementation and if you managed to get something working
> > > your
> > > > > application could be broken with a future release of Xerces. We
> > > make
> > > > > no guarantees on the stability of internal components and warn
> > > users
> > > > > in the Javadoc that they're on shaky ground if they choose that
> > > path.
> > > > >
> > > > > > --
> > > > > > Steve Ebersole <steve@hibernate.org>
> > > > > > http://hibernate.org
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > > > > > For additional commands, e-mail: j-users-help@xerces.apache.org
> > > > >
> > > > > Thanks.
> > > > >
> > > > > Michael Glavassevich
> > > > > XML Parser Development
> > > > > IBM Toronto Lab
> > > > > E-mail: mrglavas@ca.ibm.com
> > > > > E-mail: mrglavas@apache.org
> > > > >
> > > >
> > > > --
> > > > Steve Ebersole <steve@hibernate.org>
> > > > http://hibernate.org
> > > >
> > > >
> > > >
> > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > > > For additional commands, e-mail: j-users-help@xerces.apache.org
> > >
> > > Michael Glavassevich
> > > XML Parser Development
> > > IBM Toronto Lab
> > > E-mail: mrglavas@ca.ibm.com
> > > E-mail: mrglavas@apache.org
> > >
> >
>
> --
> Steve Ebersole <steve@hibernate.org>
> http://hibernate.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
[Attachment #3 (text/html)]

<html><body>
<p><tt>Steve,</tt><br>
<br>
<tt>The EntityResolver2 flavour of resolveEntity() passes you the base URI. \
&quot;Expanding&quot; the system ID is just resolving it against the base URI. As for \
a public API, you can use java.net.URI to do this.</tt><br> <br>
<tt>Thanks.</tt><br>
<br>
<tt>Michael Glavassevich<br>
XML Parser Development<br>
IBM Toronto Lab<br>
E-mail: mrglavas@ca.ibm.com</tt><br>
<tt>E-mail: mrglavas@apache.org</tt><br>
<br>
<tt>Steve Ebersole &lt;steven.ebersole@gmail.com&gt; wrote on 08/25/2010 12:38:22 \
PM:<br> <br>
&gt; Ok, I got this aspect of it work now. &nbsp;I do run into a related problem<br>
&gt; though. &nbsp;I actually am using a &quot;chain&quot; of entity resolvers. \
&nbsp;So I ended<br> &gt; up needing to have my chain implement EntityResolver2 \
also:<br> &gt; <br>
&gt; <a href="http://github.com/sebersole/jdocbook-core/blob/master/src/main/java/">http://github.com/sebersole/jdocbook-core/blob/master/src/main/java/</a><br>
 &gt; org/jboss/jdocbook/xslt/EntityResolverChain.java<br>
&gt; <br>
&gt; I am having trouble getting the delegation from<br>
&gt; EntityResolver2#resolveEntity to EntityResolver#resolveEntity correct<br>
&gt; given the need to manually account for the &quot;expanded system id&quot; \
much<br> &gt; like y'all do in<br>
&gt; com.sun.org.apache.xerces.internal.impl.XMLEntityManager#expandSystemId<br>
&gt; <br>
&gt; Is there a &quot;public API&quot; version of this method around? &nbsp;Is it \
kosher to<br> &gt; cal that method directly in my code?<br>
&gt; <br>
&gt; <br>
&gt; On Fri, 2010-08-20 at 13:50 -0500, Steve Ebersole wrote:<br>
&gt; &gt; So given the DOCTYPE I described:<br>
&gt; &gt; &lt;!DOCTYPE book PUBLIC &quot;-//OASIS//DTD DocBook XML V4.5//EN&quot;<br>
&gt; &gt; &quot;<a href="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd</a>&quot; \
[<br> &gt; &gt; &nbsp; &nbsp; &lt;!ENTITY % BOOK_ENTITIES SYSTEM<br>
&gt; &gt; &quot;Hibernate_Getting_Started_Guide.ent&quot;&gt;<br>
&gt; &gt; &nbsp; &nbsp; %BOOK_ENTITIES;<br>
&gt; &gt; ]&gt;<br>
&gt; &gt; <br>
&gt; &gt; I see the following:<br>
&gt; &gt; (1) resolveEntity( &quot;%BOOK_ENTITIES&quot;, ... );<br>
&gt; &gt; (2) resolveEntity( &quot;[dtd]&quot;, ... );<br>
&gt; &gt; <br>
&gt; &gt; I tried adding my &quot;extra&quot; entities during call (1). \
&nbsp;Essentially, I load<br> &gt; &gt; the contents of the referenced file<br>
&gt; &gt; (Hibernate_Getting_Started_Guide.ent), prepend my custom entities and<br>
&gt; &gt; wrap that whole thing up in a InputStream. &nbsp;However that does not<br>
&gt; &gt; &quot;work&quot;; it does not seem to pick up my entities. &nbsp;Found that \
a bit<br> &gt; &gt; counter-intuitive.<br>
&gt; &gt; <br>
&gt; &gt; If I delay this process until (2), I am not exactly sure what I am<br>
&gt; &gt; supposed to return. &nbsp;As I understand it, I am being asked to resolve \
the<br> &gt; &gt; actual DTD file<br>
&gt; &gt; (<a href="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd</a>)?<br>
 &gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; On Fri, 2010-08-20 at 08:41 -0400, Michael Glavassevich wrote:<br>
&gt; &gt; &gt; Steve Ebersole &lt;steven.ebersole@gmail.com&gt; wrote on \
08/20/2010<br> &gt; &gt; &gt; 08:26:19 AM:<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; On Fri, 2010-08-20 at 08:19 -0400, Michael Glavassevich \
wrote:<br> &gt; &gt; &gt; &gt; &gt; Perhaps EntityResolver2.getExternalSubset() is \
only part of the<br> &gt; &gt; &gt; &gt; &gt; solution. Can you show concrete \
examples where this wouldn't work<br> &gt; &gt; &gt; on<br>
&gt; &gt; &gt; &gt; &gt; its own?<br>
&gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; Based on what you said, I had assumed that something like this \
would<br> &gt; &gt; &gt; not<br>
&gt; &gt; &gt; &gt; work:<br>
&gt; &gt; &gt; &gt; <a \
href="http://anonsvn.jboss.org/repos/hibernate/core/trunk/documentation/">http://anonsvn.jboss.org/repos/hibernate/core/trunk/documentation/</a><br>
 &gt; &gt; &gt; &gt; manual/src/main/docbook/en-US/HIBERNATE_-<br>
&gt; &gt; &gt; &gt; _Relational_Persistence_for_Idiomatic_Java.xml<br>
&gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; Because we have:<br>
&gt; &gt; &gt; &gt; &lt;!DOCTYPE book PUBLIC &quot;-//OASIS//DTD DocBook XML \
V4.5//EN&quot;<br> &gt; &gt; &gt; &gt; &quot;<a \
href="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd</a>&quot; \
[ <br> &gt; &gt; &gt; &gt; &lt;!ENTITY % BOOK_ENTITIES SYSTEM &quot;HIBERNATE_-<br>
&gt; &gt; &gt; &gt; _Relational_Persistence_for_Idiomatic_Java.ent&quot;&gt;<br>
&gt; &gt; &gt; &gt; %BOOK_ENTITIES;<br>
&gt; &gt; &gt; &gt; ]&gt;<br>
&gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; So essentially we reference an external set of entities:<br>
&gt; &gt; &gt; &gt; <a \
href="http://anonsvn.jboss.org/repos/hibernate/core/trunk/documentation/">http://anonsvn.jboss.org/repos/hibernate/core/trunk/documentation/</a><br>
 &gt; &gt; &gt; &gt; manual/src/main/docbook/en-US/HIBERNATE_-<br>
&gt; &gt; &gt; &gt; _Relational_Persistence_for_Idiomatic_Java.ent<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; So instead of getExternalSubset() you'll get a call to \
resolveEntity()<br> &gt; &gt; &gt; and can do what I said below.<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; &gt; Note that if a document already has an external subset \
your<br> &gt; &gt; &gt; instance<br>
&gt; &gt; &gt; &gt; &gt; of EntityResolver2 will get a call to resolveEntity() and \
you can<br> &gt; &gt; &gt; tell<br>
&gt; &gt; &gt; &gt; &gt; by the entity name &quot;[dtd]&quot; that the parser is \
asking you to<br> &gt; &gt; &gt; resolve<br>
&gt; &gt; &gt; &gt; &gt; it. That's also an opportunity to inject whatever entity<br>
&gt; &gt; &gt; declarations<br>
&gt; &gt; &gt; &gt; &gt; you want to add and could include the DTD you were asked \
to<br> &gt; &gt; &gt; resolve<br>
&gt; &gt; &gt; &gt; &gt; through a parameter entity.<br>
&gt; &gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; &gt; &gt; Which takes me back to the question of a custom \
XIncludeHandler<br> &gt; &gt; &gt; and<br>
&gt; &gt; &gt; &gt; &gt; (a)<br>
&gt; &gt; &gt; &gt; &gt; &gt; whether that is a valid option and (b) how to properly \
make sure<br> &gt; &gt; &gt; my<br>
&gt; &gt; &gt; &gt; &gt; &gt; custom XIncludeHandler gets used in the pipeline.<br>
&gt; &gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; &gt; There's no supported way of doing that. You would have to \
reach<br> &gt; &gt; &gt; into<br>
&gt; &gt; &gt; &gt; &gt; the implementation and if you managed to get something \
working<br> &gt; &gt; &gt; your<br>
&gt; &gt; &gt; &gt; &gt; application could be broken with a future release of Xerces. \
We<br> &gt; &gt; &gt; make<br>
&gt; &gt; &gt; &gt; &gt; no guarantees on the stability of internal components and \
warn<br> &gt; &gt; &gt; users<br>
&gt; &gt; &gt; &gt; &gt; in the Javadoc that they're on shaky ground if they choose \
that<br> &gt; &gt; &gt; path.<br>
&gt; &gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; &gt; &gt; -- <br>
&gt; &gt; &gt; &gt; &gt; &gt; Steve Ebersole &lt;steve@hibernate.org&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; <a \
href="http://hibernate.org">http://hibernate.org</a><br> &gt; &gt; &gt; &gt; &gt; \
&gt; <br> &gt; &gt; &gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; ---------------------------------------------------------------------<br>
 &gt; &gt; &gt; &gt; &gt; &gt; To unsubscribe, e-mail: \
j-users-unsubscribe@xerces.apache.org<br> &gt; &gt; &gt; &gt; &gt; &gt; For \
additional commands, e-mail: j-users-help@xerces.apache.org<br> &gt; &gt; &gt; &gt; \
&gt; <br> &gt; &gt; &gt; &gt; &gt; Thanks.<br>
&gt; &gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; &gt; Michael Glavassevich<br>
&gt; &gt; &gt; &gt; &gt; XML Parser Development<br>
&gt; &gt; &gt; &gt; &gt; IBM Toronto Lab<br>
&gt; &gt; &gt; &gt; &gt; E-mail: mrglavas@ca.ibm.com<br>
&gt; &gt; &gt; &gt; &gt; E-mail: mrglavas@apache.org<br>
&gt; &gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; -- <br>
&gt; &gt; &gt; &gt; Steve Ebersole &lt;steve@hibernate.org&gt;<br>
&gt; &gt; &gt; &gt; <a href="http://hibernate.org">http://hibernate.org</a><br>
&gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt; <br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; ---------------------------------------------------------------------<br>
 &gt; &gt; &gt; &gt; To unsubscribe, e-mail: \
j-users-unsubscribe@xerces.apache.org<br> &gt; &gt; &gt; &gt; For additional \
commands, e-mail: j-users-help@xerces.apache.org<br> &gt; &gt; &gt; <br>
&gt; &gt; &gt; Michael Glavassevich<br>
&gt; &gt; &gt; XML Parser Development<br>
&gt; &gt; &gt; IBM Toronto Lab<br>
&gt; &gt; &gt; E-mail: mrglavas@ca.ibm.com<br>
&gt; &gt; &gt; E-mail: mrglavas@apache.org<br>
&gt; &gt; &gt; <br>
&gt; &gt; <br>
&gt; <br>
&gt; -- <br>
&gt; Steve Ebersole &lt;steve@hibernate.org&gt;<br>
&gt; <a href="http://hibernate.org">http://hibernate.org</a><br>
&gt; <br>
&gt; <br>
&gt; ---------------------------------------------------------------------<br>
&gt; To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org<br>
&gt; For additional commands, e-mail: \
j-users-help@xerces.apache.org</tt></body></html>



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

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