Subversion Repositories XServices

Rev

Rev 177 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 Rev 185
Line 24... Line 24...
24
import java.io.UnsupportedEncodingException;
24
import java.io.UnsupportedEncodingException;
25
import java.nio.charset.Charset;
25
import java.nio.charset.Charset;
26
import java.nio.charset.IllegalCharsetNameException;
26
import java.nio.charset.IllegalCharsetNameException;
27
import java.util.Iterator;
27
import java.util.Iterator;
28
import java.util.List;
28
import java.util.List;
29
import java.util.StringTokenizer;
-
 
30
 
-
 
31
import javax.jws.WebService;
29
import javax.jws.WebService;
32
import javax.ws.rs.NotAuthorizedException;
-
 
33
import javax.xml.namespace.QName;
30
import javax.xml.namespace.QName;
34
import javax.xml.stream.XMLOutputFactory;
31
import javax.xml.stream.XMLOutputFactory;
35
import javax.xml.stream.XMLStreamException;
32
import javax.xml.stream.XMLStreamException;
36
import javax.xml.stream.XMLStreamReader;
-
 
37
import javax.xml.stream.XMLStreamWriter;
33
import javax.xml.stream.XMLStreamWriter;
Line 38... Line -...
38
 
-
 
39
import net.brutex.xservices.security.DirectoryPermission;
34
 
40
import net.brutex.xservices.types.AttributeType;
35
import net.brutex.xservices.types.AttributeType;
41
import net.brutex.xservices.types.NamespaceListType;
36
import net.brutex.xservices.types.NamespaceListType;
42
import net.brutex.xservices.types.NamespaceType;
37
import net.brutex.xservices.types.NamespaceType;
43
import net.brutex.xservices.types.StringSplitType;
38
import net.brutex.xservices.types.StringSplitType;
Line 56... Line 51...
56
import org.apache.axiom.om.OMNode;
51
import org.apache.axiom.om.OMNode;
57
import org.apache.axiom.om.OMProcessingInstruction;
52
import org.apache.axiom.om.OMProcessingInstruction;
58
import org.apache.axiom.om.OMText;
53
import org.apache.axiom.om.OMText;
59
import org.apache.axiom.om.OMXMLBuilderFactory;
54
import org.apache.axiom.om.OMXMLBuilderFactory;
60
import org.apache.axiom.om.xpath.AXIOMXPath;
55
import org.apache.axiom.om.xpath.AXIOMXPath;
-
 
56
 
61
import org.apache.log4j.Logger;
57
import org.apache.logging.log4j.LogManager;
62
import org.apache.shiro.SecurityUtils;
58
import org.apache.logging.log4j.Logger;
63
import org.apache.shiro.authz.UnauthorizedException;
-
 
64
import org.apache.shiro.authz.annotation.RequiresPermissions;
59
import org.apache.shiro.authz.annotation.RequiresPermissions;
65
import org.jaxen.JaxenException;
60
import org.jaxen.JaxenException;
66
import org.jaxen.SimpleNamespaceContext;
61
import org.jaxen.SimpleNamespaceContext;
Line 67... Line 62...
67
 
62
 
68
/**
63
/**
69
 * @author Brian Rosenberger, bru(at)brutex.de
64
 * @author Brian Rosenberger, bru(at)brutex.de
70
 * 
65
 * 
71
 */
66
 */
