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


Java XMLReader.setContentHandler方法代码示例

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


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

示例1: test

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Test
public void test() throws SAXException, ParserConfigurationException, IOException {
    Schema schema = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema").newSchema(new StreamSource(new StringReader(xmlSchema)));

    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    saxParserFactory.setNamespaceAware(true);
    saxParserFactory.setSchema(schema);
    // saxParserFactory.setFeature("http://java.sun.com/xml/schema/features/report-ignored-element-content-whitespace",
    // true);

    SAXParser saxParser = saxParserFactory.newSAXParser();

    XMLReader xmlReader = saxParser.getXMLReader();

    xmlReader.setContentHandler(new MyContentHandler());

    // InputStream input =
    // ClassLoader.getSystemClassLoader().getResourceAsStream("test/test.xml");

    InputStream input = getClass().getResourceAsStream("Bug6946312.xml");
    System.out.println("Parse InputStream:");
    xmlReader.parse(new InputSource(input));
    if (!charEvent) {
        Assert.fail("missing character event");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:Bug6946312Test.java

示例2: scan

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Identify available locales
 * @param locales_directory
 * @return
 */
public Map<String, String> scan(String locales_directory) throws IOException {
    final Map<String, String> locale_map = new HashMap<String, String>();

    String[] files = PhoeniciaContext.assetManager.list(locales_directory);
    for (String locale_dir: files) {
        if (locale_dir.equals("common")) continue;
        String locale_path = locales_directory+"/"+locale_dir+"/manifest.xml";
        LocaleHeaderScanner scanner = new LocaleHeaderScanner(locale_path, locale_map);
        try {
            InputStream locale_manifest_in = PhoeniciaContext.assetManager.open(locale_path);
            final SAXParserFactory spf = SAXParserFactory.newInstance();
            final SAXParser sp = spf.newSAXParser();
            final XMLReader xr = sp.getXMLReader();
            xr.setContentHandler(scanner);
            xr.parse(new InputSource(new BufferedInputStream(locale_manifest_in)));
        } catch (Exception e) {
            Debug.e(e);
        }
    }
    return locale_map;
}
 
开发者ID:Linguaculturalists,项目名称:Phoenicia,代码行数:27,代码来源:LocaleManager.java

示例3: buildItemList

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Override
protected List<FeedItem> buildItemList() throws SAXException, ParserConfigurationException, IOException {
    XMLReader reader = XMLUtil.createXMLReader( false, true );
    FeedHandler handler = new FeedHandler( getMaxItemCount() );
    reader.setContentHandler( handler );
    reader.setEntityResolver( org.openide.xml.EntityCatalog.getDefault() );
    reader.setErrorHandler( new ErrorCatcher() );
    reader.parse( findInputSource(new URL(url1)) );

    ArrayList<FeedItem> res = new ArrayList<FeedItem>( 2*getMaxItemCount() );
    res.addAll( handler.getItemList() );

    handler = new FeedHandler( getMaxItemCount() );
    reader.setContentHandler( handler );
    reader.parse( findInputSource(new URL(url2)) );

    res.addAll( handler.getItemList() );

    List<FeedItem> items = sortNodes( res );
    if( items.size() > getMaxItemCount() ) {
        items = items.subList( 0, getMaxItemCount() );
    }
    return items;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:CombinationRSSFeed.java

示例4: parse

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Parse the given XML string an create/update the corresponding entities
 * 
 * @param xml
 *            the XML string
 * @return the parse return code
 * @throws Exception
 */
public int parse(byte[] xml) throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    SchemaFactory sf = SchemaFactory
            .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    try (InputStream inputStream = ResourceLoader.getResourceAsStream(
            getClass(), getSchemaName())) {
        Schema schema = sf.newSchema(new StreamSource(inputStream));
        spf.setSchema(schema);
    }
    SAXParser saxParser = spf.newSAXParser();
    XMLReader reader = saxParser.getXMLReader();
    reader.setFeature(Constants.XERCES_FEATURE_PREFIX
            + Constants.DISALLOW_DOCTYPE_DECL_FEATURE, true);
    reader.setContentHandler(this);
    reader.parse(new InputSource(new ByteArrayInputStream(xml)));
    return 0;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:27,代码来源:ProductImportParser.java

示例5: testcase01

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Content event handler visit all nodes to print to output file.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase01() throws Exception {
    String outputFile = USER_DIR + "Content.out";
    String goldFile = GOLDEN_DIR + "ContentGF.out";
    String xmlFile = XML_DIR + "namespace1.xml";

    try(FileInputStream instream = new FileInputStream(xmlFile);
            MyContentHandler cHandler = new MyContentHandler(outputFile)) {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        XMLReader xmlReader = spf.newSAXParser().getXMLReader();
        xmlReader.setContentHandler(cHandler);
        xmlReader.parse(new InputSource(instream));
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ContentHandlerTest.java

示例6: parse

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public static void parse(DefaultHandler handler, String file) throws SAXException, IOException {
	XMLReader xreader = XMLReaderFactory.createXMLReader();
	xreader.setContentHandler(handler);
	xreader.setErrorHandler(handler);
	FileReader reader = new FileReader(file);
    xreader.parse(new InputSource(reader));			
}
 
开发者ID:amritbhat786,项目名称:DocIT,代码行数:8,代码来源:SAXUtilities.java

示例7: read

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Override
public Object read(Reader r) throws IOException, ClassNotFoundException {
    Lookup lkp = findContext(r);
    FileObject fo = lkp.lookup(FileObject.class);
    String displayName = fo.getFileSystem().getDecorator().annotateName(fo.getName(), Collections.singleton(fo));
    try {
        XMLReader reader = XMLUtil.createXMLReader(true);
        ToolbarParser parser = new ToolbarParser();
        reader.setContentHandler(parser);
        reader.setErrorHandler(parser);
        reader.setEntityResolver(EntityCatalog.getDefault());
        reader.parse(new InputSource(r));
        return parser.createToolbarConfiguration( fo.getName(), displayName );
    } catch( SAXException saxE ) {
        IOException ioE = new IOException();
        ioE.initCause(saxE);
        throw ioE;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ToolbarConvertor.java

示例8: main

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public static void main(String[] argv) throws Exception {
	XMLReader xr = XMLReaderFactory.createXMLReader();

	BugCollection bugCollection = new SortedBugCollection();
	Project project = new Project();

	SAXBugCollectionHandler handler = new SAXBugCollectionHandler(bugCollection, project);
	xr.setContentHandler(handler);
	xr.setErrorHandler(handler);

	// Parse each file provided on the
	// command line.
	for (int i = 0; i < argv.length; i++) {
		FileReader r = new FileReader(argv[i]);
		xr.parse(new InputSource(r));
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:18,代码来源:SAXBugCollectionHandler.java

示例9: testWithTrueFalse

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Namespace processing is enabled. Hence namespace-prefix is
 * expected to be automatically off. So it is a True-False combination.
 * The test is to test XMLReader with these conditions.
 *
 * @throws Exception If any errors occur.
 */
public void testWithTrueFalse() throws Exception {
    String outputFile = USER_DIR + "XRNSTableTF.out";
    String goldFile = GOLDEN_DIR + "NSTableTFGF.out";

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    SAXParser saxParser = spf.newSAXParser();
    XMLReader xmlReader = saxParser.getXMLReader();

    try (FileInputStream fis = new FileInputStream(xmlFile);
        MyNSContentHandler handler = new MyNSContentHandler(outputFile)) {
        xmlReader.setContentHandler(handler);
        xmlReader.parse(new InputSource(fis));
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:XMLReaderNSTableTest.java

示例10: begin

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Implemented to replace the content handler currently in use by a 
 * NodeBuilder.
 * 
 * @param namespaceURI the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 * @param attributes The attribute list of this element
 * @throws Exception indicates a JAXP configuration problem
 */
public void begin(String namespaceURI, String name, Attributes attributes)
    throws Exception {

    XMLReader xmlReader = getDigester().getXMLReader();
    Document doc = documentBuilder.newDocument();
    NodeBuilder builder = null;
    if (nodeType == Node.ELEMENT_NODE) {
        Element element = null;
        if (getDigester().getNamespaceAware()) {
            element =
                doc.createElementNS(namespaceURI, name);
            for (int i = 0; i < attributes.getLength(); i++) {
                element.setAttributeNS(attributes.getURI(i),
                                       attributes.getLocalName(i),
                                       attributes.getValue(i));
            }
        } else {
            element = doc.createElement(name);
            for (int i = 0; i < attributes.getLength(); i++) {
                element.setAttribute(attributes.getQName(i),
                                     attributes.getValue(i));
            }
        }
        builder = new NodeBuilder(doc, element);
    } else {
        builder = new NodeBuilder(doc, doc.createDocumentFragment());
    }
    xmlReader.setContentHandler(builder);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:43,代码来源:NodeCreateRule.java

示例11: testXMLReader

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public void testXMLReader(boolean setUseCatalog, boolean useCatalog, String catalog,
        String xml, MyHandler handler, String expected) throws Exception {
    XMLReader reader = getXMLReader(setUseCatalog, useCatalog, catalog);

    reader.setContentHandler(handler);
    reader.setEntityResolver(handler);
    reader.parse(xml);
    Assert.assertEquals(handler.getResult().trim(), expected);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:CatalogSupportBase.java

示例12: gatherReferences

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Parses the resource to detect the referenced resources.
 *  
 * @return The referenced resources.
 *  
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 */
private Set<ReferencedResource> gatherReferences()
    throws ParserConfigurationException, SAXException, IOException {
  
  URL toParse = URLUtil.correct(resource.getLocation());
  InputSource is = new InputSource(toParse.toExternalForm());
  XMLReader xmlReader = parserCreator.createXMLReader();
  SaxContentHandler handler = new SaxContentHandler(toParse);
  xmlReader.setContentHandler(handler);
  xmlReader.parse(is);

  return handler.getDitaMapHrefs(); 
}
 
开发者ID:oxygenxml,项目名称:oxygen-dita-translation-package-builder,代码行数:22,代码来源:MapStructureResourceBuilder.java

示例13: testcase06

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
 * Unit test newTransformerHandler with a DOMSource.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase06() throws Exception {
    String outputFile = USER_DIR + "saxtf006.out";
    String goldFile = GOLDEN_DIR + "saxtf006GF.out";

    try (FileOutputStream fos = new FileOutputStream(outputFile)) {
        XMLReader reader = XMLReaderFactory.createXMLReader();
        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory)TransformerFactory.newInstance();

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Node node = (Node)docBuilder.parse(new File(XSLT_INCL_FILE));

        DOMSource domSource = new DOMSource(node, "file:///" + XML_DIR);
        TransformerHandler handler =
                    saxTFactory.newTransformerHandler(domSource);

        Result result = new StreamResult(fos);
        handler.setResult(result);
        reader.setContentHandler(handler);
        reader.parse(XML_FILE);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:SAXTFactoryTest.java

示例14: parse

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public GraphDocument parse(InputSource source, XMLParser.ParseMonitor monitor) throws SAXException {
    XMLReader reader = createReader();

    reader.setContentHandler(new XMLParser(xmlDocument, monitor));
    try {
        reader.parse(source);
    } catch (IOException ex) {
        throw new SAXException(ex);
    }

    return graphDocument;
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:13,代码来源:Parser.java

示例15: processDownloadedFile

import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public void processDownloadedFile(File downloadedFile) throws UpdateException {
    InputStream indexInputStream = null;
    try {
        if (downloadedFile == null || !downloadedFile.exists()) {
            throw new UpdateException(repo, downloadedFile + " does not exist!");
        }

        // Due to a bug in Android 5.0 Lollipop, the inclusion of spongycastle causes
        // breakage when verifying the signature of the downloaded .jar. For more
        // details, check out https://gitlab.com/fdroid/fdroidclient/issues/111.
        FDroidApp.disableSpongyCastleOnLollipop();

        JarFile jarFile = new JarFile(downloadedFile, true);
        JarEntry indexEntry = (JarEntry) jarFile.getEntry("index.xml");
        indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
                processIndexListener, new URL(repo.address), (int) indexEntry.getSize());

        // Process the index...
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        final SAXParser parser = factory.newSAXParser();
        final XMLReader reader = parser.getXMLReader();
        final RepoXMLHandler repoXMLHandler = new RepoXMLHandler(repo, createIndexReceiver());
        reader.setContentHandler(repoXMLHandler);
        reader.parse(new InputSource(indexInputStream));

        long timestamp = repoDetailsToSave.getAsLong(RepoTable.Cols.TIMESTAMP);
        if (timestamp < repo.timestamp) {
            throw new UpdateException(repo, "index.jar is older that current index! "
                    + timestamp + " < " + repo.timestamp);
        }

        signingCertFromJar = getSigningCertFromJar(indexEntry);

        // JarEntry can only read certificates after the file represented by that JarEntry
        // has been read completely, so verification cannot run until now...
        assertSigningCertFromXmlCorrect();
        commitToDb();
    } catch (SAXException | ParserConfigurationException | IOException e) {
        throw new UpdateException(repo, "Error parsing index", e);
    } finally {
        FDroidApp.enableSpongyCastleOnLollipop();
        Utils.closeQuietly(indexInputStream);
        if (downloadedFile != null) {
            if (!downloadedFile.delete()) {
                Log.w(TAG, "Couldn't delete file: " + downloadedFile.getAbsolutePath());
            }
        }
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:51,代码来源:RepoUpdater.java


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