001 /** 002 * Implements the Cold Fusion Function xmlelemnew 003 */ 004 package railo.runtime.functions.xml; 005 006 import org.w3c.dom.Document; 007 import org.w3c.dom.Element; 008 import org.w3c.dom.Node; 009 010 import railo.commons.lang.StringUtil; 011 import railo.runtime.PageContext; 012 import railo.runtime.exp.FunctionException; 013 import railo.runtime.ext.function.Function; 014 import railo.runtime.text.xml.XMLUtil; 015 import railo.runtime.text.xml.struct.XMLStructFactory; 016 017 public final class XmlElemNew implements Function { 018 019 private static final long serialVersionUID = -2601887739406776466L; 020 021 public static Element call(PageContext pc , Node node, String childname) throws FunctionException { 022 return call(pc, node, null, childname); 023 } 024 025 public static Element call(PageContext pc , Node node, String namespace, String childname) throws FunctionException { 026 Document doc=XMLUtil.getDocument(node); 027 028 if(StringUtil.isEmpty(childname)) { 029 if(!StringUtil.isEmpty(namespace)) { 030 childname=namespace; 031 namespace=null; 032 } 033 else throw new FunctionException(pc, "XmlElemNew", 3, "childname", "argument is required"); 034 } 035 036 Element el = null; 037 038 // without namespace 039 if(StringUtil.isEmpty(namespace)){ 040 el=doc.createElement(childname); 041 } 042 // with namespace 043 else { 044 el=doc.createElementNS(namespace, childname); 045 } 046 return (Element)XMLStructFactory.newInstance(el,false); 047 } 048 049 050 051 }