|
SMILA 1.0 API documentation | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.eclipse.smila.utils.xml.XMLUtils
public abstract class XMLUtils
All parse() methods must be given a wellformatted XML rescource, in which the encoding is set
forth, since none of them recieves such an parameter. If no encoding is specified in the XML recource, UTF-8 is
assumed as set forth by the W3C recommendation.
For all stream() methods without the encoding-paramter the default encoding UTF-8 is assumed (W3C
Recommendation?).
| Method Summary | |
|---|---|
static void |
clearGrammarCache()
Clear grammar cache. |
static boolean |
decodeBoolean(java.lang.String xmlBoolean)
Decodes a Boolean. |
static java.util.Date |
decodeDate(java.lang.String xmlDate)
Decodes a Date. |
static java.util.Date |
decodeDateTime(java.lang.String xmlDate)
Decodes a DateTime. |
static int |
decodeInteger(java.lang.String xmlInteger)
Decodes an Integer. |
static byte[] |
documentToBytes(org.w3c.dom.Document document)
Converts a Document into a byte[]. |
static java.lang.String |
documentToString(org.w3c.dom.Document document)
Converts a Document to a String. |
static java.lang.String |
encodeBoolean(boolean javaBoolean)
Encodes a boolean. |
static java.lang.String |
encodeDate(java.util.Date javaDate)
Encodes a date. |
static java.lang.String |
encodeDateTime(java.util.Date javaDate)
Encodes a DateTime. |
static java.lang.String |
encodeInteger(int value)
Encodes and Integer. |
static java.lang.String |
encodeInteger(java.lang.Integer value)
Encodes and Integer. |
static java.lang.String |
generateGUID(java.lang.Object o)
A 32 byte GUID generator (Globally Unique ID). |
static org.w3c.dom.Document |
getDocument()
Returns an empty document whose document element is not set ! The type of the document is by default an XML-Document. |
static org.w3c.dom.Document |
getDocument(java.lang.String docElement)
Creates a document with a new document element with it's name set to the given text. |
static java.lang.String |
getLocalPart(java.lang.String xml)
This method converts a given XML attribute or element name to a local representation by stripping it of its namespace prefix. |
static boolean |
isXML(byte[] message)
Checks if the given byte[] is XML. |
static boolean |
isXML(java.io.File file)
Checks if the given file is XML. |
static boolean |
isXML(java.io.InputStream is)
Checks if the given InputStream is XML. |
static void |
loadSchema(java.lang.String schemaName,
BundleContext context)
|
static void |
loadSchemas(java.io.File folder,
java.lang.String filter,
java.lang.String schemaUrlPrefix)
Load schemas. |
static org.w3c.dom.Document |
newDocument()
Creates a new Document. |
static org.w3c.dom.Document |
parse(byte[] bytes,
boolean validate)
Shorthand for parse(bytes, new XMLUtilsConfig(validate,true)). |
static org.w3c.dom.Document |
parse(byte[] bytes,
XMLUtilsConfig cfg)
Parses a document from the given byte-array.The applied encoding must be declared within the XML-document-instance or otherwise UTF-8 is assumed according to the W3C recommendation. |
static org.w3c.dom.Document |
parse(java.io.File file,
boolean validate)
Shorthand for parse(file, new XMLUtilsConfig(validate,true)). |
static org.w3c.dom.Document |
parse(java.io.File file,
XMLUtilsConfig cfg)
Parses a document from the given File. |
static org.w3c.dom.Document |
parse(java.io.InputStream is,
boolean validate)
Shorthand for parse(is , new XMLUtilsConfig(validate,true)). |
static org.w3c.dom.Document |
parse(java.io.InputStream is,
XMLUtilsConfig cfg)
Parses a document from the given InputStream. |
static void |
removeWhitespaceTextNodes(org.w3c.dom.Element parent)
Traverses through a DOM tree starting at the given element and removes all those text-nodes from it that only contain white spaces. |
static void |
setGrammarCacheLock(boolean lockState)
Sets the grammar cache lock. |
static byte[] |
stream(org.w3c.dom.Element el,
boolean validate)
Shorthand for stream(el , validate, "UTF-8")). |
static byte[] |
stream(org.w3c.dom.Element el,
boolean validate,
boolean preserveSpace)
Shorthand for stream(el , validate,
"UTF-8")). |
static byte[] |
stream(org.w3c.dom.Element el,
boolean validate,
java.lang.String enc,
boolean preserveSpace)
Streams the given DOM-(Sub)tree starting at the given Element into the returned byte-array. |
static void |
stream(org.w3c.dom.Element el,
boolean validate,
java.lang.String enc,
java.io.File file)
Streams the given DOM-(Sub)tree starting at the given Element into the given File. |
static void |
stream(org.w3c.dom.Element el,
boolean validate,
java.lang.String enc,
java.io.OutputStream os)
Streams the given DOM-(Sub)tree starting at the given Element into the returned byte-array. |
static boolean |
validate(org.w3c.dom.Element el)
Validates the given element and it's decendants against the XML-Schema as specified in the given element. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static org.w3c.dom.Document newDocument()
throws XMLUtilsException
XMLUtilsException - if any error occurs
public static java.lang.String documentToString(org.w3c.dom.Document document)
throws XMLUtilsException
document - the Document to convert
XMLUtilsException - if any error occurs
public static byte[] documentToBytes(org.w3c.dom.Document document)
throws XMLUtilsException
document - the Document
XMLUtilsException - if any error occurs
public static java.util.Date decodeDate(java.lang.String xmlDate)
throws java.text.ParseException
xmlDate - the xmlDate
java.text.ParseException - if any error occurspublic static java.lang.String encodeDate(java.util.Date javaDate)
javaDate - a Date
public static java.util.Date decodeDateTime(java.lang.String xmlDate)
throws java.text.ParseException
xmlDate - the xmlDate
java.text.ParseException - if any error occurspublic static java.lang.String encodeDateTime(java.util.Date javaDate)
javaDate - a date
public static boolean decodeBoolean(java.lang.String xmlBoolean)
xmlBoolean - the xmlBoolean
public static java.lang.String encodeBoolean(boolean javaBoolean)
javaBoolean - a boolean
public static int decodeInteger(java.lang.String xmlInteger)
xmlInteger - the xmlInteger
public static java.lang.String encodeInteger(int value)
value - a int
public static java.lang.String encodeInteger(java.lang.Integer value)
value - Integer
public static final java.lang.String generateGUID(java.lang.Object o)
o - a Object
public static org.w3c.dom.Document getDocument()
public static org.w3c.dom.Document getDocument(java.lang.String docElement)
docElement - a docElement
public static java.lang.String getLocalPart(java.lang.String xml)
xml - the xml
public static boolean isXML(java.io.File file)
file - a File
public static boolean isXML(byte[] message)
message - a byte[]
public static boolean isXML(java.io.InputStream is)
is - a InputStream
public static void loadSchema(java.lang.String schemaName,
BundleContext context)
throws XMLUtilsException
schemaName - Schema name.
XMLUtilsException - Unable to resolve schema.
public static void loadSchemas(java.io.File folder,
java.lang.String filter,
java.lang.String schemaUrlPrefix)
throws XMLUtilsException
folder - the folderfilter - the filterschemaUrlPrefix - the schemaUrlPrefix
XMLUtilsException - if any error occurspublic static void clearGrammarCache()
public static void setGrammarCacheLock(boolean lockState)
lockState - boolean flag
public static org.w3c.dom.Document parse(byte[] bytes,
boolean validate)
throws XMLUtilsException
parse(bytes, new XMLUtilsConfig(validate,true)).
bytes - a byte[]validate - boolean flag
XMLUtilsException - if any error occurs
public static org.w3c.dom.Document parse(byte[] bytes,
XMLUtilsConfig cfg)
throws XMLUtilsException
bytes - a byte[]cfg - a XMLUtilsConfig
XMLUtilsException - if cgf contains invalid values or parsing results in an error.
public static org.w3c.dom.Document parse(java.io.File file,
boolean validate)
throws XMLUtilsException
parse(file, new XMLUtilsConfig(validate,true)).
file - a Filevalidate - boolean flag
XMLUtilsException - if any error occurs
public static org.w3c.dom.Document parse(java.io.File file,
XMLUtilsConfig cfg)
throws XMLUtilsException
file - a Filecfg - the XMLUtilsConfig
XMLUtilsException - if the File dosn't point to a valid location, cgf contains invalid values, or parsing results in an
error.
public static org.w3c.dom.Document parse(java.io.InputStream is,
boolean validate)
throws XMLUtilsException
parse(is , new XMLUtilsConfig(validate,true)).
is - a InputStreamvalidate - boolean flag
XMLUtilsException - if any error occurs
public static org.w3c.dom.Document parse(java.io.InputStream is,
XMLUtilsConfig cfg)
throws XMLUtilsException
is - a InputStreamcfg - the XMLUtilsConfig
XMLUtilsException - if cfg contains invalid values or parsing results in an error.public static void removeWhitespaceTextNodes(org.w3c.dom.Element parent)
parent - the parent Element
public static byte[] stream(org.w3c.dom.Element el,
boolean validate)
throws XMLUtilsException
stream(el , validate, "UTF-8")).
el - a Elementvalidate - boolean flag
XMLUtilsException - if any exception occurs
public static byte[] stream(org.w3c.dom.Element el,
boolean validate,
boolean preserveSpace)
throws XMLUtilsException
stream(el , validate,
"UTF-8")).
el - a Elementvalidate - boolean flagpreserveSpace - boolean flag
XMLUtilsException - if any exception occurs
public static byte[] stream(org.w3c.dom.Element el,
boolean validate,
java.lang.String enc,
boolean preserveSpace)
throws XMLUtilsException
el - a Elementvalidate - whether the given DOM-(sub)tree shall be validated against an XML-Schema that is referenced in the given
element.enc - the encoding that shall be applied. The given String must conform to the encodings as set forth by the W3C
and are somewhat different to that of Java.preserveSpace - boolean flag
XMLUtilsException - if any exception occurs
public static void stream(org.w3c.dom.Element el,
boolean validate,
java.lang.String enc,
java.io.File file)
throws XMLUtilsException
el - a Elementenc - the encoding that shall be applied. The given String must conform to the encodings as set forth by the W3C
and are somewhat different to that of Java.validate - whether the given DOM-(sub)tree shall be validated against an XML-Schema that is referenced in the given
element.file - if it exist it will be overwritten otherwise created. If access rights are violated an XMLUtilsExcpetion
is thrown.
XMLUtilsException - if any error occurs
public static void stream(org.w3c.dom.Element el,
boolean validate,
java.lang.String enc,
java.io.OutputStream os)
throws XMLUtilsException
el - a Elementenc - the encoding that shall be applied. The given String must conform to the encodings as set forth by the W3C
and are somewhat different to that of Java.validate - whether the given DOM-(sub)tree shall be validated against an XML-Schema that is referenced in the given
element.os - a OutputStream
XMLUtilsException - if any error occurs
public static boolean validate(org.w3c.dom.Element el)
throws XMLUtilsException
Unless someone finds a way to validate a life DOM-Tree against a given schema, the quickest way to do this is to, write the damn thing into an ByteArrayOutputStream and to read from that again, and while reading it perform a validation.
el - a Element
XMLUtilsException - if any error occurs
|
SMILA 1.0 API documentation | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||