示例#1
0
 public void externalEntityDecl(String name, String publicId, String sysId) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.EXTERNAL_ENTITY_DECL);
   saxEvent.addParm(name);
   saxEvent.addParm(publicId);
   saxEvent.addParm(sysId);
   events.add(saxEvent);
 }
示例#2
0
 public void comment(char[] ch, int start, int end) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.COMMENT);
   saxEvent.addParm(ch);
   saxEvent.addParm(new Integer(start));
   saxEvent.addParm(new Integer(end));
   events.add(saxEvent);
 }
示例#3
0
 public void characters(char[] ch, int start, int end) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.CHARACTERS);
   saxEvent.addParm(ch);
   saxEvent.addParm(new Integer(start));
   saxEvent.addParm(new Integer(end));
   events.add(saxEvent);
 }
示例#4
0
 public void startDTD(String name, String publicId, String systemId) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.START_DTD);
   saxEvent.addParm(name);
   saxEvent.addParm(publicId);
   saxEvent.addParm(systemId);
   events.add(saxEvent);
 }
示例#5
0
 public void attributeDecl(
     String eName, String aName, String type, String valueDefault, String value)
     throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.ATTRIBUTE_DECL);
   saxEvent.addParm(eName);
   saxEvent.addParm(aName);
   saxEvent.addParm(type);
   saxEvent.addParm(valueDefault);
   saxEvent.addParm(value);
   events.add(saxEvent);
 }
示例#6
0
  public void endElement(String namespaceURI, String localName, String qName) throws SAXException {

    SAXEvent saxEvent = new SAXEvent(SAXEvent.END_ELEMENT);
    saxEvent.addParm(namespaceURI);
    saxEvent.addParm(localName);
    saxEvent.addParm(qName);
    events.add(saxEvent);

    // check to see if a we issued a start prefix mapping event
    // for DOMDocument namespace decls

    QName elementName = null;
    if (namespaceURI != null) {
      elementName = new QName(localName, Namespace.get(namespaceURI));
    } else {
      elementName = new QName(localName);
    }

    List prefixes = (List) prefixMappings.get(elementName);
    if (prefixes != null) {
      Iterator itr = prefixes.iterator();
      while (itr.hasNext()) {
        SAXEvent prefixEvent = new SAXEvent(SAXEvent.END_PREFIX_MAPPING);
        prefixEvent.addParm(itr.next());
        events.add(prefixEvent);
      }
    }
  }
示例#7
0
  public void replay(ContentHandler handler) throws SAXException {
    SAXEvent saxEvent;
    Iterator itr = events.iterator();

    while (itr.hasNext()) {
      saxEvent = (SAXEvent) itr.next();

      switch (saxEvent.event) {
          // replay to ContentHandler
        case SAXEvent.PROCESSING_INSTRUCTION:
          handler.processingInstruction((String) saxEvent.getParm(0), (String) saxEvent.getParm(1));

          break;

        case SAXEvent.START_PREFIX_MAPPING:
          handler.startPrefixMapping((String) saxEvent.getParm(0), (String) saxEvent.getParm(1));

          break;

        case SAXEvent.END_PREFIX_MAPPING:
          handler.endPrefixMapping((String) saxEvent.getParm(0));

          break;

        case SAXEvent.START_DOCUMENT:
          handler.startDocument();

          break;

        case SAXEvent.END_DOCUMENT:
          handler.endDocument();

          break;

        case SAXEvent.START_ELEMENT:
          AttributesImpl attributes = new AttributesImpl();
          List attParmList = (List) saxEvent.getParm(3);

          if (attParmList != null) {
            Iterator attsItr = attParmList.iterator();

            while (attsItr.hasNext()) {
              String[] attParms = (String[]) attsItr.next();
              attributes.addAttribute(
                  attParms[0], attParms[1], attParms[2], attParms[3], attParms[4]);
            }
          }

          handler.startElement(
              (String) saxEvent.getParm(0),
              (String) saxEvent.getParm(1),
              (String) saxEvent.getParm(2),
              attributes);

          break;

        case SAXEvent.END_ELEMENT:
          handler.endElement(
              (String) saxEvent.getParm(0),
              (String) saxEvent.getParm(1),
              (String) saxEvent.getParm(2));

          break;

        case SAXEvent.CHARACTERS:
          char[] chars = (char[]) saxEvent.getParm(0);
          int start = ((Integer) saxEvent.getParm(1)).intValue();
          int end = ((Integer) saxEvent.getParm(2)).intValue();
          handler.characters(chars, start, end);

          break;

          // replay to LexicalHandler
        case SAXEvent.START_DTD:
          ((LexicalHandler) handler)
              .startDTD(
                  (String) saxEvent.getParm(0),
                  (String) saxEvent.getParm(1),
                  (String) saxEvent.getParm(2));

          break;

        case SAXEvent.END_DTD:
          ((LexicalHandler) handler).endDTD();

          break;

        case SAXEvent.START_ENTITY:
          ((LexicalHandler) handler).startEntity((String) saxEvent.getParm(0));

          break;

        case SAXEvent.END_ENTITY:
          ((LexicalHandler) handler).endEntity((String) saxEvent.getParm(0));

          break;

        case SAXEvent.START_CDATA:
          ((LexicalHandler) handler).startCDATA();

          break;

        case SAXEvent.END_CDATA:
          ((LexicalHandler) handler).endCDATA();

          break;

        case SAXEvent.COMMENT:
          char[] cchars = (char[]) saxEvent.getParm(0);
          int cstart = ((Integer) saxEvent.getParm(1)).intValue();
          int cend = ((Integer) saxEvent.getParm(2)).intValue();
          ((LexicalHandler) handler).comment(cchars, cstart, cend);

          break;

          // replay to DeclHandler
        case SAXEvent.ELEMENT_DECL:
          ((DeclHandler) handler)
              .elementDecl((String) saxEvent.getParm(0), (String) saxEvent.getParm(1));

          break;

        case SAXEvent.ATTRIBUTE_DECL:
          ((DeclHandler) handler)
              .attributeDecl(
                  (String) saxEvent.getParm(0),
                  (String) saxEvent.getParm(1),
                  (String) saxEvent.getParm(2),
                  (String) saxEvent.getParm(3),
                  (String) saxEvent.getParm(4));

          break;

        case SAXEvent.INTERNAL_ENTITY_DECL:
          ((DeclHandler) handler)
              .internalEntityDecl((String) saxEvent.getParm(0), (String) saxEvent.getParm(1));

          break;

        case SAXEvent.EXTERNAL_ENTITY_DECL:
          ((DeclHandler) handler)
              .externalEntityDecl(
                  (String) saxEvent.getParm(0),
                  (String) saxEvent.getParm(1),
                  (String) saxEvent.getParm(2));

          break;

        default:
          throw new SAXException("Unrecognized event: " + saxEvent.event);
      }
    }
  }
