Last modified by Pascal Robert on 2007/09/03 19:36

From version 3.1
edited by Pascal Robert
on 2007/09/03 19:36
Change comment: There is no comment for this version
To version 1.1
edited by smmccraw
on 2007/07/08 09:46
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -Web Services-Sending Large Data
1 +Programming__WebObjects-Web Services-Sending Large Data
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.probert
1 +XWiki.smmccraw
Content
... ... @@ -1,4 +1,4 @@
1 -=== Kristoff Cossement ===
1 +=== Kristoff Cossement ===
2 2  
3 3  Soap with mime attachments was indeed the way to go.
4 4  
... ... @@ -7,344 +7,344 @@
7 7  For those who are interested I included some sample code on how to exchange large binary data between a java client and and webobjects server without taking all data in memory.
8 8  You also need the java mail and java activation framework from sun.
9 9  
10 -==== Client.java ====
10 +==== Client.java ====
11 11  
12 -{{code}}
12 +{{panel}}
13 13  
14 - import javax.xml.soap.SOAPConnectionFactory;
15 - import javax.xml.soap.*;
16 - import javax.xml.transform.stream.*;
17 - import javax.xml.transform.*;
18 - import java.io.*;
19 - import org.apache.axis.attachments.AttachmentPart;
20 - import org.apache.axis.message.*;
21 - import javax.activation.DataHandler;
22 - import javax.activation.FileDataSource;
23 - import javax.xml.soap.SOAPElement;
24 - import java.util.*;
25 - import javax.mail.*;
14 + import javax.xml.soap.SOAPConnectionFactory;
15 + import javax.xml.soap.*;
16 + import javax.xml.transform.stream.*;
17 + import javax.xml.transform.*;
18 + import java.io.*;
19 + import org.apache.axis.attachments.AttachmentPart;
20 + import org.apache.axis.message.*;
21 + import javax.activation.DataHandler;
22 + import javax.activation.FileDataSource;
23 + import javax.xml.soap.SOAPElement;
24 + import java.util.*;
25 + import javax.mail.*;
26 +
27 + public class Client {
28 +
29 + public static File resize(String sPath)
30 + {
31 + File file = new File(sPath);
32 +
33 +
34 + String endPoint = "http://localhost:55555/cgi-bin/WebObjects/project.woa/ws/FileUpload";
35 + try{
36 + SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection();
37 + SOAPMessage message = (javax.xml.soap.SOAPMessage)MessageFactory.newInstance().createMessage();
38 + SOAPPart part = message.getSOAPPart();
39 + SOAPEnvelope envelope = (org.apache.axis.message.SOAPEnvelope)part.getEnvelope();
40 + SOAPBody body = (org.apache.axis.message.SOAPBody)envelope.getBody();
41 + SOAPBodyElement operation = (org.apache.axis.message.SOAPBodyElement)body.addBodyElement(
42 + envelope.createName("upload",
43 + "ns",
44 + "http://localhost:55555/cgi-bin/WebObjects/project.woa/ws/FileUpload"));
45 + operation.setEncodingStyle("http://schemas.xmlsoaporg/soap/encoding/");
46 +
47 + DataHandler dh = new DataHandler(new FileDataSource(file));
48 + AttachmentPart attachment = (org.apache.axis.attachments.AttachmentPart)message.createAttachmentPart(dh);
49 + SOAPElement filename = operation.addChildElement("filename","");
50 + SOAPElement source = operation.addChildElement("source","");
51 + message.addAttachmentPart(attachment);
52 + filename.addTextNode(file.getName());
53 + source.addTextNode(attachment.getContentId());
54 +
55 + SOAPMessage result = connection.call(message,endPoint);
56 + System.out.println(result);
57 + part = result.getSOAPPart();
58 + envelope = (org.apache.axis.message.SOAPEnvelope)part.getEnvelope();
59 + body = (org.apache.axis.message.SOAPBody)envelope.getBody();
60 +
61 + if(!body.hasFault())
62 +________{
63 +__________System.out.println("answer_:_"+body);
64 +__
65 +________}
66 +______}
67 +______catch(Exception_e)
68 +______{
69 +________e.printStackTrace();
70 +______}
71 +______return_null;
72 +____}
73 +__
74 +____public_static_void_main(String[]_args)_{
75 +__
76 +______try_{
77 +__
78 +________resize(args[0]);
79 +__
80 +______}
81 +______catch_(Exception_e)_{
82 +________System.out.println(e.getMessage());
83 +______}
84 +____}
85 +__}
26 26  
27 - public class Client {
87 +{{/panel}}
28 28  
29 - public static File resize(String sPath)
30 - {
31 - File file = new File(sPath);
89 +==== Webobjects//Application//.java ====
32 32  
91 +override//dispatchRequest//
33 33  
34 - String endPoint = "http://localhost:55555/cgi-bin/WebObjects/project.woa/ws/FileUpload";
35 - try{
36 - SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection();
37 - SOAPMessage message = (javax.xml.soap.SOAPMessage)MessageFactory.newInstance().createMessage();
38 - SOAPPart part = message.getSOAPPart();
39 - SOAPEnvelope envelope = (org.apache.axis.message.SOAPEnvelope)part.getEnvelope();
40 - SOAPBody body = (org.apache.axis.message.SOAPBody)envelope.getBody();
41 - SOAPBodyElement operation = (org.apache.axis.message.SOAPBodyElement)body.addBodyElement(
42 - envelope.createName("upload",
43 - "ns",
44 - "http://localhost:55555/cgi-bin/WebObjects/project.woa/ws/FileUpload"));
45 - operation.setEncodingStyle("http://schemas.xmlsoaporg/soap/encoding/");
93 +{{panel}}
46 46  
47 - DataHandler dh = new DataHandler(new FileDataSource(file));
48 - AttachmentPart attachment = (org.apache.axis.attachments.AttachmentPart)message.createAttachmentPart(dh);
49 - SOAPElement filename = operation.addChildElement("filename","");
50 - SOAPElement source = operation.addChildElement("source","");
51 - message.addAttachmentPart(attachment);
52 - filename.addTextNode(file.getName());
53 - source.addTextNode(attachment.getContentId());
95 +__public_WOResponse_dispatchRequest(WORequest_request)
96 +__{
97 +____WOResponse_result_=_null;
98 +____String_sURI_=_request.uri();
99 +____NSLog.debug.appendln("Accessing_"_+_sURI);
100 +__
101 +____Pattern_p_=_Pattern.compile("/ws/FileUpload");
102 +____Matcher_m_=_p.matcher(sURI);
103 +____if(m.find())
104 +____{
105 +______String_sContType_=_request.headerForKey("content-type");
106 +______p_=_Pattern.compile("multipart/related");
107 +______m_=_p.matcher(sContType);
108 +______if(m.find())
109 +______{
110 +________result_=_Dispatcher.handleFileUpload(request);
111 +______}
112 +______else
113 +______{
114 +________result_=_super.dispatchRequest(request);
115 +______}
116 +____}
117 +____else
118 +____{
119 +______result_=_super.dispatchRequest(request);
120 +____}
121 +__
122 +____return_result;
123 +__
124 +__}
54 54  
55 - SOAPMessage result = connection.call(message,endPoint);
56 - System.out.println(result);
57 - part = result.getSOAPPart();
58 - envelope = (org.apache.axis.message.SOAPEnvelope)part.getEnvelope();
59 - body = (org.apache.axis.message.SOAPBody)envelope.getBody();
126 +{{/panel}}
60 60  
61 - if(!body.hasFault())
62 - {
63 - System.out.println("answer : "+body);
128 +==== Dispatcher.java ====
64 64  
65 - }
66 - }
67 - catch(Exception e)
68 - {
69 - e.printStackTrace();
70 - }
71 - return null;
72 - }
130 +{{panel}}
73 73  
74 - public static void main(String[] args) {
132 +__//
133 +__//_Dispatcher.java
134 +__//_project
135 +__//
136 +__//_Created_by_admin_on_5/5/06.
137 +__//_Copyright_2006___MyCompanyName__._All_rights_reserved.
138 +__//
139 +__import_com.webobjects.foundation.*;
140 +__import_com.webobjects.appserver.*;
141 +__import_com.webobjects.eocontrol.*;
142 +__
143 +__import_java.io.*;
144 +__import_java.util.regex.*;
145 +__import_org.w3c.dom.*;
146 +__import_javax.xml.transform.*;
147 +__import_javax.xml.transform.stream.*;
148 +__import_javax.xml.transform.dom.*;
149 +__import_javax.xml.parsers.*;
150 +__import_org.apache.axis.attachments.*;
151 +__
152 +__
153 +__public_class_Dispatcher_{
154 +__
155 +____public_static_WOResponse_handleFileUpload(WORequest_request)
156 +____{
157 +______String_sContType_=_request.headerForKey("content-type");
158 +______String_sSoapXml_=_"";
159 +______InputStream_requestStream_=_request.contentInputStream();
160 +__
161 +______String_sTempDir_=_System.getProperty("java.io.tmpdir");
162 +______String_timestamp_=(new_Long(System.currentTimeMillis())).toString();
163 +______File_fTempFile_=_new_File(sTempDir+"/"+timestamp);
164 +______File_fSavedFile_=_new_File(sTempDir+"/"+timestamp+".out");
165 +__
166 +______try
167 +______{
168 +________BufferedOutputStream_fOut_=_new_BufferedOutputStream(new_FileOutputStream(fTempFile));
169 +________byte[)_buffer_=_new_byte(32_*_1024];
170 +________int_bytesRead_=_0;
171 +________while_((bytesRead_=_requestStream.read(buffer))_!= -1)
172 + {
173 + fOut.write(buffer, 0, bytesRead);
174 + }
175 + fOut.close();
176 + }
177 + catch (Exception e)
178 + {
179 + NSLog.debug.appendln(e.getMessage());
180 + }
181 +
182 + try
183 + {
184 + InputStream iStream = new FileInputStream(fTempFile);
185 +
186 + MultiPartRelatedInputStream mis = new MultiPartRelatedInputStream(sContType,iStream);
187 + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
188 + Document doc = factory.newDocumentBuilder().parse(mis);
189 + sSoapXml = toString(doc);
190 + NSLog.debug.appendln("SOAP Envelope: " + sSoapXml);
191 + mis.close();
192 + iStream.close();
193 +
194 + Node nEnvelope = getNamedChildNode(doc,"Envelope");
195 + if(null !=_nEnvelope)
196 +________{
197 +__________Node_nBody_=_getNamedChildNode(nEnvelope,"Body");
198 +__________if(null_!= nBody)
199 + {
200 + NSArray nSubNodes = getElementChildNodes(nBody);
201 + if((null !=_nSubNodes)_&&_(nSubNodes.count()_>_0))
202 +____________{
203 +______________Node_nFileUpload_=_(Node)nSubNodes.get(0);
204 +______________nSubNodes_=_getElementChildNodes(nFileUpload);
205 +______________if((null_!= nSubNodes) && (nSubNodes.count() > 1))
206 + {
207 + Node nFileName = (Node)nSubNodes.get(0);
208 + Node nData = (Node)nSubNodes.get(1);
209 +
210 + String sFileName = getTextFromNode(nFileName);
211 + String sFileMimeID = getTextFromNode(nData);
212 +
213 + fSavedFile = new File(sTempDir+"/"+sFileName);
214 +
215 + Pattern pattern = Pattern.compile("(boundary=\".+?\")");
216 + Matcher match = pattern.matcher(sContType);
217 + if(match.find())
218 + {
219 + String boundary= match.group(1);
220 + String sSubContentType = "multipart/related; type=\"text/xml\"; start=\"<"+sFileMimeID+">\"; "+boundary;
221 + iStream = new FileInputStream(fTempFile);
222 + mis = new MultiPartRelatedInputStream(sSubContentType,iStream);
223 + try
224 + {
225 + BufferedOutputStream fOut = new BufferedOutputStream(new FileOutputStream(fSavedFile));
226 + byte[) buffer = new byte(32 * 1024];
227 + int bytesRead = 0;
228 + while ((bytesRead = mis.read(buffer)) !=_-1)
229 +____________________{
230 +______________________fOut.write(buffer,_0,_bytesRead);
231 +____________________}
232 +____________________mis.close();
233 +____________________fOut.close();
234 +__________________}
235 +__________________catch_(Exception_e)
236 +__________________{
237 +____________________System.out.println(e.getMessage());
238 +____________________//throw_new_IOException(me_+_"_failed,_got:_"_+_e.toString());
239 +__________________}
240 +________________}
241 +______________}
242 +____________}__
243 +__________}
244 +________}
245 +______}
246 +______catch(Exception_e)
247 +______{
248 +________e.printStackTrace();
249 +______}
250 +__
251 +__
252 +______WOResponse_result_=_new_WOResponse();
253 +______result.setContent(_"<?xml_version="1.0"_encoding="UTF-8"?>n"+
254 +__________"<soapenv:Envelope_xmlns:soapenv="http://schemas.xmlsoaporg/soap/envelope/"_xmlns:xsd="http://www.w3.org/2001/XMLSchema"_xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">n"+
255 +__________"<soapenv:Body>n"+
256 +__________"<ns:uploadResponse_soapenv:encodingStyle="http://schemas.xmlsoaporg/soap/encoding/"_xmlns:ns="http://localhost:55555/cgi-bin/WebObjects/project.woa/ws/FileUpload">n"+
257 +__________"<ns:uploadReturn_xsi:type="xsd:boolean">true</ns:uploadReturn>n"+
258 +__________"</ns:uploadResponse>n"+
259 +__________"</soapenv:Body>n"+
260 +__________"</soapenv:Envelope>");
261 +__
262 +__
263 +______result.setHeader("text/xml;_charset=utf-8","content-type");
264 +__
265 +__
266 +______return_result;
267 +__
268 +____}
269 +__
270 +__
271 +____static_public_String_toString(Document_document)_{
272 +______String_result_=_null;
273 +__
274 +______if_(document_!= null) {
275 + StringWriter strWtr = new StringWriter();
276 + StreamResult strResult = new StreamResult(strWtr);
277 + TransformerFactory tfac = TransformerFactory.newInstance();
278 + try {
279 + Transformer t = tfac.newTransformer();
280 + t.setOutputProperty(OutputKeys.ENCODING, "utf-8");
281 + t.setOutputProperty(OutputKeys.INDENT, "yes");
282 + t.setOutputProperty(OutputKeys.METHOD, "xml"); //xml, html, text
283 + t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
284 + t.transform(new DOMSource(document.getDocumentElement()), strResult);
285 + } catch (Exception e) {
286 + System.err.println("XML.toString(Document): " + e);
287 + }
288 + result = strResult.getWriter().toString();
289 + }
290 +
291 + return result;
292 + }
293 +
294 + static public Node getNamedChildNode(Node n, String sChildNodeName)
295 + {
296 +
297 + NodeList nl = n.getChildNodes();
298 +
299 + for(int i=0;i<nl.getLength();i++)
300 + {
301 + Node s = nl.item(i);
302 + String sChild = s.getNodeName();
303 + if(sChildNodeName.equalsIgnoreCase(sChild) || sChild.endsWith(":"+sChildNodeName))
304 + {
305 + NSLog.debug.appendln("childnode = " + s.getNodeName());
306 + return s;
307 + }
308 + }
309 +
310 + return null;
311 +
312 + }
313 + static public NSArray getElementChildNodes(Node n)
314 + {
315 + NSMutableArray elements = new NSMutableArray();
316 + NodeList nl = n.getChildNodes();
317 +
318 + for(int i=0;i<nl.getLength();i++)
319 + {
320 + Node s = nl.item(i);
321 + if(s.getNodeType() == Node.ELEMENT_NODE)
322 + {
323 + NSLog.debug.appendln("childnode = " + s.getNodeName());
324 + elements.addObject(s);
325 + }
326 + }
327 +
328 + return elements;
329 + }
330 + static public String getTextFromNode(Node n)
331 + {
332 + String text = "";
333 +
334 + NodeList nl = n.getChildNodes();
335 +
336 + for(int i=0;i<nl.getLength();i++)
337 + {
338 + Node s = nl.item(i);
339 + if(s.getNodeType() == Node.TEXT_NODE)
340 + {
341 + return s.getNodeValue();
342 + }
343 + }
344 + return text;
345 + }
346 + }
75 75  
76 - try {
348 +{{/panel}}
77 77  
78 - resize(args[0]);
79 -
80 - }
81 - catch (Exception e) {
82 - System.out.println(e.getMessage());
83 - }
84 - }
85 - }
86 -
87 -{{/code}}
88 -
89 -==== ====
90 -
91 -===== Webobjects Application .java =====
92 -
93 -override dispatchRequest
94 -
95 -{{code}}
96 -
97 -  public WOResponse dispatchRequest(WORequest request)
98 - {
99 - WOResponse result = null;
100 - String sURI = request.uri();
101 - NSLog.debug.appendln("Accessing " + sURI);
102 -
103 - Pattern p = Pattern.compile("/ws/FileUpload");
104 - Matcher m = p.matcher(sURI);
105 - if(m.find())
106 - {
107 - String sContType = request.headerForKey("content-type");
108 - p = Pattern.compile("multipart/related");
109 - m = p.matcher(sContType);
110 - if(m.find())
111 - {
112 - result = Dispatcher.handleFileUpload(request);
113 - }
114 - else
115 - {
116 - result = super.dispatchRequest(request);
117 - }
118 - }
119 - else
120 - {
121 - result = super.dispatchRequest(request);
122 - }
123 -
124 - return result;
125 -
126 - }
127 -
128 -{{/code}}
129 -
130 -===== Dispatcher.java =====
131 -
132 -{{code}}
133 -
134 -  //
135 - // Dispatcher.java
136 - // project
137 - //
138 - // Created by admin on 5/5/06.
139 - // Copyright 2006 __MyCompanyName__. All rights reserved.
140 - //
141 - import com.webobjects.foundation.*;
142 - import com.webobjects.appserver.*;
143 - import com.webobjects.eocontrol.*;
144 -
145 - import java.io.*;
146 - import java.util.regex.*;
147 - import org.w3c.dom.*;
148 - import javax.xml.transform.*;
149 - import javax.xml.transform.stream.*;
150 - import javax.xml.transform.dom.*;
151 - import javax.xml.parsers.*;
152 - import org.apache.axis.attachments.*;
153 -
154 -
155 - public class Dispatcher {
156 -
157 - public static WOResponse handleFileUpload(WORequest request)
158 - {
159 - String sContType = request.headerForKey("content-type");
160 - String sSoapXml = "";
161 - InputStream requestStream = request.contentInputStream();
162 -
163 - String sTempDir = System.getProperty("java.io.tmpdir");
164 - String timestamp =(new Long(System.currentTimeMillis())).toString();
165 - File fTempFile = new File(sTempDir+"/"+timestamp);
166 - File fSavedFile = new File(sTempDir+"/"+timestamp+".out");
167 -
168 - try
169 - {
170 - BufferedOutputStream fOut = new BufferedOutputStream(new FileOutputStream(fTempFile));
171 - byte[] buffer = new byte[32 * 1024];
172 - int bytesRead = 0;
173 - while ((bytesRead = requestStream.read(buffer)) != -1)
174 - {
175 - fOut.write(buffer, 0, bytesRead);
176 - }
177 - fOut.close();
178 - }
179 - catch (Exception e)
180 - {
181 - NSLog.debug.appendln(e.getMessage());
182 - }
183 -
184 - try
185 - {
186 - InputStream iStream = new FileInputStream(fTempFile);
187 -
188 - MultiPartRelatedInputStream mis = new MultiPartRelatedInputStream(sContType,iStream);
189 - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
190 - Document doc = factory.newDocumentBuilder().parse(mis);
191 - sSoapXml = toString(doc);
192 - NSLog.debug.appendln("SOAP Envelope: " + sSoapXml);
193 - mis.close();
194 - iStream.close();
195 -
196 - Node nEnvelope = getNamedChildNode(doc,"Envelope");
197 - if(null != nEnvelope)
198 - {
199 - Node nBody = getNamedChildNode(nEnvelope,"Body");
200 - if(null != nBody)
201 - {
202 - NSArray nSubNodes = getElementChildNodes(nBody);
203 - if((null != nSubNodes) && (nSubNodes.count() > 0))
204 - {
205 - Node nFileUpload = (Node)nSubNodes.get(0);
206 - nSubNodes = getElementChildNodes(nFileUpload);
207 - if((null != nSubNodes) && (nSubNodes.count() > 1))
208 - {
209 - Node nFileName = (Node)nSubNodes.get(0);
210 - Node nData = (Node)nSubNodes.get(1);
211 -
212 - String sFileName = getTextFromNode(nFileName);
213 - String sFileMimeID = getTextFromNode(nData);
214 -
215 - fSavedFile = new File(sTempDir+"/"+sFileName);
216 -
217 - Pattern pattern = Pattern.compile("(boundary=\".+?\")");
218 - Matcher match = pattern.matcher(sContType);
219 - if(match.find())
220 - {
221 - String boundary= match.group(1);
222 - String sSubContentType = "multipart/related; type=\"text/xml\"; start=\"<"+sFileMimeID+">\"; "+boundary;
223 - iStream = new FileInputStream(fTempFile);
224 - mis = new MultiPartRelatedInputStream(sSubContentType,iStream);
225 - try
226 - {
227 - BufferedOutputStream fOut = new BufferedOutputStream(new FileOutputStream(fSavedFile));
228 - byte[] buffer = new byte[32 * 1024];
229 - int bytesRead = 0;
230 - while ((bytesRead = mis.read(buffer)) != -1)
231 - {
232 - fOut.write(buffer, 0, bytesRead);
233 - }
234 - mis.close();
235 - fOut.close();
236 - }
237 - catch (Exception e)
238 - {
239 - System.out.println(e.getMessage());
240 - //throw new IOException(me + " failed, got: " + e.toString());
241 - }
242 - }
243 - }
244 - }
245 - }
246 - }
247 - }
248 - catch(Exception e)
249 - {
250 - e.printStackTrace();
251 - }
252 -
253 -
254 - WOResponse result = new WOResponse();
255 - result.setContent( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
256 - "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoaporg/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"+
257 - "<soapenv:Body>\n"+
258 - "<ns:uploadResponse soapenv:encodingStyle=\"http://schemas.xmlsoaporg/soap/encoding/\" xmlns:ns=\"http://localhost:55555/cgi-bin/WebObjects/project.woa/ws/FileUpload\">\n"+
259 - "<ns:uploadReturn xsi:type=\"xsd:boolean\">true</ns:uploadReturn>\n"+
260 - "</ns:uploadResponse>\n"+
261 - "</soapenv:Body>\n"+
262 - "</soapenv:Envelope>");
263 -
264 -
265 - result.setHeader("text/xml; charset=utf-8","content-type");
266 -
267 -
268 - return result;
269 -
270 - }
271 -
272 -
273 - static public String toString(Document document) {
274 - String result = null;
275 -
276 - if (document != null) {
277 - StringWriter strWtr = new StringWriter();
278 - StreamResult strResult = new StreamResult(strWtr);
279 - TransformerFactory tfac = TransformerFactory.newInstance();
280 - try {
281 - Transformer t = tfac.newTransformer();
282 - t.setOutputProperty(OutputKeys.ENCODING, "utf-8");
283 - t.setOutputProperty(OutputKeys.INDENT, "yes");
284 - t.setOutputProperty(OutputKeys.METHOD, "xml"); //xml, html, text
285 - t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
286 - t.transform(new DOMSource(document.getDocumentElement()), strResult);
287 - } catch (Exception e) {
288 - System.err.println("XML.toString(Document): " + e);
289 - }
290 - result = strResult.getWriter().toString();
291 - }
292 -
293 - return result;
294 - }
295 -
296 - static public Node getNamedChildNode(Node n, String sChildNodeName)
297 - {
298 -
299 - NodeList nl = n.getChildNodes();
300 -
301 - for(int i=0;i<nl.getLength();i++)
302 - {
303 - Node s = nl.item(i);
304 - String sChild = s.getNodeName();
305 - if(sChildNodeName.equalsIgnoreCase(sChild) || sChild.endsWith(":"+sChildNodeName))
306 - {
307 - NSLog.debug.appendln("childnode = " + s.getNodeName());
308 - return s;
309 - }
310 - }
311 -
312 - return null;
313 -
314 - }
315 - static public NSArray getElementChildNodes(Node n)
316 - {
317 - NSMutableArray elements = new NSMutableArray();
318 - NodeList nl = n.getChildNodes();
319 -
320 - for(int i=0;i<nl.getLength();i++)
321 - {
322 - Node s = nl.item(i);
323 - if(s.getNodeType() == Node.ELEMENT_NODE)
324 - {
325 - NSLog.debug.appendln("childnode = " + s.getNodeName());
326 - elements.addObject(s);
327 - }
328 - }
329 -
330 - return elements;
331 - }
332 - static public String getTextFromNode(Node n)
333 - {
334 - String text = "";
335 -
336 - NodeList nl = n.getChildNodes();
337 -
338 - for(int i=0;i<nl.getLength();i++)
339 - {
340 - Node s = nl.item(i);
341 - if(s.getNodeType() == Node.TEXT_NODE)
342 - {
343 - return s.getNodeValue();
344 - }
345 - }
346 - return text;
347 - }
348 - }
349 -
350 -{{/code}}
350 +Category:WebObjects