Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.ken.util;
 
 
 
This class handles XSLT transformations.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 public class ContentTransformer {
     private static final Logger LOG = Logger.getLogger(ContentTransformer.class);
 
     private static final class LoggingErrorListener implements ErrorListener {
         private final ErrorListener delegate;
         public LoggingErrorListener(ErrorListener delegate) {
             this. = delegate;
         }
 
         public void error(TransformerException exceptionthrows TransformerException {
             .error("Error transforming document"exception);
         }
 
         public void fatalError(TransformerException exceptionthrows TransformerException {
             if ( != null) {
                 .fatalError(exception);
             } else {
                 throw exception;
             }
             
         }
 
         public void warning(TransformerException exceptionthrows TransformerException {
             .warn("Error transforming document"exception);
         }
         
     };
 
     private Transformer transformer;

    
Constructs a ContentTransformer.java.

Parameters:
aStyleSheet
Throws:
java.lang.Exception
 
     public ContentTransformer(StreamSource aStyleSheetthrows Exception {
         // create transformer        
         TransformerFactory factory = TransformerFactory.newInstance();
          = factory.newTransformeraStyleSheet );
     }

    
Constructs a ContentTransformer.java.

Parameters:
aStyleSheet
parametermap
Throws:
java.lang.Exception
 
     public ContentTransformer(StreamSource aStyleSheetHashMap parametermapthrows Exception {
        // create transformer
        TransformerFactory factory = TransformerFactory.newInstance();
         = factory.newTransformeraStyleSheet );
        Iterator iter = parametermap.keySet().iterator();
        while (iter.hasNext()) {
           Object o = iter.next();
           String param = o.toString();
           String value = (Stringparametermap.get(param);
           .setParameter(paramvalue);
        }
     }

    
This method performs the actual transformation.

Parameters:
xml
Returns:
Throws:
java.lang.Exception
    public String transform(String xmlthrows Exception {
        // perform transformation
        Source xmlsource = new StreamSource(new StringReader(xml));
        StringWriter sout = new StringWriter();
         
        .transform(xmlsourcenew StreamResult(sout));
        // return resulting document
        return sout.toString();
    }
New to GrepCode? Check out our FAQ X