Package org.apache.uima.util.XMLSerializer

Examples of org.apache.uima.util.XMLSerializer.CharacterValidatingContentHandler


      }
    } else {
      // write start tag for attribute if desired
      outputStartElement(aContentHandler, matchingNode, aNamespace, aXmlElementName, aXmlElementName, EMPTY_ATTRIBUTES);       

      CharacterValidatingContentHandler cc = maybeGetCharacterValidatingContentHandler(aContentHandler);
      if (null != cc) {
        cc.lastOutputNodeAddLevel();
      }
      try {
        // iterate over entries in the Map
        for (Map.Entry<String, Object> curEntry : theMap.entrySet()) {
          String key = curEntry.getKey();
 
          // write a tag for the value, with a "key" attribute
          AttributesImpl attrs = new AttributesImpl();
          attrs.addAttribute("", aKeyXmlAttribute, aKeyXmlAttribute, null, key); // are these nulls OK?
          Node innerMatchingNode = findMatchingSubElement(aContentHandler, aValueTagName);
          outputStartElement(aContentHandler, innerMatchingNode, aNamespace, aValueTagName, aValueTagName, attrs);     
          // write the value (must be XMLizable or an array of XMLizable)
          Object val = curEntry.getValue();
          if (val.getClass().isArray()) {
            Object[] arr = (Object[]) val;
            for (int j = 0; j < arr.length; j++) {
              XMLizable elem = (XMLizable) arr[j];
              elem.toXML(aContentHandler);
            }
          } else {
            if (null != cc) {
              cc.lastOutputNodeAddLevel();
            }
            try {
            ((XMLizable) val).toXML(aContentHandler);
            } finally {
              if (null != cc) {
                cc.lastOutputNodeClearLevel();
              }
            }
          }
 
          // write end tag for the value
          outputEndElement(aContentHandler, innerMatchingNode, aNamespace, aValueTagName, aValueTagName);
        }
      } finally {
        if (null != cc) {
          cc.lastOutputNodeClearLevel();
        }
      }

      // if we wrote start tag for attribute, now write end tag
      outputEndElement(aContentHandler, matchingNode, aNamespace, aXmlElementName, aXmlElementName);
View Full Code Here


      indent = ((CharacterValidatingContentHandler) contentHandler).getIndent();;
    }
  
    if (null == node) {
      if (contentHandler instanceof CharacterValidatingContentHandler) {
        CharacterValidatingContentHandler cvch = (CharacterValidatingContentHandler)contentHandler;
        if (!cvch.prevNL) {
          outputNL(contentHandler);
          outputIndent(indent, contentHandler);
        }
      }
View Full Code Here

      indent = ((CharacterValidatingContentHandler) contentHandler).prevIndent();
    }
   
    if (null == node || (!hasElementChildNode(node))) {
      if (null == node && contentHandler instanceof CharacterValidatingContentHandler) {
        CharacterValidatingContentHandler cvch = (CharacterValidatingContentHandler)contentHandler;
        if (cvch.prevWasEndElement) {
          outputNL(contentHandler);
          outputIndent(indent, contentHandler);
        }
      }
View Full Code Here

   */
  protected Node findMatchingSubElement(ContentHandler contentHandler, String elementName) {
    if (null == infoset || null == elementName) {
      return null;
    }
    CharacterValidatingContentHandler cc = maybeGetCharacterValidatingContentHandler(contentHandler);
    if (null == cc) {
      return null;
    }
    Node lastOutput = cc.getLastOutputNode();
    Node n = null;
   
    if (lastOutput == null) {
      lastOutput = cc.getLastOutputNodePrevLevel();
      if (lastOutput == null) {
        return null;
      }
      n = lastOutput.getFirstChild();
    } else {
      n = lastOutput.getNextSibling();
    }
    for (; n != null; n = n.getNextSibling()) {
      if ((n instanceof Element) &&
          elementName.equals(((Element)n).getTagName())) {
        cc.setLastOutputNode(n);
        return n;
      }
    }
    return null;
  }
View Full Code Here

//    aContentHandler.endElement(null, className, className);
  }
 
  // https://issues.apache.org/jira/browse/UIMA-3477
  private CharacterValidatingContentHandler maybeGetCharacterValidatingContentHandler(ContentHandler contentHandler) {
    CharacterValidatingContentHandler cc = null;
    try {
      cc = (CharacterValidatingContentHandler) contentHandler;
    } catch (ClassCastException e) {
    }
    return cc;
View Full Code Here

TOP

Related Classes of org.apache.uima.util.XMLSerializer.CharacterValidatingContentHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.