|
From: <tr...@us...> - 2003-06-27 00:15:11
|
Update of /cvsroot/babeldoc/babeldoc/modules/soap/src/com/babeldoc/soap/pipeline/util In directory sc8-pr-cvs1:/tmp/cvs-serv19206/modules/soap/src/com/babeldoc/soap/pipeline/util Modified Files: SoapHelper.java Log Message: Updated the build system using an explicit modular ant task. This is better than the method previously employed which added "hidden" tasks to the build and clean etc targets. Additionally using a more robust module sorting algorithm. Index: SoapHelper.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/soap/src/com/babeldoc/soap/pipeline/util/SoapHelper.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SoapHelper.java 22 May 2003 03:20:32 -0000 1.6 --- SoapHelper.java 27 Jun 2003 00:14:56 -0000 1.7 *************** *** 1,22 **** ! /* ! * $Header$ ! * $DateTime:$ * * ! * babeldoc: universal document processor * ! * This program is free software; you can redistribute it and/or ! * modify it under the terms of the GNU General Public License ! * as published by the Free Software Foundation; either version 2 ! * of the License, or (at your option) any later version. * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.babeldoc.soap.pipeline.util; --- 1,66 ---- ! /* ==================================================================== ! * The Apache Software License, Version 1.1 * + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. * ! * Redistribution and use in source and binary forms, with or without ! * modification, are permitted provided that the following conditions ! * are met: * ! * 1. Redistributions of source code must retain the above copyright ! * notice, this list of conditions and the following disclaimer. * ! * 2. Redistributions in binary form must reproduce the above copyright ! * notice, this list of conditions and the following disclaimer in ! * the documentation and/or other materials provided with the ! * distribution. ! * ! * 3. The end-user documentation included with the redistribution, ! * if any, must include the following acknowledgment: ! * "This product includes software developed by the ! * Apache Software Foundation (http://www.apache.org/)." ! * Alternately, this acknowledgment may appear in the software itself, ! * if and wherever such third-party acknowledgments normally appear. ! * ! * 4. The names "Apache" and "Apache Software Foundation" must ! * not be used to endorse or promote products derived from this ! * software without prior written permission. For written ! * permission, please contact ap...@ap.... ! * ! * 5. Products derived from this software may not be called "Apache", ! * nor may "Apache" appear in their name, without prior written ! * permission of the Apache Software Foundation. ! * ! * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ! * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ! * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ! * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ! * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ! * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ! * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ! * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ! * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ! * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! * SUCH DAMAGE. ! * ==================================================================== ! * ! * This software consists of voluntary contributions made by many ! * individuals on behalf of the Apache Software Foundation. For more ! * information on the Apache Software Foundation, please see ! * <http://www.apache.org/>. ! * ! * Portions of this software are based upon public domain software ! * originally written at the National Center for Supercomputing Applications, ! * University of Illinois, Urbana-Champaign. ! * ==================================================================== ! * ! * Babeldoc: The Universal Document Processor ! * ! * $Header$ ! * $DateTime$ ! * $Author$ * */ package com.babeldoc.soap.pipeline.util; *************** *** 24,38 **** import com.babeldoc.core.pipeline.PipelineDocument; import com.babeldoc.core.pipeline.stage.DomifyPipelineStage; import org.dom4j.Element; import org.dom4j.io.DOMReader; import org.dom4j.io.XMLWriter; import org.w3c.dom.Document; - import javax.xml.soap.*; import java.io.IOException; import java.io.StringWriter; import java.util.Iterator; import java.util.Vector; /** --- 68,87 ---- import com.babeldoc.core.pipeline.PipelineDocument; import com.babeldoc.core.pipeline.stage.DomifyPipelineStage; + import org.dom4j.Element; + import org.dom4j.io.DOMReader; import org.dom4j.io.XMLWriter; + import org.w3c.dom.Document; import java.io.IOException; import java.io.StringWriter; + import java.util.Iterator; import java.util.Vector; + import javax.xml.soap.*; + /** *************** *** 44,203 **** */ public class SoapHelper { ! //~ Methods ································································ ! ! /** ! * a helper function to extract a {@link SOAPFault} from a given ! * <code>SOAPMessage</code>. {@link #containsFault(SOAPMessage} should be ! * called before. ! * ! * @param message the message to get the fault from ! * ! * @return the <code>SOAPFault</code> or <code>null</code> if there isn't ! * any ! * ! * @throws SOAPException if the extraction of the message's body failed ! */ ! public static SOAPFault getFault(SOAPMessage message) ! throws SOAPException { ! SOAPPart sp = message.getSOAPPart(); ! SOAPEnvelope se = sp.getEnvelope(); ! SOAPBody sb = se.getBody(); ! ! return sb.getFault(); ! } ! /** ! * A helper function to add a {@link SOAPFault} to a given ! * <code>SOAPMessage</code>. ! * ! * @param message the <code>SOAPMessage</code> to add the fault to ! * ! * @return the {@link SOAPFault} object that was added or an existing one, ! * if there already was one. ! * ! * @throws SOAPException if there is an error ! */ ! public static SOAPFault addFault(SOAPMessage message) ! throws SOAPException { ! SOAPPart part = message.getSOAPPart(); ! SOAPEnvelope envelope = part.getEnvelope(); ! SOAPBody body = envelope.getBody(); ! if (body.hasFault()) { ! return body.getFault(); ! } ! return body.addFault(); } ! /** ! * attaches a {@link Document} to a {@link SOAPMessage} at the moment this ! * is done by putting it in the body of the message. The way this happens ! * depends on the implementation of the javax.xml API and should propably ! * be replaced by something different. ! * ! * @param message the message, to which the document shall be attached ! * @param document the document to attach ! * ! * @throws SOAPException a {@link SOAPException} if something goes wrong ! * ! * @see <a ! * href="http://access1.sun.com/techarticles/SOAPMessage.XML.html">this ! * article</a> ! */ ! public static void attachDocument(SOAPMessage message, Document document) ! throws SOAPException { ! SOAPPart sp = message.getSOAPPart(); ! SOAPEnvelope envelope = sp.getEnvelope(); ! SOAPBody body = envelope.getBody(); ! DOMReader dr = new DOMReader(); ! org.dom4j.Document d = dr.read(document); ! Element e = d.getRootElement(); ! // TODO test for namespace ! // TODO should the whole thing be implemented with attachments? ! // if (e.getNamespace()==Namespace.NO_NAMESPACE) { ! // e.addNamespace("babeldoc","http://www.babeldoc.com/"); ! // } ! ((Element) body).add(e); ! } ! /** ! * attaches a {@link PipelineDocument} to a {@link SOAPMessage} at the ! * moment this is done by putting it in the body of the message. The way ! * this happens depends on the implementation of the javax.xml API and ! * should propably be replaced by something different. ! * ! * @param message the message, to which the document shall be attached ! * @param document the document to attach ! * ! * @throws SOAPException a {@link SOAPException} if something goes wrong ! * ! * @see <a ! * href="http://access1.sun.com/techarticles/SOAPMessage.XML.html">this ! * article</a> ! */ ! public static void attachDocument(SOAPMessage message, ! PipelineDocument document) throws SOAPException { ! org.w3c.dom.Document doc = DomifyPipelineStage.parseToDom(document, ! false); ! attachDocument(message, doc); ! } ! /** ! * a helper function to check whether a given <code>SOAPMessage</code> ! * contains a {@link SOAPFault}. ! * ! * @param message the message to check ! * ! * @return <code>true</code> if a <code>SOAPFault</code> exists in this ! * message, <code> false</code> otherwise. ! * ! * @throws SOAPException if the extraction of the message's body failed ! */ ! public static boolean containsFault(SOAPMessage message) ! throws SOAPException { ! SOAPPart sp = message.getSOAPPart(); ! SOAPEnvelope se = sp.getEnvelope(); ! SOAPBody sb = se.getBody(); ! return (sb.hasFault()); ! } ! /** ! * gives all {@link PipelineDocument PipelineDocuments} that were attached ! * to the given message. ! * ! * @param message the message containing the documents ! * ! * @return an <code>Iterator</code> for the contained ! * <code>PipelineDocuments</code> ! * ! * @throws SOAPException if the extraction of the documents fails ! * @throws IOException if a document cannot be converted to xml ! */ ! public static Iterator detachDocuments(SOAPMessage message) ! throws SOAPException, IOException { ! Vector docs = new Vector(); ! SOAPPart part = message.getSOAPPart(); ! SOAPEnvelope envelope = part.getEnvelope(); ! SOAPBody body = envelope.getBody(); ! for (Iterator it = body.getChildElements(); it.hasNext();) { ! SOAPElement element = (SOAPElement) it.next(); ! Element domElement = (Element) element; ! StringWriter string = new StringWriter(); ! XMLWriter writer = new XMLWriter(string); ! writer.write(domElement); ! String xml = writer.toString(); ! com.babeldoc.core.pipeline.PipelineDocument pdoc = new com.babeldoc.core.pipeline.PipelineDocument(xml.getBytes()); ! pdoc.setMimeType("text/xml"); ! docs.add(pdoc); ! } ! return docs.iterator(); } } --- 93,248 ---- */ public class SoapHelper { ! /** ! * a helper function to extract a {@link SOAPFault} from a given ! * <code>SOAPMessage</code>. {@link #containsFault(SOAPMessage} should be ! * called before. ! * ! * @param message the message to get the fault from ! * ! * @return the <code>SOAPFault</code> or <code>null</code> if there isn't any ! * ! * @throws SOAPException if the extraction of the message's body failed ! */ ! public static SOAPFault getFault(SOAPMessage message) ! throws SOAPException { ! SOAPPart sp = message.getSOAPPart(); ! SOAPEnvelope se = sp.getEnvelope(); ! SOAPBody sb = se.getBody(); ! return sb.getFault(); ! } ! /** ! * A helper function to add a {@link SOAPFault} to a given ! * <code>SOAPMessage</code>. ! * ! * @param message the <code>SOAPMessage</code> to add the fault to ! * ! * @return the {@link SOAPFault} object that was added or an existing one, if ! * there already was one. ! * ! * @throws SOAPException if there is an error ! */ ! public static SOAPFault addFault(SOAPMessage message) ! throws SOAPException { ! SOAPPart part = message.getSOAPPart(); ! SOAPEnvelope envelope = part.getEnvelope(); ! SOAPBody body = envelope.getBody(); ! if (body.hasFault()) { ! return body.getFault(); } ! return body.addFault(); ! } ! /** ! * attaches a {@link Document} to a {@link SOAPMessage} at the moment this is ! * done by putting it in the body of the message. The way this happens ! * depends on the implementation of the javax.xml API and should propably be ! * replaced by something different. ! * ! * @param message the message, to which the document shall be attached ! * @param document the document to attach ! * ! * @throws SOAPException a {@link SOAPException} if something goes wrong ! * ! * @see <a ! * href="http://access1.sun.com/techarticles/SOAPMessage.XML.html">this ! * article</a> ! */ ! public static void attachDocument(SOAPMessage message, Document document) ! throws SOAPException { ! SOAPPart sp = message.getSOAPPart(); ! SOAPEnvelope envelope = sp.getEnvelope(); ! SOAPBody body = envelope.getBody(); ! DOMReader dr = new DOMReader(); ! org.dom4j.Document d = dr.read(document); ! Element e = d.getRootElement(); ! // TODO test for namespace ! // TODO should the whole thing be implemented with attachments? ! // if (e.getNamespace()==Namespace.NO_NAMESPACE) { ! // e.addNamespace("babeldoc","http://www.babeldoc.com/"); ! // } ! ((Element) body).add(e); ! } ! /** ! * attaches a {@link PipelineDocument} to a {@link SOAPMessage} at the moment ! * this is done by putting it in the body of the message. The way this ! * happens depends on the implementation of the javax.xml API and should ! * propably be replaced by something different. ! * ! * @param message the message, to which the document shall be attached ! * @param document the document to attach ! * ! * @throws SOAPException a {@link SOAPException} if something goes wrong ! * ! * @see <a ! * href="http://access1.sun.com/techarticles/SOAPMessage.XML.html">this ! * article</a> ! */ ! public static void attachDocument(SOAPMessage message, ! PipelineDocument document) throws SOAPException { ! org.w3c.dom.Document doc = DomifyPipelineStage.parseToDom(document, false); ! attachDocument(message, doc); ! } ! /** ! * a helper function to check whether a given <code>SOAPMessage</code> ! * contains a {@link SOAPFault}. ! * ! * @param message the message to check ! * ! * @return <code>true</code> if a <code>SOAPFault</code> exists in this ! * message, <code> false</code> otherwise. ! * ! * @throws SOAPException if the extraction of the message's body failed ! */ ! public static boolean containsFault(SOAPMessage message) ! throws SOAPException { ! SOAPPart sp = message.getSOAPPart(); ! SOAPEnvelope se = sp.getEnvelope(); ! SOAPBody sb = se.getBody(); ! return (sb.hasFault()); ! } ! /** ! * gives all {@link PipelineDocument PipelineDocuments} that were attached to ! * the given message. ! * ! * @param message the message containing the documents ! * ! * @return an <code>Iterator</code> for the contained ! * <code>PipelineDocuments</code> ! * ! * @throws SOAPException if the extraction of the documents fails ! * @throws IOException if a document cannot be converted to xml ! */ ! public static Iterator detachDocuments(SOAPMessage message) ! throws SOAPException, IOException { ! Vector docs = new Vector(); ! SOAPPart part = message.getSOAPPart(); ! SOAPEnvelope envelope = part.getEnvelope(); ! SOAPBody body = envelope.getBody(); ! for (Iterator it = body.getChildElements(); it.hasNext();) { ! SOAPElement element = (SOAPElement) it.next(); ! Element domElement = (Element) element; ! StringWriter string = new StringWriter(); ! XMLWriter writer = new XMLWriter(string); ! writer.write(domElement); ! String xml = writer.toString(); ! com.babeldoc.core.pipeline.PipelineDocument pdoc = new com.babeldoc.core.pipeline.PipelineDocument(xml.getBytes()); ! pdoc.setMimeType("text/xml"); ! docs.add(pdoc); } + + return docs.iterator(); + } } |