java类org.w3c.dom.ls.LSInput的实例源码

XMLUtils.java 文件源码 项目:wildfly-core 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GXmlUtils.java 文件源码 项目:geometria 阅读 18 收藏 0 点赞 0 评论 0
public static LSResourceResolver getLSResourceResolver() throws Exception {
    logger.info("");
    LSResourceResolver resourceResolver = new LSResourceResolver() {
        public LSInput resolveResource(String type, String namespaceUri,
                String publicId, String systemId, String baseUri) {
            try {
                final InputStream in = GXmlEntity.class.getResource(
                        "/" + systemId).openStream();
                LSInputAdapter adapter = new LSInputAdapter(in);
                return adapter;
            }
            catch (Exception exception) {
                exception.printStackTrace();
                return null;
            }
        }
    };
    return resourceResolver;
}
GXmlUtils.java 文件源码 项目:geometria 阅读 18 收藏 0 点赞 0 评论 0
private static LSResourceResolver getLSResourceResolver() throws Exception {
    logger.info("");
    LSResourceResolver resourceResolver = new LSResourceResolver() {
        public LSInput resolveResource(String type, String namespaceUri,
                String publicId, String systemId, String baseUri) {
            try {
                final InputStream in = GXmlEntity.class.getResource(
                        "/" + systemId).openStream();
                LSInputAdapter adapter = new LSInputAdapter(in);
                return adapter;
            }
            catch (Exception exception) {
                logger.error(GStringUtils.stackTraceToString(exception));
                return null;
            }
        }
    };
    return resourceResolver;
}
DefaultLSResourceResolver.java 文件源码 项目:geo-publisher 阅读 20 收藏 0 点赞 0 评论 0
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {

    try {
        InputStream inputStream = new URL(new URL(baseURI), systemId).openStream();

        LSInput retval = new DefaultLSInput();
        retval.setByteStream(inputStream);
        retval.setBaseURI(baseURI);
        retval.setSystemId(systemId);
        retval.setPublicId(publicId);

        return retval;
    } catch(IOException e) {
        return null;
    }
}
DomDocumentBuilder.java 文件源码 项目:classpath 阅读 26 收藏 0 点赞 0 评论 0
public Document parse(InputStream in)
  throws SAXException, IOException
{
  LSInput input = ls.createLSInput();
  input.setByteStream(in);
  try
    {
      return parser.parse(input);
    }
  catch (LSException e)
    {
      Throwable e2 = e.getCause();
      if (e2 instanceof IOException)
        throw (IOException) e2;
      else
        throw e;
    }
}
DomDocumentBuilder.java 文件源码 项目:classpath 阅读 17 收藏 0 点赞 0 评论 0
public Document parse(InputStream in, String systemId)
  throws SAXException, IOException
{
  LSInput input = ls.createLSInput();
  input.setByteStream(in);
  input.setSystemId(systemId);
  try
    {
      return parser.parse(input);
    }
  catch (LSException e)
    {
      Throwable e2 = e.getCause();
      if (e2 instanceof IOException)
        throw (IOException) e2;
      else
        throw e;
    }
}
InterceptingResolver.java 文件源码 项目:cougar 阅读 16 收藏 0 点赞 0 评论 0
@Override
public LSInput resolveResource(
                String type,
                String namespaceURI,
                String publicId,
                String systemId,
                String baseURI) {

    try {
        if (shouldLoadAsResource(systemId)) {
            log.debug("Loading resource '" + systemId + "' as resource");
            return resourceToLSInput(publicId, systemId);
        }
        else {
               return super.resolveResource(type, namespaceURI, publicId, systemId, baseURI);
        }
    }
    catch (Exception e) {
        // this is cheating, the spec says allow for an exception, but we don't care
        throw new PluginException("Error resolving resource: " + systemId + ": " + e, e);
    }
}
InterceptingResolver.java 文件源码 项目:cougar 阅读 17 收藏 0 点赞 0 评论 0
private LSInput resourceToLSInput(String publicId, String systemId) {

        InputStream is = resourceAsStream(systemId);

        if (is != null) {
            DOMInputImpl result = new DOMInputImpl(); // any old impl would do
            result.setByteStream(is);
            result.setCharacterStream(null);
            result.setPublicId(publicId);
            result.setSystemId(systemId);

            return result;
        }
        else {
            return null;
        }
    }
SchemaLoader.java 文件源码 项目:molgenis 阅读 26 收藏 0 点赞 0 评论 0
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI)
{
    InputStream resourceAsStream;
    try
    {
        resourceAsStream = getSchema(systemId).getInputStream();
    }
    catch (IOException e)
    {

        throw new RuntimeException(e);
    }

    return new LSInputImpl(publicId, systemId, resourceAsStream);
}
WSDLInlineSchemaValidator.java 文件源码 项目:incubator-netbeans 阅读 25 收藏 0 点赞 0 评论 0
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;                      
}


问题


面经


文章

微信
公众号

扫码关注公众号