Exemple #1
0
  /**
   * Description of the Method
   *
   * @param th Description of the Parameter
   * @param lex Description of the Parameter
   * @return Description of the Return Value
   * @exception Exception Description of the Exception
   */
  @Override
  public synchronized E parseXML(XMLTagHandler th, XMLLex lex) throws Exception {
    TagPeer tagPeer;
    TagPeer currentTagPeer = null;
    Tag tag;
    E object = null;
    XMLStack stack = new XMLStack();

    // show the contents of the tag handler
    while ((tag = lex.getNextTag()) != null) {
      if (DEBUG) {
        System.out.println(this + " XMLCParser: Tag=" + tag);
      }
      /*
       *  Process this tag, also process text in between tags
       */
      switch (tag.type) {
        case STAG:
          tagPeer = th.findTagPeer(tag.name);
          if (DEBUG) {
            System.out.println("Tag Peer: " + tagPeer);
          }
          if (tagPeer != null) {
            currentTagPeer = tagPeer;
            tagPeer.assignSlots(stack, tag);
            if (tag.hasImplicitEndTag) {
              object = (E) tagPeer.validateEntity(stack);
              // need to reset otherwise possible PCDATA is assigned wrong
              currentTagPeer = null;
            }
          }
          break;
        case ETAG:
          tagPeer = th.findTagPeer(tag.name);
          if (DEBUG) {
            System.out.println("Tag Peer/End tag: " + tagPeer);
          }
          if (tagPeer != null) {
            object = (E) tagPeer.validateEntity(stack);
          }
          currentTagPeer = null;
          break;
        default:
          if (currentTagPeer != null && currentTagPeer instanceof StringPeer) {
            StringPeer stringPeer = (StringPeer) currentTagPeer;
            if (DEBUG) {
              System.out.println("Applying string to " + stringPeer);
            }
            stringPeer.applyString(stack, tag);
            currentTagPeer = null;
          }
          break;
      }
    }
    return object;
  }
Exemple #2
0
    /**
     * Handle character data.
     *
     * <p>The default implementation does nothing.
     *
     * @param ch Description of the Parameter
     * @param start Description of the Parameter
     * @param length Description of the Parameter
     * @exception Exception Derived methods may throw exceptions.
     * @see dtdc_rt.parser.XMLHandler#charData
     */
    @Override
    public void charData(char ch[], int start, int length) throws Exception {
      tag.clearAttributes();
      tag.type = Tag.STRING;
      tag.name = new String(ch, start, length);

      tagPeer = null;
      if (currentTagPeer != null && currentTagPeer instanceof StringPeer) {
        StringPeer stringPeer = (StringPeer) currentTagPeer;
        stringPeer.applyString(stack, tag);
        currentTagPeer = null;
      }
    }
Exemple #3
0
  /**
   * Description of the Method
   *
   * @param node Description of the Parameter
   * @param args Description of the Parameter
   * @return Description of the Return Value
   * @exception Exception Description of the Exception
   */
  private Object[] walkTree(Node node, Object[] args) throws Exception {
    XMLStack stack = (XMLStack) args[1];
    XMLTagHandler th = (XMLTagHandler) args[2];
    TagPeer currentTagPeer = (TagPeer) args[3];
    TagPeer tagPeer;
    Tag tag;
    Object object = null;

    int type = node.getNodeType();
    switch (type) {
      case Node.ELEMENT_NODE:
        /*
         *  Create a tag for this element
         */
        tag = new Tag(Tag.STAG, node.getNodeName());
        Attr attrs[] = sortAttributes(node.getAttributes());
        for (int i = 0; i < attrs.length; i++) {
          Attr attr = attrs[i];
          tag.addAttribute(attr.getNodeName(), attr.getNodeValue());
        }

        tagPeer = th.findTagPeer(tag.name);
        if (DEBUG) {
          System.out.println("Tag Peer: " + tagPeer);
        }
        if (tagPeer != null) {
          currentTagPeer = tagPeer;
          tagPeer.assignSlots(stack, tag);
          if (tag.hasImplicitEndTag) {
            object = tagPeer.validateEntity(stack);
          }
        }

        // recurse through all the children
        NodeList children = node.getChildNodes();
        if (children != null) {
          int len = children.getLength();
          for (int i = 0; i < len; i++) {
            args[3] = currentTagPeer;
            args = walkTree(children.item(i), args);
          }
        }
        break;
      case Node.CDATA_SECTION_NODE:
      case Node.TEXT_NODE:
        tag = new Tag(Tag.STRING, node.getNodeValue());
        if (currentTagPeer != null && currentTagPeer instanceof StringPeer) {
          StringPeer stringPeer = (StringPeer) currentTagPeer;
          if (DEBUG) {
            System.out.println("Applying string to " + stringPeer);
          }
          stringPeer.applyString(stack, tag);
          currentTagPeer = null;
        }

        break;
    }

    if (type == Node.ELEMENT_NODE) {
      tag = new Tag(Tag.ETAG, node.getNodeName());
      tagPeer = th.findTagPeer(tag.name);
      if (DEBUG) {
        System.out.println("Tag Peer/End tag: " + tagPeer);
      }
      if (tagPeer != null) {
        object = tagPeer.validateEntity(stack);
      }
      currentTagPeer = null;
    }

    args[0] = object;
    args[3] = currentTagPeer;
    return args;
  }