Package org.cip4.jdflib.core
Class XMLDoc
java.lang.Object
org.cip4.jdflib.core.XMLDoc
- All Implemented Interfaces:
Cloneable,IStreamWriter
- Direct Known Subclasses:
JDFDoc
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappendChild(Node newChild) append a new child node to 'this'clone()clone the document, completely severing all connections to the original documentcloneNode(boolean deep) get a copy of 'this'voidcopy metadata from other documentcreateAttribute(String name) createAttribute in namespace JDFCoreConstants.NONAMESPACE (DOM Level 2)createAttributeNS(String namespaceURI, String qualifiedName) create an attribute withe the given name in the given namespacecreateCDATASection(String data) create a CDATA section, which has this document as ownerDoccreateComment(String data) createCommentcreateDocumentFragmentcreateDocumentType(String qualifiedName, String publicID, String systemID) createDocumentTypecreateElement(String elementName) createElement create a JDFElement that floats in nirvana.org.apache.xerces.dom.ElementDefinitionImplcreates an element definition.createElementNS(String namespaceURI, String qualifiedName) create a Element that floats in nirvana, this must be appended to a node with appendChildcreateEntity(String name) create an entitycreateEntityReference(String name) creates an EntityReferencecreateEvent(String type) create an Event objectcreateNodeIterator(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion) createNodeIteratorcreateNodeIterator(Node root, short whatToShow, NodeFilter filter) create a node iteratorcreateNotation(String name) creates a Notation having this Document as its OwnerDoccreateProcessingInstruction(String target, String data) creates a ProcessingInstruction having this Document as ownerDoccreateRangeprotected XMLDoccreateRoot(Document document) createTextNode(String data) createTextNodecreateTreeWalker(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion) creates a TreeWalkercreateTreeWalker(Node root, short whatToShow, NodeFilter filter) creates a TreeWalkerbooleanprotected booleanflush()Method Flush
clean the m_doc and restart from scratch.get the attributes associated with this nodejavax.mail.BodyPartget the Javax.Mail.BodyPartprotected NodegetChildNode(int nodeType, int iPos) gets the n'th child node of nodetypenodeTypewith n = iPosget the child nodes of this nodelongrough guestimate of the memory used by this if called after parsinggetDoctypegetDocumentElementgetElementById(String elementId) get element with ID = elementId similar to Docoment.getElementByID but works with non schema parsed documentsgetElementsByTagName(String tagname) return a NodeList of all elements having the specified tagnamegetElementsByTagNameNS(String namespaceURI, String myLocalName) get a NodeList of all elements with a given name and namespace URIbooleandoes the DOM implementation perform error checking upon operations?get the first child node of 'this'getIdentifier(String idName) gets the element with the registered name = "idName"Enumeration<?>gets the registered identifiersprotected DocumentXMLImplgetImpl()getImplementationstatic intget the last child node of 'this'static intget the the local part of the qualified name of 'this'getMemberDocumentjavax.mail.Multipartget the Javax.Mail.Multipartget the next sibling of 'this'gets the node nameshortget node typegets the node valuegetNSMap()get a copy of the nsmapget the parent node of 'this' nodeget the namespace prefix of 'this' nodeget the previous sibling of 'this'getProcessingInstruction(int skip, String name) getRoot()get the root of the dom treegetSchemaLocation(String nsURI) getSchemaLocationFile(String nsURI) gets of 'this' the text of the i-th child XMLComment.protected XMLParsergets the url for an xslt stylesheet eget the ZipReaderbooleancheck if 'this' has attributesbooleantest if 'this' has any childreninthashCode()importNode(Node importedNode, boolean deep) copy a node from another document in this documentinsertBefore(Node newChild, Node refChild) insert a new node before a given nodebooleanisDirty()check whether the underlying document is nullbooleanisNull()check whether the underlying document is nullbooleanbooleanisSupported(String feature, String version) test whether a specific DOMImplelementation feature is supported by 'this'voidnormalizestatic XMLDocparse an XML filestatic XMLDocparse an XML filestatic XMLDocparse a JDF input streamstatic XMLDocparseString(String string) parse an XML filestatic XMLDocparse a given urlstatic XMLDocparseZipFile(File file) parse an XML fileprotected voidpushParser(XMLParser xmlParser) voidputIdentifier(String idName, Element element) Registers an identifier name with a specified element noderemoveChild(Node oldChild) remove a child from 'this'voidremoveIdentifier(String idName) remove element with identifier "idName"replaceChild(Node newChild, Node oldChild) replace a child node with a new onevoidsetBodyPart(javax.mail.BodyPart bodyPart) set the Javax.Mail.BodyPartvoidsetErrorChecking(boolean check) sets whether the DOM implementation performs error checking upon operationsstatic voidsetIndent(int indent) static voidsetLineWidth(int lineWidth) protected voidsetMemberDoc(DocumentXMLImpl myDoc) voidsetNodeValue(String nodeValue) set the node valuevoidset the namespace map from another documentvoidsetOriginalFileName(String originalFileName) voidset the namespace prefix of 'this' nodeinitialize a new root of strDocType in the document called by constructor XMLDoc(String strDocType)voidsetSchemaLocation(String nsURI, File _schemaLocation) set xs:schemalocation tovoidsetValidationResult(XMLDoc validationResult) voidsetXPathValues(JDFAttributeMap valueMap) set the xpath values of thei to the values in the nodevoidsetXSLTURL(String url) sets the processing instruction for an xslt stylesheetvoidsetZipReader(ZipReader zip) set the ZipReadertoString()toStringtoXML()toXMLbooleanwrite2File(File oFilePath) write2File - write to a file; Create if it doesn't exist always assume utf-8 encodingbooleanwrite2File(File file, int indent, boolean bPreserveSpace) write2File - write to a file; Create if it doesn't existbooleanwrite2File(String oFilePath) write2File - write to a file; Create if it doesn't exist always assume utf-8 encodingbooleanwrite2File(String oFilePath, int indent) Deprecated.060419 use write2File(oFilePath, indent, true);booleanwrite2File(String oFilePath, int indent, boolean bPreserveSpace) write2File - write to a file; Create if it doesn't exist DO NOT attempt any url escaping voodoo @see write2URLwrite2HttpURL(URL url, String strContentType, HTTPDetails det) write2HTTPURL(URL url, String strContentType, HTTPDetails det) voidwrite2Stream(OutputStream outStream, int indent) voidwrite2Stream(OutputStream outStream, int indent, boolean bPreserveSpace) write this to a streamstatic voidwrite2StreamStatic(Element elem, OutputStream outStream, int indent) Deprecated.060306static voidwrite2StreamStatic(Element elem, OutputStream outStream, int indent, boolean bPreserveSpace) Deprecated.060306write2String(int indent) write2String - write to a string;This method sends the contents of this XMLDoc to the URLstrURLand receives the response in the returned XMLDoc.write2URL(String strURL, String strContentType, HTTPDetails details) This method sends the contents of this XMLDoc to the URLstrURLand receives the response in the returned XMLDoc.write2Zip - write to a file and compress as zip; remove the .zip from the extension in the zip entry or add .zipvoidwriteStream(OutputStream stream) write myself to a stream
-
Field Details
-
m_doc
-
-
Constructor Details
-
XMLDoc
public XMLDoc()constructor -
XMLDoc
constructor- Parameters:
document-
-
XMLDoc
constructor- Parameters:
document-
-
XMLDoc
constructor- Parameters:
other-
-
XMLDoc
convenience constructor- Parameters:
strDocType- ElementName.JDF, ElementName.JMF, "Config" ...
-
XMLDoc
constructor- Parameters:
strDocType- ElementName.JDF, ElementName.JMF, "Config" ...namespaceURI- namespace to be used by the new XMLDoc
-
-
Method Details
-
getIndent
public static int getIndent() -
setIndent
public static void setIndent(int indent) -
getLineWidth
public static int getLineWidth() -
setLineWidth
public static void setLineWidth(int lineWidth) -
equals
-
hashCode
public int hashCode() -
createRoot
-
getImpl
-
setRoot
initialize a new root of strDocType in the document called by constructor XMLDoc(String strDocType)- Parameters:
strDocType- qualified tag name of the doc root to create if still emptynamespaceURI- namespace URI of the doc root- Returns:
- JDFElement - the root element
-
getMemberDocument
getMemberDocument- Returns:
- the MemberDocument
-
flush
protected boolean flush()Method Flush
clean the m_doc and restart from scratch. The root element remains- Returns:
- boolean - true if successful
-
getRoot
get the root of the dom tree- Returns:
- JDFElement default: getRoot()
-
write2String
write2String - write to a string;- Parameters:
indent- the indentation of the xml- Returns:
- String - output
-
write2File
Deprecated.060419 use write2File(oFilePath, indent, true);write2File - write to a file; Create if it doesn't exist always assume utf-8 encoding- Parameters:
oFilePath-indent-- Returns:
- boolean
-
write2File
write2File - write to a file; Create if it doesn't exist always assume utf-8 encoding- Parameters:
oFilePath-indent-- Returns:
- boolean
-
write2File
write2File - write to a file; Create if it doesn't exist always assume utf-8 encoding- Parameters:
oFilePath-indent-- Returns:
- boolean
-
write2Zip
write2Zip - write to a file and compress as zip; remove the .zip from the extension in the zip entry or add .zip- Parameters:
file-- Returns:
- the created file
-
write2File
write2File - write to a file; Create if it doesn't exist DO NOT attempt any url escaping voodoo @see write2URL- Parameters:
oFilePath- the file path where to write the fileindent- indentationbPreserveSpace- if true, preserve whitespace- Returns:
- boolean - true if successful
-
write2File
write2File - write to a file; Create if it doesn't exist- Parameters:
file- the file to write toindent- indentationbPreserveSpace- if true, preserve whitespace- Returns:
- boolean - true if successful
-
getRootName
-
write2Stream
- Parameters:
outStream-indent-- Throws:
IOException
-
writeStream
Description copied from interface:IStreamWriterwrite myself to a stream- Specified by:
writeStreamin interfaceIStreamWriter- Parameters:
stream- the output stream- Throws:
IOException- if io snafu...
-
write2Stream
public void write2Stream(OutputStream outStream, int indent, boolean bPreserveSpace) throws IOException write this to a stream- Parameters:
outStream-indent-bPreserveSpace-- Throws:
IOException- Since:
- 080425 synchronized
-
write2StreamStatic
@Deprecated public static void write2StreamStatic(Element elem, OutputStream outStream, int indent) throws IOException Deprecated.060306- Parameters:
elem-outStream-indent-- Throws:
IOException
-
write2StreamStatic
@Deprecated public static void write2StreamStatic(Element elem, OutputStream outStream, int indent, boolean bPreserveSpace) throws IOException Deprecated.060306- Parameters:
elem-outStream-indent-bPreserveSpace-- Throws:
IOException
-
getDoctype
getDoctype- Returns:
- DocumentType
-
getImplementation
getImplementation- Returns:
- DOMImplementation
-
getDocumentElement
getDocumentElement- Returns:
- Element
-
createElement
createElement create a JDFElement that floats in nirvana. This must be appended to a node with appendChild (created in namespace JDFCoreConstants.NONAMESPACE (DOM Level 2)).
Another way would be to use KElement.appendElement(String elementName, String nameSpaceURI)- Parameters:
elementName- name of the element that is created- Returns:
- Element - unconnected element that is created
-
createDocumentFragment
createDocumentFragment- Returns:
- DocumentFragment
-
createTextNode
createTextNode- Parameters:
data-- Returns:
- Text
-
createComment
createComment- Parameters:
data-- Returns:
- Comment
-
createCDATASection
create a CDATA section, which has this document as ownerDoc- Parameters:
data- content of the CDATA- Returns:
- CDATASection
-
setXSLTURL
sets the processing instruction for an xslt stylesheet- Parameters:
url- the url of the xslt file
-
getXSLTURL
gets the url for an xslt stylesheet e -
setXPathValues
set the xpath values of thei to the values in the node- Parameters:
valueMap- the map of values, if this is still null, MUST be fully qualified
-
createProcessingInstruction
creates a ProcessingInstruction having this Document as ownerDoc- Parameters:
target- the target "processor channel"data- parameter string to be passed to the target- Returns:
- ProcessingInstruction
-
getProcessingInstruction
- Parameters:
skip-name-- Returns:
-
getNode
- Parameters:
type- the node type seeDocumentskip- the number onodes to skip- Returns:
-
createAttribute
createAttribute in namespace JDFCoreConstants.NONAMESPACE (DOM Level 2)- Parameters:
name- attribute name- Returns:
- Attr
-
createEntityReference
creates an EntityReference- Parameters:
name- name of the entity to refer to- Returns:
- the newly created EntityReference
-
getElementsByTagName
return a NodeList of all elements having the specified tagname- Parameters:
tagname- tag name of the elements to find (JDFCoreConstants.star for all elements)- Returns:
- NodeList
-
importNode
copy a node from another document in this document- Parameters:
importedNode- node to importdeep- if true: recurse and import the subtree under the node as well- Returns:
- Node
-
createElementNS
create a Element that floats in nirvana, this must be appended to a node with appendChild- Parameters:
namespaceURI- the namespace uri of the created elementqualifiedName- name of the element that is created- Returns:
- Element - unconnected element that is created
-
createAttributeNS
create an attribute withe the given name in the given namespace- Parameters:
namespaceURI- namespace URI of the attributequalifiedName- qualified name of the attribute- Returns:
- Attr - the newly created attribute
-
getElementsByTagNameNS
get a NodeList of all elements with a given name and namespace URI- Parameters:
namespaceURI- the namespace URI to look formyLocalName- the element name to look for- Returns:
- NodeList with all elements found
-
getElementById
get element with ID = elementId similar to Docoment.getElementByID but works with non schema parsed documents- Parameters:
elementId- the element ID to look for- Returns:
- the Element found
-
getNodeName
gets the node name- Returns:
- String
-
getNodeValue
gets the node value- Returns:
- String
-
setNodeValue
set the node value- Parameters:
nodeValue- value to set the node to
-
setNSMap
set the namespace map from another document- Parameters:
other- value to set the node to
-
getNSMap
get a copy of the nsmap -
getNodeType
public short getNodeType()get node type- Returns:
- a short representing the node type
-
getParentNode
get the parent node of 'this' node- Returns:
- the parent node
-
getChildNodes
get the child nodes of this node- Returns:
- a NodeList containing the child nodes
-
getFirstChild
get the first child node of 'this'- Returns:
- the first child node
-
getLastChild
get the last child node of 'this'- Returns:
- the last child node
-
getPreviousSibling
get the previous sibling of 'this'- Returns:
- the previous sibling node
-
getNextSibling
get the next sibling of 'this'- Returns:
- the next sibling node
-
getAttributes
get the attributes associated with this node- Returns:
- NamedNodeMap containing the attributes associated with this node
-
insertBefore
insert a new node before a given node- Parameters:
newChild- the new child node to insertrefChild- the ref child node, the new node is inserted before it- Returns:
- Node
-
replaceChild
replace a child node with a new one- Parameters:
newChild- the new child node to addoldChild- the old child node to be replaced- Returns:
- Node
-
removeChild
remove a child from 'this'- Parameters:
oldChild- the child node to be removed- Returns:
- oldChild, in its new state (removed)
-
appendChild
append a new child node to 'this'- Parameters:
newChild- new child node to add- Returns:
- Node
-
hasChildNodes
public boolean hasChildNodes()test if 'this' has any children- Returns:
- boolean - true, if 'this' has children
-
cloneNode
get a copy of 'this'- Parameters:
deep- true: copy children as well- Returns:
- Node - a copy of 'this'
-
normalize
public void normalize()normalize -
isSupported
test whether a specific DOMImplelementation feature is supported by 'this'- Parameters:
feature- package name of the feature to testversion- version number of the package name to test- Returns:
- boolean - true, if the feature is sopported
- See Also:
-
- invalid input: '<a href="http://xerces.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/NodeImpl.html#isSupported(java.lang.String,%20java.lang.String)" <a>Xerxes-Documentation</a>'
-
getPrefix
get the namespace prefix of 'this' node- Returns:
- String - namespace prefix (null if unspecified)
-
setPrefix
set the namespace prefix of 'this' node- Parameters:
prefix- namespace prefix
-
getLocalName
get the the local part of the qualified name of 'this'- Returns:
- String - local name
-
isNull
public boolean isNull()check whether the underlying document is null- Returns:
- true if m_doc==null
-
isDirty
public boolean isDirty()check whether the underlying document is null- Returns:
- true if m_doc==null
-
hasAttributes
public boolean hasAttributes()check if 'this' has attributes- Returns:
- true, if 'this' has attributes
-
createDocumentType
createDocumentType- Parameters:
qualifiedName-publicID-systemID-- Returns:
- DocumentType
-
setErrorChecking
public void setErrorChecking(boolean check) sets whether the DOM implementation performs error checking upon operations- Parameters:
check- true - enable error checking
-
getErrorChecking
public boolean getErrorChecking()does the DOM implementation perform error checking upon operations?- Returns:
- true - error checking is enabled, otherwise false
-
createEntity
create an entity- Parameters:
name- name of the entity- Returns:
- Entity - the newly created entity
-
createNotation
creates a Notation having this Document as its OwnerDoc- Parameters:
name- name of the notation- Returns:
- Notation - the newly created notation
-
createElementDefinition
creates an element definition. Element definitions hold default attribute values.- Parameters:
name-- Returns:
- ElementDefinitionImpl
-
putIdentifier
Registers an identifier name with a specified element node- Parameters:
idName-element-
-
getIdentifier
gets the element with the registered name = "idName"- Parameters:
idName- name of the element to get- Returns:
- Element - the element with "idName"
-
removeIdentifier
remove element with identifier "idName"- Parameters:
idName-
-
getIdentifiers
gets the registered identifiers- Returns:
- Enumeration of registered identifiers
-
createNodeIterator
create a node iterator- Parameters:
root- the root of the iteratorwhatToShow- the whatToShow maskfilter- the node filter (null = no filter)- Returns:
- the newly created NodeIterator
-
createNodeIterator
public NodeIterator createNodeIterator(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion) createNodeIterator- Parameters:
root- the root of the iteratorwhatToShow- the whatToShow maskfilter- the node filter (null = no filter)entityReferenceExpansion- true: expand the contents of EntityReference nodes- Returns:
- the newly created NodeIterator
-
createTreeWalker
creates a TreeWalker- Parameters:
root- the root of the iteratorwhatToShow- the whatToShow maskfilter- the node filter (null = no filter)- Returns:
- the newly created TreeWalker
-
createTreeWalker
public TreeWalker createTreeWalker(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion) creates a TreeWalker- Parameters:
root- the root of the iteratorwhatToShow- the whatToShow maskfilter- the node filter (null = no filter)entityReferenceExpansion- true: expand the contents of EntityReference nodes- Returns:
- the newly created TreeWalker
-
createRange
createRange- Returns:
- Range
-
createEvent
create an Event object- Parameters:
type- type of Event interface to be created- Returns:
- the newly created Event
-
clone
clone the document, completely severing all connections to the original document -
toString
toString -
toXML
toXML- Returns:
- String
-
setMemberDoc
-
write2URL
This method sends the contents of this XMLDoc to the URLstrURLand receives the response in the returned XMLDoc.- Parameters:
strURL- the URL to write tostrContentType- the content type to write to- Returns:
- docResponse the response received from URL. if url is a file, an empty doc is returned A Null document if no response was received, or an exception occurred
-
write2URL
This method sends the contents of this XMLDoc to the URLstrURLand receives the response in the returned XMLDoc.- Parameters:
strURL- the URL to write tostrContentType- the content type to write to- Returns:
- docResponse the response received from URL. if url is a file, an empty doc is returned A Null document if no response was received, or an exception occurred
-
pushParser
- Parameters:
xmlParser-
-
getChildNode
gets the n'th child node of nodetypenodeTypewith n = iPos- Parameters:
nodeType- the DOM node type to get- copy from KElement -
- ELEMENT_NODE = 1
- ATTRIBUTE_NODE = 2
- TEXT_NODE = 3
- CDATA_SECTION_NODE = 4
- ENTITY_REFERENCE_NODE = 5
- ENTITY_NODE = 6
- PROCESSING_INSTRUCTION_NODE = 7
- COMMENT_NODE = 8
- DOCUMENT_NODE = 9
- DOCUMENT_TYPE_NODE = 10
- DOCUMENT_FRAGMENT_NODE = 11
- NOTATION_NODE = 12
- XML_DECL_NODE = 13
iPos- the index of the node with default 0 for the first occurance- Returns:
- KElement: a node that matches the filter, null if iPos is higher then the number of child nodes
-
-
getXMLComment
gets of 'this' the text of the i-th child XMLComment.would returnthis is a XMLComment- Returns:
- String text document XMLComment, null if i is higher then the number of child nodes
-
getXMLParser
- Returns:
-
getValidationResult
- Returns:
- Returns the validation result.
-
isSchemaValid
public boolean isSchemaValid()- Returns:
- Returns the m_OriginalFileName.
-
write2HTTPURL
- Parameters:
url- the url to write tostrContentType- the content type; if null use text/xmldet- the details to set- Returns:
- the HttpURLConnection, null if failure
-
write2HttpURL
- Parameters:
url- the url to write tostrContentType- the content type; if null use text/xmldet- the details to set- Returns:
- the HttpURLConnection, null if failure
-
getDocMemoryUsed
public long getDocMemoryUsed()rough guestimate of the memory used by this if called after parsing- Returns:
- the difference of memory used when calling compared to construction time
-
getBodyPart
public javax.mail.BodyPart getBodyPart()get the Javax.Mail.BodyPart- Returns:
- the BodyPart
-
getMultiPart
public javax.mail.Multipart getMultiPart()get the Javax.Mail.Multipart- Returns:
- the Multipart
-
setBodyPart
public void setBodyPart(javax.mail.BodyPart bodyPart) set the Javax.Mail.BodyPart- Parameters:
bodyPart- the value to set
-
setZipReader
set the ZipReader- Parameters:
zip- the value to set
-
getZipReader
get the ZipReader- Returns:
- zip the value to set
-
getOriginalFileName
- Returns:
- Returns the m_OriginalFileName.
-
setOriginalFileName
- Parameters:
originalFileName- The OriginalFileName to set.
-
getSchemaLocation
- Parameters:
nsURI- the namespace uri to get the schema location for- Returns:
- String that corresponds to the schema, null if no schemalocation is defined for nsURI
-
getSchemaLocationFile
- Parameters:
nsURI- the namespace uri to get the schema location for- Returns:
- File that corresponds to the schema, null if no readable file is found
-
setSchemaLocation
set xs:schemalocation to- Parameters:
nsURI-_schemaLocation-
-
setValidationResult
- Parameters:
validationResult- the validationResult to set.
-
parseStream
parse a JDF input stream- Parameters:
is-- Returns:
- the parsed JDFDoc
-
parseFile
parse an XML file- Parameters:
fileName-- Returns:
- the parsed JDFDoc
-
parseString
parse an XML file- Parameters:
string-- Returns:
- the parsed JDFDoc
-
parseFile
parse an XML file- Parameters:
file-- Returns:
- the parsed JDFDoc
-
parseZipFile
parse an XML file- Parameters:
file-- Returns:
- the parsed JDFDoc
-
parseURL
parse a given url- Parameters:
url- the url to searchbp- the bodypart that the CID url is located in- Returns:
- the parsed JDFDoc
-
copyMeta
copy metadata from other document- Parameters:
dMine-