當前位置: 首頁>>代碼示例>>Java>>正文


Java TransformerHandler.getTransformer方法代碼示例

本文整理匯總了Java中javax.xml.transform.sax.TransformerHandler.getTransformer方法的典型用法代碼示例。如果您正苦於以下問題:Java TransformerHandler.getTransformer方法的具體用法?Java TransformerHandler.getTransformer怎麽用?Java TransformerHandler.getTransformer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.transform.sax.TransformerHandler的用法示例。


在下文中一共展示了TransformerHandler.getTransformer方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createTransformerHandler

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
public static TransformerHandler createTransformerHandler(final ErrorListener errorListener,
                                                          final boolean indentOutput) throws TransformerConfigurationException {
    final SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactoryFactory.newInstance();
    if (errorListener != null) {
        stf.setErrorListener(errorListener);
    }

    final TransformerHandler th = stf.newTransformerHandler();
    final Transformer transformer = th.getTransformer();
    setCommonOutputProperties(transformer, indentOutput);

    if (errorListener != null) {
        transformer.setErrorListener(errorListener);
    }

    return th;
}
 
開發者ID:gchq,項目名稱:stroom-stats,代碼行數:18,代碼來源:XMLUtil.java

示例2: JDependProcessorXML2

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
/**
 * Constructs a <code>JDepend</code> instance with the specified writer.
 * Creates a new instance of JDependProcessorXML
 *
 *
 * @param writer Writer.
 */
public JDependProcessorXML2(PrintWriter writer)  {
    super(writer);
    
    formatter = NumberFormat.getInstance(Locale.ENGLISH);
    formatter.setMaximumFractionDigits(2);
    
    try {
        SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        TransformerHandler hd = tf.newTransformerHandler();
        Transformer serializer = hd.getTransformer();
        serializer.setOutputProperty(OutputKeys.INDENT,"yes");
        
        // use getWriter as transform result destination
        hd.setResult(new StreamResult(this.getWriter()) );
        
        // create the XmlEmitter
        this.xmlEmitter = new XmlEmitter( hd );
    } catch (TransformerConfigurationException tce) {
        throw new XmlEmitterException(tce);
    }
}
 
開發者ID:bernhardhuber,項目名稱:netbeansplugins,代碼行數:29,代碼來源:JDependProcessorXML2.java