72
@WebService(targetNamespace = "http://ws.xservices.brutex.net", endpointInterface = "net.brutex.xservices.ws.XmlService", serviceName = "XmlService")
67
@WebService(targetNamespace = "http://ws.xservices.brutex.net", endpointInterface = "net.brutex.xservices.ws.XmlService", serviceName = "XmlService")
73
public class XmlServiceImpl implements XmlService {
68
public class XmlServiceImpl implements XmlService {
Line 74... Line 69...
74
	final Logger logger = Logger.getLogger(XmlServiceImpl.class);
69
	private static final Logger logger = LogManager.getLogger();
-
 
70
 
75
 
71
	public String insertNodesFromFile(FileResource res, NamespaceListType nsList, String xpath, String xmlFragment)
76
	public String insertNodesFromFile(FileResource res, NamespaceListType nsList, String xpath, String xmlFragment) throws XServicesFault {
72
			throws XServicesFault {
77
		try {
73
		try {
78
			AXIOMXPath axp = new AXIOMXPath(xpath);
74
			AXIOMXPath axp = new AXIOMXPath(xpath);
79
			InputStream is = res.getAntResource(null).getInputStream();
-
 
80
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is)
75
			InputStream is = res.getAntResource(null).getInputStream();
81
					.getDocument();
76
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is).getDocument();
82
			OMDocument fragdoc = null;
-
 
83
			if ((xmlFragment != null) && (new String(xmlFragment).length() > 0)) {
77
			OMDocument fragdoc = null;
84
				fragdoc = OMXMLBuilderFactory.createOMBuilder(
78
			if ((xmlFragment != null) && (new String(xmlFragment).length() > 0)) {
85
						new StringReader("<XS>" + xmlFragment + "</XS>"))
79
				fragdoc = OMXMLBuilderFactory.createOMBuilder(new StringReader("<XS>" + xmlFragment + "</XS>"))
86
						.getDocument();
80
						.getDocument();
87
			} else {
81
			} else {
Line 112... Line 106...
112
			e.printStackTrace();
106
			e.printStackTrace();
113
			throw new XServicesFault(e);
107
			throw new XServicesFault(e);
114
		}
108
		}
115
	}
109
	}
Line 116... Line 110...
116
 
110
 
-
 
111
	public String replaceNodesFromFile(FileResource res, NamespaceListType nsList, String xpath, String xmlFragment)
117
	public String replaceNodesFromFile(FileResource res, NamespaceListType nsList, String xpath, String xmlFragment) throws XServicesFault {
112
			throws XServicesFault {
118
		try {
113
		try {
119
				AXIOMXPath axp = new AXIOMXPath(xpath);
114
			AXIOMXPath axp = new AXIOMXPath(xpath);
120
				InputStream is = res.getAntResource(null).getInputStream();
115
			InputStream is = res.getAntResource(null).getInputStream();
121
				OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is).getDocument();
116
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is).getDocument();
122
				OMDocument fragdoc = null;
117
			OMDocument fragdoc = null;
123
				if ((xmlFragment != null) && (new String(xmlFragment).length() > 0)) {
-
 
124
					fragdoc = OMXMLBuilderFactory.createOMBuilder(
118
			if ((xmlFragment != null) && (new String(xmlFragment).length() > 0)) {
125
							new StringReader("<XS>" + xmlFragment + "</XS>"))
119
				fragdoc = OMXMLBuilderFactory.createOMBuilder(new StringReader("<XS>" + xmlFragment + "</XS>"))
126
							.getDocument();
120
						.getDocument();
127
				} else {
121
			} else {
128
					throw new XServicesFault("No xmldata to insert.");
-
 
129
				}
-
 
130
 
-
 
131
				// Initialize XPath context
-
 
132
				SimpleNamespaceContext context = createContext(nsList);
-
 
133
				axp.setNamespaceContext(context);
-
 
134
				axp.addNamespaces(fragdoc.getOMDocumentElement());
-
 
135
 
-
 
136
				OMDocument document = replaceNodes(sourcedoc, axp, fragdoc);
-
 
137
 
-
 
138
				StringWriter sw = new StringWriter();
-
 
139
				XMLOutputFactory xof = XMLOutputFactory.newInstance();
-
 
140
				XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
-
 
141
				document.serialize(writer);
-
 
142
 
-
 
143
				this.logger.trace(sw.getBuffer().toString());
-
 
144
				return sw.getBuffer().toString();
-
 
145
			} catch (JaxenException e) {
-
 
146
				e.printStackTrace();
-
 
147
				throw new XServicesFault(e);
-
 
148
			} catch (XMLStreamException e) {
-
 
149
				e.printStackTrace();
-
 
150
				throw new XServicesFault(e);
-
 
151
			} catch (IOException e) {
-
 
152
				e.printStackTrace();
-
 
153
				throw new XServicesFault(e);
122
				throw new XServicesFault("No xmldata to insert.");
-
 
123
			}
-
 
124
 
-
 
125
			// Initialize XPath context
-
 
126
			SimpleNamespaceContext context = createContext(nsList);
-
 
127
			axp.setNamespaceContext(context);
-
 
128
			axp.addNamespaces(fragdoc.getOMDocumentElement());
-
 
129
 
-
 
130
			OMDocument document = replaceNodes(sourcedoc, axp, fragdoc);
-
 
131
 
-
 
132
			StringWriter sw = new StringWriter();
-
 
133
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
-
 
134
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
-
 
135
			document.serialize(writer);
-
 
136
 
-
 
137
			this.logger.trace(sw.getBuffer().toString());
-
 
138
			return sw.getBuffer().toString();
-
 
139
		} catch (JaxenException e) {
-
 
140
			e.printStackTrace();
-
 
141
			throw new XServicesFault(e);
-
 
142
		} catch (XMLStreamException e) {
-
 
143
			e.printStackTrace();
-
 
144
			throw new XServicesFault(e);
-
 
145
		} catch (IOException e) {
-
 
146
			e.printStackTrace();
-
 
147
			throw new XServicesFault(e);
154
			}
148
		}
Line 155... Line 149...
155
	}
149
	}
