boolean testImpl(DOMImplementation impl, String features) {

    StringTokenizer st = new StringTokenizer(features);
    String feature = null;
    String version = null;

    if (st.hasMoreTokens()) {
      feature = st.nextToken();
    }
    while (feature != null) {
      boolean isVersion = false;
      if (st.hasMoreTokens()) {
        char c;
        version = st.nextToken();
        c = version.charAt(0);
        switch (c) {
          case '0':
          case '1':
          case '2':
          case '3':
          case '4':
          case '5':
          case '6':
          case '7':
          case '8':
          case '9':
            isVersion = true;
        }
      } else {
        version = null;
      }
      if (isVersion) {
        if (!impl.hasFeature(feature, version)) {
          return false;
        }
        if (st.hasMoreTokens()) {
          feature = st.nextToken();
        } else {
          feature = null;
        }
      } else {
        if (!impl.hasFeature(feature, null)) {
          return false;
        }
        feature = version;
      }
    }
    return true;
  }
Beispiel #2
0
  /**
   * Creates new org.w3c.dom.Document with Traversing possibility
   *
   * @param is <code>InputSource</code>
   * @return org.w3c.dom.Document
   * @throws CitationStyleManagerException
   */
  public static Document parseDocumentForTraversing(InputSource is)
      throws CitationStyleManagerException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder parser;
    try {
      parser = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
      throw new CitationStyleManagerException("Cannot create DocumentBuilder:", e);
    }

    // Check for the traversal module
    DOMImplementation impl = parser.getDOMImplementation();
    if (!impl.hasFeature("traversal", "2.0")) {
      throw new CitationStyleManagerException(
          "A DOM implementation that supports traversal is required.");
    }
    Document doc;
    try {
      doc = parser.parse(is);
    } catch (Exception e) {
      throw new CitationStyleManagerException("Cannot parse InputSource to w3c document:", e);
    }

    return doc;
  }
Beispiel #3
0
  /**
   * Converts a dom element to a String
   *
   * @param node
   * @return the dom as a String
   */
  public static String writeDomToString(Element node) {
    DOMImplementation domImplementation = node.getOwnerDocument().getImplementation();
    if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) {
      DOMImplementationLS domImplementationLS =
          (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
      LSSerializer lsSerializer = domImplementationLS.createLSSerializer();

      LSOutput lsOutput = domImplementationLS.createLSOutput();
      lsOutput.setEncoding("UTF-8");

      StringWriter stringWriter = new StringWriter();
      lsOutput.setCharacterStream(stringWriter);
      lsSerializer.write(node, lsOutput);
      return stringWriter.toString();
    } else {
      throw new RuntimeException("DOM 3.0 LS and/or DOM 2.0 Core not supported.");
    }
  }
  /**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    org.w3c.dom.bootstrap.DOMImplementationRegistry domImplRegistry;
    DOMImplementation domImpl;
    boolean hasFeature;
    String nullVersion = null;

    DOMImplementationList domImplList;
    int length;
    domImplRegistry = org.w3c.dom.bootstrap.DOMImplementationRegistry.newInstance();
    assertNotNull("domImplRegistryNotNull", domImplRegistry);
    domImplList = domImplRegistry.getDOMImplementationList("+cOrE");
    length = (int) domImplList.getLength();
    assertTrue("atLeastOne", (length > 0));
    for (int indexN10057 = 0; indexN10057 < domImplList.getLength(); indexN10057++) {
      domImpl = (DOMImplementation) domImplList.item(indexN10057);
      hasFeature = domImpl.hasFeature("+Core", nullVersion);
      assertTrue("hasCore", hasFeature);
    }
  }
Beispiel #5
0
 private LSInput getLSInput() throws Exception {
   DOMImplementationLS impl;
   DOMImplementation docImpl = builder.getDOMImplementation();
   // Try to get the DOMImplementation from doc first before
   // defaulting to the sun implementation.
   if (docImpl != null && docImpl.hasFeature("LS", "3.0")) {
     impl = (DOMImplementationLS) docImpl.getFeature("LS", "3.0");
   } else {
     DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
     impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
     if (impl == null) {
       System.setProperty(
           DOMImplementationRegistry.PROPERTY,
           "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
       registry = DOMImplementationRegistry.newInstance();
       impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
     }
   }
   return impl.createLSInput();
 }