示例#1
0
  /**
   * This will invoke the <code>startElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param nsAtts <code>List</code> of namespaces to declare with the element or <code>null</code>.
   */
  private void startElement(Element element, Attributes nsAtts) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    // Allocate attribute list.
    AttributesImpl atts = (nsAtts != null) ? new AttributesImpl(nsAtts) : new AttributesImpl();

    List attributes = element.getAttributes();
    Iterator i = attributes.iterator();
    while (i.hasNext()) {
      Attribute a = (Attribute) i.next();
      atts.addAttribute(
          a.getNamespaceURI(),
          a.getName(),
          a.getQualifiedName(),
          getAttributeTypeName(a.getAttributeType()),
          a.getValue());
    }

    try {
      contentHandler.startElement(namespaceURI, localName, rawName, atts);
    } catch (SAXException se) {
      throw new JDOMException("Exception in startElement", se);
    }
  }
示例#2
0
 /**
  * This will take the supplied <code>{@link Element}</code> and transfer its namespaces to the
  * global namespace storage.
  *
  * @param element <code>Element</code> to read namespaces from.
  */
 private void transferNamespaces(Element element) {
   Iterator i = declaredNamespaces.iterator();
   while (i.hasNext()) {
     Namespace ns = (Namespace) i.next();
     if (ns != element.getNamespace()) {
       element.addNamespaceDeclaration(ns);
     }
   }
   declaredNamespaces.clear();
 }
示例#3
0
  /**
   * This will invoke the callbacks for the content of an element.
   *
   * @param content element content as a <code>List</code> of nodes.
   * @param namespaces <code>List</code> stack of Namespaces in scope.
   */
  private void elementContent(List content, NamespaceStack namespaces) throws JDOMException {
    for (Iterator i = content.iterator(); i.hasNext(); ) {
      Object obj = i.next();

      if (obj instanceof Content) {
        this.elementContent((Content) obj, namespaces);
      } else {
        // Not a valid element child. This could happen with
        // application-provided lists which may contain non
        // JDOM objects.
        handleError(new JDOMException("Invalid element content: " + obj));
      }
    }
  }
  private void nameLengthStatistics() {
    Iterator i = Person.iterator();
    Person p;
    int l = Person.getMaxNameLength();
    int lengthTable[] = new int[l + 1];
    int j;

    System.out.println();
    // System.out.println("Name length: Number of persons");
    while (i.hasNext()) {
      p = (Person) i.next();
      lengthTable[p.getName().length()]++;
    }
    for (j = 1; j <= l; j++) {
      System.out.print(j + ": " + lengthTable[j] + "  ");
      if (j % 5 == 0) System.out.println();
    }
    System.out.println();
  }
示例#5
0
  /**
   * This will invoke the <code>ContentHandler.startPrefixMapping</code> callback when a new
   * namespace is encountered in the <code>Document</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param namespaces <code>List</code> stack of Namespaces in scope.
   * @return <code>Attributes</code> declaring the namespaces local to <code>element</code> or
   *     <code>null</code>.
   */
  private Attributes startPrefixMapping(Element element, NamespaceStack namespaces)
      throws JDOMException {
    AttributesImpl nsAtts = null; // The namespaces as xmlns attributes

    Namespace ns = element.getNamespace();
    if (ns != Namespace.XML_NAMESPACE) {
      String prefix = ns.getPrefix();
      String uri = namespaces.getURI(prefix);
      if (!ns.getURI().equals(uri)) {
        namespaces.push(ns);
        nsAtts = this.addNsAttribute(nsAtts, ns);
        try {
          contentHandler.startPrefixMapping(prefix, ns.getURI());
        } catch (SAXException se) {
          throw new JDOMException("Exception in startPrefixMapping", se);
        }
      }
    }

    // Fire additional namespace declarations
    List additionalNamespaces = element.getAdditionalNamespaces();
    if (additionalNamespaces != null) {
      Iterator itr = additionalNamespaces.iterator();
      while (itr.hasNext()) {
        ns = (Namespace) itr.next();
        String prefix = ns.getPrefix();
        String uri = namespaces.getURI(prefix);
        if (!ns.getURI().equals(uri)) {
          namespaces.push(ns);
          nsAtts = this.addNsAttribute(nsAtts, ns);
          try {
            contentHandler.startPrefixMapping(prefix, ns.getURI());
          } catch (SAXException se) {
            throw new JDOMException("Exception in startPrefixMapping", se);
          }
        }
      }
    }
    return nsAtts;
  }
示例#6
0
  /**
   * This will output the <code>JDOM Document</code>, firing off the SAX events that have been
   * registered.
   *
   * @param document <code>JDOM Document</code> to output.
   * @throws JDOMException if any error occurred.
   */
  public void output(Document document) throws JDOMException {
    if (document == null) {
      return;
    }

    // contentHandler.setDocumentLocator()
    documentLocator(document);

    // contentHandler.startDocument()
    startDocument();

    // Fire DTD events
    if (this.reportDtdEvents) {
      dtdEvents(document);
    }

    // Handle root element, as well as any root level
    // processing instructions and comments
    Iterator i = document.getContent().iterator();
    while (i.hasNext()) {
      Object obj = i.next();

      // update locator
      locator.setNode(obj);

      if (obj instanceof Element) {
        // process root element and its content
        element(document.getRootElement(), new NamespaceStack());
      } else if (obj instanceof ProcessingInstruction) {
        // contentHandler.processingInstruction()
        processingInstruction((ProcessingInstruction) obj);
      } else if (obj instanceof Comment) {
        // lexicalHandler.comment()
        comment(((Comment) obj).getText());
      }
    }

    // contentHandler.endDocument()
    endDocument();
  }
  private void publicationCountStatistics() {
    Iterator i = Person.iterator();
    Person p;
    int l = Person.getMaxPublCount();
    int countTable[] = new int[l + 1];
    int j, n;

    System.out.println();
    System.out.println("Number of publications: Number of persons");
    while (i.hasNext()) {
      p = (Person) i.next();
      countTable[p.getCount()]++;
    }
    n = 0;
    for (j = 1; j <= l; j++) {
      if (countTable[j] == 0) continue;
      n++;
      System.out.print(j + ": " + countTable[j] + "  ");
      if (n % 5 == 0) System.out.println();
    }
    System.out.println();
  }
  private void applyUpdates() throws SAXException {
    // now handle any updates
    if (updates.size() > 0) {
      try {
        Object upd[];
        Iterator<?> i = updates.iterator();
        while (i.hasNext()) {
          upd = (Object[]) i.next();
          idx = ((Integer) upd[0]).intValue();

          if (!(lastval.equals(upd[1]))) {
            insertValue((String) (upd[1]));
          }
        }

        rs.updateRow();
      } catch (SQLException ex) {
        throw new SAXException(
            MessageFormat.format(
                resBundle.handleGetObject("xmlrch.errupdrow").toString(), ex.getMessage()));
      }
      updates.removeAllElements();
    }
  }