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
 /**
  * This will invoke the <code>endPrefixMapping</code> callback in the <code>ContentHandler</code>
  * when a namespace is goes out of scope in the <code>Document</code>.
  *
  * @param namespace Namespace leaving scope.
  */
 private void endPrefixMapping(Namespace namespace) throws JDOMException {
   try {
     contentHandler.endPrefixMapping(namespace.getPrefix());
   } catch (SAXException se) {
     throw new JDOMException("Exception in endPrefixMapping", se);
   }
 }
Exemplo n.º 3
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();
 }
Exemplo n.º 4
0
 /**
  * This will invoke the <code>endPrefixMapping</code> callback in the <code>ContentHandler</code>
  * when a namespace is goes out of scope in the <code>Document</code>.
  *
  * @param namespaces <code>List</code> stack of Namespaces in scope.
  * @param previouslyDeclaredNamespaces number of previously declared namespaces
  */
 private void endPrefixMapping(NamespaceStack namespaces, int previouslyDeclaredNamespaces)
     throws JDOMException {
   while (namespaces.size() > previouslyDeclaredNamespaces) {
     String prefix = namespaces.pop();
     try {
       contentHandler.endPrefixMapping(prefix);
     } catch (SAXException se) {
       throw new JDOMException("Exception in endPrefixMapping", se);
     }
   }
 }