001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.bpmscript.jbi;
018:
019: import java.io.IOException;
020: import java.io.Reader;
021:
022: import javax.jbi.messaging.MessagingException;
023: import javax.jbi.messaging.NormalizedMessage;
024: import javax.xml.parsers.DocumentBuilder;
025: import javax.xml.parsers.DocumentBuilderFactory;
026: import javax.xml.parsers.ParserConfigurationException;
027: import javax.xml.transform.Result;
028: import javax.xml.transform.Source;
029: import javax.xml.transform.Transformer;
030: import javax.xml.transform.TransformerConfigurationException;
031: import javax.xml.transform.TransformerException;
032: import javax.xml.transform.TransformerFactory;
033: import javax.xml.transform.dom.DOMSource;
034: import javax.xml.transform.sax.SAXSource;
035: import javax.xml.transform.stream.StreamSource;
036:
037: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
038: import org.apache.servicemix.jbi.jaxp.StringSource;
039: import org.w3c.dom.Document;
040: import org.w3c.dom.Node;
041: import org.xml.sax.SAXException;
042:
043: public class SourceUtils {
044:
045: private static final SourceTransformer sourceTransformer = new SourceTransformer();
046:
047: public static String contentToString(NormalizedMessage message)
048: throws MessagingException, TransformerException,
049: ParserConfigurationException, IOException, SAXException {
050: return sourceTransformer.contentToString(message);
051: }
052:
053: public static Document createDocument()
054: throws ParserConfigurationException {
055: return sourceTransformer.createDocument();
056: }
057:
058: public static DocumentBuilder createDocumentBuilder()
059: throws ParserConfigurationException {
060: return sourceTransformer.createDocumentBuilder();
061: }
062:
063: public static DocumentBuilderFactory createDocumentBuilderFactory() {
064: return sourceTransformer.createDocumentBuilderFactory();
065: }
066:
067: public static Transformer createTransfomer()
068: throws TransformerConfigurationException {
069: return sourceTransformer.createTransfomer();
070: }
071:
072: public static TransformerFactory createTransformerFactory() {
073: return sourceTransformer.createTransformerFactory();
074: }
075:
076: public static DocumentBuilderFactory getDocumentBuilderFactory() {
077: return sourceTransformer.getDocumentBuilderFactory();
078: }
079:
080: public static TransformerFactory getTransformerFactory() {
081: return sourceTransformer.getTransformerFactory();
082: }
083:
084: public static void setDocumentBuilderFactory(
085: DocumentBuilderFactory documentBuilderFactory) {
086: sourceTransformer
087: .setDocumentBuilderFactory(documentBuilderFactory);
088: }
089:
090: public static void setTransformerFactory(
091: TransformerFactory transformerFactory) {
092: sourceTransformer.setTransformerFactory(transformerFactory);
093: }
094:
095: public static Node toDOMNode(NormalizedMessage message)
096: throws MessagingException, TransformerException,
097: ParserConfigurationException, IOException, SAXException {
098: return sourceTransformer.toDOMNode(message);
099: }
100:
101: public static Node toDOMNode(Source source)
102: throws TransformerException, ParserConfigurationException,
103: IOException, SAXException {
104: return sourceTransformer.toDOMNode(source);
105: }
106:
107: public static Node toDOMNodeFromSAX(SAXSource source)
108: throws ParserConfigurationException, IOException,
109: SAXException {
110: return sourceTransformer.toDOMNodeFromSAX(source);
111: }
112:
113: public static Source toDOMSource(NormalizedMessage message)
114: throws MessagingException, TransformerException,
115: ParserConfigurationException, IOException, SAXException {
116: return sourceTransformer.toDOMSource(message);
117: }
118:
119: public static DOMSource toDOMSource(Source source)
120: throws ParserConfigurationException, IOException,
121: SAXException, TransformerException {
122: return sourceTransformer.toDOMSource(source);
123: }
124:
125: public static DOMSource toDOMSourceFromSAX(SAXSource source)
126: throws IOException, SAXException,
127: ParserConfigurationException {
128: return sourceTransformer.toDOMSourceFromSAX(source);
129: }
130:
131: public static DOMSource toDOMSourceFromStream(StreamSource source)
132: throws ParserConfigurationException, IOException,
133: SAXException {
134: return sourceTransformer.toDOMSourceFromStream(source);
135: }
136:
137: public static Reader toReaderFromSource(Source src)
138: throws TransformerException {
139: return sourceTransformer.toReaderFromSource(src);
140: }
141:
142: public static void toResult(Source source, Result result)
143: throws TransformerException {
144: sourceTransformer.toResult(source, result);
145: }
146:
147: public static SAXSource toSAXSource(Source source)
148: throws IOException, SAXException {
149: return sourceTransformer.toSAXSource(source);
150: }
151:
152: public static SAXSource toSAXSourceFromDOM(DOMSource source) {
153: return sourceTransformer.toSAXSourceFromDOM(source);
154: }
155:
156: public static SAXSource toSAXSourceFromStream(StreamSource source) {
157: return sourceTransformer.toSAXSourceFromStream(source);
158: }
159:
160: public static StreamSource toStreamSource(Source source)
161: throws TransformerException {
162: return sourceTransformer.toStreamSource(source);
163: }
164:
165: public static StreamSource toStreamSource(String source)
166: throws TransformerException {
167: if (source == null) {
168: return null;
169: }
170: return new StringSource(source);
171: }
172:
173: public static StreamSource toStreamSourceFromDOM(DOMSource source)
174: throws TransformerException {
175: return sourceTransformer.toStreamSourceFromDOM(source);
176: }
177:
178: public static StreamSource toStreamSourceFromSAX(SAXSource source)
179: throws TransformerException {
180: return sourceTransformer.toStreamSourceFromSAX(source);
181: }
182:
183: public static String toString(Node node)
184: throws TransformerException {
185: return sourceTransformer.toString(node);
186: }
187:
188: public static String toString(Source source)
189: throws TransformerException {
190: return sourceTransformer.toString(source);
191: }
192:
193: }
|