-
 
150
 
156
 
151
	public String replaceNodes(String source, String encoding, NamespaceListType nsList, String xpath,
157
	public String replaceNodes(String source, String encoding, NamespaceListType nsList, String xpath, String xmlFragment) throws XServicesFault {
152
			String xmlFragment) throws XServicesFault {
158
		encoding = validateEncoding(encoding);
153
		encoding = validateEncoding(encoding);
159
		try {
154
		try {
160
			AXIOMXPath axp = new AXIOMXPath(xpath);
155
			AXIOMXPath axp = new AXIOMXPath(xpath);
161
			InputStream is = new ByteArrayInputStream(source.getBytes(encoding));
-
 
162
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is)
156
			InputStream is = new ByteArrayInputStream(source.getBytes(encoding));
163
					.getDocument();
157
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is).getDocument();
164
			OMDocument fragdoc = null;
-
 
165
			if ((xmlFragment != null) && (new String(xmlFragment).length() > 0)) {
158
			OMDocument fragdoc = null;
166
				fragdoc = OMXMLBuilderFactory.createOMBuilder(
159
			if ((xmlFragment != null) && (new String(xmlFragment).length() > 0)) {
167
						new StringReader("<XS>" + xmlFragment + "</XS>"))
160
				fragdoc = OMXMLBuilderFactory.createOMBuilder(new StringReader("<XS>" + xmlFragment + "</XS>"))
168
						.getDocument();
161
						.getDocument();
169
			} else {
162
			} else {
Line 192... Line 185...
192
			throw new XServicesFault(e);
185
			throw new XServicesFault(e);
193
		} catch (UnsupportedEncodingException e) {
186
		} catch (UnsupportedEncodingException e) {
194
			throw new XServicesFault(e);
187
			throw new XServicesFault(e);
195
		}
188
		}
196
	}
189
	}
197
	
190
 
198
	@RequiresPermissions("insertNodes")
191
	@RequiresPermissions("insertNodes")
