SourceTreeManagerpublic class SourceTreeManager extends Object This class bottlenecks all management of source trees. The methods
in this class should allow easy garbage collection of source
trees (not yet!), and should centralize parsing for those source trees. |
Fields Summary |
---|
private Vector | m_sourceTreeVector of SourceTree objects that this manager manages. | URIResolver | m_uriResolverThe TrAX URI resolver used to obtain source trees. |
Methods Summary |
---|
public java.lang.String | findURIFromDoc(int owner)Given a document, find the URL associated with that document.
int n = m_sourceTree.size();
for (int i = 0; i < n; i++)
{
SourceTree sTree = (SourceTree) m_sourceTree.elementAt(i);
if (owner == sTree.m_root)
return sTree.m_url;
}
return null;
| public int | getNode(javax.xml.transform.Source source)Given a Source object, find the node associated with it.
// if (source instanceof DOMSource)
// return ((DOMSource) source).getNode();
// TODO: Not sure if the BaseID is really the same thing as the ID.
String url = source.getSystemId();
if (null == url)
return DTM.NULL;
int n = m_sourceTree.size();
// System.out.println("getNode: "+n);
for (int i = 0; i < n; i++)
{
SourceTree sTree = (SourceTree) m_sourceTree.elementAt(i);
// System.out.println("getNode - url: "+url);
// System.out.println("getNode - sTree.m_url: "+sTree.m_url);
if (url.equals(sTree.m_url))
return sTree.m_root;
}
// System.out.println("getNode - returning: "+node);
return DTM.NULL;
| public int | getSourceTree(javax.xml.transform.Source source, javax.xml.transform.SourceLocator locator, com.sun.org.apache.xpath.internal.XPathContext xctxt)Get the source tree from the input source.
int n = getNode(source);
if (DTM.NULL != n)
return n;
n = parseToNode(source, locator, xctxt);
if (DTM.NULL != n)
putDocumentInCache(n, source);
return n;
| public int | getSourceTree(java.lang.String base, java.lang.String urlString, javax.xml.transform.SourceLocator locator, com.sun.org.apache.xpath.internal.XPathContext xctxt)Get the source tree from the a base URL and a URL string.
// System.out.println("getSourceTree");
try
{
Source source = this.resolveURI(base, urlString, locator);
// System.out.println("getSourceTree - base: "+base+", urlString: "+urlString+", source: "+source.getSystemId());
return getSourceTree(source, locator, xctxt);
}
catch (IOException ioe)
{
throw new TransformerException(ioe.getMessage(), locator, ioe);
}
/* catch (TransformerException te)
{
throw new TransformerException(te.getMessage(), locator, te);
}*/
| public javax.xml.transform.URIResolver | getURIResolver()Get the object that will be used to resolve URIs used in
document(), etc.
return m_uriResolver;
| public static org.xml.sax.XMLReader | getXMLReader(javax.xml.transform.Source inputSource, javax.xml.transform.SourceLocator locator)This method returns the SAX2 parser to use with the InputSource
obtained from this URI.
It may return null if any SAX2-conformant XML parser can be used,
or if getInputSource() will also return null. The parser must
be free for use (i.e.
not currently in use for another parse().
try
{
XMLReader reader = (inputSource instanceof SAXSource)
? ((SAXSource) inputSource).getXMLReader() : null;
if (null == reader)
{
try {
javax.xml.parsers.SAXParserFactory factory=
javax.xml.parsers.SAXParserFactory.newInstance();
factory.setNamespaceAware( true );
javax.xml.parsers.SAXParser jaxpParser=
factory.newSAXParser();
reader=jaxpParser.getXMLReader();
} catch( javax.xml.parsers.ParserConfigurationException ex ) {
throw new org.xml.sax.SAXException( ex );
} catch( javax.xml.parsers.FactoryConfigurationError ex1 ) {
throw new org.xml.sax.SAXException( ex1.toString() );
} catch( NoSuchMethodError ex2 ) {
}
catch (AbstractMethodError ame){}
if(null == reader)
reader = XMLReaderFactory.createXMLReader();
}
try
{
reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
}
catch (org.xml.sax.SAXException se)
{
// What can we do?
// TODO: User diagnostics.
}
return reader;
}
catch (org.xml.sax.SAXException se)
{
throw new TransformerException(se.getMessage(), locator, se);
}
| public int | parseToNode(javax.xml.transform.Source source, javax.xml.transform.SourceLocator locator, com.sun.org.apache.xpath.internal.XPathContext xctxt)Try to create a DOM source tree from the input source.
try
{
Object xowner = xctxt.getOwnerObject();
DTM dtm;
if(null != xowner && xowner instanceof com.sun.org.apache.xml.internal.dtm.DTMWSFilter)
{
dtm = xctxt.getDTM(source, false,
(com.sun.org.apache.xml.internal.dtm.DTMWSFilter)xowner, false, true);
}
else
{
dtm = xctxt.getDTM(source, false, null, false, true);
}
return dtm.getDocument();
}
catch (Exception e)
{
//e.printStackTrace();
throw new TransformerException(e.getMessage(), locator, e);
}
| public void | putDocumentInCache(int n, javax.xml.transform.Source source)Put the source tree root node in the document cache.
TODO: This function needs to be a LOT more sophisticated.
int cachedNode = getNode(source);
if (DTM.NULL != cachedNode)
{
if (!(cachedNode == n))
throw new RuntimeException(
"Programmer's Error! "
+ "putDocumentInCache found reparse of doc: "
+ source.getSystemId());
return;
}
if (null != source.getSystemId())
{
m_sourceTree.addElement(new SourceTree(n, source.getSystemId()));
}
| public void | removeDocumentFromCache(int n)JJK: Support kluge in ElemForEach.
TODO: This function is highly dangerous. Cache management must be improved.
if(DTM.NULL ==n)
return;
for(int i=m_sourceTree.size()-1;i>=0;--i)
{
SourceTree st=(SourceTree)m_sourceTree.elementAt(i);
if(st!=null && st.m_root==n)
{
m_sourceTree.removeElementAt(i);
return;
}
}
| public void | reset()Reset the list of SourceTree objects that this manager manages.
m_sourceTree = new Vector();
| public javax.xml.transform.Source | resolveURI(java.lang.String base, java.lang.String urlString, javax.xml.transform.SourceLocator locator)This will be called by the processor when it encounters
an xsl:include, xsl:import, or document() function.
Source source = null;
if (null != m_uriResolver)
{
source = m_uriResolver.resolve(urlString, base);
}
if (null == source)
{
String uri = SystemIDResolver.getAbsoluteURI(urlString, base);
source = new StreamSource(uri);
}
return source;
| public void | setURIResolver(javax.xml.transform.URIResolver resolver)Set an object that will be used to resolve URIs used in
document(), etc.
m_uriResolver = resolver;
|
|