libws-commons-util-1.0.1.orig/pom.xml0000644000175000017500000001442210445606047017742 0ustar vladimirvladimir 4.0.0 org.apache.ws.commons ws-commons-util Apache WebServices Common Utilities 1.0.1 This is a small collection of utility classes, that allow high performance XML processing based on SAX. Basically, it is assumed, that you are using an JAXP 1.1 compliant XML parser and nothing else. In particular, no dependency on the javax.xml.transform package is introduced. http://ws.apache.org/commons/util jira http://issues.apache.org/jira/browse/XMLRPC 2005 XML-RPC Users xmlrpc-user-subscribe@ws.apache.org xmlrpc-user-unsubscribe@ws.apache.org xmlrpc-user@ws.apache.org http://mail-archives.apache.org/mod_mbox/ws-xmlrpc-user/ http://marc.theaimsgroup.com/?l=xmlrpc-user XML-RPC Developers xmlrpc-dev-subscribe@ws.apache.org xmlrpc-dev-unsubscribe@ws.apache.org xmlrpc-dev@ws.apache.org http://mail-archives.apache.org/mod_mbox/ws-xmlrpc-dev/ http://marc.theaimsgroup.com/?l=xmlrpc-dev Jochen Wiedmann jochen jochen.wiedmann@gmail.com The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo scm:svn:http://svn.apache.org/repos/asf/webservices/commons/tags/ws-commons-util-1.0 scm:svn:https://svn.apache.org/repos/asf/webservices/commons/tags/ws-commons-util-1.0 http://svn.apache.org/viewcvs.cgi/webservices/commons/tags/ws-commons-util-1.0 Apache Software Foundation http://www.apache.org/ org.apache.maven.plugins maven-compiler-plugin 1.3 1.2 org.apache.maven.plugins maven-eclipse-plugin true true org.apache.maven.plugins maven-source-plugin jar org.apache.maven.plugins maven-assembly-plugin src/main/assembly/bin.xml src/main/assembly/src.xml gnu junit junit 3.8.1 xml-apis xml-apis 1.0.b2 org.apache.maven.plugins maven-javadoc-plugin apache-maven Apache Maven Repository scp://people.apache.org/www/www.apache.org/dist/maven-repository false apache-maven-snapshots Apache Maven Snapshot Repository scp://people.apache.org/www/cvs.apache.org/maven-snapshot-repository commons-util-site WebServices Site / Commons/ Util scp://people.apache.org/www/ws.apache.org/commons/util 1.4 org.apache.ws.commons ws-commons-java5 1.0 libws-commons-util-1.0.1.orig/LICENSE.txt0000644000175000017500000002613610327756010020250 0ustar vladimirvladimir Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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. libws-commons-util-1.0.1.orig/.project0000644000175000017500000000123510360070743020064 0ustar vladimirvladimir ws-commons-util These classes are used for creating and reading XML with JAXP 1.1. In other words, without the javax.xml.transform package. org.eclipse.jdt.core.javabuilder org.maven.ide.eclipse.maven2Builder org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature libws-commons-util-1.0.1.orig/.classpath0000644000175000017500000000062310360070743020400 0ustar vladimirvladimir libws-commons-util-1.0.1.orig/src/changes/changes.xml0000644000175000017500000000061610445606136022755 0ustar vladimirvladimir Changes in WS Commons Util The classes XsDateTimeFormat, and XsTimeFormat have been parsing the milliseconds wrong, if the string contained less than three digits. libws-commons-util-1.0.1.orig/src/changes/0000755000175000017500000000000010430324240020603 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/test/java/org/apache/ws/commons/util/test/Base64Test.java0000644000175000017500000000423510327756010031707 0ustar vladimirvladimir/* * Copyright 1999,2005 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.test; import java.io.StringWriter; import java.util.Arrays; import org.apache.ws.commons.util.Base64; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import junit.framework.TestCase; /** A test case for the Base64 encoder/decoder. */ public class Base64Test extends TestCase { /** Test for the base64 decoder/encoder. * @throws Exception The test failed. */ public void testBase64() throws Exception { for (int i = 0; i <= 256; i++) { byte[] bytes = new byte[i]; for (int j = 0; j < i; j++) { bytes[j] = (byte) j; } String s = Base64.encode(bytes); byte[] result = Base64.decode(s); assertTrue(Arrays.equals(bytes, result)); } } /** Test for the base64 SAX encoder. * @throws Exception The test failed. */ public void testSAXEncoder() throws Exception { for (int i = 0; i <= 256; i++) { byte[] bytes = new byte[i]; for (int j = 0; j < i; j++) { bytes[j] = (byte) j; } final StringWriter sw = new StringWriter(); ContentHandler ch = new DefaultHandler(){ public void characters(char[] pChars, int pOffset, int pLen) throws SAXException { sw.write(pChars, pOffset, pLen); } }; Base64.SAXEncoder encoder = new Base64.SAXEncoder(new char[4096], 0, null, ch); Base64.EncoderOutputStream eos = new Base64.EncoderOutputStream(encoder); eos.write(bytes); eos.close(); String s = sw.toString(); byte[] result = Base64.decode(s); assertTrue(Arrays.equals(bytes, result)); } } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibws-commons-util-1.0.1.orig/src/test/java/org/apache/ws/commons/util/test/XsDateTimeFormatTest.javalibws-commons-util-1.0.1.orig/src/test/java/org/apache/ws/commons/util/test/XsDateTimeFormatTest.jav0000644000175000017500000001677110433145501033705 0ustar vladimirvladimir/* * Copyright 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.test; import java.text.Format; import java.text.ParseException; import java.util.Calendar; import java.util.TimeZone; import org.apache.ws.commons.util.XsDateFormat; import org.apache.ws.commons.util.XsDateTimeFormat; import org.apache.ws.commons.util.XsTimeFormat; import junit.framework.TestCase; /**

