velosurf.util
Class XIncludeResolver

java.lang.Object
  extended by velosurf.util.XIncludeResolver

public class XIncludeResolver
extends java.lang.Object

A basic JDOM XInclude resolver that will also work with a document base inside WEB-INF and with war archives.

Author:
Claude Brisson

Field Summary
private  java.lang.String base
          base directory
private  javax.servlet.ServletContext context
          servlet context
 
Constructor Summary
XIncludeResolver(java.lang.String base)
          Constructor outside a webapp.
XIncludeResolver(java.lang.String base, javax.servlet.ServletContext ctx)
          Constructor for a webapp resolver.
 
Method Summary
private  java.util.List<org.jdom.Content> include(org.jdom.Element xinclude)
          Performs the real include.
private  boolean isXIncludeElement(org.jdom.Element element)
          Check whether this element is an include element.
private  java.lang.String readStream(java.io.InputStream stream)
          Read a stream in a string.
 org.jdom.Document resolve(org.jdom.Document doc)
          Resolve includes in the document.
private  void resolveChildren(org.jdom.Element parent)
          Resolve children XML elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base

private java.lang.String base
base directory


context

private javax.servlet.ServletContext context
servlet context

Constructor Detail

XIncludeResolver

public XIncludeResolver(java.lang.String base,
                        javax.servlet.ServletContext ctx)
Constructor for a webapp resolver.

Parameters:
base - base directory
ctx - servlet context

XIncludeResolver

public XIncludeResolver(java.lang.String base)
Constructor outside a webapp.

Parameters:
base - base directory
Method Detail

resolve

public org.jdom.Document resolve(org.jdom.Document doc)
                          throws java.lang.Exception
Resolve includes in the document.

Parameters:
doc - document to be resolved
Returns:
document with includes resolved
Throws:
java.lang.Exception

isXIncludeElement

private boolean isXIncludeElement(org.jdom.Element element)
Check whether this element is an include element.

Parameters:
element - element to check
Returns:
true if this element is an include element

resolveChildren

private void resolveChildren(org.jdom.Element parent)
                      throws java.lang.Exception
Resolve children XML elements.

Parameters:
parent - parent XML element
Throws:
java.lang.Exception

include

private java.util.List<org.jdom.Content> include(org.jdom.Element xinclude)
                                          throws java.lang.Exception
Performs the real include.

Parameters:
xinclude - xinclude element
Returns:
included content
Throws:
java.lang.Exception

readStream

private java.lang.String readStream(java.io.InputStream stream)
                             throws java.lang.Exception
Read a stream in a string.

Parameters:
stream - stream
Returns:
accumulated string
Throws:
java.lang.Exception


~ooOoo~