001 /** 002 * Implements the CFML Function xmltransform 003 */ 004 package railo.runtime.functions.xml; 005 006 import org.w3c.dom.Document; 007 import org.w3c.dom.Node; 008 009 import railo.runtime.PageContext; 010 import railo.runtime.exp.PageException; 011 import railo.runtime.exp.XMLException; 012 import railo.runtime.ext.function.Function; 013 import railo.runtime.op.Caster; 014 import railo.runtime.text.xml.XMLUtil; 015 import railo.runtime.type.Struct; 016 017 public final class XmlTransform implements Function { 018 019 020 public static String call( PageContext pc , Object oXml, String xsl ) throws PageException { 021 return call( pc, oXml, xsl, null ); 022 } 023 024 public static String call( PageContext pc , Object oXml, String xsl, Struct parameters ) throws PageException { 025 try { 026 Document doc; 027 if(oXml instanceof String) { 028 doc=XMLUtil.parse(XMLUtil.toInputSource(pc, oXml.toString()), null, false); 029 } 030 else if(oXml instanceof Node) doc=XMLUtil.getDocument((Node)oXml); 031 else throw new XMLException("XML Object is of invalid type, must be a XML String or a XML Object","now it is "+Caster.toClassName(oXml)); 032 033 return XMLUtil.transform( doc, XMLUtil.toInputSource( pc, xsl ), parameters ); 034 } 035 catch (Exception e) { 036 throw Caster.toPageException(e); 037 } 038 } 039 }