There are 1 code examples for javax.xml.transform.Source.

The API names are highlighted below. You can use suckoo button to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.

Project Name: jbidwatcher Package: com.jbidwatcher.auction

Source Code: AuctionTransformer.java (Click to view .java file)

Method Code:
vote
like

public static StringBuffer outputHTML(String loadFile,String xmlOutputFile){
  InputStream xmlIn=null;
  InputStream xslIn=null;
  FileOutputStream htmlOut=null;
  try {
    try {
      xmlIn=new FileInputStream(loadFile);
    }
 catch (    FileNotFoundException fnfe) {
      xmlIn=new StringBufferInputStream("<?xml version=\"1.0\"?>\n" + "\n" + "<!DOCTYPE auctions SYSTEM \"http://www.jbidwatcher.com/auctions.dtd\">\n"+ "<jbidwatcher format=\"0101\">"+ "<auctions count=\"0\">"+ "</auctions>"+ "</jbidwatcher>");
    }
    Source xmlSource=new StreamSource(xmlIn);
    String xsltInputFile="auctionTransform.xsl";
    xslIn=JConfig.bestSource(AuctionTransformer.class.getClassLoader(),xsltInputFile);
    Source xsltSource=new StreamSource(xslIn);
    Result transResult;
    StringWriter sw=null;
    if (xmlOutputFile == null) {
      sw=new StringWriter();
      transResult=new StreamResult(sw);
    }
 else {
      htmlOut=new FileOutputStream(xmlOutputFile);
      transResult=new StreamResult(htmlOut);
    }
    TransformerFactory tf=TransformerFactory.newInstance();
    Transformer t=tf.newTransformer(xsltSource);
    t.setErrorListener(new AuctionTransformer());
    t.transform(xmlSource,transResult);
    if (xmlOutputFile == null)     return sw.getBuffer();
  }
 catch (  Exception ignored) {
    ignored.printStackTrace();
  }
 finally {
    try {
      if (xmlIn != null)       xmlIn.close();
      if (xslIn != null)       xslIn.close();
      if (htmlOut != null)       htmlOut.close();
    }
 catch (    IOException ignored) {
    }
  }
  return null;
}