199
	public String insertNodes(String source, String encoding, NamespaceListType nsList, String xpath, String xmlFragment) throws XServicesFault {
192
	public String insertNodes(String source, String encoding, NamespaceListType nsList, String xpath,
-
 
193
			String xmlFragment) throws XServicesFault {
200
		encoding = validateEncoding(encoding);
194
		encoding = validateEncoding(encoding);
201
		try {
195
		try {
202
			AXIOMXPath axp = new AXIOMXPath(xpath);
196
			AXIOMXPath axp = new AXIOMXPath(xpath);
203
			InputStream is = new ByteArrayInputStream(source.getBytes(encoding));
197
			InputStream is = new ByteArrayInputStream(source.getBytes(encoding));
204
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is)
198
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is).getDocument();
205
					.getDocument();
-
 
206
			OMDocument fragdoc = null;
199
			OMDocument fragdoc = null;
207
			if ((xmlFragment != null) && (new String(xmlFragment).length() > 0)) {
200
			if ((xmlFragment != null) && (new String(xmlFragment).length() > 0)) {
208
				fragdoc = OMXMLBuilderFactory.createOMBuilder(
-
 
209
						new StringReader("<XS>" + xmlFragment + "</XS>"))
201
				fragdoc = OMXMLBuilderFactory.createOMBuilder(new StringReader("<XS>" + xmlFragment + "</XS>"))
210
						.getDocument();
202
						.getDocument();
211
			} else {
203
			} else {
212
				throw new XServicesFault("No xmldata to insert.");
204
				throw new XServicesFault("No xmldata to insert.");
213
			}
205
			}
Line 236... Line 228...
236
			throw new XServicesFault(e);
228
			throw new XServicesFault(e);
237
		}
229
		}
238
	}
230
	}
Line 239... Line 231...
239
 
231
 
240
	public String wrapInCDATA(String data) throws XServicesFault {
232
	public String wrapInCDATA(String data) throws XServicesFault {
241
		String result ="";
233
		String result = "";
242
		String[] tokens = data.split("\\]\\]>", -1);
234
		String[] tokens = data.split("\\]\\]>", -1);
243
		
235
 
244
		for(int i=0; i<tokens.length; i++) {
236
		for (int i = 0; i < tokens.length; i++) {
-
 
237
			result += tokens[i];
245
			result +=  tokens[i];
238
			if (i + 1 < tokens.length)
246
			if (i+1 < tokens.length ) result += "]]]]><![CDATA[>";
239
				result += "]]]]><![CDATA[>";
247
		}
240
		}
248
		
241
 
249
		result = "<![CDATA[" + result + "]]>";
242
		result = "<![CDATA[" + result + "]]>";
250
		return result;
243
		return result;
Line 251... Line 244...
251
	}
244
	}
-
 
245
 
252
 
246
	public StringSplitType selectXPath(String source, String encoding, NamespaceListType nsList, String xpath)
