Thread: [Practicalxml-commits] SF.net SVN: practicalxml:[71] trunk
Brought to you by:
kdgregory
From: Auto-Generated S. C. M. <pra...@li...> - 2009-01-02 13:20:13
|
Revision: 71 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=71&view=rev Author: kdgregory Date: 2009-01-02 13:19:54 +0000 (Fri, 02 Jan 2009) Log Message: ----------- Add license Modified Paths: -------------- trunk/src/example/java/net/sf/practicalxml/example/BuilderExample.java trunk/src/main/java/net/sf/practicalxml/DomUtil.java trunk/src/main/java/net/sf/practicalxml/OutputUtil.java trunk/src/main/java/net/sf/practicalxml/ParseUtil.java trunk/src/main/java/net/sf/practicalxml/SchemaUtil.java trunk/src/main/java/net/sf/practicalxml/XmlException.java trunk/src/main/java/net/sf/practicalxml/XmlUtil.java trunk/src/main/java/net/sf/practicalxml/builder/AttributeNode.java trunk/src/main/java/net/sf/practicalxml/builder/CommentNode.java trunk/src/main/java/net/sf/practicalxml/builder/ElementNode.java trunk/src/main/java/net/sf/practicalxml/builder/Node.java trunk/src/main/java/net/sf/practicalxml/builder/TextNode.java trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilder.java trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilderException.java trunk/src/main/java/net/sf/practicalxml/junit/DomAsserts.java trunk/src/main/java/net/sf/practicalxml/util/ErrorHandlerAdapter.java trunk/src/main/java/net/sf/practicalxml/util/ExceptionErrorHandler.java trunk/src/main/java/net/sf/practicalxml/util/NodeListIterable.java trunk/src/main/java/net/sf/practicalxml/xpath/AbstractFunction.java trunk/src/main/java/net/sf/practicalxml/xpath/FunctionResolver.java trunk/src/main/java/net/sf/practicalxml/xpath/NamespaceResolver.java trunk/src/main/java/net/sf/practicalxml/xpath/SimpleNamespaceResolver.java trunk/src/main/java/net/sf/practicalxml/xpath/XPathWrapper.java trunk/src/main/java/net/sf/practicalxml/xpath/function/Constants.java trunk/src/main/java/net/sf/practicalxml/xpath/function/Lowercase.java trunk/src/main/java/net/sf/practicalxml/xpath/function/Uppercase.java trunk/src/main/java/net/sf/practicalxml/xpath/function/XsiBoolean.java trunk/src/test/java/net/sf/practicalxml/AbstractTestCase.java trunk/src/test/java/net/sf/practicalxml/TestDomUtil.java trunk/src/test/java/net/sf/practicalxml/TestDomUtilGetPath.java trunk/src/test/java/net/sf/practicalxml/TestOutputUtil.java trunk/src/test/java/net/sf/practicalxml/TestParseUtil.java trunk/src/test/java/net/sf/practicalxml/TestSchemaUtil.java trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java trunk/src/test/java/net/sf/practicalxml/builder/TestXmlBuilder.java trunk/src/test/java/net/sf/practicalxml/junit/TestDomAsserts.java trunk/src/test/java/net/sf/practicalxml/util/TestNodeListIterable.java trunk/src/test/java/net/sf/practicalxml/xpath/TestAbstractFunction.java trunk/src/test/java/net/sf/practicalxml/xpath/TestFunctionResolver.java trunk/src/test/java/net/sf/practicalxml/xpath/TestNamespaceResolver.java trunk/src/test/java/net/sf/practicalxml/xpath/TestSimpleNamespaceResolver.java trunk/src/test/java/net/sf/practicalxml/xpath/TestXPathWrapper.java trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java trunk/src/test/java/net/sf/practicalxml/xpath/function/TestXsiBoolean.java Added Paths: ----------- trunk/LICENSE.txt trunk/src/main/resources/ trunk/src/main/resources/LICENSE.txt Added: trunk/LICENSE.txt =================================================================== --- trunk/LICENSE.txt (rev 0) +++ trunk/LICENSE.txt 2009-01-02 13:19:54 UTC (rev 71) @@ -0,0 +1,202 @@ + + 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. Modified: trunk/src/example/java/net/sf/practicalxml/example/BuilderExample.java =================================================================== --- trunk/src/example/java/net/sf/practicalxml/example/BuilderExample.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/example/java/net/sf/practicalxml/example/BuilderExample.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.example; import net.sf.practicalxml.builder.ElementNode; Modified: trunk/src/main/java/net/sf/practicalxml/DomUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/DomUtil.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/DomUtil.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml; import java.util.ArrayList; Modified: trunk/src/main/java/net/sf/practicalxml/OutputUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/OutputUtil.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/OutputUtil.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml; import java.io.IOException; Modified: trunk/src/main/java/net/sf/practicalxml/ParseUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/ParseUtil.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/ParseUtil.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml; import java.io.IOException; @@ -8,15 +22,15 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.validation.Schema; -import net.sf.practicalxml.util.ExceptionErrorHandler; - import org.w3c.dom.Document; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import net.sf.practicalxml.util.ExceptionErrorHandler; + /** * A collection of static methods for parsing XML into a DOM, with or without * validation. Modified: trunk/src/main/java/net/sf/practicalxml/SchemaUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/SchemaUtil.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/SchemaUtil.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml; import java.util.Comparator; Modified: trunk/src/main/java/net/sf/practicalxml/XmlException.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/XmlException.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/XmlException.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml; Modified: trunk/src/main/java/net/sf/practicalxml/XmlUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/XmlUtil.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/XmlUtil.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml; import java.text.DateFormat; Modified: trunk/src/main/java/net/sf/practicalxml/builder/AttributeNode.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/AttributeNode.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/builder/AttributeNode.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.builder; import org.w3c.dom.Element; Modified: trunk/src/main/java/net/sf/practicalxml/builder/CommentNode.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/CommentNode.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/builder/CommentNode.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.builder; import org.w3c.dom.Comment; Modified: trunk/src/main/java/net/sf/practicalxml/builder/ElementNode.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/ElementNode.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/builder/ElementNode.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.builder; import java.io.OutputStream; Modified: trunk/src/main/java/net/sf/practicalxml/builder/Node.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/Node.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/builder/Node.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.builder; import org.w3c.dom.Element; Modified: trunk/src/main/java/net/sf/practicalxml/builder/TextNode.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/TextNode.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/builder/TextNode.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.builder; import org.w3c.dom.Element; Modified: trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilder.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilder.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilder.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.builder; Modified: trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilderException.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilderException.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilderException.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.builder; Modified: trunk/src/main/java/net/sf/practicalxml/junit/DomAsserts.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/junit/DomAsserts.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/junit/DomAsserts.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,17 +1,32 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.junit; -import static junit.framework.Assert.*; - import java.util.List; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + import junit.framework.Assert; import net.sf.practicalxml.DomUtil; import net.sf.practicalxml.xpath.XPathWrapper; -import org.w3c.dom.Element; -import org.w3c.dom.Node; +import static junit.framework.Assert.*; + /** * JUnit assertions for DOM documents. These are defined as static methods, * so may be statically imported (although in some cases this will clash Modified: trunk/src/main/java/net/sf/practicalxml/util/ErrorHandlerAdapter.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/util/ErrorHandlerAdapter.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/util/ErrorHandlerAdapter.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.util; import org.xml.sax.ErrorHandler; Modified: trunk/src/main/java/net/sf/practicalxml/util/ExceptionErrorHandler.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/util/ExceptionErrorHandler.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/util/ExceptionErrorHandler.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.util; import java.util.ArrayList; @@ -3,11 +17,11 @@ import java.util.List; -import net.sf.practicalxml.XmlException; - import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; +import net.sf.practicalxml.XmlException; + /** * An error handler that throws <code>XmlException</code> on any error, Modified: trunk/src/main/java/net/sf/practicalxml/util/NodeListIterable.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/util/NodeListIterable.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/util/NodeListIterable.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.util; import java.util.Iterator; Modified: trunk/src/main/java/net/sf/practicalxml/xpath/AbstractFunction.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/xpath/AbstractFunction.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/xpath/AbstractFunction.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.xpath; import java.util.Collections; Modified: trunk/src/main/java/net/sf/practicalxml/xpath/FunctionResolver.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/xpath/FunctionResolver.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/xpath/FunctionResolver.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.xpath; import java.util.HashMap; Modified: trunk/src/main/java/net/sf/practicalxml/xpath/NamespaceResolver.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/xpath/NamespaceResolver.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/xpath/NamespaceResolver.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.xpath; import java.util.ArrayList; Modified: trunk/src/main/java/net/sf/practicalxml/xpath/SimpleNamespaceResolver.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/xpath/SimpleNamespaceResolver.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/xpath/SimpleNamespaceResolver.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.xpath; import java.util.Arrays; Modified: trunk/src/main/java/net/sf/practicalxml/xpath/XPathWrapper.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/xpath/XPathWrapper.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/xpath/XPathWrapper.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.xpath; import java.util.HashMap; Modified: trunk/src/main/java/net/sf/practicalxml/xpath/function/Constants.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/xpath/function/Constants.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/xpath/function/Constants.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.xpath.function; /** Modified: trunk/src/main/java/net/sf/practicalxml/xpath/function/Lowercase.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/xpath/function/Lowercase.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/xpath/function/Lowercase.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.xpath.function; import org.w3c.dom.Node; Modified: trunk/src/main/java/net/sf/practicalxml/xpath/function/Uppercase.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/xpath/function/Uppercase.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/xpath/function/Uppercase.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.xpath.function; import org.w3c.dom.Node; Modified: trunk/src/main/java/net/sf/practicalxml/xpath/function/XsiBoolean.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/xpath/function/XsiBoolean.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/main/java/net/sf/practicalxml/xpath/function/XsiBoolean.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.xpath.function; import org.w3c.dom.Node; @@ -66,4 +80,4 @@ { return Boolean.FALSE; } -} \ No newline at end of file +} Added: trunk/src/main/resources/LICENSE.txt =================================================================== --- trunk/src/main/resources/LICENSE.txt (rev 0) +++ trunk/src/main/resources/LICENSE.txt 2009-01-02 13:19:54 UTC (rev 71) @@ -0,0 +1,202 @@ + + 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. Modified: trunk/src/test/java/net/sf/practicalxml/AbstractTestCase.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/AbstractTestCase.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/test/java/net/sf/practicalxml/AbstractTestCase.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml; import junit.framework.TestCase; Modified: trunk/src/test/java/net/sf/practicalxml/TestDomUtil.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/TestDomUtil.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/test/java/net/sf/practicalxml/TestDomUtil.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml; import java.util.List; Modified: trunk/src/test/java/net/sf/practicalxml/TestDomUtilGetPath.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/TestDomUtilGetPath.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/test/java/net/sf/practicalxml/TestDomUtilGetPath.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml; import javax.xml.namespace.NamespaceContext; Modified: trunk/src/test/java/net/sf/practicalxml/TestOutputUtil.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/TestOutputUtil.java 2008-12-30 14:08:10 UTC (rev 70) +++ trunk/src/test/java/net/sf/practicalxml/TestOutputUtil.java 2009-01-02 13:19:54 UTC (rev 71) @@ -1,3 +1,17 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 ... [truncated message content] |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-04-25 12:24:50
|
Revision: 76 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=76&view=rev Author: kdgregory Date: 2009-04-25 12:24:37 +0000 (Sat, 25 Apr 2009) Log Message: ----------- Add XmlUtil.escape, XmlUtil.unescape Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/XmlUtil.java trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-01-14 14:14:44 UTC (rev 75) +++ trunk/pom.xml 2009-04-25 12:24:37 UTC (rev 76) @@ -5,7 +5,7 @@ <groupId>net.sf.practicalxml</groupId> <artifactId>practicalxml</artifactId> <packaging>jar</packaging> - <version>1.0.0</version> + <version>1.0.1</version> <name>practicalxml</name> <url>http://sourceforge.net/projects/practicalxml/</url> Modified: trunk/src/main/java/net/sf/practicalxml/XmlUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/XmlUtil.java 2009-01-14 14:14:44 UTC (rev 75) +++ trunk/src/main/java/net/sf/practicalxml/XmlUtil.java 2009-04-25 12:24:37 UTC (rev 76) @@ -122,6 +122,95 @@ } + /** + * Escapes the passed string, converting the five reserved XML characters + * into their entities: &amp;, &lt;, &gt;, &apos;, and + * &quot;. If the string does not contain any of these characters, it + * will be returned unchanged. If passed <code>null</code>, returns an + * empty string. + * <p> + * Yes, this method is available elsewhere, eg Jakarta Commons. I'm trying + * to minimize external dependencies from this library, so am reinventing + * a few small wheels (but they're round!). + */ + public static String escape(String s) + { + if (s == null) + return ""; + + StringBuilder buf = new StringBuilder(s.length()); + boolean wasEscaped = false; + + for (int ii = 0 ; ii < s.length() ; ii++) + { + char c = s.charAt(ii); + switch (c) + { + case '&' : + buf.append("&"); + wasEscaped = true; + break; + case '<' : + buf.append("<"); + wasEscaped = true; + break; + case '>' : + buf.append(">"); + wasEscaped = true; + break; + case '\'' : + buf.append("'"); + wasEscaped = true; + break; + case '"' : + buf.append("""); + wasEscaped = true; + break; + default : + buf.append(c); + } + } + + return wasEscaped ? buf.toString() : s; + } + + + /** + * Unescapes the passed string, converting the five XML entities + * (&amp;, &lt;, &gt;, &apos;, and &quot;) into + * their correspinding characters. Also converts any numeric entities + * into their characters. If the string does not contain any convertable + * entities, it will be returned unchanged. If passed <code>null</code>, + * returns an empty string. + * <p> + * Yes, this method is available elsewhere, eg Jakarta Commons. + */ + public static String unescape(String s) + { + if (s == null) + return ""; + + StringBuilder buf = new StringBuilder(s.length() + 20); + boolean wasEscaped = false; + + for (int ii = 0 ; ii < s.length() ; ii++) + { + char c = s.charAt(ii); + switch (c) + { + case '&' : + ii = unescapeHelper(s, ii, buf); + wasEscaped = true; + break; + default : + buf.append(c); + } + } + + return wasEscaped ? buf.toString() : s; + } + + //---------------------------------------------------------------------------- // Internals //---------------------------------------------------------------------------- @@ -234,4 +323,125 @@ : "GMT"; cal.setTimeZone(TimeZone.getTimeZone(tz)); } + + + /** + * Attempts to recognize an entity in the passed string, appending the + * corresponding character to the passed buffer. If unable to recognize + * an entity, appends the current character (an ampersand) to the buffer. + * Returns the updated string index (position of the trailing semi-colon). + */ + private static int unescapeHelper(String s, int curPos, StringBuilder buf) + { + // the case of a malformed entity at the end of the string should be + // all but nonexistent in the real world, so rather than clutter the + // code with index tests, I'll just catch the exception + try + { + if (s.startsWith("&", curPos)) + { + buf.append("&"); + return curPos + 4; + } + else if (s.startsWith("'", curPos)) + { + buf.append("'"); + return curPos + 5; + } + else if (s.startsWith(""", curPos)) + { + buf.append('"'); + return curPos + 5; + } + else if (s.startsWith("<", curPos)) + { + buf.append("<"); + return curPos + 3; + } + else if (s.startsWith(">", curPos)) + { + buf.append(">"); + return curPos + 3; + } + else if (s.startsWith("&#", curPos)) + { + char c = numericEntityHelper(s, curPos); + if (c != '\0') + { + buf.append(c); + return s.indexOf(';', curPos); + } + } + } + catch (StringIndexOutOfBoundsException ignored) + { + // fall through to default handler + } + + // it's not an entity that we know how to process, so just copy the + // ampersand and let the rest of the string process + buf.append('&'); + return curPos; + } + + + /** + * Attempts to decode a numeric character entity starting at the current + * position within the string. If able, returns the corresponding character. + * If unable, returns NUL (which is disallowed by both XML 1.0 and XML 1.1). + * <p> + * Limited to + */ + private static char numericEntityHelper(String s, int curPos) + { + int value = 0; + + // caller has checked &#, so skip them + curPos += 2; + + boolean isHex = false; + int multiplier = 10; + if (s.charAt(curPos) == 'x') + { + isHex = true; + multiplier = 16; + curPos++; + } + + // XML is limited to Unicode plane 0, so 4 hex or 5 decimal digits + // ... don't index through entire string looking for semi-colon + for (int ii = 0 ; ii < 6 ; ii++) + { + char c = s.charAt(curPos + ii); + if (c == ';') + break; + int cVal = convertDigit(c, isHex); + if (cVal < 0) + return '\0'; + value = value * multiplier + cVal; + } + + if (value > 65535) + return '\0'; + + return (char)value; + } + + + // FIXME - refactor this into a common method + /** + * Verifies that the passed character is a digit, and converts it to its + * numeric value if yes. Returns -1 if not a legal digit. + */ + private static int convertDigit(char c, boolean allowHex) + { + if ((c >= '0') && (c <= '9')) + return c - '0'; + if (allowHex && (c >= 'a') && (c <= 'f')) + return c - 'a' + 10; + if (allowHex && (c >= 'A') && (c <= 'F')) + return c - 'A' + 10; + return -1; + } + } Modified: trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java 2009-01-14 14:14:44 UTC (rev 75) +++ trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java 2009-04-25 12:24:37 UTC (rev 76) @@ -75,4 +75,60 @@ assertEquals(expected.getTime(), XmlUtil.parseXsdDatetime("2004-10-28T09:10:11.123")); assertEquals(expected.getTime(), XmlUtil.parseXsdDatetime("2004-10-28T04:10:11.123-05:00")); } + + + public void testEscape() throws Exception + { + assertEquals("", XmlUtil.escape(null)); + assertEquals("", XmlUtil.escape("")); + + String s1 = new String("this has nothing to escape"); + assertSame(s1, XmlUtil.escape(s1)); + + assertEquals("this & <string> does "'", + XmlUtil.escape("this & <string> does \"'")); + } + + + public void testUnescape() throws Exception + { + assertEquals("", XmlUtil.unescape(null)); + assertEquals("", XmlUtil.unescape("")); + + String s1 = new String("this has nothing to escape"); + assertSame(s1, XmlUtil.unescape(s1)); + + assertEquals("this string'\"does<&>", + XmlUtil.unescape("this string'"does<&>")); + + assertEquals("this is an &unknown; entity", + XmlUtil.unescape("this is an &unknown; entity")); + } + + + public void testUnescapeWithInvalidNumericEntity() throws Exception + { + assertEquals("𘚟", + XmlUtil.unescape("𘚟")); + assertEquals("𒍅", + XmlUtil.unescape("𒍅")); + assertEquals("cAA;", + XmlUtil.unescape("cAA;")); + + assertEquals("&#;", + XmlUtil.unescape("&#;")); + + assertEquals("&#this is not really an entity", + XmlUtil.unescape("&#this is not really an entity")); + } + + + public void testUnescapeAtEndOfString() throws Exception + { + assertEquals("&", + XmlUtil.unescape("&")); + assertEquals("&am", + XmlUtil.unescape("&am")); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-09-14 23:30:53
|
Revision: 128 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=128&view=rev Author: kdgregory Date: 2009-09-14 23:30:45 +0000 (Mon, 14 Sep 2009) Log Message: ----------- DomAsserts: XPath assertions now take any node as initial context Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/junit/DomAsserts.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-09-11 18:30:39 UTC (rev 127) +++ trunk/pom.xml 2009-09-14 23:30:45 UTC (rev 128) @@ -5,7 +5,7 @@ <groupId>net.sf.practicalxml</groupId> <artifactId>practicalxml</artifactId> <packaging>jar</packaging> - <version>1.0.4</version> + <version>1.0.5-SNAPSHOT</version> <name>practicalxml</name> <url>http://sourceforge.net/projects/practicalxml/</url> Modified: trunk/src/main/java/net/sf/practicalxml/junit/DomAsserts.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/junit/DomAsserts.java 2009-09-11 18:30:39 UTC (rev 127) +++ trunk/src/main/java/net/sf/practicalxml/junit/DomAsserts.java 2009-09-14 23:30:45 UTC (rev 128) @@ -38,10 +38,10 @@ public class DomAsserts { /** - * Asserts that an element has the given name, ignoring namespace. + * Asserts that an element has the given localname. * - * @param expected The expected name. - * @param elem The element to assert. + * @param expected The expected name, sans prefix. + * @param elem The element on which to assert this name. */ public static void assertName(String expected, Element elem) { @@ -49,11 +49,11 @@ } /** - * Asserts that an element has the given name, ignoring namespace. + * Asserts that an element has the given localname. * * @param message Message to display if assertion fails. - * @param expected The expected name. - * @param elem The element to assert. + * @param expected The expected name, sans prefix. + * @param elem The element on which to assert this name. */ public static void assertName(String message, String expected, Element elem) { @@ -71,7 +71,7 @@ * </code> to assert that the element does not * have a namespace. * @param localName The expected name, sans prefix - * @param elem The element to assert. + * @param elem The element on which to assert this name. */ public static void assertNamespaceAndName( String expectedNSUri, String localName, Element elem) @@ -89,7 +89,7 @@ * </code> to assert that the element does not * have a namespace. * @param localName The expected name, sans prefix - * @param elem The element to assert. + * @param elem The element on which to assert this name. */ public static void assertNamespaceAndName( String message, String expectedNSUri, String localName, Element elem) @@ -100,189 +100,184 @@ /** - * Asserts that the specified XPath selects at least one node. - * <p> - * Will display the XPath if assertion fails. + * Asserts that the specified XPath selects at least one node. Uses the + * path as a failed-assertion message. * - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ - public static void assertExists(Element elem, String xpath) + public static void assertExists(Node node, String xpath) { - assertExists(xpath, elem, xpath); + assertExists(xpath, node, xpath); } /** - * Asserts that the specified XPath selects at least one node. + * Asserts that the specified XPath selects at least one node, using + * the specified message if the assertion fails. * - * @param message Message to display if assertion fails. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param message Message to display if assertion fails. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ - public static void assertExists(String message, Element elem, String xpath) + public static void assertExists(String message, Node node, String xpath) { - assertExists(message, elem, new XPathWrapper(xpath)); + assertExists(message, node, new XPathWrapper(xpath)); } /** - * Asserts that the specified XPath selects at least one node. Uses the - * <code>XPathWrapper</code> class to allow more complex paths, including - * namespace bindings. - * <p> - * Will display the XPath if assertion fails. + * Asserts that the specified XPath selects at least one node. Uses + * {@link net.sf.practicalxml.xpath.XPathWrapper} to allow complex + * paths, including namespace bindings. Uses the path as a failed- + * assertion message. * - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ - public static void assertExists(Element elem, XPathWrapper xpath) + public static void assertExists(Node node, XPathWrapper xpath) { - assertExists(xpath.toString(), elem, xpath); + assertExists(xpath.toString(), node, xpath); } /** - * Asserts that the specified XPath selects at least one node. Uses the - * <code>XPathWrapper</code> class to allow more complex paths, including - * namespace bindings. + * Asserts that the specified XPath selects at least one node. Uses + * {@link net.sf.practicalxml.xpath.XPathWrapper} to allow complex + * paths, including namespace bindings. * - * @param message Message to display if assertion fails. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param message Message to display if assertion fails. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ - public static void assertExists(String message, Element elem, XPathWrapper xpath) + public static void assertExists(String message, Node node, XPathWrapper xpath) { - List<Node> result = xpath.evaluate(elem); + List<Node> result = xpath.evaluate(node); assertTrue(message, result.size() > 0); } /** * Asserts that the specified XPath selects a specified number of nodes. - * <p> - * Will display the XPath if assertion fails. + * Uses the path as a failed-assertion message. * - * @param expected The expected number of nodes selected. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param expected The expected number of nodes selected. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ - public static void assertCount(int expected, Element elem, String xpath) + public static void assertCount(int expected, Node node, String xpath) { - assertCount(xpath, expected, elem, xpath); + assertCount(xpath, expected, node, xpath); } /** * Asserts that the specified XPath selects a specified number of nodes. * - * @param message Message to display if assertion fails. - * @param expected The expected number of nodes selected. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param message Message to display if assertion fails. + * @param expected The expected number of nodes selected. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ public static void assertCount( - String message, int expected, Element elem, String xpath) + String message, int expected, Node node, String xpath) { - assertCount(message, expected, elem, new XPathWrapper(xpath)); + assertCount(message, expected, node, new XPathWrapper(xpath)); } /** * Asserts that the specified XPath selects a specified number of nodes. - * Uses the <code>XPathWrapper</code> class to allow more complex paths, - * including namespace bindings. - * <p> - * Will display the XPath if assertion fails. + * Uses {@link net.sf.practicalxml.xpath.XPathWrapper} to allow complex + * paths, including namespace bindings. Uses the path as a failed-assertion + * message. * - * @param expected The expected number of nodes selected. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param expected The expected number of nodes selected. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ - public static void assertCount(int expected, Element elem, XPathWrapper xpath) + public static void assertCount(int expected, Node node, XPathWrapper xpath) { - assertCount(xpath.toString(), expected, elem, xpath); + assertCount(xpath.toString(), expected, node, xpath); } /** * Asserts that the specified XPath selects a specified number of nodes. - * Uses the <code>XPathWrapper</code> class to allow more complex paths, - * including namespace bindings. + * Uses {@link net.sf.practicalxml.xpath.XPathWrapper} to allow complex + * paths, including namespace bindings. * - * @param message Message to display if assertion fails. - * @param expected The expected number of nodes selected. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param message Message to display if assertion fails. + * @param expected The expected number of nodes selected. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ public static void assertCount( - String message, int expected, Element elem, XPathWrapper xpath) + String message, int expected, Node node, XPathWrapper xpath) { - List<Node> result = xpath.evaluate(elem); + List<Node> result = xpath.evaluate(node); Assert.assertEquals(message, expected, result.size()); } /** * Asserts that the specified XPath selects a particular String value. - * <p> - * Will display the XPath if assertion fails. + * Uses the path as a failed-assertion message. * - * @param expected The expected value. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param expected The expected value. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ - public static void assertEquals(String expected, Element elem, String xpath) + public static void assertEquals(String expected, Node node, String xpath) { - assertEquals(xpath, expected, elem, new XPathWrapper(xpath)); + assertEquals(xpath, expected, node, new XPathWrapper(xpath)); } /** * Asserts that the specified XPath selects a particular String value. * - * @param message Message to display if assertion fails. - * @param expected The expected value. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param message Message to display if assertion fails. + * @param expected The expected value. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ public static void assertEquals( - String message, String expected, Element elem, String xpath) + String message, String expected, Node node, String xpath) { - assertEquals(message, expected, elem, new XPathWrapper(xpath)); + assertEquals(message, expected, node, new XPathWrapper(xpath)); } /** * Asserts that the specified XPath selects a particular String value. - * This variant uses the <code>XPathWrapper</code> class to allow - * more complex paths, including namespace bindings. - * <p> - * Will display the XPath if assertion fails. + * This variant uses {@link net.sf.practicalxml.xpath.XPathWrapper} to + * allow complex paths, including namespace bindings. Uses the path as + * a failed-assertion message. * - * @param expected The expected value. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param expected The expected value. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ - public static void assertEquals(String expected, Element elem, XPathWrapper xpath) + public static void assertEquals(String expected, Node node, XPathWrapper xpath) { - assertEquals(xpath.toString(), expected, elem, xpath); + assertEquals(xpath.toString(), expected, node, xpath); } /** * Asserts that the specified XPath selects a particular String value. - * This variant uses the <code>XPathWrapper</code> class to allow - * more complex paths, including namespace bindings. + * This variant uses {@link net.sf.practicalxml.xpath.XPathWrapper} to + * allow complex paths, including namespace bindings. * - * @param message Message to display if assertion fails. - * @param expected The expected value. - * @param elem The element to serve as initial context. - * @param xpath The path expression. + * @param message Message to display if assertion fails. + * @param expected The expected value. + * @param node Initial context for expression evaluation. + * @param xpath Path expression to assert. */ public static void assertEquals( - String message, String expected, Element elem, XPathWrapper xpath) + String message, String expected, Node node, XPathWrapper xpath) { - Assert.assertEquals(message, expected, xpath.evaluateAsString(elem)); + Assert.assertEquals(message, expected, xpath.evaluateAsString(node)); } -} +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-09-15 18:37:16
|
Revision: 132 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=132&view=rev Author: kdgregory Date: 2009-09-15 18:37:09 +0000 (Tue, 15 Sep 2009) Log Message: ----------- add changelog report Modified Paths: -------------- trunk/pom.xml Added Paths: ----------- trunk/src/site/changes.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-09-15 00:56:23 UTC (rev 131) +++ trunk/pom.xml 2009-09-15 18:37:09 UTC (rev 132) @@ -82,11 +82,13 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> - <bottom> - <a href="http://sourceforge.net/projects/practicalxml/"> - <img src="http://sflogo.sourceforge.net/sflogo.php?group_id=234884&type=3"> + <bottom> + <a + href="http://sourceforge.net/projects/practicalxml/"> + <img + src="http://sflogo.sourceforge.net/sflogo.php?group_id=234884&type=3"> </a> - </bottom> + </bottom> </configuration> </plugin> <plugin> @@ -117,6 +119,20 @@ </executions> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-changes-plugin</artifactId> + <configuration> + <xmlPath>${basedir}/src/site/changes.xml</xmlPath> + </configuration> + <reportSets> + <reportSet> + <reports> + <report>changes-report</report> + </reports> + </reportSet> + </reportSets> + </plugin> </plugins> </reporting> Added: trunk/src/site/changes.xml =================================================================== --- trunk/src/site/changes.xml (rev 0) +++ trunk/src/site/changes.xml 2009-09-15 18:37:09 UTC (rev 132) @@ -0,0 +1,49 @@ +<document xmlns="http://maven.apache.org/changes/1.0.0"> + <properties> + <title>PracticalXML Change Log</title> + </properties> + + <body> + <release version="1.0.5" date="2009-09-15" + description="DomAsserts"> + <action dev='kdgregory' type='update'> + DomAsserts: XPath assertions now take any node as + initial context + </action> + </release> + + <release version="1.0.4" date="2009-09-10" + description="NodeListIterator"> + <action dev='kdgregory' type='add'> + NodeListIterator: wrapper for a NodeList that provides + full iterator functionality + </action> + </release> + + <release version="1.0.3" date="2009-07-14" description="XmlUtil"> + <action dev='kdgregory' type='add'> + XmlUtil: add formatXsdDecimal() + </action> + </release> + + <release version="1.0.2" date="2009-04-27" description="OutputUtil, XmlBuilder"> + <action dev='kdgregory' type='add'> + OutputUtil: added support for XMLReader as input source + </action> + <action dev='kdgregory' type='update'> + XmlBuilder: use SAX for text output; support PI nodes + </action> + </release> + + <release version="1.0.1" date="2009-04-25" description="XmlUtil"> + <action dev='kdgregory' type='add'> + XmlUtil: add .scape(), unescape() + </action> + <action /> + </release> + + <release version="1.0.0" date="2009-01-14" description="First production release"/> + </body> +</document> + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-11-23 14:47:25
|
Revision: 179 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=179&view=rev Author: kdgregory Date: 2009-11-23 14:34:08 +0000 (Mon, 23 Nov 2009) Log Message: ----------- merge 1.1-dev branch to trunk Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/OutputUtil.java trunk/src/main/java/net/sf/practicalxml/XmlUtil.java trunk/src/main/java/net/sf/practicalxml/converter/package.html trunk/src/main/java/net/sf/practicalxml/internal/package.html trunk/src/main/java/net/sf/practicalxml/junit/DomAsserts.java trunk/src/test/java/net/sf/practicalxml/AbstractTestCase.java trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java Added Paths: ----------- trunk/src/main/java/net/sf/practicalxml/converter/BeanConverter.java trunk/src/main/java/net/sf/practicalxml/converter/ConversionException.java trunk/src/main/java/net/sf/practicalxml/converter/JsonConverter.java trunk/src/main/java/net/sf/practicalxml/converter/bean/ trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlAppenders.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlConverter.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlOptions.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Introspection.java trunk/src/main/java/net/sf/practicalxml/converter/bean/IntrospectionCache.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Xml2BeanConverter.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Xml2BeanOptions.java trunk/src/main/java/net/sf/practicalxml/converter/bean/package.html trunk/src/main/java/net/sf/practicalxml/converter/internal/ trunk/src/main/java/net/sf/practicalxml/converter/internal/ConversionStrings.java trunk/src/main/java/net/sf/practicalxml/converter/internal/ConversionUtils.java trunk/src/main/java/net/sf/practicalxml/converter/internal/JavaConversionUtils.java trunk/src/main/java/net/sf/practicalxml/converter/internal/JsonUtils.java trunk/src/main/java/net/sf/practicalxml/converter/internal/TypeUtils.java trunk/src/main/java/net/sf/practicalxml/converter/json/ trunk/src/main/java/net/sf/practicalxml/converter/json/Json2XmlConverter.java trunk/src/main/java/net/sf/practicalxml/converter/json/Json2XmlOptions.java trunk/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonConverter.java trunk/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java trunk/src/main/java/net/sf/practicalxml/converter/json/package.html trunk/src/perftest/ trunk/src/perftest/java/ trunk/src/perftest/java/net/ trunk/src/perftest/java/net/sf/ trunk/src/perftest/java/net/sf/practicalxml/ trunk/src/perftest/java/net/sf/practicalxml/perftest/ trunk/src/perftest/java/net/sf/practicalxml/perftest/AbstractPerformanceTest.java trunk/src/perftest/java/net/sf/practicalxml/perftest/converter/ trunk/src/perftest/java/net/sf/practicalxml/perftest/converter/BeanExerciser.java trunk/src/perftest/java/net/sf/practicalxml/perftest/converter/JsonExerciser.java trunk/src/perftest/java/net/sf/practicalxml/perftest/package.html trunk/src/test/java/net/sf/practicalxml/converter/ trunk/src/test/java/net/sf/practicalxml/converter/AbstractConversionTestCase.java trunk/src/test/java/net/sf/practicalxml/converter/bean/ trunk/src/test/java/net/sf/practicalxml/converter/bean/AbstractBeanConverterTestCase.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestBean2XmlAppenders.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestBean2XmlConverter.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestBeanConverter.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestIntrospection.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestIntrospectionCache.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestXml2BeanConverter.java trunk/src/test/java/net/sf/practicalxml/converter/internal/ trunk/src/test/java/net/sf/practicalxml/converter/internal/TestJavaConversionUtils.java trunk/src/test/java/net/sf/practicalxml/converter/internal/TestJsonUtils.java trunk/src/test/java/net/sf/practicalxml/converter/internal/TestTypeUtils.java trunk/src/test/java/net/sf/practicalxml/converter/json/ trunk/src/test/java/net/sf/practicalxml/converter/json/TestJson2XmlConverter.java trunk/src/test/java/net/sf/practicalxml/converter/json/TestJsonConverter.java trunk/src/test/java/net/sf/practicalxml/converter/json/TestXml2JsonConverter.java Removed Paths: ------------- trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlAppenders.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlConverter.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlOptions.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Introspection.java trunk/src/main/java/net/sf/practicalxml/converter/bean/IntrospectionCache.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Xml2BeanConverter.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Xml2BeanOptions.java trunk/src/main/java/net/sf/practicalxml/converter/bean/package.html trunk/src/main/java/net/sf/practicalxml/converter/internal/ConversionStrings.java trunk/src/main/java/net/sf/practicalxml/converter/internal/ConversionUtils.java trunk/src/main/java/net/sf/practicalxml/converter/internal/JavaConversionUtils.java trunk/src/main/java/net/sf/practicalxml/converter/internal/JsonUtils.java trunk/src/main/java/net/sf/practicalxml/converter/internal/TypeUtils.java trunk/src/main/java/net/sf/practicalxml/converter/json/Json2XmlConverter.java trunk/src/main/java/net/sf/practicalxml/converter/json/Json2XmlOptions.java trunk/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonConverter.java trunk/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java trunk/src/main/java/net/sf/practicalxml/converter/json/package.html trunk/src/perftest/java/ trunk/src/perftest/java/net/ trunk/src/perftest/java/net/sf/ trunk/src/perftest/java/net/sf/practicalxml/ trunk/src/perftest/java/net/sf/practicalxml/perftest/ trunk/src/perftest/java/net/sf/practicalxml/perftest/AbstractPerformanceTest.java trunk/src/perftest/java/net/sf/practicalxml/perftest/converter/ trunk/src/perftest/java/net/sf/practicalxml/perftest/converter/BeanExerciser.java trunk/src/perftest/java/net/sf/practicalxml/perftest/converter/JsonExerciser.java trunk/src/perftest/java/net/sf/practicalxml/perftest/package.html trunk/src/test/java/net/sf/practicalxml/converter/AbstractConversionTestCase.java trunk/src/test/java/net/sf/practicalxml/converter/bean/ trunk/src/test/java/net/sf/practicalxml/converter/bean/AbstractBeanConverterTestCase.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestBean2XmlAppenders.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestBean2XmlConverter.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestBeanConverter.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestIntrospection.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestIntrospectionCache.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestXml2BeanConverter.java trunk/src/test/java/net/sf/practicalxml/converter/internal/ trunk/src/test/java/net/sf/practicalxml/converter/internal/TestJavaConversionUtils.java trunk/src/test/java/net/sf/practicalxml/converter/internal/TestJsonUtils.java trunk/src/test/java/net/sf/practicalxml/converter/internal/TestTypeUtils.java trunk/src/test/java/net/sf/practicalxml/converter/json/ trunk/src/test/java/net/sf/practicalxml/converter/json/TestJson2XmlConverter.java trunk/src/test/java/net/sf/practicalxml/converter/json/TestJsonConverter.java trunk/src/test/java/net/sf/practicalxml/converter/json/TestXml2JsonConverter.java Property Changed: ---------------- trunk/ Property changes on: trunk ___________________________________________________________________ Added: svn:mergeinfo + /trunk:128 |
From: Auto-Generated S. C. M. <pra...@li...> - 2010-01-07 23:33:04
|
Revision: 189 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=189&view=rev Author: kdgregory Date: 2010-01-07 23:32:52 +0000 (Thu, 07 Jan 2010) Log Message: ----------- DomUtil: add hasChildren(), hasElementChildren(), hasTextChildren() Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/DomUtil.java trunk/src/test/java/net/sf/practicalxml/TestDomUtil.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2010-04-19 19:40:28
|
Revision: 201 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=201&view=rev Author: kdgregory Date: 2010-04-19 19:40:21 +0000 (Mon, 19 Apr 2010) Log Message: ----------- DomUtil: add getAttributes(), getLocalName(Attr) Xml2BeanConverter: support conversion of attributes Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/DomUtil.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Xml2BeanConverter.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Xml2BeanOptions.java trunk/src/test/java/net/sf/practicalxml/TestDomUtil.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestXml2BeanConverter.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2010-11-18 12:50:36
|
Revision: 203 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=203&view=rev Author: kdgregory Date: 2010-11-18 12:50:30 +0000 (Thu, 18 Nov 2010) Log Message: ----------- bugfix: Introspector (bean conversion) was not ignoring invalid getter/setter methods Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/converter/bean/Introspection.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestIntrospection.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2012-08-02 01:14:35
|
Revision: 255 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=255&view=rev Author: kdgregory Date: 2012-08-02 01:14:29 +0000 (Thu, 02 Aug 2012) Log Message: ----------- fix dependency and re-release Modified Paths: -------------- trunk/pom.xml trunk/src/site/changes.xml This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2013-06-15 13:19:23
|
Revision: 265 http://sourceforge.net/p/practicalxml/code/265 Author: kdgregory Date: 2013-06-15 13:19:22 +0000 (Sat, 15 Jun 2013) Log Message: ----------- post-release Modified Paths: -------------- trunk/pom.xml trunk/src/site/changes.xml This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2013-11-15 12:51:51
|
Revision: 291 http://sourceforge.net/p/practicalxml/code/291 Author: kdgregory Date: 2013-11-15 12:51:48 +0000 (Fri, 15 Nov 2013) Log Message: ----------- Bean2XmlConverter: support conversion of byte arrays to base64- and hex-encoded strings Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlAppenders.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlConverter.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlOptions.java trunk/src/main/java/net/sf/practicalxml/converter/internal/TypeUtils.java trunk/src/site/changes.xml trunk/src/test/java/net/sf/practicalxml/converter/bean/TestBean2XmlConverter.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-04-25 13:17:39
|
Revision: 77 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=77&view=rev Author: kdgregory Date: 2009-04-25 13:17:38 +0000 (Sat, 25 Apr 2009) Log Message: ----------- Add "internal" package Remove dependency on Jakarta Commons lang Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/DomUtil.java trunk/src/main/java/net/sf/practicalxml/XmlUtil.java Added Paths: ----------- trunk/src/main/java/net/sf/practicalxml/internal/ trunk/src/main/java/net/sf/practicalxml/internal/StringUtils.java trunk/src/main/java/net/sf/practicalxml/internal/package.html trunk/src/test/java/net/sf/practicalxml/internal/ trunk/src/test/java/net/sf/practicalxml/internal/TestStringUtils.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-04-25 12:24:37 UTC (rev 76) +++ trunk/pom.xml 2009-04-25 13:17:38 UTC (rev 77) @@ -122,11 +122,6 @@ <dependencies> <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.2</version> Modified: trunk/src/main/java/net/sf/practicalxml/DomUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/DomUtil.java 2009-04-25 12:24:37 UTC (rev 76) +++ trunk/src/main/java/net/sf/practicalxml/DomUtil.java 2009-04-25 13:17:38 UTC (rev 77) @@ -27,11 +27,10 @@ import org.w3c.dom.NodeList; import org.w3c.dom.Text; +import net.sf.practicalxml.internal.StringUtils; import net.sf.practicalxml.xpath.NamespaceResolver; -import org.apache.commons.lang.StringUtils; - /** * A collection of static utility methods for working with DOM trees. * Most of these are usability workarounds for the <code>org.w3c.dom</code> Modified: trunk/src/main/java/net/sf/practicalxml/XmlUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/XmlUtil.java 2009-04-25 12:24:37 UTC (rev 76) +++ trunk/src/main/java/net/sf/practicalxml/XmlUtil.java 2009-04-25 13:17:38 UTC (rev 77) @@ -21,7 +21,9 @@ import java.util.GregorianCalendar; import java.util.TimeZone; +import net.sf.practicalxml.internal.StringUtils; + /** * A collection of static methods for manipulating XML as text. */ @@ -399,11 +401,9 @@ // caller has checked &#, so skip them curPos += 2; - boolean isHex = false; int multiplier = 10; if (s.charAt(curPos) == 'x') { - isHex = true; multiplier = 16; curPos++; } @@ -415,7 +415,7 @@ char c = s.charAt(curPos + ii); if (c == ';') break; - int cVal = convertDigit(c, isHex); + int cVal = StringUtils.parseDigit(c, multiplier); if (cVal < 0) return '\0'; value = value * multiplier + cVal; @@ -426,22 +426,4 @@ return (char)value; } - - - // FIXME - refactor this into a common method - /** - * Verifies that the passed character is a digit, and converts it to its - * numeric value if yes. Returns -1 if not a legal digit. - */ - private static int convertDigit(char c, boolean allowHex) - { - if ((c >= '0') && (c <= '9')) - return c - '0'; - if (allowHex && (c >= 'a') && (c <= 'f')) - return c - 'a' + 10; - if (allowHex && (c >= 'A') && (c <= 'F')) - return c - 'A' + 10; - return -1; - } - } Added: trunk/src/main/java/net/sf/practicalxml/internal/StringUtils.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/internal/StringUtils.java (rev 0) +++ trunk/src/main/java/net/sf/practicalxml/internal/StringUtils.java 2009-04-25 13:17:38 UTC (rev 77) @@ -0,0 +1,108 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.internal; + + +/** + * Static methods for working with strings and characters. This class exists + * primarily to break dependency on Jakarta Commons. + */ +public class StringUtils +{ + /** + * Returns true if the passed string is null or zero-length; false + * otherwise (including a string containing only whitespace). This + * is a replacement for the Jakarta Commons method with the same + * name. + */ + public static boolean isEmpty(String s) + { + return (s == null) || (s.length() == 0); + } + + + /** + * Returns true if the passed string is null, zero-length, or contains + * only whitespace characters as defined by Character.isWhitespace(); + * false otherwise. This is a replacement for the Jakarta Commons method + * with the same name. + */ + public static boolean isBlank(String s) + { + if ((s == null) || (s.length() == 0)) + return true; + + for (int ii = 0 ; ii < s.length() ; ii++) + { + if (!Character.isWhitespace(s.charAt(ii))) + return false; + } + + return true; + } + + + /** + * Trims all whitespace characters (as defined by Character.isWhitespace()) + * from both ends of the string, returning an empty string if there's + * nothing left. Will also return an empty string if passed null. This is a + * replacement for the Jakarta Commons method with the same name. + */ + public static String trimToEmpty(String s) + { + if ((s == null) || (s.length() == 0)) + return ""; + + int i0 = 0; + int i1 = s.length() - 1; + while (i0 <= i1) + { + if (Character.isWhitespace(s.charAt(i0))) + i0++; + else if (Character.isWhitespace(s.charAt(i1))) + i1--; + else + return s.substring(i0, i1 + 1); + } + + return ""; + } + + + /** + * Parses the passed character as a digit in the specified base, + * returning its value. Bases > 10 are represented by ASCII letters + * in the range A to Z (or a to z). Base 36 is the largest supported. + * + * @return The value, or -1 if the character is not a valid digit + * in the specified base (this method will typically be used + * in a loop, so no good reason to force exception checking). + */ + public static int parseDigit(char c, int base) + { + int value = -1; + if ((c >= '0') && (c <= '9')) + value = c - '0'; + else if ((c >= 'a') && (c <= 'z')) + value = c - 'a' + 10; + else if ((c >= 'A') && (c <= 'Z')) + value = c - 'A' + 10; + + if (value >= base) + value = -1; + return value; + } + +} Added: trunk/src/main/java/net/sf/practicalxml/internal/package.html =================================================================== --- trunk/src/main/java/net/sf/practicalxml/internal/package.html (rev 0) +++ trunk/src/main/java/net/sf/practicalxml/internal/package.html 2009-04-25 13:17:38 UTC (rev 77) @@ -0,0 +1,4 @@ +This package contains classes used internally by the PracticalXML library. +Applications should not rely on the API of these classes, or indeed of their +continued existence. In most cases, there's a better alternative in a third- +party library. \ No newline at end of file Added: trunk/src/test/java/net/sf/practicalxml/internal/TestStringUtils.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/internal/TestStringUtils.java (rev 0) +++ trunk/src/test/java/net/sf/practicalxml/internal/TestStringUtils.java 2009-04-25 13:17:38 UTC (rev 77) @@ -0,0 +1,77 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.internal; + +import junit.framework.TestCase; + + +public class TestStringUtils extends TestCase +{ + public void testIsEmpty() throws Exception + { + assertTrue(StringUtils.isEmpty(null)); + assertTrue(StringUtils.isEmpty("")); + + assertFalse(StringUtils.isEmpty("A")); + assertFalse(StringUtils.isEmpty(" ")); + } + + + public void testIsBlank() throws Exception + { + assertTrue(StringUtils.isBlank(null)); + assertTrue(StringUtils.isBlank("")); + assertTrue(StringUtils.isBlank(" ")); + assertTrue(StringUtils.isBlank(" \n ")); + + assertFalse(StringUtils.isBlank("A")); + assertFalse(StringUtils.isBlank(" A ")); + assertFalse(StringUtils.isBlank("\u00A0")); + } + + + public void testTrimToEmpty() throws Exception + { + assertEquals("", StringUtils.trimToEmpty(null)); + assertEquals("", StringUtils.trimToEmpty("")); + assertEquals("", StringUtils.trimToEmpty(" \n \t ")); + + assertEquals("A", StringUtils.trimToEmpty(" A\n ")); + assertEquals("AB", StringUtils.trimToEmpty(" AB\n ")); + assertEquals("\u00A0", StringUtils.trimToEmpty("\u00A0")); + } + + + public void testParseDigit() throws Exception + { + assertEquals(0, StringUtils.parseDigit('0', 10)); + assertEquals(9, StringUtils.parseDigit('9', 10)); + assertEquals(-1, StringUtils.parseDigit('A', 10)); + + assertEquals(0, StringUtils.parseDigit('0', 16)); + assertEquals(9, StringUtils.parseDigit('9', 16)); + assertEquals(10, StringUtils.parseDigit('A', 16)); + assertEquals(15, StringUtils.parseDigit('F', 16)); + assertEquals(-1, StringUtils.parseDigit('G', 16)); + assertEquals(10, StringUtils.parseDigit('a', 16)); + assertEquals(15, StringUtils.parseDigit('f', 16)); + assertEquals(-1, StringUtils.parseDigit('g', 16)); + + assertEquals(35, StringUtils.parseDigit('Z', 36)); + assertEquals(35, StringUtils.parseDigit('z', 36)); + + assertEquals(-1, StringUtils.parseDigit('!', 100)); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-04-27 12:41:56
|
Revision: 79 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=79&view=rev Author: kdgregory Date: 2009-04-27 12:41:46 +0000 (Mon, 27 Apr 2009) Log Message: ----------- OutputUtil: added support for XMLReader as input source XmlBuilder: use SAX for output (lowers footprint, discards comments) support Processing Instruction nodes (not that anyone uses them) added better package comment Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/OutputUtil.java trunk/src/main/java/net/sf/practicalxml/builder/AttributeNode.java trunk/src/main/java/net/sf/practicalxml/builder/CommentNode.java trunk/src/main/java/net/sf/practicalxml/builder/ElementNode.java trunk/src/main/java/net/sf/practicalxml/builder/Node.java trunk/src/main/java/net/sf/practicalxml/builder/TextNode.java trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilder.java trunk/src/main/java/net/sf/practicalxml/builder/package.html trunk/src/test/java/net/sf/practicalxml/TestOutputUtil.java trunk/src/test/java/net/sf/practicalxml/builder/TestXmlBuilder.java Added Paths: ----------- trunk/src/main/java/net/sf/practicalxml/builder/PINode.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/pom.xml 2009-04-27 12:41:46 UTC (rev 79) @@ -5,7 +5,7 @@ <groupId>net.sf.practicalxml</groupId> <artifactId>practicalxml</artifactId> <packaging>jar</packaging> - <version>1.0.1</version> + <version>1.0.2</version> <name>practicalxml</name> <url>http://sourceforge.net/projects/practicalxml/</url> Modified: trunk/src/main/java/net/sf/practicalxml/OutputUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/OutputUtil.java 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/main/java/net/sf/practicalxml/OutputUtil.java 2009-04-27 12:41:46 UTC (rev 79) @@ -25,10 +25,12 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.xml.sax.XMLReader; /** @@ -42,7 +44,8 @@ /** * A simple <code>toString()</code> for an element, using the format * "<code>{<i>NSURI</i>}<i>LOCALNAME</i></code>"; if the element has no - * namespace, the brackets remain but are empty. + * namespace, the brackets remain but are empty. This is typically used + * for debugging. */ public static String elementToString(Element elem) { @@ -51,12 +54,8 @@ /** - * Debug dump of the tree rooted at the specified element. Each line holds - * one element, - * - * - * @param elem - * @param indent + * Debug dump of the e rooted at the specified element. Each line holds + * one element, and elements are formatted per {@link #elementToString}. */ public static String treeToString(Element elem, int indent) { @@ -68,7 +67,6 @@ * Writes a DOM document to a simple string format, without a prologue or * whitespace between elements. * <p> - * * Do not simply write this string to a file unless you use UTF-8 encoding * or attach a prologue that specifies your actual encoding. * @@ -84,10 +82,38 @@ /** + * Writes XML in a simple string format, without prologue or whitespace + * between elements, using the passed <code>XMLReader</code> to generate + * a stream of SAX events. + * <p> + * The transformer will call the reader's <code>setContentHandler()</code> + * method, followed by <code>parse()</code>. In the latter method, the + * reader must invoke the content handler's event methods in the correct + * order: at the very least, <code>startDocument() </code>, followed by + * <code>startElement()</code> and <code>endElement()</code> for the root + * element, finishing with <code>endDocument()</code>. Note that SAX does + * not support all DOM node types: in particular, there are no comments. + * <p> + * Do not simply write this string to a file unless you use UTF-8 encoding + * or attach a prologue that specifies your actual encoding. + * + * @param reader Provides a source of SAX events for the transformer. + */ + public static String compactString(XMLReader reader) + { + StringWriter out = new StringWriter(); + new TransformHelper() + .transform(new SAXSource(reader, null), new StreamResult(out)); + return out.toString(); + } + + + /** * Writes a DOM document to a string format, with indenting between - * elements but without a prologue. Do not simply write this string - * to a file unless you use UTF-8 encoding or attach a prologue that - * specifies the encoding. + * elements but without a prologue. + * <p> + * Do not simply write this string to a file unless you use UTF-8 encoding + * or attach a prologue that specifies the encoding. * * @param dom The DOM tree to be output. * @param indentSize The number of spaces to indent each level of the @@ -110,9 +136,45 @@ /** - * Writes a DOM document to a stream, without a prologue or whitespace - * between elements, and using UTF-8 encoding. + * Writes XML in a simple string format, without prologue or whitespace + * between elements, using the passed <code>XMLReader</code> to generate + * a stream of SAX events. + * <p> + * The transformer will call the reader's <code>setContentHandler()</code> + * method, followed by <code>parse()</code>. In the latter method, the + * reader must invoke the content handler's event methods in the correct + * order: at the very least, <code>startDocument() </code>, followed by + * <code>startElement()</code> and <code>endElement()</code> for the root + * element, finishing with <code>endDocument()</code>. Note that SAX does + * not support all DOM node types: in particular, there are no comments. + * <p> + * Do not simply write this string to a file unless you use UTF-8 encoding + * or attach a prologue that specifies the encoding. * + * @param reader Provides a source of SAX events for the transformer. + * @param indentSize The number of spaces to indent each level of the + * tree. Indentation is <em>best effort</em>: the + * <code>javax.transform</code> API does not provide + * any way to set indent level, so we use JDK-specific + * features to achieve this, <em>where available</em>. + * Note also that indenting will cause problems with + * elements that contain mixed content, particularly + * if the text elements cannot be trimmed. + */ + public static String indentedString(XMLReader reader, int indentSize) + { + StringWriter out = new StringWriter(); + new TransformHelper() + .setIndent(indentSize) + .transform(new SAXSource(reader, null), new StreamResult(out)); + return out.toString(); + } + + + /** + * Writes a DOM document to a stream using UTF-8 encoding, without a prologue + * or whitespace between elements. + * * @param dom The DOM tree to be output. * @param stream The output stream. This stream will be flushed by * this method, but will <em>not</em> be closed. @@ -126,6 +188,31 @@ /** + * Writes XML to a stream using UTF-8 encoding, without prologue or + * whitespace between elements, using the passed <code>XMLReader</code> + * to generate a stream of SAX events. + * <p> + * The transformer will call the reader's <code>setContentHandler()</code> + * method, followed by <code>parse()</code>. In the latter method, the + * reader must invoke the content handler's event methods in the correct + * order: at the very least, <code>startDocument() </code>, followed by + * <code>startElement()</code> and <code>endElement()</code> for the root + * element, finishing with <code>endDocument()</code>. Note that SAX does + * not support all DOM node types: in particular, there are no comments. + * + * @param reader Provides a source of SAX events for the transformer. + * @param stream The output stream. This stream will be flushed by + * this method, but will <em>not</em> be closed. + */ + public static void compactStream(XMLReader reader, OutputStream stream) + { + new TransformHelper() + .transform(new SAXSource(reader, null), new StreamResult(stream)); + flushStream(stream); + } + + + /** * Writes a DOM document to a stream using the specified encoding, without * whitespace between elements, but <em>with</em> a prologue that specifes * the encoding. @@ -144,6 +231,32 @@ /** + * Writes XML to a stream using the specified encoding, without prologue or + * whitespace between elements, using the passed <code>XMLReader</code> + * to generate a stream of SAX events. + * <p> + * The transformer will call the reader's <code>setContentHandler()</code> + * method, followed by <code>parse()</code>. In the latter method, the + * reader must invoke the content handler's event methods in the correct + * order: at the very least, <code>startDocument() </code>, followed by + * <code>startElement()</code> and <code>endElement()</code> for the root + * element, finishing with <code>endDocument()</code>. Note that SAX does + * not support all DOM node types: in particular, there are no comments. + * + * @param reader Provides a source of SAX events for the transformer. + * @param stream The output stream. This stream will be flushed by + * this method, but will <em>not</em> be closed. + */ + public static void compactStream(XMLReader reader, OutputStream stream, String encoding) + { + new TransformHelper() + .setPrologue(encoding) + .transform(new SAXSource(reader, null), new StreamResult(stream)); + flushStream(stream); + } + + + /** * This object does the actual transformation work; the exposed static * methods create and configure an instance to do their job. If you * need finer control over output, you can do the same: call the various Modified: trunk/src/main/java/net/sf/practicalxml/builder/AttributeNode.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/AttributeNode.java 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/main/java/net/sf/practicalxml/builder/AttributeNode.java 2009-04-27 12:41:46 UTC (rev 79) @@ -15,6 +15,7 @@ package net.sf.practicalxml.builder; import org.w3c.dom.Element; +import org.xml.sax.helpers.AttributesImpl; /** @@ -24,16 +25,18 @@ extends Node implements java.io.Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; private String _nsUri; private String _qname; + private String _lclName; private String _value; public AttributeNode(String nsUri, String qname, String value) { _nsUri = nsUri; _qname = qname; + _lclName = getLocalName(qname); _value = value; } @@ -46,4 +49,14 @@ else parent.setAttributeNS(_nsUri, _qname, _value); } + + + /** + * Helper method to produce a SAX <code>Attributes</code> object. This + * is called by ElementNode. + */ + protected void appendToAttributes(AttributesImpl attrs) + { + attrs.addAttribute(_nsUri, _lclName, _qname, "", _value); + } } Modified: trunk/src/main/java/net/sf/practicalxml/builder/CommentNode.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/CommentNode.java 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/main/java/net/sf/practicalxml/builder/CommentNode.java 2009-04-27 12:41:46 UTC (rev 79) @@ -18,6 +18,9 @@ import org.w3c.dom.Element; +/** + * Holds a comment. + */ public class CommentNode extends Node { Modified: trunk/src/main/java/net/sf/practicalxml/builder/ElementNode.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/ElementNode.java 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/main/java/net/sf/practicalxml/builder/ElementNode.java 2009-04-27 12:41:46 UTC (rev 79) @@ -14,71 +14,130 @@ package net.sf.practicalxml.builder; +import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; +import org.xml.sax.helpers.XMLFilterImpl; import net.sf.practicalxml.DomUtil; import net.sf.practicalxml.OutputUtil; +/** + * The primary class for building XML trees and converting them to different + * JAXP-centric forms. Callers should not create instances of this class + * directly; instead use the static factory methods in {@link XmlBuilder}. + */ public final class ElementNode extends Node { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; - private String _nsUri; - private String _qname; - private List<Node> _children; + private String _nsUri; + private String _qname; + private String _lclName; + private List<AttributeNode> _attribs = new ArrayList<AttributeNode>(); + private List<Node> _children = new ArrayList<Node>(); + ElementNode(String nsUri, String qname, Node... children) { _nsUri = nsUri; _qname = qname; - _children = new ArrayList<Node>(Arrays.asList(children)); + _lclName = getLocalName(qname); + for (Node child : children) + addChild(child); } /** - * Adds a child node -- of any type -- to this element. + * Adds a child node -- of any type -- to this element. Returns this as + * a convenience to caller, allowing calls to be chained. */ public ElementNode addChild(Node child) { - if (child != null) + if (child instanceof AttributeNode) + _attribs.add((AttributeNode)child); + else if (child != null) _children.add(child); return this; } /** + * Generates a new DOM document with this element as the root. + */ + public Document toDOM() + { + Element root = DomUtil.newDocument(_nsUri, _qname); + appendChildren(root); + return root.getOwnerDocument(); + } + + + /** + * Invokes the passed <code>ContentHandler</code> for this element + * and its children. + */ + @Override + protected void toSAX(ContentHandler handler) + throws SAXException + { + handler.startElement(_nsUri, _lclName, _qname, getAttributes()); + for (Node child : _children) + { + child.toSAX(handler); + } + handler.endElement(_nsUri, _lclName, _qname); + } + + + /** * Generates an XML string, where this node is the root element. Does - * not insert whitespace between elements. + * not insert whitespace between elements. Note that you <em>must</em> + * use UTF-8 encoding or add a prologue that specifies encoding when + * writing this string to a stream. * <p> - * If you write this string to a file, you <em>must</em> use UTF-8 - * encoding or attach a prologue that specifies the encoding used. + * <em>Warning:</em> + * This method uses a SAX transformer, to minimize footprint. However, + * SAX does not support comment modes, so they will be silently dropped. + * If they are important to you, call {@link #toDOM} and use {@link + * net.sf.practicalxml.OutputUtil#compactString} to generate output. */ @Override public String toString() { - return OutputUtil.compactString(toDOM()); + return OutputUtil.compactString(new SerializationHelper()); } /** * Generates an XML string, where this node is the root element. Inserts - * whitespace between nodes, with the specified indent size. + * whitespace between nodes, along with newlines and the specified indent + * between elements. * <p> * This is the best choice for writing log output. If you write this string * to a stream, you <em>must</em> use UTF-8 encoding or attach a prologue * that specifies the encoding used. + * <p> + * <em>Warning:</em> + * This method uses a SAX transformer, to minimize footprint. However, + * SAX does not support comment modes, so they will be silently dropped. + * If they are important to you, call {@link #toDOM} and use {@link + * net.sf.practicalxml.OutputUtil#indentedString} to generate output. */ public String toString(int indentSize) { - return OutputUtil.indentedString(toDOM(), indentSize); + return OutputUtil.indentedString(new SerializationHelper(), indentSize); } @@ -88,10 +147,16 @@ * <p> * This is the best choice for writing XML that will be read by another * party. + * <p> + * <em>Warning:</em> + * This method uses a SAX transformer, to minimize footprint. However, + * SAX does not support comment modes, so they will be silently dropped. + * If they are important to you, call {@link #toDOM} and use {@link + * net.sf.practicalxml.OutputUtil#compactStream} to generate output. */ public void toStream(OutputStream out) { - OutputUtil.compactStream(toDOM(), out); + OutputUtil.compactStream(new SerializationHelper(), out); } @@ -99,6 +164,12 @@ * Writes the tree rooted at this element to an <code>OutputStream</code>, * using a specified encoding, without a prologue or whitepspace between * nodes. + * <p> + * <em>Warning:</em> + * This method uses a SAX transformer, to minimize footprint. However, + * SAX does not support comment modes, so they will be silently dropped. + * If they are important to you, call {@link #toDOM} and use {@link + * net.sf.practicalxml.OutputUtil#compactStream} to generate output. */ public void toStream(OutputStream out, String encoding) { @@ -106,27 +177,51 @@ } - /** - * Generates a new DOM document, with this element as the root. - */ - public Document toDOM() +//---------------------------------------------------------------------------- +// Internals +//---------------------------------------------------------------------------- + + @Override + protected void appendToElement(Element parent) { - Element root = DomUtil.newDocument(_nsUri, _qname); + appendChildren(DomUtil.appendChild(parent, _nsUri, _qname)); + } + + + private void appendChildren(Element elem) + { + for (Node child : _attribs) + { + child.appendToElement(elem); + } for (Node child : _children) { - child.appendToElement(root); + child.appendToElement(elem); } - return root.getOwnerDocument(); } - @Override - protected void appendToElement(Element parent) + private Attributes getAttributes() { - Element elem = DomUtil.appendChild(parent, _nsUri, _qname); - for (Node child : _children) + AttributesImpl result = new AttributesImpl(); + for (AttributeNode attr : _attribs) { - child.appendToElement(elem); + attr.appendToAttributes(result); } + return result; } + + + private class SerializationHelper + extends XMLFilterImpl + { + @Override + public void parse(InputSource input) + throws SAXException, IOException + { + startDocument(); + toSAX(getContentHandler()); + endDocument(); + } + } } Modified: trunk/src/main/java/net/sf/practicalxml/builder/Node.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/Node.java 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/main/java/net/sf/practicalxml/builder/Node.java 2009-04-27 12:41:46 UTC (rev 79) @@ -15,6 +15,8 @@ package net.sf.practicalxml.builder; import org.w3c.dom.Element; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; /** @@ -23,15 +25,40 @@ * are immutable, and require their parent to provide context (ie, no back- * pointers). * <p> - * <code>Node</code> is defined as an abstract class because all methods are - * internal. Only <code>ElementNode</code> should define public methods. + * <code>Node</code> is defined as an abstract class (rather than an interface) + * to allow declaration of protected methods and to provide helper methods. */ public abstract class Node implements java.io.Serializable { /** * This method is called internally by {@link ElementNode}, to append - * its children. + * its children to the DOM subtree rooted at the specified element. */ protected abstract void appendToElement(Element elem); + + + /** + * Invokes the passed <code>ContentHandler</code> for this element + * and its children. Default implementation does nothing (appropriate + * for attributes only). + */ + protected void toSAX(ContentHandler handler) + throws SAXException + { + // nothing happening here ... but almost everyone should override + } + + + /** + * Utility method to return a local name from either a qualified or + * non-qualified name. + */ + protected static String getLocalName(String qname) + { + int sepIdx = qname.indexOf(':'); + return (sepIdx < 0) + ? qname + : qname.substring(sepIdx + 1); + } } Added: trunk/src/main/java/net/sf/practicalxml/builder/PINode.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/PINode.java (rev 0) +++ trunk/src/main/java/net/sf/practicalxml/builder/PINode.java 2009-04-27 12:41:46 UTC (rev 79) @@ -0,0 +1,54 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.builder; + +import org.w3c.dom.Element; +import org.w3c.dom.ProcessingInstruction; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + + +/** + * Holds a processing instruction. + */ +public class PINode extends Node +{ + private static final long serialVersionUID = 1L; + + private String _target; + private String _data; + + public PINode(String target, String data) + { + _target = target; + _data = data; + } + + + @Override + protected void appendToElement(Element parent) + { + ProcessingInstruction pi = parent.getOwnerDocument() + .createProcessingInstruction(_target, _data); + parent.appendChild(pi); + } + + + @Override + protected void toSAX(ContentHandler handler) throws SAXException + { + handler.processingInstruction(_target, _data); + } +} Modified: trunk/src/main/java/net/sf/practicalxml/builder/TextNode.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/TextNode.java 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/main/java/net/sf/practicalxml/builder/TextNode.java 2009-04-27 12:41:46 UTC (rev 79) @@ -15,10 +15,16 @@ package net.sf.practicalxml.builder; import org.w3c.dom.Element; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; import net.sf.practicalxml.DomUtil; +/** + * Holds element content. Will be converted to DOM as <code>Text</code> + * (not <code>CDATASection</code>). + */ public class TextNode extends Node { private static final long serialVersionUID = 1L; @@ -36,4 +42,11 @@ { DomUtil.appendText(parent, _content); } + + + @Override + protected void toSAX(ContentHandler handler) throws SAXException + { + handler.characters(_content.toCharArray(), 0, _content.length()); + } } Modified: trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilder.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilder.java 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/main/java/net/sf/practicalxml/builder/XmlBuilder.java 2009-04-27 12:41:46 UTC (rev 79) @@ -96,9 +96,22 @@ /** * Creates a comment node. + * <p> + * <em>Warning</em>: + * Comment nodes are not reported by SAX sources. If comments are + * important to you, convert to DOM before serialization. */ public static Node comment(String text) { return new CommentNode(text); } + + + /** + * Creates a processing instruction node. + */ + public static Node processingInstruction(String target, String data) + { + return new PINode(target, data); + } } Modified: trunk/src/main/java/net/sf/practicalxml/builder/package.html =================================================================== --- trunk/src/main/java/net/sf/practicalxml/builder/package.html 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/main/java/net/sf/practicalxml/builder/package.html 2009-04-27 12:41:46 UTC (rev 79) @@ -1,5 +1,31 @@ <html> <body> - This package contains a tool for declarative creation of XML documents. + <code>XmlBuilder</code> is a tool for declarative construction of XML. + It was originally created to generate XML for unit tests, but is useful + wherever you want to construct XML documents with minimal code and a + low memory footprint. + <p> + The two classes of interest are {@link net.sf.practicalxml.builder.ElementNode} + and {@link net.sf.practicalxml.builder.XmlBuilder}: the former contains public + methods for transforming a tree into various representations, while the latter + contains static methods for building such a tree: + + <pre> + import static net.sf.practicalxml.builder.XmlBuilder.*; + + // ... + + ElementNode root = + element("root", + element("child1", + text("this is some <text>")), + element("child2", + attribute("foo", "bar"), + attribute("baz", "biff")), + element("http::www.example.com/foo", "ns:child3")); + + Document dom = root.toDOM(); + String out = root.toString(); + </pre> </body> </html> \ No newline at end of file Modified: trunk/src/test/java/net/sf/practicalxml/TestOutputUtil.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/TestOutputUtil.java 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/test/java/net/sf/practicalxml/TestOutputUtil.java 2009-04-27 12:41:46 UTC (rev 79) @@ -15,7 +15,13 @@ package net.sf.practicalxml; import java.io.ByteArrayOutputStream; +import java.io.IOException; + import org.w3c.dom.Element; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLFilterImpl; public class TestOutputUtil @@ -44,6 +50,33 @@ public final static String SOME_TEXT = "blah"; + /** + * An XMLReader that emits a specified series of nested tags. + */ + private static class MyXMLReader + extends XMLFilterImpl + { + private String[] _elems; + + public MyXMLReader(String... elems) + { + _elems = elems; + } + + @Override + public void parse(InputSource input) + throws SAXException, IOException + { + getContentHandler().startDocument(); + for (int ii = 0 ; ii < _elems.length ; ii++) + getContentHandler().startElement(null, _elems[ii], _elems[ii], null); + for (int ii = _elems.length -1 ; ii >= 0 ; ii--) + getContentHandler().endElement(null, _elems[ii], _elems[ii]); + getContentHandler().endDocument(); + } + } + + //---------------------------------------------------------------------------- // Test Cases -- in most of these tests we look for overall structure, assume // that the output transform will do the right thing @@ -69,7 +102,7 @@ } - public void testCompactStringSingleElement() throws Exception + public void testCompactStringSingleElementDOM() throws Exception { Element root = DomUtil.newDocument(EL_ROOT); @@ -78,7 +111,7 @@ } - public void testCompactStringParentChild() throws Exception + public void testCompactStringParentChildDOM() throws Exception { Element root = DomUtil.newDocument(EL_ROOT); DomUtil.appendChild(root, EL_CHILD); @@ -88,6 +121,22 @@ } + public void testCompactStringSingleElementSAX() throws Exception + { + XMLReader reader = new MyXMLReader(EL_ROOT); + String s = OutputUtil.compactString(reader); + assertEquals(EL_ROOT_SOLO, s); + } + + + public void testCompactStringParentChildSAX() throws Exception + { + XMLReader reader = new MyXMLReader(EL_ROOT, EL_CHILD); + String s = OutputUtil.compactString(reader); + assertEquals(EL_ROOT_START + EL_CHILD_SOLO + EL_ROOT_END, s); + } + + public void testCompactStringWithText() throws Exception { Element root = DomUtil.newDocument(EL_ROOT); @@ -98,6 +147,29 @@ } + public void testIndentedStringParentChildDOM() throws Exception + { + Element root = DomUtil.newDocument(EL_ROOT); + Element child = DomUtil.appendChild(root, EL_CHILD); + DomUtil.setText(child, SOME_TEXT); + + String s = OutputUtil.indentedString(root.getOwnerDocument(), 4); + assertMultiline(EL_ROOT_START + + "\n " + EL_CHILD_START + SOME_TEXT + EL_CHILD_END + + "\n" + EL_ROOT_END + "\n", s); + } + + + public void testIndentedStringParentChildSAX() throws Exception + { + XMLReader reader = new MyXMLReader(EL_ROOT, EL_CHILD); + String s = OutputUtil.indentedString(reader, 4); + assertMultiline(EL_ROOT_START + + "\n " + EL_CHILD_SOLO + + "\n" + EL_ROOT_END + "\n", s); + } + + public void testIndentedStringParentChildText() throws Exception { Element root = DomUtil.newDocument(EL_ROOT); @@ -111,7 +183,7 @@ } - public void testCompactStreamAsciiContent() throws Exception + public void testCompactStreamAsciiContentDOM() throws Exception { Element root = DomUtil.newDocument("foo"); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -128,6 +200,23 @@ } + public void testCompactStreamAsciiContentSAX() throws Exception + { + XMLReader reader = new MyXMLReader("foo"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + OutputUtil.compactStream(reader, out); + byte[] data = out.toByteArray(); + assertEquals(6, data.length); + assertEquals('<', data[0]); + assertEquals('f', data[1]); + assertEquals('o', data[2]); + assertEquals('o', data[3]); + assertEquals('/', data[4]); + assertEquals('>', data[5]); + } + + public void testCompactStreamNonAsciiDefaultEncoding() throws Exception { Element root = DomUtil.newDocument("\u00C0\u00C1"); @@ -147,7 +236,7 @@ } - public void testCompactStreamNonAsciiISO8859Encoding() throws Exception + public void testCompactStreamNonAsciiISO8859EncodingDOM() throws Exception { Element root = DomUtil.newDocument("\u00C0\u00C1"); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -169,6 +258,30 @@ assertTrue("no encoding", s.indexOf("encoding") > 0); assertTrue("incorrect encoding", s.indexOf("iso-8859-1") > 0 || s.indexOf("ISO-8859-1") > 0); + } + + public void testCompactStreamNonAsciiISO8859EncodingSAX() throws Exception + { + XMLReader reader = new MyXMLReader("\u00C0\u00C1"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + OutputUtil.compactStream(reader, out, "ISO-8859-1"); + byte[] data = out.toByteArray(); + + // look for specific bytes for the element ... note reverse order + int idx = data.length - 1; + assertEquals('>', data[idx--]); + assertEquals('/', data[idx--]); + assertEquals(0xC1, data[idx--] & 0xFF); + assertEquals(0xC0, data[idx--] & 0xFF); + assertEquals('<', data[idx]); + + // convert to string to check for prologue + String s = new String(data, "ISO-8859-1"); + assertTrue("no prologue", s.startsWith("<?xml")); + assertTrue("no encoding", s.indexOf("encoding") > 0); + assertTrue("incorrect encoding", + s.indexOf("iso-8859-1") > 0 || s.indexOf("ISO-8859-1") > 0); } } Modified: trunk/src/test/java/net/sf/practicalxml/builder/TestXmlBuilder.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/builder/TestXmlBuilder.java 2009-04-25 13:59:44 UTC (rev 78) +++ trunk/src/test/java/net/sf/practicalxml/builder/TestXmlBuilder.java 2009-04-27 12:41:46 UTC (rev 79) @@ -15,6 +15,12 @@ package net.sf.practicalxml.builder; import java.io.ByteArrayOutputStream; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; @@ -23,6 +29,9 @@ import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.ProcessingInstruction; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; import net.sf.practicalxml.AbstractTestCase; import net.sf.practicalxml.DomUtil; @@ -55,6 +64,71 @@ } + private static class MockContentHandler + implements InvocationHandler + { + public ContentHandler getHandler() + throws Exception + { + return (ContentHandler)Proxy.newProxyInstance( + ContentHandler.class.getClassLoader(), + new Class[] { ContentHandler.class }, + this); + } + + private ArrayList<String> _names = new ArrayList<String>(); + private ArrayList<Object[]> _args = new ArrayList<Object[]>(); + + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable + { + // this is a hack for characters + for (int ii = 0 ; ii < args.length ; ii++) + { + if (args[ii] instanceof char[]) + args[ii] = new String((char[])args[ii]); + } + + _names.add(method.getName()); + _args.add(args); + return null; + } + + /** + * Asserts that the specific sequence of methods was called on this + * handler. + */ + public void assertInvocationSequence(String... methodNames) + { + List<String> expected = Arrays.asList(methodNames); + assertEquals(expected, _names); + } + + /** + * Asserts the name and argument values for a specific call to this + * handler. For convenience, ignores any arguments past the expected + * list. + */ + public void assertInvocation(int callNum, String methodName, Object... args) + { + assertEquals(methodName, _names.get(callNum)); + for (int ii = 0 ; ii < args.length ; ii++) + { + assertEquals("argument " + ii, args[ii], _args.get(callNum)[ii]); + } + } + + /** + * Returns a specific argument passed to a specific invocation. This + * allows the caller to make test-specific assertions. + */ + public Object getInvocationArgument(int callNum, int argNum) + { + return _args.get(callNum)[argNum]; + } + } + + //---------------------------------------------------------------------------- // Test Cases //---------------------------------------------------------------------------- @@ -62,114 +136,212 @@ public void testSingleElement() throws Exception { ElementNode node = element("foo"); - assertEquals("<foo/>", node.toString()); Document dom = node.toDOM(); assertRootElement(dom, null, "foo", 0); + + MockContentHandler handler = new MockContentHandler(); + node.toSAX(handler.getHandler()); + handler.assertInvocationSequence("startElement", "endElement"); + handler.assertInvocation(0, "startElement", null, "foo", "foo"); + + assertEquals("<foo/>", node.toString()); } - public void testNamespacedSingleElement() throws Exception + public void testSingleElementDefaultNamespace() throws Exception { ElementNode node = element("foo", "bar"); + + Document dom = node.toDOM(); + assertRootElement(dom, "foo", "bar", 0); + + MockContentHandler handler = new MockContentHandler(); + node.toSAX(handler.getHandler()); + handler.assertInvocationSequence("startElement", "endElement"); + handler.assertInvocation(0, "startElement", "foo", "bar", "bar"); + assertEquals("<bar xmlns=\"foo\"/>", node.toString()); + } + + public void testSingleElementQualifiedNamespace() throws Exception + { + ElementNode node = element("foo", "bar:baz"); + Document dom = node.toDOM(); - assertRootElement(dom, "foo", "bar", 0); } + assertRootElement(dom, "foo", "bar:baz", 0); + MockContentHandler handler = new MockContentHandler(); + node.toSAX(handler.getHandler()); + handler.assertInvocationSequence("startElement", "endElement"); + handler.assertInvocation(0, "startElement", "foo", "baz", "bar:baz"); + assertEquals("<bar:baz xmlns:bar=\"foo\"/>", node.toString()); + } + + public void testNestedElement() throws Exception { ElementNode node = element("foo", element("bar")); - assertEquals("<foo><bar/></foo>", node.toString()); Document dom = node.toDOM(); assertRootElement(dom, null, "foo", 1); assertElement(dom, "/foo/bar", null, "bar", 0); + + MockContentHandler handler = new MockContentHandler(); + node.toSAX(handler.getHandler()); + handler.assertInvocationSequence("startElement", + "startElement", "endElement", + "endElement"); + handler.assertInvocation(0, "startElement", null, "foo", "foo"); + handler.assertInvocation(1, "startElement", null, "bar", "bar"); + + assertEquals("<foo><bar/></foo>", node.toString()); } public void testAttribute() throws Exception { - Document dom = element("foo", + ElementNode node = element("foo", attribute("argle", "bargle", "wargle"), - attribute("bar", "baz")) - .toDOM(); + attribute("bar", "baz")); + Document dom = node.toDOM(); Element root = dom.getDocumentElement(); assertEquals("wargle", root.getAttributeNS("argle", "bargle")); assertEquals("baz", root.getAttribute("bar")); + + MockContentHandler handler = new MockContentHandler(); + node.toSAX(handler.getHandler()); + handler.assertInvocationSequence("startElement", "endElement"); + handler.assertInvocation(0, "startElement", null, "foo", "foo"); + + Attributes attrs = (Attributes)handler.getInvocationArgument(0, 3); + assertEquals(2, attrs.getLength()); } public void testTextElement() throws Exception { - Document dom = element("foo", text("bar")) - .toDOM(); + ElementNode node = element("foo", text("bar")); + Document dom = node.toDOM(); Element root = dom.getDocumentElement(); assertEquals("bar", DomUtil.getText(root)); + + MockContentHandler handler = new MockContentHandler(); + node.toSAX(handler.getHandler()); + handler.assertInvocationSequence("startElement", + "characters", + "endElement"); + handler.assertInvocation(0, "startElement", null, "foo", "foo"); + handler.assertInvocation(1, "characters", "bar", 0, 3); + + assertEquals("<foo>bar</foo>", node.toString()); } public void testConsecutiveTextElements() throws Exception { - Document dom = element("foo", text("bar"), text("baz")) - .toDOM(); + ElementNode node = element("foo", text("bar"), text("baz")); + Document dom = node.toDOM(); Element root = dom.getDocumentElement(); assertEquals("barbaz", DomUtil.getText(root)); + + MockContentHandler handler = new MockContentHandler(); + node.toSAX(handler.getHandler()); + handler.assertInvocationSequence("startElement", + "characters", "characters", + "endElement"); + handler.assertInvocation(0, "startElement", null, "foo", "foo"); + handler.assertInvocation(1, "characters", "bar", 0, 3); + handler.assertInvocation(2, "characters", "baz", 0, 3); + + assertEquals("<foo>barbaz</foo>", node.toString()); } public void testComment() throws Exception { - Document dom = element("foo", comment("bar")) - .toDOM(); + ElementNode node = element("foo", comment("bar")); + Document dom = node.toDOM(); Element root = dom.getDocumentElement(); assertEquals(1, root.getChildNodes().getLength()); - Comment child = (Comment)root.getChildNodes().item(0); assertEquals("bar", child.getNodeValue()); + + // note: ContentHandler knows nothing of comments + MockContentHandler handler = new MockContentHandler(); + node.toSAX(handler.getHandler()); + handler.assertInvocationSequence("startElement", "endElement"); + handler.assertInvocation(0, "startElement", null, "foo", "foo"); + + +// assertEquals("<foo><!--bar--></foo>", node.toString()); } + public void testPI() throws Exception + { + ElementNode node = element("foo", processingInstruction("argle", "bargle")); + + Document dom = node.toDOM(); + Element root = dom.getDocumentElement(); + assertEquals(1, root.getChildNodes().getLength()); + ProcessingInstruction child = (ProcessingInstruction)root.getChildNodes().item(0); + assertEquals("argle", child.getTarget()); + assertEquals("bargle", child.getData()); + + MockContentHandler handler = new MockContentHandler(); + node.toSAX(handler.getHandler()); + handler.assertInvocationSequence( + "startElement", + "processingInstruction", + "endElement"); + handler.assertInvocation(1, "processingInstruction", "argle", "bargle"); + + assertEquals("<foo><?argle bargle?></foo>", node.toString()); + } + + public void testAddChild() throws Exception { ElementNode root = element("foo"); assertSame(root, root.addChild(element("bar"))); - Element eRoot = root.toDOM().getDocumentElement(); - assertEquals("foo", eRoot.getNodeName()); - assertEquals(1, eRoot.getChildNodes().getLength()); - assertEquals("bar", eRoot.getChildNodes().item(0).getNodeName()); - } + Document dom = root.toDOM(); + assertRootElement(dom, null, "foo", 1); + MockContentHandler handler = new MockContentHandler(); + root.toSAX(handler.getHandler()); + handler.assertInvocationSequence("startElement", + "startElement", "endElement", + "endElement"); + handler.assertInvocation(0, "startElement", null, "foo", "foo"); + handler.assertInvocation(1, "startElement", null, "bar", "bar"); - public void testToString() throws Exception - { - String s = element("foo", - attribute("argle", "bar&gle"), - element("bar", text("baz"))) - .toString(); - assertEquals("<foo argle=\"bar&gle\"><bar>baz</bar></foo>", s); + assertEquals("<foo><bar/></foo>", root.toString()); } public void testToStringIndented() throws Exception { - String s = element("foo", element("bar", text("baz"))) - .toString(3); + ElementNode root = element("foo", element("bar", text("baz"))); + + String s = root.toString(3); assertMultiline("<foo>\n <bar>baz</bar>\n</foo>\n", s); } public void testToStream() throws Exception { + ElementNode root = element("foo", element("b\u00e2r", text("baz"))); + ByteArrayOutputStream out = new ByteArrayOutputStream(); - element("foo", element("b\u00e2r", text("baz"))) - .toStream(out); + root.toStream(out); String s = new String(out.toByteArray(), "UTF-8"); assertEquals("<foo><b\u00e2r>baz</b\u00e2r></foo>", s); @@ -178,9 +350,10 @@ public void testToStreamWithPrologue() throws Exception { + ElementNode root = element("f\u00f6o", element("bar", text("baz"))); + ByteArrayOutputStream out = new ByteArrayOutputStream(); - element("f\u00f6o", element("bar", text("baz"))) - .toStream(out, "ISO-8859-1"); + root.toStream(out, "ISO-8859-1"); byte[] b = out.toByteArray(); assertEquals(0xF6, b[b.length-3] & 0xFF); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-04-30 12:09:07
|
Revision: 81 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=81&view=rev Author: kdgregory Date: 2009-04-30 12:08:58 +0000 (Thu, 30 Apr 2009) Log Message: ----------- update logo usage per new SF policy Modified Paths: -------------- trunk/pom.xml trunk/src/site/site.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-04-28 17:54:17 UTC (rev 80) +++ trunk/pom.xml 2009-04-30 12:08:58 UTC (rev 81) @@ -83,7 +83,7 @@ <artifactId>maven-javadoc-plugin</artifactId> <configuration> <bottom> - <a href="http://sourceforge.net/"> + <a href="http://sourceforge.net/projects/practicalxml/"> <img src="http://sflogo.sourceforge.net/sflogo.php?group_id=234884&type=3"> </a> </bottom> Modified: trunk/src/site/site.xml =================================================================== --- trunk/src/site/site.xml 2009-04-28 17:54:17 UTC (rev 80) +++ trunk/src/site/site.xml 2009-04-30 12:08:58 UTC (rev 81) @@ -7,7 +7,7 @@ href="http://maven.apache.org/" img="http://maven.apache.org/images/logos/maven-feather.png"/> <logo name="SourceForge" - href="http://sourceforge.net/" + href="http://sourceforge.net/projects/practicalxml/" img="http://sflogo.sourceforge.net/sflogo.php?group_id=234884&type=3"/> </poweredBy> </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-07-14 14:06:16
|
Revision: 84 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=84&view=rev Author: kdgregory Date: 2009-07-14 14:06:13 +0000 (Tue, 14 Jul 2009) Log Message: ----------- add XmlUtil.formatXsdDecimal() Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/XmlUtil.java trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-07-14 12:26:58 UTC (rev 83) +++ trunk/pom.xml 2009-07-14 14:06:13 UTC (rev 84) @@ -5,7 +5,7 @@ <groupId>net.sf.practicalxml</groupId> <artifactId>practicalxml</artifactId> <packaging>jar</packaging> - <version>1.0.2</version> + <version>1.0.3</version> <name>practicalxml</name> <url>http://sourceforge.net/projects/practicalxml/</url> Modified: trunk/src/main/java/net/sf/practicalxml/XmlUtil.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/XmlUtil.java 2009-07-14 12:26:58 UTC (rev 83) +++ trunk/src/main/java/net/sf/practicalxml/XmlUtil.java 2009-07-14 14:06:13 UTC (rev 84) @@ -15,6 +15,7 @@ package net.sf.practicalxml; import java.text.DateFormat; +import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -99,6 +100,31 @@ /** + * Converts a Java <code>double</code> to a string, using the format + * specified by XML Schema for <code>decimal</code> elements. This + * method wraps the value and calls {@link #formatXsdDecimal(Number)}, + * so call that method if you already have an object. + */ + public static String formatXsdDecimal(double value) + { + return formatXsdDecimal(Double.valueOf(value)); + } + + + /** + * Converts a Java <code>double</code> to a string, using the format + * specified by XML Schema for <code>decimal</code> elements. If + * passed <code>null</code>, returns an empty string + */ + public static String formatXsdDecimal(Number value) + { + if (value == null) + return ""; + return getXsdDecimalFormatter().format(value); + } + + + /** * Parses an XML Schema <code>dateTime</code> object, accepting any of * the legal formats. Note that this method can also be used to parse * a generic ISO-8601 date. @@ -231,6 +257,9 @@ private static ThreadLocal<DateFormat> _xsdDatetimeFormatter = new ThreadLocal<DateFormat>(); + // used by getXsdDecimalFormatter() + private static ThreadLocal<DecimalFormat> _xsdDecimalFormatter = new ThreadLocal<DecimalFormat>(); + /** * Does the actual work of {@link isLegal(String)}. */ @@ -247,7 +276,8 @@ /** - * Returns a DateFormat that will output our standard XSD dateTime format. + * Returns a DateFormat that will output the standard XSD dateTime format. + * This is managed as a ThreadLocal because formatters are not threadsafe. */ private static DateFormat getXsdDatetimeFormatter() { @@ -263,6 +293,30 @@ /** + * Returns a DecimalFormat that will output the standard XSD decimalformat. + * This is managed as a ThreadLocal because formatters are not threadsafe. + * <p> + * Note: output is limited to 17 digits to the right of the decimal point, + * because we assume a <code>double</code> input. For that reason, while + * you can use this method for <code>BigDecimal</code> values, that class' + * <code>toString()</code> is a better choice. + * <p> + * Note 2: there is no corresponding parse method; <code>Double.parseDouble() + * </code> will do the job for you. + */ + private static DecimalFormat getXsdDecimalFormatter() + { + DecimalFormat format = _xsdDecimalFormatter.get(); + if (format == null) + { + format = new DecimalFormat("#0.0################;-#"); + _xsdDecimalFormatter.set(format); + } + return format; + } + + + /** * Used by {@link parseXsdDatetime} to process individual fields of the * dateTime string and store them into a calendar object. It expects to * be called with <code>index</code> pointing to the start of the field, Modified: trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java 2009-07-14 12:26:58 UTC (rev 83) +++ trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java 2009-07-14 14:06:13 UTC (rev 84) @@ -77,6 +77,17 @@ } + public void testFormatXsdDecimal() throws Exception + { + assertEquals("", XmlUtil.formatXsdDecimal(null)); + assertEquals("0.0", XmlUtil.formatXsdDecimal(0)); + assertEquals("1234.0", XmlUtil.formatXsdDecimal(1234)); + assertEquals("-1234.0", XmlUtil.formatXsdDecimal(-1234)); + assertEquals("1234.5", XmlUtil.formatXsdDecimal(1234.5)); + assertEquals("1234567890.123456", XmlUtil.formatXsdDecimal(1234567890.123456)); + } + + public void testEscape() throws Exception { assertEquals("", XmlUtil.escape(null)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-09-10 13:39:29
|
Revision: 125 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=125&view=rev Author: kdgregory Date: 2009-09-10 13:39:16 +0000 (Thu, 10 Sep 2009) Log Message: ----------- add NodeListIterator Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/util/NodeListIterable.java Added Paths: ----------- trunk/src/main/java/net/sf/practicalxml/util/NodeListIterator.java trunk/src/test/java/net/sf/practicalxml/util/TestNodeListIterator.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-09-08 16:06:13 UTC (rev 124) +++ trunk/pom.xml 2009-09-10 13:39:16 UTC (rev 125) @@ -5,7 +5,7 @@ <groupId>net.sf.practicalxml</groupId> <artifactId>practicalxml</artifactId> <packaging>jar</packaging> - <version>1.0.3</version> + <version>1.0.4</version> <name>practicalxml</name> <url>http://sourceforge.net/projects/practicalxml/</url> Modified: trunk/src/main/java/net/sf/practicalxml/util/NodeListIterable.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/util/NodeListIterable.java 2009-09-08 16:06:13 UTC (rev 124) +++ trunk/src/main/java/net/sf/practicalxml/util/NodeListIterable.java 2009-09-10 13:39:16 UTC (rev 125) @@ -15,15 +15,15 @@ package net.sf.practicalxml.util; import java.util.Iterator; -import java.util.NoSuchElementException; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** - * A wrapper for a DOM <code>NodeList</code> that allows it to be used in - * a JDK 1.5 for-each loop. + * A wrapper for a DOM <code>NodeList</code> that allows it to be used in a + * JDK 1.5 for-each loop. See {@link net.sf.practicalxml.util.NodeListIterator} + * if you want full iterator operation. */ public class NodeListIterable implements Iterable<Node> @@ -37,30 +37,6 @@ public Iterator<Node> iterator() { - return new MyIterator(); + return new NodeListIterator(_list); } - - - private class MyIterator - implements Iterator<Node> - { - int _position = 0; - - public boolean hasNext() - { - return _position < _list.getLength(); - } - - public Node next() - { - if (!hasNext()) - throw new NoSuchElementException(); - return _list.item(_position++); - } - - public void remove() - { - throw new UnsupportedOperationException("unable to remove from NodeList"); - } - } } Added: trunk/src/main/java/net/sf/practicalxml/util/NodeListIterator.java =================================================================== --- trunk/src/main/java/net/sf/practicalxml/util/NodeListIterator.java (rev 0) +++ trunk/src/main/java/net/sf/practicalxml/util/NodeListIterator.java 2009-09-10 13:39:16 UTC (rev 125) @@ -0,0 +1,79 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.util; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +/** + * A wrapper for {@link org.w3c.dom.NodeList} that provides full iterator + * behavior. See {@link net.sf.practicalxml.util.NodeListIterable} if all + * you want to do is use the NodeList in a JDK 1.5 <code>for</code> loop. + * <p> + * Because a <code>NodeList</code> is a view on a DOM tree, this iterator has + * slightly different semantics than a typical <code>java.util</code> iterator. + * First, it is not "fail fast": the DOM consists of independent nodes, and we + * have no way to track when changes to the DOM may have made the nodelist + * invalid. + * <p> + * Second, and more important, removal via the iterator changes the DOM, not + * just the underlying list. + */ +public class NodeListIterator +implements Iterator<Node> +{ + private NodeList _list; + private int _pos; + private Node _current; + + + public NodeListIterator(NodeList nodelist) + { + _list = nodelist; + } + + + public boolean hasNext() + { + return _pos < _list.getLength(); + } + + + public Node next() + { + if (hasNext()) + { + _current = _list.item(_pos++); + return _current; + } + throw new NoSuchElementException("invalid index: " + _pos); + } + + + public void remove() + { + if (_current == null) + throw new IllegalStateException("no current node"); + + Node _parent = _current.getParentNode(); + _parent.removeChild(_current); + _pos--; + _current = null; + } +} Added: trunk/src/test/java/net/sf/practicalxml/util/TestNodeListIterator.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/util/TestNodeListIterator.java (rev 0) +++ trunk/src/test/java/net/sf/practicalxml/util/TestNodeListIterator.java 2009-09-10 13:39:16 UTC (rev 125) @@ -0,0 +1,179 @@ +// Copyright 2008-2009 severally by the contributors +// +// 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 net.sf.practicalxml.util; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +import junit.framework.TestCase; + +import static net.sf.practicalxml.builder.XmlBuilder.*; + + +public class TestNodeListIterator +extends TestCase +{ + public final static String EL_CHILD1 = "child1"; + public final static String EL_CHILD2 = "child2"; + public final static String TXT1 = "some text"; + + private Element _testData + = element("root", + element(EL_CHILD1), + text(TXT1), + element(EL_CHILD2)) + .toDOM().getDocumentElement(); + +//---------------------------------------------------------------------------- +// Test Cases +//---------------------------------------------------------------------------- + + public void testBasicIteration() throws Exception + { + Iterator<Node> itx = new NodeListIterator(_testData.getChildNodes()); + + assertTrue(itx.hasNext()); + Node node1 = itx.next(); + assertTrue(node1 instanceof Element); + assertEquals(EL_CHILD1, node1.getNodeName()); + + assertTrue(itx.hasNext()); + Node node2 = itx.next(); + assertTrue(node2 instanceof Text); + assertEquals(TXT1, node2.getNodeValue()); + + assertTrue(itx.hasNext()); + Node node3 = itx.next(); + assertTrue(node3 instanceof Element); + assertEquals(EL_CHILD2, node3.getNodeName()); + + assertFalse(itx.hasNext()); + } + + + public void testIterationOffTheEnd() throws Exception + { + Iterator<Node> itx = new NodeListIterator(_testData.getChildNodes()); + while (itx.hasNext()) + itx.next(); + + try + { + itx.next(); + fail("able to iterate off end of list"); + } + catch (NoSuchElementException ee) + { + // success + } + } + + + public void testRemove() throws Exception + { + Iterator<Node> itx = new NodeListIterator(_testData.getChildNodes()); + + itx.next(); + itx.next(); + itx.remove(); + + assertTrue(itx.hasNext()); + Node node = itx.next(); + assertTrue(node instanceof Element); + assertEquals(EL_CHILD2, node.getNodeName()); + + assertFalse(itx.hasNext()); + + // verify that DOM was changed + + NodeList list = _testData.getChildNodes(); + assertEquals(2, list.getLength()); + + Node node1 = list.item(0); + assertTrue(node1 instanceof Element); + assertEquals(EL_CHILD1, node1.getNodeName()); + + Node node2 = list.item(1); + assertTrue(node2 instanceof Element); + assertEquals(EL_CHILD2, node2.getNodeName()); + } + + + public void testRemoveAtEndOfIteration() throws Exception + { + Iterator<Node> itx = new NodeListIterator(_testData.getChildNodes()); + + itx.next(); + itx.next(); + itx.next(); + assertFalse(itx.hasNext()); + + itx.remove(); + + // verify that DOM was changed + + NodeList list = _testData.getChildNodes(); + assertEquals(2, list.getLength()); + + Node node1 = list.item(0); + assertTrue(node1 instanceof Element); + assertEquals(EL_CHILD1, node1.getNodeName()); + + Node node2 = list.item(1); + assertTrue(node2 instanceof Text); + assertEquals(TXT1, node2.getNodeValue()); + } + + + public void testRemoveFailsIfNextNotCalled() throws Exception + { + Iterator<Node> itx = new NodeListIterator(_testData.getChildNodes()); + + try + { + itx.remove(); + fail("remove() succeeded without initial next()"); + } + catch (IllegalStateException ee) + { + // success + } + } + + + public void testRemoveFailsIfCalledTwice() throws Exception + { + Iterator<Node> itx = new NodeListIterator(_testData.getChildNodes()); + + itx.next(); + itx.next(); + itx.remove(); + + try + { + itx.remove(); + fail("remove() succeeded without intervening next()"); + } + catch (IllegalStateException ee) + { + // success + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-12-30 21:53:10
|
Revision: 184 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=184&view=rev Author: kdgregory Date: 2009-12-30 21:53:00 +0000 (Wed, 30 Dec 2009) Log Message: ----------- add SimpleXMLReader, XMLFilterImplBridge Modified Paths: -------------- trunk/pom.xml Added Paths: ----------- trunk/src/main/java/net/sf/practicalxml/util/SimpleXMLReader.java trunk/src/main/java/net/sf/practicalxml/util/XMLFilterImplBridge.java trunk/src/test/java/net/sf/practicalxml/util/TestSimpleXMLReader.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2009-12-31 14:47:33
|
Revision: 185 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=185&view=rev Author: kdgregory Date: 2009-12-31 14:47:25 +0000 (Thu, 31 Dec 2009) Log Message: ----------- NodeListIterator - recognize when we should iterate via nextSibling links - add an optional class-based filter DomUtil - update getChildren() to use NodeListIterator Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/DomUtil.java trunk/src/main/java/net/sf/practicalxml/util/NodeListIterator.java trunk/src/test/java/net/sf/practicalxml/TestDomUtil.java trunk/src/test/java/net/sf/practicalxml/util/TestNodeListIterator.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2010-01-15 15:51:20
|
Revision: 196 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=196&view=rev Author: kdgregory Date: 2010-01-15 15:51:07 +0000 (Fri, 15 Jan 2010) Log Message: ----------- 1.1.3 pre-release Modified Paths: -------------- trunk/pom.xml trunk/src/site/changes.xml This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2010-03-04 12:35:00
|
Revision: 200 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=200&view=rev Author: kdgregory Date: 2010-03-04 12:34:53 +0000 (Thu, 04 Mar 2010) Log Message: ----------- BeanConverter: support enums Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/converter/bean/Bean2XmlConverter.java trunk/src/main/java/net/sf/practicalxml/converter/bean/Xml2BeanConverter.java trunk/src/main/java/net/sf/practicalxml/converter/bean/package.html trunk/src/test/java/net/sf/practicalxml/converter/bean/AbstractBeanConverterTestCase.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestBean2XmlAppenders.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestBean2XmlConverter.java trunk/src/test/java/net/sf/practicalxml/converter/bean/TestXml2BeanConverter.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2010-08-04 11:48:38
|
Revision: 202 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=202&view=rev Author: kdgregory Date: 2010-08-04 11:48:31 +0000 (Wed, 04 Aug 2010) Log Message: ----------- bug 3036625: incorrect exception thrown by XmlUtil.parseXsdDatetime() Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/XmlUtil.java trunk/src/test/java/net/sf/practicalxml/TestXmlUtil.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2010-12-05 01:10:50
|
Revision: 207 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=207&view=rev Author: kdgregory Date: 2010-12-05 01:10:37 +0000 (Sun, 05 Dec 2010) Log Message: ----------- JSON->XML Conversion: add method that appends to existing element Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/converter/JsonConverter.java trunk/src/main/java/net/sf/practicalxml/converter/json/Json2XmlConverter.java trunk/src/test/java/net/sf/practicalxml/converter/json/TestJson2XmlConverter.java trunk/src/test/java/net/sf/practicalxml/converter/json/TestJsonConverter.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2011-05-09 11:57:03
|
Revision: 213 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=213&view=rev Author: kdgregory Date: 2011-05-09 11:56:57 +0000 (Mon, 09 May 2011) Log Message: ----------- 3279326: support attributes in JSON conversion Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonConverter.java trunk/src/main/java/net/sf/practicalxml/converter/json/Xml2JsonOptions.java trunk/src/test/java/net/sf/practicalxml/converter/json/TestXml2JsonConverter.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2011-05-10 11:31:36
|
Revision: 214 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=214&view=rev Author: kdgregory Date: 2011-05-10 11:31:30 +0000 (Tue, 10 May 2011) Log Message: ----------- release Modified Paths: -------------- trunk/pom.xml trunk/src/site/changes.xml This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Auto-Generated S. C. M. <pra...@li...> - 2011-09-21 18:57:29
|
Revision: 224 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=224&view=rev Author: kdgregory Date: 2011-09-21 18:57:23 +0000 (Wed, 21 Sep 2011) Log Message: ----------- post-release: update version; late update of changes Modified Paths: -------------- trunk/pom.xml trunk/src/site/changes.xml This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |