org.mycore.common.xml
Class MCRXMLResource

java.lang.Object
  extended by org.mycore.common.xml.MCRXMLResource

public class MCRXMLResource
extends Object

provides a cache for reading XML resources. Cache size can be configured by property MCR.MCRXMLResouce.Cache.Size which defaults to 100.

Author:
Thomas Scheffler (yagee)

Method Summary
 boolean exists(String name, ClassLoader classLoader)
           
 long getLastModified(String name, ClassLoader classLoader)
           
 byte[] getRawResource(String name)
          returns xml as byte array using ClassLoader of MCRXMLResource class
 byte[] getRawResource(String name, ClassLoader classLoader)
          Returns raw XML resource as byte array.
 Document getResource(String name)
          Returns JDOM Document using ClassLoader of MCRXMLResource class
 Document getResource(String name, ClassLoader classLoader)
          Returns parsed XML resource as JDOM Document.
static MCRXMLResource instance()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static MCRXMLResource instance()
Returns:
singleton instance

getResource

public Document getResource(String name)
                     throws IOException,
                            JDOMException
Returns JDOM Document using ClassLoader of MCRXMLResource class

Parameters:
name - resource name
Throws:
IOException
JDOMException
See Also:
getResource(String, ClassLoader)

getRawResource

public byte[] getRawResource(String name)
                      throws IOException
returns xml as byte array using ClassLoader of MCRXMLResource class

Parameters:
name - resource name
Throws:
IOException
See Also:
getRawResource(String, ClassLoader)

getResource

public Document getResource(String name,
                            ClassLoader classLoader)
                     throws IOException,
                            JDOMException
Returns parsed XML resource as JDOM Document. A cache is used to avoid reparsing if the source of the resource did not change.

Parameters:
name - the resource name
classLoader - a ClassLoader that should be used to locate the resource
Returns:
a parsed Document of the resource or null if the resource is not found
Throws:
IOException - if resource cannot be loaded
JDOMException - if resource cannot be parsed

getRawResource

public byte[] getRawResource(String name,
                             ClassLoader classLoader)
                      throws IOException
Returns raw XML resource as byte array. Note that no cache will be used.

Parameters:
name - the resource name
classLoader - a ClassLoader that should be used to locate the resource
Returns:
unparsed xml of the resource or null if the resource is not found
Throws:
IOException - if resource cannot be loaded

getLastModified

public long getLastModified(String name,
                            ClassLoader classLoader)
                     throws IOException
Throws:
IOException

exists

public boolean exists(String name,
                      ClassLoader classLoader)
               throws IOException
Throws:
IOException