253
	public StringSplitType selectXPath(String source, String encoding, NamespaceListType nsList, String xpath) throws XServicesFault {
247
			throws XServicesFault {
254
		encoding = validateEncoding(encoding);
248
		encoding = validateEncoding(encoding);
255
		try {
249
		try {
256
			StringSplitType rarray = new StringSplitType();
250
			StringSplitType rarray = new StringSplitType();
257
			AXIOMXPath axp = new AXIOMXPath(xpath);
251
			AXIOMXPath axp = new AXIOMXPath(xpath);
258
			InputStream is = new ByteArrayInputStream(source.getBytes(encoding));
252
			InputStream is = new ByteArrayInputStream(source.getBytes(encoding));
259
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is).getDocument();
253
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is).getDocument();
260
			
254
 
261
			// Initialize XPath context
255
			// Initialize XPath context
262
			SimpleNamespaceContext context = createContext(nsList);
256
			SimpleNamespaceContext context = createContext(nsList);
263
			
257
 
264
			axp.setNamespaceContext(context);
258
			axp.setNamespaceContext(context);
265
			List results = axp.selectNodes(sourcedoc);
259
			List results = axp.selectNodes(sourcedoc);
266
			for(Object o : results) {
260
			for (Object o : results) {
267
				String text = null;
261
				String text = null;
268
				
262
 
269
				if(o instanceof OMNode) {
263
				if (o instanceof OMNode) {
270
					switch (((OMNode)o).getType()) {
264
					switch (((OMNode) o).getType()) {
271
						case OMNode.TEXT_NODE:
265
					case OMNode.TEXT_NODE:
272
							text = ((OMText)o).getText();
266
						text = ((OMText) o).getText();
273
							break;
267
						break;
274
						case OMNode.COMMENT_NODE:
268
					case OMNode.COMMENT_NODE:
275
							text = ((OMComment)o).getValue();
269
						text = ((OMComment) o).getValue();
276
							break;
270
						break;
277
						case OMNode.PI_NODE:
271
					case OMNode.PI_NODE:
278
							text = ((OMProcessingInstruction)o).getValue();
272
						text = ((OMProcessingInstruction) o).getValue();
279
							break;
273
						break;
280
						default:
274
					default:
281
							StringWriter sw = new StringWriter();
275
						StringWriter sw = new StringWriter();
282
							XMLOutputFactory xof = XMLOutputFactory.newInstance();
276
						XMLOutputFactory xof = XMLOutputFactory.newInstance();
283
							XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
277
						XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
284
							((OMNode)o).serialize(writer);
278
						((OMNode) o).serialize(writer);
285
							writer.flush();
279
						writer.flush();
286
							text = sw.toString();							
280
						text = sw.toString();
287
					}					
281
					}
288
				} else if(o instanceof OMAttribute) {
282
				} else if (o instanceof OMAttribute) {
289
					text = ((OMAttribute)o).getAttributeValue();
283
					text = ((OMAttribute) o).getAttributeValue();
290
				} else {
284
				} else {
291
					text = String.valueOf(o);
285
					text = String.valueOf(o);
292
				}
286
				}
293
				rarray.addStringMatch(text);
-
 
Line 294... Line 287...
294
			}
287
				rarray.addStringMatch(text);
295
			
288
			}
296
 
289
 
297
			return rarray;
290
			return rarray;
298
			} catch (JaxenException e) {
291
		} catch (JaxenException e) {
299
			e.printStackTrace();
292
			e.printStackTrace();
300
			throw new XServicesFault(e);
293
			throw new XServicesFault(e);
301
		} catch (XMLStreamException e) {
294
		} catch (XMLStreamException e) {
302
				// TODO Auto-generated catch block
295
			// TODO Auto-generated catch block
303
			throw new XServicesFault(e.getMessage());
296
			throw new XServicesFault(e.getMessage());
304
			} catch (UnsupportedEncodingException e) {
297
		} catch (UnsupportedEncodingException e) {
305
				throw new XServicesFault(e);
298
			throw new XServicesFault(e);
306
		}
299
		}
-
 
300
	}
307
	}
301
 
308
	
