axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ias" <iasan...@apache-korea.org>
Subject RE: setPretty forced on
Date Mon, 11 Aug 2003 20:20:12 GMT
In order to override Axis' default policies on pretty printing, I made a
workaround, for example, by extending SOAPBodyElement like the following:

package ias;

import org.apache.axis.encoding.SerializationContext;
import org.apache.axis.message.MessageElement;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.utils.Mapping;
import org.w3c.dom.Element;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author Ias
 * 
 * Print pretty elements
 */
public class PrettySoapBodyElement extends SOAPBodyElement {

    private Object objectValue = null;
    private ArrayList children = null;

    public PrettySoapBodyElement(Element elem) {
        super(elem);
    }

    protected void outputImpl(SerializationContext context) throws Exception
{
        if (elementRep != null) {
            boolean oldPretty = context.getPretty();
	// originally context.setPretty(false); from MessagElement
            context.setPretty(true);
            context.writeDOMElement(elementRep);
            context.setPretty(oldPretty);
            return;
        }

        if (textRep != null) {
            boolean oldPretty = context.getPretty();
            context.setPretty(false);
            context.writeSafeString(textRep.getData());
            context.setPretty(oldPretty);
            return;
        }

        if (prefix != null)
            context.registerPrefixForURI(prefix, namespaceURI);

        if (namespaces != null) {
            for (Iterator i = namespaces.iterator(); i.hasNext();) {
                Mapping mapping = (Mapping) i.next();
                context.registerPrefixForURI(mapping.getPrefix(),
mapping.getNamespaceURI());
            }
        }

        if (objectValue != null) {
            context.serialize(new QName(namespaceURI, name),
                    attributes,
                    objectValue, null, false, Boolean.TRUE);
            return;
        }

        context.startElement(new QName(namespaceURI, name), attributes);
        if (children != null) {
            for (Iterator it = children.iterator(); it.hasNext();) {
                ((MessageElement) it.next()).output(context);
            }
        }
        context.endElement();
    }

} 

In the above example, PrettySoapBodyElement changes how MessageElement, its
ancestor does pretty print for an element belonging to the class. I thought
Message should support adjusting pretty options, but soon found this kind of
workaround and decided not to modify MessageElement but to inherit and
override it.

I hope there would be a nicer approach for this issue essentially,

Ias.

> 
> -----Original Message-----
> From: Eric.D.Friedman@wellsfargo.com 
> [mailto:Eric.D.Friedman@wellsfargo.com] 
> Sent: Friday, August 08, 2003 4:53 PM
> To: axis-dev@ws.apache.org
> 
> Anyone know why SOAPEnvelope always forces 
> SerializationContextImpl to pretty print XML messages?  This 
> means that whitespace/indentation costs are incurred for 
> every serialized message: nice during debugging, but not in 
> production.  Why is this hardcoded in SOAPEnvelope?  Does 
> anyone object if I remove it?
> 


Mime
View raw message