当前位置: 首页>>代码示例>>Java>>正文


Java XMLReader.setProperty方法代码示例

本文整理汇总了Java中org.xml.sax.XMLReader.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java XMLReader.setProperty方法的具体用法?Java XMLReader.setProperty怎么用?Java XMLReader.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xml.sax.XMLReader的用法示例。


在下文中一共展示了XMLReader.setProperty方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSAXParser

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
private static SAXParser getSAXParser(
    boolean validating,
    JspDocumentParser jspDocParser)
    throws Exception {

    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);

    // Preserve xmlns attributes
    factory.setFeature(
        "http://xml.org/sax/features/namespace-prefixes",
        true);
    factory.setValidating(validating);
    //factory.setFeature(
    //    "http://xml.org/sax/features/validation",
    //    validating);
    
    // Configure the parser
    SAXParser saxParser = factory.newSAXParser();
    XMLReader xmlReader = saxParser.getXMLReader();
    xmlReader.setProperty(LEXICAL_HANDLER_PROPERTY, jspDocParser);
    xmlReader.setErrorHandler(jspDocParser);

    return saxParser;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:JspDocumentParser.java

示例2: parse

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public void parse(InputStream xml, OutputStream finf, String workingDirectory) throws Exception {
    StAXDocumentSerializer documentSerializer = new StAXDocumentSerializer();
    documentSerializer.setOutputStream(finf);

    SAX2StAXWriter saxTostax = new SAX2StAXWriter(documentSerializer);

    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    saxParserFactory.setNamespaceAware(true);
    SAXParser saxParser = saxParserFactory.newSAXParser();

    XMLReader reader = saxParser.getXMLReader();
    reader.setProperty("http://xml.org/sax/properties/lexical-handler", saxTostax);
    reader.setContentHandler(saxTostax);

    if (workingDirectory != null) {
        reader.setEntityResolver(createRelativePathResolver(workingDirectory));
    }
    reader.parse(new InputSource(xml));

    xml.close();
    finf.close();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:XML_SAX_StAX_FI.java

示例3: create

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public MutableXMLStreamBuffer create(XMLReader reader, InputStream in, String systemId) throws IOException, SAXException {
    if (_buffer == null) {
        createBuffer();
    }
    _buffer.setSystemId(systemId);
    reader.setContentHandler(this);
    reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, this);

    try {
        setHasInternedStrings(reader.getFeature(Features.STRING_INTERNING_FEATURE));
    } catch (SAXException e) {
    }


    if (systemId != null) {
        InputSource s = new InputSource(systemId);
        s.setByteStream(in);
        reader.parse(s);
    } else {
        reader.parse(new InputSource(in));
    }

    return getXMLStreamBuffer();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:SAXBufferCreator.java

示例4: main

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
    public static void main(String[] args) {
        TestRunner.run(JDK6770436Test.class);
    }
*/
    @Test
    public void entityCallbackOrderJava() throws SAXException, IOException {
        final String input = "<element> &amp; some more text</element>";

        final MockContentHandler handler = new MockContentHandler();
        final XMLReader xmlReader = XMLReaderFactory.createXMLReader();

        xmlReader.setContentHandler(handler);
        xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);

        xmlReader.parse(new InputSource(new StringReader(input)));

        final List<String> events = handler.getEvents();
        printEvents(events);
        assertCallbackOrder(events); //regression from JDK5
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:EntityCharacterEventOrder.java

示例5: identityTransform

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Performs identity transformation.
 * @param <T>
 * @param src
 * @param result
 * @return
 * @throws javax.xml.transform.TransformerException
 * @throws java.io.IOException
 * @throws org.xml.sax.SAXException
 * @throws javax.xml.parsers.ParserConfigurationException
 */
public static <T extends Result> T identityTransform(Source src, T result)
        throws TransformerException, SAXException, ParserConfigurationException, IOException {
    if (src instanceof StreamSource) {
        // work around a bug in JAXP in JDK6u4 and earlier where the namespace processing
        // is not turned on by default
        StreamSource ssrc = (StreamSource) src;
        TransformerHandler th = ((SAXTransformerFactory) transformerFactory.get()).newTransformerHandler();
        th.setResult(result);
        XMLReader reader = saxParserFactory.get().newSAXParser().getXMLReader();
        reader.setContentHandler(th);
        reader.setProperty(LEXICAL_HANDLER_PROPERTY, th);
        reader.parse(toInputSource(ssrc));
    } else {
        newTransformer().transform(src, result);
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:XmlUtil.java

示例6: testSAX

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Test(dataProvider = "xml-data")
public void testSAX(String xml, int chunkSize, int numOfChunks, boolean withinLimit) throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    XMLReader reader = spf.newSAXParser().getXMLReader();
    MyHandler handler = new MyHandler(chunkSize);
    reader.setContentHandler(handler);
    reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);

    if (chunkSize > 0) {
        reader.setProperty(CDATA_CHUNK_SIZE, chunkSize);
    }

    reader.parse(new InputSource(new StringReader(xml)));
    System.out.println("CData num of chunks:" + handler.getNumOfCDataChunks());
    System.out.println("CData size within limit:" + handler.chunkSizeWithinLimit());
    Assert.assertEquals(handler.getNumOfCDataChunks(), numOfChunks);
    Assert.assertEquals(handler.chunkSizeWithinLimit(), withinLimit);

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:CDataChunkSizeTest.java

示例7: createXMLReader

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
protected XMLReader createXMLReader() {
    XMLReader parser = null;
    
    try {
        parser = XMLUtil.createXMLReader(false, true);           
        try {
            parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);  //NOI18N
        } catch (SAXException sex) {
            Logger.getLogger(XMLMIMEComponent.class.getName()).fine(NbBundle.getMessage(XMLMIMEComponent.class, "W-003"));  //NOI18N
        }
    } catch (SAXException ex) {
        Logger.getLogger(XMLMIMEComponent.class.getName()).log(Level.WARNING, null, ex);
    }
    return parser;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:XMLMIMEComponent.java

示例8: parse

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@NonNull
private Document parse(@NonNull String xml, @NonNull InputSource input, boolean checkBom)
        throws ParserConfigurationException, SAXException, IOException {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setFeature(NAMESPACE_FEATURE, true);
        factory.setFeature(NAMESPACE_PREFIX_FEATURE, true);
        factory.setFeature(PROVIDE_XMLNS_URIS, true);
        SAXParser parser = factory.newSAXParser();
        DomBuilder handler = new DomBuilder(xml);
        XMLReader xmlReader = parser.getXMLReader();
        xmlReader.setProperty(
                "http://xml.org/sax/properties/lexical-handler",
                handler
        );
        parser.parse(input, handler);
        return handler.getDocument();
    } catch (SAXException e) {
        if (checkBom && e.getMessage().contains("Content is not allowed in prolog")) {
            // Byte order mark in the string? Skip it. There are many markers
            // (see http://en.wikipedia.org/wiki/Byte_order_mark) so here we'll
            // just skip those up to the XML prolog beginning character, <
            xml = xml.replaceFirst("^([\\W]+)<","<");  //$NON-NLS-1$ //$NON-NLS-2$
            return parse(xml, new InputSource(new StringReader(xml)), false);
        }
        throw e;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:29,代码来源:PositionXmlParser.java

示例9: parse

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public void parse(InputStream xml, OutputStream finf, String workingDirectory) throws Exception {
    SAXParser saxParser = getParser();
    SAXDocumentSerializer documentSerializer = getSerializer(finf);

    XMLReader reader = saxParser.getXMLReader();
    reader.setProperty("http://xml.org/sax/properties/lexical-handler", documentSerializer);
    reader.setContentHandler(documentSerializer);

    if (workingDirectory != null) {
        reader.setEntityResolver(createRelativePathResolver(workingDirectory));
    }
    reader.parse(new InputSource(xml));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:XML_SAX_FI.java

示例10: setXMLReaderPropertyIfSupport

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Sets the XMLReader instance with the specified property if the the
 * property is supported, ignores error if not, issues a warning if so
 * requested.
 *
 * @param reader an XMLReader instance
 * @param property the name of the property
 * @param value the value of the property
 * @param warn a flag indicating whether a warning should be issued
 */
public static void setXMLReaderPropertyIfSupport(XMLReader reader, String property,
        Object value, boolean warn) {
    try {
        reader.setProperty(property, value);
    } catch (SAXNotRecognizedException | SAXNotSupportedException e) {
        if (warn) {
            XMLSecurityManager.printWarning(reader.getClass().getName(),
                    property, e);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:JdkXmlUtils.java

示例11: getXMLReader

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Returns an instance of XMLReader with a catalog if one is provided.
 *
 * @param setUseCatalog a flag indicates whether USE_CATALOG shall be set
 * through the factory
 * @param useCatalog the value of USE_CATALOG
 * @param catalog a catalog
 * @return an instance of XMLReader
 * @throws ParserConfigurationException
 * @throws SAXException
 */
XMLReader getXMLReader(boolean setUseCatalog, boolean useCatalog, String catalog)
        throws ParserConfigurationException, SAXException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    XMLReader reader = spf.newSAXParser().getXMLReader();
    if (setUseCatalog) {
        reader.setFeature(XMLConstants.USE_CATALOG, useCatalog);
    }
    reader.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog);
    return reader;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:CatalogSupportBase.java

示例12: xrProperty05

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * XMLReader.setProperty/getProperty for LEXICAL_HANDLER unit test.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void xrProperty05() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    MyLexicalHandler myLexicalHandler = new MyLexicalHandler();
    xmlReader.setProperty(LEXICAL_HANDLER, myLexicalHandler);
    assertNotNull(xmlReader.getProperty(LEXICAL_HANDLER));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:XMLReaderTest.java

示例13: xrProperty06

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * XMLReader.setProperty/getProperty for DECL_HANDLER unit test.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void xrProperty06() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    XMLReader xmlReader = spf.newSAXParser().getXMLReader();
    MyDeclHandler myDeclHandler = new MyDeclHandler();
    xmlReader.setProperty(DECL_HANDLER, myDeclHandler);
    assertNotNull(xmlReader.getProperty(DECL_HANDLER));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:XMLReaderTest.java

示例14: createFromXMLReader

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
 *
 * <p>
 * The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
 *
 * <p>
 * The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
 * and registering associated handlers on the {@link XMLReader}.
 *
 * @param reader
 * The {@link XMLReader} to use for parsing.
 * @param in
 * The {@link InputStream} to be parsed.
 * @param systemId
 * The system ID of the input stream.
 */
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
    reset();
    SAXBufferCreator c = new SAXBufferCreator(this);

    reader.setContentHandler(c);
    reader.setDTDHandler(c);
    reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);

    c.create(reader, in, systemId);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:MutableXMLStreamBuffer.java


注:本文中的org.xml.sax.XMLReader.setProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。