當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。