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


Java XMLFilter.parse方法代码示例

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


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

示例1: testcase10

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
 * Unit test for contentHandler setter/getter along reader as handler's
 * parent.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase10() throws Exception {
    String outputFile = USER_DIR + "saxtf010.out";
    String goldFile = GOLDEN_DIR + "saxtf010GF.out";
    // The transformer will use a SAX parser as it's reader.
    XMLReader reader = XMLReaderFactory.createXMLReader();
    SAXTransformerFactory saxTFactory
            = (SAXTransformerFactory)TransformerFactory.newInstance();
    XMLFilter filter =
        saxTFactory.newXMLFilter(new StreamSource(XSLT_FILE));
    filter.setParent(reader);
    filter.setContentHandler(new MyContentHandler(outputFile));

    // Now, when you call transformer.parse, it will set itself as
    // the content handler for the parser object (it's "parent"), and
    // will then call the parse method on the parser.
    filter.parse(new InputSource(XML_FILE));
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:SAXTFactoryTest.java

示例2: testcase12

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
 * Unit test for contentHandler setter/getter.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase12() throws Exception {
    String outputFile = USER_DIR + "saxtf012.out";
    String goldFile = GOLDEN_DIR + "saxtf012GF.out";
    // The transformer will use a SAX parser as it's reader.
    XMLReader reader = XMLReaderFactory.createXMLReader();

    InputSource is = new InputSource(new FileInputStream(XSLT_FILE));
    SAXSource saxSource = new SAXSource();
    saxSource.setInputSource(is);

    SAXTransformerFactory saxTFactory = (SAXTransformerFactory)TransformerFactory.newInstance();
    XMLFilter filter = saxTFactory.newXMLFilter(saxSource);

    filter.setParent(reader);
    filter.setContentHandler(new MyContentHandler(outputFile));

    // Now, when you call transformer.parse, it will set itself as
    // the content handler for the parser object (it's "parent"), and
    // will then call the parse method on the parser.
    filter.parse(new InputSource(XML_FILE));
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:SAXTFactoryTest.java

示例3: testcase13

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
 * Unit test for TemplatesHandler setter/getter.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase13() throws Exception {
    String outputFile = USER_DIR + "saxtf013.out";
    String goldFile = GOLDEN_DIR + "saxtf013GF.out";
    try(FileInputStream fis = new FileInputStream(XML_FILE)) {
        // The transformer will use a SAX parser as it's reader.
        XMLReader reader = XMLReaderFactory.createXMLReader();

        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory) TransformerFactory.newInstance();
        TemplatesHandler thandler = saxTFactory.newTemplatesHandler();
        // I have put this as it was complaining about systemid
        thandler.setSystemId("file:///" + USER_DIR);

        reader.setContentHandler(thandler);
        reader.parse(XSLT_FILE);
        XMLFilter filter
                = saxTFactory.newXMLFilter(thandler.getTemplates());
        filter.setParent(reader);

        filter.setContentHandler(new MyContentHandler(outputFile));
        filter.parse(new InputSource(fis));
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:SAXTFactoryTest.java

示例4: unmarshal

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
protected org.kuali.rice.core.impl.config.property.Config unmarshal(Unmarshaller unmarshaller, InputStream in)
        throws SAXException, ParserConfigurationException, IOException,
        IllegalStateException, JAXBException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);

    XMLFilter filter = new ConfigNamespaceURIFilter();
    filter.setParent(spf.newSAXParser().getXMLReader());

    UnmarshallerHandler handler = unmarshaller.getUnmarshallerHandler();
    filter.setContentHandler(handler);

    filter.parse(new InputSource(in));

    return (org.kuali.rice.core.impl.config.property.Config) handler.getResult();
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:17,代码来源:JAXBConfigImpl.java

示例5: testcase11

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
 * Unit test for contentHandler setter/getter with parent.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase11() throws Exception {
    String outputFile = USER_DIR + "saxtf011.out";
    String goldFile = GOLDEN_DIR + "saxtf011GF.out";
    // The transformer will use a SAX parser as it's reader.
    XMLReader reader = XMLReaderFactory.createXMLReader();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder docBuilder = dbf.newDocumentBuilder();
    Document document = docBuilder.parse(new File(XSLT_FILE));
    Node node = (Node)document;
    DOMSource domSource= new DOMSource(node);

    SAXTransformerFactory saxTFactory
            = (SAXTransformerFactory)TransformerFactory.newInstance();
    XMLFilter filter = saxTFactory.newXMLFilter(domSource);

    filter.setParent(reader);
    filter.setContentHandler(new MyContentHandler(outputFile));

    // Now, when you call transformer.parse, it will set itself as
    // the content handler for the parser object (it's "parent"), and
    // will then call the parse method on the parser.
    filter.parse(new InputSource(XML_FILE));
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:SAXTFactoryTest.java

示例6: unmarshal

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public static Object unmarshal(String path, String contextPath, String namespace)
        throws JAXBException, SAXException, ParserConfigurationException,
        IOException {
    UnmarshallerHandler unmarshallerHandler = JAXBContext
            .newInstance(contextPath).createUnmarshaller()
            .getUnmarshallerHandler();
    XMLFilter xmlFilter = new NamespaceFilter(namespace);
    xmlFilter.setParent(
            SAXParserFactory.newInstance().newSAXParser().getXMLReader());
    xmlFilter.setContentHandler(unmarshallerHandler);
    xmlFilter.parse(new InputSource(Thread.currentThread()
            .getContextClassLoader().getResource(path).getPath()));
    return unmarshallerHandler.getResult();
}
 
开发者ID:sandor-balazs,项目名称:sentiment-analysis,代码行数:15,代码来源:AbstractXmlParser.java

示例7: unmarshal

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public static Model unmarshal(InputSource inputSource){
    try {
        JAXBContext jc = JAXBContext.newInstance(Model.class);
        XMLFilter filter = new NamespaceFilter();
        filter.setParent(SAXParserFactory.newInstance().newSAXParser().getXMLReader());
        UnmarshallerHandler unmarshallerHandler = jc.createUnmarshaller().getUnmarshallerHandler();
        filter.setContentHandler(unmarshallerHandler);
        filter.parse(inputSource);
        return (Model) ((JAXBElement)unmarshallerHandler.getResult()).getValue();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
}
 
开发者ID:ThoughtWorksInc,项目名称:go-plugin-util,代码行数:14,代码来源:Model.java

示例8: main

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public static void main(String[] args)
        throws TransformerException, TransformerConfigurationException,
        SAXException, IOException
{
    // Instantiate  a TransformerFactory.
    TransformerFactory tFactory = TransformerFactory.newInstance();
    // Determine whether the TransformerFactory supports The use uf SAXSource
    // and SAXResult
    if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE)) {
        // Cast the TransformerFactory to SAXTransformerFactory.
        SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
        // Create an XMLFilter for each stylesheet.
        XMLFilter xmlFilter = saxTFactory.newXMLFilter(new StreamSource("C:\\Users\\Gian\\Desktop\\config.xsl"));

        // Create an XMLReader.
        XMLReader reader = XMLReaderFactory.createXMLReader();

        // xmlFilter uses the XMLReader as its reader.
        xmlFilter.setParent(reader);

        // xmlFilter3 outputs SAX events to the serializer.
        java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
        xmlProps.setProperty("indent", "yes");
        xmlProps.setProperty("standalone", "no");

        FileOutputStream fileOutputStream = null;
        File file = null;

        try {

            file = new File("C:\\Users\\Gian\\Desktop\\target.profile");
            file.createNewFile();
            fileOutputStream = new FileOutputStream(file);

            Serializer serializer = SerializerFactory.getSerializer(xmlProps);
            serializer.setOutputStream(fileOutputStream);

            xmlFilter.setContentHandler(serializer.asContentHandler());
            xmlFilter.parse(new InputSource("C:\\Users\\Gian\\Desktop\\Enterprise - Area Channel Sales Manager.profile"));

        } catch(IOException ex){

        } finally {
            fileOutputStream.close();
        }
    }
}
 
开发者ID:piegandolfi,项目名称:SalesforceProfiler,代码行数:48,代码来源:UtilsXsl.java

示例9: exampleXMLFilter

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
 * Show the Transformer as a simple XMLFilter. This is pretty similar to
 * exampleXMLReader, except that here the parent XMLReader is created by the
 * caller, instead of automatically within the XMLFilter. This gives the
 * caller more direct control over the parent reader.
 */
public static boolean exampleXMLFilter (final String sourceID, final String stxID) throws TransformerException,
                                                                                   TransformerConfigurationException,
                                                                                   SAXException,
                                                                                   IOException // ,
                                                                                               // ParserConfigurationException
{

  final TransformerFactory tfactory = TransformerFactory.newInstance ();

  XMLReader reader = null;

  // Use JAXP1.1 ( if possible )

  try
  {

    final javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance ();

    factory.setNamespaceAware (true);

    final javax.xml.parsers.SAXParser jaxpParser = factory.newSAXParser ();

    reader = jaxpParser.getXMLReader ();

  }
  catch (final javax.xml.parsers.ParserConfigurationException ex)
  {
    throw new org.xml.sax.SAXException (ex);
  }
  catch (final javax.xml.parsers.FactoryConfigurationError ex1)
  {
    throw new org.xml.sax.SAXException (ex1.toString ());
  }
  catch (final NoSuchMethodError ex2)
  {}

  if (reader == null)
    reader = XMLReaderFactory.createXMLReader ();

  // The transformer will use a SAX parser as it's reader.
  reader.setContentHandler (new ContentHandlerTest ());
  try
  {
    reader.setFeature ("http://xml.org/sax/features/namespace-prefixes", true);
    reader.setFeature ("http://apache.org/xml/features/validation/dynamic", true);
  }
  catch (final SAXException se)
  {
    se.printStackTrace ();
  }

  final XMLFilter filter = ((SAXTransformerFactory) tfactory).newXMLFilter (_getSource (stxID));

  filter.setParent (reader);

  // Now, when you call transformer.parse, it will set itself as
  // the content handler for the parser object (it's "parent"), and
  // will then call the parse method on the parser.
  filter.parse (_getInputSource (sourceID));

  return true;
}
 
开发者ID:phax,项目名称:ph-stx,代码行数:69,代码来源:TestCases.java

示例10: extractMorph

import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public static void extractMorph(ExtractionProperties extractProps)
		throws TransformerException, TransformerConfigurationException,
		SAXException, IOException, JDOMException {

	System.out.println("Extracting morph:");
	System.out.println("Generating morph.xml");

	TransformerFactory tFactory = TransformerFactory.newInstance();

	File morphFile = new File(new File(extractProps.destDir), "morph.xml");
	File tempFile = new File(new File(extractProps.tempDir), "temp.xml");

	if (tFactory.getFeature(SAXSource.FEATURE)
			&& tFactory.getFeature(SAXResult.FEATURE)) {

		SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);

		ArrayList<XMLFilter> filterChain = new ArrayList<XMLFilter>();
		ArrayList<String> xslChain = new ArrayList<String>();

		if (extractProps.macroSpecs.length() > 0) {

		}

		addTransforms(xslChain, extractProps.macroSpecs);

		for (String xslFile : xslChain)
			filterChain.add(saxTFactory.newXMLFilter(ExtractGrammar
					.getSource(xslFile)));
		// Create an XMLReader and set first xsl transform to that.
		XMLReader reader = XMLReaderFactory.createXMLReader();
		XMLFilter xmlFilter0 = filterChain.get(0);
		xmlFilter0.setParent(reader);

		//Create chain of xsl transforms
		// Create an XMLFilter for each stylesheet.
		for (int i = 1; i < filterChain.size(); i++) {
			XMLFilter xmlFilterPrev = filterChain.get(i - 1);
			XMLFilter xmlFilterCurr = filterChain.get(i);
			xmlFilterCurr.setParent(xmlFilterPrev);
		}

		XMLFilter xmlFilter = filterChain.get(filterChain.size() - 1);

		java.util.Properties xmlProps = OutputPropertiesFactory
				.getDefaultMethodProperties("xml");
		xmlProps.setProperty("indent", "yes");
		xmlProps.setProperty("standalone", "no");
		xmlProps.setProperty("{http://xml.apache.org/xalan}indent-amount",
				"2");
		Serializer serializer = SerializerFactory.getSerializer(xmlProps);
		serializer.setOutputStream(new FileOutputStream(morphFile));
		//XMLFilter xmlFilter = xmlFilter2;
		//XMLFilter xmlFilter = xmlFilter3;

		xmlFilter.setContentHandler(serializer.asContentHandler());
		xmlFilter.parse(new InputSource(tempFile.getPath()));
	}

	//Deleting the temporary lex file
	//tempFile.delete();
}
 
开发者ID:OpenCCG,项目名称:openccg,代码行数:63,代码来源:MorphExtract.java


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