Class XMLDoc

java.lang.Object
org.cip4.jdflib.core.XMLDoc
All Implemented Interfaces:
Cloneable, IStreamWriter
Direct Known Subclasses:
JDFDoc

public class XMLDoc extends Object implements Cloneable, IStreamWriter
  • Field Details

  • Constructor Details

    • XMLDoc

      public XMLDoc()
      constructor
    • XMLDoc

      public XMLDoc(Document document)
      constructor
      Parameters:
      document -
    • XMLDoc

      public XMLDoc(DocumentXMLImpl document)
      constructor
      Parameters:
      document -
    • XMLDoc

      public XMLDoc(XMLDoc other)
      constructor
      Parameters:
      other -
    • XMLDoc

      public XMLDoc(String strDocType)
      convenience constructor
      Parameters:
      strDocType - ElementName.JDF, ElementName.JMF, "Config" ...
    • XMLDoc

      public XMLDoc(String strDocType, String namespaceURI)
      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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      See Also:
    • createRoot

      protected XMLDoc createRoot(Document document)
    • getImpl

      protected DocumentXMLImpl getImpl()
    • setRoot

      public KElement setRoot(String strDocType, String namespaceURI)
      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 empty
      namespaceURI - namespace URI of the doc root
      Returns:
      JDFElement - the root element
    • getMemberDocument

      public DocumentXMLImpl 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

      public KElement getRoot()
      get the root of the dom tree
      Returns:
      JDFElement default: getRoot()
    • write2String

      public String write2String(int indent)
      write2String - write to a string;
      Parameters:
      indent - the indentation of the xml
      Returns:
      String - output
    • write2File

      @Deprecated public boolean write2File(String oFilePath, int indent)
      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

      public boolean write2File(String oFilePath)
      write2File - write to a file; Create if it doesn't exist always assume utf-8 encoding
      Parameters:
      oFilePath -
      indent -
      Returns:
      boolean
    • write2File

      public boolean write2File(File oFilePath)
      write2File - write to a file; Create if it doesn't exist always assume utf-8 encoding
      Parameters:
      oFilePath -
      indent -
      Returns:
      boolean
    • write2Zip

      public File write2Zip(File file)
      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

      public boolean write2File(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 write2URL
      Parameters:
      oFilePath - the file path where to write the file
      indent - indentation
      bPreserveSpace - if true, preserve whitespace
      Returns:
      boolean - true if successful
    • write2File

      public boolean write2File(File file, int indent, boolean bPreserveSpace)
      write2File - write to a file; Create if it doesn't exist
      Parameters:
      file - the file to write to
      indent - indentation
      bPreserveSpace - if true, preserve whitespace
      Returns:
      boolean - true if successful
    • getRootName

      public String getRootName()
    • write2Stream

      public void write2Stream(OutputStream outStream, int indent) throws IOException
      Parameters:
      outStream -
      indent -
      Throws:
      IOException
    • writeStream

      public void writeStream(OutputStream stream) throws IOException
      Description copied from interface: IStreamWriter
      write myself to a stream
      Specified by:
      writeStream in interface IStreamWriter
      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

      public DocumentType getDoctype()
      getDoctype
      Returns:
      DocumentType
    • getImplementation

      public DOMImplementation getImplementation()
      getImplementation
      Returns:
      DOMImplementation
    • getDocumentElement

      public Element getDocumentElement()
      getDocumentElement
      Returns:
      Element
    • createElement

      public Element createElement(String elementName)
      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

      public DocumentFragment createDocumentFragment()
      createDocumentFragment
      Returns:
      DocumentFragment
    • createTextNode

      public Text createTextNode(String data)
      createTextNode
      Parameters:
      data -
      Returns:
      Text
    • createComment

      public Comment createComment(String data)
      createComment
      Parameters:
      data -
      Returns:
      Comment
    • createCDATASection

      public CDATASection createCDATASection(String data)
      create a CDATA section, which has this document as ownerDoc
      Parameters:
      data - content of the CDATA
      Returns:
      CDATASection
    • setXSLTURL

      public void setXSLTURL(String url)
      sets the processing instruction for an xslt stylesheet
      Parameters:
      url - the url of the xslt file
    • getXSLTURL

      public String getXSLTURL()
      gets the url for an xslt stylesheet e
    • setXPathValues

      public void setXPathValues(JDFAttributeMap valueMap)
      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

      public ProcessingInstruction createProcessingInstruction(String target, String data)
      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

      public ProcessingInstruction getProcessingInstruction(int skip, String name)
      Parameters:
      skip -
      name -
      Returns:
    • getNode

      public Node getNode(short type, int skip, String nodeName)
      Parameters:
      type - the node type see Document
      skip - the number onodes to skip
      Returns:
    • createAttribute

      public Attr createAttribute(String name)
      createAttribute in namespace JDFCoreConstants.NONAMESPACE (DOM Level 2)
      Parameters:
      name - attribute name
      Returns:
      Attr
    • createEntityReference

      public EntityReference createEntityReference(String name)
      creates an EntityReference
      Parameters:
      name - name of the entity to refer to
      Returns:
      the newly created EntityReference
    • getElementsByTagName

      public NodeList getElementsByTagName(String tagname)
      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

      public Node importNode(Node importedNode, boolean deep)
      copy a node from another document in this document
      Parameters:
      importedNode - node to import
      deep - if true: recurse and import the subtree under the node as well
      Returns:
      Node
    • createElementNS

      public Element createElementNS(String namespaceURI, String qualifiedName)
      create a Element that floats in nirvana, this must be appended to a node with appendChild
      Parameters:
      namespaceURI - the namespace uri of the created element
      qualifiedName - name of the element that is created
      Returns:
      Element - unconnected element that is created
    • createAttributeNS

      public Attr createAttributeNS(String namespaceURI, String qualifiedName)
      create an attribute withe the given name in the given namespace
      Parameters:
      namespaceURI - namespace URI of the attribute
      qualifiedName - qualified name of the attribute
      Returns:
      Attr - the newly created attribute
    • getElementsByTagNameNS

      public NodeList getElementsByTagNameNS(String namespaceURI, String myLocalName)
      get a NodeList of all elements with a given name and namespace URI
      Parameters:
      namespaceURI - the namespace URI to look for
      myLocalName - the element name to look for
      Returns:
      NodeList with all elements found
    • getElementById

      public Element getElementById(String elementId)
      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

      public String getNodeName()
      gets the node name
      Returns:
      String
    • getNodeValue

      public String getNodeValue()
      gets the node value
      Returns:
      String
    • setNodeValue

      public void setNodeValue(String nodeValue)
      set the node value
      Parameters:
      nodeValue - value to set the node to
    • setNSMap

      public void setNSMap(XMLDoc other)
      set the namespace map from another document
      Parameters:
      other - value to set the node to
    • getNSMap

      public JDFAttributeMap getNSMap()
      get a copy of the nsmap
    • getNodeType

      public short getNodeType()
      get node type
      Returns:
      a short representing the node type
    • getParentNode

      public Node getParentNode()
      get the parent node of 'this' node
      Returns:
      the parent node
    • getChildNodes

      public NodeList getChildNodes()
      get the child nodes of this node
      Returns:
      a NodeList containing the child nodes
    • getFirstChild

      public Node getFirstChild()
      get the first child node of 'this'
      Returns:
      the first child node
    • getLastChild

      public Node getLastChild()
      get the last child node of 'this'
      Returns:
      the last child node
    • getPreviousSibling

      public Node getPreviousSibling()
      get the previous sibling of 'this'
      Returns:
      the previous sibling node
    • getNextSibling

      public Node getNextSibling()
      get the next sibling of 'this'
      Returns:
      the next sibling node
    • getAttributes

      public NamedNodeMap getAttributes()
      get the attributes associated with this node
      Returns:
      NamedNodeMap containing the attributes associated with this node
    • insertBefore

      public Node insertBefore(Node newChild, Node refChild)
      insert a new node before a given node
      Parameters:
      newChild - the new child node to insert
      refChild - the ref child node, the new node is inserted before it
      Returns:
      Node
    • replaceChild

      public Node replaceChild(Node newChild, Node oldChild)
      replace a child node with a new one
      Parameters:
      newChild - the new child node to add
      oldChild - the old child node to be replaced
      Returns:
      Node
    • removeChild

      public Node removeChild(Node oldChild)
      remove a child from 'this'
      Parameters:
      oldChild - the child node to be removed
      Returns:
      oldChild, in its new state (removed)
    • appendChild

      public Node appendChild(Node newChild)
      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

      public Node cloneNode(boolean deep)
      get a copy of 'this'
      Parameters:
      deep - true: copy children as well
      Returns:
      Node - a copy of 'this'
    • normalize

      public void normalize()
      normalize
    • isSupported

      public boolean isSupported(String feature, String version)
      test whether a specific DOMImplelementation feature is supported by 'this'
      Parameters:
      feature - package name of the feature to test
      version - 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

      public String getPrefix()
      get the namespace prefix of 'this' node
      Returns:
      String - namespace prefix (null if unspecified)
    • setPrefix

      public void setPrefix(String prefix)
      set the namespace prefix of 'this' node
      Parameters:
      prefix - namespace prefix
    • getLocalName

      public String 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

      public DocumentType createDocumentType(String qualifiedName, String publicID, String systemID)
      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

      public Entity createEntity(String name)
      create an entity
      Parameters:
      name - name of the entity
      Returns:
      Entity - the newly created entity
    • createNotation

      public Notation createNotation(String name)
      creates a Notation having this Document as its OwnerDoc
      Parameters:
      name - name of the notation
      Returns:
      Notation - the newly created notation
    • createElementDefinition

      public org.apache.xerces.dom.ElementDefinitionImpl createElementDefinition(String name)
      creates an element definition. Element definitions hold default attribute values.
      Parameters:
      name -
      Returns:
      ElementDefinitionImpl
    • putIdentifier

      public void putIdentifier(String idName, Element element)
      Registers an identifier name with a specified element node
      Parameters:
      idName -
      element -
    • getIdentifier

      public Element getIdentifier(String idName)
      gets the element with the registered name = "idName"
      Parameters:
      idName - name of the element to get
      Returns:
      Element - the element with "idName"
    • removeIdentifier

      public void removeIdentifier(String idName)
      remove element with identifier "idName"
      Parameters:
      idName -
    • getIdentifiers

      public Enumeration<?> getIdentifiers()
      gets the registered identifiers
      Returns:
      Enumeration of registered identifiers
    • createNodeIterator

      public NodeIterator createNodeIterator(Node root, short whatToShow, NodeFilter filter)
      create a node iterator
      Parameters:
      root - the root of the iterator
      whatToShow - the whatToShow mask
      filter - 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 iterator
      whatToShow - the whatToShow mask
      filter - the node filter (null = no filter)
      entityReferenceExpansion - true: expand the contents of EntityReference nodes
      Returns:
      the newly created NodeIterator
    • createTreeWalker

      public TreeWalker createTreeWalker(Node root, short whatToShow, NodeFilter filter)
      creates a TreeWalker
      Parameters:
      root - the root of the iterator
      whatToShow - the whatToShow mask
      filter - 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 iterator
      whatToShow - the whatToShow mask
      filter - the node filter (null = no filter)
      entityReferenceExpansion - true: expand the contents of EntityReference nodes
      Returns:
      the newly created TreeWalker
    • createRange

      public Range createRange()
      createRange
      Returns:
      Range
    • createEvent

      public Event createEvent(String type)
      create an Event object
      Parameters:
      type - type of Event interface to be created
      Returns:
      the newly created Event
    • clone

      public XMLDoc clone()
      clone the document, completely severing all connections to the original document
      Overrides:
      clone in class Object
      Returns:
      Object
    • toString

      public String toString()
      toString
      Overrides:
      toString in class Object
      Returns:
      String
    • toXML

      public String toXML()
      toXML
      Returns:
      String
    • setMemberDoc

      protected void setMemberDoc(DocumentXMLImpl myDoc)
    • write2URL

      public XMLDoc write2URL(String strURL, String strContentType)
      This method sends the contents of this XMLDoc to the URL strURL and receives the response in the returned XMLDoc.
      Parameters:
      strURL - the URL to write to
      strContentType - 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

      public XMLDoc write2URL(String strURL, String strContentType, HTTPDetails details)
      This method sends the contents of this XMLDoc to the URL strURL and receives the response in the returned XMLDoc.
      Parameters:
      strURL - the URL to write to
      strContentType - 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

      protected void pushParser(XMLParser xmlParser)
      Parameters:
      xmlParser -
    • getChildNode

      protected Node getChildNode(int nodeType, int iPos)
      gets the n'th child node of nodetype nodeType with 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

    public String getXMLComment()
    gets of 'this' the text of the i-th child XMLComment. would return this is a XMLComment
    Returns:
    String text document XMLComment, null if i is higher then the number of child nodes
  • getXMLParser

    protected XMLParser getXMLParser()
    Returns:
  • getValidationResult

    public XMLDoc getValidationResult()
    Returns:
    Returns the validation result.
  • isSchemaValid

    public boolean isSchemaValid()
    Returns:
    Returns the m_OriginalFileName.
  • write2HTTPURL

    public HttpURLConnection write2HTTPURL(URL url, String strContentType, HTTPDetails det)
    Parameters:
    url - the url to write to
    strContentType - the content type; if null use text/xml
    det - the details to set
    Returns:
    the HttpURLConnection, null if failure
  • write2HttpURL

    public UrlPart write2HttpURL(URL url, String strContentType, HTTPDetails det)
    Parameters:
    url - the url to write to
    strContentType - the content type; if null use text/xml
    det - 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 jakarta.mail.BodyPart getBodyPart()
    get the Javax.Mail.BodyPart
    Returns:
    the BodyPart
  • getMultiPart

    public jakarta.mail.Multipart getMultiPart()
    get the Javax.Mail.Multipart
    Returns:
    the Multipart
  • setBodyPart

    public void setBodyPart(jakarta.mail.BodyPart bodyPart)
    set the Javax.Mail.BodyPart
    Parameters:
    bodyPart - the value to set
  • setZipReader

    public void setZipReader(ZipReader zip)
    set the ZipReader
    Parameters:
    zip - the value to set
  • getZipReader

    public ZipReader getZipReader()
    get the ZipReader
    Returns:
    zip the value to set
  • getOriginalFileName

    public String getOriginalFileName()
    Returns:
    Returns the m_OriginalFileName.
  • setOriginalFileName

    public void setOriginalFileName(String originalFileName)
    Parameters:
    originalFileName - The OriginalFileName to set.
  • getSchemaLocation

    public String getSchemaLocation(String nsURI)
    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

    public File getSchemaLocationFile(String nsURI)
    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

    public void setSchemaLocation(String nsURI, File _schemaLocation)
    set xs:schemalocation to
    Parameters:
    nsURI -
    _schemaLocation -
  • setValidationResult

    public void setValidationResult(XMLDoc validationResult)
    Parameters:
    validationResult - the validationResult to set.
  • parseStream

    public static XMLDoc parseStream(InputStream is)
    parse a JDF input stream
    Parameters:
    is -
    Returns:
    the parsed JDFDoc
  • parseFile

    public static XMLDoc parseFile(String fileName)
    parse an XML file
    Parameters:
    fileName -
    Returns:
    the parsed JDFDoc
  • parseString

    public static XMLDoc parseString(String string)
    parse an XML file
    Parameters:
    string -
    Returns:
    the parsed JDFDoc
  • parseFile

    public static XMLDoc parseFile(File file)
    parse an XML file
    Parameters:
    file -
    Returns:
    the parsed JDFDoc
  • parseZipFile

    public static XMLDoc parseZipFile(File file)
    parse an XML file
    Parameters:
    file -
    Returns:
    the parsed JDFDoc
  • parseURL

    public static XMLDoc parseURL(String url, jakarta.mail.BodyPart bp)
    parse a given url
    Parameters:
    url - the url to search
    bp - the bodypart that the CID url is located in
    Returns:
    the parsed JDFDoc
  • copyMeta

    public void copyMeta(XMLDoc dMine)
    copy metadata from other document
    Parameters:
    dMine -