Exemplo n.º 1
1
  /**
   * Generate the xml top level element and start streaming the components.
   *
   * @param components
   * @param contentHandler
   * @throws SAXException
   */
  protected static void generateXML(
      Components components, ContentHandler contentHandler, boolean isScrPrivateFile)
      throws SAXException {
    // detect namespace to use
    final String namespace;
    if (components.getSpecVersion() == Constants.VERSION_1_0) {
      namespace = NAMESPACE_URI_1_0;
    } else if (components.getSpecVersion() == Constants.VERSION_1_1) {
      namespace = NAMESPACE_URI_1_1;
    } else {
      namespace = NAMESPACE_URI_1_1_FELIX;
    }
    contentHandler.startDocument();
    contentHandler.startPrefixMapping(PREFIX, namespace);

    // wrapper element to generate well formed xml
    contentHandler.startElement(
        "",
        ComponentDescriptorIO.COMPONENTS,
        ComponentDescriptorIO.COMPONENTS,
        new AttributesImpl());
    IOUtils.newline(contentHandler);

    for (final Component component : components.getComponents()) {
      if (component.isDs()) {
        generateXML(namespace, component, contentHandler, isScrPrivateFile);
      }
    }
    // end wrapper element
    contentHandler.endElement(
        "", ComponentDescriptorIO.COMPONENTS, ComponentDescriptorIO.COMPONENTS);
    IOUtils.newline(contentHandler);
    contentHandler.endPrefixMapping(PREFIX);
    contentHandler.endDocument();
  }
Exemplo n.º 2
0
  /** Always the last method of all callbacks in all handlers to be invoked. */
  private void endDocument() throws JDOMException {
    try {
      contentHandler.endDocument();

      // reset locator
      locator = null;
    } catch (SAXException se) {
      throw new JDOMException("Exception in endDocument", se);
    }
  }
Exemplo n.º 3
0
 @Override
 public void parse(final String id) throws SAXException {
   try {
     contentHandler.startDocument();
     serialize(item);
     contentHandler.endDocument();
   } catch (final Exception ex) {
     throw new SAXException(ex);
   }
 }
Exemplo n.º 4
0
 public static void streamNullDocument(ContentHandler contentHandler) throws SAXException {
   contentHandler.startDocument();
   contentHandler.startPrefixMapping(XMLConstants.XSI_PREFIX, XMLConstants.XSI_URI);
   final AttributesImpl attributes = new AttributesImpl();
   attributes.addAttribute(XMLConstants.XSI_URI, "nil", "xsi:nil", "CDATA", "true");
   contentHandler.startElement("", "null", "null", attributes);
   contentHandler.endElement("", "null", "null");
   contentHandler.endPrefixMapping(XMLConstants.XSI_PREFIX);
   contentHandler.endDocument();
 }