Test case for the various instances of {@link java.text.Format}, * which are being used to parse special types like xs:dateTime.

* * @author Jochen Wiedmann */ public class XsDateTimeFormatTest extends TestCase { /** Creates a new test with the given name. */ public XsDateTimeFormatTest(String pName) { super(pName); } private Calendar getCalendar(TimeZone pTimeZone) { Calendar cal = Calendar.getInstance(pTimeZone); cal.set(2004, 01-1, 14, 03, 12, 07); cal.set(Calendar.MILLISECOND, 0); return cal; } /** Test for * {@link org.apache.ws.jaxme.xs.util.XsDateTimeFormat#format(Object, StringBuffer, java.text.FieldPosition)}. */ public void testFormatDateTime() { Calendar cal = getCalendar(TimeZone.getTimeZone("GMT")); assertEquals(0, cal.get(Calendar.MILLISECOND)); XsDateTimeFormat format = new XsDateTimeFormat(); String got = format.format(cal); String expect = "2004-01-14T03:12:07Z"; assertEquals(expect, got); cal = getCalendar(TimeZone.getTimeZone("GMT-03:00")); assertEquals(0, cal.get(Calendar.MILLISECOND)); got = format.format(cal); expect = "2004-01-14T03:12:07-03:00"; assertEquals(expect, got); } /** Test for * {@link org.apache.ws.jaxme.xs.util.XsDateTimeFormat#parseObject(String, java.text.ParsePosition)}. */ public void testParseDateTime() throws ParseException { String[] dateTimes = new String[]{ "2004-01-14T03:12:07.000Z", "2004-01-14T03:12:07", "2004-01-14T03:12:07-00:00", "2004-01-14T03:12:07+00:00", }; XsDateTimeFormat format = new XsDateTimeFormat(); Calendar expect = getCalendar(TimeZone.getTimeZone("GMT")); for (int i = 0; i < dateTimes.length; i++) { Calendar got = (Calendar) format.parseObject(dateTimes[0]); assertEquals(expect, got); } String dateTime = "2004-01-14T03:12:07.000-03:00"; expect = getCalendar(TimeZone.getTimeZone("GMT-03:00")); Calendar got = (Calendar) format.parseObject(dateTime); assertEquals(expect, got); } /** Test for * {@link org.apache.ws.jaxme.xs.util.XsDateFormat#format(Object, StringBuffer, java.text.FieldPosition)}. */ public void testFormatDate() { Calendar cal = getCalendar(TimeZone.getTimeZone("GMT")); assertEquals(0, cal.get(Calendar.MILLISECOND)); XsDateFormat format = new XsDateFormat(); String got = format.format(cal); String expect = "2004-01-14Z"; assertEquals(expect, got); cal = getCalendar(TimeZone.getTimeZone("GMT-03:00")); assertEquals(0, cal.get(Calendar.MILLISECOND)); got = format.format(cal); expect = "2004-01-14-03:00"; assertEquals(expect, got); } protected void assertEqualDate(Calendar pExpect, Calendar pGot) { assertEquals(pExpect.get(Calendar.YEAR), pGot.get(Calendar.YEAR)); assertEquals(pExpect.get(Calendar.MONTH), pGot.get(Calendar.MONTH)); assertEquals(pExpect.get(Calendar.DAY_OF_MONTH), pGot.get(Calendar.DAY_OF_MONTH)); assertEquals(pExpect.getTimeZone(), pGot.getTimeZone()); } protected void assertEqualTime(Calendar pExpect, Calendar pGot) { assertEquals(pExpect.get(Calendar.HOUR_OF_DAY), pGot.get(Calendar.HOUR_OF_DAY)); assertEquals(pExpect.get(Calendar.MINUTE), pGot.get(Calendar.MINUTE)); assertEquals(pExpect.get(Calendar.SECOND), pGot.get(Calendar.SECOND)); assertEquals(pExpect.get(Calendar.MILLISECOND), pGot.get(Calendar.MILLISECOND)); assertEquals(pExpect.getTimeZone(), pGot.getTimeZone()); } /** Test for * {@link org.apache.ws.jaxme.xs.util.XsDateFormat#parseObject(String, java.text.ParsePosition)}. */ public void testParseDate() throws ParseException { String[] dateTimes = new String[]{ "2004-01-14Z", "2004-01-14", "2004-01-14+00:00", "2004-01-14-00:00", }; XsDateFormat format = new XsDateFormat(); Calendar expect = getCalendar(TimeZone.getTimeZone("GMT")); for (int i = 0; i < dateTimes.length; i++) { Calendar got = (Calendar) format.parseObject(dateTimes[0]); assertEqualDate(expect, got); } String dateTime = "2004-01-14-03:00"; expect = getCalendar(TimeZone.getTimeZone("GMT-03:00")); Calendar got = (Calendar) format.parseObject(dateTime); assertEqualDate(expect, got); } /** Test for * {@link org.apache.ws.jaxme.xs.util.XsTimeFormat#format(Object, StringBuffer, java.text.FieldPosition)}. */ public void testFormatTime() { Calendar cal = getCalendar(TimeZone.getTimeZone("GMT")); assertEquals(0, cal.get(Calendar.MILLISECOND)); XsTimeFormat format = new XsTimeFormat(); String got = format.format(cal); String expect = "03:12:07Z"; assertEquals(expect, got); cal = getCalendar(TimeZone.getTimeZone("GMT-03:00")); assertEquals(0, cal.get(Calendar.MILLISECOND)); got = format.format(cal); expect = "03:12:07-03:00"; assertEquals(expect, got); } /** Test for * {@link org.apache.ws.jaxme.xs.util.XsTimeFormat#parseObject(String, java.text.ParsePosition)}. */ public void testParseTime() throws ParseException { String[] dateTimes = new String[]{ "03:12:07.000Z", "03:12:07", "03:12:07-00:00", "03:12:07+00:00", }; XsTimeFormat format = new XsTimeFormat(); Calendar expect = getCalendar(TimeZone.getTimeZone("GMT")); for (int i = 0; i < dateTimes.length; i++) { Calendar got = (Calendar) format.parseObject(dateTimes[0]); assertEqualTime(expect, got); } String dateTime = "03:12:07.000-03:00"; expect = getCalendar(TimeZone.getTimeZone("GMT-03:00")); Calendar got = (Calendar) format.parseObject(dateTime); assertEqualTime(expect, got); } /** Tests, whether e zero as suffix matters in milliseconds. */ public void testZeroSuffix() throws Exception { Format format = new XsDateTimeFormat(); Calendar c1 = (Calendar) format.parseObject("2006-05-03T15:29:17.15Z"); Calendar c2 = (Calendar) format.parseObject("2006-05-03T15:29:17.150Z"); assertEquals(c1, c2); format = new XsTimeFormat(); c1 = (Calendar) format.parseObject("15:29:17.15Z"); c2 = (Calendar) format.parseObject("15:29:17.150Z"); assertEquals(c1, c2); } } libws-commons-util-1.0.1.orig/src/test/java/org/apache/ws/commons/util/test/0000755000175000017500000000000010435415036027154 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/test/java/org/apache/ws/commons/util/0000755000175000017500000000000010435415036026175 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/test/java/org/apache/ws/commons/0000755000175000017500000000000010435415036025220 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/test/java/org/apache/ws/0000755000175000017500000000000010435415035023544 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/test/java/org/apache/0000755000175000017500000000000010435415035023113 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/test/java/org/0000755000175000017500000000000010435415036021673 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/test/java/0000755000175000017500000000000010435415035021103 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/test/0000755000175000017500000000000010435415220020156 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/XMLWriter.java0000644000175000017500000001121610243730055031653 0ustar vladimirvladimir/* * 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.io.Writer; /** A simple serializer for XML documents, which is writing to * an instance of {@link java.io.Writer}. */ public interface XMLWriter extends org.xml.sax.ContentHandler { /** Sets the writers encoding. * @param pEncoding Writers encoding, by default null, in * which case UTF-8 is being used. */ public void setEncoding(String pEncoding); /** Returns the writers encoding. * @return Writers encoding, by default null, in * which case UTF-8 is being used. */ public String getEncoding(); /** Sets, whether an XML declaration is being generated. * @param pDeclarating Whether an XML declaration is generated. Defaults * to false. */ public void setDeclarating(boolean pDeclarating); /** Returns, whether an XML declaration is being generated. * @return Whether an XML declaration is generated. Defaults * to false. */ public boolean isDeclarating(); /** Sets the target {@link Writer}. This is typically an instance * of {@link java.io.BufferedWriter}, which is connected to an * instance of {@link java.io.OutputStreamWriter} with an encoding * matching the XML documents encoding. * @param pWriter The target writer. */ public void setWriter(Writer pWriter); /** Returns the target {@link Writer}. This is typically an instance * of {@link java.io.BufferedWriter}, which is connected to an * instance of {@link java.io.OutputStreamWriter} with an encoding * matching the XML documents encoding. * @return The target writer. */ public Writer getWriter(); /**

Returns whether the XMLWriter can encode the character * c without an escape sequence like &#ddd;.

* @param pChar The character being checked for escaping. * @return Whether to encode the character. */ public boolean canEncode(char pChar); /** 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. * @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(); } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/OrderedAttributeXMLWriter.javalibws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/OrderedAttributeXMLWrite0000644000175000017500000000531610243730055033746 0ustar vladimirvladimir/* * 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.java0000644000175000017500000001527310243730055031753 0ustar vladimirvladimir/* * 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); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/PassThroughXMLWriter.javalibws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/PassThroughXMLWriter.jav0000644000175000017500000000156410243730055033707 0ustar vladimirvladimir/* * 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.java0000644000175000017500000002475210243730055032506 0ustar vladimirvladimir/* * 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("'); } 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(""); } } 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.java0000644000175000017500000002640710243730055032477 0ustar vladimirvladimir/* * 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 the namespaceDeclarationAttribute * 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.java0000644000175000017500000000243710243730055033132 0ustar vladimirvladimir/* * 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.html0000644000175000017500000000222610243730055031435 0ustar vladimirvladimir Package Documentation for org.apache.ws.commons.util Package

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.

libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/serialize/0000755000175000017500000000000010435414716027160 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/util/XsDateFormat.java0000644000175000017500000000176010433145406031351 0ustar vladimirvladimir/* * 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; /**

An instance of {@link java.text.Format}, which may be used to parse * and format xs:date values.

*/ public class XsDateFormat extends XsDateTimeFormat { private static final long serialVersionUID = 3832621764093030707L; /** Creates a new instance. */ public XsDateFormat() { super(true, false); } } libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/util/NamespaceContextImpl.java0000644000175000017500000002660410243730055033076 0ustar vladimirvladimir/* * 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.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; /** Default implementation of {@link javax.xml.namespace.NamespaceContext}. */ public class NamespaceContextImpl implements NamespaceContext { /* List of currently defined prefixes (even indexes, 0, 2, 4, ...) * and namespace URI's (odd indexes, 1, 3, 5, ...) */ private List prefixList; /* The prefix and namespace URI, which have been defined * last. It is assumed, that these are looked up the most. * Thus we keep them in separate variables, for reasons * of speed. */ private String cachedPrefix, cachedURI; /** Resets the NamespaceSupport's state. Allows reusing the * object. */ public void reset() { cachedURI = cachedPrefix = null; if (prefixList != null) { prefixList.clear(); } } /** Declares a new prefix. Typically called from within * {@link org.xml.sax.ContextHandler#startPrefixMapping(java.lang.String, java.lang.String)}. * @throws IllegalArgumentException Prefix or URI are null. */ public void startPrefixMapping(String pPrefix, String pURI) { if (pPrefix == null) { throw new IllegalArgumentException("The namespace prefix must not be null."); } if (pURI == null) { throw new IllegalArgumentException("The namespace prefix must not be null."); } if (cachedURI != null) { if (prefixList == null) { prefixList = new ArrayList(); } prefixList.add(cachedPrefix); prefixList.add(cachedURI); } cachedURI = pURI; cachedPrefix = pPrefix; } /** Removes the declaration of the prefix, which has been defined * last. Typically called from within * {@link org.xml.sax.ContextHandler#endPrefixMapping(java.lang.String)}. * @throws IllegalArgumentException The prefix is null. * @throws IllegalStateException The prefix is not the prefix, which * has been defined last. In other words, the calls to * {@link #startPrefixMapping(String, String)}, and * {@link #endPrefixMapping(String)} aren't in LIFO order. */ public void endPrefixMapping(String pPrefix) { if (pPrefix == null) { throw new IllegalArgumentException("The namespace prefix must not be null."); } if (pPrefix.equals(cachedPrefix)) { if (prefixList != null && prefixList.size() > 0) { cachedURI = prefixList.remove(prefixList.size()-1).toString(); cachedPrefix = prefixList.remove(prefixList.size()-1).toString(); } else { cachedPrefix = cachedURI = null; } } else { throw new IllegalStateException("The prefix " + pPrefix + " isn't the prefix, which has been defined last."); } } /** Given a prefix, returns the URI to which the prefix is * currently mapped or null, if there is no such mapping.

*

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.java0000644000175000017500000002275210433145363032176 0ustar vladimirvladimir/* * 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.

*/ public class XsDateTimeFormat extends Format { private static final long serialVersionUID = 3258131340871479609L; final boolean parseDate; final boolean parseTime; XsDateTimeFormat(boolean pParseDate, boolean pParseTime) { parseDate = pParseDate; parseTime = pParseTime; } /** Creates a new instance. */ public XsDateTimeFormat() { this(true, true); } private int parseInt(String pString, int pOffset, StringBuffer pDigits) { int length = pString.length(); pDigits.setLength(0); while (pOffset < length) { char c = pString.charAt(pOffset); if (Character.isDigit(c)) { pDigits.append(c); ++pOffset; } else { break; } } return pOffset; } public Object parseObject(String pString, ParsePosition pParsePosition) { if (pString == null) { throw new NullPointerException("The String argument must not be null."); } if (pParsePosition == null) { throw new NullPointerException("The ParsePosition argument must not be null."); } int offset = pParsePosition.getIndex(); int length = pString.length(); boolean isMinus = false; StringBuffer digits = new StringBuffer(); int year, month, mday; if (parseDate) { // Sign if (offset < length) { char c = pString.charAt(offset); if (c == '+') { ++offset; } else if (c == '-') { ++offset; isMinus = true; } } offset = parseInt(pString, offset, digits); if (digits.length() < 4) { pParsePosition.setErrorIndex(offset); return null; } year = Integer.parseInt(digits.toString()); if (offset < length && pString.charAt(offset) == '-') { ++offset; } else { pParsePosition.setErrorIndex(offset); return null; } offset = parseInt(pString, offset, digits); if (digits.length() != 2) { pParsePosition.setErrorIndex(offset); return null; } month = Integer.parseInt(digits.toString()); if (offset < length && pString.charAt(offset) == '-') { ++offset; } else { pParsePosition.setErrorIndex(offset); return null; } offset = parseInt(pString, offset, digits); if (digits.length() != 2) { pParsePosition.setErrorIndex(offset); return null; } mday = Integer.parseInt(digits.toString()); if (parseTime) { if (offset < length && pString.charAt(offset) == 'T') { ++offset; } else { pParsePosition.setErrorIndex(offset); return null; } } } else { year = month = mday = 0; } int hour, minute, second, millis; if (parseTime) { offset = parseInt(pString, offset, digits); if (digits.length() != 2) { pParsePosition.setErrorIndex(offset); return null; } hour = Integer.parseInt(digits.toString()); if (offset < length && pString.charAt(offset) == ':') { ++offset; } else { pParsePosition.setErrorIndex(offset); return null; } offset = parseInt(pString, offset, digits); if (digits.length() != 2) { pParsePosition.setErrorIndex(offset); return null; } minute = Integer.parseInt(digits.toString()); if (offset < length && pString.charAt(offset) == ':') { ++offset; } else { pParsePosition.setErrorIndex(offset); return null; } offset = parseInt(pString, offset, digits); if (digits.length() != 2) { pParsePosition.setErrorIndex(offset); return null; } second = Integer.parseInt(digits.toString()); if (offset < length && pString.charAt(offset) == '.') { ++offset; offset = parseInt(pString, offset, digits); if (digits.length() > 0) { millis = Integer.parseInt(digits.toString()); if (millis > 999) { pParsePosition.setErrorIndex(offset); return null; } for (int i = digits.length(); i < 3; i++) { millis *= 10; } } else { millis = 0; } } else { millis = 0; } } else { hour = minute = second = millis = 0; } digits.setLength(0); digits.append("GMT"); if (offset < length) { char c = pString.charAt(offset); if (c == 'Z') { // Ignore UTC, it is the default ++offset; } else if (c == '+' || c == '-') { digits.append(c); ++offset; for (int i = 0; i < 5; i++) { if (offset >= length) { pParsePosition.setErrorIndex(offset); return null; } c = pString.charAt(offset); if ((i != 2 && Character.isDigit(c)) || (i == 2 && c == ':')) { digits.append(c); } else { pParsePosition.setErrorIndex(offset); return null; } ++offset; } } } Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(digits.toString())); cal.set(isMinus ? -year : year, parseDate ? month-1 : month, mday, hour, minute, second); cal.set(Calendar.MILLISECOND, millis); pParsePosition.setIndex(offset); return cal; } private void append(StringBuffer pBuffer, int pNum, int pMinLen) { String s = Integer.toString(pNum); for (int i = s.length(); i < pMinLen; i++) { pBuffer.append('0'); } pBuffer.append(s); } public StringBuffer format(Object pCalendar, StringBuffer pBuffer, FieldPosition pPos) { if (pCalendar == null) { throw new NullPointerException("The Calendar argument must not be null."); } if (pBuffer == null) { throw new NullPointerException("The StringBuffer argument must not be null."); } if (pPos == null) { throw new NullPointerException("The FieldPosition argument must not be null."); } Calendar cal = (Calendar) pCalendar; if (parseDate) { int year = cal.get(Calendar.YEAR); if (year < 0) { pBuffer.append('-'); year = -year; } append(pBuffer, year, 4); pBuffer.append('-'); append(pBuffer, cal.get(Calendar.MONTH)+1, 2); pBuffer.append('-'); append(pBuffer, cal.get(Calendar.DAY_OF_MONTH), 2); if (parseTime) { pBuffer.append('T'); } } if (parseTime) { append(pBuffer, cal.get(Calendar.HOUR_OF_DAY), 2); pBuffer.append(':'); append(pBuffer, cal.get(Calendar.MINUTE), 2); pBuffer.append(':'); append(pBuffer, cal.get(Calendar.SECOND), 2); int millis = cal.get(Calendar.MILLISECOND); if (millis > 0) { pBuffer.append('.'); append(pBuffer, millis, 3); } } TimeZone tz = cal.getTimeZone(); // JDK 1.4: int offset = tz.getOffset(cal.getTimeInMillis()); int offset = cal.get(Calendar.ZONE_OFFSET); if (tz.inDaylightTime(cal.getTime())) { offset += cal.get(Calendar.DST_OFFSET); } if (offset == 0) { pBuffer.append('Z'); } else { if (offset < 0) { pBuffer.append('-'); offset = -offset; } else { pBuffer.append('+'); } int minutes = offset / (60*1000); int hours = minutes / 60; minutes -= hours * 60; append(pBuffer, hours, 2); pBuffer.append(':'); append(pBuffer, minutes, 2); } return pBuffer; } } libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/util/XsTimeFormat.java0000644000175000017500000000176010433145445031375 0ustar vladimirvladimir/* * 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; /**

An instance of {@link java.text.Format}, which may be used to parse * and format xs:time values.

*/ public class XsTimeFormat extends XsDateTimeFormat { private static final long serialVersionUID = 3906931187925727282L; /** Creates a new instance. */ public XsTimeFormat() { super(false, true); } } libws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/util/Base64.java0000644000175000017500000004710110244423072030031 0ustar vladimirvladimir/* * Copyright 1999,2005 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.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.StringWriter; import java.io.Writer; import java.lang.reflect.UndeclaredThrowableException; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; /** Performs Base64 encoding and/or decoding. This is an on-the-fly decoder: Unlike, * for example, the commons-codec classes, it doesn't depend on byte arrays. In * other words, it has an extremely low memory profile. This is well suited even * for very large byte streams. */ public class Base64 { /** An exception of this type is thrown, if the decoded * character stream contains invalid input. */ public static class DecodingException extends IOException { private static final long serialVersionUID = 3257006574836135478L; DecodingException(String pMessage) { super(pMessage); } } /** An exception of this type is thrown by the {@link SAXEncoder}, * if writing to the target handler causes a SAX exception. * This class is required, because the {@link IOException} * allows no cause until Java 1.3. */ public static class SAXIOException extends IOException { private static final long serialVersionUID = 3258131345216451895L; final SAXException saxException; SAXIOException(SAXException e) { super(); saxException = e; } /** Returns the encapsulated {@link SAXException}. * @return An exception, which was thrown when invoking * {@link ContentHandler#characters(char[], int, int)}. */ public SAXException getSAXException() { return saxException; } } /** Default line separator: \n */ public static final String LINE_SEPARATOR = "\n"; /** Default size for line wrapping. */ public static final int LINE_SIZE = 76; /** * This array is a lookup table that translates 6-bit positive integer * index values into their "Base64 Alphabet" equivalents as specified * in Table 1 of RFC 2045. */ private static final char intToBase64[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; /** * This array is a lookup table that translates unicode characters * drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) * into their 6-bit positive integer equivalents. Characters that * are not in the Base64 alphabet but fall within the bounds of the * array are translated to -1. */ private static final byte base64ToInt[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 }; /** An encoder is an object, which is able to encode byte array * in blocks of three bytes. Any such block is converted into an * array of four bytes. */ public static abstract class Encoder { private int num, numBytes; private final char[] charBuffer; private int charOffset; private final int wrapSize; private final int skipChars; private final String sep; private int lineChars = 0; /** Creates a new instance. * @param pBuffer The encoders buffer. The encoder will * write to the buffer as long as possible. If the * buffer is full or the end of data is signaled, then * the method {@link #writeBuffer(char[], int, int)} * will be invoked. * @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. */ protected Encoder(char[] pBuffer, int pWrapSize, String pSep) { charBuffer = pBuffer; sep = pSep == null ? null : Base64.LINE_SEPARATOR; skipChars = pWrapSize == 0 ? 4 : 4 + sep.length(); wrapSize = skipChars == 4 ? 0 : pWrapSize; if (wrapSize < 0 || wrapSize %4 > 0) { throw new IllegalArgumentException("Illegal argument for wrap size: " + pWrapSize + "(Expected nonnegative multiple of 4)"); } if (pBuffer.length < skipChars) { throw new IllegalArgumentException("The buffer must contain at least " + skipChars + " characters, but has " + pBuffer.length); } } /** Called for writing the buffer contents to the target. * @param pChars The buffer being written. * @param pOffset Offset of first character being written. * @param pLen Number of characters being written. * @throws IOException Writing to the destination failed. */ protected abstract void writeBuffer(char[] pChars, int pOffset, int pLen) throws IOException; private void wrap() { for (int j = 0; j < sep.length(); j++) { charBuffer[charOffset++] = sep.charAt(j); } lineChars = 0; } /** Encodes the given byte array. * @param pBuffer Byte array being encoded. * @param pOffset Offset of first byte being encoded. * @param pLen Number of bytes being encoded. * @throws IOException Invoking the {@link #writeBuffer(char[],int,int)} method * for writing the encoded data failed. */ public void write(byte[] pBuffer, int pOffset, int pLen) throws IOException { for(int i = 0; i < pLen; i++) { int b = pBuffer[pOffset++]; if (b < 0) { b += 256; } num = (num << 8) + b; if (++numBytes == 3) { charBuffer[charOffset++] = intToBase64[num >> 18]; charBuffer[charOffset++] = intToBase64[(num >> 12) & 0x3f]; charBuffer[charOffset++] = intToBase64[(num >> 6) & 0x3f]; charBuffer[charOffset++] = intToBase64[num & 0x3f]; if (wrapSize > 0) { lineChars += 4; if (lineChars >= wrapSize) { wrap(); } } num = 0; numBytes = 0; if (charOffset + skipChars > charBuffer.length) { writeBuffer(charBuffer, 0, charOffset); charOffset = 0; } } } } /** Writes any currently buffered data to the destination. * @throws IOException Invoking the {@link #writeBuffer(char[],int,int)} * method for writing the encoded data failed. */ public void flush() throws IOException { if (numBytes > 0) { if (numBytes == 1) { charBuffer[charOffset++] = intToBase64[num >> 2]; charBuffer[charOffset++] = intToBase64[(num << 4) & 0x3f]; charBuffer[charOffset++] = '='; charBuffer[charOffset++] = '='; } else { charBuffer[charOffset++] = intToBase64[num >> 10]; charBuffer[charOffset++] = intToBase64[(num >> 4) & 0x3f]; charBuffer[charOffset++] = intToBase64[(num << 2) & 0x3f]; charBuffer[charOffset++] = '='; } lineChars += 4; num = 0; numBytes = 0; } if (wrapSize > 0 && lineChars > 0) { wrap(); } if (charOffset > 0) { writeBuffer(charBuffer, 0, charOffset); charOffset = 0; } } } /** An {@link OutputStream}, which is writing to the given * {@link Encoder}. */ public static class EncoderOutputStream extends OutputStream { private final Encoder encoder; /** Creates a new instance, which is creating * output using the given {@link Encoder}. * @param pEncoder The base64 encoder being used. */ public EncoderOutputStream(Encoder pEncoder) { encoder = pEncoder; } private final byte[] oneByte = new byte[1]; public void write(int b) throws IOException { oneByte[0] = (byte) b; encoder.write(oneByte, 0, 1); } public void write(byte[] pBuffer, int pOffset, int pLen) throws IOException { encoder.write(pBuffer, pOffset, pLen); } public void close() throws IOException { encoder.flush(); } } /** 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. * @return An output stream, encoding its input in Base64 and writing * the output to the writer 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.html0000644000175000017500000000155410243730055030426 0ustar vladimirvladimir Package Documentation for org.apache.ws.commons.util Package

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/0000755000175000017500000000000010435414715026145 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/commons/0000755000175000017500000000000010435414716025171 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/main/java/org/apache/ws/0000755000175000017500000000000010435414715023515 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/main/java/org/apache/0000755000175000017500000000000010435414714023063 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/main/java/org/0000755000175000017500000000000010435414716021644 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/main/java/0000755000175000017500000000000010435414714021053 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/main/assembly/src.xml0000644000175000017500000000062010435415421023254 0ustar vladimirvladimir src tar.gz LICENSE.txt pom.xml .cvsignore .classpath .project src libws-commons-util-1.0.1.orig/src/main/assembly/bin.xml0000644000175000017500000000067610435415310023245 0ustar vladimirvladimir bin tar.gz true LICENSE.txt target /lib *.jar libws-commons-util-1.0.1.orig/src/main/assembly/0000755000175000017500000000000010435420000021732 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/main/0000755000175000017500000000000010435414714020132 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/site/site.xml0000644000175000017500000000124210435414346021640 0ustar vladimirvladimir Apache Webservices Common Utilities http://ws.apache.org/images/project-logo.jpg http://ws.apache.org/commons/util/ ${reports} libws-commons-util-1.0.1.orig/src/site/apt/index.apt0000644000175000017500000000071710435414216022555 0ustar vladimirvladimir ----------------------------------- Apache Webservices Common Utilities ----------------------------------- About Apache WS Common Utilities This is a small collection of utility classes, that allow high performance XML processing based on SAX. Basically, it is assumed, that you are using an JAXP 1.1 compliant XML parser and nothing else. In particular, no dependency on the javax.xml.transform package is introduced. libws-commons-util-1.0.1.orig/src/site/apt/0000755000175000017500000000000010435414375020741 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/site/0000755000175000017500000000000010435414375020155 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/src/0000755000175000017500000000000010435415217017205 5ustar vladimirvladimirlibws-commons-util-1.0.1.orig/0000755000175000017500000000000010614460465016422 5ustar vladimirvladimir