302
	public String setAttribute(String source, String encoding, NamespaceListType nsList, String xpath,
309
	public String setAttribute(String source, String encoding, NamespaceListType nsList, String xpath, AttributeType attr) throws XServicesFault {
303
			AttributeType attr) throws XServicesFault {
310
		encoding = validateEncoding(encoding);
304
		encoding = validateEncoding(encoding);
311
		try {
305
		try {
312
			StringSplitType rarray = new StringSplitType();
306
			StringSplitType rarray = new StringSplitType();
313
			AXIOMXPath axp = new AXIOMXPath(xpath);
307
			AXIOMXPath axp = new AXIOMXPath(xpath);
314
			InputStream is = new ByteArrayInputStream(source.getBytes(encoding));
308
			InputStream is = new ByteArrayInputStream(source.getBytes(encoding));
315
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is).getDocument();
309
			OMDocument sourcedoc = OMXMLBuilderFactory.createOMBuilder(is).getDocument();
316
			OMFactory fac = OMAbstractFactory.getOMFactory();
310
			OMFactory fac = OMAbstractFactory.getOMFactory();
317
			
311
 
318
			// Initialize XPath context
312
			// Initialize XPath context
319
			SimpleNamespaceContext context = createContext(nsList);
313
			SimpleNamespaceContext context = createContext(nsList);
320
			
314
 
321
			axp.setNamespaceContext(context);
315
			axp.setNamespaceContext(context);
322
			List results = axp.selectNodes(sourcedoc);
316
			List results = axp.selectNodes(sourcedoc);
323
			for(Object o : results) {
317
			for (Object o : results) {
324
				String text = null;
318
				String text = null;
325
				
319
 
326
				if(o instanceof OMNode) {
320
				if (o instanceof OMNode) {
327
					switch (((OMNode)o).getType()) {
321
					switch (((OMNode) o).getType()) {
328
						case OMNode.ELEMENT_NODE:
322
					case OMNode.ELEMENT_NODE:
329
							OMElement node = ((OMElement)o);
323
						OMElement node = ((OMElement) o);
330
							if(attr.value == null) {
324
						if (attr.value == null) {
331
								node.removeAttribute( node.getAttribute(new QName(attr.name)));
325
							node.removeAttribute(node.getAttribute(new QName(attr.name)));
332
							} else {
326
						} else {
333
								node.addAttribute(attr.name, attr.value, node.getNamespace());
327
							node.addAttribute(attr.name, attr.value, node.getNamespace());
334
							}
328
						}
335
							break;
329
						break;
336
						default:
330
					default:
337
							throw new XServicesFault("XPath expression did not match an element node.");
331
						throw new XServicesFault("XPath expression did not match an element node.");
338
					}
332
					}
339
				} else {
333
				} else {
340
					throw new XServicesFault("XPath expression did not match a node.");
334
					throw new XServicesFault("XPath expression did not match a node.");
341
				}
335
				}
342
			}
336
			}
343
						
337
 
344
			StringWriter sw = new StringWriter();
338
			StringWriter sw = new StringWriter();
345
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
339
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
346
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
340
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
347
			sourcedoc.serialize(writer);
341
			sourcedoc.serialize(writer);
348
			writer.flush();
342
			writer.flush();
349
			return sw.toString();	
343
			return sw.toString();
350
			} catch (JaxenException e) {
344
		} catch (JaxenException e) {
351
			e.printStackTrace();
345
			e.printStackTrace();
352
			throw new XServicesFault(e);
346
			throw new XServicesFault(e);
353
		} catch (XMLStreamException e) {
347
		} catch (XMLStreamException e) {
354
				// TODO Auto-generated catch block
348
			// TODO Auto-generated catch block
355
			throw new XServicesFault(e.getMessage());
349
			throw new XServicesFault(e.getMessage());
356
			} catch (UnsupportedEncodingException e) {
350
		} catch (UnsupportedEncodingException e) {
357
				throw new XServicesFault(e);
351
			throw new XServicesFault(e);
358
		}
352
		}
-
 
353
	}
359
	}
354
 
360
	
355
	private OMDocument insertNodes(OMDocument xmldocument, AXIOMXPath axp, OMDocument xmlfragment)
361
	private OMDocument insertNodes(OMDocument xmldocument, AXIOMXPath axp,OMDocument xmlfragment) throws XServicesFault {
356
			throws XServicesFault {
362
		List<?> olist = null;
357
		List<?> olist = null;
363
		try {
-
 
364
			olist = axp.selectNodes(xmldocument.getOMDocumentElement());
358
		try {
365
			this.logger.debug("XPath '" + axp.toString() + "' has "
-
 
366
					+ olist.size() + " matches.");
359
			olist = axp.selectNodes(xmldocument.getOMDocumentElement());
367
			this.logger.trace("XPath root expression is: '" + axp.debug()
360
			this.logger.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
368
					+ "'.");
361
			this.logger.trace("XPath root expression is: '" + axp.debug() + "'.");
369
		} catch (JaxenException e) {
362
		} catch (JaxenException e) {
370
			throw new XServicesFault(e.getMessage(), e);
363
			throw new XServicesFault(e.getMessage(), e);
371
		}
-
 
Line 372... Line 364...
372
		if (olist.size() == 0)
364
		}
373
			throw new XServicesFault(Messages.getString("XmlService.no_match",
365
		if (olist.size() == 0)
Line 374... Line 366...
374
					new Object[] { axp.toString() }));
366
			throw new XServicesFault(Messages.getString("XmlService.no_match", new Object[] { axp.toString() }));
375
 
367
 
376
		// Prepare children to insert
368
		// Prepare children to insert
377
		xmlfragment.build();
369
		xmlfragment.build();
378
 
-
 
379
		// Determine what has been matched
370
 
380
		OMContainer match = null;
371
		// Determine what has been matched
381
		for (Object o : olist) {
372
		OMContainer match = null;
382
			Iterator<?> children = xmlfragment.getOMDocumentElement()
373
		for (Object o : olist) {
383
					.getChildren();
374
			Iterator<?> children = xmlfragment.getOMDocumentElement().getChildren();
Line 399... Line 390...
399
					// match = node.getParent();
390
					// match = node.getParent();
400
					match = (OMContainer) node;
391
					match = (OMContainer) node;
401
					this.logger.debug(Messages.getString("XmlService.10"));
392
					this.logger.debug(Messages.getString("XmlService.10"));
402
					break;
393
					break;
403
				default:
394
				default:
404
					this.logger.error("XPath matched "
395
					this.logger
405
							+ o.getClass().getCanonicalName() + " Node Type:"
396
							.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
406
							+ node.getType());
-
 
407
					this.logger.error(Messages.getString("XmlService.11"));
397
					this.logger.error(Messages.getString("XmlService.11"));
408
					throw new XServicesFault(
-
 
409
							Messages.getString("XmlService.12"));
398
					throw new XServicesFault(Messages.getString("XmlService.12"));
410
				}
399
				}
411
			} else {
400
			} else {
412
				this.logger.error("XPath matched "
-
 
413
						+ o.getClass().getCanonicalName());
401
				this.logger.error("XPath matched " + o.getClass().getCanonicalName());
414
				this.logger.error(Messages.getString("XmlService.11"));
402
				this.logger.error(Messages.getString("XmlService.11"));
415
				throw new XServicesFault(Messages.getString("XmlService.12"));
403
				throw new XServicesFault(Messages.getString("XmlService.12"));
416
			}
404
			}
