Moved MethodEndpoint functionality to core-tiger module. (Fixed #SWS-20)
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.xml.dom;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
@@ -36,11 +37,12 @@ public abstract class DomUtils {
|
||||
/**
|
||||
* Returns the root element of the given source, transforming it if necessary.
|
||||
*
|
||||
* @param source the source to get the root element from
|
||||
* @param transformer a transformer
|
||||
* @param source the source to get the root element from
|
||||
* @param transformerFactory a transformer factory, necessary if the given source is not a <code>DOMSource</code>
|
||||
* @return the root element
|
||||
*/
|
||||
public static Element getRootElement(Source source, Transformer transformer) throws TransformerException {
|
||||
public static Element getRootElement(Source source, TransformerFactory transformerFactory)
|
||||
throws TransformerException {
|
||||
if (source instanceof DOMSource) {
|
||||
DOMSource domSource = (DOMSource) source;
|
||||
Node node = domSource.getNode();
|
||||
@@ -55,6 +57,7 @@ public abstract class DomUtils {
|
||||
return document.getDocumentElement();
|
||||
}
|
||||
}
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(source, domResult);
|
||||
Document document = (Document) domResult.getNode();
|
||||
|
||||
@@ -34,9 +34,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
*/
|
||||
public abstract class TransformerObjectSupport {
|
||||
|
||||
/**
|
||||
* Logger available to subclasses.
|
||||
*/
|
||||
/** Logger available to subclasses. */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private static TransformerFactory transformerFactory;
|
||||
@@ -45,6 +43,11 @@ public abstract class TransformerObjectSupport {
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
}
|
||||
|
||||
/** Returns the <code>TransformerFactory</code>. */
|
||||
protected TransformerFactory getTransformerFactory() {
|
||||
return transformerFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Transformer</code>. Must be called per request, as transformer is not thread-safe.
|
||||
*
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.io.StringReader;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
@@ -34,16 +33,16 @@ import org.xml.sax.InputSource;
|
||||
|
||||
public class DomUtilsTest extends TestCase {
|
||||
|
||||
private Transformer transformer;
|
||||
|
||||
private static final String NAMESPACE = "http://springframework.org/spring-ws";
|
||||
|
||||
private static final String LOCAL_NAME = "Root";
|
||||
|
||||
private static final String XML = "<" + LOCAL_NAME + " xmlns='" + NAMESPACE + "'/>";
|
||||
|
||||
private TransformerFactory transformerFactory;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
}
|
||||
|
||||
public void testGetRootElementDomSource() throws Exception {
|
||||
@@ -67,7 +66,7 @@ public class DomUtilsTest extends TestCase {
|
||||
}
|
||||
|
||||
private void testSource(Source source) throws TransformerException {
|
||||
Element result = DomUtils.getRootElement(source, transformer);
|
||||
Element result = DomUtils.getRootElement(source, transformerFactory);
|
||||
assertNotNull("No result", result);
|
||||
assertEquals("Invalid namespace", NAMESPACE, result.getNamespaceURI());
|
||||
assertEquals("Invalid local name", LOCAL_NAME, result.getLocalName());
|
||||
|
||||
Reference in New Issue
Block a user