示例3: newRAFilter

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
@Override
public TransformerHandler newRAFilter(double min, double max) throws TransformerConfigurationException, SAXException, ParserConfigurationException,
        IOException {
    TransformerHandler retval = getTransformerHandler(getRAXsl());
    Transformer xformer = retval.getTransformer();
    xformer.setParameter("ra_min_hr", String.valueOf(min));
    xformer.setParameter("ra_max_hr", String.valueOf(max));
    return retval;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:AbstractFilterFactory.java

示例4: newDECFilter

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
@Override
public TransformerHandler newDECFilter(double min, double max) throws TransformerConfigurationException, SAXException, ParserConfigurationException,
        IOException {
    TransformerHandler retval = getTransformerHandler(getDECXsl());
    Transformer xformer = retval.getTransformer();
    xformer.setParameter("dec_min_deg", String.valueOf(min));
    xformer.setParameter("dec_max_deg", String.valueOf(max));
    return retval;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:AbstractFilterFactory.java

示例5: newRADECFilter

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
@Override
public TransformerHandler newRADECFilter(double rmin, double rmax, double dmin, double dmax) throws TransformerConfigurationException, SAXException,
        ParserConfigurationException, IOException {
    TransformerHandler retval = getTransformerHandler(getRADECXsl());
    Transformer xformer = retval.getTransformer();
    xformer.setParameter("ra_min_hr", String.valueOf(rmin));
    xformer.setParameter("ra_max_hr", String.valueOf(rmax));
    xformer.setParameter("dec_min_deg", String.valueOf(dmin));
    xformer.setParameter("dec_max_deg", String.valueOf(dmax));
    return retval;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:AbstractFilterFactory.java

示例6: newStellarTypeFilter

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
@Override
public TransformerHandler newStellarTypeFilter(String type) throws TransformerConfigurationException, SAXException, ParserConfigurationException,
        IOException {
    TransformerHandler retval = getTransformerHandler(getStellarXsl());
    Transformer xformer = retval.getTransformer();
    xformer.setParameter("type", type);
    return retval;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:AbstractFilterFactory.java

示例7: getTransformHandlerList

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
protected LinkedList<TransformerHandler> getTransformHandlerList(MCRParameterCollector parameterCollector)
    throws TransformerConfigurationException, SAXException {
    checkTemplateUptodate();
    LinkedList<TransformerHandler> xslSteps = new LinkedList<>();
    //every transformhandler shares the same ErrorListener instance
    MCRErrorListener errorListener = MCRErrorListener.getInstance();
    for (Templates template : templates) {
        TransformerHandler handler = tFactory.newTransformerHandler(template);
        parameterCollector.setParametersTo(handler.getTransformer());
        handler.getTransformer().setErrorListener(errorListener);
        if (TRACE_LISTENER_ENABLED) {
            TransformerImpl transformer = (TransformerImpl) handler.getTransformer();
            TraceManager traceManager = transformer.getTraceManager();
            try {
                traceManager.addTraceListener(TRACE_LISTENER);
            } catch (TooManyListenersException e) {
                LOGGER.warn("Could not add MCRTraceListener.", e);
            }
        }
        if (!xslSteps.isEmpty()) {
            Result result = new SAXResult(handler);
            xslSteps.getLast().setResult(result);
        }
        xslSteps.add(handler);
    }
    return xslSteps;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:28,代碼來源:MCRXSLTransformer.java

示例8: formatFile

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
private void formatFile(final Path in, final Path out) {
    try {
        final SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactoryFactory.newInstance();
        final TransformerHandler transformerHandler = stf.newTransformerHandler();
        final Transformer serializer = transformerHandler.getTransformer();

        serializer.setOutputProperty(OutputKeys.METHOD, "xml");
        serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");

        transformerHandler.setResult(new StreamResult(Files.newOutputStream(out)));

        final SAXParser parser = PARSER_FACTORY.newSAXParser();

        final WhiteSpaceStripper stripper = new WhiteSpaceStripper();
        stripper.setLexicalHandler(transformerHandler);
        stripper.setContentHandler(transformerHandler);

        final XMLReader xmlReader = parser.getXMLReader();
        xmlReader.setContentHandler(stripper);
        xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", stripper);

        // Do some final replacement on some text.
        String xsd = new String(Files.readAllBytes(in));

        // Strip out empty annotations.
        xsd = xsd.replaceAll("<xs:annotation\\s*/>", "");
        xmlReader.parse(new InputSource(new StringReader(xsd)));

    } catch (final Exception e) {
        System.out.println("Error processing file: " + in.toAbsolutePath().toString());
        e.printStackTrace();
    }
}
 
開發者ID:gchq,項目名稱:event-logging-schema,代碼行數:35,代碼來源:SchemaGenerator.java

示例9: outputAll

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
private void outputAll(Jar ajar[]) throws Exception {
    SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler hd = tf.newTransformerHandler();
    Transformer serializer = hd.getTransformer();
    serializer.setOutputProperty(OutputKeys.INDENT,"yes");
    hd.setResult(new StreamResult(this.writer));
    
    XmlEmitter xmlEmitter = new XmlEmitter( hd, ajar );
    xmlEmitter.emit();
    
    this.writer.flush();
    this.writer.close();
}
 
開發者ID:bernhardhuber,項目名稱:netbeansplugins,代碼行數:14,代碼來源:JarAnalyzerProcessor2.java

示例10: prepareTh

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
/**
 * Prepare TH instance for work This involves setting TrAX parameters and all
 * other stuff if needed
 *
 * @param th
 * @param params
 */
protected void prepareTh (final TransformerHandler th, final Hashtable <String, Object> params)
{
  if (CSTX.DEBUG)
    log.debug ("prepareTh()");

  final Transformer tr = th.getTransformer ();

  // make sure old parameters are cleaned
  tr.clearParameters ();

  // set transformation parameters
  if (!params.isEmpty ())
  {
    for (final Enumeration <String> e = params.keys (); e.hasMoreElements ();)
    {
      final String key = e.nextElement ();
      if (CSTX.DEBUG)
        log.debug ("prepareTh(): set parameter " + key + "=" + params.get (key));

      if (!key.startsWith (tmp_TRAX_ATTR_NS) && !key.startsWith (tmp_FILTER_ATTR_NS))
      {
        // ordinary parameter, set it to the TrAX object
        tr.setParameter (key, params.get (key));
      }
    }
  }
}
 
開發者ID:phax,項目名稱:ph-stx,代碼行數:35,代碼來源:THTrAXResolver.java

示例11: createTransformerHandler

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
/**
 * Creates a {@link TransformerHandler}.
 * 
 * @param commentHeader the comment header
 * @param rootTag the root tag
 * @param streamResult stream result
 */
public static TransformerHandler createTransformerHandler(String commentHeader, String rootTag,
		StreamResult streamResult, Charset charset)
		throws TransformerFactoryConfigurationError,
		TransformerConfigurationException, SAXException {
	SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
       try {
       	tf.setAttribute("indent-number", new Integer(2));
       } catch (Exception e) {
       	// ignore, workaround for JDK 1.5 bug, see http://forum.java.sun.com/thread.jspa?threadID=562510
       }
       TransformerHandler transformerHandler = tf.newTransformerHandler();
       Transformer serializer = transformerHandler.getTransformer();
       serializer.setOutputProperty(OutputKeys.ENCODING, charset.name());
       serializer.setOutputProperty(OutputKeys.METHOD, "xml");
       serializer.setOutputProperty(OutputKeys.INDENT, "yes");
       transformerHandler.setResult(streamResult);
       transformerHandler.startDocument();
       String newline = System.getProperty("line.separator");
       if (newline == null) {
       	newline = "\n";
       }
	commentHeader = (newline + commentHeader).replaceAll("\\n--", newline + " ");
	transformerHandler.characters("\n".toCharArray(), 0, 1);
       transformerHandler.comment(commentHeader.toCharArray(), 0, commentHeader.toCharArray().length);
	transformerHandler.characters("\n".toCharArray(), 0, 1);
	if (rootTag.length() > 0) {
		transformerHandler.startElement("", "", rootTag, null);
	}
       return transformerHandler;
}
 
開發者ID:P15,項目名稱:jailer,代碼行數:38,代碼來源:XmlUtil.java

示例12: openWriter

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
public void openWriter()
		throws SAXException {
	LOGGER.debug("openWriter()");
	
	if (xmlWriter != null) {
		throw new SAXException("Writer still open");
	} else {

		if (metaData == null) {
			throw new SAXException("Attempt to start writing XML without processing meta data to indicate which feed the data is for " + processFilePath);
		}
		
		
		String feed = metaData.get(StroomHeaderArguments.FEED);
		
		if (feed == null) {
			throw new StroomStreamException(StroomStatusCode.FEED_MUST_BE_SPECIFIED);
		}

		filePartCount ++;
		try {
			
			
			StroomZipOutputStream stroomZipOutputStream = feedToStroomZipOutputStreamMap.get(feed);
			if (stroomZipOutputStream == null) {
				stroomZipOutputStream = stroomZipRepository.getStroomZipOutputStream();
				LOGGER.debug("openWriter() - %s - Opened %s for feed %s", processFilePath, stroomZipOutputStream.getFinalFile(),feed);
				feedToStroomZipOutputStreamMap.put(feed, stroomZipOutputStream);
				fileCount ++;
			}
			// Close off last entry?
			OutputStream outputStream = feedToOutputStreamMap.get(feed);
			if (outputStream != null) {
				outputStream.close();
			}
			
			
			
			
			final SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory
					.newInstance();
			final TransformerHandler th = stf.newTransformerHandler();
			serializer = th.getTransformer();
			serializer.setOutputProperty(OutputKeys.METHOD, XML);
			serializer.setOutputProperty(OutputKeys.ENCODING, UTF_8);
			serializer.setOutputProperty(OutputKeys.INDENT, YES);
			metaData.write(stroomZipOutputStream.addEntry(new StroomZipEntry(null, String.valueOf(filePartCount), StroomZipFileType.Meta)), true);
			OutputStream dataStream = stroomZipOutputStream.addEntry(new StroomZipEntry(null, String.valueOf(filePartCount), StroomZipFileType.Data));
			feedToOutputStreamMap.put(feed, dataStream);
			th.setResult(new StreamResult(dataStream));
			xmlWriter = th;
			
			xmlWriter.startDocument();
			for (Map.Entry<String, String> prefix : startPrefixMapping.entrySet()) {
				xmlWriter.startPrefixMapping(prefix.getKey(), prefix.getValue());
			}
			xmlWriter.startElement(startElementUri, startElementLocalName, startElementQName, startElementAttributes);

		} catch (TransformerConfigurationException sax) {
			throw new SAXException(sax);
		} catch (IOException ioEx) {
			throw new SAXException(ioEx);
		}
	}
}
 
開發者ID:gchq,項目名稱:stroom-agent,代碼行數:66,代碼來源:HeadlessStroomFileProcessor.java

示例13: createXml

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
@Override
public void createXml(List<User> list, String fileName) throws Exception {
	Result resultXml = new StreamResult(new FileOutputStream(fileName)); // 輸出到person.xml
	SAXTransformerFactory sff = (SAXTransformerFactory) SAXTransformerFactory
			.newInstance();
	TransformerHandler th = sff.newTransformerHandler();
	th.setResult(resultXml);
	Transformer transformer = th.getTransformer();
	transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // 編碼格式是UTF-8
	transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // 換行

	// 開始xml文檔
	th.startDocument();

	th.startElement("", "", "users", null); // 定義users節點
	for (User user : list) {
		AttributesImpl attrs = new AttributesImpl();
		attrs.addAttribute("", "", "id", "", String.valueOf(user.getId()));

		th.startElement("", "", "user", attrs); // 定義user節點

		// 定義name節點
		th.startElement("", "", "name", null);
		th.characters(user.getName().toCharArray(), 0, user.getName()
				.length());
		th.endElement("", "", "name");
		// 定義age節點
		th.startElement("", "", "age", null);
		th.characters(String.valueOf(user.getAge()).toCharArray(), 0,
				String.valueOf(user.getAge()).toCharArray().length);
		th.endElement("", "", "age");
		// 定義sex節點
		th.startElement("", "", "sex", null);
		th.characters(user.getSex().toCharArray(), 0, user.getSex()
				.length());
		th.endElement("", "", "sex");

		th.endElement("", "", "user"); // 結束user節點
	}
	th.endElement("", "", "users"); // 結束users節點

	// 結束xml文檔
	th.endDocument();
}
 
開發者ID:xuxueli,項目名稱:xxl-incubator,代碼行數:45,代碼來源:XmlSaxImpl.java

示例14: generate

import javax.xml.transform.sax.TransformerHandler; //導入方法依賴的package包/類
public void generate(Values values) throws IOException {
    File dimenFile = values.dimenFile;
    FileOutputStream fos = new FileOutputStream(dimenFile);
    StreamResult result = new StreamResult(fos);
    SAXTransformerFactory sff = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler th = null;
    try {
        th = sff.newTransformerHandler();
        Transformer transformer = th.getTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");

        th.setResult(result);

        th.startDocument();

        AttributesImpl attr = new AttributesImpl();
        char[] space = "\n".toCharArray();
        th.characters(space, 0, space.length);
        th.startElement("", "", "resources", attr);

        List<Dimen> dimens = values.dimens;
        char[] spaceChar = "\n    ".toCharArray();
        for (Dimen dimen : dimens) {
            //white space
            th.characters(spaceChar, 0, spaceChar.length);
            //name attr
            attr.addAttribute("", "", "name", String.class.getName(), dimen.name);
            th.startElement("", "", "dimen", attr);
            char[] valueChars = String.format("%spx", dimen.value).toCharArray();
            th.characters(valueChars, 0, valueChars.length);
            th.endElement("", "", "dimen");
        }

        th.endElement("", "", "resources");
        th.endDocument();

    } catch (TransformerConfigurationException | SAXException e) {
        e.printStackTrace();
    } finally {
        fos.close();
    }
}
 
開發者ID:succlz123,項目名稱:AndroidPixelDimenGenerator,代碼行數:44,代碼來源:SAXGenerator.java


注:本文中的javax.xml.transform.sax.TransformerHandler.getTransformer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。