KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > business > TransformManagerImpl


1 package org.enhydra.snapper.business;
2 /**
3  * @author Milin Radivoj
4  *
5  */

6 import javax.xml.transform.stream.StreamSource JavaDoc;
7 //import javax.xml.transform.dom.DOMResult;
8
import javax.xml.transform.TransformerFactory JavaDoc;
9 import javax.xml.transform.Transformer JavaDoc;
10
11 import org.enhydra.snapper.Log;
12 import org.enhydra.snapper.spec.*;
13 import java.io.*;
14
15 public class TransformManagerImpl implements TransformManager{
16
17     
18 public String JavaDoc transform(String JavaDoc content,String JavaDoc xslPath)throws Exception JavaDoc{
19     
20     try{
21     TransformerFactory JavaDoc tFactory = TransformerFactory.newInstance();
22     Transformer JavaDoc transformer = tFactory.newTransformer(new StreamSource JavaDoc(xslPath));
23         
24    
25       StringWriter stringWriter= new StringWriter();
26       transformer.transform(new StreamSource JavaDoc(new StringReader(content)),new javax.xml.transform.stream.StreamResult JavaDoc
27                         (stringWriter) );
28       String JavaDoc result=stringWriter.toString();
29       return result;
30     }catch(Exception JavaDoc e)
31       {
32         Log.logException(e);
33           return new String JavaDoc();
34       }
35  }
36
37
38 }
Popular Tags