當前位置: 首頁>>代碼示例>>Java>>正文


Java DOMImplementationLS.createLSInput方法代碼示例

本文整理匯總了Java中org.w3c.dom.ls.DOMImplementationLS.createLSInput方法的典型用法代碼示例。如果您正苦於以下問題:Java DOMImplementationLS.createLSInput方法的具體用法?Java DOMImplementationLS.createLSInput怎麽用?Java DOMImplementationLS.createLSInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.w3c.dom.ls.DOMImplementationLS的用法示例。


在下文中一共展示了DOMImplementationLS.createLSInput方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testLSInputParsingByteStream

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
@Test
public void testLSInputParsingByteStream() throws Exception {
    DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
    LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
    LSInput src = impl.createLSInput();

    try (InputStream is = new FileInputStream(ASTROCAT)) {
        src.setByteStream(is);
        assertNotNull(src.getByteStream());
        // set certified accessor methods
        boolean origCertified = src.getCertifiedText();
        src.setCertifiedText(true);
        assertTrue(src.getCertifiedText());
        src.setCertifiedText(origCertified); // set back to orig

        src.setSystemId(filenameToURL(ASTROCAT));

        Document doc = domParser.parse(src);
        Element result = doc.getDocumentElement();
        assertEquals(result.getTagName(), "stardb");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:DocumentLSTest.java

示例2: testLSInputParsingString

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
@Test
public void testLSInputParsingString() throws Exception {
    DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
    String xml = "<?xml version='1.0'?><test>runDocumentLS_Q6</test>";

    LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
    LSSerializer domSerializer = impl.createLSSerializer();
    // turn off xml decl in serialized string for comparison
    domSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
    LSInput src = impl.createLSInput();
    src.setStringData(xml);
    assertEquals(src.getStringData(), xml);

    Document doc = domParser.parse(src);
    String result = domSerializer.writeToString(doc);

    assertEquals(result, "<test>runDocumentLS_Q6</test>");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:DocumentLSTest.java

示例3: loadContext

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
private void loadContext(final Collection<String> routes) {
    try {
        DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance();
        DOMImplementationLS domImpl = (DOMImplementationLS) reg.getDOMImplementation("LS");
        LSParser parser = domImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

        JAXBContext jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        List<RouteDefinition> routeDefs = new ArrayList<>();
        for (String route : routes) {
            try (InputStream input = IOUtils.toInputStream(route, StandardCharsets.UTF_8)) {
                LSInput lsinput = domImpl.createLSInput();
                lsinput.setByteStream(input);

                Node routeElement = parser.parse(lsinput).getDocumentElement();
                routeDefs.add(unmarshaller.unmarshal(routeElement, RouteDefinition.class).getValue());
            }
        }
        camelContext.addRouteDefinitions(routeDefs);
    } catch (Exception e) {
        LOG.error("While loading Camel context {}", e);
        throw new CamelException(e);
    }
}
 
開發者ID:apache,項目名稱:syncope,代碼行數:25,代碼來源:SyncopeCamelContext.java

示例4: normalizeXML

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
private static String normalizeXML(String xml) throws Exception {
    // Remove all white space adjoining tags ("trim all elements")
    xml = xml.replaceAll("\\s*<", "<");
    xml = xml.replaceAll(">\\s*", ">");

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS domLS = (DOMImplementationLS) registry.getDOMImplementation("LS");
    LSParser lsParser = domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

    LSInput input = domLS.createLSInput();
    input.setStringData(xml);
    Document document = lsParser.parse(input);

    LSSerializer lsSerializer = domLS.createLSSerializer();
    lsSerializer.getDomConfig().setParameter("comments", Boolean.FALSE);
    lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
    return lsSerializer.writeToString(document);
}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:19,代碼來源:PersistentResourceXMLParserTestCase.java

示例5: normalizeXML

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
 * Normalize and pretty-print XML so that it can be compared using string
 * compare. The following code does the following: - Removes comments -
 * Makes sure attributes are ordered consistently - Trims every element -
 * Pretty print the document
 *
 * @param xml The XML to be normalized
 * @return The equivalent XML, but now normalized
 */
public static String normalizeXML(String xml) throws Exception {
    // Remove all white space adjoining tags ("trim all elements")
    xml = xml.replaceAll("\\s*<", "<");
    xml = xml.replaceAll(">\\s*", ">");

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS domLS = (DOMImplementationLS) registry.getDOMImplementation("LS");
    LSParser lsParser = domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

    LSInput input = domLS.createLSInput();
    input.setStringData(xml);
    Document document = lsParser.parse(input);

    LSSerializer lsSerializer = domLS.createLSSerializer();
    lsSerializer.getDomConfig().setParameter("comments", Boolean.FALSE);
    lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
    return lsSerializer.writeToString(document);
}
 
開發者ID:wildfly,項目名稱:wildfly-core,代碼行數:28,代碼來源:ModelTestUtils.java

示例6: resolveResource

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
public LSInput resolveResource(String type, 
                               String namespaceURI, 
                               String publicId, 
                               String systemId, 
                               String baseURI) {
    
     LSInput lsi = mDelegate.resolveResource(type, namespaceURI, publicId, systemId, baseURI);

     if (lsi == null) {
         //if we can not get an input from catalog, then it could that
         //there as a schema in types section which refer to schema compoment from other inline schema
         //so we try to check in other inline schema.
         WSDLSchema schema = findSchema(namespaceURI);
         if(schema != null) {
             Reader in = createInlineSchemaSource(mWsdlText, mWsdlPrefixes, mWsdlLinePositions, schema);
             if(in != null) {
                 //create LSInput object
                 DOMImplementation domImpl = null;
                 try {
                     domImpl =  DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
                 } catch (ParserConfigurationException ex) {
                     Logger.getLogger(getClass().getName()).log(Level.SEVERE, "resolveResource", ex); //NOI18N
                     return null;
                 }

                 DOMImplementationLS dols = (DOMImplementationLS) domImpl.getFeature("LS","3.0");
                 lsi = dols.createLSInput();
                 lsi.setCharacterStream(in);

                 if(mWsdlSystemId != null) {
                     lsi.setSystemId(mWsdlSystemId);
                 }
                 return lsi;  
             }
         }
     }
     return lsi;                      
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:WSDLInlineSchemaValidator.java

示例7: parse

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
public static Document parse(InputStream stream)
{
	DOMImplementationLS impl = (DOMImplementationLS)REGISTRY.getDOMImplementation("LS");
	LSParser builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
	LSInput input=impl.createLSInput();
	input.setByteStream(stream);
	Document document = builder.parse(input);

	LinkedList<Pair<Node, Node>> removed=new LinkedList<>();
	removeBlankText(document, removed);
	for(Pair<Node, Node> r: removed) r.get0().removeChild(r.get1());
	
	return document;
}
 
開發者ID:cycentum,項目名稱:birdsong-recognition,代碼行數:15,代碼來源:XmlUtils.java

示例8: resolveResource

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
 * @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
    if (!type.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
        return null;
    }
    LOG.error(type);
    LOG.error(namespaceURI);
    LOG.error(publicId);
    LOG.error(systemId);
    LOG.error(baseURI);
    String path = resolveSystemId(systemId);
    if (path == null) {
        return null;
    }
    LOG.debug("Looking up resource '" + path + "' for system id '" + systemId + "'");
    InputStream is = getClass().getClassLoader().getResourceAsStream(path);
    if (is == null) {
        String message = "Unable to find schema (" + path + ") for: " + systemId;
        LOG.error(message);
        throw new RuntimeException/*SAXException*/(message);
    }
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        DOMImplementation domImpl = builder.getDOMImplementation();
        DOMImplementationLS dils = (DOMImplementationLS) domImpl;
        LSInput input = dils.createLSInput();
        input.setByteStream(is);
        return input;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:36,代碼來源:ClassLoaderLSResourceResolver.java

示例9: resolveResource

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
    * @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
    */
   public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
       if (!type.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
           return null;
       }

       if (!systemId.startsWith(CONTENT_TYPE_PREFIX)) {
           LOG.warn("Cannot resolve non-ContentType resources");
           return null;
       }

       NotificationContentTypeBo notificationContentType = resolveContentType(systemId);
       if (notificationContentType == null) {
    LOG.error("Unable to resolve system id '" + systemId + "' locally...delegating to default resolution strategy.");
    return null;
}

       Reader reader = new StringReader(notificationContentType.getXsd());
       try {
           DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
           DocumentBuilder builder = factory.newDocumentBuilder();
           DOMImplementation domImpl = builder.getDOMImplementation();
           DOMImplementationLS dils = (DOMImplementationLS) domImpl;
           LSInput input = dils.createLSInput();
           input.setCharacterStream(reader);
           return input;
       } catch (Exception e) {
           throw new RuntimeException(e);
       }
   }
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:33,代碼來源:ContentTypeLSResourceResolver.java

示例10: parse

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
@Override
public Element parse(final InputStream input) {
    try {
        final DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance();
        final DOMImplementationLS impl = (DOMImplementationLS) reg.getDOMImplementation("LS");
        final LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

        final LSInput lsinput = impl.createLSInput();
        lsinput.setByteStream(input);

        return parser.parse(lsinput).getDocumentElement();
    } catch (Exception e) {
        throw new IllegalArgumentException("Could not parse DOM", e);
    }
}
 
開發者ID:ashank,項目名稱:Office-365-SDK-for-Android,代碼行數:16,代碼來源:DefaultDOMParserImpl.java

示例11: createLSInput

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
private static LSInput createLSInput(@Nullable InputStream inputStream) {
  if (inputStream != null) {
    try {
      DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
      DOMImplementation impl = registry.getDOMImplementation("XML 1.0 LS 3.0");
      DOMImplementationLS implls = (DOMImplementationLS) impl;
      LSInput lsInput = implls.createLSInput();
      lsInput.setByteStream(inputStream);
      return lsInput;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
      throw new IllegalStateException(e);
    }
  }
  return null;
}
 
開發者ID:SonarSource,項目名稱:sonar-xml,代碼行數:16,代碼來源:SchemaResolver.java

示例12: getDocument

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
private Document getDocument(InputStream is) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
  DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
  DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
  LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
  // we need to ignore whitespace here so the nodeToString() method will be able to indent it properly:
  parser.setFilter(new IgnoreWhitespaceFilter());
  LSInput domInput = impl.createLSInput();
  domInput.setByteStream(is);
  return parser.parse(domInput);
}
 
開發者ID:languagetool-org,項目名稱:languagetool,代碼行數:11,代碼來源:PatternRuleXmlCreator.java

示例13: testCheckCharNorm001

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
 * Equivalence class partitioning with state and input values orientation
 * for public void setParameter(String name, Object value) throws
 * DOMException, <br>
 * <b>pre-conditions</b>: the root element has one Text node with not fully
 * normalized characters, the 'check-character-normalization' parameter set
 * to true, <br>
 * <b>name</b>: error-handler <br>
 * <b>value</b>: DOMErrorHandler. <br>
 * <b>Expected results</b>: LSParser calls the specified error handler
 */
@Test
public void testCheckCharNorm001() {
    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException pce) {
        Assert.fail(pce.toString());
    } catch (FactoryConfigurationError fce) {
        Assert.fail(fce.toString());
    }

    DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");

    if (lsImpl == null) {
        System.out.println("OK, the DOM implementation does not support the LS 3.0");
        return;
    }

    LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

    DOMConfiguration config = lsParser.getDomConfig();

    if (!config.canSetParameter("check-character-normalization", Boolean.TRUE)) {
        System.out.println("OK, setting 'check-character-normalization' to true is not supported");
        return;
    }

    config.setParameter("check-character-normalization", Boolean.TRUE);

    TestHandler testHandler = new TestHandler();
    config.setParameter("error-handler", testHandler);

    LSInput lsInput = lsImpl.createLSInput();
    lsInput.setStringData("<root>\u0073\u0075\u0063\u0327\u006F\u006E</root>");
    Document doc = lsParser.parse(lsInput);

    if (null == testHandler.getError()) {
        Assert.fail("no error is reported, expected 'check-character-normalization-failure'");

    }

    return; // Status.passed("OK");

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:56,代碼來源:DOMConfigurationTest.java

示例14: testCheckCharNorm002

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
 * Equivalence class partitioning with state and input values orientation
 * for public void setParameter(String name, Object value) throws
 * DOMException, <br>
 * <b>pre-conditions</b>: the root element contains a fully-normalized text, <br>
 * <b>name</b>: check-character-normalization <br>
 * <b>value</b>: false. <br>
 * <b>Expected results</b>: LSParser reports no errors
 */
@Test
public void testCheckCharNorm002() {
    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException pce) {
        Assert.fail(pce.toString());
    } catch (FactoryConfigurationError fce) {
        Assert.fail(fce.toString());
    }

    DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");

    if (lsImpl == null) {
        System.out.println("OK, the DOM implementation does not support the LS 3.0");
        return;
    }

    LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

    DOMConfiguration config = lsParser.getDomConfig();

    if (!config.canSetParameter("check-character-normalization", Boolean.FALSE)) {
        Assert.fail("setting 'check-character-normalization' to false is not supported");
    }

    config.setParameter("check-character-normalization", Boolean.FALSE);

    TestHandler testHandler = new TestHandler();
    config.setParameter("error-handler", testHandler);

    LSInput lsInput = lsImpl.createLSInput();
    lsInput.setStringData("<root>fully-normalized</root>");
    Document doc = lsParser.parse(lsInput);

    if (null != testHandler.getError()) {
        Assert.fail("no error is expected, but reported: " + testHandler.getError());

    }

    return; // Status.passed("OK");

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:53,代碼來源:DOMConfigurationTest.java

示例15: newInputSource

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
public InputSource newInputSource(String filename) throws Exception {
    // Create DOMImplementationLS, and DOM L3 LSParser
    DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
    DocumentBuilder bldr = fact.newDocumentBuilder();
    DOMImplementationLS impl = (DOMImplementationLS) bldr.getDOMImplementation();
    LSParser domparser = impl.createLSParser(MODE_SYNCHRONOUS, null);
    domparser.setFilter(new MyDOMBuilderFilter());

    // Parse the xml document to create the DOM Document using
    // the DOM L3 LSParser and a LSInput (formerly LSInputSource)
    Document doc = null;
    LSInput src = impl.createLSInput();
    // register the input file with the input source...
    String systemId = filenameToURL(filename);
    src.setSystemId(systemId);
    try (Reader reader = new FileReader(filename)) {
        src.setCharacterStream(reader);
        src.setEncoding("UTF-8");
        doc = domparser.parse(src);
    }

    // Use DOM L3 LSSerializer (previously called a DOMWriter)
    // to serialize the xml doc DOM to a file stream.
    String tmpCatalog = Files.createTempFile(Paths.get(USER_DIR), "catalog.xml", null).toString();

    LSSerializer domserializer = impl.createLSSerializer();
    domserializer.setFilter(new MyDOMWriterFilter());
    domserializer.getNewLine();
    DOMConfiguration config = domserializer.getDomConfig();
    config.setParameter("xml-declaration", Boolean.TRUE);
    String result = domserializer.writeToString(doc);
    try (FileWriter os = new FileWriter(tmpCatalog, false)) {
        os.write(result);
        os.flush();
    }

    // Return the Input Source created from the Serialized DOM L3 Document.
    InputSource catsrc = new InputSource(new InputStreamReader(new ByteArrayInputStream(Files.readAllBytes(Paths.get(tmpCatalog)))));
    catsrc.setSystemId(systemId);
    return catsrc;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:42,代碼來源:DOML3InputSourceFactoryImpl.java


注:本文中的org.w3c.dom.ls.DOMImplementationLS.createLSInput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。