Line 417... Line 405...
417
 
405
 
Line 423... Line 411...
423
 
411
 
424
		xmldocument.build();
412
		xmldocument.build();
425
		return xmldocument;
413
		return xmldocument;
Line -... Line 414...
-
 
414
	}
-
 
415
 
Line 426... Line -...
426
	}
-
 
427
 
-
 
428
 
416
	private OMDocument replaceNodes(OMDocument xmldocument, AXIOMXPath axp, OMDocument xmlfragment)
429
	private OMDocument replaceNodes(OMDocument xmldocument, AXIOMXPath axp, OMDocument xmlfragment) throws XServicesFault {
417
			throws XServicesFault {
430
		
418
 
431
		List<?> olist = null;
419
		List<?> olist = null;
432
		try {
-
 
433
			olist = axp.selectNodes(xmldocument.getOMDocumentElement());
420
		try {
434
			this.logger.debug("XPath '" + axp.toString() + "' has "
-
 
435
					+ olist.size() + " matches.");
421
			olist = axp.selectNodes(xmldocument.getOMDocumentElement());
436
			this.logger.trace("XPath root expression is: '" + axp.debug()
422
			this.logger.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
437
					+ "'.");
423
			this.logger.trace("XPath root expression is: '" + axp.debug() + "'.");
438
		} catch (JaxenException e) {
424
		} catch (JaxenException e) {
439
			throw new XServicesFault(e.getMessage(), e);
425
			throw new XServicesFault(e.getMessage(), e);
440
		}
-
 
Line 441... Line 426...
441
		if (olist.size() == 0)
426
		}
442
			throw new XServicesFault(Messages.getString("XmlService.no_match",
427
		if (olist.size() == 0)
Line 443... Line 428...
443
					new Object[] { axp.toString() }));
428
			throw new XServicesFault(Messages.getString("XmlService.no_match", new Object[] { axp.toString() }));
444
 
429
 
445
		// Prepare children to insert
430
		// Prepare children to insert
446
		xmlfragment.build();
431
		xmlfragment.build();
447
 
-
 
448
		// Determine what has been matched
432
 
449
		OMNode match = null;
433
		// Determine what has been matched
450
		for (Object o : olist) {
434
		OMNode match = null;
451
			Iterator<?> children = xmlfragment.getOMDocumentElement()
435
		for (Object o : olist) {
452
					.getChildren();
436
			Iterator<?> children = xmlfragment.getOMDocumentElement().getChildren();
Line 459... Line 443...
459
					if ((o instanceof OMDocument))
443
					if ((o instanceof OMDocument))
460
						match = ((OMDocument) o).getOMDocumentElement();
444
						match = ((OMDocument) o).getOMDocumentElement();
461
					this.logger.debug(Messages.getString("XmlService.8"));
445
					this.logger.debug(Messages.getString("XmlService.8"));
462
					break;
446
					break;
463
				default:
447
				default:
464
					this.logger.error("XPath matched "
448
					this.logger
465
							+ o.getClass().getCanonicalName() + " Node Type:"
449
							.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
466
							+ node.getType());
-
 
467
					this.logger.error(Messages.getString("XmlService.11"));
450
					this.logger.error(Messages.getString("XmlService.11"));
468
					throw new XServicesFault(
-
 
469
							Messages.getString("XmlService.12"));
451
					throw new XServicesFault(Messages.getString("XmlService.12"));
470
				}
452
				}
471
			} else {
453
			} else {
472
				this.logger.error("XPath matched "
-
 
473
						+ o.getClass().getCanonicalName());
454
				this.logger.error("XPath matched " + o.getClass().getCanonicalName());
474
				this.logger.error(Messages.getString("XmlService.11"));
455
				this.logger.error(Messages.getString("XmlService.11"));
475
				throw new XServicesFault(Messages.getString("XmlService.12"));
456
				throw new XServicesFault(Messages.getString("XmlService.12"));
476
			}
457
			}
