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


Java Serializer类代码示例

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


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

示例1: getDestination

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
private Destination getDestination(WebApp webApp, Destination destination, PipelineStep step) {
  if (webApp.getDevelopmentMode() && step.getLog()) {
    StringWriter sw = new StringWriter();
    sw.write("----------\n");
    sw.write("OUTPUT OF STEP: \"" + step.getName() + "\":\n");            
    Serializer debugSerializer = webApp.getProcessor().newSerializer(new ProxyWriter(sw) {
      @Override
      public void flush() throws IOException {        
        logger.debug(out.toString());                
      }
    });                
    debugSerializer.setOutputProperty(Serializer.Property.METHOD, "xml");
    debugSerializer.setOutputProperty(Serializer.Property.INDENT, "yes");
    if (destination instanceof XdmDestination) {
      destination = new TeeSourceDestination((XdmDestination) destination, debugSerializer);
    } else {
      destination = new TeeDestination(destination, debugSerializer);
    }
  }
  return destination;
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:22,代码来源:XSLWebServlet.java

示例2: processInlineEntry

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
private void processInlineEntry(String uri, String localName, String qName, Attributes attributes) throws Exception {
  String name = attributes.getValue("", "name");
  if (name == null) {
    throw new SAXException("No attribute \"name\" specified on inline-entry element");
  }
  Serializer serializer = webApp.getProcessor().newSerializer(this.zos);    
  for (int i=0; i<attributes.getLength(); i++) {
    String n = attributes.getLocalName(i);
    if (n.equals("name")) {
      continue;
    }
    String value = attributes.getValue(i);
    if (n.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
      value = value.replaceAll("\\{\\}", "{''}");
    }
    serializer.setOutputProperty(Property.get(n), value);             
  }
  ZipEntry entry = new ZipEntry(name);
  zos.putNextEntry(entry);        
  this.xsw = serializer.getXMLStreamWriter();     
  this.serializingHandler = new ContentHandlerToXMLStreamWriter(xsw);
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:23,代码来源:ZipSerializer.java

示例3: evaluateXQuery

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
/**
 * Executes a given XQuery expression on the given XML.
 * @param xml is the XQuery data source
 * @param query is the query expression
 * @return with the query result as String
 * @throws SaxonApiException was thrown when the XQuery execution is failed
 */
public String evaluateXQuery(final String xml, final String query) throws SaxonApiException {
    Processor processor = processorFactory.createProcessor();
    XQueryCompiler xqueryCompiler = processor.newXQueryCompiler();
    xqueryCompiler.setErrorListener(errorListener);
    XQueryExecutable xqueryExec = xqueryCompiler.compile(query);
    XQueryEvaluator xqueryEval = xqueryExec.load();
    xqueryEval.setErrorListener(errorListener);
    SAXSource requestXml = saxSourceFactory.createSAXSource(inputSourceFactory.createInputSource(xml));
    xqueryEval.setSource(requestXml);
    ByteArrayOutputStream baos = byteArrayOutputStreamFactory.createByteArrayOutputStream();
    Serializer ser = serializerFactory.createSerializer(baos);
    xqueryEval.setDestination(ser);
    xqueryEval.run();
    return baos.toString();
}
 
开发者ID:epam,项目名称:Wilma,代码行数:23,代码来源:XQueryExpressionEvaluator.java

示例4: WikiI5Processor

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
public WikiI5Processor(I5Corpus corpus, String inflectives) throws I5Exception {
	if (corpus == null){
		throw new IllegalArgumentException("I5Corpus cannot be null.");
	}
	
	this.corpus = corpus;
	this.xPathFactory = XPathFactory.newInstance();
	this.xPath = xPathFactory.newXPath();
	this.processor = new Processor(true);
	this.serializer = new Serializer();
	
	String errorFilename = corpus.getDumpFilename().substring(0,15) + "-"+ 
			corpus.getType(); 
	errorHandler = new I5ErrorHandler(errorFilename);
	// Set temporary i5 file
	tempI5 = new File(corpus.getLang()+"wiki-"+corpus.getType()+"-temp.i5");
			
	setSerializer(corpus.getEncoding());
	setTransformer(inflectives);		
	setXmlBuilder(); // Setting a document builder for reading XML 		
	setXmlReader(); // Setting an XML reader for DTD validation
}
 
开发者ID:IDS-Mannheim,项目名称:Wikipedia-Corpus-Converter,代码行数:23,代码来源:WikiI5Processor.java

示例5: OutputPropertyEntry

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
public OutputPropertyEntry(Serializer.Property saxonProp, String... values) {
    super();
    this.saxonProp=saxonProp;
    if(values!=null && values.length>0) {
        Arrays.sort(values);
        validValuesList = Arrays.asList(values);
    }
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:9,代码来源:Output.java

示例6: doTest

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
@Test
public void doTest() throws SaxonApiException, FileNotFoundException, IOException {
    Configuration config = Configuration.newConfiguration();
    Processor processor = new Processor(config);
    XsltTransformer transformer = processor.newXsltCompiler().compile(new StreamSource("src/test/resources/identity.xsl")).load();
    Serializer serializer = processor.newSerializer(new File("target/generated-test-files/output.xml"));
    FileAppenderStep fas = new FileAppenderStep();
    fas.setParameter(FileAppenderStep.FILE_NAME, new XdmAtomicValue("target/generated-test-files/appendee.txt"));
    fas.setParameter(FileAppenderStep.VALUE, new XdmAtomicValue("blablabla"));
    fas.setParameter(FileAppenderStep.LINE_SEPARATOR, new XdmAtomicValue("LF"));
    fas.setDestination(serializer);
    transformer.setDestination(fas);
    transformer.setSource(new StreamSource("src/test/resources/source.xml"));
    File expect = new File("target/generated-test-files/appendee.txt");
    if(expect.exists()) expect.delete();
    transformer.transform();
    assertTrue(expect.isFile());
    BufferedReader br = new BufferedReader(new FileReader(expect));
    char[] buff = new char[30];
    int ret = br.read(buff);
    br.close();
    assertEquals(10, ret);
    char[] ex = new char[] { 'b', 'l', 'a', 'b', 'l', 'a', 'b', 'l', 'a', '\n'};
    assertArrayEquals(ex, Arrays.copyOf(buff, ret));
    fas.setDestination(processor.newSerializer(new File("target/generated-test-files/output2.xml")));
    transformer.transform();
    br = new BufferedReader(new FileReader(expect));
    ret = br.read(buff);
    br.close();
    assertEquals(20, ret);
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:32,代码来源:FileAppenderStepTest.java

示例7: getSerializer

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
/**
 * Return indenting XML serializer
 * 
 * @return Saxon serializer 
 */
private static Serializer getSerializer() {
	Configuration config = new Configuration();
	Processor processor = new Processor(config);
	Serializer s = processor.newSerializer();
	s.setOutputProperty(Property.METHOD, "xml");
	s.setOutputProperty(Property.ENCODING, "utf-8");
	s.setOutputProperty(Property.INDENT, "yes");
	return s;
}
 
开发者ID:Fedict,项目名称:dcattools,代码行数:15,代码来源:EDP.java

示例8: main

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
/**
   * Main program
   * 
   * @param args 
   */
  public static void main(String[] args)  {
      logger.info("-- START --");
      if (args.length < 2) {
          logger.error("No input or output file");
          System.exit(-1);
      }
      
      Optional<RDFFormat> fmtin = Rio.getParserFormatForFileName(args[0]);
      if(!fmtin.isPresent()) {
          logger.error("No parser for input {}", args[0]);
          System.exit(-2);
      }
      
      int code = 0;
      Repository repo = new SailRepository(new MemoryStore());
repo.initialize();

Serializer s = getSerializer();		
s.setOutputFile(new File(args[1]));
	
      try (RepositoryConnection con = repo.getConnection()) {
          con.add(new File(args[0]), "http://data.gov.be", fmtin.get());
	
	XMLStreamWriter w = s.getXMLStreamWriter();

	w.writeStartDocument();
	writeCatalog(w, con);
	w.writeEndDocument();
	
	w.close();		
} catch (IOException|XMLStreamException|SaxonApiException ex) {
          logger.error("Error converting", ex);
          System.exit(-1);
      } finally {
	repo.shutDown();
}
  }
 
开发者ID:Fedict,项目名称:dcattools,代码行数:43,代码来源:EDP.java

示例9: getOutput

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
/** Retrieves the output for a given xslt transformer.
 * @param xsltTransformer the {@link XsltTransformer} that will receive the output
 * @return the output as a {@link ByteArrayOutputStream}
 */
public ByteArrayOutputStream getOutput(final XsltTransformer xsltTransformer) {
    Serializer serializer = serializerFactory.createSerializer();
    serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
    serializer.setOutputProperty(Serializer.Property.INDENT, "no");
    ByteArrayOutputStream output = byteArrayOutputStreamFactory.createByteArrayOutputStream();
    serializer.setOutputStream(output);
    xsltTransformer.setDestination(serializer);
    return output;
}
 
开发者ID:epam,项目名称:Wilma,代码行数:14,代码来源:XslOutputProvider.java

示例10: createSerializer

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
private static Serializer createSerializer(final OutputStream out) {
  Serializer serializer = new Serializer();
  serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
  serializer.setOutputProperty(Serializer.Property.ENCODING, "UTF-8");
  serializer.setOutputProperty(Serializer.Property.INDENT, "yes");
  serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");
  serializer.setOutputStream(out);
  return serializer;
}
 
开发者ID:CoreFiling,项目名称:reviki,代码行数:10,代码来源:XQueryMacro.java

示例11: runApp

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
@Override
public void runApp() throws Exception {
    doAdditionalConfiguration(processor);
    Serializer out = prepareSerializer();
    XQueryCompiler compiler = processor.newXQueryCompiler();
    XQueryExecutable executable = compiler.compile(new File(config.getMainFile()));
    setMainModule(executable.getUnderlyingCompiledQuery().getMainModule());
    XQueryEvaluator evaluator = executable.load();
    bindContextItem(evaluator);
    bindVariables(evaluator);
    evaluator.run(out);
}
 
开发者ID:ligasgr,项目名称:intellij-xquery,代码行数:13,代码来源:SaxonRunnerApp.java

示例12: FormattingXMLStreamWriterBuilder

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
FormattingXMLStreamWriterBuilder(Serializer serializer, Flushable flushable) {
  _serializer = serializer;
  _flushable = flushable;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:5,代码来源:FormattingXmlStreamWriter.java

示例13: doFilter

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
    throws IOException, ServletException {
  WebApp webApp = null;
  HttpServletRequest req = (HttpServletRequest) request;
  HttpServletResponse resp = (HttpServletResponse) response;
  try {             
    webApp = (WebApp) request.getAttribute(Definitions.ATTRNAME_WEBAPP);    
    RequestSerializer requestSerializer = new RequestSerializer(req, webApp);
    try {
      NodeInfo requestNodeInfo = requestSerializer.serializeToNodeInfo();
      request.setAttribute(Definitions.ATTRNAME_REQUESTXML, requestNodeInfo);      
      if (webApp.getDevelopmentMode()) {
        StringWriter sw = new StringWriter();
        try {
          Serializer ser = webApp.getProcessor().newSerializer(sw);
          ser.setOutputProperty(Serializer.Property.INDENT, "yes");
          ser.serializeNode(new XdmNode(requestNodeInfo));
          logger.debug("----------\nREQUEST XML:" + lineSeparator + sw.toString());
        } finally {
          sw.close();
        }
      }      
      chain.doFilter(request, response);        
    } finally {
      requestSerializer.close();
    }
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
    if (webApp != null && webApp.getDevelopmentMode()) {              
      resp.setContentType("text/plain; charset=UTF-8");        
      e.printStackTrace(new PrintStream(resp.getOutputStream()));        
    } else if (!resp.isCommitted()) {
      resp.resetBuffer();
      resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      resp.setContentType("text/html; charset=UTF-8");
      Writer w = new OutputStreamWriter(resp.getOutputStream(), "UTF-8");
      w.write("<html><body><h1>Internal Server Error</h1></body></html>");
    }
  }
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:42,代码来源:RequestSerializerFilter.java

示例14: init

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
/**
 * Initialization to improve performance for repetitive invocations of filter and evaluate expressions
 * 
 * @throws XPathException
 */
private void init() throws XPathException {
	
	try {
		
		// Get the processor
		proc = new Processor(false);

		// Set any specified configuration properties for the processor
		if (featureMappings != null) {
			for (Entry<String, Object> entry : featureMappings.entrySet()) {
				proc.setConfigurationProperty(entry.getKey(), entry.getValue());
			}
		}
		
		//proc.setConfigurationProperty(FeatureKeys.ENTITY_RESOLVER_CLASS, "com.elsevier.spark_xml_utils.common.IgnoreDoctype");
		
		// Get the XPath compiler
		XPathCompiler xpathCompiler = proc.newXPathCompiler();

		// Set the namespace to prefix mappings
		this.setPrefixNamespaceMappings(xpathCompiler, namespaceMappings);

		// Compile the XPath expression  and get a document builder
		xsel = xpathCompiler.compile(xPathExpression).load();
		builder = proc.newDocumentBuilder();
	
		// Create and initialize the serializer  
		baos = new ByteArrayOutputStream();
		serializer = proc.newSerializer(baos);
		serializer.setOutputStream(baos);
		serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
		serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION,"yes");			
		serializer.setProcessor(proc);
	
	} catch (SaxonApiException e) {
		
		log.error("Problems creating an XPathProcessor.  " + e.getMessage(),e);
		throw new XPathException(e.getMessage());

	}
	
}
 
开发者ID:elsevierlabs-os,项目名称:spark-xml-utils,代码行数:48,代码来源:XPathProcessor.java

示例15: init

import net.sf.saxon.s9api.Serializer; //导入依赖的package包/类
/**
 * Initialization to improve performance for repetitive invocations of evaluate expressions
 * 
 * @throws XQueryException
 */
private void init() throws XQueryException {
	
	try {
		
		// Get the processor
		proc = new Processor(false);

		// Set any specified configuration properties for the processor
		if (featureMappings != null) {
			for (Entry<String, Object> entry : featureMappings.entrySet()) {
				proc.setConfigurationProperty(entry.getKey(), entry.getValue());
			}
		}
		
		// Get the XQuery compiler
		XQueryCompiler xqueryCompiler = proc.newXQueryCompiler();
		xqueryCompiler.setEncoding(CharEncoding.UTF_8);

		// Set the namespace to prefix mappings
		this.setPrefixNamespaceMappings(xqueryCompiler, namespaceMappings);

		// Compile the XQuery expression and get an XQuery evaluator
		exp = xqueryCompiler.compile(xQueryExpression);
		eval = exp.load();
		
		// Create and initialize the serializer 
		baos = new ByteArrayOutputStream();
		serializer = proc.newSerializer(baos);
		// Appears ok to always set output property to xml (even if we are just returning a text string)
		serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
		serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION,"yes");
		serializer.setProcessor(proc);
		
	} catch (SaxonApiException e) {
		
		log.error("Problems creating an XQueryProcessor.  " + e.getMessage(),e);
		throw new XQueryException(e.getMessage());

	}
	
}
 
开发者ID:elsevierlabs-os,项目名称:spark-xml-utils,代码行数:47,代码来源:XQueryProcessor.java


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