libws-commons-util-1.0.1.orig/pom.xml 0000644 0001750 0001750 00000014422 10445606047 017742 0 ustar vladimir vladimir
Test case for the various instances of {@link java.text.Format},
* which are being used to parse special types like xs:dateTime
.
Returns whether the XMLWriter can encode the character
* c
without an escape sequence like &#ddd;.
XMLWriter
is indenting
* (pretty printing). If you want indenting,
* you should consider to invoke the methods
* {@link #setIndentString(java.lang.String)} and
* {@link #setLineFeed(java.lang.String)} as well.
* @param pIndenting Whether indentation is enabled. Defaults to false.
*/
public void setIndenting(boolean pIndenting);
/** Returns, whether the XMLWriter
is indenting
* (pretty printing). If you want indenting,
* you should consider to invoke the methods
* {@link #setIndentString(java.lang.String)} and
* {@link #setLineFeed(java.lang.String)} as well.
* @return Whether indentation is enabled. Defaults to false.
*/
public boolean isIndenting();
/** Sets the string being used to indent an XML element
* by one level. Ignored, if indentation is disabled.
* @param pIndentString The indentation string, by default " " (two blanks).
*/
void setIndentString(String pIndentString);
/** Returns the string being used to indent an XML element
* by one level. Ignored, if indentation is disabled.
* @return The indentation string, by default " " (two blanks).
*/
String getIndentString();
/** Sets the line terminator. Ignored, if indentation is
* disabled.
* @param pLineFeed The line terminator, by default "\n"
* (Line Feed). You might prefer "\r\n" (Carriage Return,
* Line Feed), which is the default on Windows and related
* operating systems.
*/
void setLineFeed(String pLineFeed);
/** Returns the line terminator. Ignored, if indentation is
* disabled.
* @return The line terminator, by default "\n"
* (Line Feed). You might prefer "\r\n" (Carriage Return,
* Line Feed), which is the default on Windows and related
* operating systems.
*/
String getLineFeed();
/** Sets, whether the method {@link org.xml.sax.ContentHandler#endDocument}
* should do a flush on the target stream.
* @param pFlushing True, if a flush should be done. Defaults to
* false.
*/
void setFlushing(boolean pFlushing);
/** Returns, whether the method {@link org.xml.sax.ContentHandler#endDocument}
* should do a flush on the target stream.
* @return True, if a flush should be done. Defaults to false.
*/
boolean isFlushing();
}
././@LongLink 0000000 0000000 0000000 00000000153 00000000000 011564 L ustar root root libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/OrderedAttributeXMLWriter.java libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/OrderedAttributeXMLWrite0000644 0001750 0001750 00000005316 10243730055 033746 0 ustar vladimir vladimir /*
* Copyright 2003, 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ws.commons.serialize;
import java.util.Arrays;
import java.util.Comparator;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/** A subclass of {@link org.apache.ws.commons.serialize.XMLWriterImpl},
* which writes the attributes ordered alphabetically. This is mainly
* useful for test purposes, when a canonical representation of the
* result is required for comparing against an expected value.
*/
public class OrderedAttributeXMLWriter extends XMLWriterImpl {
public void startElement(String pNamespaceURI, String pLocalName,
String pQName, final Attributes pAttrs)
throws SAXException {
Integer[] attributeNumbers = new Integer[pAttrs.getLength()];
for (int i = 0; i < attributeNumbers.length; i++) {
attributeNumbers[i] = new Integer(i);
}
Arrays.sort(attributeNumbers, new Comparator(){
public int compare(Object pNum1, Object pNum2) {
int i1 = ((Integer) pNum1).intValue();
int i2 = ((Integer) pNum2).intValue();
String uri1 = pAttrs.getURI(i1);
if (uri1 == null) {
uri1 = "";
}
String uri2 = pAttrs.getURI(i2);
if (uri2 == null) {
uri2 = "";
}
int result = uri1.compareTo(uri2);
if (result == 0) {
result = pAttrs.getLocalName(i1).compareTo(pAttrs.getLocalName(i2));
}
return result;
}
});
AttributesImpl orderedAttributes = new AttributesImpl();
for (int i = 0; i < attributeNumbers.length; i++) {
int num = attributeNumbers[i].intValue();
orderedAttributes.addAttribute(pAttrs.getURI(num), pAttrs.getLocalName(num),
pAttrs.getQName(num), pAttrs.getType(num),
pAttrs.getValue(num));
}
super.startElement(pNamespaceURI, pLocalName, pQName, orderedAttributes);
}
}
libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/DOMBuilder.java 0000644 0001750 0001750 00000015273 10243730055 031753 0 ustar vladimir vladimir /*
* Copyright 2003, 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ws.commons.serialize;
import java.util.ArrayList;
import java.util.List;
import javax.xml.XMLConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.EntityReference;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/** Converts a stream of SAX events into a DOM node.
*/
public class DOMBuilder implements ContentHandler {
private Document document;
private Node target;
private Node currentNode;
private Locator locator;
private boolean prefixMappingIsAttribute;
private List prefixes;
/** Sets whether the event {@link #startPrefixMapping}
* shall create an xmlns
attribute. Defaults
* to false.
* @return True, if xmlns
attributes are being
* created, false otherwise.
*/
public boolean isPrefixMappingIsAttribute() {
return prefixMappingIsAttribute;
}
/** Returns whether the event {@link #startPrefixMapping}
* shall create an xmlns
attribute. Defaults
* to false.
* @param pPrefixMappingIsAttribute True, if xmlns
* attributes are being created, false otherwise.
*/
public void setPrefixMappingIsAttribute(boolean pPrefixMappingIsAttribute) {
prefixMappingIsAttribute = pPrefixMappingIsAttribute;
}
/** Sets the document being used as object factory.
* @param pDocument The object factory.
*/
public void setDocument(Document pDocument) {
document = pDocument;
}
/** Returns the document being used as object factory.
* @return pDocument The object factory.
*/
public Document getDocument() {
return document;
}
/** Sets the Locator.
* @param pLocator The Locator being set.
*/
public void setDocumentLocator(Locator pLocator) {
locator = pLocator;
}
/** Returns the Locator.
* @return The documents Locator.
*/
public Locator getDocumentLocator() {
return locator;
}
/** Sets the target node. The document is built as a fragment
* in the target node.
* @param pNode The target node.
*/
public void setTarget(Node pNode) {
target = pNode;
currentNode = pNode;
if (getDocument() == null) {
setDocument(pNode.getNodeType() == Node.DOCUMENT_NODE ?
(Document) pNode : pNode.getOwnerDocument());
}
}
/** Returns the target node. The document is built as a fragment
* in the target node.
* @return The target node.
*/
public Node getTarget() {
return target;
}
public void startDocument() throws SAXException {
}
public void endDocument() throws SAXException {
}
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
if (isPrefixMappingIsAttribute()) {
if (prefixes == null) {
prefixes = new ArrayList();
}
prefixes.add(prefix);
prefixes.add(uri);
}
}
public void endPrefixMapping(String prefix) throws SAXException {
}
public void startElement(String pNamespaceURI, String pLocalName,
String pQName, Attributes pAttr) throws SAXException {
Document doc = getDocument();
Element element;
if (pNamespaceURI == null || pNamespaceURI.length() == 0) {
element = doc.createElement(pQName);
} else {
element = doc.createElementNS(pNamespaceURI, pQName);
}
if (pAttr != null) {
for (int i = 0; i < pAttr.getLength(); i++) {
String uri = pAttr.getURI(i);
String qName = pAttr.getQName(i);
String value = pAttr.getValue(i);
if (uri == null || uri.length() == 0) {
element.setAttribute(qName, value);
} else {
element.setAttributeNS(uri, qName, value);
}
}
}
if (prefixes != null) {
for (int i = 0; i < prefixes.size(); i += 2) {
String prefix = (String) prefixes.get(i);
String uri = (String) prefixes.get(i+1);
if (prefix == null || "".equals(prefix)) {
element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
XMLConstants.XMLNS_ATTRIBUTE, uri);
} else {
element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
XMLConstants.XMLNS_ATTRIBUTE + ':' + prefix, uri);
}
}
prefixes.clear();
}
currentNode.appendChild(element);
currentNode = element;
}
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
currentNode = currentNode.getParentNode();
}
public void characters(char[] ch, int start, int length)
throws SAXException {
Node node = currentNode.getLastChild();
String s = new String(ch, start, length);
if (node != null && node.getNodeType() == Node.TEXT_NODE) {
((Text) node).appendData(s);
} else {
Text text = getDocument().createTextNode(s);
currentNode.appendChild(text);
}
}
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException {
characters(ch, start, length);
}
public void processingInstruction(String pTarget, String pData)
throws SAXException {
ProcessingInstruction pi = getDocument().createProcessingInstruction(pTarget, pData);
currentNode.appendChild(pi);
}
public void skippedEntity(String pName) throws SAXException {
EntityReference entity = getDocument().createEntityReference(pName);
currentNode.appendChild(entity);
}
}
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/PassThroughXMLWriter.java libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/PassThroughXMLWriter.jav0000644 0001750 0001750 00000001564 10243730055 033707 0 ustar vladimir vladimir /*
* Copyright 2003, 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ws.commons.serialize;
/** A subclass of {@link org.apache.ws.commons.serialize.XMLWriterImpl},
* which is escaping nothing.
*/
public class PassThroughXMLWriter extends XMLWriterImpl {
public boolean canEncode(char c) {
return true;
}
}
libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/XMLWriterImpl.java 0000644 0001750 0001750 00000024752 10243730055 032506 0 ustar vladimir vladimir /*
* Copyright 2003, 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ws.commons.serialize;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.Writer;
import javax.xml.XMLConstants;
/** Default implementation of {@link XMLWriter}. Works with Java 1.2 and
* later.
*/
public class XMLWriterImpl implements XMLWriter {
private static final int STATE_OUTSIDE = 0;
private static final int STATE_IN_START_ELEMENT = 1;
private static final int STATE_IN_ELEMENT = 2;
private String encoding, indentString, lineFeed;
private Writer w;
private Locator l;
private java.util.Map delayedPrefixes;
int curIndent = 0;
private int state;
private boolean declarating, indenting, flushing;
public void setEncoding(String pEncoding) { encoding = pEncoding; }
public String getEncoding() { return encoding; }
public void setDeclarating(boolean pDeclarating) { declarating = pDeclarating; }
public boolean isDeclarating() { return declarating; }
public void setIndenting(boolean pIndenting) { indenting = pIndenting; }
public boolean isIndenting() { return indenting; }
public void setIndentString(String pIndentString) { indentString = pIndentString; }
public String getIndentString() { return indentString; }
public void setLineFeed(String pLineFeed) { lineFeed = pLineFeed; }
public String getLineFeed() { return lineFeed; }
public void setFlushing(boolean pFlushing) { flushing = pFlushing; }
public boolean isFlushing() { return flushing; }
/** Sets the JaxbXMLSerializers Writer.
*/ public void setWriter(Writer pWriter) { w = pWriter; } /**Returns the JaxbXMLSerializers Writer.
*/ public Writer getWriter() { return w; } /** Sets the locator. * * @param pLocator A locator for use in case of errors * @see #getDocumentLocator */ public void setDocumentLocator(Locator pLocator) { l = pLocator; } /** Returns the locator * @return A locator previously set with setDocumentLocator or null. * @see #setDocumentLocator */ public Locator getDocumentLocator() { return l; } /** *Starts use of a namespace prefix.
* * @param namespaceURI The namespace URI * @param prefix The prefix * @throws SAXException Not actually thrown, just for compliance to the interface specification. */ public void startPrefixMapping(String prefix, String namespaceURI) throws SAXException { if (delayedPrefixes == null) { delayedPrefixes = new java.util.HashMap(); } if ("".equals(prefix)) { if (namespaceURI.equals(prefix)) { return; } prefix = XMLConstants.XMLNS_ATTRIBUTE; } else { prefix = XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix; } delayedPrefixes.put(prefix, namespaceURI); } /**Terminates use of a namespace prefix.
* * @param prefix The prefix being abandoned. * @throws SAXException Not actually thrown, just for compliance to the interface specification. */ public void endPrefixMapping(String prefix) throws SAXException { if (delayedPrefixes != null) { if ("".equals(prefix)) { prefix = XMLConstants.XMLNS_ATTRIBUTE; } else { prefix = XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix; } delayedPrefixes.remove(prefix); } } /**Starts a document.
* @throws SAXException Not actually thrown, just for compliance to the interface specification. */ public void startDocument() throws SAXException { if (delayedPrefixes != null) { delayedPrefixes.clear(); } state = STATE_OUTSIDE; curIndent = 0; if (isDeclarating() && w != null) { try { w.write(""); if (isIndenting()) { String lf = getLineFeed(); if (lf != null) { w.write(lf); } } } catch (IOException e) { throw new SAXException("Failed to write XML declaration: " + e.getMessage(), e); } } } /**This method finishs the handlers action. After calling endDocument you * may start a new action by calling startDocument again.
* * @throws SAXException Not actually thrown, just for compliance to the * interface specification. */ public void endDocument() throws SAXException { if (isFlushing() && w != null) { try { w.flush(); } catch (IOException e) { throw new SAXException("Failed to flush target writer: " + e.getMessage(), e); } } } /** Calls the character method with the same arguments. * @param ch A string of whitespace characters being inserted into the document. * @param start The index of the first character. * @param length The number of characters. * @throws SAXException Thrown in case of an IOException. */ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { characters(ch, start, length); } private void stopTerminator() throws java.io.IOException { if (state == STATE_IN_START_ELEMENT) { if (w != null) { w.write('>'); } state = STATE_IN_ELEMENT; } } /** Inserts a string of characters into the document. * @param ch The characters being inserted. A substring, to be precise. * @param start Index of the first character * @param length Number of characters being inserted * @throws SAXException Thrown in case of an IOException */ public void characters(char[] ch, int start, int length) throws SAXException { try { stopTerminator(); if (w == null) return; int end = start+length; for (int i = start; i < end; i++) { char c = ch[i]; switch (c) { case '&': w.write("&"); break; case '<': w.write("<"); break; case '>': w.write(">"); break; case '\n': case '\r': case '\t': w.write(c); break; default: if (canEncode(c)) { w.write(c); } else { w.write(""); w.write(Integer.toString(c)); w.write(";"); } break; } } } catch (IOException e) { throw new SAXException(e); } } public boolean canEncode(char c) { return c == '\n' || (c >= ' ' && c < 0x7f); } /**Terminates an element.
* * @param namespaceURI The namespace URI, if any, or null * @param localName The local name, without prefix, or null * @param qName The qualified name, including a prefix, or null * @throws SAXException Thrown in case of an IOException. */ public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (isIndenting()) { --curIndent; } if (w != null) { try { if (state == STATE_IN_START_ELEMENT) { w.write("/>"); state = STATE_OUTSIDE; } else { if (state == STATE_OUTSIDE) { indentMe(); } w.write(""); w.write(qName); w.write('>'); } state = STATE_OUTSIDE; } catch (java.io.IOException e) { throw new SAXException(e); } } } private void indentMe() throws java.io.IOException { if (w != null) { if (isIndenting()) { String s = getLineFeed(); if (s != null) { w.write(s); } s = getIndentString(); if (s != null) { for (int i = 0; i < curIndent; i++) { w.write(s); } } } } } private void writeCData(String v) throws java.io.IOException { int len = v.length(); for (int j = 0; j < len; j++) { char c = v.charAt(j); switch (c) { case '&': w.write("&"); break; case '<': w.write("<"); break; case '>': w.write(">"); break; case '\'': w.write("'"); break; case '"': w.write("""); break; default: if (canEncode(c)) { w.write(c); } else { w.write(""); w.write(Integer.toString(c)); w.write(';'); } break; } } } /** Starts a new element. * * @param namespaceURI The namespace URI, if any, or null * @param localName The local name, without prefix, or null * @param qName The qualified name, including a prefix, or null * @param attr The element attributes * @throws SAXException Thrown in case of an IOException. */ public void startElement(String namespaceURI, String localName, String qName, Attributes attr) throws SAXException { try { stopTerminator(); if (isIndenting()) { if (curIndent > 0) { indentMe(); } curIndent++; } if (w != null) { w.write('<'); w.write(qName); if (attr != null) { for (int i = attr.getLength(); i > 0;) { w.write(' '); String name = attr.getQName(--i); w.write(name); if (delayedPrefixes != null) { delayedPrefixes.remove(name); } w.write("=\""); writeCData(attr.getValue(i)); w.write('"'); } } if (delayedPrefixes != null && delayedPrefixes.size() > 0) { for (java.util.Iterator iter = delayedPrefixes.entrySet().iterator(); iter.hasNext(); ) { java.util.Map.Entry entry = (java.util.Map.Entry) iter.next(); w.write(' '); w.write((String) entry.getKey()); w.write("=\""); w.write((String) entry.getValue()); w.write('"'); } delayedPrefixes.clear(); } } state = STATE_IN_START_ELEMENT; } catch (java.io.IOException e) { throw new SAXException(e); } } /** Not actually implemented, because I don't know how to skip entities. * * @param ent The entity being skipped. * @throws SAXException Not actually thrown, just for compliance to the interface specification. */ public void skippedEntity(String ent) throws SAXException { throw new SAXException("Don't know how to skip entities"); } /** Inserts a processing instruction. * * @param target The PI target * @param data The PI data * @throws SAXException Thrown in case of an IOException */ public void processingInstruction(String target, String data) throws SAXException { try { stopTerminator(); if (w != null) { w.write(""); w.write(target); w.write(' '); w.write(data); w.write("?>"); } } catch (java.io.IOException e) { throw new SAXException(e); } } } libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/DOMSerializer.java 0000644 0001750 0001750 00000026407 10243730055 032477 0 ustar vladimir vladimir /* * Copyright 2003, 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.ws.commons.serialize; import javax.xml.XMLConstants; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.AttributesImpl; /** Serializes a DOM node into a stream of SAX events. */ public class DOMSerializer { private boolean namespaceDeclarationAttribute; private boolean parentsNamespaceDeclarationDisabled; private boolean startingDocument = true; /** Sets whether XML namespace declarations are being serialized as * attributes or as SAX events (default). * @param pXmlDeclarationAttribute True, if a namespace declaration * is being transmitted as an XML attribute. False otherwise. */ public void setNamespaceDeclarationAttribute(boolean pXmlDeclarationAttribute) { namespaceDeclarationAttribute = pXmlDeclarationAttribute; } /** Returns whether XML declarations are being serialized as * attributes or as SAX events (default). * @return True, if a namespace declaration * is being transmitted as an XML attribute. False otherwise. */ public boolean isNamespaceDeclarationAttribute() { return namespaceDeclarationAttribute; } /** Returns whether XML declarations present in the parent nodes * are being serialized (default) or not. This option takes effect * only if the namespace declarations are sent as events. In other * words, if thenamespaceDeclarationAttribute
* properts is false.
* @param pParentsXmlDeclarationDisabled True, if namespace
* declarations of the parent nodes are disabled, false otherwise.
*/
public void setParentsNamespaceDeclarationDisabled(boolean pParentsXmlDeclarationDisabled) {
parentsNamespaceDeclarationDisabled = pParentsXmlDeclarationDisabled;
}
/** Sets whether XML declarations present in the parent nodes
* are being serialized (default) or not. This option takes effect
* only if the namespace declarations are sent as events. In other
* words, if the namespaceDeclarationAttribute
* properts is false.
* @return True, if namespace declarations of the parent nodes are
* disabled, false otherwise.
*/
public boolean isParentsNamespaceDeclarationDisabled() {
return parentsNamespaceDeclarationDisabled;
}
/** Returns, whether startDocument
and
* endDocument
events are generated for
* document nodes.
* @return True (default), if startDocument
and
* endDocument
events are being generated.
* False otherwise.
*/
public boolean isStartingDocument() {
return startingDocument;
}
/** Sets, whether startDocument
and
* endDocument
events are generated for
* document nodes.
* @param pStartingDocument True (default), if
* startDocument
and
* endDocument
events are being generated.
* False otherwise.
*/
public void setStartingDocument(boolean pStartingDocument) {
startingDocument = pStartingDocument;
}
/** Serializes the childs of pNode
.
* @param pNode The parent node, whose childs are being serialized.
* @param pHandler The target handler.
* @throws SAXException The target handler reported an error.
*/
protected void doSerializeChilds(Node pNode, ContentHandler pHandler)
throws SAXException {
for (Node child = pNode.getFirstChild(); child != null;
child = child.getNextSibling()) {
doSerialize(child, pHandler);
}
}
/** Initially creates startPrefixMapping events for the nodes parents. This
* is invoked only, if {@link #isNamespaceDeclarationAttribute()},
* and {@link #isParentsNamespaceDeclarationDisabled()} are false.
* @param pNode The node, for which namespace declarations are being
* created.
* @param pHandler The target handler.
* @throws SAXException The target handler reported an error.
*/
private void parentsStartPrefixMappingEvents(Node pNode, ContentHandler pHandler)
throws SAXException {
if (pNode != null) {
parentsStartPrefixMappingEvents(pNode.getParentNode(), pHandler);
if (pNode.getNodeType() == Node.ELEMENT_NODE) {
startPrefixMappingEvents(pNode, pHandler);
}
}
}
/** Finally creates endPrefixMapping events for the nodes parents. This
* is invoked only, if {@link #isNamespaceDeclarationAttribute()},
* and {@link #isParentsNamespaceDeclarationDisabled()} are false.
* @param pNode The node, for which namespace declarations are being
* created.
* @param pHandler The target handler.
* @throws SAXException The target handler reported an error.
*/
private void parentsEndPrefixMappingEvents(Node pNode, ContentHandler pHandler)
throws SAXException {
if (pNode != null) {
if (pNode.getNodeType() == Node.ELEMENT_NODE) {
endPrefixMappingEvents(pNode, pHandler);
}
parentsEndPrefixMappingEvents(pNode.getParentNode(), pHandler);
}
}
/** Creates startPrefixMapping events for the node pNode
.
* @param pNode The node being serialized.
* @param pHandler The target handler.
* @throws SAXException The target handler reported an error.
*/
private void startPrefixMappingEvents(Node pNode, ContentHandler pHandler)
throws SAXException {
NamedNodeMap nnm = pNode.getAttributes();
if (nnm != null) {
for (int i = 0; i < nnm.getLength(); i++) {
Node attr = nnm.item(i);
if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())) {
String prefix;
if (XMLConstants.XMLNS_ATTRIBUTE.equals(attr.getPrefix())) {
prefix = attr.getLocalName();
} else if (XMLConstants.XMLNS_ATTRIBUTE.equals(attr.getNodeName())) {
prefix = "";
} else {
throw new IllegalStateException("Unable to parse namespace declaration: " + attr.getNodeName());
}
String uri = attr.getNodeValue();
if (uri == null) {
uri = "";
}
pHandler.startPrefixMapping(prefix, uri);
}
}
}
}
/** Creates endPrefixMapping events for the node pNode
.
* @param pNode The node being serialized.
* @param pHandler The target handler.
* @throws SAXException The target handler reported an error.
*/
private void endPrefixMappingEvents(Node pNode, ContentHandler pHandler)
throws SAXException {
NamedNodeMap nnm = pNode.getAttributes();
if (nnm != null) {
for (int i = nnm.getLength()-1; i >= 0; i--) {
Node attr = nnm.item(i);
if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())) {
String prefix = attr.getLocalName();
pHandler.endPrefixMapping(prefix);
}
}
}
}
private void characters(ContentHandler pHandler, String pValue, boolean pCdata)
throws SAXException {
LexicalHandler lh;
if (pCdata) {
lh = (pHandler instanceof LexicalHandler) ? (LexicalHandler) pHandler : null;
} else {
lh = null;
}
if (lh != null) {
lh.startCDATA();
}
pHandler.characters(pValue.toCharArray(), 0, pValue.length());
if (lh != null) {
lh.endCDATA();
}
}
/** Converts the given node pNode
into a
* stream of SAX events, which are fired into the
* content handler pHandler
.
* @param pNode The node being serialized.
* @param pHandler The target handler.
* @throws SAXException The target handler reported an error.
*/
public void serialize(Node pNode, ContentHandler pHandler)
throws SAXException {
if (!isNamespaceDeclarationAttribute() &&
!isParentsNamespaceDeclarationDisabled()) {
parentsStartPrefixMappingEvents(pNode.getParentNode(), pHandler);
}
doSerialize(pNode, pHandler);
if (!isNamespaceDeclarationAttribute() &&
!isParentsNamespaceDeclarationDisabled()) {
parentsEndPrefixMappingEvents(pNode.getParentNode(), pHandler);
}
}
/** Converts the given node pNode
into a
* stream of SAX events, which are fired into the
* content handler pHandler
. Unlike
* {@link #serialize(Node, ContentHandler)}, this method
* doesn't call
* {@link #parentsStartPrefixMappingEvents(Node, ContentHandler)},
* and
* {@link #parentsEndPrefixMappingEvents(Node, ContentHandler)}.
* @param pNode The node being serialized.
* @param pHandler The target handler.
* @throws SAXException The target handler reported an error.
*/
protected void doSerialize(Node pNode, ContentHandler pHandler)
throws SAXException {
switch (pNode.getNodeType()) {
case Node.DOCUMENT_NODE:
boolean startDocumentEvent = isStartingDocument();
if (startDocumentEvent) {
pHandler.startDocument();
}
doSerializeChilds(pNode, pHandler);
if (startDocumentEvent) {
pHandler.endDocument();
}
break;
case Node.DOCUMENT_FRAGMENT_NODE:
doSerializeChilds(pNode, pHandler);
break;
case Node.ELEMENT_NODE:
AttributesImpl attr = new AttributesImpl();
boolean isNamespaceDeclarationAttribute = isNamespaceDeclarationAttribute();
if (!isNamespaceDeclarationAttribute) {
startPrefixMappingEvents(pNode, pHandler);
}
NamedNodeMap nnm = pNode.getAttributes();
if (nnm != null) {
for (int i = 0; i < nnm.getLength(); i++) {
Node a = nnm.item(i);
if (isNamespaceDeclarationAttribute ||
!XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(a.getNamespaceURI())) {
String aUri = a.getNamespaceURI();
String aLocalName = a.getLocalName();
String aNodeName = a.getNodeName();
if (aLocalName == null) {
if (aUri == null || aUri.length() == 0) {
aLocalName = aNodeName;
} else {
throw new IllegalStateException("aLocalName is null");
}
}
attr.addAttribute(aUri == null ? "" : aUri, aNodeName,
aLocalName, "CDATA", a.getNodeValue());
}
}
}
String nUri = pNode.getNamespaceURI();
if (nUri == null) {
nUri = "";
}
pHandler.startElement(nUri, pNode.getLocalName(),
pNode.getNodeName(), attr);
doSerializeChilds(pNode, pHandler);
pHandler.endElement(nUri, pNode.getLocalName(),
pNode.getNodeName());
if (!isNamespaceDeclarationAttribute) {
endPrefixMappingEvents(pNode, pHandler);
}
break;
case Node.TEXT_NODE:
characters(pHandler, pNode.getNodeValue(), false);
break;
case Node.CDATA_SECTION_NODE:
characters(pHandler, pNode.getNodeValue(), true);
break;
case Node.PROCESSING_INSTRUCTION_NODE:
pHandler.processingInstruction(pNode.getNodeName(), pNode.getNodeValue());
break;
case Node.ENTITY_REFERENCE_NODE:
pHandler.skippedEntity(pNode.getNodeName());
break;
case Node.COMMENT_NODE:
if (pHandler instanceof LexicalHandler) {
String s = pNode.getNodeValue();
((LexicalHandler) pHandler).comment(s.toCharArray(), 0, s.length());
}
break;
default:
throw new IllegalStateException("Unknown node type: " + pNode.getNodeType());
}
}
}
libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/CharSetXMLWriter.java 0000644 0001750 0001750 00000002437 10243730055 033132 0 ustar vladimir vladimir /*
* Copyright 2003, 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ws.commons.serialize;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import org.xml.sax.SAXException;
/** An improved version of {@link org.apache.ws.commons.serialize.XMLWriterImpl},
* using the{@link java.nio.charset.Charset} from Java 1.4.
*/
public class CharSetXMLWriter extends XMLWriterImpl {
private CharsetEncoder charsetEncoder;
public void startDocument() throws SAXException {
Charset charSet = Charset.forName(getEncoding());
if (charSet.canEncode()) {
charsetEncoder = charSet.newEncoder();
}
}
public boolean canEncode(char c) {
return (charsetEncoder == null) ? false : charsetEncoder.canEncode(c);
}
}
libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/package.html 0000644 0001750 0001750 00000002226 10243730055 031435 0 ustar vladimir vladimir
This package contains classes for serializing XML to an instance of
{@link java.io.Writer}, much like the javax.xml.transform.stream
package. The main differences are, that the serializer classes depend
on JAXP 1.1 only (as opposed to JAXP 1.2, which introduced the
javax.xml.transform
package) and that they allow a more
granular handling of namespaces.
An instance of {@link java.text.Format}, which may be used to parse
* and format xs:date
values.
Note: This methods behaviour is precisely
* defined by {@link NamespaceContext#getNamespaceURI(java.lang.String)}.
* @param pPrefix The prefix in question
*/
public String getNamespaceURI(String pPrefix) {
if (pPrefix == null) {
throw new IllegalArgumentException("The namespace prefix must not be null.");
}
if (cachedURI != null) {
if (cachedPrefix.equals(pPrefix)) { return cachedURI; }
if (prefixList != null) {
for (int i = prefixList.size(); i > 0; i -= 2) {
if (pPrefix.equals(prefixList.get(i-2))) {
return (String) prefixList.get(i-1);
}
}
}
}
if (XMLConstants.XML_NS_PREFIX.equals(pPrefix)) {
return XMLConstants.XML_NS_URI;
} else if (XMLConstants.XMLNS_ATTRIBUTE.equals(pPrefix)) {
return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
}
return null;
}
/** Returns a prefix currently mapped to the given URI or
* null, if there is no such mapping. This method may be used
* to find a possible prefix for an elements namespace URI. For
* attributes you should use {@link #getAttributePrefix(String)}.
* Note: This methods behaviour is precisely
* defined by {@link NamespaceContext#getPrefix(java.lang.String)}.
* @param pURI The namespace URI in question
* @throws IllegalArgumentException The namespace URI is null.
*/
public String getPrefix(String pURI) {
if (pURI == null) {
throw new IllegalArgumentException("The namespace URI must not be null.");
}
if (cachedURI != null) {
if (cachedURI.equals(pURI)) { return cachedPrefix; }
if (prefixList != null) {
for (int i = prefixList.size(); i > 0; i -= 2) {
if (pURI.equals(prefixList.get(i-1))) {
return (String) prefixList.get(i-2);
}
}
}
}
if (XMLConstants.XML_NS_URI.equals(pURI)) {
return XMLConstants.XML_NS_PREFIX;
} else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(pURI)) {
return XMLConstants.XMLNS_ATTRIBUTE;
}
return null;
}
/** Returns a non-empty prefix currently mapped to the given
* URL or null, if there is no such mapping. This method may be
* used to find a possible prefix for an attributes namespace
* URI. For elements you should use {@link #getPrefix(String)}.
* @param pURI Thhe namespace URI in question
* @throws IllegalArgumentException The namespace URI is null.
*/
public String getAttributePrefix(String pURI) {
if (pURI == null) {
throw new IllegalArgumentException("The namespace URI must not be null.");
}
if (pURI.length() == 0) {
return "";
}
if (cachedURI != null) {
if (cachedURI.equals(pURI) && cachedPrefix.length() > 0) {
return cachedPrefix;
}
if (prefixList != null) {
for (int i = prefixList.size(); i > 0; i -= 2) {
if (pURI.equals(prefixList.get(i-1))) {
String prefix = (String) prefixList.get(i-2);
if (prefix.length() > 0) {
return prefix;
}
}
}
}
}
if (XMLConstants.XML_NS_URI.equals(pURI)) {
return XMLConstants.XML_NS_PREFIX;
} else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(pURI)) {
return XMLConstants.XMLNS_ATTRIBUTE;
}
return null;
}
/** Returns a collection to all prefixes bound to the given
* namespace URI.
* Note: This methods behaviour is precisely
* defined by {@link NamespaceContext#getPrefixes(java.lang.String)}.
* @param pURI The namespace prefix in question
*/
public Iterator getPrefixes(String pURI) {
if (pURI == null) {
throw new IllegalArgumentException("The namespace URI must not be null.");
}
List list = new ArrayList();
if (cachedURI != null) {
if (cachedURI.equals(pURI)) { list.add(cachedPrefix); }
if (prefixList != null) {
for (int i = prefixList.size(); i > 0; i -= 2) {
if (pURI.equals(prefixList.get(i-1))) {
list.add(prefixList.get(i-2));
}
}
}
}
if (pURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
list.add(XMLConstants.XMLNS_ATTRIBUTE);
} else if (pURI.equals(XMLConstants.XML_NS_URI)) {
list.add(XMLConstants.XML_NS_PREFIX);
}
return list.iterator();
}
/** Returns whether a given prefix is currently declared.
*/
public boolean isPrefixDeclared(String pPrefix) {
if (cachedURI != null) {
if (cachedPrefix != null && cachedPrefix.equals(pPrefix)) { return true; }
if (prefixList != null) {
for (int i = prefixList.size(); i > 0; i -= 2) {
if (prefixList.get(i-2).equals(pPrefix)) {
return true;
}
}
}
}
return "xml".equals(pPrefix);
}
/** Returns the current number of assigned prefixes.
* Note, that a prefix may be assigned in several nested
* elements, in which case every assignment is counted.
* This method is typically called before invoking the
* method
* {@link org.xml.sax.ContentHandler#startElement(String, String, String, org.xml.sax.Attributes)}.
* The return value is used as a saveable state. After
* invoking
* {@link org.xml.sax.ContentHandler#endElement(String, String, String)},
* the state is restored by calling {@link #checkContext(int)}.
*/
public int getContext() {
return (prefixList == null ? 0 : prefixList.size()) +
(cachedURI == null ? 0 : 2);
}
/** This method is used to restore the namespace state
* after an element is created. It takes as input a state,
* as returned by {@link #getContext()}.
* For any prefix, which was since saving the state,
* the prefix is returned and deleted from the internal
* list. In other words, a typical use looks like this:
*
* NamespaceSupport nss; * ContentHandler h; * int context = nss.getContext(); * h.startElement("foo", "bar", "f:bar", new AttributesImpl()); * ... * h.endElement("foo", "bar", "f:bar"); * for (;;) { * String prefix = nss.checkContext(context); * if (prefix == null) { * break; * } * h.endPrefixMapping(prefix); * } **/ public String checkContext(int i) { if (getContext() == i) { return null; } String result = cachedPrefix; if (prefixList != null && prefixList.size() > 0) { cachedURI = prefixList.remove(prefixList.size()-1).toString(); cachedPrefix = prefixList.remove(prefixList.size()-1).toString(); } else { cachedURI = null; cachedPrefix = null; } return result; } /** Returns a list of all prefixes, which are currently declared, * in the order of declaration. Duplicates are possible, if a * prefix has been assigned to more than one URI, or repeatedly to * the same URI. */ public List getPrefixes() { if (cachedPrefix == null) { return Collections.EMPTY_LIST; } else if (prefixList == null) { return Collections.singletonList(cachedPrefix); } else { List result = new ArrayList(prefixList.size() + 1); for (int i = 0; i < prefixList.size(); i += 2) { result.add(prefixList.get(i)); } result.add(cachedPrefix); return result; } } } libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/util/XsDateTimeFormat.java 0000644 0001750 0001750 00000022752 10433145363 032176 0 ustar vladimir vladimir /* * Copyright 2003, 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.ws.commons.util; import java.text.FieldPosition; import java.text.Format; import java.text.ParsePosition; import java.util.Calendar; import java.util.TimeZone; /**
An instance of {@link java.text.Format}, which may be used
* to parse and format xs:dateTime
values.
An instance of {@link java.text.Format}, which may be used to parse
* and format xs:time
values.
pWriter
.
*/
public static OutputStream newEncoder(Writer pWriter) {
return newEncoder(pWriter, LINE_SIZE, LINE_SEPARATOR);
}
/** Returns an {@link OutputStream}, that encodes its input in Base64
* and writes it to the given {@link Writer}. If the Base64 stream
* ends, then the output streams {@link OutputStream#close()} method
* must be invoked. Note, that this will not close the
* target {@link Writer}!
* @param pWriter Target writer.
* @param pLineSize Size of one line in characters, must be a multiple
* of four. Zero indicates, that no line wrapping should occur.
* @param pSeparator Line separator or null, in which case the default value
* {@link #LINE_SEPARATOR} is used.
* @return An output stream, encoding its input in Base64 and writing
* the output to the writer pWriter
.
*/
public static OutputStream newEncoder(final Writer pWriter, int pLineSize, String pSeparator) {
final Encoder encoder = new Encoder(new char[4096], pLineSize, pSeparator){
protected void writeBuffer(char[] pBuffer, int pOffset, int pLen) throws IOException {
pWriter.write(pBuffer, pOffset, pLen);
}
};
return new EncoderOutputStream(encoder);
}
/** An {@link Encoder}, which is writing to a SAX content handler.
* This is typically used for embedding a base64 stream into an
* XML document.
*/
public static class SAXEncoder extends Encoder {
private final ContentHandler handler;
/** Creates a new instance.
* @param pBuffer The encoders buffer.
* @param pWrapSize A nonzero value indicates, that a line
* wrap should be performed after the given number of
* characters. The value must be a multiple of 4. Zero
* indicates, that no line wrap should be performed.
* @param pSep The eol sequence being used to terminate
* a line in case of line wraps. May be null, in which
* case the default value {@link Base64#LINE_SEPARATOR}
* is being used.
* @param pHandler The target handler.
*/
public SAXEncoder(char[] pBuffer, int pWrapSize, String pSep,
ContentHandler pHandler) {
super(pBuffer, pWrapSize, pSep);
handler = pHandler;
}
/** Writes to the content handler.
* @throws SAXIOException Writing to the content handler
* caused a SAXException.
*/
protected void writeBuffer(char[] pChars, int pOffset, int pLen) throws IOException {
try {
handler.characters(pChars, pOffset, pLen);
} catch (SAXException e) {
throw new SAXIOException(e);
}
}
}
/** Converts the given byte array into a base64 encoded character
* array.
* @param pBuffer The buffer being encoded.
* @param pOffset Offset in buffer, where to begin encoding.
* @param pLength Number of bytes being encoded.
* @return Character array of encoded bytes.
*/
public static String encode(byte[] pBuffer, int pOffset, int pLength) {
return encode(pBuffer, pOffset, pLength, LINE_SIZE, LINE_SEPARATOR);
}
/** Converts the given byte array into a base64 encoded character
* array.
* @param pBuffer The buffer being encoded.
* @param pOffset Offset in buffer, where to begin encoding.
* @param pLength Number of bytes being encoded.
* @param pLineSize Size of one line in characters, must be a multiple
* of four. Zero indicates, that no line wrapping should occur.
* @param pSeparator Line separator or null, in which case the default value
* {@link #LINE_SEPARATOR} is used.
* @return Character array of encoded bytes.
*/
public static String encode(byte[] pBuffer, int pOffset, int pLength,
int pLineSize, String pSeparator) {
StringWriter sw = new StringWriter();
OutputStream ostream = newEncoder(sw, pLineSize, pSeparator);
try {
ostream.write(pBuffer, pOffset, pLength);
ostream.close();
} catch (IOException e) {
throw new UndeclaredThrowableException(e);
}
return sw.toString();
}
/** Converts the given byte array into a base64 encoded character
* array with the line size {@link #LINE_SIZE} and the separator
* {@link #LINE_SEPARATOR}.
* @param pBuffer The buffer being encoded.
* @return Character array of encoded bytes.
*/
public static String encode(byte[] pBuffer) {
return encode(pBuffer, 0, pBuffer.length);
}
/** An encoder is an object, which is able to decode char arrays
* in blocks of four bytes. Any such block is converted into a
* array of three bytes.
*/
public static abstract class Decoder {
private final byte[] byteBuffer;
private int byteBufferOffset;
private int num, numBytes;
private int eofBytes;
/** Creates a new instance.
* @param pBufLen The decoders buffer size. The decoder will
* store up to this number of decoded bytes before invoking
* {@link #writeBuffer(byte[],int,int)}.
*/
protected Decoder(int pBufLen) {
byteBuffer = new byte[pBufLen];
}
/** Called for writing the decoded bytes to the destination.
* @param pBuffer The byte array being written.
* @param pOffset Offset of the first byte being written.
* @param pLen Number of bytes being written.
* @throws IOException Writing to the destination failed.
*/
protected abstract void writeBuffer(byte[] pBuffer, int pOffset, int pLen) throws IOException;
/** Converts the Base64 encoded character array.
* @param pData The character array being decoded.
* @param pOffset Offset of first character being decoded.
* @param pLen Number of characters being decoded.
* @throws DecodingException Decoding failed.
* @throws IOException An invocation of the {@link #writeBuffer(byte[],int,int)}
* method failed.
*/
public void write(char[] pData, int pOffset, int pLen) throws IOException {
for (int i = 0; i < pLen; i++) {
char c = pData[pOffset++];
if (Character.isWhitespace(c)) {
continue;
}
if (c == '=') {
++eofBytes;
num = num << 6;
switch(++numBytes) {
case 1:
case 2:
throw new DecodingException("Unexpected end of stream character (=)");
case 3:
// Wait for the next '='
break;
case 4:
byteBuffer[byteBufferOffset++] = (byte) (num >> 16);
if (eofBytes == 1) {
byteBuffer[byteBufferOffset++] = (byte) (num >> 8);
}
writeBuffer(byteBuffer, 0, byteBufferOffset);
byteBufferOffset = 0;
break;
case 5:
throw new DecodingException("Trailing garbage detected");
default:
throw new IllegalStateException("Invalid value for numBytes");
}
} else {
if (eofBytes > 0) {
throw new DecodingException("Base64 characters after end of stream character (=) detected.");
}
int result;
if (c >= 0 && c < base64ToInt.length) {
result = base64ToInt[c];
if (result >= 0) {
num = (num << 6) + result;
if (++numBytes == 4) {
byteBuffer[byteBufferOffset++] = (byte) (num >> 16);
byteBuffer[byteBufferOffset++] = (byte) ((num >> 8) & 0xff);
byteBuffer[byteBufferOffset++] = (byte) (num & 0xff);
if (byteBufferOffset + 3 > byteBuffer.length) {
writeBuffer(byteBuffer, 0, byteBufferOffset);
byteBufferOffset = 0;
}
num = 0;
numBytes = 0;
}
continue;
}
}
if (!Character.isWhitespace(c)) {
throw new DecodingException("Invalid Base64 character: " + (int) c);
}
}
}
}
/** Indicates, that no more data is being expected. Writes all currently
* buffered data to the destination by invoking {@link #writeBuffer(byte[],int,int)}.
* @throws DecodingException Decoding failed (Unexpected end of file).
* @throws IOException An invocation of the {@link #writeBuffer(byte[],int,int)} method failed.
*/
public void flush() throws IOException {
if (numBytes != 0 && numBytes != 4) {
throw new DecodingException("Unexpected end of file");
}
if (byteBufferOffset > 0) {
writeBuffer(byteBuffer, 0, byteBufferOffset);
byteBufferOffset = 0;
}
}
}
/** Returns a {@link Writer}, that decodes its Base64 encoded
* input and writes it to the given {@link OutputStream}.
* Note, that the writers {@link Writer#close()} method will
* not close the output stream pStream
!
* @param pStream Target output stream.
* @return An output stream, encoding its input in Base64 and writing
* the output to the writer pWriter
.
*/
public Writer newDecoder(final OutputStream pStream) {
return new Writer(){
private final Decoder decoder = new Decoder(1024){
protected void writeBuffer(byte[] pBytes, int pOffset, int pLen) throws IOException {
pStream.write(pBytes, pOffset, pLen);
}
};
public void close() throws IOException {
flush();
}
public void flush() throws IOException {
decoder.flush();
pStream.flush();
}
public void write(char[] cbuf, int off, int len) throws IOException {
decoder.write(cbuf, off, len);
}
};
}
/** Converts the given base64 encoded character buffer into a byte array.
* @param pBuffer The character buffer being decoded.
* @param pOffset Offset of first character being decoded.
* @param pLength Number of characters being decoded.
* @return Converted byte array
* @throws DecodingException The input character stream contained invalid data.
*/
public static byte[] decode(char[] pBuffer, int pOffset, int pLength) throws DecodingException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
Decoder d = new Decoder(1024){
protected void writeBuffer(byte[] pBuf, int pOff, int pLen) throws IOException {
baos.write(pBuf, pOff, pLen);
}
};
try {
d.write(pBuffer, pOffset, pLength);
d.flush();
} catch (DecodingException e) {
throw e;
} catch (IOException e) {
throw new UndeclaredThrowableException(e);
}
return baos.toByteArray();
}
/** Converts the given base64 encoded character buffer into a byte array.
* @param pBuffer The character buffer being decoded.
* @return Converted byte array
* @throws DecodingException The input character stream contained invalid data.
*/
public static byte[] decode(char[] pBuffer) throws DecodingException {
return decode(pBuffer, 0, pBuffer.length);
}
/** Converts the given base64 encoded String into a byte array.
* @param pBuffer The string being decoded.
* @return Converted byte array
* @throws DecodingException The input character stream contained invalid data.
*/
public static byte[] decode(String pBuffer) throws DecodingException {
return decode(pBuffer.toCharArray());
}
}
libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/util/package.html 0000644 0001750 0001750 00000001554 10243730055 030426 0 ustar vladimir vladimir
This package contains some utility classes, which aren't worth a separate package.
libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/util/ 0000755 0001750 0001750 00000000000 10435414715 026145 5 ustar vladimir vladimir libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/ 0000755 0001750 0001750 00000000000 10435414716 025171 5 ustar vladimir vladimir libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/ 0000755 0001750 0001750 00000000000 10435414715 023515 5 ustar vladimir vladimir libws-commons-util-1.0.1.orig/src/main/java/org/apache/ 0000755 0001750 0001750 00000000000 10435414714 023063 5 ustar vladimir vladimir libws-commons-util-1.0.1.orig/src/main/java/org/ 0000755 0001750 0001750 00000000000 10435414716 021644 5 ustar vladimir vladimir libws-commons-util-1.0.1.orig/src/main/java/ 0000755 0001750 0001750 00000000000 10435414714 021053 5 ustar vladimir vladimir libws-commons-util-1.0.1.orig/src/main/assembly/src.xml 0000644 0001750 0001750 00000000620 10435415421 023254 0 ustar vladimir vladimir