Line 477... Line 458...
477
 
458
 
Line 486... Line 467...
486
	}
467
	}
Line 487... Line 468...
487
 
468
 
488
	private SimpleNamespaceContext createContext(NamespaceListType nsList) {
469
	private SimpleNamespaceContext createContext(NamespaceListType nsList) {
489
		// Initialize XPath context
470
		// Initialize XPath context
490
		SimpleNamespaceContext context = new SimpleNamespaceContext();
471
		SimpleNamespaceContext context = new SimpleNamespaceContext();
491
		if(nsList != null) {
472
		if (nsList != null) {
492
			for (NamespaceType ns : nsList.getNamespaces()) {
473
			for (NamespaceType ns : nsList.getNamespaces()) {
493
				context.addNamespace(ns.getPrefix(), ns.getUri().toString());
474
				context.addNamespace(ns.getPrefix(), ns.getUri().toString());
494
				this.logger.debug(Messages.getString("XmlService.0")
475
				this.logger.debug(
495
						+ ns.getPrefix() + "=\"" + ns.getUri().toString()
-
 
496
						+ "\"'");
476
						Messages.getString("XmlService.0") + ns.getPrefix() + "=\"" + ns.getUri().toString() + "\"'");
497
			}
477
			}
498
		} else {
478
		} else {
499
			logger.debug("No namespaces defined.");
479
			logger.debug("No namespaces defined.");
500
		}
480
		}
501
		return context;
481
		return context;
Line 502... Line 482...
502
	}
482
	}
-
 
483
 
503
 
484
	private String validateEncoding(String encoding) throws XServicesFault {
-
 
485
		if (encoding == null || encoding.equals("")) {
504
	private String validateEncoding(String encoding) throws XServicesFault {
486
			encoding = Charset.defaultCharset().displayName();
505
		if(encoding == null || encoding.equals("")) { encoding=Charset.defaultCharset().displayName(); }
487
		}
506
		try { 
488
		try {
507
			Charset.isSupported(encoding);
489
			Charset.isSupported(encoding);
508
		} catch (IllegalCharsetNameException e) {
490
		} catch (IllegalCharsetNameException e) {
509
			throw new XServicesFault("Endcoding '"+encoding+"' is not supported by this JRE.");
491
			throw new XServicesFault("Endcoding '" + encoding + "' is not supported by this JRE.");
510
		}
492
		}
511
		logger.debug("Setting source xml string encoding to '"+encoding+"'");
493
		logger.debug("Setting source xml string encoding to '" + encoding + "'");
512
		return encoding;
-
 
Line 513... Line 494...
513
	}
494
		return encoding;