示例#8
0
 public void internalEntityDecl(String name, String value) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.INTERNAL_ENTITY_DECL);
   saxEvent.addParm(name);
   saxEvent.addParm(value);
   events.add(saxEvent);
 }
示例#9
0
 public void elementDecl(String name, String model) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.ELEMENT_DECL);
   saxEvent.addParm(name);
   saxEvent.addParm(model);
   events.add(saxEvent);
 }
示例#10
0
 public void endEntity(String name) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.END_ENTITY);
   saxEvent.addParm(name);
   events.add(saxEvent);
 }
示例#11
0
 public void startEntity(String name) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.START_ENTITY);
   saxEvent.addParm(name);
   events.add(saxEvent);
 }
示例#12
0
  public void startElement(
      String namespaceURI, String localName, String qualifiedName, Attributes attributes)
      throws SAXException {
    SAXEvent saxEvent = new SAXEvent(SAXEvent.START_ELEMENT);
    saxEvent.addParm(namespaceURI);
    saxEvent.addParm(localName);
    saxEvent.addParm(qualifiedName);

    QName qName = null;
    if (namespaceURI != null) {
      qName = new QName(localName, Namespace.get(namespaceURI));
    } else {
      qName = new QName(localName);
    }

    if ((attributes != null) && (attributes.getLength() > 0)) {
      List attParmList = new ArrayList(attributes.getLength());
      String[] attParms = null;

      for (int i = 0; i < attributes.getLength(); i++) {

        String attLocalName = attributes.getLocalName(i);

        if (attLocalName.startsWith(XMLNS)) {

          // if SAXWriter is writing a DOMDocument, namespace
          // decls are treated as attributes. record a start
          // prefix mapping event
          String prefix = null;
          if (attLocalName.length() > 5) {
            prefix = attLocalName.substring(6);
          } else {
            prefix = EMPTY_STRING;
          }

          SAXEvent prefixEvent = new SAXEvent(SAXEvent.START_PREFIX_MAPPING);
          prefixEvent.addParm(prefix);
          prefixEvent.addParm(attributes.getValue(i));
          events.add(prefixEvent);

          // 'register' the prefix so that we can generate
          // an end prefix mapping event within endElement
          List prefixes = (List) prefixMappings.get(qName);
          if (prefixes == null) {
            prefixes = new ArrayList();
            prefixMappings.put(qName, prefixes);
          }
          prefixes.add(prefix);

        } else {

          attParms = new String[5];
          attParms[0] = attributes.getURI(i);
          attParms[1] = attLocalName;
          attParms[2] = attributes.getQName(i);
          attParms[3] = attributes.getType(i);
          attParms[4] = attributes.getValue(i);
          attParmList.add(attParms);
        }
      }

      saxEvent.addParm(attParmList);
    }

    events.add(saxEvent);
  }
示例#13
0
 public void endPrefixMapping(String prefix) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.END_PREFIX_MAPPING);
   saxEvent.addParm(prefix);
   events.add(saxEvent);
 }
示例#14
0
 public void startPrefixMapping(String prefix, String uri) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.START_PREFIX_MAPPING);
   saxEvent.addParm(prefix);
   saxEvent.addParm(uri);
   events.add(saxEvent);
 }
示例#15
0
 public void processingInstruction(String target, String data) throws SAXException {
   SAXEvent saxEvent = new SAXEvent(SAXEvent.PROCESSING_INSTRUCTION);
   saxEvent.addParm(target);
   saxEvent.addParm(data);
   events.add(saxEvent);
 }