1 4 5 9 10 package org.openlaszlo.remote.soap; 11 12 import javax.xml.namespace.QName ; 13 import org.openlaszlo.iv.flash.util.*; 14 import org.openlaszlo.iv.flash.api.action.*; 15 import org.openlaszlo.iv.flash.api.*; 16 import org.openlaszlo.xml.internal.DataCommon; 17 import org.openlaszlo.xml.internal.DataContext; 18 import java.io.IOException ; 19 import java.io.StringReader ; 20 import javax.xml.parsers.DocumentBuilder ; 21 import javax.xml.parsers.DocumentBuilderFactory ; 22 import javax.xml.parsers.ParserConfigurationException ; 23 import org.apache.log4j.Logger; 24 import org.w3c.dom.Element ; 25 import org.w3c.dom.NodeList ; 26 import org.xml.sax.InputSource ; 27 import org.xml.sax.SAXException ; 28 import org.apache.axis.utils.XMLUtils; 29 30 31 public class LZSOAPUtils { 32 33 private static Logger mLogger = Logger.getLogger(LZSOAPUtils.class); 34 35 41 static public String getPrefix(String tag) { 42 int index = tag.indexOf(':'); 43 if (index == -1) return ""; 44 return tag.substring(0, index); 45 } 46 47 53 static public String getLocal(String tag) { 54 int index = tag.indexOf(':'); 55 if (index == -1) return tag; 56 return tag.substring(index+1); 57 } 58 59 static public Element xmlStringToElement(String xml) 60 throws IOException , SAXException { 61 62 DocumentBuilder builder = null; 63 try { 64 builder = XMLUtils.getDocumentBuilder(); 65 return builder.parse(new InputSource ( new StringReader (xml))) 66 .getDocumentElement(); 67 } catch (ParserConfigurationException e) { 68 throw new SAXException ("can't create document builder"); 69 } finally { 70 if (builder != null) { 71 XMLUtils.releaseDocumentBuilder(builder); 72 } 73 } 74 75 } 76 77 static public void pushString(Program program, String str, DataContext dc) { 78 if (str == null) { 79 pushNull(program.body()); 80 return; 81 } 82 DataCommon.pushStringData(str, program.body(), dc); 83 } 84 85 static public void pushNull(FlashBuffer body) { 86 body.writeByte(Actions.PushData); 87 body.writeWord(0+1); 88 body.writeByte(2); 89 } 90 91 static public void pushQName(Program program, QName qname, DataContext dc) { 92 FlashBuffer body = program.body(); 93 if (qname == null) { 94 pushNull(body); 95 return; 96 } 97 DataCommon.pushStringData(qname.getNamespaceURI(), body, dc); 99 DataCommon.pushStringData(qname.getLocalPart(), body, dc); 100 program.push(2); 101 DataCommon.pushStringData("_root.QName", body, dc); 102 program.newObject(); 103 } 104 105 106 115 static Element getFirstElementByTagNameNS(String ns, Element element, String tag) { 116 if (element == null) 117 return null; 118 119 NodeList list; 120 if (ns == null) 121 list = element.getElementsByTagName(tag); 122 else 123 list = element.getElementsByTagNameNS(ns, tag); 124 125 if (list.getLength() == 0) 126 return null; 127 return (Element )list.item(0); 128 } 129 130 133 static Element getFirstElementByTagName(Element element, String tag) { 134 return getFirstElementByTagNameNS(null, element, tag); 135 } 136 137 } 138 | Popular Tags |