Java Code Examples for org.w3c.dom.ls.LSInput#setSystemId()

The following examples show how to use org.w3c.dom.ls.LSInput#setSystemId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentLSTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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");
    }
}
 
Example 2
Source File: SimpleLSResourceResolver.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
        String location = map.get(systemId);
//        System.out.printf("\ntype: %s\nnsURI: %s\npublicId: %s\nsystemId: %s\nbaseURI: %s\n",
//                type, namespaceURI, publicId, systemId, baseURI);
        if (location == null) {
            for (Class<?> base : bases) {
                URL resource = base.getResource(systemId);
                if (resource != null) {
                    systemId = resource.toExternalForm();
                    break;
                }
            }
        }
        LSInput input = dls.createLSInput();
        input.setSystemId(systemId);
//        System.out.println("Real system ID: " + systemId);
        return input;
    }
 
Example 3
Source File: WSDLInlineSchemaValidator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;                      
}
 
Example 4
Source File: LocalResolver.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public LSInput resolveResource(final String type, final String namespaceURI, final String publicId, final String systemId, final String baseURI) {
    final LSInput input = lsImplementation.createLSInput();

    final String path = URI.create(systemId).getPath();

    input.setPublicId(publicId);
    input.setBaseURI(baseURI);
    input.setSystemId(path);
    input.setByteStream(LocalResolver.class.getResourceAsStream("/xsd/" + path));

    return input;
}
 
Example 5
Source File: MetsLSResolver.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
    String location = URL_MAP.get(systemId);
    if (location == null) {
        throw new IllegalStateException("Unable to find mapping for:" + systemId);
    }
    InputStream is = this.getClass().getResourceAsStream(location);
    LSInput input = dls.createLSInput();
    input.setByteStream(is);
    input.setPublicId(publicId);
    input.setSystemId(systemId);
    return input;
}
 
Example 6
Source File: QuikitResolver.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
public LSInput resolveResource( String type, String namespaceURI, String publicId, String systemId, String baseURI )
{
    String resourceName = local.getProperty( systemId );
    if( resourceName == null )
    {
        System.out.println( "type: " + type );
        System.out.println( "namespaceURI: " + namespaceURI );
        System.out.println( "publicId: " + publicId );
        System.out.println( "systemId: " + systemId );
        System.out.println( "baseURI: " + baseURI );
        return null;
    }

    InputStream resource = getClass().getClassLoader().getResourceAsStream( resourceName );
    LSInput input;
    try
    {
        input = getLSInput();
    }
    catch( Exception e )
    {
        throw new UnsupportedOperationException( "Internal problem. Please report to [email protected] mailing list.", e  );
    }
    input.setBaseURI( baseURI );
    input.setByteStream( resource );
    input.setPublicId( publicId );
    input.setSystemId( systemId );
    return input;
}
 
Example 7
Source File: SchemaValidator.java    From cxf with Apache License 2.0 5 votes vote down vote up
private LSInput loadLSInput(String ns) {
    String path = ToolConstants.CXF_SCHEMAS_DIR_INJAR + NSFILEMAP.get(ns);
    URL url = getClass().getClassLoader().getResource(path);
    LSInput lsin = new LSInputImpl();
    lsin.setSystemId(url.toString());
    try {
        lsin.setByteStream(url.openStream());
    } catch (IOException e) {
        return null;
    }
    return lsin;
}
 
Example 8
Source File: JaxbJavaee.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
         * Allow the application to resolve external resources.
         */
        public LSInput resolveResource(final String type, final String namespaceURI, final String publicId, final String systemId, final String baseURI) {
//            System.out.println("\n>> Resolving "  +  "\n"   
//                              + "TYPE: "  + type +  "\n"   
//                              + "NAMESPACE_URI: "  + namespaceURI +  "\n"    
//                              + "PUBLIC_ID: "  + publicId +  "\n"   
//                              + "SYSTEM_ID: "  + systemId +  "\n"   
//                              + "BASE_URI: "  + baseURI +  "\n" );  

            final LSInput lsInput = new LSInputImpl();

            // In all Java EE schema xsd files, the <xsd:include schemaLocation=../> always reference to a relative path. 
            // so the systemId here will be the xsd file name.
            final URL schemaURL = JaxbJavaee.getSchemaURL(systemId);

            InputStream is = null;
            if (schemaURL != null) {
                try {
                    is = schemaURL.openStream();
                } catch (final IOException e) {
                    //should not happen
                    throw new RuntimeException(e);
                }
            }

            lsInput.setSystemId(systemId);
            lsInput.setByteStream(is);

            return lsInput;
        }
 
Example 9
Source File: DOML3InputSourceFactoryImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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;
}