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


Java XMLReaderFactory类代码示例

本文整理汇总了Java中org.xml.sax.helpers.XMLReaderFactory的典型用法代码示例。如果您正苦于以下问题:Java XMLReaderFactory类的具体用法?Java XMLReaderFactory怎么用?Java XMLReaderFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testcase08

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
/**
 * Test newTransformerHandler with a Template Handler.
 *
 * @throws Exception If any errors occur.
 */
public void testcase08() throws Exception {
    String outputFile = USER_DIR + "saxtf008.out";
    String goldFile = GOLDEN_DIR + "saxtf008GF.out";

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

        TemplatesHandler thandler = saxTFactory.newTemplatesHandler();
        reader.setContentHandler(thandler);
        reader.parse(XSLT_FILE);
        TransformerHandler tfhandler
                = saxTFactory.newTransformerHandler(thandler.getTemplates());

        Result result = new StreamResult(fos);
        tfhandler.setResult(result);

        reader.setContentHandler(tfhandler);
        reader.parse(XML_FILE);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:SAXTFactoryTest.java

示例2: load

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public static SyntaxScheme load(Font baseFont, InputStream in)
		throws IOException {
	SyntaxSchemeLoader parser = null;
	try {
		XMLReader reader = XMLReaderFactory.createXMLReader();
		parser = new SyntaxSchemeLoader(baseFont);
		parser.baseFont = baseFont;
		reader.setContentHandler(parser);
		InputSource is = new InputSource(in);
		is.setEncoding("UTF-8");
		reader.parse(is);
	} catch (SAXException se) {
		throw new IOException(se.toString());
	}
	return parser.scheme;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:17,代码来源:SyntaxScheme.java

示例3: getFileChecksum

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
private FileChecksum getFileChecksum(String f) throws IOException {
  final HttpURLConnection connection = openConnection(
      "/fileChecksum" + ServletUtil.encodePath(f),
      "ugi=" + getEncodedUgiParameter());
  try {
    final XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(this);
    xr.parse(new InputSource(connection.getInputStream()));
  } catch(SAXException e) {
    final Exception embedded = e.getException();
    if (embedded != null && embedded instanceof IOException) {
      throw (IOException)embedded;
    }
    throw new IOException("invalid xml directory content", e);
  } finally {
    connection.disconnect();
  }
  return filechecksum;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:HftpFileSystem.java

示例4: instantiateXMLService

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public static Object instantiateXMLService(String serviceName) throws Exception {
    ClassLoader backup = Thread.currentThread().getContextClassLoader();
    try {
        // set thread context class loader to module class loader
        Thread.currentThread().setContextClassLoader(XMLFactoryHelper.class.getClassLoader());
        if (serviceName.equals("org.xml.sax.XMLReader"))
            return XMLReaderFactory.createXMLReader();
        else if (serviceName.equals("javax.xml.validation.SchemaFactory"))
            return Class.forName(serviceName).getMethod("newInstance", String.class)
                    .invoke(null, W3C_XML_SCHEMA_NS_URI);
        else
            return Class.forName(serviceName).getMethod("newInstance").invoke(null);
    } finally {
        Thread.currentThread().setContextClassLoader(backup);
    }

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

示例5: fillMaps

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
private static void fillMaps() throws IOException {
  Logger log = Logger.getInstance(UnsupportedFeaturesUtil.class.getName());
  FileReader reader = new FileReader(PythonHelpersLocator.getHelperPath("/tools/versions.xml"));
  try {
    XMLReader xr = XMLReaderFactory.createXMLReader();
    VersionsParser parser = new VersionsParser();
    xr.setContentHandler(parser);
    xr.parse(new InputSource(reader));
  }
  catch (SAXException e) {
    log.error("Improperly formed \"versions.xml\". " + e.getMessage());
  }
  finally {
    reader.close();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:UnsupportedFeaturesUtil.java

示例6: xsltprocess

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public void xsltprocess(String[] args) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException {
    // 1. Instantiate a TransformerFactory.
    SAXTransformerFactory tFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
    
    // 2. Use the TransformerFactory to process the stylesheet Source and
    //    generate a Transformer.
    InputStream is = getClass().getResourceAsStream("xmg2pol.xsl");
    Transformer transformer = tFactory.newTransformer (new StreamSource(is));
    transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "polarities.dtd,xml");
    transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
    
    // 3. Use the Transformer to transform an XML Source and send the
    //    output to a Result object.
    try {
	    String input = args[0];
	    String output= args[1];
	    SAXSource saxs = new SAXSource(new InputSource(input));
		XMLReader saxReader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
		saxReader.setEntityResolver(new MyEntityResolver());
		saxs.setXMLReader(saxReader);
	    transformer.transform(saxs, new StreamResult(new OutputStreamWriter(new FileOutputStream(output), "utf-8")));
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
}
 
开发者ID:spetitjean,项目名称:TuLiPA-frames,代码行数:26,代码来源:TransformPolarity.java

示例7: parse

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的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

示例8: testAnalyzePom

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
@Test
public void testAnalyzePom(){

    try {
        XMLReader xmlReader = XMLReaderFactory.createXMLReader();
        PomDependencyHandler handler = new PomDependencyHandler();
        xmlReader.setContentHandler(handler);
        xmlReader.parse(new InputSource(this.getClass().getClassLoader().getResourceAsStream("testpom.xml")));
        assertEquals(4, handler.getDependencies().size());
        PomInfo pom = handler.getPomInfo();
        boolean hasVI=false;
        for (PomDependency d : handler.getDependencies()) {
            assertNotNull(d.artifactId);
            assertNotNull(d.groupId);
            assertNotNull(d.version);
            if("framework-validateinternals".equals(d.artifactId)){
                hasVI=true;
                assertEquals(d.version,"0.9");
            }
        }
        assertTrue(hasVI);
    }catch (Exception e){
        e.printStackTrace();
    }

}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:27,代码来源:AnalyzerTest.java

示例9: parse

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public Danmakus parse() {
    if (this.mDataSource != null) {
        AndroidFileSource source = this.mDataSource;
        try {
            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
            XmlContentHandler contentHandler = new XmlContentHandler();
            xmlReader.setContentHandler(contentHandler);
            xmlReader.parse(new InputSource(source.data()));
            return contentHandler.getResult();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }
    return null;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:BiliDanmukuParser.java

示例10: processSource

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
protected Source processSource(Source source) {
	if (source instanceof StreamSource) {
		StreamSource streamSource = (StreamSource) source;
		InputSource inputSource = new InputSource(streamSource.getInputStream());
		try {
			XMLReader xmlReader = XMLReaderFactory.createXMLReader();
			String featureName = "http://xml.org/sax/features/external-general-entities";
			xmlReader.setFeature(featureName, isProcessExternalEntities());
			if (!isProcessExternalEntities()) {
				xmlReader.setEntityResolver(NO_OP_ENTITY_RESOLVER);
			}
			return new SAXSource(xmlReader, inputSource);
		}
		catch (SAXException ex) {
			logger.warn("Processing of external entities could not be disabled", ex);
			return source;
		}
	}
	else {
		return source;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:Jaxb2RootElementHttpMessageConverter.java

示例11: main

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的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

示例12: fetchList

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
private void fetchList(String path, boolean recur) throws IOException {
  try {
    XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(this);
    HttpURLConnection connection = openConnection(
        "/listPaths" + ServletUtil.encodePath(path),
        "ugi=" + getEncodedUgiParameter() + (recur ? "&recursive=yes" : ""));
    InputStream resp = connection.getInputStream();
    xr.parse(new InputSource(resp));
  } catch(SAXException e) {
    final Exception embedded = e.getException();
    if (embedded != null && embedded instanceof IOException) {
      throw (IOException)embedded;
    }
    throw new IOException("invalid xml directory content", e);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:HftpFileSystem.java

示例13: getContentSummary

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
/**
 * Connect to the name node and get content summary.
 * @param path The path
 * @return The content summary for the path.
 * @throws IOException
 */
private ContentSummary getContentSummary(String path) throws IOException {
  final HttpURLConnection connection = openConnection(
      "/contentSummary" + ServletUtil.encodePath(path),
      "ugi=" + getEncodedUgiParameter());
  InputStream in = null;
  try {
    in = connection.getInputStream();

    final XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(this);
    xr.parse(new InputSource(in));
  } catch(FileNotFoundException fnfe) {
    //the server may not support getContentSummary
    return null;
  } catch(SAXException saxe) {
    final Exception embedded = saxe.getException();
    if (embedded != null && embedded instanceof IOException) {
      throw (IOException)embedded;
    }
    throw new IOException("Invalid xml format", saxe);
  } finally {
    if (in != null) {
      in.close();
    }
    connection.disconnect();
  }
  return contentsummary;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:35,代码来源:HftpFileSystem.java

示例14: decode

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
/** This will unmarshal the input XML into a List of FormKey objects.
 * @param historyNavXml The XML representation of the historyNavList.
 * @return The List of FormKey objects.
 */
public static List decode(String historyNavXml) {
    List historyNavList = null;
    try {
        // The following step may seem out of place.
        // And the correct thing to do is to probably do a convertToHtml() on the String returned by the encode() method.
        // However, on a Post, the browser implicitly converts all the entities to corresponding characters.
        // Hence the need for the following step !!
        historyNavXml = StringHelper.replace(historyNavXml, "&", "&amp;");

        if (log.isDebugEnabled())
            log.debug("Unmarshalling the historyNavXml " + historyNavXml);
        XMLReader reader = XMLReaderFactory.createXMLReader();
        HistoryNavHandler handler = new HistoryNavHandler();
        reader.setContentHandler(handler);
        reader.parse(new InputSource(new BufferedReader(new StringReader(historyNavXml))));
        historyNavList = handler.getHistoryNavList();
    } catch (Exception e) {
        if (log.isInfoEnabled())
            log.info("Error while parsing the historyNavXml " + historyNavXml, e);
    }
    if (log.isDebugEnabled())
        log.debug("Unmarshalled List: " + historyNavList);
    return historyNavList;
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:29,代码来源:HistoryNav.java

示例15: main

import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的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


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