libcommons-digester-java-1.8.1.orig/0000755000175000017500000000000011226450007017300 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/LICENSE.txt0000644000175000017500000002613611226450007021133 0ustar twernertwerner 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. libcommons-digester-java-1.8.1.orig/RELEASE-NOTES.txt0000644000175000017500000000526611226450007022020 0ustar twernertwerner $Id: RELEASE-NOTES.txt 730329 2008-12-31 06:47:27Z rahul $ Commons Digester Package Version 1.8.1 Release Notes INTRODUCTION ============ This is a minor bugfix and maintenance release. Existing projects using Digester 1.8 are encouraged to upgrade to the 1.8.1 release. New projects are encouraged to use Digester 2.0, which requires JDK 1.5. This release is 100% binary and source compatible with the 1.8 release. DEPENDENCIES ============= Digester 1.8.1 works with all sets of dependencies that worked for Digester 1.8. Users should upgrade to the recommended dependency set below where possible. The Recommended Dependency Set for Digester 1.8.1 is: Digester 1.8.1 + Logging 1.1.1 + BeanUtils 1.8.0 Other Compatible Dependency Sets: Digester 1.8.1 + Logging 1.1.x + BeanUtils 1.x + Collections 2.x Digester 1.8.1 + Logging 1.1.x + BeanUtils 1.x + Collections 3.x It is also possible to use Logging 1.0.x or BeanUtils 1.7.0 instead. BUGS FROM PREVIOUS RELEASE =========================== * [DIGESTER-114] SetPropertyRule throws java.lang.IllegalArgumentException: No name specified when matched element has no attributes. * [DIGESTER-117] Missing unit tests using Ant and Maven. * [DIGESTER-120] Digesting XML content with NodeCreateRule swallows spaces. * [DIGESTER-122] Potential NullPointerException if debug is enabled in Digester#resolveEntity() * [DIGESTER-125] Clear inputSources list in method Digester.clear() * [DIGESTER-126] Potential NullPointerException if debug is enabled in FactoryCreateRule#begin() IMPROVEMENTS FROM PREVIOUS RELEASE =================================== * [DIGESTER-89] Add jar target to Ant build.xml * [DIGESTER-111] Null arguments to all Digester#parse() methods now throw an IllegalArgumentException. libcommons-digester-java-1.8.1.orig/checkstyle.xml0000644000175000017500000000324511226450007022164 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/xdocs/0000755000175000017500000000000011226450007020420 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/xdocs/dtds/0000755000175000017500000000000011226450007021356 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/xdocs/dtds/digester-rules.dtd0000644000175000017500000001477511226450007025027 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/xdocs/index.xml0000644000175000017500000001667011226450007022263 0ustar twernertwerner Commons Commons Documentation Team

Many projects read XML configuration files to provide initialization of various Java objects within the system. There are several ways of doing this, and the Digester component was designed to provide a common implementation that can be used in many different projects.

Basically, the Digester package lets you configure an XML -> Java object mapping module, which triggers certain actions called rules whenever a particular pattern of nested XML elements is recognized. A rich set of predefined rules is available for your use, or you can also create your own. Advanced features of Digester include:

  • Ability to plug in your own pattern matching engine, if the standard one is not sufficient for your requirements.
  • Optional namespace-aware processing, so that you can define rules that are relevant only to a particular XML namespace.
  • Encapsulation of Rules into RuleSets that can be easily and conveniently reused in more than one application that requires the same type of processing.

User documentation is available as package descriptions within the JavaDoc API documents. In particular, you should read the package description for the org.apache.commons.digester package for detailed information on using the package.

The Release Notes document the new features and bug fixes that have been included in this release.

The "examples" directory in the source code repository contains code which demonstrates the basic functionality. In particular, you should read the AddressBook example in the "api" subdirectory. You can view the examples directly from the Subversion repository via the web-based repository browser web site, or can use subversion to download the files.

For the FAQ and other digester-related information, see the Digester wiki page.

Digester 2.0 is a major release. New projects are encouraged to use this release of digester. There are breaking changes from Digester 1.8, see release notes in detail before choosing to upgrade. There is no urgency for existing projects to upgrade; Digester 1.8 has proven to be a stable release.

Digester 2.0 requires a minimum of JDK 1.5 and no longer requires any classes from Commons Collections (as Digester 1.8 did).

The recommended dependency set for Digester 2.0 is:

Recommended Dependency Set
Digester +Logging 1.1.1 +BeanUtils 1.8.0

It is also possible to use Logging 1.0.x or BeanUtils 1.7.0 instead.

Digester 1.8.1 is a minor bugfix and maintenance release. Existing projects using Digester 1.8 are encouraged to upgrade to the 1.8.1 release. New projects are encouraged to use Digester 2.0, which requires JDK 1.5. See the release notes for more details.

The dependencies for Digester 1.8.1 are identical to the dependencies for Digester 1.8.

Digester has a dependency on Commons Collections. The dependency can alternatively be satisfied by including the latest BeanUtils releases (1.7.0 or above) (which includes the stable collections ArrayStack class necessary).

The recommended dependency set for Digester 1.8 is:

Recommended Dependency Set
Digester +Logging 1.1.1 +BeanUtils 1.8.0

Other compatible dependency sets for Digester 1.8 can be summarized as follows:

Compatible Dependency Sets
Digester +Logging 1.1.x +BeanUtils 1.x +Collections 2.x
Digester +Logging 1.1.x +BeanUtils 1.x +Collections 3.x

It is also possible to use Logging 1.0.x or BeanUtils 1.7.0 instead.

Please remember to verify the MD5 check sums.

libcommons-digester-java-1.8.1.orig/xdocs/images/0000755000175000017500000000000011226450007021665 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/xdocs/images/logo.png0000644000175000017500000003046311226450007023341 0ustar twernertwernerPNG  IHDR,dcbKGD pHYs  ~tIME*Dv IDATx}y\SI yUm~}-n"ݬ w뫯ֺUX\֥kˎh &AQ$Ǽo87|B2w9eAE& 2<>>Z600PрzI޽9 j@KMrHIIn}||9r|||ZZZ~~>1$$$,]~)%^z}rr2 /en ^Z/ݻwSQԁprdqNP>K6m|||6|+WܻwbXVZe˖9 hO~ժv5bxpǎUUU555IIIAAARZ@.~"s te˖ỪN6*??֬Yv!EvG)))v[M_~AlrrYylUUյkfΜi˶mVYYI.L00oXXXPxc܇`̘1ݻwΟ??l0[l{neee]ONI}ޔZlllyyTt:]TTB\\l{i(IIlƘ7"S6RRRf͚%xl6/^eϟ_ZZ ェ"##RG: ܶm[yyl.--ݼy?% 9#FHWVV?BX 6o\VVVQQQUUeC_ĉHl6;noӀa||}(44ق֭[l3deeeR^2,,l6ܾ}֭[(>w\FaWׯ_~=<5eʔ-[DFFr2o߆/Zt[nݹsl6K4%hj4wߺud2 6;w. OO7nqDR;wR:z~oݺUZZJbTWW/^b0ƺvzС[nF^12Ɔzypn2 ɞڵkF}b"0nܸ"Ι3b{үȤ //oժUr~~~aaaYY:-p%%%jNk׮l&;; .Çs₦eff޼yd2\~K.sժUzzCV--- h4LG|Ng4ܹS^^ބ3)>gddj2 RT*^^^֭çfs֭۵k'BP( PRs΅G c /^|gڷo/6}K.w(X,77ldȑ# n޼9dU~ Zc ^o>òeƎۼysƘj7!!ەuҥo7@m۶_F#  z eeuAZBB3DQP(ӧOrYYY~~>x *X`6l6/Yd͛7Vm۶ iX]T*BBBChJΟ?ũSbT*IԿO8rH0u-ZTTTJZV>,7x1p8{lu„ 0sZ @/,// foWSNχe "T*'''n۩SE 0t:]ee% =h$Ŝ1c+-l>urrG={v^***4e燘FV(QQQhC}'P`jyȑ#IIIHuu5lQ UJ) rrr94!(@tvv9qR 7%i8ն@]ll,-ZԢE BG}.W(NNNңG+F1::zuE޲eXV...nnn=z]Te]]]Ǐ%;0\>G*Rj5vPZhq=@]y@kYb"`sA@如uqq&<&([r|dɜUDGGC=T*US~1ݻw;r  >3gϞȸpB~pT}@Ϗ9cTnѣXc' .2AAM#Kph!3P3 8@IiBB:JX`C UaaalNNN^^sƤa RzF`C?~LL <)$tBUT=zංN:mK$3F:dzsѢEF@ln{@qlp͕ѓѱ\f\]]jJ2 2II!ݻs\eee(:|V#0(m`_6T2t8Z)uY,@1VzJgkRoNN7е(*FWFj$RY ׯLGhv{igQA5LD@#l֬Y͛7otJ$y 9UFְ`Ʃ:i-N5 vP#A)RRSS8 +n;h4y .&ŋ:C>uT>ëWJ'u$ĜCf)8'N4d#tAG}aY&h6٫w^A4FR6p@ r4Jûx\\܄ Y^[|9NѦu!t. dPJǏS,O J٣?9ޟh5ee#%=`W߿7̙ /\v B:k ?Oh49fS{>vww9ccxW/,XFșC>:(((99?g׮]W0x>ǎyC0#@i"ɓ'6po:tb]yK.CY'ؿam'NO?=Cq?+W%Njw;2Bn+iА$X0@%W~wTW:ug8֕TdgWћ5kֶm?ĉ`0^K!hv[nM=sLNN굜#GRʙ3gcu )cn(d2L&+mժ_mFZ|9ҟ{UV-Y9rԑjZ~4#Gܹs'UϞ=vq`Y|o+ @׮Xmۗ_$TdK7oO >|رl4!&6`XϜZ5L/Iinɓ ^ך8MywFaʔ)jlz`|-`w( t0{Z`'MD9u)ɣPӧsM'NxSSS t۶m_GIر`0`]?^^^iS(!t=b2n%XZg1BeMa}vcǎ4IAq`'ֹs>h׮]v튏5kV6mҶmZjEPzP6m>cR?g8ۇ58G_ "668YbEAA:A.Ben:Xge80UV\TT0H  ExxxLL7n]wy뭷x+V8O~+ uáD3gfΜIsAmǃIk4ÇlRE>GFbi~UVVr*3N*cĉ]2Q9dtI˗S3gH)ۑ&ǀɓ`ܸQdm@V{M60`6w_|EJJ ٳgnZi4-[} |M>Ymv8h |tСk֬d=h;AWQQq &`m"""}(j9Hݻk׮ݼy3n#u6Z}7n޽swwرo^VgffEf4m۶򊋋dww>}?sڵؽ{7;vYՎ5i߾}iiiR}} ٳgv휝 wر_~mڴٳgĝ(555IIIɱ+XF3uI&i暚bdeeF'60==}q*saaa?Jzzb9tcߟvh4'O~bqrre<^hi(o`UUUW^MOO?vD9www__~BGqxlgRa6333'''77BR j^^^*ժP([7|ڎ\={Tk֬`^V;c @"Rj=z􈎎vQ0=]RmڴF1UC|W1(ufD2eJϞ=qPw6???++رcBjZ?4 ƢpByժUTVv_i&WWל+WR=K &Mٳ'OZZSO=E Ϝ9c0TajjjVWW3p[1zXPnT/CܷgX9 DEi<@;s1):ݻPflM0'ŀlZJ e$nSd XVS ]q$ރjwiX1) Z Rm X,h 1[v>*Jԥz(u8fy+-1Z(5|ncqEQx;>101rV EЪ2"c72+m( d@Va+sm!e0Q?p2 BҾPja哾Q&Ibv%c 0ĮTMxZؠ a`Qh]qj?R+N@JQ@"Dž0i ]_W=Cѩrl}Fh J8D@d?iHC"#l 0)Y<;@V8,-g!Ҏnfg4S}zI{Ӄ  m=JGPKM$K%+v̤ZB)`wZ%y!TᨆQZa*j`Ȃmk/au!sVĈd$ |Z]rc"$(9EdkWQ҆8nŸȰc,d{_MϮR J݄F5=x )3 Yo+Z˟@_6]K!mKq=?d2</_fΜ)-X{yw=c zW.~<5&))IՊ&?jd}<$$$@"ٳSRRpi3Vk||<>NdC ehlн{w^viKܡ{///ȹkM{ IHNNˣU!}A "4f„ x"Ç >6M+) z1#֭[-[<`|M{?G8 rfԭ[7___<< 8̖+IMc8owq I 1%HM\5 -i Gz=\0*ڃ] GG'A 4q`F4-Pfؘ+a8EQRe? #GJRFi>zP  g& $w"}ATTذZXa̶FȀ^yf!N:յkWfSM<`e(>>>|7zh`1d/SSS9f>oo֭SBBh+px$55UٕU=R;QATTw.cl/_ o-Zqׯ^tiZ1ZZZZZZZVVu(FN1bc,(((((采/]4))-¶ҥKSRR{K. o!Cܾ}l62:oa͘1ڵkwnٛ5kψ#פ$̙39ICA6F YAw {ŋ34 '\hQJJ ޽{KÇm@/>>>>>3gܵkΝ;.]JFk`sYTeYUU}vp"0ꬶcd 4ڵk.]x+Wt:d*..S]]رkmpDl2+UWWرC*J-Tρlp:*)A-)| &'''%%={6$$dȐ!Æ 8\$ @K XA(x#w b -Z" D|||Є… $%%q w5xhhl:]ʭ["吐s;wz͛P.85(8oiE 9aaa.]bA;klfsiiiqqqqq۷{ ,HJJϜ9sUSNEaÆݾ} וϝ;Gߕs֭;wж_]&eΝ;qDFF"P X`;wA"C=،_v`0K,A,))sNdd$.***..GCyhhM@!C o޼ s#ai_˛F ۷oBN:w燏U[ncX "M1Z7DO?4 7x1"4VUU 4Y>nX6Vyz'N@7c$C O)Sp 8$$$w8O/ڷo r3gNbbbttի( Ҿ1Bjj*E5pOٝupVZNUUghpF_J'11"+WS ՝;w-ݻw/߯XL\-˸qcH@(֮2)((Xz5clXÊ3B=, 5zh[QQK/S7^R;(#̚5 >a lv&}LWMIDATX,(B(nH1@.]8:vѧ( ۷~twܸ֮qvС`D[h>N:Zl B9j.fbb"gn4 yJSF[QQǰh?[,lt:.c0~Ft{QB9V@Xw}EQAjFF駟6VJqÿ&L?  1vXaݺuiG옙 ۷EPYYE-Ձ2i%4(bD2JBrB$%J%~떌_~rP1@.x(,,ѝԆVju[,]Mhqƍ7;6""¢ԀZ V.=pEf ~ n2:GCWM` ҪҒ9aQq8:i445WPG +Vgrɨ)F؈Ͳ7ʢ;:Os'O:t޽'NxСSs3$uQ.O5OVOpա#G'P7&&fHiiil8OAo קŕR GI !1HS ĢS@nܹ#G<`%Kڵݫ~С`llUr= p(hyDDL&7l@テ洒 Rn݂;a2%;v-޵zj4B̄NӲeKMF3~F#~\^bʼn'EQ 3f̴iڴiCGJ8Fa7|b D4"曐 J`M&X*m$ ǢQb4d2qqqcFFF^ݻx@Tn@HKKȐڡKqq1ݻ7dxr)۶mC!=z/dyzzΛ7͙3'**`0~AA'|[oiEq3mn$\4"݊V!K g̘ѬY3777Zydꫯjjj Kf͚5kF 0Z].]`vMZVV%5NS !l?ƘF9v?^kW_1*ou>j(wwoݺ5--g4{&t[TFF矽 }3ݰaTj\/F؈:6ݻ(x{{.N:իW^^^^h z᧞z М{@V֯_hhί^:d́ Ço3o޼nݺALff֭[ׯ… a ƫ7oCCC0Vkuuq=ꀽP8+M۷/fLL̋/P(j5!\ZlFظ|?*///rߌO4IDDD$&&FDD۷Ǥ .p>/=s ʕ+W\pn=i9]nݖ-[L&2dȤI|||% ЩSy扢VEnݺ=c`17T*ռy֯_:t5k?,oByMMMeeeZZ… Ϝ9õhРA333sڵpȃ«ڱcG??@4B.U1Fظ@xV-++h44iРA0uBPMƘJ*))8nݺ=h BG-[ 9vX]zyyV!]J\XvIbÇW,0NNNh(tԪ^xe˖J6\\\SzcJۻ[n@s֑ӧO t5gAj``8qN I8  9WWW\MTVVZ,Aa$|W$+=Dʷ jZ rDDQUCN.%J31y6^ %\zQ*8pfK{}kP 0qNmlGC;99MP!E ¥JqC>Pt(ݻw̘1f޼yx&,_JK/u!88wyyy;wߏ%`_6Hk #|ꒀGz/PJ`v6r(ڒ~hllKt FH`xt c`cR LX񋌌YF$բE fllR$=#] +)ڎ"Unp7譨[@s.EPМ*PŒ$&P6e#ltV1412DD@舀ѕ]5BFVknn.c i"rT*aXKbQ@J> A *}:喦Km:Nc0MhH acT8X,y_fsIDMYipq/##cҙ]Zl;.䨇JW!͘AB"ܚD6Iurr¨ŝiE-vcMP'#GT=t_-acD=#'[]&I!׬YӪU1cƈPV>cLӧ3}]jm4:t)//={@R*[5,T*H1+)F_VdsJ-z"FwpZrHnwGΩr 6j@>ER R-]kA"{=ztù8q_|!rf}H&^kg{R##n a:jN'F$Nݙ]hF9j$?IDDQX,)))| [#ȉ' WZ+ԨP9)]tE b^Q#RaJ#G UJ=-Ү0RM 68piX m IX?z֮ԅG}.a@6Pb9wضVN&0 Q lHyu1pXIw&Q.}F]փP+̅k [ M7dh8FX`[m4o3 KWp}l;(m%ܣ1n 4-@6hXc~L]wHȍBe |0P`vG\Qu oQXҀL.DVP_vc2 ?d]IENDB`libcommons-digester-java-1.8.1.orig/xdocs/images/logo.jpg0000644000175000017500000002565311226450007023342 0ustar twernertwernerJFIFHHCreated with The GIMPCCN"  F  !1AQq 2a"#7BRue$%3b 8!1AQa"q2B#$34 ?OѣFu4jy'GGUѪnSFOGGi~sUѣFJttthѣGGF4tthѣGGF4tthѣGGF4tthѣGGF4tthѣGGF4tthѪ9vEhY8xZܫ#v@7G qc/w5|6'ZdE;*_GY~P /|Tйw,~ > wql6H(1 6K75"\٩SէW/__^B˯ 5f$Lf p(um#I\RVuQ+aRIKK Pd-e/ eY2 %rM:j"О3]c\m6YSƙ>@oq[N[C%t<̃i 2(Sm&<KN tN- u_Ӏ 2mDGXKi5d{ Ù!NFCqG ^tuM6<rD`\jyW# qe1r9Ȭqq74(/#[k:u^^bp\wʓk I`ǟVw'V.*&؈bR4t0:rW =+Rؒ="!!0_ָ2!mӳnp]R$[ZHm"/I; ` owFdX*xøķbd8َX:VmXf5*s3dbly4JdSxRYM⩝^4֗.T5d!=ĞIM]W*׆y0C.9OhگpUo@"ʀDt#^u01ٖ]k.oR N:"k$s\3 z^׵58mXw5-l*%亍5ʯ2LC X5@ ){^% I!ʽAjK$llXbK`)kdR/rKl-z4 "11b/K*f9)~1ו eZͯS%#Lǣ81כ絀&Vf2ULSW}GUGqW^\bk܎XJ$؂(ty F ZѮUMmSo>̵5]u 隒%UL*p[a*\Ez((Ru I66LmX$I} O \ɛ̟ }n+im0FGIW9j"0"#7zƼc]S8e; Woi\̊L3>#Pbi>,\oLY+ 1OZ5k[#ّUHQ⇘lZN7sC4Ө2ЇfcI&œ Gq)L1"c,sJ+6긦UjRz-)jF4s$5RLNIc'4ڥ4Y~pSWpk Wkb"'z-` ˌr3<ËoO:;-*! EqBB5 ޓ 5fKF16,|zzH-'m_kr)5UMܖ)6c[R/KF(-PO[=짛[+{u S 9W5g9J9vPǝZ6xFoRQmUF{hǖ-!H1:ݤQ`%޾Q'$fTlv%p#b)O&IOw5sV$;**5Qs:ݣs*q#l>dG9$9 <C%zɑ+Ъ)2bia\(&dk#C(2r*mb2 suQU NWHfQ[#>Ms%:PҴE2[%̾'Nh2ciumB3K*cRs4\C'_“twrDĬ=Ulkqעydapz*Ys8'$X"G55p(멪eLhCG0Onۯuwq 9gk;I*Ir֨ " o P#\G )J洼Eñ3MWVF Q!"_%[6et lcl^'ӟH\I#WO$6 HZIdkY ٯuK-ҷn@YӬOzZ.SQ 6` 5 J;*hs6-3BWd-r kϟ9JHu-Z-'vЇYW8~9WźbAPZL47 M1dJ3yD2:>+϶-#F6Sd"lމϞEU])\߿V'6\FQ P{`l,M"4w6,AIlF9ưZel;gM,:u+V#%E$㘒ǬvB)$Fx&qf㭧U<#+k9-nf2V"ʙe v \ixJƥX+[l8ج˫U b1Uj/*XT-{&<{F1!c"{ֵEsDj""jw,\~J㱫(x!l.D?)Y<"Svr%[ʻz~;omgb5G_2;+qb^ÈY*Ʋm`UuD˻s+ :NygAki+ Um*+쳈aJb˺z~~]\oyy87mԛ6b{6~q,P3∟Yo;uYv[$c;G#Lf5E~k֨*{SRQ1]棈|'ģb866k3\I_(Bȫc k6G9ʒpʽn9}hg\PTޟrwZ5HrM<U;kNuTZ EtJ\J|+ϿLxËY Y 曆\aذ_a,sY" GyNwS .Ecؓhq;蕭ɮ8jv8IҸ(f̫y ILbϗg) ΦO5bbzU'QC9*jr@XBc]2ј4aXgoDj;g7ä`3[{6EN]CHtSoR,{5kdc9ƭ"+^ ,b;)≑vÚ״}gevC9:EO)alUJVB2 /Y+FLksaw}mӊ !ؕխ\wkS8|,d8m)me3`MiW{b! V $FC^ [ t;JyjkzİJVG ?H?(:ȹ o"h- ؎jNRP1ujί Olj4V3{;*KNhYEi([;^]IGFM.zsvVO 9+GSKYa5;dUB/Td',>a'm60@U+noT1qr.M?Gg(d9 $Nh岏u$E'ڧs_0-xؑ}u7{_`~99%`'Qv)mhn-뙳\5F [%^D,7f9DnxG0<׍6S!Ã+Zй eL7(Bdҥ B+'rj#dJbk iFuj 7,Yx7^I9<1V>ݯbKNREVZyl$;?t)k>SʡBpLeb c<9P Ƙa/HVHwCx0;7E[>o]w5Y֣!G0Lc!es[l}_4ud/:=9+JŲ0Zrt<xP"5= r 8@GF/ny%Yu|fb@Rϩ{;VP$@86xdsgdAűK Cm6*Lb):{IEb5$|1>mCk:|kYEcea Mw"L9)^Usډ*;tb;i\Zn}{~^[/!k3PȪ)&@_Uu!UYf` $R01ҍ[YtZ^0sh,͖%kzɾDB0!)9^p ~GS`=&MYgVCcU  ,g+[6 `Q!Dh8wCel~ce$6EbQ0Aep^V59i(ܨdCkF}dD%6Iɺ.w-nuSlH@+RR;RTK[DXM[VO/nˍmf_ ӆ1N6D59k dl2222ݸw8wq2&+G<يm&LV "2&%rJ%rj º|K$CLyF+&$aʎa f0+׌kTEMuU۫ooPj~y'ժ*kNdr/ߴ=kQxԪ%ᬄ%JT>)UmWW \qѬh4`AϰLs``XgǾP#FaQa".mlt@)(WC(}J8klsEq8 ֖UX%ʔد!<: hM5R8[m/j=kǷ"W滯ڱ6J坋z_oVTۥfM yCQ9JBLZaIzlݽ9Lgl;Ö1Kh^`T½1Z] [$fex`u/-J!qxl"knd[3AeB Ck&/ aåЍp٫ڏFU=T<&ZEkҞ[ymHED'WJm/6ӎ7yŋ096ʹYx]>?>];HFEZ r~WbE .(u~tD^i~[ڛ'nȉ˺PcxMDdO~dsz#N4'>z4hӇMxs7N6/ߥz5/wq2> Xl^״vdK4kHPG1~_Ois'?GV(OQ4Fô~ ~z3vTFͿ{oXvnS_fMvM_HR]?/ߧ趭IDx~dP=\5|;VÎ^7Bj6{=j5:ig{Lw?Ԃ6;vWH˲"z>j5[o$No-^DDDwHR:tUUp1?'93_~.,F*_uZM}]J1G˷o}w~:6DV>H羖h1b>_ӷ? 8}l ˫͎F?4F 1~_N.dfY~_O‡tO6uaZ׿SKk2?-1O_c?"~?;WXGo v>q,6*oofb#v%̘YLz~j.>{o{Z5g.Gd~_ѭ;zGZLzlibcommons-digester-java-1.8.1.orig/xdocs/cvs-usage.xml0000644000175000017500000000330311226450007023036 0ustar twernertwerner Source repository Commons Documentation Team

Apache Commons Digester is hosted on the Apache subversion repository.

The project URL is:
http://svn.apache.org/repos/asf/commons/proper/digester/trunk

The best way to view the repository is via the subversion viewer.

The alternative is to use the native subversion display.

libcommons-digester-java-1.8.1.orig/xdocs/download_digester.xml0000644000175000017500000001657011226450007024650 0ustar twernertwerner Download Commons Digester Commons Documentation Team

We recommend you use a mirror to download our release builds, but you must verify the integrity of the downloaded files using signatures downloaded from our main distribution directories. Recent releases (48 hours) may not yet be available from the mirrors.

You are currently using [preferred]. If you encounter a problem with this mirror, please select another mirror. If all mirrors are failing, there are backup mirrors (at the end of the mirrors list) that should be available.

[if-any logo][end]

Other mirrors:

The KEYS link links to the code signing keys used to sign the product. The PGP link downloads the OpenPGP compatible signature from our main site. The MD5 link downloads the checksum from the main site.

For more information concerning Commons Digester, see the Commons Digester web site.

libcommons-digester-java-1.8.1.orig/xdocs/issue-tracking.xml0000644000175000017500000001327111226450007024076 0ustar twernertwerner Commons Digester Issue tracking Commons Documentation Team

Commons Digester uses ASF JIRA for tracking issues. See the Commons Digester JIRA project page.

To use JIRA you may need to create an account (if you have previously created/updated Commons issues using Bugzilla an account will have been automatically created and you can use the Forgot Password page to get a new password).

If you would like to report a bug, or raise an enhancement request with Commons Digester please do the following:

  1. Search existing open bugs. If you find your issue listed then please add a comment with your details.
  2. Search the mailing list archive(s). You may find your issue or idea has already been discussed.
  3. Decide if your issue is a bug or an enhancement.
  4. Submit either a bug report or enhancement request.

Please also remember these points:

  • the more information you provide, the better we can help you
  • test cases are vital, particularly for any proposed enhancements
  • the developers of Commons Digester are all unpaid volunteers

For more information on subversion and creating patches see the Apache Contributors Guide.

You may also find these links useful:

libcommons-digester-java-1.8.1.orig/xdocs/style/0000755000175000017500000000000011226450007021560 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/xdocs/style/project.css0000644000175000017500000000010211226450007023731 0ustar twernertwerner@import url("http://commons.apache.org/style/commons-maven.css"); libcommons-digester-java-1.8.1.orig/src/0000755000175000017500000000000011126627037020077 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/site/0000755000175000017500000000000011226450007021033 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/site/resources/0000755000175000017500000000000011126627036023054 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/site/resources/images/0000755000175000017500000000000011226450007024312 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/site/resources/images/logo.png0000644000175000017500000003046311226450007025766 0ustar twernertwernerPNG  IHDR,dcbKGD pHYs  ~tIME*Dv IDATx}y\SI yUm~}-n"ݬ w뫯ֺUX\֥kˎh &AQ$Ǽo87|B2w9eAE& 2<>>Z600PрzI޽9 j@KMrHIIn}||9r|||ZZZ~~>1$$$,]~)%^z}rr2 /en ^Z/ݻwSQԁprdqNP>K6m|||6|+WܻwbXVZe˖9 hO~ժv5bxpǎUUU555IIIAAARZ@.~"s te˖ỪN6*??֬Yv!EvG)))v[M_~AlrrYylUUյkfΜi˶mVYYI.L00oXXXPxc܇`̘1ݻwΟ??l0[l{neee]ONI}ޔZlllyyTt:]TTB\\l{i(IIlƘ7"S6RRRf͚%xl6/^eϟ_ZZ ェ"##RG: ܶm[yyl.--ݼy?% 9#FHWVV?BX 6o\VVVQQQUUeC_ĉHl6;noӀa||}(44ق֭[l3deeeR^2,,l6ܾ}֭[(>w\FaWׯ_~=<5eʔ-[DFFr2o߆/Zt[nݹsl6K4%hj4wߺud2 6;w. OO7nqDR;wR:z~oݺUZZJbTWW/^b0ƺvzС[nF^12Ɔzypn2 ɞڵkF}b"0nܸ"Ι3b{үȤ //oժUr~~~aaaYY:-p%%%jNk׮l&;; .Çs₦eff޼yd2\~K.sժUzzCV--- h4LG|Ng4ܹS^^ބ3)>gddj2 RT*^^^֭çfs֭۵k'BP( PRs΅G c /^|gڷo/6}K.w(X,77ldȑ# n޼9dU~ Zc ^o>òeƎۼysƘj7!!ەuҥo7@m۶_F#  z eeuAZBB3DQP(ӧOrYYY~~>x *X`6l6/Yd͛7Vm۶ iX]T*BBBChJΟ?ũSbT*IԿO8rH0u-ZTTTJZV>,7x1p8{lu„ 0sZ @/,// foWSNχe "T*'''n۩SE 0t:]ee% =h$Ŝ1c+-l>urrG={v^***4e燘FV(QQQhC}'P`jyȑ#IIIHuu5lQ UJ) rrr94!(@tvv9qR 7%i8ն@]ll,-ZԢE BG}.W(NNNңG+F1::zuE޲eXV...nnn=z]Te]]]Ǐ%;0\>G*Rj5vPZhq=@]y@kYb"`sA@如uqq&<&([r|dɜUDGGC=T*US~1ݻw;r  >3gϞȸpB~pT}@Ϗ9cTnѣXc' .2AAM#Kph!3P3 8@IiBB:JX`C UaaalNNN^^sƤa RzF`C?~LL <)$tBUT=zංN:mK$3F:dzsѢEF@ln{@qlp͕ѓѱ\f\]]jJ2 2II!ݻs\eee(:|V#0(m`_6T2t8Z)uY,@1VzJgkRoNN7е(*FWFj$RY ׯLGhv{igQA5LD@#l֬Y͛7otJ$y 9UFְ`Ʃ:i-N5 vP#A)RRSS8 +n;h4y .&ŋ:C>uT>ëWJ'u$ĜCf)8'N4d#tAG}aY&h6٫w^A4FR6p@ r4Jûx\\܄ Y^[|9NѦu!t. dPJǏS,O J٣?9ޟh5ee#%=`W߿7̙ /\v B:k ?Oh49fS{>vww9ccxW/,XFșC>:(((99?g׮]W0x>ǎyC0#@i"ɓ'6po:tb]yK.CY'ؿam'NO?=Cq?+W%Njw;2Bn+iА$X0@%W~wTW:ug8֕TdgWћ5kֶm?ĉ`0^K!hv[nM=sLNN굜#GRʙ3gcu )cn(d2L&+mժ_mFZ|9ҟ{UV-Y9rԑjZ~4#Gܹs'UϞ=vq`Y|o+ @׮Xmۗ_$TdK7oO >|رl4!&6`XϜZ5L/Iinɓ ^ך8MywFaʔ)jlz`|-`w( t0{Z`'MD9u)ɣPӧsM'NxSSS t۶m_GIر`0`]?^^^iS(!t=b2n%XZg1BeMa}vcǎ4IAq`'ֹs>h׮]v튏5kV6mҶmZjEPzP6m>cR?g8ۇ58G_ "668YbEAA:A.Ben:Xge80UV\TT0H  ExxxLL7n]wy뭷x+V8O~+ uáD3gfΜIsAmǃIk4ÇlRE>GFbi~UVVr*3N*cĉ]2Q9dtI˗S3gH)ۑ&ǀɓ`ܸQdm@V{M60`6w_|EJJ ٳgnZi4-[} |M>Ymv8h |tСk֬d=h;AWQQq &`m"""}(j9Hݻk׮ݼy3n#u6Z}7n޽swwرo^VgffEf4m۶򊋋dww>}?sڵؽ{7;vYՎ5i߾}iiiR}} ٳgv휝 wر_~mڴٳgĝ(555IIIɱ+XF3uI&i暚bdeeF'60==}q*saaa?Jzzb9tcߟvh4'O~bqrre<^hi(o`UUUW^MOO?vD9www__~BGqxlgRa6333'''77BR j^^^*ժP([7|ڎ\={Tk֬`^V;c @"Rj=z􈎎vQ0=]RmڴF1UC|W1(ufD2eJϞ=qPw6???++رcBjZ?4 ƢpByժUTVv_i&WWל+WR=K &Mٳ'OZZSO=E Ϝ9c0TajjjVWW3p[1zXPnT/CܷgX9 DEi<@;s1):ݻPflM0'ŀlZJ e$nSd XVS ]q$ރjwiX1) Z Rm X,h 1[v>*Jԥz(u8fy+-1Z(5|ncqEQx;>101rV EЪ2"c72+m( d@Va+sm!e0Q?p2 BҾPja哾Q&Ibv%c 0ĮTMxZؠ a`Qh]qj?R+N@JQ@"Dž0i ]_W=Cѩrl}Fh J8D@d?iHC"#l 0)Y<;@V8,-g!Ҏnfg4S}zI{Ӄ  m=JGPKM$K%+v̤ZB)`wZ%y!TᨆQZa*j`Ȃmk/au!sVĈd$ |Z]rc"$(9EdkWQ҆8nŸȰc,d{_MϮR J݄F5=x )3 Yo+Z˟@_6]K!mKq=?d2</_fΜ)-X{yw=c zW.~<5&))IՊ&?jd}<$$$@"ٳSRRpi3Vk||<>NdC ehlн{w^viKܡ{///ȹkM{ IHNNˣU!}A "4f„ x"Ç >6M+) z1#֭[-[<`|M{?G8 rfԭ[7___<< 8̖+IMc8owq I 1%HM\5 -i Gz=\0*ڃ] GG'A 4q`F4-Pfؘ+a8EQRe? #GJRFi>zP  g& $w"}ATTذZXa̶FȀ^yf!N:յkWfSM<`e(>>>|7zh`1d/SSS9f>oo֭SBBh+px$55UٕU=R;QATTw.cl/_ o-Zqׯ^tiZ1ZZZZZZZVVu(FN1bc,(((((采/]4))-¶ҥKSRR{K. o!Cܾ}l62:oa͘1ڵkwnٛ5kψ#פ$̙39ICA6F YAw {ŋ34 '\hQJJ ޽{KÇm@/>>>>>3gܵkΝ;.]JFk`sYTeYUU}vp"0ꬶcd 4ڵk.]x+Wt:d*..S]]رkmpDl2+UWWرC*J-Tρlp:*)A-)| &'''%%={6$$dȐ!Æ 8\$ @K XA(x#w b -Z" D|||Є… $%%q w5xhhl:]ʭ["吐s;wz͛P.85(8oiE 9aaa.]bA;klfsiiiqqqqq۷{ ,HJJϜ9sUSNEaÆݾ} וϝ;Gߕs֭;wж_]&eΝ;qDFF"P X`;wA"C=،_v`0K,A,))sNdd$.***..GCyhhM@!C o޼ s#ai_˛F ۷oBN:w燏U[ncX "M1Z7DO?4 7x1"4VUU 4Y>nX6Vyz'N@7c$C O)Sp 8$$$w8O/ڷo r3gNbbbttի( Ҿ1Bjj*E5pOٝupVZNUUghpF_J'11"+WS ՝;w-ݻw/߯XL\-˸qcH@(֮2)((Xz5clXÊ3B=, 5zh[QQK/S7^R;(#̚5 >a lv&}LWMIDATX,(B(nH1@.]8:vѧ( ۷~twܸ֮qvС`D[h>N:Zl B9j.fbb"gn4 yJSF[QQǰh?[,lt:.c0~Ft{QB9V@Xw}EQAjFF駟6VJqÿ&L?  1vXaݺuiG옙 ۷EPYYE-Ձ2i%4(bD2JBrB$%J%~떌_~rP1@.x(,,ѝԆVju[,]Mhqƍ7;6""¢ԀZ V.=pEf ~ n2:GCWM` ҪҒ9aQq8:i445WPG +Vgrɨ)F؈Ͳ7ʢ;:Os'O:t޽'NxСSs3$uQ.O5OVOpա#G'P7&&fHiiil8OAo קŕR GI !1HS ĢS@nܹ#G<`%Kڵݫ~С`llUr= p(hyDDL&7l@テ洒 Rn݂;a2%;v-޵zj4B̄NӲeKMF3~F#~\^bʼn'EQ 3f̴iڴiCGJ8Fa7|b D4"曐 J`M&X*m$ ǢQb4d2qqqcFFF^ݻx@Tn@HKKȐڡKqq1ݻ7dxr)۶mC!=z/dyzzΛ7͙3'**`0~AA'|[oiEq3mn$\4"݊V!K g̘ѬY3777Zydꫯjjj Kf͚5kF 0Z].]`vMZVV%5NS !l?ƘF9v?^kW_1*ou>j(wwoݺ5--g4{&t[TFF矽 }3ݰaTj\/F؈:6ݻ(x{{.N:իW^^^^h z᧞z М{@V֯_hhί^:d́ Ço3o޼nݺALff֭[ׯ… a ƫ7oCCC0Vkuuq=ꀽP8+M۷/fLL̋/P(j5!\ZlFظ|?*///rߌO4IDDD$&&FDD۷Ǥ .p>/=s ʕ+W\pn=i9]nݖ-[L&2dȤI|||% ЩSy扢VEnݺ=c`17T*ռy֯_:t5k?,oByMMMeeeZZ… Ϝ9õhРA333sڵpȃ«ڱcG??@4B.U1Fظ@xV-++h44iРA0uBPMƘJ*))8nݺ=h BG-[ 9vX]zyyV!]J\XvIbÇW,0NNNh(tԪ^xe˖J6\\\SzcJۻ[n@s֑ӧO t5gAj``8qN I8  9WWW\MTVVZ,Aa$|W$+=Dʷ jZ rDDQUCN.%J31y6^ %\zQ*8pfK{}kP 0qNmlGC;99MP!E ¥JqC>Pt(ݻw̘1f޼yx&,_JK/u!88wyyy;wߏ%`_6Hk #|ꒀGz/PJ`v6r(ڒ~hllKt FH`xt c`cR LX񋌌YF$բE fllR$=#] +)ڎ"Unp7譨[@s.EPМ*PŒ$&P6e#ltV1412DD@舀ѕ]5BFVknn.c i"rT*aXKbQ@J> A *}:喦Km:Nc0MhH acT8X,y_fsIDMYipq/##cҙ]Zl;.䨇JW!͘AB"ܚD6Iurr¨ŝiE-vcMP'#GT=t_-acD=#'[]&I!׬YӪU1cƈPV>cLӧ3}]jm4:t)//={@R*[5,T*H1+)F_VdsJ-z"FwpZrHnwGΩr 6j@>ER R-]kA"{=ztù8q_|!rf}H&^kg{R##n a:jN'F$Nݙ]hF9j$?IDDQX,)))| [#ȉ' WZ+ԨP9)]tE b^Q#RaJ#G UJ=-Ү0RM 68piX m IX?z֮ԅG}.a@6Pb9wضVN&0 Q lHyu1pXIw&Q.}F]փP+̅k [ M7dh8FX`[m4o3 KWp}l;(m%ܣ1n 4-@6hXc~L]wHȍBe |0P`vG\Qu oQXҀL.DVP_vc2 ?d]IENDB`libcommons-digester-java-1.8.1.orig/src/site/resources/images/logo.jpg0000644000175000017500000002565311226450007025767 0ustar twernertwernerJFIFHHCreated with The GIMPCCN"  F  !1AQq 2a"#7BRue$%3b 8!1AQa"q2B#$34 ?OѣFu4jy'GGUѪnSFOGGi~sUѣFJttthѣGGF4tthѣGGF4tthѣGGF4tthѣGGF4tthѣGGF4tthѪ9vEhY8xZܫ#v@7G qc/w5|6'ZdE;*_GY~P /|Tйw,~ > wql6H(1 6K75"\٩SէW/__^B˯ 5f$Lf p(um#I\RVuQ+aRIKK Pd-e/ eY2 %rM:j"О3]c\m6YSƙ>@oq[N[C%t<̃i 2(Sm&<KN tN- u_Ӏ 2mDGXKi5d{ Ù!NFCqG ^tuM6<rD`\jyW# qe1r9Ȭqq74(/#[k:u^^bp\wʓk I`ǟVw'V.*&؈bR4t0:rW =+Rؒ="!!0_ָ2!mӳnp]R$[ZHm"/I; ` owFdX*xøķbd8َX:VmXf5*s3dbly4JdSxRYM⩝^4֗.T5d!=ĞIM]W*׆y0C.9OhگpUo@"ʀDt#^u01ٖ]k.oR N:"k$s\3 z^׵58mXw5-l*%亍5ʯ2LC X5@ ){^% I!ʽAjK$llXbK`)kdR/rKl-z4 "11b/K*f9)~1ו eZͯS%#Lǣ81כ絀&Vf2ULSW}GUGqW^\bk܎XJ$؂(ty F ZѮUMmSo>̵5]u 隒%UL*p[a*\Ez((Ru I66LmX$I} O \ɛ̟ }n+im0FGIW9j"0"#7zƼc]S8e; Woi\̊L3>#Pbi>,\oLY+ 1OZ5k[#ّUHQ⇘lZN7sC4Ө2ЇfcI&œ Gq)L1"c,sJ+6긦UjRz-)jF4s$5RLNIc'4ڥ4Y~pSWpk Wkb"'z-` ˌr3<ËoO:;-*! EqBB5 ޓ 5fKF16,|zzH-'m_kr)5UMܖ)6c[R/KF(-PO[=짛[+{u S 9W5g9J9vPǝZ6xFoRQmUF{hǖ-!H1:ݤQ`%޾Q'$fTlv%p#b)O&IOw5sV$;**5Qs:ݣs*q#l>dG9$9 <C%zɑ+Ъ)2bia\(&dk#C(2r*mb2 suQU NWHfQ[#>Ms%:PҴE2[%̾'Nh2ciumB3K*cRs4\C'_“twrDĬ=Ulkqעydapz*Ys8'$X"G55p(멪eLhCG0Onۯuwq 9gk;I*Ir֨ " o P#\G )J洼Eñ3MWVF Q!"_%[6et lcl^'ӟH\I#WO$6 HZIdkY ٯuK-ҷn@YӬOzZ.SQ 6` 5 J;*hs6-3BWd-r kϟ9JHu-Z-'vЇYW8~9WźbAPZL47 M1dJ3yD2:>+϶-#F6Sd"lމϞEU])\߿V'6\FQ P{`l,M"4w6,AIlF9ưZel;gM,:u+V#%E$㘒ǬvB)$Fx&qf㭧U<#+k9-nf2V"ʙe v \ixJƥX+[l8ج˫U b1Uj/*XT-{&<{F1!c"{ֵEsDj""jw,\~J㱫(x!l.D?)Y<"Svr%[ʻz~;omgb5G_2;+qb^ÈY*Ʋm`UuD˻s+ :NygAki+ Um*+쳈aJb˺z~~]\oyy87mԛ6b{6~q,P3∟Yo;uYv[$c;G#Lf5E~k֨*{SRQ1]棈|'ģb866k3\I_(Bȫc k6G9ʒpʽn9}hg\PTޟrwZ5HrM<U;kNuTZ EtJ\J|+ϿLxËY Y 曆\aذ_a,sY" GyNwS .Ecؓhq;蕭ɮ8jv8IҸ(f̫y ILbϗg) ΦO5bbzU'QC9*jr@XBc]2ј4aXgoDj;g7ä`3[{6EN]CHtSoR,{5kdc9ƭ"+^ ,b;)≑vÚ״}gevC9:EO)alUJVB2 /Y+FLksaw}mӊ !ؕխ\wkS8|,d8m)me3`MiW{b! V $FC^ [ t;JyjkzİJVG ?H?(:ȹ o"h- ؎jNRP1ujί Olj4V3{;*KNhYEi([;^]IGFM.zsvVO 9+GSKYa5;dUB/Td',>a'm60@U+noT1qr.M?Gg(d9 $Nh岏u$E'ڧs_0-xؑ}u7{_`~99%`'Qv)mhn-뙳\5F [%^D,7f9DnxG0<׍6S!Ã+Zй eL7(Bdҥ B+'rj#dJbk iFuj 7,Yx7^I9<1V>ݯbKNREVZyl$;?t)k>SʡBpLeb c<9P Ƙa/HVHwCx0;7E[>o]w5Y֣!G0Lc!es[l}_4ud/:=9+JŲ0Zrt<xP"5= r 8@GF/ny%Yu|fb@Rϩ{;VP$@86xdsgdAűK Cm6*Lb):{IEb5$|1>mCk:|kYEcea Mw"L9)^Usډ*;tb;i\Zn}{~^[/!k3PȪ)&@_Uu!UYf` $R01ҍ[YtZ^0sh,͖%kzɾDB0!)9^p ~GS`=&MYgVCcU  ,g+[6 `Q!Dh8wCel~ce$6EbQ0Aep^V59i(ܨdCkF}dD%6Iɺ.w-nuSlH@+RR;RTK[DXM[VO/nˍmf_ ӆ1N6D59k dl2222ݸw8wq2&+G<يm&LV "2&%rJ%rj º|K$CLyF+&$aʎa f0+׌kTEMuU۫ooPj~y'ժ*kNdr/ߴ=kQxԪ%ᬄ%JT>)UmWW \qѬh4`AϰLs``XgǾP#FaQa".mlt@)(WC(}J8klsEq8 ֖UX%ʔد!<: hM5R8[m/j=kǷ"W滯ڱ6J坋z_oVTۥfM yCQ9JBLZaIzlݽ9Lgl;Ö1Kh^`T½1Z] [$fex`u/-J!qxl"knd[3AeB Ck&/ aåЍp٫ڏFU=T<&ZEkҞ[ymHED'WJm/6ӎ7yŋ096ʹYx]>?>];HFEZ r~WbE .(u~tD^i~[ڛ'nȉ˺PcxMDdO~dsz#N4'>z4hӇMxs7N6/ߥz5/wq2> Xl^״vdK4kHPG1~_Ois'?GV(OQ4Fô~ ~z3vTFͿ{oXvnS_fMvM_HR]?/ߧ趭IDx~dP=\5|;VÎ^7Bj6{=j5:ig{Lw?Ԃ6;vWH˲"z>j5[o$No-^DDDwHR:tUUp1?'93_~.,F*_uZM}]J1G˷o}w~:6DV>H羖h1b>_ӷ? 8}l ˫͎F?4F 1~_N.dfY~_O‡tO6uaZ׿SKk2?-1O_c?"~?;WXGo v>q,6*oofb#v%̘YLz~j.>{o{Z5g.Gd~_ѭ;zGZLzlibcommons-digester-java-1.8.1.orig/src/site/site.xml0000644000175000017500000000543411226450007022527 0ustar twernertwerner Commons Digester /images/logo.png /index.html libcommons-digester-java-1.8.1.orig/src/test/0000755000175000017500000000000011126627031021050 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/test/org/0000755000175000017500000000000011126627031021637 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/test/org/apache/0000755000175000017500000000000011126627031023060 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/0000755000175000017500000000000011126627031024533 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/0000755000175000017500000000000011226450007026337 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/TestBean.java0000644000175000017500000001447011226450007030715 0ustar twernertwerner/* $Id: TestBean.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * General purpose test bean for Digester tests. * * @author Craig R. McClanahan * @version $Revision: 471661 $ $Date: 2006-11-06 03:09:25 -0500 (Mon, 06 Nov 2006) $ */ public class TestBean { // ------------------------------------------------------------- Properties /** * A boolean property whose initial value is true. */ private boolean booleanProperty = true; public boolean getBooleanProperty() { return (booleanProperty); } public void setBooleanProperty(boolean booleanProperty) { this.booleanProperty = booleanProperty; } /** * A double property. */ private double doubleProperty = 321.0; public double getDoubleProperty() { return (this.doubleProperty); } public void setDoubleProperty(double doubleProperty) { this.doubleProperty = doubleProperty; } /** * A boolean property whose initial value is false */ private boolean falseProperty = false; public boolean getFalseProperty() { return (falseProperty); } public void setFalseProperty(boolean falseProperty) { this.falseProperty = falseProperty; } /** * A float property. */ private float floatProperty = (float) 123.0; public float getFloatProperty() { return (this.floatProperty); } public void setFloatProperty(float floatProperty) { this.floatProperty = floatProperty; } /** * Integer arrays that are accessed as an array as well as indexed. */ private int intArray[] = { 0, 10, 20, 30, 40 }; public int[] getIntArray() { return (this.intArray); } public void setIntArray(int intArray[]) { this.intArray = intArray; } private int intIndexed[] = { 0, 10, 20, 30, 40 }; public int getIntIndexed(int index) { return (intIndexed[index]); } public void setIntIndexed(int index, int value) { intIndexed[index] = value; } private int intMultibox[] = new int[0]; public int[] getIntMultibox() { return (this.intMultibox); } public void setIntMultibox(int intMultibox[]) { this.intMultibox = intMultibox; } /** * An integer property. */ private int intProperty = 123; public int getIntProperty() { return (this.intProperty); } public void setIntProperty(int intProperty) { this.intProperty = intProperty; } /** * A long property. */ private long longProperty = 321; public long getLongProperty() { return (this.longProperty); } public void setLongProperty(long longProperty) { this.longProperty = longProperty; } /** * A multiple-String SELECT element. */ private String[] multipleSelect = { "Multiple 3", "Multiple 5", "Multiple 7" }; public String[] getMultipleSelect() { return (this.multipleSelect); } public void setMultipleSelect(String multipleSelect[]) { this.multipleSelect = multipleSelect; } /** * A nested reference to another test bean (populated as needed). */ private TestBean nested = null; public TestBean getNested() { if (nested == null) nested = new TestBean(); return (nested); } /** * A String property with an initial value of null. */ private String nullProperty = null; public String getNullProperty() { return (this.nullProperty); } public void setNullProperty(String nullProperty) { this.nullProperty = nullProperty; } /** * A short property. */ private short shortProperty = (short) 987; public short getShortProperty() { return (this.shortProperty); } public void setShortProperty(short shortProperty) { this.shortProperty = shortProperty; } /** * A single-String value for a SELECT element. */ private String singleSelect = "Single 5"; public String getSingleSelect() { return (this.singleSelect); } public void setSingleSelect(String singleSelect) { this.singleSelect = singleSelect; } /** * String arrays that are accessed as an array as well as indexed. */ private String stringArray[] = { "String 0", "String 1", "String 2", "String 3", "String 4" }; public String[] getStringArray() { return (this.stringArray); } public void setStringArray(String stringArray[]) { this.stringArray = stringArray; } private String stringIndexed[] = { "String 0", "String 1", "String 2", "String 3", "String 4" }; public String getStringIndexed(int index) { return (stringIndexed[index]); } public void setStringIndexed(int index, String value) { stringIndexed[index] = value; } /** * A String property. */ private String stringProperty = "This is a string"; public String getStringProperty() { return (this.stringProperty); } public void setStringProperty(String stringProperty) { this.stringProperty = stringProperty; } /** * An empty String property. */ private String emptyStringProperty = ""; public String getEmptyStringProperty() { return (this.emptyStringProperty); } public void setEmptyStringProperty(String emptyStringProperty) { this.emptyStringProperty = emptyStringProperty; } } ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/WDRulesWrapperTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/WDRulesWrapperTestCase.java0000644000175000017500000001057111226450007033530 0ustar twernertwerner/* $Id: WDRulesWrapperTestCase.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.List; import junit.framework.TestCase; /** * Test case for WithDefaultsRulesWrapper * * @author Robert Burrell Donkin * @version $Revision: 471661 $ $Date: 2006-11-06 03:09:25 -0500 (Mon, 06 Nov 2006) $ */ public class WDRulesWrapperTestCase extends TestCase { /** Base constructor */ public WDRulesWrapperTestCase(String name) { super(name); } public void testClear() { // test clear wrapped WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new RulesBase()); rules.add("alpha", new TestRule("Tom")); rules.add("alpha", new TestRule("Dick")); rules.add("alpha", new TestRule("Harry")); assertNotNull("Rules should not be null", rules.rules()); assertEquals("Wrong number of rules registered (1)", 3 , rules.rules().size()); rules.clear(); assertEquals("Clear Failed (1)", 0 , rules.rules().size()); // mixed rules.add("alpha", new TestRule("Tom")); rules.add("alpha", new TestRule("Dick")); rules.add("alpha", new TestRule("Harry")); rules.addDefault(new TestRule("Roger")); assertEquals("Wrong number of rules registered (2)", 4 , rules.rules().size()); rules.clear(); assertEquals("Clear Failed (2)", 0 , rules.rules().size()); rules.addDefault(new TestRule("Roger")); assertEquals("Wrong number of rules registered (3)", 1 , rules.rules().size()); rules.clear(); assertEquals("Clear Failed (3)", 0 , rules.rules().size()); } public void testRules() { // test rules WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new RulesBase()); rules.add("alpha", new TestRule("Tom")); rules.add("alpha", new TestRule("Dick")); rules.addDefault(new TestRule("Roger")); rules.add("alpha", new TestRule("Harry")); assertNotNull("Rules should not be null", rules.rules()); assertEquals("Wrong order (1)", "Tom" , ((TestRule) rules.rules().get(0)).getIdentifier()); assertEquals("Wrong order (2)", "Dick" , ((TestRule) rules.rules().get(1)).getIdentifier()); assertEquals("Wrong order (3)", "Roger" , ((TestRule) rules.rules().get(2)).getIdentifier()); assertEquals("Wrong order (4)", "Harry" , ((TestRule) rules.rules().get(3)).getIdentifier()); } public void testMatch() { // test no defaults WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new RulesBase()); rules.add("alpha", new TestRule("Tom")); rules.add("alpha", new TestRule("Dick")); rules.add("alpha", new TestRule("Harry")); rules.addDefault(new TestRule("Roger")); rules.addDefault(new TestRule("Rabbit")); List matches = rules.match("", "alpha"); assertEquals("Wrong size (1)", 3 , matches.size()); assertEquals("Wrong order (1)", "Tom" , ((TestRule) matches.get(0)).getIdentifier()); assertEquals("Wrong order (2)", "Dick" , ((TestRule) matches.get(1)).getIdentifier()); assertEquals("Wrong order (3)", "Harry" , ((TestRule) matches.get(2)).getIdentifier()); matches = rules.match("", "not-alpha"); assertEquals("Wrong size (2)", 2 , matches.size()); assertEquals("Wrong order (4)", "Roger" , ((TestRule) matches.get(0)).getIdentifier()); assertEquals("Wrong order (5)", "Rabbit" , ((TestRule) matches.get(1)).getIdentifier()); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/simple.dtd0000644000175000017500000000145511226450007030332 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/EBRTestCase.java0000644000175000017500000004233211226450007031252 0ustar twernertwerner/* $Id: EBRTestCase.java 472840 2006-11-09 10:18:34Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.Iterator; import java.util.List; import junit.framework.Test; import junit.framework.TestSuite; /** *

Runs standard tests for RulesBase as well as tests of extensions. * * @author Robert Burrell Donkin * @version $Revision: 472840 $ $Date: 2006-11-09 05:18:34 -0500 (Thu, 09 Nov 2006) $ */ public class EBRTestCase extends RulesBaseTestCase { // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public EBRTestCase(String name) { super(name); } // -------------------------------------------------- Overall Test Methods /** *

This should be overriden by subclasses. * * @return the matching rules to be tested. */ protected Rules createMatchingRulesForTest() { return new ExtendedBaseRules(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(EBRTestCase.class)); } /** * Basic test of parent matching rules. * A parent match matches any child of a particular kind of parent. * A wild parent has a wildcard prefix. * This method tests non-universal wildcards. */ public void testBasicParentMatch() { // clear any existing rules digester.getRules().clear(); assertEquals("Initial rules list is empty", 0, digester.getRules().rules().size()); // Set up rules // since these are all NON-UNIVERSAL matches // only expect one match at each stage digester.addRule("alpha/beta/gamma/delta", new TestRule("exact")); digester.addRule("*/beta/gamma/epsilon", new TestRule("wild_child")); digester.addRule("alpha/beta/gamma/?", new TestRule("exact_parent")); digester.addRule("*/beta/gamma/?", new TestRule("wild_parent")); List list = null; Iterator it = null; // this should match just the exact since this has presidence list = digester.getRules().match(null, "alpha/beta/gamma/delta"); // all three rules should match assertEquals("Testing basic parent mismatch (A)", 1, list.size()); it = list.iterator(); assertEquals("Testing basic parent mismatch (B)", "exact", ((TestRule) it.next()).getIdentifier()); // we don't have an exact match for this child so we should get the exact parent list = digester.getRules().match(null, "alpha/beta/gamma/epsilon"); // all three rules should match assertEquals("Testing basic parent mismatch (C)", 1, list.size()); it = list.iterator(); assertEquals("Testing basic parent mismatch (D)", "exact_parent", ((TestRule) it.next()).getIdentifier()); // wild child overrides wild parent list = digester.getRules().match(null, "alpha/omega/beta/gamma/epsilon"); // all three rules should match assertEquals("Testing basic parent mismatch (E)", 1, list.size()); it = list.iterator(); assertEquals("Testing basic parent mismatch (F)", "wild_child", ((TestRule) it.next()).getIdentifier()); // nothing else matches so return wild parent list = digester.getRules().match(null, "alpha/omega/beta/gamma/zeta"); // all three rules should match assertEquals("Testing basic parent mismatch (G)", 1, list.size()); it = list.iterator(); assertEquals("Testing basic parent mismatch (H)", "wild_parent", ((TestRule) it.next()).getIdentifier()); // clean up digester.getRules().clear(); } /** * Basic test of universal matching rules. * Universal rules act independent. */ public void testBasicUniversal() { // clear any existing rules digester.getRules().clear(); assertEquals("Initial rules list is empty", 0, digester.getRules().rules().size()); // Set up rules // set up universal matches against non-universal ones digester.addRule("alpha/beta/gamma", new TestRule("exact")); digester.addRule("*/beta/gamma", new TestRule("non_wild_head")); digester.addRule("!*/beta/gamma", new TestRule("universal_wild_head")); digester.addRule("!alpha/beta/gamma/?", new TestRule("universal_wild_child")); digester.addRule("alpha/beta/gamma/?", new TestRule("non_wild_child")); digester.addRule("alpha/beta/gamma/epsilon", new TestRule("exact2")); digester.addRule("alpha/epsilon/beta/gamma/zeta", new TestRule("exact3")); digester.addRule("*/gamma/?", new TestRule("non_wildhead_child")); digester.addRule("!*/epsilon/beta/gamma/?", new TestRule("universal_wildhead_child")); List list = null; Iterator it = null; // test universal wild head list = digester.getRules().match(null, "alpha/beta/gamma"); assertEquals("Testing universal wildcard mismatch (A)", 2, list.size()); it = list.iterator(); assertEquals("Testing universal wildcard mismatch (B)", "exact", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing universal wildcard mismatch (C)", "universal_wild_head", ((TestRule) it.next()).getIdentifier()); // test universal parent list = digester.getRules().match(null, "alpha/beta/gamma/epsilon"); assertEquals("Testing universal wildcard mismatch (D)", 2, list.size()); it = list.iterator(); assertEquals("Testing universal wildcard mismatch (E)", "universal_wild_child", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing universal wildcard mismatch (F)", "exact2", ((TestRule) it.next()).getIdentifier()); // test universal parent list = digester.getRules().match(null, "alpha/beta/gamma/zeta"); assertEquals("Testing universal wildcard mismatch (G)", 2, list.size()); it = list.iterator(); assertEquals("Testing universal wildcard mismatch (H)", "universal_wild_child", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing universal wildcard mismatch (I)", "non_wild_child", ((TestRule) it.next()).getIdentifier()); // test wildcard universal parent list = digester.getRules().match(null, "alpha/epsilon/beta/gamma/alpha"); assertEquals("Testing universal wildcard mismatch (J)", 2, list.size()); it = list.iterator(); assertEquals("Testing universal wildcard mismatch (K)", "non_wildhead_child", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing universal wildcard mismatch (L)", "universal_wildhead_child", ((TestRule) it.next()).getIdentifier()); // test wildcard universal parent list = digester.getRules().match(null, "alpha/epsilon/beta/gamma/zeta"); assertEquals("Testing universal wildcard mismatch (M)", 2, list.size()); it = list.iterator(); assertEquals("Testing universal wildcard mismatch (M)", "exact3", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing universal wildcard mismatch (O)", "universal_wildhead_child", ((TestRule) it.next()).getIdentifier()); // clean up digester.getRules().clear(); } /** * Basic test of wild matches. * A universal will match matches anything! * A non-universal will match matches anything not matched by something else. * This method tests non-universal and universal wild matches. */ public void testWildMatch() { // clear any existing rules digester.getRules().clear(); assertEquals("Initial rules list is empty", 0, digester.getRules().rules().size()); // Set up rules // The combinations a little large to test everything but we'll pick a couple and try them. digester.addRule("*", new TestRule("basic_wild")); digester.addRule("!*", new TestRule("universal_wild")); digester.addRule("alpha/beta/gamma/delta", new TestRule("exact")); digester.addRule("*/beta/gamma/?", new TestRule("wild_parent")); List list = null; Iterator it = null; // The universal wild will always match whatever else does list = digester.getRules().match(null, "alpha/beta/gamma/delta"); // all three rules should match assertEquals("Testing wild mismatch (A)", 2, list.size()); it = list.iterator(); assertEquals("Testing wild mismatch (B)", "universal_wild", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing wild mismatch (C)", "exact", ((TestRule) it.next()).getIdentifier()); // The universal wild will always match whatever else does list = digester.getRules().match(null, "alpha/beta/gamma/epsilon"); assertEquals("Testing wild mismatch (D)", 2, list.size()); it = list.iterator(); assertEquals("Testing wild mismatch (E)", "universal_wild", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing wild mismatch (F)", "wild_parent", ((TestRule) it.next()).getIdentifier()); // The universal wild will always match whatever else does // we have no other non-universal matching so this will match the non-universal wild as well list = digester.getRules().match(null, "alpha/gamma"); assertEquals("Testing wild mismatch (G)", 2, list.size()); it = list.iterator(); assertEquals("Testing wild mismatch (H)", "basic_wild", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing wild mismatch (I)", "universal_wild", ((TestRule) it.next()).getIdentifier()); // clean up digester.getRules().clear(); } /** * Basic test of wild matches. * A universal will match matches anything! * A non-universal will match matches anything not matched by something else. * This method tests non-universal and universal wild matches. */ public void testRootTailMatch() { // clear any existing rules digester.getRules().clear(); assertEquals("Initial rules list is empty", 0, digester.getRules().rules().size()); // Set up rules // The combinations a little large to test everything but we'll pick a couple and try them. digester.addRule("*/a", new TestRule("a_tail")); List list = null; list = digester.getRules().match(null, "a"); assertEquals("Testing tail wrong size (A)", 1, list.size()); assertEquals("Testing tail mismatch (B)", "a_tail", ((TestRule) list.get(0)).getIdentifier()); list = digester.getRules().match(null, "beta/a"); assertEquals("Testing tail wrong size (C)", 1, list.size()); assertEquals("Testing tail mismatch (D)", "a_tail", ((TestRule) list.get(0)).getIdentifier()); list = digester.getRules().match(null, "be/aaa"); assertEquals("Testing tail no matches (E)", 0, list.size()); list = digester.getRules().match(null, "aaa"); assertEquals("Testing tail no matches (F)", 0, list.size()); list = digester.getRules().match(null, "a/beta"); assertEquals("Testing tail no matches (G)", 0, list.size()); // clean up digester.getRules().clear(); } public void testAncesterMatch() throws Exception { // test fixed root ancester digester.getRules().clear(); digester.addRule("!a/b/*", new TestRule("uni-a-b-star")); digester.addRule("a/b/*", new TestRule("a-b-star")); digester.addRule("a/b/c", new TestRule("a-b-c")); digester.addRule("a/b/?", new TestRule("a-b-child")); List list = digester.getRules().match(null, "a/b/c"); assertEquals("Simple ancester matches (1)", 2, list.size()); assertEquals("Univeral ancester mismatch (1)", "uni-a-b-star" , ((TestRule) list.get(0)).getIdentifier()); assertEquals("Parent precedence failure", "a-b-c" , ((TestRule) list.get(1)).getIdentifier()); list = digester.getRules().match(null, "a/b/b"); assertEquals("Simple ancester matches (2)", 2, list.size()); assertEquals("Univeral ancester mismatch (2)", "uni-a-b-star" , ((TestRule) list.get(0)).getIdentifier()); assertEquals("Child precedence failure", "a-b-child" , ((TestRule) list.get(1)).getIdentifier()); list = digester.getRules().match(null, "a/b/d"); assertEquals("Simple ancester matches (3)", 2, list.size()); assertEquals("Univeral ancester mismatch (3)", "uni-a-b-star" , ((TestRule) list.get(0)).getIdentifier()); assertEquals("Ancester mismatch (1)", "a-b-child" , ((TestRule) list.get(1)).getIdentifier()); list = digester.getRules().match(null, "a/b/d/e/f"); assertEquals("Simple ancester matches (4)", 2, list.size()); assertEquals("Univeral ancester mismatch (4)", "uni-a-b-star" , ((TestRule) list.get(0)).getIdentifier()); assertEquals("Ancester mismatch (2)", "a-b-star" , ((TestRule) list.get(1)).getIdentifier()); // test wild root ancester digester.getRules().clear(); digester.addRule("!*/a/b/*", new TestRule("uni-star-a-b-star")); digester.addRule("*/b/c/*", new TestRule("star-b-c-star")); digester.addRule("*/b/c/d", new TestRule("star-b-c-d")); digester.addRule("a/b/c", new TestRule("a-b-c")); list = digester.getRules().match(null, "a/b/c"); assertEquals("Wild ancester match (1)", 2, list.size()); assertEquals( "Univeral ancester mismatch (5)", "uni-star-a-b-star" , ((TestRule) list.get(0)).getIdentifier()); assertEquals("Match missed (1)", "a-b-c" , ((TestRule) list.get(1)).getIdentifier()); list = digester.getRules().match(null, "b/c"); assertEquals("Wild ancester match (2)", 1, list.size()); assertEquals("Match missed (2)", "star-b-c-star" , ((TestRule) list.get(0)).getIdentifier()); list = digester.getRules().match(null, "a/b/c/d"); assertEquals("Wild ancester match (3)", 2, list.size()); assertEquals("Match missed (3)", "uni-star-a-b-star" , ((TestRule) list.get(0)).getIdentifier()); assertEquals("Match missed (4)", "star-b-c-d" , ((TestRule) list.get(1)).getIdentifier()); list = digester.getRules().match(null, "b/b/c/e/d"); assertEquals("Wild ancester match (2)", 1, list.size()); assertEquals("Match missed (5)", "star-b-c-star" , ((TestRule) list.get(0)).getIdentifier()); } public void testLongMatch() { digester.getRules().clear(); digester.addRule("a/b/c/d/*", new TestRule("a-b-c-d-star")); List list = digester.getRules().match(null, "a/b/c/d/e"); assertEquals("Long match (1)", 1, list.size()); assertEquals("Match missed (1)", "a-b-c-d-star" , ((TestRule) list.get(0)).getIdentifier()); list = digester.getRules().match(null, "a/b/c/d/e/f"); assertEquals("Long match (2)", 1, list.size()); assertEquals("Match missed (2)", "a-b-c-d-star" , ((TestRule) list.get(0)).getIdentifier()); list = digester.getRules().match(null, "a/b/c/d/e/f/g"); assertEquals("Long match (3)", 1, list.size()); assertEquals("Match missed (3)", "a-b-c-d-star" , ((TestRule) list.get(0)).getIdentifier()); list = digester.getRules().match(null, "a/b/c/d"); assertEquals("Long match (4)", 0, list.size()); } public void testInstructors() { digester.getRules().clear(); digester.addRule("!instructors/*", new TestRule("instructors")); digester.addRule("!instructor/*", new TestRule("instructor")); List list = digester.getRules().match(null, "instructors"); assertEquals("Only expect to match instructors", 1, list.size()); assertEquals("Instructors expected", "instructors" , ((TestRule) list.get(0)).getIdentifier()); } public void testMiddleInstructors() { digester.getRules().clear(); digester.addRule("!instructors/*", new TestRule("instructors")); List list = digester.getRules().match(null, "/tosh/instructors/fiddlesticks"); assertEquals("No matches expected", 0, list.size()); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test8.xml0000644000175000017500000000166011226450007030073 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/NamespacedBox.java0000644000175000017500000000255111226450007031716 0ustar twernertwerner/* $Id: NamespacedBox.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.Map; /** * Simple class for use in unit tests. A box with a namespaces property * to store the current namespaces as a Map. * * Used by NamespaceSnapshotTestCase. */ public class NamespacedBox extends Box { private Map namespaces; public NamespacedBox() { super(); } public Map getNamespaces() { return namespaces; } public void setNamespaces(Map namespaces) { this.namespaces = namespaces; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Box.java0000644000175000017500000000460711226450007027741 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.List; import java.util.LinkedList; import java.util.Iterator; /** * Simple class for use in unit tests. A box has an ID, and can have * multiple boxes within it. */ public class Box { private String id; private List children = new LinkedList(); public Box() {} public String getId() { return id; } public void setId(String id) { this.id = id; } public void addChild(Box child) { this.children.add(child); } public List getChildren() { return children; } public String toString() { StringBuffer buf = new StringBuffer(); buf.append("[Box] id="); buf.append(id); buf.append(" nchildren="); buf.append(children.size()); for(Iterator i = children.iterator(); i.hasNext(); ) { Box child = (Box) i.next(); buf.append(" "); buf.append(child.toString()); } return buf.toString(); } /** * Return a string containing this object's name value, followed by the * names of all child objects (and their children etc) in pre-order * sequence. Each name is separated by a space from the preceding one. */ public String getIds() { StringBuffer buf = new StringBuffer(); buf.append(this.id); for(Iterator i = children.iterator(); i.hasNext(); ) { Box child = (Box) i.next(); buf.append(" "); buf.append(child.getIds()); } return buf.toString(); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/TestRuleSet.java0000644000175000017500000000652411226450007031434 0ustar twernertwerner/* $Id: TestRuleSet.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * RuleSet that mimics the rules set used for Employee and Address creation, * optionally associated with a particular namespace URI. * * @author Craig R. McClanahan * @version $Revision: 471661 $ $Date: 2006-11-06 03:09:25 -0500 (Mon, 06 Nov 2006) $ */ public class TestRuleSet extends RuleSetBase { // ----------------------------------------------------------- Constructors /** * Construct an instance of this RuleSet with default values. */ public TestRuleSet() { this(null, null); } /** * Construct an instance of this RuleSet associated with the specified * prefix, associated with no namespace URI. * * @param prefix Matching pattern prefix (must end with '/') or null. */ public TestRuleSet(String prefix) { this(prefix, null); } /** * Construct an instance of this RuleSet associated with the specified * prefix and namespace URI. * * @param prefix Matching pattern prefix (must end with '/') or null. * @param namespaceURI The namespace URI these rules belong to */ public TestRuleSet(String prefix, String namespaceURI) { super(); if (prefix == null) this.prefix = ""; else this.prefix = prefix; this.namespaceURI = namespaceURI; } // ----------------------------------------------------- Instance Variables /** * The prefix for each matching pattern added to the Digester instance, * or an empty String for no prefix. */ protected String prefix = null; // --------------------------------------------------------- Public Methods /** * Add the set of Rule instances defined in this RuleSet to the * specified Digester instance, associating them with * our namespace URI (if any). This method should only be called * by a Digester instance. * * @param digester Digester instance to which the new Rule instances * should be added. */ public void addRuleInstances(Digester digester) { digester.addObjectCreate(prefix + "employee", Employee.class); digester.addSetProperties(prefix + "employee"); digester.addObjectCreate("employee/address", "org.apache.commons.digester.Address"); digester.addSetProperties(prefix + "employee/address"); digester.addSetNext(prefix + "employee/address", "addAddress"); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/document-with-relative-dtd.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/document-with-relative-dtd.0000644000175000017500000000156011226450007033513 0ustar twernertwerner Hello, world libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/substitution/0000755000175000017500000000000011226450007031113 5ustar twernertwerner././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/substitution/VariableExpansionTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/substitution/VariableExpans0000644000175000017500000003076011226450007033750 0ustar twernertwerner/* $Id: VariableExpansionTestCase.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.substitution; import org.apache.commons.digester.CallMethodRule; import org.apache.commons.digester.Digester; import org.apache.commons.digester.SimpleTestBean; import java.io.IOException; import java.io.StringReader; import java.util.HashMap; import java.util.LinkedList; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.SAXException; /** *

Test Case for the variable expansion facility in Digester. * * @author Simon Kitching * @version $Revision: 471661 $ $Date: 2006-11-06 03:09:25 -0500 (Mon, 06 Nov 2006) $ */ public class VariableExpansionTestCase extends TestCase { // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public VariableExpansionTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(VariableExpansionTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { } // method used in tests4 private LinkedList simpleTestBeans = new LinkedList(); public void addSimpleTestBean(SimpleTestBean bean) { simpleTestBeans.add(bean); } // implementation of source shared by the variable expander and // is updatable during digesting via an Ant-like property element private HashMap mutableSource=new HashMap(); /** * Used in test case "testExpansionWithMutableSource", where the * set of variables available to be substituted into the xml is * updated as the xml is parsed. */ public void addProperty(String key, String value) { mutableSource.put(key, value); } /** * Creates a Digester configured to show Ant-like capability. * * @return a Digester with rules and variable substitutor */ private Digester createDigesterThatCanDoAnt() { Digester digester = new Digester(); MultiVariableExpander expander = new MultiVariableExpander(); expander.addSource("$", mutableSource); digester.setSubstitutor(new VariableSubstitutor(expander)); int useRootObj = -1; Class[] callerArgTypes = new Class[] {String.class, String.class}; CallMethodRule caller = new CallMethodRule(useRootObj, "addProperty", callerArgTypes.length, callerArgTypes); digester.addRule("root/property", caller); digester.addCallParam("root/property", 0, "name"); digester.addCallParam("root/property", 1, "value"); digester.addObjectCreate("root/bean", SimpleTestBean.class); digester.addSetProperties("root/bean"); digester.addSetNext("root/bean", "addSimpleTestBean"); return digester; } // ------------------------------------------------ Individual Test Methods /** * Test that by default no expansion occurs. */ public void testNoExpansion() throws SAXException, IOException { String xml = ""; StringReader input = new StringReader(xml); Digester digester = new Digester(); // Configure the digester as required digester.addObjectCreate("root", SimpleTestBean.class); digester.addSetProperties("root"); // Parse our test input. Object root = digester.parse(input); assertNotNull("Digester returned no object", root); SimpleTestBean bean = (SimpleTestBean) root; assertEquals("${attr1}", bean.getAlpha()); assertEquals("var{attr2}", bean.getBeta()); } /** * Test that a MultiVariableExpander with no sources does no expansion. */ public void testExpansionWithNoSource() throws SAXException, IOException { String xml = ""; StringReader input = new StringReader(xml); Digester digester = new Digester(); // Configure the digester as required MultiVariableExpander expander = new MultiVariableExpander(); digester.setSubstitutor(new VariableSubstitutor(expander)); digester.addObjectCreate("root", SimpleTestBean.class); digester.addSetProperties("root"); // Parse our test input. Object root = digester.parse(input); assertNotNull("Digester returned no object", root); SimpleTestBean bean = (SimpleTestBean) root; assertEquals("${attr1}", bean.getAlpha()); assertEquals("var{attr2}", bean.getBeta()); } /** * Test that a MultiVariableExpander with multiple sources works. * It also tests that expansion works ok where multiple elements * exist. */ public void testExpansionWithMultipleSources() throws SAXException, IOException { String xml = "" + "" + "" + ""; StringReader input = new StringReader(xml); Digester digester = new Digester(); // Configure the digester as required HashMap source1 = new HashMap(); source1.put("attr1", "source1.attr1"); source1.put("attr2", "source1.attr2"); // should not be used HashMap source2 = new HashMap(); source2.put("attr1", "source2.attr1"); // should not be used source2.put("attr2", "source2.attr2"); MultiVariableExpander expander = new MultiVariableExpander(); expander.addSource("$", source1); expander.addSource("var", source2); digester.setSubstitutor(new VariableSubstitutor(expander)); digester.addObjectCreate("root/bean", SimpleTestBean.class); digester.addSetProperties("root/bean"); digester.addSetNext("root/bean", "addSimpleTestBean"); // Parse our test input. this.simpleTestBeans.clear(); digester.push(this); digester.parse(input); assertEquals(2, this.simpleTestBeans.size()); { SimpleTestBean bean = (SimpleTestBean) this.simpleTestBeans.get(0); assertEquals("source1.attr1", bean.getAlpha()); assertEquals("source2.attr1", bean.getBeta()); } { SimpleTestBean bean = (SimpleTestBean) this.simpleTestBeans.get(1); assertEquals("source1.attr2", bean.getAlpha()); assertEquals("source2.attr2", bean.getBeta()); } } /** * Test expansion of text in element bodies. */ public void testBodyExpansion() throws SAXException, IOException { String xml = "" + "Twas noun{1} and the noun{2}" + " did verb{1} and verb{2} in the noun{3}" + ""; StringReader input = new StringReader(xml); Digester digester = new Digester(); // Configure the digester as required HashMap nouns = new HashMap(); nouns.put("1", "brillig"); nouns.put("2", "slithy toves"); nouns.put("3", "wabe"); HashMap verbs = new HashMap(); verbs.put("1", "gyre"); verbs.put("2", "gimble"); MultiVariableExpander expander = new MultiVariableExpander(); expander.addSource("noun", nouns); expander.addSource("verb", verbs); digester.setSubstitutor(new VariableSubstitutor(expander)); digester.addObjectCreate("root", SimpleTestBean.class); digester.addCallMethod("root", "setAlpha", 0); // Parse our test input. Object root = digester.parse(input); assertNotNull("Digester returned no object", root); SimpleTestBean bean = (SimpleTestBean) root; assertEquals( "Twas brillig and the slithy toves" + " did gyre and gimble in the wabe", bean.getAlpha()); } /** * Test that an unknown variable causes a RuntimeException. */ public void testExpansionException() throws IOException { String xml = ""; StringReader input = new StringReader(xml); Digester digester = new Digester(); // Configure the digester as required MultiVariableExpander expander = new MultiVariableExpander(); expander.addSource("$", new HashMap()); digester.setSubstitutor(new VariableSubstitutor(expander)); digester.addObjectCreate("root", SimpleTestBean.class); digester.addSetProperties("root"); // Parse our test input. try { digester.parse(input); fail("Exception expected due to unknown variable."); } catch(SAXException e) { // expected, due to reference to undefined variable } } /** * First of two tests added to verify that the substitution * framework is capable of processing Ant-like properties. * * The tests above essentially verify that if a property * was pre-set (e.g. using the "-D" option to Ant), then * the property could be expanded via a variable used either * in an attribute or in body text. * * This test shows that if properties were also set while * processing a document, you could still perform variable * expansion (i.e. just like using the "property" task in Ant). * * @throws IOException * @throws SAXException */ public void testExpansionWithMutableSource() throws SAXException, IOException { String xml = "" + "" + "" + ""; StringReader input = new StringReader(xml); Digester digester = createDigesterThatCanDoAnt(); simpleTestBeans.clear(); digester.push(this); digester.parse(input); assertEquals(1, simpleTestBeans.size()); SimpleTestBean bean = (SimpleTestBean) simpleTestBeans.get(0); assertEquals("prop.value", bean.getAlpha()); } /** * Second of two tests added to verify that the substitution * framework is capable of processing Ant-like properties. * * This test shows that if properties were also set while * processing a document, the resulting variables could also * be expanded within a property element. This is thus * effectively a "closure" test, since it shows that the * mechanism used to bind properties is also capable of * having property values that are driven by property variables. * * @throws IOException * @throws SAXException */ public void testExpansionOfPropertyInProperty() throws SAXException, IOException { String xml = "" + "" + "" + "" + ""; StringReader input = new StringReader(xml); Digester digester = createDigesterThatCanDoAnt(); simpleTestBeans.clear(); digester.push(this); digester.parse(input); assertEquals(1, simpleTestBeans.size()); SimpleTestBean bean = (SimpleTestBean) simpleTestBeans.get(0); assertEquals("substituted-prop.value1", bean.getAlpha()); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/substitution/TestAll.java0000644000175000017500000000255311226450007033333 0ustar twernertwerner/* $Id: TestAll.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.substitution; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Entry point for all substitution package tests. * * @author Robert Burrell Donkin */ public class TestAll extends TestCase { public TestAll(String testName) { super(testName); } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(VariableExpansionTestCase.suite()); return suite; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Employee.java0000644000175000017500000000576511226450007030776 0ustar twernertwerner/* $Id: Employee.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.ArrayList; import java.util.Iterator; /** * Bean for Digester testing. */ public class Employee { public Employee() { this("My First Name", "My Last Name"); } public Employee(String firstName, String lastName) { super(); setFirstName(firstName); setLastName(lastName); } private ArrayList addresses = new ArrayList(); public void addAddress(Address address) { addresses.add(address); } public Address getAddress(String type) { Iterator elements = addresses.iterator(); while (elements.hasNext()) { Address element = (Address) elements.next(); if (type.equals(element.getType())) return (element); } return (null); } public void removeAddress(Address address) { addresses.remove(address); } private String firstName = null; public String getFirstName() { return (this.firstName); } public void setFirstName(String firstName) { this.firstName = firstName; } private String lastName = null; public String getLastName() { return (this.lastName); } public void setLastName(String lastName) { this.lastName = lastName; } // this is to allow testing of primitive convertion private int age; private boolean active; private float salary; public int getAge() { return age; } public void setAge(int age) { this.age = age; } public boolean isActive() { return active; } public void setActive(boolean active) { this.active = active; } public float getSalary() { return salary; } public void setSalary(float salary) { this.salary = salary; } public String toString() { StringBuffer sb = new StringBuffer("Employee["); sb.append("firstName="); sb.append(firstName); sb.append(", lastName="); sb.append(lastName); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/TestOthers.java0000644000175000017500000000264611226450007031316 0ustar twernertwerner/* $Id: TestOthers.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * This class is a place that new test cases * can easily added without having to chance the build.xml. * * @author Robert Burrell Donkin */ public class TestOthers extends TestCase { public TestOthers(String testName) { super(testName); } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(SetNestedPropertiesRuleTestCase.suite()); return suite; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test2.xml0000644000175000017500000000225111226450007030062 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/ParamBean.java0000644000175000017500000000314311226450007031031 0ustar twernertwerner/* $Id: ParamBean.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * This bean is used to replicate a reasonably complex use case * whose behaviour has changed from Digester 1.3 to 1.4. * * @author robert burrell donkin */ public class ParamBean { private boolean cool; private String that; private String _this; public ParamBean() {} public boolean isCool() { return cool; } public void setCool(boolean cool) { this.cool = cool; } public String getThis() { return _this; } public String getThat() { return that; } public String setThisAndThat(String _this, String that) { this._this = _this; this.that = that; return "The Other"; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/BetaBean.java0000644000175000017500000000312711226450007030646 0ustar twernertwerner/* $Id: BetaBean.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; public class BetaBean implements Nameable { private String name = "BETA"; private Nameable child; private Nameable parent; public BetaBean() {} public String getName() { return name; } public void setName(String name) { this.name = name; } public void setParent(Nameable parent) { this.parent = parent; } public Nameable getParent() { return parent; } public void setChild(Nameable child) { this.child = child; } public Nameable getChild() { return child; } public String toString() { return "[BetaBean] name=" + name + " child=" + child; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/NamedBean.java0000644000175000017500000000276311226450007031024 0ustar twernertwerner/* $Id: NamedBean.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * Very simple test bean * * @author Robert Burrell Donkin * @version $Revision: 471661 $ $Date: 2006-11-06 03:09:25 -0500 (Mon, 06 Nov 2006) $ */ public class NamedBean { private String name = "**UNSET**"; public NamedBean() {} public NamedBean(String name) {} public String getName() { return name; } public void setName(String name) { this.name = name; } public void test(String name, String ignored) { setName(name); } public String toString() { return "NamedBean[" + getName() + "]"; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/TestObjectCreationFactory.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/TestObjectCreationFactory.j0000644000175000017500000000260411226450007033577 0ustar twernertwerner/* $Id: TestObjectCreationFactory.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl; /** * Object creation factory used for testing. * * @author Robert Burrell Donkin */ public class TestObjectCreationFactory extends AbstractObjectCreationFactory { public boolean called = false; public Attributes attributes; public Object createObject(Attributes attributes) { this.attributes = new AttributesImpl(attributes); called = true; return this; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/TestEntityResolution.java0000644000175000017500000000364411226450007033411 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.File; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.helpers.DefaultHandler; import junit.framework.TestCase; /** * Tests for entity resolution. * @author Apache Commons Team * @version $Revision: 561579 $ */ public class TestEntityResolution extends TestCase { public void testParserResolveRelative() throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); factory.setNamespaceAware(true); SAXParser parser = factory.newSAXParser(); parser.parse( new File("src/test/org/apache/commons/digester/document-with-relative-dtd.xml"), new DefaultHandler()); } public void testDigesterResolveRelative() throws Exception { Digester digester = new Digester(); digester.setValidating(true); digester.parse( new File("src/test/org/apache/commons/digester/document-with-relative-dtd.xml")); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test10.xml0000644000175000017500000000175011226450007030144 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/TestFactoryCreate.java0000644000175000017500000003024111226450007032575 0ustar twernertwerner/* $Id: TestFactoryCreate.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.Attributes; /** * Test case for factory create rules. * * @author Robert Burrell Donkin */ public class TestFactoryCreate extends TestCase { /** Standard constructor */ public TestFactoryCreate(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestFactoryCreate.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testPropagateException() throws Exception { // only used with this method class ThrowExceptionCreateRule extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) throws Exception { throw new RuntimeException(); } } // now for the tests String xml = ""; // test default - which is to propagate the exception Digester digester = new Digester(); digester.addFactoryCreate("root", new ThrowExceptionCreateRule()); try { digester.parse(new StringReader(xml)); fail("Exception not propagated from create rule (1)"); } catch (Exception e) { /* This is what's expected */ } // test propagate exception digester = new Digester(); digester.addFactoryCreate("root", new ThrowExceptionCreateRule(), false); try { digester.parse(new StringReader(xml)); fail("Exception not propagated from create rule (1)"); } catch (Exception e) { /* This is what's expected */ } // test don't propagate exception digester = new Digester(); digester.addFactoryCreate("root", new ThrowExceptionCreateRule(), true); try { digester.parse(new StringReader(xml)); } catch (Exception e) { // this shouldn't happen fail("Exception should not be propagated"); } } public void testFactoryCreateRule() throws Exception { tryVariations(true); tryVariations(false); } private void tryVariations(boolean propagateExceptions) throws Exception { // test passing object create Digester digester = new Digester(); TestObjectCreationFactory factory = new TestObjectCreationFactory(); digester.addFactoryCreate("root", factory, propagateExceptions); String xml = new String ( ""); digester.parse(new StringReader(xml)); assertEquals("Object create not called(1)[" + propagateExceptions + "]", factory.called , true); assertEquals( "Attribute not passed (1)[" + propagateExceptions + "]", factory.attributes.getValue("one"), "good"); assertEquals( "Attribute not passed (2)[" + propagateExceptions + "]", factory.attributes.getValue("two"), "bad"); assertEquals( "Attribute not passed (3)[" + propagateExceptions + "]", factory.attributes.getValue("three"), "ugly"); digester = new Digester(); digester.addFactoryCreate( "root", "org.apache.commons.digester.TestObjectCreationFactory", propagateExceptions); digester.addSetNext("root", "add"); xml = new String ( ""); List list = new ArrayList(); digester.push(list); digester.parse(new StringReader(xml)); assertEquals("List should contain only the factory object", list.size() , 1); factory = (TestObjectCreationFactory) list.get(0); assertEquals("Object create not called(2)[" + propagateExceptions + "]", factory.called , true); assertEquals( "Attribute not passed (4)[" + propagateExceptions + "]", factory.attributes.getValue("one"), "good"); assertEquals( "Attribute not passed (5)[" + propagateExceptions + "]", factory.attributes.getValue("two"), "bad"); assertEquals( "Attribute not passed (6)[" + propagateExceptions + "]", factory.attributes.getValue("three"), "ugly"); digester = new Digester(); digester.addFactoryCreate( "root", "org.apache.commons.digester.TestObjectCreationFactory", "override", propagateExceptions); digester.addSetNext("root", "add"); xml = new String ( ""); list = new ArrayList(); digester.push(list); digester.parse(new StringReader(xml)); assertEquals("List should contain only the factory object", list.size() , 1); factory = (TestObjectCreationFactory) list.get(0); assertEquals("Object create not called(3)[" + propagateExceptions + "]", factory.called , true); assertEquals( "Attribute not passed (7)[" + propagateExceptions + "]", factory.attributes.getValue("one"), "good"); assertEquals( "Attribute not passed (8)[" + propagateExceptions + "]", factory.attributes.getValue("two"), "bad"); assertEquals( "Attribute not passed (8)[" + propagateExceptions + "]", factory.attributes.getValue("three"), "ugly"); digester = new Digester(); digester.addFactoryCreate( "root", "org.apache.commons.digester.TestObjectCreationFactory", "override", propagateExceptions); digester.addSetNext("root", "add"); xml = new String ( "" + ""); list = new ArrayList(); digester.push(list); digester.parse(new StringReader(xml)); assertEquals("List should contain only the factory object", list.size() , 1); factory = (TestObjectCreationFactory) list.get(0); assertEquals( "Attribute Override Failed (1)", factory.getClass().getName() , "org.apache.commons.digester.OtherTestObjectCreationFactory"); assertEquals("Object create not called(4)[" + propagateExceptions + "]", factory.called , true); assertEquals( "Attribute not passed (10)[" + propagateExceptions + "]", factory.attributes.getValue("one"), "good"); assertEquals( "Attribute not passed (11)[" + propagateExceptions + "]", factory.attributes.getValue("two"), "bad"); assertEquals( "Attribute not passed (12)[" + propagateExceptions + "]", factory.attributes.getValue("three"), "ugly"); digester = new Digester(); digester.addFactoryCreate( "root", TestObjectCreationFactory.class, "override", propagateExceptions); digester.addSetNext("root", "add"); xml = new String ( ""); list = new ArrayList(); digester.push(list); digester.parse(new StringReader(xml)); assertEquals("List should contain only the factory object", list.size() , 1); factory = (TestObjectCreationFactory) list.get(0); assertEquals("Object create not called(5)[" + propagateExceptions + "]", factory.called , true); assertEquals( "Attribute not passed (13)[" + propagateExceptions + "]", factory.attributes.getValue("one"), "good"); assertEquals( "Attribute not passed (14)[" + propagateExceptions + "]", factory.attributes.getValue("two"), "bad"); assertEquals( "Attribute not passed (15)[" + propagateExceptions + "]", factory.attributes.getValue("three"), "ugly"); digester = new Digester(); digester.addFactoryCreate( "root", TestObjectCreationFactory.class, "override", propagateExceptions); digester.addSetNext("root", "add"); xml = new String ( "" + ""); list = new ArrayList(); digester.push(list); digester.parse(new StringReader(xml)); assertEquals("List should contain only the factory object", list.size() , 1); factory = (TestObjectCreationFactory) list.get(0); assertEquals( "Attribute Override Failed (2)", factory.getClass().getName() , "org.apache.commons.digester.OtherTestObjectCreationFactory"); assertEquals("Object create not called(6)[" + propagateExceptions + "]", factory.called , true); assertEquals( "Attribute not passed (16)[" + propagateExceptions + "]", factory.attributes.getValue("one"), "good"); assertEquals( "Attribute not passed (17)[" + propagateExceptions + "]", factory.attributes.getValue("two"), "bad"); assertEquals( "Attribute not passed (18)[" + propagateExceptions + "]", factory.attributes.getValue("three"), "ugly"); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Address.java0000644000175000017500000000510211226450007030565 0ustar twernertwerner/* $Id: Address.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * Bean for Digester testing. */ public class Address { public Address() { this("My Street", "My City", "US", "MyZip"); } public Address(String street, String city, String state, String zipCode) { super(); setStreet(street); setCity(city); setState(state); setZipCode(zipCode); } private String city = null; public String getCity() { return (this.city); } public void setCity(String city) { this.city = city; } private String state = null; public String getState() { return (this.state); } public void setState(String state) { this.state = state; } private String street = null; public String getStreet() { return (this.street); } public void setStreet(String street) { this.street = street; } private String type = null; public String getType() { return (this.type); } public void setType(String type) { this.type = type; } private String zipCode = null; public String getZipCode() { return (this.zipCode); } public void setZipCode(String zipCode) { this.zipCode = zipCode; } public void setEmployee(Employee employee) { employee.addAddress(this); } public String toString() { StringBuffer sb = new StringBuffer("Address["); sb.append("street="); sb.append(street); sb.append(", city="); sb.append(city); sb.append(", state="); sb.append(state); sb.append(", zipCode="); sb.append(zipCode); sb.append("]"); return (sb.toString()); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/ObjectParamRuleTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/ObjectParamRuleTestCase.jav0000644000175000017500000001074311226450007033521 0ustar twernertwerner/* $Id: ObjectParamRuleTestCase.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.SAXException; /** *

Tests for the ObjectParamRuleTestCase * * @author Mark Huisman */ public class ObjectParamRuleTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * The digester instance we will be processing. */ protected Digester digester = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public ObjectParamRuleTestCase(String name) { super(name); } public static void main(String[] args){ // so we can run standalone junit.textui.TestRunner.run(suite()); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(ObjectParamRuleTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods private StringBuffer sb = new StringBuffer(). append(""); /** * Test method calls with the ObjectParamRule rule. It should be possible to * pass any subclass of Object as a parameter, provided that either the element * or the element + attribute has been matched. */ public void testBasic() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("arraylist", ArrayList.class); // Test adding a variety of objects digester.addCallMethod("arraylist/A", "add", 1); ObjectParamRule opr = new ObjectParamRule(0, new Integer(-9)); digester.addRule("arraylist/A", opr); digester.addCallMethod("arraylist/B", "add", 1); opr = new ObjectParamRule(0, new Float(3.14159)); digester.addRule("arraylist/B", opr); digester.addCallMethod("arraylist/C", "add", 1); opr = new ObjectParamRule(0, new Long(999999999)); digester.addRule("arraylist/C", opr); digester.addCallMethod("arraylist/D", "add", 1); opr = new ObjectParamRule(0, "desc", new String("foobarbazbing")); digester.addRule("arraylist/D", opr); // note that this will add a null parameter to the method call and will // not be added to the arraylist. digester.addCallMethod("arraylist/E", "add", 1); opr = new ObjectParamRule(0, "nonexistentattribute", new String("ignore")); digester.addRule("arraylist/E", opr); //Parse it and obtain the ArrayList ArrayList al = (ArrayList)digester.parse(new StringReader(sb.toString())); assertNotNull(al); assertEquals(al.size(), 4); assertTrue(al.contains(new Integer(-9))); assertTrue(al.contains(new Float(3.14159))); assertTrue(al.contains(new Long(999999999))); assertTrue(al.contains(new String("foobarbazbing"))); assertTrue(!(al.contains(new String("ignore")))); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test9.xml0000644000175000017500000000160111226450007030067 0ustar twernertwerner First Name Last Name libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test5.xml0000644000175000017500000000241411226450007030066 0ustar twernertwerner First Name Last Name 21 1000000 true

home Home Street Home City HS HmZip
office Office Street Office City OS OfZip
libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/DigesterTestCase.java0000644000175000017500000005371711226450007032421 0ustar twernertwerner/* $Id: DigesterTestCase.java 728879 2008-12-23 05:44:07Z rahul $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.File; import java.io.InputStream; import java.io.Reader; import java.io.StringReader; import java.math.BigDecimal; import java.net.URL; import java.util.ArrayList; import java.util.EmptyStackException; import java.util.Iterator; import java.util.Map; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.Attributes; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.helpers.AttributesImpl; /** *

Test Case for the Digester class. These tests exercise the individual * methods of a Digester, but do not attempt to process complete documents. *

* * @author Craig R. McClanahan * @version $Revision: 728879 $ $Date: 2008-12-23 00:44:07 -0500 (Tue, 23 Dec 2008) $ */ public class DigesterTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * The digester instance we will be processing. */ protected Digester digester = null; /** * The set of public identifiers, and corresponding resource names, * for the versions of the DTDs that we know about. There * MUST be an even number of Strings in this array. */ protected static final String registrations[] = { "-//Netscape Communications//DTD RSS 0.9//EN", "/org/apache/commons/digester/rss/rss-0.9.dtd", "-//Netscape Communications//DTD RSS 0.91//EN", "/org/apache/commons/digester/rss/rss-0.91.dtd", }; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public DigesterTestCase(String name) { super(name); } // -------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); digester.setRules(new RulesBase()); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(DigesterTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods /** * Test null parsing. * (should lead to IllegalArgumentExceptions) */ public void testNullFileParse() throws Exception { try { digester.parse((File) null); fail("Expected IllegalArgumentException with null argument"); } catch (IllegalArgumentException e) { // expected } } public void testNullInputSourceParse() throws Exception { try { digester.parse((InputSource) null); fail("Expected IllegalArgumentException with null argument"); } catch (IllegalArgumentException e) { // expected } } public void testNullInputStreamParse() throws Exception { try { digester.parse((InputStream) null); fail("Expected IllegalArgumentException with null argument"); } catch (IllegalArgumentException e) { // expected } } public void testNullReaderParse() throws Exception { try { digester.parse((Reader) null); fail("Expected IllegalArgumentException with null argument"); } catch (IllegalArgumentException e) { // expected } } public void testNullStringParse() throws Exception { try { digester.parse((String) null); fail("Expected IllegalArgumentException with null argument"); } catch (IllegalArgumentException e) { // expected } } public void testNullURLParse() throws Exception { try { digester.parse((URL) null); fail("Expected IllegalArgumentException with null argument"); } catch (IllegalArgumentException e) { // expected } } /** * Test the basic property getters and setters. */ public void testProperties() { assertNull("Initial error handler is null", digester.getErrorHandler()); digester.setErrorHandler((ErrorHandler) digester); assertTrue("Set error handler is digester", digester.getErrorHandler() == digester); digester.setErrorHandler(null); assertNull("Reset error handler is null", digester.getErrorHandler()); assertTrue("Initial namespace aware is false", !digester.getNamespaceAware()); digester.setNamespaceAware(true); assertTrue("Set namespace aware is true", digester.getNamespaceAware()); digester.setNamespaceAware(false); assertTrue("Reset namespace aware is false", !digester.getNamespaceAware()); assertTrue("Initial validating is false", !digester.getValidating()); digester.setValidating(true); assertTrue("Set validating is true", digester.getValidating()); digester.setValidating(false); assertTrue("Reset validating is false", !digester.getValidating()); } /** * Test registration of URLs for specified public identifiers. */ public void testRegistrations() { Map map = digester.getRegistrations(); assertEquals("Initially zero registrations", 0, map.size()); int n = 0; for (int i = 0; i < registrations.length; i += 2) { URL url = this.getClass().getResource(registrations[i + 1]); if (url != null) { digester.register(registrations[i], url); n++; } } map = digester.getRegistrations(); assertEquals("Registered two URLs", n, map.size()); int count[] = new int[n]; for (int i = 0; i < n; i++) count[i] = 0; Iterator keys = map.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); for (int i = 0; i < n; i++) { if (key.equals(registrations[i * 2])) { count[i]++; break; } } } for (int i = 0; i < n; i++) assertEquals("Count for key " + registrations[i * 2], 1, count[i]); } /** * Basic test for rule creation and matching. */ public void testRules() { assertEquals("Initial rules list is empty", 0, digester.getRules().match(null, "a").size()); digester.addSetProperties("a"); assertEquals("Add a matching rule", 1, digester.getRules().match(null, "a").size()); digester.addSetProperties("b"); assertEquals("Add a non-matching rule", 1, digester.getRules().match(null, "a").size()); digester.addSetProperties("a/b"); assertEquals("Add a non-matching nested rule", 1, digester.getRules().match(null, "a").size()); digester.addSetProperties("a/b"); assertEquals("Add a second matching rule", 2, digester.getRules().match(null, "a/b").size()); } /** *

Test matching rules in {@link RulesBase}.

* *

Tests:

*
    *
  • exact match
  • *
  • tail match
  • *
  • longest pattern rule
  • *
*/ public void testRulesBase() { assertEquals("Initial rules list is empty", 0, digester.getRules().rules().size()); // We're going to set up digester.addRule("a/b/c/d", new TestRule("a/b/c/d")); digester.addRule("*/d", new TestRule("*/d")); digester.addRule("*/c/d", new TestRule("*/c/d")); // Test exact match assertEquals("Exact match takes precedence 1", 1, digester.getRules().match(null, "a/b/c/d").size()); assertEquals("Exact match takes precedence 2", "a/b/c/d", ((TestRule) digester.getRules().match(null, "a/b/c/d").iterator().next()).getIdentifier()); // Test wildcard tail matching assertEquals("Wildcard tail matching rule 1", 1, digester.getRules().match(null, "a/b/d").size()); assertEquals("Wildcard tail matching rule 2", "*/d", ((TestRule) digester.getRules().match(null, "a/b/d").iterator().next()).getIdentifier()); // Test the longest matching pattern rule assertEquals("Longest tail rule 1", 1, digester.getRules().match(null, "x/c/d").size()); assertEquals("Longest tail rule 2", "*/c/d", ((TestRule) digester.getRules().match(null, "x/c/d").iterator().next()).getIdentifier()); } /** * Test the basic stack mechanisms. */ public void testStackMethods() { Object value = null; // New stack must be empty assertEquals("New stack is empty", 0, digester.getCount()); value = digester.peek(); assertNull("New stack peek() returns null", value); value = digester.pop(); assertNull("New stack pop() returns null", value); // Test pushing and popping activities digester.push("First Item"); assertEquals("Pushed one item size", 1, digester.getCount()); value = digester.peek(); assertNotNull("Peeked first item is not null", value); assertEquals("Peeked first item value", "First Item", (String) value); digester.push("Second Item"); assertEquals("Pushed two items size", 2, digester.getCount()); value = digester.peek(); assertNotNull("Peeked second item is not null", value); assertEquals("Peeked second item value", "Second Item", (String) value); value = digester.pop(); assertEquals("Popped stack size", 1, digester.getCount()); assertNotNull("Popped second item is not null", value); assertEquals("Popped second item value", "Second Item", (String) value); value = digester.peek(); assertNotNull("Remaining item is not null", value); assertEquals("Remaining item value", "First Item", (String) value); assertEquals("Remaining stack size", 1, digester.getCount()); // Cleared stack is empty digester.push("Dummy Item"); digester.clear(); assertEquals("Cleared stack is empty", 0, digester.getCount()); value = digester.peek(); assertNull("Cleared stack peek() returns null", value); value = digester.pop(); assertNull("Cleared stack pop() returns null", value); } public void testOnceAndOnceOnly() throws Exception { class TestConfigureDigester extends Digester { public int called=0; public TestConfigureDigester() {} protected void initialize() { called++; } } TestConfigureDigester digester = new TestConfigureDigester(); String xml = ""; digester.parse(new StringReader(xml)); assertEquals("Initialize should be called once and only once", 1, digester.called); } public void testBasicSubstitution() throws Exception { class TestSubRule extends Rule { public String body; public Attributes attributes; public void begin(String namespace, String name, Attributes attributes) { this.attributes = new AttributesImpl(attributes); } public void body(String namespace, String name, String text) { this.body = text; } } TestSubRule tsr = new TestSubRule(); Digester digester = new Digester(); digester.addRule("alpha/beta", tsr); // it's not easy to transform dirty harry into the mighty circus - but let's give it a try String xml = "Do you feel luck punk?"; InputSource in = new InputSource(new StringReader(xml)); digester.parse(in); assertEquals("Unsubstituted body text", "Do you feel luck punk?", tsr.body); assertEquals("Unsubstituted number of attributes", 2, tsr.attributes.getLength()); assertEquals("Unsubstituted forname attribute value", "Dirty", tsr.attributes.getValue("forname")); assertEquals("Unsubstituted surname attribute value", "Harry", tsr.attributes.getValue("surname")); digester.setSubstitutor( new Substitutor() { public Attributes substitute(Attributes attributes) { AttributesImpl results = new AttributesImpl(); results.addAttribute("", "python", "python", "CDATA", "Cleese"); return results; } public String substitute(String bodyText) { return "And now for something completely different..."; } }); // now transform into the full monty in = new InputSource(new StringReader(xml)); digester.parse(in); assertEquals("Substituted body text", "And now for something completely different...", tsr.body); assertEquals("Substituted number of attributes", 1, tsr.attributes.getLength()); assertEquals("Substituted python attribute value", "Cleese", tsr.attributes.getValue("", "python")); } /** Tests the push-peek-pop cycle for a named stack */ public void testNamedStackPushPeekPop() throws Exception { BigDecimal archimedesAveragePi = new BigDecimal("3.1418"); String testStackName = "org.apache.commons.digester.tests.testNamedStackPushPeekPop"; Digester digester = new Digester(); assertTrue("Stack starts empty:", digester.isEmpty(testStackName)); digester.push(testStackName, archimedesAveragePi); assertEquals("Peeked value:", archimedesAveragePi, digester.peek(testStackName)); assertEquals("Popped value:", archimedesAveragePi, digester.pop(testStackName)); assertTrue("Stack ends empty:", digester.isEmpty(testStackName)); digester.push(testStackName, "1"); digester.push(testStackName, "2"); digester.push(testStackName, "3"); assertEquals("Peek#1", "1", digester.peek(testStackName, 2)); assertEquals("Peek#2", "2", digester.peek(testStackName, 1)); assertEquals("Peek#3", "3", digester.peek(testStackName, 0)); assertEquals("Peek#3a", "3", digester.peek(testStackName)); try { // peek beyond stack digester.peek(testStackName, 3); fail("Peek#4 failed to throw an exception."); } catch(EmptyStackException ex) { // ok, expected } try { // peek a nonexistent named stack digester.peek("no.such.stack", 0); fail("Peeking a non-existent stack failed to throw an exception."); } catch(EmptyStackException ex) { // ok, expected } } /** Tests that values are stored independently */ public void testNamedIndependence() { String testStackOneName = "org.apache.commons.digester.tests.testNamedIndependenceOne"; String testStackTwoName = "org.apache.commons.digester.tests.testNamedIndependenceTwo"; Digester digester = new Digester(); digester.push(testStackOneName, "Tweedledum"); digester.push(testStackTwoName, "Tweedledee"); assertEquals("Popped value one:", "Tweedledum", digester.pop(testStackOneName)); assertEquals("Popped value two:", "Tweedledee", digester.pop(testStackTwoName)); } /** Tests popping named stack not yet pushed */ public void testPopNamedStackNotPushed() { String testStackName = "org.apache.commons.digester.tests.testPopNamedStackNotPushed"; Digester digester = new Digester(); try { digester.pop(testStackName); fail("Expected an EmptyStackException"); } catch (EmptyStackException e) { // expected } try { digester.peek(testStackName); fail("Expected an EmptyStackException"); } catch (EmptyStackException e) { // expected } } /** Tests for isEmpty */ public void testNamedStackIsEmpty() { String testStackName = "org.apache.commons.digester.tests.testNamedStackIsEmpty"; Digester digester = new Digester(); assertTrue( "A named stack that has no object pushed onto it yet should be empty", digester.isEmpty(testStackName)); digester.push(testStackName, "Some test value"); assertFalse( "A named stack that has an object pushed onto it should be not empty", digester.isEmpty(testStackName)); digester.peek(testStackName); assertFalse( "Peek should not effect whether the stack is empty", digester.isEmpty(testStackName)); digester.pop(testStackName); assertTrue( "A named stack that has it's last object popped is empty", digester.isEmpty(testStackName)); } /** * Test the Digester.getRoot method. */ public void testGetRoot() throws Exception { Digester digester = new Digester(); digester.addRule("root", new ObjectCreateRule(TestBean.class)); String xml = ""; InputSource in = new InputSource(new StringReader(xml)); digester.parse(in); Object root = digester.getRoot(); assertNotNull("root object not retrieved", root); assertTrue("root object not a TestRule instance", (root instanceof TestBean)); } /** Utility class for method testStackAction */ private static class TrackingStackAction implements StackAction { public ArrayList events = new ArrayList(); public Object onPush(Digester d, String stackName, Object o) { String msg = "push:" + stackName + ":" + o.toString(); events.add(msg); String str = o.toString(); if (str.startsWith("replpush")) { return new String(str); } else { return o; } } public Object onPop(Digester d, String stackName, Object o) { String msg = "pop:" + stackName + ":" + o.toString(); events.add(msg); String str = o.toString(); if (str.startsWith("replpop")) { return new String(str); } else { return o; } } } /** * Test custom StackAction subclasses. */ public void testStackAction() { TrackingStackAction action = new TrackingStackAction(); Object obj1 = new String("obj1"); Object obj2 = new String("obj2"); Object obj3 = new String("replpop.obj3"); Object obj4 = new String("replpush.obj4"); Object obj8 = new String("obj8"); Object obj9 = new String("obj9"); Digester d = new Digester(); d.setStackAction(action); assertEquals(0, action.events.size()); d.push(obj1); d.push(obj2); d.push(obj3); d.push(obj4); assertNotNull(d.peek(0)); // for obj4, a copy should have been pushed assertFalse(obj4 == d.peek(0)); assertEquals(obj4, d.peek(0)); // for obj3, replacement only occurs on pop assertSame(obj3, d.peek(1)); assertSame(obj2, d.peek(2)); assertSame(obj1, d.peek(3)); Object obj4a = d.pop(); Object obj3a = d.pop(); Object obj2a = d.pop(); Object obj1a = d.pop(); assertFalse(obj4 == obj4a); assertEquals(obj4, obj4a); assertFalse(obj3 == obj4a); assertEquals(obj3, obj3a); assertSame(obj2, obj2a); assertSame(obj1, obj1a); d.push("stack1", obj8); d.push("stack1", obj9); Object obj9a = d.pop("stack1"); Object obj8a = d.pop("stack1"); assertSame(obj8, obj8a); assertSame(obj9, obj9a); assertEquals(12, action.events.size()); assertEquals("push:null:obj1", action.events.get(0)); assertEquals("push:null:obj2", action.events.get(1)); assertEquals("push:null:replpop.obj3", action.events.get(2)); assertEquals("push:null:replpush.obj4", action.events.get(3)); assertEquals("pop:null:replpush.obj4", action.events.get(4)); assertEquals("pop:null:replpop.obj3", action.events.get(5)); assertEquals("pop:null:obj2", action.events.get(6)); assertEquals("pop:null:obj1", action.events.get(7)); assertEquals("push:stack1:obj8", action.events.get(8)); assertEquals("push:stack1:obj9", action.events.get(9)); assertEquals("pop:stack1:obj9", action.events.get(10)); assertEquals("pop:stack1:obj8", action.events.get(11)); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/RulesBaseTestCase.java0000644000175000017500000002360611226450007032532 0ustar twernertwerner/* $Id: RulesBaseTestCase.java 472840 2006-11-09 10:18:34Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.Iterator; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** *

Test Case for the RulesBase matching rules. * Most of this material was original contained in the digester test case * but was moved into this class so that extensions of the basic matching rules * behaviour can extend this test case. *

* * @author Craig R. McClanahan * @version $Revision: 472840 $ $Date: 2006-11-09 05:18:34 -0500 (Thu, 09 Nov 2006) $ */ public class RulesBaseTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * The digester instance we will be processing. */ protected Digester digester = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public RulesBaseTestCase(String name) { super(name); } // -------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); digester.setRules(createMatchingRulesForTest()); } /** *

This should be overriden by subclasses. * * @return the matching rules to be tested. */ protected Rules createMatchingRulesForTest() { return new RulesBase(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(RulesBaseTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods /** * Basic test for rule creation and matching. */ public void testRules() { // clear any existing rules digester.getRules().clear(); // perform tests assertEquals("Initial rules list is empty", 0, digester.getRules().match("a").size()); digester.addSetProperties("a"); assertEquals("Add a matching rule", 1, digester.getRules().match(null, "a").size()); digester.addSetProperties("b"); assertEquals("Add a non-matching rule", 1, digester.getRules().match(null, "a").size()); digester.addSetProperties("a/b"); assertEquals("Add a non-matching nested rule", 1, digester.getRules().match(null, "a").size()); digester.addSetProperties("a/b"); assertEquals("Add a second matching rule", 2, digester.getRules().match(null, "a/b").size()); // clean up digester.getRules().clear(); } /** *

Test matching rules in {@link RulesBase}.

* *

Tests:

*
    *
  • exact match
  • *
  • tail match
  • *
  • longest pattern rule
  • *
*/ public void testRulesBase() { // clear any existing rules digester.getRules().clear(); assertEquals("Initial rules list is empty", 0, digester.getRules().rules().size()); // We're going to set up digester.addRule("a/b/c/d", new TestRule("a/b/c/d")); digester.addRule("*/d", new TestRule("*/d")); digester.addRule("*/c/d", new TestRule("*/c/d")); // Test exact match assertEquals("Exact match takes precedence 1", 1, digester.getRules().match(null, "a/b/c/d").size()); assertEquals("Exact match takes precedence 2", "a/b/c/d", ((TestRule) digester.getRules().match(null, "a/b/c/d").iterator().next()).getIdentifier()); // Test wildcard tail matching assertEquals("Wildcard tail matching rule 1", 1, digester.getRules().match(null, "a/b/d").size()); assertEquals("Wildcard tail matching rule 2", "*/d", ((TestRule) digester.getRules().match(null, "a/b/d").iterator().next()).getIdentifier()); // Test the longest matching pattern rule assertEquals("Longest tail rule 1", 1, digester.getRules().match(null, "x/c/d").size()); assertEquals("Longest tail rule 2", "*/c/d", ((TestRule) digester.getRules().match(null, "x/c/d").iterator().next()).getIdentifier()); // Test wildcard tail matching at the top level, // i.e. the wildcard is nothing digester.addRule("*/a", new TestRule("*/a")); assertEquals("Wildcard tail matching rule 3", 1, digester.getRules().match(null,"a").size()); assertEquals("Wildcard tail matching rule 3 (match too much)", 0, digester.getRules().match(null,"aa").size()); // clean up digester.getRules().clear(); } /** * Test basic matchings involving namespaces. */ public void testBasicNamespaceMatching() { List list = null; Iterator it = null; // clear any existing rules digester.getRules().clear(); assertEquals("Initial rules list is empty", 0, digester.getRules().rules().size()); // Set up rules digester.addRule("alpha/beta/gamma", new TestRule("No-Namespace")); digester.addRule("alpha/beta/gamma", new TestRule("Euclidean-Namespace", "euclidean")); list = digester.getRules().rules(); // test that matching null namespace brings back namespace and non-namespace rules list = digester.getRules().match(null, "alpha/beta/gamma"); assertEquals("Null namespace match (A)", 2, list.size()); it = list.iterator(); assertEquals("Null namespace match (B)", "No-Namespace", ((TestRule) it.next()).getIdentifier()); assertEquals("Null namespace match (C)", "Euclidean-Namespace", ((TestRule) it.next()).getIdentifier()); // test that matching euclid namespace brings back namespace and non-namespace rules list = digester.getRules().match("euclidean", "alpha/beta/gamma"); assertEquals("Matching namespace match (A)", 2, list.size()); it = list.iterator(); assertEquals("Matching namespace match (B)", "No-Namespace", ((TestRule) it.next()).getIdentifier()); assertEquals("Matching namespace match (C)", "Euclidean-Namespace", ((TestRule) it.next()).getIdentifier()); // test that matching another namespace brings back only non-namespace rule list = digester.getRules().match("hyperbolic", "alpha/beta/gamma"); assertEquals("Non matching namespace match (A)", 1, list.size()); it = list.iterator(); assertEquals("Non matching namespace match (B)", "No-Namespace", ((TestRule) it.next()).getIdentifier()); // clean up digester.getRules().clear(); } /** * Rules must always be returned in the correct order. */ public void testOrdering() { // clear any existing rules digester.getRules().clear(); assertEquals("Initial rules list is empty", 0, digester.getRules().rules().size()); // Set up rules digester.addRule("alpha/beta/gamma", new TestRule("one")); digester.addRule("alpha/beta/gamma", new TestRule("two")); digester.addRule("alpha/beta/gamma", new TestRule("three")); // test that rules are returned in set order List list = digester.getRules().match(null, "alpha/beta/gamma"); assertEquals("Testing ordering mismatch (A)", 3, list.size()); Iterator it = list.iterator(); assertEquals("Testing ordering mismatch (B)", "one", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing ordering mismatch (C)", "two", ((TestRule) it.next()).getIdentifier()); assertEquals("Testing ordering mismatch (D)", "three", ((TestRule) it.next()).getIdentifier()); // clean up digester.getRules().clear(); } /** Tests the behaviour when a rule is added with a trailing slash*/ public void testTrailingSlash() { // clear any existing rules digester.getRules().clear(); assertEquals("Initial rules list is empty", 0, digester.getRules().rules().size()); // Set up rules digester.addRule("alpha/beta/gamma/", new TestRule("one")); digester.addRule("alpha/beta/", new TestRule("two")); digester.addRule("beta/gamma/alpha", new TestRule("three")); // test that rules are returned in set order List list = digester.getRules().match(null, "alpha/beta/gamma"); assertEquals("Testing number of matches", 1, list.size()); Iterator it = list.iterator(); assertEquals("Testing ordering (A)", "one", ((TestRule) it.next()).getIdentifier()); // clean up digester.getRules().clear(); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/LocationTrackerTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/LocationTrackerTestCase.jav0000644000175000017500000000626211226450007033567 0ustar twernertwerner/* $Id: LocationTrackerTestCase.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.StringReader; import java.util.HashMap; import java.util.List; import java.util.Map; import junit.framework.TestCase; import org.xml.sax.Locator; /** * Tests that StackAction can be used to track the source location * of objects created from input xml stream. */ public class LocationTrackerTestCase extends TestCase { private static class LocationTracker implements StackAction { public Map locations = new HashMap(); public Object onPush(Digester d, String stackName, Object o) { if (stackName == null) { // we only care about the real object stack // note that a Locator object can also provide // publicId and systemId info. Locator l = d.getDocumentLocator(); StringBuffer locn = new StringBuffer(); locn.append("line="); locn.append(l.getLineNumber()); locations.put(o, locn.toString()); } return o; } public Object onPop(Digester d, String stackName, Object o) { return o; } } public void testAll() throws Exception { final String TEST_XML = "\n" + "\n" + " \n" + " \n" + " \n" + ""; LocationTracker locnTracker = new LocationTracker(); Digester digester = new Digester(); digester.setStackAction(locnTracker); digester.addObjectCreate("box", Box.class); digester.addSetProperties("box"); digester.addObjectCreate("box/subBox", Box.class); digester.addSetProperties("box/subBox"); digester.addSetNext("box/subBox", "addChild"); Object result = digester.parse(new StringReader(TEST_XML)); assertNotNull(result); Box root = (Box) result; List children = root.getChildren(); assertEquals(3, children.size()); Box box1 = (Box) children.get(0); Box box2 = (Box) children.get(1); Box box3 = (Box) children.get(2); assertEquals("line=2", locnTracker.locations.get(root)); assertEquals("line=3", locnTracker.locations.get(box1)); assertEquals("line=5", locnTracker.locations.get(box2)); assertEquals("line=5", locnTracker.locations.get(box3)); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test4.xml0000644000175000017500000000170711226450007030071 0ustar twernertwerner
libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test11.xml0000644000175000017500000000262611226450007030150 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/TestRule.java0000644000175000017500000000652011226450007030754 0ustar twernertwerner/* $Id: TestRule.java 730332 2008-12-31 07:09:35Z rahul $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.List; import org.xml.sax.Attributes; /** *

This rule implementation is intended to help test digester. * The idea is that you can test which rule matches by looking * at the identifier.

* * @author Robert Burrell Donkin */ public class TestRule extends Rule { // ----------------------------------------------------- Instance Variables /** String identifing this particular TestRule */ private String identifier; /** Used when testing body text */ private String bodyText; /** Used when testing call orders */ private List order; // ----------------------------------------------------------- Constructors /** * Base constructor. * * @param identifier Used to tell which TestRule is which */ public TestRule(String identifier) { this.identifier = identifier; } /** * Constructor sets namespace URI. * * @param identifier Used to tell which TestRule is which * @param namespaceURI Set rule namespace */ public TestRule( String identifier, String namespaceURI) { this.identifier = identifier; setNamespaceURI(namespaceURI); } // ------------------------------------------------ Rule Implementation /** * 'Begin' call. */ public void begin(Attributes attributes) { appendCall(); } /** * 'Body' call. */ public void body(String text) { this.bodyText = text; appendCall(); } /** * 'End' call. */ public void end() { appendCall(); } // ------------------------------------------------ Methods /** * If a list has been set, append this to the list. */ protected void appendCall() { if (order != null) order.add(this); } /** * Get the body text that was set. */ public String getBodyText() { return bodyText; } /** * Get the identifier associated with this test. */ public String getIdentifier() { return identifier; } /** * Get call order list. */ public List getOrder() { return order; } /** * Set call order list */ public void setOrder(List order) { this.order = order; } /** * Return the identifier. */ public String toString() { return identifier; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/NamespaceSnapshotTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/NamespaceSnapshotTestCase.j0000644000175000017500000001110011226450007033553 0ustar twernertwerner/* $Id: NamespaceSnapshotTestCase.java 561583 2007-07-31 22:48:00Z dennisl $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Map; import junit.framework.TestCase; import org.xml.sax.Attributes; /** * Tests namespace snapshotting. */ public class NamespaceSnapshotTestCase extends TestCase { /** * A test case specific helper rule. */ static class NamespaceSnapshotRule extends Rule { /** * @see Rule#begin(String, String, Attributes) */ public final void begin(final String namespace, final String name, final Attributes attributes) { Digester d = getDigester(); Map namespaces = d.getCurrentNamespaces(); ((NamespacedBox) d.peek()).setNamespaces(namespaces); } } /** * Namespace snapshot test case. */ public void testNamespaceSnapshots() throws Exception { Digester digester = new Digester(); digester.setNamespaceAware(true); digester.addObjectCreate("box", NamespacedBox.class); digester.addSetProperties("box"); digester.addRule("box", new NamespaceSnapshotRule()); digester.addObjectCreate("box/subBox", NamespacedBox.class); digester.addSetProperties("box/subBox"); digester.addRule("box/subBox", new NamespaceSnapshotRule()); digester.addSetNext("box/subBox", "addChild"); Object result = digester.parse(getInputStream("Test11.xml")); assertNotNull(result); NamespacedBox root = (NamespacedBox) result; Map nsmap = root.getNamespaces(); assertEquals(3, nsmap.size()); assertEquals("", nsmap.get("")); assertEquals("http://commons.apache.org/digester/Foo", nsmap.get("foo")); assertEquals("http://commons.apache.org/digester/Bar", nsmap.get("bar")); List children = root.getChildren(); assertEquals(3, children.size()); NamespacedBox child1 = (NamespacedBox) children.get(0); nsmap = child1.getNamespaces(); assertEquals(3, nsmap.size()); assertEquals("", nsmap.get("")); assertEquals("http://commons.apache.org/digester/Foo1", nsmap.get("foo")); assertEquals("http://commons.apache.org/digester/Bar1", nsmap.get("bar")); NamespacedBox child2 = (NamespacedBox) children.get(1); nsmap = child2.getNamespaces(); assertEquals(5, nsmap.size()); assertEquals("", nsmap.get("")); assertEquals("http://commons.apache.org/digester/Foo", nsmap.get("foo")); assertEquals("http://commons.apache.org/digester/Bar", nsmap.get("bar")); assertEquals("http://commons.apache.org/digester/Alpha", nsmap.get("alpha")); assertEquals("http://commons.apache.org/digester/Beta", nsmap.get("beta")); NamespacedBox child3 = (NamespacedBox) children.get(2); nsmap = child3.getNamespaces(); assertEquals(4, nsmap.size()); assertEquals("", nsmap.get("")); assertEquals("http://commons.apache.org/digester/Foo3", nsmap.get("foo")); assertEquals("http://commons.apache.org/digester/Alpha", nsmap.get("alpha")); assertEquals("http://commons.apache.org/digester/Bar", nsmap.get("bar")); } // ------------------------------------------------ Utility Support Methods /** * Return an appropriate InputStream for the specified test file (which * must be inside our current package. * * @param name Name of the test file we want * * @exception IOException if an input/output error occurs */ protected InputStream getInputStream(String name) throws IOException { return (this.getClass().getResourceAsStream ("/org/apache/commons/digester/" + name)); } } ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/CallMethodRuleTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/CallMethodRuleTestCase.java0000644000175000017500000006630011226450007033507 0ustar twernertwerner/* $Id: CallMethodRuleTestCase.java 472840 2006-11-09 10:18:34Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.SAXException; //import org.apache.commons.logging.impl.SimpleLog; /** *

Tests for the CallMethodRule and associated * CallParamRule. * * @author Christopher Lenz */ public class CallMethodRuleTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * The digester instance we will be processing. */ protected Digester digester = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public CallMethodRuleTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(CallMethodRuleTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods /** * Test method calls with the CallMethodRule rule. It should be possible * to call a method with no arguments using several rule syntaxes. */ public void testBasic() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", Employee.class); // try all syntax permutations digester.addCallMethod("employee", "toString", 0, (Class[])null); digester.addCallMethod("employee", "toString", 0, (String[])null); digester.addCallMethod("employee", "toString", 0, new Class[] {}); digester.addCallMethod("employee", "toString", 0, new String[] {}); digester.addCallMethod("employee", "toString"); // Parse our test input. // An exception will be thrown if the method can't be found Object root1 = digester.parse(getInputStream("Test5.xml")); assertNotNull(root1); } /** * Test method calls with the CallMethodRule reading from the element * body, with no CallParamMethod rules added. */ public void testCallMethodOnly() throws Exception { // Configure the digester as required digester.addObjectCreate("employee", Employee.class); digester.addCallMethod("employee/firstName", "setFirstName", 0); digester.addCallMethod("employee/lastName", "setLastName", 0); // Parse our test input Employee employee = (Employee) digester.parse(getInputStream("Test9.xml")); assertNotNull("parsed an employee", employee); // Validate that the property setters were called assertEquals("Set first name", "First Name", employee.getFirstName()); assertEquals("Set last name", "Last Name", employee.getLastName()); } /** * Test CallMethodRule variants which specify the classes of the * parameters to target methods. String, int, boolean, float should all * be acceptable as parameter types. */ public void testSettingProperties() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", Employee.class); // try all syntax permutations digester.addCallMethod("employee", "setLastName", 1, new String[] {"java.lang.String"}); digester.addCallParam("employee/lastName", 0); // Parse our test input Object root1 = null; // an exception will be thrown if the method can't be found root1 = digester.parse(getInputStream("Test5.xml")); Employee employee = (Employee) root1; assertEquals("Failed to call Employee.setLastName", "Last Name", employee.getLastName()); digester = new Digester(); // Configure the digester as required digester.addObjectCreate("employee", Employee.class); // try out primitive convertion digester.addCallMethod("employee", "setAge", 1, new Class[] {int.class}); digester.addCallParam("employee/age", 0); // Parse our test input root1 = null; // an exception will be thrown if the method can't be found root1 = digester.parse(getInputStream("Test5.xml")); employee = (Employee) root1; assertEquals("Failed to call Employee.setAge", 21, employee.getAge()); digester = new Digester(); // Configure the digester as required digester.addObjectCreate("employee", Employee.class); digester.addCallMethod("employee", "setActive", 1, new Class[] {boolean.class}); digester.addCallParam("employee/active", 0); // Parse our test input root1 = null; // an exception will be thrown if the method can't be found root1 = digester.parse(getInputStream("Test5.xml")); employee = (Employee) root1; assertEquals("Failed to call Employee.setActive", true, employee.isActive()); digester = new Digester(); // Configure the digester as required digester.addObjectCreate("employee", Employee.class); digester.addCallMethod("employee", "setSalary", 1, new Class[] {float.class}); digester.addCallParam("employee/salary", 0); // Parse our test input root1 = null; // an exception will be thrown if the method can't be found root1 = digester.parse(getInputStream("Test5.xml")); employee = (Employee) root1; assertEquals("Failed to call Employee.setSalary", 1000000.0f, employee.getSalary(), 0.1f); } /** * This tests the call methods params enhancement that provides * for more complex stack-based calls. */ public void testParamsFromStack() throws SAXException, IOException { StringBuffer xml = new StringBuffer(). append(""). append(""). append(" "). append(" "). append(""); digester.addObjectCreate("map", HashMap.class); digester.addCallMethod("map", "put", 2); digester.addObjectCreate("map/key", AlphaBean.class); digester.addSetProperties("map/key"); digester.addCallParam("map/key", 0, true); digester.addObjectCreate("map/value", BetaBean.class); digester.addSetProperties("map/value"); digester.addCallParam("map/value", 1, true); Map map = (Map) digester.parse(new StringReader(xml.toString())); assertNotNull(map); assertEquals(1, map.size()); assertEquals("The key", ((AlphaBean)map.keySet().iterator().next()).getName()); assertEquals("The value", ((BetaBean)map.values().iterator().next()).getName()); } /** * Test that the target object for a CallMethodRule is the object that was * on top of the object stack when the CallMethodRule fired, even when other * rules fire between the CallMethodRule and its associated CallParamRules. *

* The current implementation of CallMethodRule ensures this works by * firing only at the end of the tag that CallMethodRule triggered on. */ public void testOrderNestedPartA() throws Exception { // Configure the digester as required // Here, we use the "grandchild element name" as a parameter to // the created element, to ensure that all the params aren't // avaiable to the CallMethodRule until some other rules have fired, // in particular an ObjectCreateRule. The CallMethodRule should still // function correctly in this scenario. digester.addObjectCreate("toplevel/element", NamedBean.class); digester.addCallMethod("toplevel/element", "setName", 1); digester.addCallParam("toplevel/element/element/element", 0, "name"); digester.addObjectCreate("toplevel/element/element", NamedBean.class); // Parse our test input NamedBean root1 = null; try { // an exception will be thrown if the method can't be found root1 = (NamedBean) digester.parse(getInputStream("Test8.xml")); } catch (Throwable t) { // this means that the method can't be found and so the test fails fail("Digester threw Exception: " + t); } // if the CallMethodRule were to incorrectly invoke the method call // on the second-created NamedBean instance, then the root one would // have a null name. If it works correctly, the target element will // be the first-created (root) one, despite the fact that a second // object instance was created between the firing of the // CallMethodRule and its associated CallParamRule. assertEquals("Wrong method call order", "C", root1.getName()); } /** * Test nested CallMethod rules. *

* The current implementation of CallMethodRule, in which the method is * invoked in its end() method, causes behaviour which some users find * non-intuitive. In this test it can be seen to "reverse" the order of * data processed. However this is the way CallMethodRule has always * behaved, and it is expected that apps out there rely on this call order * so this test is present to ensure that no-one changes this behaviour. */ public void testOrderNestedPartB() throws Exception { // Configure the digester as required StringBuffer word = new StringBuffer(); digester.push(word); digester.addCallMethod("*/element", "append", 1); digester.addCallParam("*/element", 0, "name"); // Parse our test input Object root1 = null; try { // an exception will be thrown if the method can't be found root1 = digester.parse(getInputStream("Test8.xml")); assertNotNull(root1); } catch (Throwable t) { // this means that the method can't be found and so the test fails fail("Digester threw Exception: " + t); } assertEquals("Wrong method call order", "CBA", word.toString()); } public void testPrimitiveReading() throws Exception { StringReader reader = new StringReader( "" + "" + ""); Digester digester = new Digester(); //SimpleLog log = new SimpleLog("[testPrimitiveReading:Digester]"); //log.setLevel(SimpleLog.LOG_LEVEL_TRACE); //digester.setLogger(log); digester.addObjectCreate("root/bean", PrimitiveBean.class); digester.addSetNext("root/bean", "add"); Class [] params = { Boolean.TYPE }; digester.addCallMethod("root/bean", "setBoolean", 1, params); digester.addCallParam("root/bean", 0, "good"); digester.addObjectCreate("root/beanie", PrimitiveBean.class); digester.addSetNext("root/beanie", "add"); Class [] beanieParams = { String.class, Boolean.TYPE }; digester.addCallMethod("root/beanie", "testSetBoolean", 2, beanieParams); digester.addCallParam("root/beanie", 0, "bad"); digester.addCallParam("root/beanie", 1, "good"); ArrayList list = new ArrayList(); digester.push(list); digester.parse(reader); assertEquals("Wrong number of beans in list", 6, list.size()); PrimitiveBean bean = (PrimitiveBean) list.get(0); assertTrue("Bean 0 property not called", bean.getSetBooleanCalled()); assertEquals("Bean 0 property incorrect", true, bean.getBoolean()); bean = (PrimitiveBean) list.get(1); assertTrue("Bean 1 property not called", bean.getSetBooleanCalled()); assertEquals("Bean 1 property incorrect", false, bean.getBoolean()); bean = (PrimitiveBean) list.get(2); // no attibute, no call is what's expected assertTrue("Bean 2 property called", !bean.getSetBooleanCalled()); bean = (PrimitiveBean) list.get(3); assertTrue("Bean 3 property not called", bean.getSetBooleanCalled()); assertEquals("Bean 3 property incorrect", true, bean.getBoolean()); bean = (PrimitiveBean) list.get(4); assertTrue("Bean 4 property not called", bean.getSetBooleanCalled()); assertEquals("Bean 4 property incorrect", false, bean.getBoolean()); bean = (PrimitiveBean) list.get(5); assertTrue("Bean 5 property not called", bean.getSetBooleanCalled()); assertEquals("Bean 5 property incorrect", false, bean.getBoolean()); } public void testFromStack() throws Exception { StringReader reader = new StringReader( ""); Digester digester = new Digester(); Class [] params = { String.class }; digester.addObjectCreate("root/one", NamedBean.class); digester.addSetNext("root/one", "add"); digester.addCallMethod("root/one", "setName", 1, params); digester.addCallParam("root/one", 0, 2); digester.addObjectCreate("root/two", NamedBean.class); digester.addSetNext("root/two", "add"); digester.addCallMethod("root/two", "setName", 1, params); digester.addCallParam("root/two", 0, 3); digester.addObjectCreate("root/three", NamedBean.class); digester.addSetNext("root/three", "add"); digester.addCallMethod("root/three", "setName", 1, params); digester.addCallParam("root/three", 0, 4); digester.addObjectCreate("root/four", NamedBean.class); digester.addSetNext("root/four", "add"); digester.addCallMethod("root/four", "setName", 1, params); digester.addCallParam("root/four", 0, 5); digester.addObjectCreate("root/five", NamedBean.class); digester.addSetNext("root/five", "add"); Class [] newParams = { String.class, String.class }; digester.addCallMethod("root/five", "test", 2, newParams); digester.addCallParam("root/five", 0, 10); digester.addCallParam("root/five", 1, 3); // prepare stack digester.push("That lamb was sure to go."); digester.push("And everywhere that Mary went,"); digester.push("It's fleece was white as snow."); digester.push("Mary had a little lamb,"); ArrayList list = new ArrayList(); digester.push(list); digester.parse(reader); assertEquals("Wrong number of beans in list", 5, list.size()); NamedBean bean = (NamedBean) list.get(0); assertEquals("Parameter not set from stack (1)", "Mary had a little lamb,", bean.getName()); bean = (NamedBean) list.get(1); assertEquals("Parameter not set from stack (2)", "It's fleece was white as snow.", bean.getName()); bean = (NamedBean) list.get(2); assertEquals("Parameter not set from stack (3)", "And everywhere that Mary went,", bean.getName()); bean = (NamedBean) list.get(3); assertEquals("Parameter not set from stack (4)", "That lamb was sure to go.", bean.getName()); bean = (NamedBean) list.get(4); assertEquals("Out of stack not set to null", null , bean.getName()); } public void testTwoCalls() throws Exception { StringReader reader = new StringReader( "" + "25" + "50" + "90"); Digester digester = new Digester(); //SimpleLog log = new SimpleLog("{testTwoCalls:Digester]"); //log.setLevel(SimpleLog.LOG_LEVEL_TRACE); //digester.setLogger(log); digester.addObjectCreate( "root/param", ParamBean.class ); digester.addSetNext( "root/param", "add" ); digester.addCallMethod( "root/param", "setThisAndThat", 2 ); digester.addCallParam( "root/param", 0, "class" ); digester.addCallParam( "root/param", 1 ); digester.addCallMethod( "root/param", "setCool", 1, new Class[] {boolean.class } ); digester.addCallParam( "root/param", 0, "coolness" ); ArrayList list = new ArrayList(); digester.push(list); digester.parse(reader); assertEquals("Wrong number of objects created", 3, list.size()); ParamBean bean = (ParamBean) list.get(0); assertEquals("Coolness wrong (1)", true, bean.isCool()); assertEquals("This wrong (1)", "int", bean.getThis()); assertEquals("That wrong (1)", "25", bean.getThat()); bean = (ParamBean) list.get(1); assertEquals("Coolness wrong (2)", false, bean.isCool()); assertEquals("This wrong (2)", "long", bean.getThis()); assertEquals("That wrong (2)", "50", bean.getThat()); bean = (ParamBean) list.get(2); assertEquals("Coolness wrong (3)", false, bean.isCool()); assertEquals("This wrong (3)", "float", bean.getThis()); assertEquals("That wrong (3)", "90", bean.getThat()); } public void testNestedBody() throws Exception { StringReader reader = new StringReader( "" + "Simple" + "ComplexDeepDeeperDeepest" + ""); Digester digester = new Digester(); //SimpleLog log = new SimpleLog("[testPrimitiveReading:Digester]"); //log.setLevel(SimpleLog.LOG_LEVEL_TRACE); //digester.setLogger(log); digester.addObjectCreate("root/spam", NamedBean.class); digester.addSetRoot("root/spam", "add"); digester.addCallMethod( "root/spam", "setName", 1 ); digester.addCallParam( "root/spam", 0); digester.addObjectCreate("root/spam/spam", NamedBean.class); digester.addSetRoot("root/spam/spam", "add"); digester.addCallMethod( "root/spam/spam", "setName", 1 ); digester.addCallParam( "root/spam/spam", 0); digester.addObjectCreate("root/spam/spam/spam", NamedBean.class); digester.addSetRoot("root/spam/spam/spam", "add"); digester.addCallMethod( "root/spam/spam/spam", "setName", 1 ); digester.addCallParam( "root/spam/spam/spam", 0); digester.addObjectCreate("root/spam/spam/spam/spam", NamedBean.class); digester.addSetRoot("root/spam/spam/spam/spam", "add"); digester.addCallMethod( "root/spam/spam/spam/spam", "setName", 1 ); digester.addCallParam( "root/spam/spam/spam/spam", 0); ArrayList list = new ArrayList(); digester.push(list); digester.parse(reader); NamedBean bean = (NamedBean) list.get(0); assertEquals("Wrong name (1)", "Simple", bean.getName()); // these are added in deepest first order by the addRootRule bean = (NamedBean) list.get(4); assertEquals("Wrong name (2)", "Complex", bean.getName()); bean = (NamedBean) list.get(3); assertEquals("Wrong name (3)", "Deep", bean.getName()); bean = (NamedBean) list.get(2); assertEquals("Wrong name (4)", "Deeper", bean.getName()); bean = (NamedBean) list.get(1); assertEquals("Wrong name (5)", "Deepest", bean.getName()); } public void testProcessingHook() throws Exception { class TestCallMethodRule extends CallMethodRule { Object result; TestCallMethodRule(String methodName, int paramCount) { super(methodName, paramCount); } protected void processMethodCallResult(Object result) { this.result = result; } } StringReader reader = new StringReader( "" + "90"); Digester digester = new Digester(); //SimpleLog log = new SimpleLog("{testTwoCalls:Digester]"); //log.setLevel(SimpleLog.LOG_LEVEL_TRACE); //digester.setLogger(log); digester.addObjectCreate( "root/param", ParamBean.class ); digester.addSetNext( "root/param", "add" ); TestCallMethodRule rule = new TestCallMethodRule( "setThisAndThat" , 2 ); digester.addRule( "root/param", rule ); digester.addCallParam( "root/param", 0, "class" ); digester.addCallParam( "root/param", 1, "coolness" ); ArrayList list = new ArrayList(); digester.push(list); digester.parse(reader); assertEquals("Wrong number of objects created", 1, list.size()); assertEquals("Result not passed into hook", "The Other", rule.result); } /** Test for the PathCallParamRule */ public void testPathCallParam() throws Exception { String xml = "

" + "Ignore this" + "Ignore that" + "
"; SimpleTestBean bean = new SimpleTestBean(); bean.setAlphaBeta("[UNSET]", "[UNSET]"); StringReader in = new StringReader(xml); Digester digester = new Digester(); digester.setRules(new ExtendedBaseRules()); digester.addCallParamPath("*/alpha/?", 0); digester.addCallParamPath("*/epsilon/?", 1); digester.addCallMethod("main", "setAlphaBeta", 2); digester.push(bean); digester.parse(in); assertEquals("Test alpha property setting", "main/alpha/beta" , bean.getAlpha()); assertEquals("Test beta property setting", "main/beta/epsilon/gamma" , bean.getBeta()); } /** * Test invoking an object which does not exist on the stack. */ public void testCallInvalidTarget() throws Exception { Digester digester = new Digester(); digester.addObjectCreate("employee", HashMap.class); // there should be only one object on the stack (index zero), // so selecting a target object with index 1 on the object stack // should result in an exception. CallMethodRule r = new CallMethodRule(1, "put", 0); digester.addRule("employee", r); try { digester.parse(getInputStream("Test5.xml")); fail("Exception should be thrown for invalid target offset"); } catch(SAXException e) { // ok, exception expected } } /** * Test invoking an object which is at top-1 on the stack, like * SetNextRule does... */ public void testCallNext() throws Exception { Digester digester = new Digester(); digester.addObjectCreate("employee", HashMap.class); digester.addObjectCreate("employee/address", Address.class); digester.addSetNestedProperties("employee/address"); CallMethodRule r = new CallMethodRule(1, "put", 2); digester.addRule("employee/address", r); digester.addCallParam("employee/address/type", 0); digester.addCallParam("employee/address", 1, 0); HashMap map = (HashMap) digester.parse(getInputStream("Test5.xml")); assertNotNull(map); java.util.Set keys = map.keySet(); assertEquals(2, keys.size()); Address home = (Address) map.get("home"); assertNotNull(home); assertEquals("HmZip", home.getZipCode()); Address office = (Address) map.get("office"); assertNotNull(office); assertEquals("OfZip", office.getZipCode()); } /** * Test invoking an object which is at the root of the stack, like * SetRoot does... */ public void testCallRoot() throws Exception { Digester digester = new Digester(); digester.addObjectCreate("employee", HashMap.class); digester.addObjectCreate("employee/address", Address.class); digester.addSetNestedProperties("employee/address"); CallMethodRule r = new CallMethodRule(-1, "put", 2); digester.addRule("employee/address", r); digester.addCallParam("employee/address/type", 0); digester.addCallParam("employee/address", 1, 0); HashMap map = (HashMap) digester.parse(getInputStream("Test5.xml")); assertNotNull(map); java.util.Set keys = map.keySet(); assertEquals(2, keys.size()); Address home = (Address) map.get("home"); assertNotNull(home); assertEquals("HmZip", home.getZipCode()); Address office = (Address) map.get("office"); assertNotNull(office); assertEquals("OfZip", office.getZipCode()); } // ------------------------------------------------ Utility Support Methods /** * Return an appropriate InputStream for the specified test file (which * must be inside our current package. * * @param name Name of the test file we want * * @exception IOException if an input/output error occurs */ protected InputStream getInputStream(String name) throws IOException { return (this.getClass().getResourceAsStream ("/org/apache/commons/digester/" + name)); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/URLTestCase.java0000644000175000017500000000730511226450007031305 0ustar twernertwerner/* $Id: URLTestCase.java 479257 2006-11-26 01:54:32Z craigmcc $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.net.URL; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** *

Unit tests that exercise the new (in 1.8) methods for passing in * URL arguments instead of strings.

*/ public class URLTestCase extends TestCase { // ------------------------------------------------------------ Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public URLTestCase(String name) { super(name); } // ----------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(URLTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------------ Manifest Constants /** *

Public identifier of the Digester Rules DTD.

*/ private static final String DIGESTER_RULES_PUBLIC_ID = "-//Jakarta Apache //DTD digester-rules XML V1.0//EN"; /** *

System identifier of the Digester Rules DTD.

*/ private static final String DIGESTER_RULES_SYSTEM_ID = "/org/apache/commons/digester/xmlrules/digester-rules.dtd"; /** *

System identifier for the Digester Rules file that we will parse.

*/ private static final String TEST_INPUT_SYSTEM_ID = "/org/apache/commons/digester/xmlrules/test-call-param-rules.xml"; // ------------------------------------------------------ Instance Variables /** *

The Digester instance under test.

*/ private Digester digester = null; // ------------------------------------------------------------ Test Methods // Test a pristine instance public void testPristine() { assertNotNull(digester); } // Test parsing a resource, using a registered DTD, both passed with URLs public void testResource() throws Exception { Object root = null; // Register the Digester Rules DTD URL dtd = URLTestCase.class.getResource(DIGESTER_RULES_SYSTEM_ID); assertNotNull(dtd); digester.register(DIGESTER_RULES_PUBLIC_ID, dtd); // Parse one of the existing test resources twice with // the same Digester instance URL xml = URLTestCase.class.getResource(TEST_INPUT_SYSTEM_ID); assertNotNull(xml); root = digester.parse(xml); root = digester.parse(xml); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/RuleTestCase.java0000644000175000017500000006003111226450007031545 0ustar twernertwerner/* $Id: RuleTestCase.java 730332 2008-12-31 07:09:35Z rahul $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.SAXException; /** *

Test Case for the Digester class. These tests perform parsing of * XML documents to exercise the built-in rules.

* * @author Craig R. McClanahan * @author Janek Bogucki * @version $Revision: 730332 $ $Date: 2008-12-31 02:09:35 -0500 (Wed, 31 Dec 2008) $ */ public class RuleTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * The digester instance we will be processing. */ protected Digester digester = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public RuleTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(RuleTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods /** * Test object creation (and associated property setting) with nothing on * the stack, which should cause an appropriate Employee object to be * returned. */ public void testObjectCreate1() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", "org.apache.commons.digester.Employee"); digester.addSetProperties("employee"); // Parse our test input. Object root = null; root = digester.parse(getInputStream("Test1.xml")); assertNotNull("Digester returned an object", root); assertTrue("Digester returned an Employee", root instanceof Employee); Employee employee = (Employee) root; assertEquals("First name is correct", "First Name", employee.getFirstName()); assertEquals("Last name is correct", "Last Name", employee.getLastName()); } /** * Test object creation (and associated property setting) with nothing on * the stack, which should cause an appropriate Employee object to be * returned. The processing rules will process the nested Address elements * as well, but will not attempt to add them to the Employee. */ public void testObjectCreate2() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", Employee.class); digester.addSetProperties("employee"); digester.addObjectCreate("employee/address", "org.apache.commons.digester.Address"); digester.addSetProperties("employee/address"); // Parse our test input. Object root = null; root = digester.parse(getInputStream("Test1.xml")); assertNotNull("Digester returned an object", root); assertTrue("Digester returned an Employee", root instanceof Employee); Employee employee = (Employee) root; assertEquals("First name is correct", "First Name", employee.getFirstName()); assertEquals("Last name is correct", "Last Name", employee.getLastName()); } /** * Test object creation (and associated property setting) with nothing on * the stack, which should cause an appropriate Employee object to be * returned. The processing rules will process the nested Address elements * as well, and will add them to the owning Employee. */ public void testObjectCreate3() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", Employee.class); digester.addSetProperties("employee"); digester.addObjectCreate("employee/address", "org.apache.commons.digester.Address"); digester.addSetProperties("employee/address"); digester.addSetNext("employee/address", "addAddress"); // Parse our test input once Object root = null; root = digester.parse(getInputStream("Test1.xml")); validateObjectCreate3(root); // Parse the same input again try { root = digester.parse(getInputStream("Test1.xml")); } catch (Throwable t) { fail("Digester threw IOException: " + t); } validateObjectCreate3(root); } /** * Same as testObjectCreate1(), except use individual call method rules * to set the properties of the Employee. */ public void testObjectCreate4() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", Employee.class); digester.addCallMethod("employee", "setFirstName", 1); digester.addCallParam("employee", 0, "firstName"); digester.addCallMethod("employee", "setLastName", 1); digester.addCallParam("employee", 0, "lastName"); // Parse our test input. Object root = null; root = digester.parse(getInputStream("Test1.xml")); assertNotNull("Digester returned an object", root); assertTrue("Digester returned an Employee", root instanceof Employee); Employee employee = (Employee) root; assertEquals("First name is correct", "First Name", employee.getFirstName()); assertEquals("Last name is correct", "Last Name", employee.getLastName()); } /** * Same as testObjectCreate1(), except use individual call method rules * to set the properties of the Employee. Bean data are defined using * elements instead of attributes. The purpose is to test CallMethod with * a paramCount=0 (ie the body of the element is the argument of the * method). */ public void testObjectCreate5() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", Employee.class); digester.addCallMethod("employee/firstName", "setFirstName", 0); digester.addCallMethod("employee/lastName", "setLastName", 0); // Parse our test input. Object root = null; root = digester.parse(getInputStream("Test5.xml")); assertNotNull("Digester returned an object", root); assertTrue("Digester returned an Employee", root instanceof Employee); Employee employee = (Employee) root; assertEquals("First name is correct", "First Name", employee.getFirstName()); assertEquals("Last name is correct", "Last Name", employee.getLastName()); } /** * It should be possible to parse the same input twice, and get trees * of objects that are isomorphic but not be identical object instances. */ public void testRepeatedParse() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", Employee.class); digester.addSetProperties("employee"); digester.addObjectCreate("employee/address", "org.apache.commons.digester.Address"); digester.addSetProperties("employee/address"); digester.addSetNext("employee/address", "addAddress"); // Parse our test input the first time Object root1 = null; root1 = digester.parse(getInputStream("Test1.xml")); validateObjectCreate3(root1); // Parse our test input the second time Object root2 = null; root2 = digester.parse(getInputStream("Test1.xml")); validateObjectCreate3(root2); // Make sure that it was a different root assertTrue("Different tree instances were returned", root1 != root2); } /** * Test object creation (and associated property setting) with nothing on * the stack, which should cause an appropriate Employee object to be * returned. The processing rules will process the nested Address elements * as well, but will not attempt to add them to the Employee. */ public void testRuleSet1() throws SAXException, IOException { // Configure the digester as required RuleSet rs = new TestRuleSet(); digester.addRuleSet(rs); // Parse our test input. Object root = null; root = digester.parse(getInputStream("Test1.xml")); assertNotNull("Digester returned an object", root); assertTrue("Digester returned an Employee", root instanceof Employee); Employee employee = (Employee) root; assertEquals("First name is correct", "First Name", employee.getFirstName()); assertEquals("Last name is correct", "Last Name", employee.getLastName()); assertNotNull("Can retrieve home address", employee.getAddress("home")); assertNotNull("Can retrieve office address", employee.getAddress("office")); } /** * Same as testRuleSet1 except using a single namespace. */ public void testRuleSet2() throws SAXException, IOException { // Configure the digester as required digester.setNamespaceAware(true); RuleSet rs = new TestRuleSet(null, "http://commons.apache.org/digester/Foo"); digester.addRuleSet(rs); // Parse our test input. Object root = null; root = digester.parse(getInputStream("Test2.xml")); assertNotNull("Digester returned an object", root); assertTrue("Digester returned an Employee", root instanceof Employee); Employee employee = (Employee) root; assertEquals("First name is correct", "First Name", employee.getFirstName()); assertEquals("Last name is correct", "Last Name", employee.getLastName()); assertNotNull("Can retrieve home address", employee.getAddress("home")); assertNotNull("Can retrieve office address", employee.getAddress("office")); } /** * Same as testRuleSet2 except using a namespace * for employee that we should recognize, and a namespace for * address that we should skip. */ public void testRuleSet3() throws SAXException, IOException { // Configure the digester as required digester.setNamespaceAware(true); RuleSet rs = new TestRuleSet(null, "http://commons.apache.org/digester/Foo"); digester.addRuleSet(rs); // Parse our test input. Object root = null; root = digester.parse(getInputStream("Test3.xml")); assertNotNull("Digester returned an object", root); assertTrue("Digester returned an Employee", root instanceof Employee); Employee employee = (Employee) root; assertEquals("First name is correct", "First Name", employee.getFirstName()); assertEquals("Last name is correct", "Last Name", employee.getLastName()); assertNull("Can not retrieve home address", employee.getAddress("home")); assertNull("Can not retrieve office address", employee.getAddress("office")); } /** * Test the two argument version of the SetTopRule rule. This test is * based on testObjectCreate3 and should result in the same tree of * objects. Instead of using the SetNextRule rule which results in * a method invocation on the (top-1) (parent) object with the top * object (child) as an argument, this test uses the SetTopRule rule * which results in a method invocation on the top object (child) * with the top-1 (parent) object as an argument. The three argument * form is tested in testSetTopRule2. */ public void testSetTopRule1() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", "org.apache.commons.digester.Employee"); digester.addSetProperties("employee"); digester.addObjectCreate("employee/address", "org.apache.commons.digester.Address"); digester.addSetProperties("employee/address"); digester.addSetTop("employee/address", "setEmployee"); // Parse our test input. Object root = null; root = digester.parse(getInputStream("Test1.xml")); validateObjectCreate3(root); } /** * Same as testSetTopRule1 except using the three argument * form of the SetTopRule rule. */ public void testSetTopRule2() throws SAXException, IOException { // Configure the digester as required digester.addObjectCreate("employee", "org.apache.commons.digester.Employee"); digester.addSetProperties("employee"); digester.addObjectCreate("employee/address", "org.apache.commons.digester.Address"); digester.addSetProperties("employee/address"); digester.addSetTop("employee/address", "setEmployee", "org.apache.commons.digester.Employee"); // Parse our test input. Object root = null; root = digester.parse(getInputStream("Test1.xml")); validateObjectCreate3(root); } /** * Test rule addition - this boils down to making sure that * digester is set properly on rule addition. */ public void testAddRule() { Digester digester = new Digester(); TestRule rule = new TestRule("Test"); digester.addRule("/root", rule); assertEquals("Digester is not properly on rule addition.", digester, rule.getDigester()); } public void testSetNext() throws SAXException, IOException { Digester digester = new Digester(); digester.setRules(new ExtendedBaseRules()); digester.setValidating(false); digester.addObjectCreate("!*/b", BetaBean.class); digester.addObjectCreate("!*/a", AlphaBean.class); digester.addObjectCreate("root", ArrayList.class); digester.addSetProperties("!*"); digester.addSetNext("!*/b/?", "setChild"); digester.addSetNext("!*/a/?", "setChild"); digester.addSetNext("!root/?", "add"); ArrayList root = (ArrayList) digester.parse(getInputStream("Test4.xml")); assertEquals("Wrong array size", 2, root.size()); AlphaBean one = (AlphaBean) root.get(0); assertTrue(one.getChild() instanceof BetaBean); BetaBean two = (BetaBean) one.getChild(); assertEquals("Wrong name (1)", two.getName() , "TWO"); assertTrue(two.getChild() instanceof AlphaBean); AlphaBean three = (AlphaBean) two.getChild(); assertEquals("Wrong name (2)", three.getName() , "THREE"); BetaBean four = (BetaBean) root.get(1); assertEquals("Wrong name (3)", four.getName() , "FOUR"); assertTrue(four.getChild() instanceof BetaBean); BetaBean five = (BetaBean) four.getChild(); assertEquals("Wrong name (4)", five.getName() , "FIVE"); } public void testSetTop() throws SAXException, IOException { Digester digester = new Digester(); digester.setRules(new ExtendedBaseRules()); digester.setValidating(false); digester.addObjectCreate("!*/b", BetaBean.class); digester.addObjectCreate("!*/a", AlphaBean.class); digester.addObjectCreate("root", ArrayList.class); digester.addSetProperties("!*"); digester.addSetTop("!*/b/?", "setParent"); digester.addSetTop("!*/a/?", "setParent"); digester.addSetRoot("!*/a", "add"); digester.addSetRoot("!*/b", "add"); ArrayList root = (ArrayList) digester.parse(getInputStream("Test4.xml")); assertEquals("Wrong array size", 5, root.size()); // note that the array is in popped order (rather than pushed) Object obj = root.get(1); assertTrue("TWO should be a BetaBean", obj instanceof BetaBean); BetaBean two = (BetaBean) obj; assertNotNull("Two's parent should not be null", two.getParent()); assertEquals("Wrong name (1)", "TWO", two.getName()); assertEquals("Wrong name (2)", "ONE", two.getParent().getName() ); obj = root.get(0); assertTrue("THREE should be an AlphaBean", obj instanceof AlphaBean); AlphaBean three = (AlphaBean) obj; assertNotNull("Three's parent should not be null", three.getParent()); assertEquals("Wrong name (3)", "THREE", three.getName()); assertEquals("Wrong name (4)", "TWO", three.getParent().getName()); obj = root.get(3); assertTrue("FIVE should be a BetaBean", obj instanceof BetaBean); BetaBean five = (BetaBean) obj; assertNotNull("Five's parent should not be null", five.getParent()); assertEquals("Wrong name (5)", "FIVE", five.getName()); assertEquals("Wrong name (6)", "FOUR", five.getParent().getName()); } /** */ public void testSetCustomProperties() throws SAXException, IOException { Digester digester = new Digester(); digester.setValidating(false); digester.addObjectCreate("toplevel", ArrayList.class); digester.addObjectCreate("toplevel/one", Address.class); digester.addSetNext("toplevel/one", "add"); digester.addObjectCreate("toplevel/two", Address.class); digester.addSetNext("toplevel/two", "add"); digester.addObjectCreate("toplevel/three", Address.class); digester.addSetNext("toplevel/three", "add"); digester.addObjectCreate("toplevel/four", Address.class); digester.addSetNext("toplevel/four", "add"); digester.addSetProperties("toplevel/one"); digester.addSetProperties( "toplevel/two", new String[] {"alt-street", "alt-city", "alt-state"}, new String[] {"street", "city", "state"}); digester.addSetProperties( "toplevel/three", new String[] {"aCity", "state"}, new String[] {"city"}); digester.addSetProperties("toplevel/four", "alt-city", "city"); ArrayList root = (ArrayList) digester.parse(getInputStream("Test7.xml")); assertEquals("Wrong array size", 4, root.size()); // note that the array is in popped order (rather than pushed) Object obj = root.get(0); assertTrue("(1) Should be an Address ", obj instanceof Address); Address addressOne = (Address) obj; assertEquals("(1) Street attribute", "New Street", addressOne.getStreet()); assertEquals("(1) City attribute", "Las Vegas", addressOne.getCity()); assertEquals("(1) State attribute", "Nevada", addressOne.getState()); obj = root.get(1); assertTrue("(2) Should be an Address ", obj instanceof Address); Address addressTwo = (Address) obj; assertEquals("(2) Street attribute", "Old Street", addressTwo.getStreet()); assertEquals("(2) City attribute", "Portland", addressTwo.getCity()); assertEquals("(2) State attribute", "Oregon", addressTwo.getState()); obj = root.get(2); assertTrue("(3) Should be an Address ", obj instanceof Address); Address addressThree = (Address) obj; assertEquals("(3) Street attribute", "4th Street", addressThree.getStreet()); assertEquals("(3) City attribute", "Dayton", addressThree.getCity()); assertEquals("(3) State attribute", "US" , addressThree.getState()); obj = root.get(3); assertTrue("(4) Should be an Address ", obj instanceof Address); Address addressFour = (Address) obj; assertEquals("(4) Street attribute", "6th Street", addressFour.getStreet()); assertEquals("(4) City attribute", "Cleveland", addressFour.getCity()); assertEquals("(4) State attribute", "Ohio", addressFour.getState()); } // ------------------------------------------------ Utility Support Methods /** * Return an appropriate InputStream for the specified test file (which * must be inside our current package. * * @param name Name of the test file we want * * @exception IOException if an input/output error occurs */ protected InputStream getInputStream(String name) throws IOException { return (this.getClass().getResourceAsStream ("/org/apache/commons/digester/" + name)); } /** * Validate the assertions for ObjectCreateRule3. * * @param root Root object returned by digester.parse() */ protected void validateObjectCreate3(Object root) { // Validate the retrieved Employee assertNotNull("Digester returned an object", root); assertTrue("Digester returned an Employee", root instanceof Employee); Employee employee = (Employee) root; assertEquals("First name is correct", "First Name", employee.getFirstName()); assertEquals("Last name is correct", "Last Name", employee.getLastName()); // Validate the corresponding "home" Address Address home = employee.getAddress("home"); assertNotNull("Retrieved home address", home); assertEquals("Home street", "Home Street", home.getStreet()); assertEquals("Home city", "Home City", home.getCity()); assertEquals("Home state", "HS", home.getState()); assertEquals("Home zip", "HmZip", home.getZipCode()); // Validate the corresponding "office" Address Address office = employee.getAddress("office"); assertNotNull("Retrieved office address", office); assertEquals("Office street", "Office Street", office.getStreet()); assertEquals("Office city", "Office City", office.getCity()); assertEquals("Office state", "OS", office.getState()); assertEquals("Office zip", "OfZip", office.getZipCode()); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/0000755000175000017500000000000011226450007030212 5ustar twernertwerner././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/test-node-create-rules.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/test-node-create-r0000644000175000017500000000216611226450007033544 0ustar twernertwerner ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testrulesinclude.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testrulesinclude.x0000644000175000017500000000212111226450007033775 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testrules.xml0000644000175000017500000000413311226450007032767 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/test.xml0000644000175000017500000000264711226450007031724 0ustar twernertwerner 555 somestringvalue foo bar I am a property! I am a property! ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testfactoryignore.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testfactoryignore.0000644000175000017500000000225711226450007033774 0ustar twernertwerner ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testfactorynoignore.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testfactorynoignor0000644000175000017500000000217411226450007034104 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/IncludeTest.java0000644000175000017500000000510511226450007033301 0ustar twernertwerner/* $Id: IncludeTest.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import java.util.ArrayList; import java.io.StringReader; import org.xml.sax.InputSource; import junit.framework.TestCase; import org.apache.commons.digester.Digester; import org.apache.commons.digester.Rule; /** * Test for the include class functionality */ public class IncludeTest extends TestCase { public static class TestDigesterRuleSource implements DigesterRulesSource { public void getRules(Digester digester) { digester.addRule("bar", new Rule() { public void body(String namespace, String name, String text) { ((ArrayList) this.digester.peek()).add(text); } }); } } public IncludeTest(String testName) { super(testName); } public void testBasicInclude() throws Exception { String rulesXml = "" + "" + " " + " " + " " + ""; String xml = "short"; ArrayList list = new ArrayList(); Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(rulesXml))); digester.push(list); digester.parse(new StringReader(xml)); assertEquals("Number of entries", 1, list.size()); assertEquals("Entry value", "short", list.get(0)); } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testPropertyAliasRules.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testPropertyAliasR0000644000175000017500000000410111226450007033751 0ustar twernertwerner ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/DigesterPatternStackTest.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/DigesterPatternSta0000644000175000017500000000633711226450007033722 0ustar twernertwerner/* $Id: DigesterPatternStackTest.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import junit.framework.TestCase; import junit.framework.TestSuite; /** * This test case tests the behavior of * DigesterRuleParser.PatternStack, a specialized stack whose * toString() method returns a /-separated representation of the * stack's elements. The tests ensure that * DigesterRuleParser.PatternStack.toString() returns the properly * formatted string. */ public class DigesterPatternStackTest extends TestCase { public DigesterPatternStackTest(String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public static junit.framework.Test suite() { TestSuite suite = new TestSuite(DigesterPatternStackTest.class); return suite; } private DigesterRuleParser.PatternStack stack; public void setUp() { DigesterRuleParser parser = new DigesterRuleParser(); stack = parser.patternStack; } public void test1() throws Exception { assertEquals("", stack.toString()); } public void test2() throws Exception { stack.push("A"); assertEquals("A", stack.toString()); stack.pop(); assertEquals("", stack.toString()); } public void test3() throws Exception { stack.push("A"); stack.push("B"); assertEquals("A/B", stack.toString()); stack.pop(); assertEquals("A", stack.toString()); } public void test4() throws Exception { stack.push(""); assertEquals("", stack.toString()); stack.push(""); assertEquals("", stack.toString()); } public void test5() throws Exception { stack.push("A"); assertEquals("A", stack.toString()); stack.push(""); stack.push(""); assertEquals("A", stack.toString()); } public void test6() throws Exception { stack.push("A"); stack.push("B"); stack.clear(); assertEquals("", stack.toString()); } public void test7() throws Exception { stack.push("///"); assertEquals("///", stack.toString()); stack.push("/"); assertEquals("/////", stack.toString()); stack.pop(); assertEquals("///", stack.toString()); stack.pop(); assertEquals("", stack.toString()); } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/ThrowExceptionCreationFactory.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/ThrowExceptionCrea0000644000175000017500000000251511226450007033715 0ustar twernertwerner/* $Id: ThrowExceptionCreationFactory.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import org.apache.commons.digester.AbstractObjectCreationFactory; import org.xml.sax.Attributes; /** * Object creation factory used for testing exception propagation. * * @author Robert Burrell Donkin */ public class ThrowExceptionCreationFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) throws Exception { throw new RuntimeException(); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testfactory.xml0000644000175000017500000000231311226450007033302 0ustar twernertwerner ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/FromXmlRuleSetTest.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/FromXmlRuleSetTest0000644000175000017500000000640711226450007033674 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import java.io.StringReader; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; import org.xml.sax.InputSource; /** * Tests loading Digester rules from an XML file. */ public class FromXmlRuleSetTest extends TestCase { public FromXmlRuleSetTest(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public static junit.framework.Test suite() { TestSuite suite = new TestSuite(FromXmlRuleSetTest.class); return suite; } /** * Test the FromXmlRules.addRuleInstances(digester, path) method, ie * test loading rules at a base position other than the root. */ public void testBasePath() throws Exception { String xmlRules = "" + "" + " " + " " + " " + ""; String xml = "" + "" + " success" + ""; // First try with no base path. The rule shouldn't match, because // foo is not the root element. { TestObject testObject = new TestObject(); FromXmlRuleSet ruleset = new FromXmlRuleSet( new InputSource(new StringReader(xmlRules))); Digester digester = new Digester(); ruleset.addRuleInstances(digester); digester.push(testObject); digester.parse(new InputSource(new StringReader(xml))); assertEquals("", testObject.getProperty()); } // Now try with a base path. The rule should now match. { TestObject testObject = new TestObject(); FromXmlRuleSet ruleset = new FromXmlRuleSet( new InputSource(new StringReader(xmlRules))); Digester digester = new Digester(); ruleset.addRuleInstances(digester, "root"); digester.push(testObject); digester.parse(new InputSource(new StringReader(xml))); assertEquals("success", testObject.getProperty()); } } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest0000644000175000017500000003717611226450007033710 0ustar twernertwerner/* $Id: DigesterLoaderTest.java 474932 2006-11-14 19:36:29Z rahul $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import java.io.InputStream; import java.io.StringReader; import java.net.URL; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Address; import org.apache.commons.digester.Digester; import org.apache.commons.digester.TestObjectCreationFactory; import org.w3c.dom.Node; import org.xml.sax.InputSource; /** * Tests loading Digester rules from an XML file. * * @author David H. Martin - Initial Contribution * @author Scott Sanders - Added ASL, removed external dependencies */ public class DigesterLoaderTest extends TestCase { public DigesterLoaderTest(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public static junit.framework.Test suite() { TestSuite suite = new TestSuite(DigesterLoaderTest.class); return suite; } /** * Tests the DigesterLoader.createDigester(), with multiple * included rule sources: testrules.xml includes another rules xml * file, and also includes programmatically created rules. */ public void testCreateDigester() throws Exception { URL rules = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/testrules.xml"); URL input = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/test.xml"); assertNotNull("The test could not locate testrules.xml", rules); assertNotNull("The test could not locate test.xml", input); Digester digester = DigesterLoader.createDigester(rules); digester.push(new ArrayList()); Object root = digester.parse(input.openStream()); assertEquals("[foo1 baz1 foo2, foo3 foo4]",root.toString()); } /** * Tests the DigesterLoader.load(), with multiple included rule * sources: testrules.xml includes another rules xml file, and * also includes programmatically created rules. */ public void testLoad1() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); URL rules = classLoader.getResource("org/apache/commons/digester/xmlrules/testrules.xml"); URL input = classLoader.getResource("org/apache/commons/digester/xmlrules/test.xml"); assertNotNull("The test could not locate testrules.xml", rules); assertNotNull("The test could not locate test.xml", input); Object root = DigesterLoader.load(rules, classLoader, input, new ArrayList()); if (!(root instanceof ArrayList)) { fail("Unexpected object returned from DigesterLoader. Expected ArrayList; got " + root.getClass().getName()); } assertEquals( "[foo1 baz1 foo2, foo3 foo4]",root.toString()); ArrayList al = (ArrayList)root; Object obj = al.get(0); if (! (obj instanceof TestObject)) { fail("Unexpected object returned from DigesterLoader. Expected TestObject; got " + obj.getClass().getName()); } TestObject to = (TestObject)obj; assertEquals(new Long(555),to.getLongValue()); assertEquals( "foo", to.getMapValue( "test1" ) ); assertEquals( "bar", to.getMapValue( "test2" ) ); } /** * The same as testLoad1, exception the input file is passed to * DigesterLoader as an InputStream instead of a URL. */ public void testLoad2() throws Exception { URL rules = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/testrules.xml"); InputStream input = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/test.xml").openStream(); Object root = DigesterLoader.load(rules, getClass().getClassLoader(), input, new ArrayList()); if (!(root instanceof ArrayList)) { fail("Unexpected object returned from DigesterLoader. Expected ArrayList; got " + root.getClass().getName()); } ArrayList list = (ArrayList) root; assertEquals(root.toString(), "[foo1 baz1 foo2, foo3 foo4]"); assertEquals("Wrong number of classes created", 2 , list.size()); assertEquals("Pushed first", true , ((TestObject)list.get(0)).isPushed()); assertEquals("Didn't push second", false , ((TestObject)list.get(1)).isPushed()); assertTrue("Property was set properly", ((TestObject)list.get(0)).getProperty().equals("I am a property!") ); } /** * Validates that circular includes are detected and result in an exception */ public void testCircularInclude1() { URL rules = ClassLoader.getSystemResource("org/apache/commons/digester/xmlrules/testCircularRules.xml"); try { Digester digester = DigesterLoader.createDigester(rules); assertNotNull(digester); // just to prevent compiler warning on unused var } catch (Exception ex) { return; } fail("Creating a digester with circular rules should have thrown CircularIncludeException."); } /** */ public void testSetCustomProperties() throws Exception { URL rules = getClass().getClassLoader().getResource ("org/apache/commons/digester/xmlrules/testPropertyAliasRules.xml"); InputStream input = getClass().getClassLoader().getResource ("org/apache/commons/digester/Test7.xml").openStream(); Object obj = DigesterLoader.load( rules, getClass().getClassLoader(), input, new ArrayList()); if (!(obj instanceof ArrayList)) { fail( "Unexpected object returned from DigesterLoader. Expected ArrayList; got " + obj.getClass().getName()); } ArrayList root = (ArrayList) obj; assertEquals("Wrong array size", 4, root.size()); // note that the array is in popped order (rather than pushed) obj = root.get(0); assertTrue("(1) Should be an Address ", obj instanceof Address); Address addressOne = (Address) obj; assertEquals("(1) Street attribute", "New Street", addressOne.getStreet()); assertEquals("(1) City attribute", "Las Vegas", addressOne.getCity()); assertEquals("(1) State attribute", "Nevada", addressOne.getState()); obj = root.get(1); assertTrue("(2) Should be an Address ", obj instanceof Address); Address addressTwo = (Address) obj; assertEquals("(2) Street attribute", "Old Street", addressTwo.getStreet()); assertEquals("(2) City attribute", "Portland", addressTwo.getCity()); assertEquals("(2) State attribute", "Oregon", addressTwo.getState()); obj = root.get(2); assertTrue("(3) Should be an Address ", obj instanceof Address); Address addressThree = (Address) obj; assertEquals("(3) Street attribute", "4th Street", addressThree.getStreet()); assertEquals("(3) City attribute", "Dayton", addressThree.getCity()); assertEquals("(3) State attribute", "US" , addressThree.getState()); obj = root.get(3); assertTrue("(4) Should be an Address ", obj instanceof Address); Address addressFour = (Address) obj; assertEquals("(4) Street attribute", "6th Street", addressFour.getStreet()); assertEquals("(4) City attribute", "Cleveland", addressFour.getCity()); assertEquals("(4) State attribute", "Ohio", addressFour.getState()); } public void testFactoryCreateRule() throws Exception { URL rules = getClass().getClassLoader().getResource ("org/apache/commons/digester/xmlrules/testfactory.xml"); String xml = ""; Object obj = DigesterLoader.load( rules, getClass().getClassLoader(), new StringReader(xml), new ArrayList()); if (!(obj instanceof ArrayList)) { fail( "Unexpected object returned from DigesterLoader. Expected ArrayList; got " + obj.getClass().getName()); } ArrayList list = (ArrayList) obj; assertEquals("List should contain only the factory object", list.size() , 1); TestObjectCreationFactory factory = (TestObjectCreationFactory) list.get(0); assertEquals("Object create not called(1)", factory.called , true); assertEquals( "Attribute not passed (1)", factory.attributes.getValue("one"), "good"); assertEquals( "Attribute not passed (2)", factory.attributes.getValue("two"), "bad"); assertEquals( "Attribute not passed (3)", factory.attributes.getValue("three"), "ugly"); rules = getClass().getClassLoader().getResource ("org/apache/commons/digester/xmlrules/testfactoryignore.xml"); xml = ""; try { DigesterLoader.load( rules, getClass().getClassLoader(), new StringReader(xml)); } catch (Exception e) { fail("This exception should have been ignored: " + e.getClass().getName()); } rules = getClass().getClassLoader().getResource ("org/apache/commons/digester/xmlrules/testfactorynoignore.xml"); xml = ""; try { DigesterLoader.load( rules, getClass().getClassLoader(), new StringReader(xml)); fail("Exception should have been propagated from create method."); } catch (Exception e) { /* What we expected */ assertEquals(org.xml.sax.SAXParseException.class, e.getClass()); } } public void testCallParamRule() throws Exception { URL rules = getClass().getClassLoader().getResource ("org/apache/commons/digester/xmlrules/test-call-param-rules.xml"); String xml = "" + "shorttosh"; CallParamTestObject testObject = new CallParamTestObject(); DigesterLoader.load( rules, getClass().getClassLoader(), new StringReader(xml), testObject); assertEquals("Incorrect left value", "long", testObject.getLeft()); assertEquals("Incorrect middle value", "short", testObject.getMiddle()); assertEquals("Incorrect right value", "", testObject.getRight()); } public void testInputSourceLoader() throws Exception { String rulesXml = "" + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; String xml = "" + "shorttosh"; CallParamTestObject testObject = new CallParamTestObject(); Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(rulesXml))); digester.push(testObject); digester.parse(new StringReader(xml)); assertEquals("Incorrect left value", "long", testObject.getLeft()); assertEquals("Incorrect middle value", "short", testObject.getMiddle()); assertEquals("Incorrect right value", "", testObject.getRight()); } public void testNodeCreateRule() throws Exception { URL rules = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/test-node-create-rules.xml"); URL input = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/test-node-create-rules-input.xml"); assertNotNull("The test could not locate test-node-create-rules.xml", rules); assertNotNull("The test could not locate test-node-create-rules-input.xml", input); Digester digester = DigesterLoader.createDigester(rules); digester.push(new ArrayList()); Object root = digester.parse(input.openStream()); assertNotNull("root was null", root); assertTrue("no nodes were captured.", (((List)root).size() > 0)); Object[] nodeArray = (Object[])((List)root).toArray(); assertNotNull("resulting node array from array list was null", nodeArray); // test foo1 structure Node foo1 = (Node)nodeArray[0]; assertTrue("foo1 didn't have any children", foo1.hasChildNodes()); Node foo1Bar1 = foo1.getFirstChild(); assertTrue("foo1's child was not named bar1", "bar1".equals(foo1Bar1.getNodeName())); assertTrue("foo1/bar1 value was not bar-1-value", "bar1-value".equals(foo1Bar1.getFirstChild().getNodeValue())); } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/TestDigesterRulesSource.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/TestDigesterRulesS0000644000175000017500000000323711226450007033706 0ustar twernertwerner/* $Id: TestDigesterRulesSource.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import org.apache.commons.digester.Digester; /** * A test class, for validating FromXmlRuleSet's ability to 'include' * programmatically-created rules from within an XML rules file. * * @author David H. Martin - Initial Contribution * @author Scott Sanders - Added ASL, removed external dependencies */ public class TestDigesterRulesSource implements DigesterRulesSource { /** * Creates and adds Digester Rules to a given Rules object * @param digester the Digester to add the new Rule objects to */ public void getRules(Digester digester) { digester.addObjectCreate("/baz", TestObject.class.getName()); digester.addSetNext("/baz", "add", "java.lang.Object"); digester.addSetProperties("/baz"); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/CallParamTestObject.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/CallParamTestObjec0000644000175000017500000000370711226450007033603 0ustar twernertwerner/* $Id: CallParamTestObject.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; /** * Object for use with testing call param rules. * * @author Robert Burrell Donkin */ public class CallParamTestObject { private String left = "UNSET"; private String right = "UNSET"; private String middle = "UNSET"; public void triple(String left, String middle, String right) { this.left = left; this.right = right; this.middle = middle; } public void duo(String left, String right) { this.left = left; this.right = right; } public String getLeft() { return left; } public String getRight() { return right; } public String getMiddle() { return middle; } public void setLeft(String left) { this.left=left; } public void setRight(String right) { this.right = right; } public void setMiddle(String middle) { this.middle = middle; } public String toString() { return "LEFT: " + left + " MIDDLE:" + middle + " RIGHT:" + right; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/TestObject.java0000644000175000017500000000502411226450007033124 0ustar twernertwerner/* $Id: TestObject.java 472840 2006-11-09 10:18:34Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; /** * Test harness object for holding results of digestion. * * @author David H. Martin - Initial Contribution * @author Scott Sanders - Added ASL, removed external dependencies * @author Tim O'Brien - Added bean property to test bean property setter rule */ public class TestObject { private ArrayList children = new ArrayList(); private String value = ""; private Long longValue = new Long(-1L); private String property = ""; private HashMap mapValue = new HashMap(); private boolean pushed = false; public TestObject() { } public String toString() { String str = value; for (Iterator i = children.iterator(); i.hasNext();) { str += " " + i.next(); } return str; } public void add(Object o) { children.add(o); } public void setValue(String val) { value = val; } public void setLongValue(Long val) { longValue = val; } public Long getLongValue() { return longValue; } public void setStringValue(String val) { } public boolean isPushed() { return pushed; } public void push() { pushed = true; } public void setMapValue( String name, String value ) { this.mapValue.put( name, value ); } public String getMapValue( String name ) { return (String) this.mapValue.get( name ); } public String getProperty() { return property; } public void setProperty(String pProperty) { property = pProperty; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testCircularRules.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/testCircularRules.0000644000175000017500000000244011226450007033672 0ustar twernertwerner ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderRulesTest.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderRule0000644000175000017500000001303211226450007033661 0ustar twernertwerner/* $Id: DigesterLoaderRulesTest.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import java.io.StringReader; import junit.framework.TestCase; import org.xml.sax.InputSource; import org.apache.commons.digester.Digester; /** * Tests for digester loader rule implementations, * * @author Robert Burrell Donkin */ public class DigesterLoaderRulesTest extends TestCase { public DigesterLoaderRulesTest(java.lang.String testName) { super(testName); } /** Basic test for object param rule */ public void testObjectParamRule() throws Exception { String xmlRules = "" + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; String xml = "" + "" + " " + " " + " " + " " + ""; CallParamTestObject testObject = new CallParamTestObject(); Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(xmlRules))); digester.push(testObject); digester.parse(new InputSource(new StringReader(xml))); assertEquals("First param", "", testObject.getLeft()); assertEquals("Param with default set", "tester.test", testObject.getRight()); } /** Test for call method rule with target offset */ public void testCallMethodRuleTargetOffset() throws Exception { String xmlRules = "" + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; String xml = "" + "" + " DataForTheTopObject" + " DataForTheParentObject" + " DataForTheRootObject" + ""; CallParamTestObject testObjectA = new CallParamTestObject(); CallParamTestObject testObjectB = new CallParamTestObject(); CallParamTestObject testObjectC = new CallParamTestObject(); Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(xmlRules))); digester.push( testObjectA ); digester.push( testObjectB ); digester.push( testObjectC ); digester.parse(new InputSource(new StringReader(xml))); assertEquals("Top object invoked", "DataForTheTopObject", testObjectC.getMiddle()); assertEquals("Parent object invoked", "DataForTheParentObject", testObjectB.getLeft()); assertEquals("Root object invoked", "DataForTheRootObject", testObjectA.getRight()); } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/test-node-create-rules-input.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/test-node-create-r0000644000175000017500000000163711226450007033546 0ustar twernertwerner bar1-value ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/test-call-param-rules.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/test-call-param-ru0000644000175000017500000000335411226450007033554 0ustar twernertwerner ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTestSuite.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest0000644000175000017500000000332211226450007033672 0ustar twernertwerner/* $Id: DigesterLoaderTestSuite.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Tests loading Digester rules from an XML file. * * @author Scott Sanders */ public class DigesterLoaderTestSuite extends TestCase { public DigesterLoaderTestSuite(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public static junit.framework.Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(FromXmlRuleSetTest.class); suite.addTestSuite(DigesterLoaderTest.class); suite.addTestSuite(DigesterPatternStackTest.class); suite.addTestSuite(DigesterLoaderRulesTest.class); suite.addTestSuite(IncludeTest.class); return suite; } }libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test3.xml0000644000175000017500000000233011226450007030061 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Nameable.java0000644000175000017500000000201211226450007030701 0ustar twernertwerner/* $Id: Nameable.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * Interface used for testing. */ public interface Nameable { String getName(); void setName(String name); } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/SetNestedPropertiesRuleTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/SetNestedPropertiesRuleTest0000644000175000017500000004054111226450007033731 0ustar twernertwerner/* $Id: SetNestedPropertiesRuleTestCase.java 472840 2006-11-09 10:18:34Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.SAXException; /** *

Test case for SetNestedPropertiesRule. * This contains tests for the main applications of the rule * and two more general tests of digester functionality used by this rule. */ public class SetNestedPropertiesRuleTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * Simple test xml document used in the tests. */ protected final static String TEST_XML = "" + "ROOT BODY" + "ALPHA BODY" + "BETA BODY" + "GAMMA BODY" + "DELTA BODY" + ""; /** * The digester instance we will be processing. */ protected Digester digester = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public SetNestedPropertiesRuleTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(SetNestedPropertiesRuleTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods /** * Test that you can successfully automatically set properties. */ public void testAutomaticallySetProperties() throws SAXException, IOException { // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); // match all children of root with this rule digester.addRule("root", new SetNestedPropertiesRule()); SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader()); // check properties are set correctly assertEquals( "Property alpha not set correctly", "ALPHA BODY", bean.getAlpha()); assertEquals( "Property beta not set correctly", "BETA BODY", bean.getBeta()); assertEquals( "Property gamma not set correctly", "GAMMA BODY", bean.getGamma()); assertEquals( "Property delta not set correctly", "DELTA BODY", bean.getDeltaValue()); } /** * Test that it is an error when a child element exists but no corresponding * java property exists. */ public void testMandatoryProperties() throws SAXException, IOException { String TEST_XML = "" + "ROOT BODY" + "ALPHA BODY" + ""; // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); // match all children of root with this rule digester.addRule("root", new SetNestedPropertiesRule()); try { SimpleTestBean bean = (SimpleTestBean) digester.parse( new StringReader(TEST_XML)); // we should never get here... fail("No exception thrown by parse when unknown child element found."); assertNotNull(bean); // just to prevent compiler warning on unused var } catch(org.xml.sax.SAXParseException e) { String msg = e.getMessage(); if (msg.indexOf("badprop") >= 0) { // ok, this is expected; there is no "setBadprop" method on the // SimpleTestBean class... } else { fail("Unexpected parse exception:" + e.getMessage()); } } } /** * Test that you can customise the property mappings using the * constructor which takes arrays-of-strings. */ public void testCustomisedProperties1() throws SAXException, IOException { String TEST_XML = "" + "ROOT BODY" + "ALPHA BODY" + "BETA BODY" + "GAMMA BODY" + "DELTA BODY" + ""; // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); // ignore the "alpha" element (target=null) // don't remap the "beta" element // map the gamma-alt element into the gamma property // ignore the delta element (no matching element in array) Rule rule = new SetNestedPropertiesRule( new String[]{"alpha", "gamma-alt", "delta"}, new String[]{null, "gamma"}); digester.addRule("root", rule); SimpleTestBean bean = (SimpleTestBean) digester.parse( new StringReader(TEST_XML)); // check properties are set correctly assertEquals( "Property alpha was not ignored (it should be)", null, bean.getAlpha()); assertEquals( "Property beta not set correctly", "BETA BODY", bean.getBeta()); assertEquals( "Property gamma not set correctly", "GAMMA BODY", bean.getGamma()); assertEquals( "Property delta was not ignored (it should be)", null, bean.getDeltaValue()); // check no bad rules object is left assertEquals( "Digester rules object not reset.", RulesBase.class, digester.getRules().getClass()); } /** * Test that you can ignore a single input xml element using the * constructor which takes a single remapping. */ public void testCustomisedProperties2a() throws SAXException, IOException { String TEST_XML = "" + "ROOT BODY" + "ALPHA BODY" + "BETA BODY" + "GAMMA BODY" + "DELTA BODY" + ""; // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); // ignore the "alpha" element (target=null) Rule rule = new SetNestedPropertiesRule("alpha", null); digester.addRule("root", rule); SimpleTestBean bean = (SimpleTestBean) digester.parse( new StringReader(TEST_XML)); // check properties are set correctly assertEquals( "Property alpha was not ignored (it should be)", null, bean.getAlpha()); assertEquals( "Property beta not set correctly", "BETA BODY", bean.getBeta()); assertEquals( "Property gamma not set correctly", "GAMMA BODY", bean.getGamma()); assertEquals( "Property delta not set correctly", "DELTA BODY", bean.getDeltaValue()); // check no bad rules object is left assertEquals( "Digester rules object not reset.", RulesBase.class, digester.getRules().getClass()); } /** * Test that you can customise the property mappings using the * constructor which takes a single remapping. */ public void testCustomisedProperties2b() throws SAXException, IOException { String TEST_XML = "" + "ROOT BODY" + "ALPHA BODY" + "BETA BODY" + "GAMMA BODY" + "DELTA BODY" + ""; // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); // map the contents of the alpha-alt xml child into the // "alpha" java property. Rule rule = new SetNestedPropertiesRule("alpha-alt", "alpha"); digester.addRule("root", rule); SimpleTestBean bean = (SimpleTestBean) digester.parse( new StringReader(TEST_XML)); // check properties are set correctly assertEquals( "Property alpha not set correctly", "ALPHA BODY", bean.getAlpha()); assertEquals( "Property beta not set correctly", "BETA BODY", bean.getBeta()); assertEquals( "Property gamma not set correctly", "GAMMA BODY", bean.getGamma()); assertEquals( "Property delta not set correctly", "DELTA BODY", bean.getDeltaValue()); // check no bad rules object is left assertEquals( "Digester rules object not reset.", RulesBase.class, digester.getRules().getClass()); } /** * Test that: *

    *
  • you can have rules matching the same pattern as the * SetNestedPropertiesRule,
  • *
  • you can have rules matching child elements of the rule,
  • *
  • the Rules object is reset nicely.
  • *
*/ public void testMultiRuleMatch() throws SAXException, IOException { String testXml = "" + "" + "ROOT BODY" + "BETA BODY" + "GAMMA " + "" + "BODY" + "" + "" + ""; Reader reader = new StringReader(testXml); // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root/testbean", "org.apache.commons.digester.SimpleTestBean"); digester.addRule("root/testbean", new SetNestedPropertiesRule()); digester.addSetProperties("root/testbean"); digester.addSetProperty("root/testbean/gamma/prop", "name", "value"); SimpleTestBean bean = (SimpleTestBean) digester.parse(reader); assertNotNull("No object created", bean); // check properties are set correctly assertEquals( "Property alpha not set correctly", "alpha-attr", bean.getAlpha()); assertEquals( "Property beta not set correctly", "BETA BODY", bean.getBeta()); assertEquals( "Property gamma not set correctly", "GAMMA BODY", bean.getGamma()); assertEquals( "Property delta not set correctly", "delta-prop", bean.getDeltaValue()); // check no bad rules object is left assertEquals( "Digester rules object not reset.", RulesBase.class, digester.getRules().getClass()); } /** * Test that unknown child elements trigger an exception. */ public void testUnknownChildrenCausesException() throws SAXException, IOException { String testXml = "" + "" + "" + "BETA BODY" + "GAMMA" + "" + ""; Reader reader = new StringReader(testXml); // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); Rule rule = new SetNestedPropertiesRule(); digester.addRule("root", rule); try { SimpleTestBean bean = (SimpleTestBean) digester.parse(reader); fail("Expected to generate an exception."); assertNotNull(bean); // just to prevent compiler warning on unused var } catch(SAXException e) { Exception nested = e.getException(); if ((nested==null) || !(nested instanceof NoSuchMethodException)) { // nope, not the sort of exception we expected throw e; } } } /** * Test that unknown child elements are allowed if the appropriate * flag is set. */ public void testUnknownChildrenExceptionOverride() throws SAXException, IOException { String testXml = "" + "" + "" + "BETA BODY" + "GAMMA" + "" + ""; Reader reader = new StringReader(testXml); // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); SetNestedPropertiesRule rule = new SetNestedPropertiesRule(); rule.setAllowUnknownChildElements(true); digester.addRule("root", rule); SimpleTestBean bean = (SimpleTestBean) digester.parse(reader); assertNotNull(bean); } /** * Test that the rule works in a sane manner when the associated pattern * is a wildcard such that the rule matches one of its own child elements. *

* See bugzilla entry 31393. */ public void testRecursiveNestedProperties() throws SAXException, IOException { String testXml = "" + "" + "BETA BODY" + "" + "BETA BODY" + "" + ""; Reader reader = new StringReader(testXml); // going to be setting properties on a SimpleTestBean digester.addObjectCreate("*/testbean", "org.apache.commons.digester.SimpleTestBean"); SetNestedPropertiesRule rule = new SetNestedPropertiesRule(); rule.setAllowUnknownChildElements(true); digester.addRule("*/testbean", rule); SimpleTestBean bean = (SimpleTestBean) digester.parse(reader); assertNotNull(bean); } /** * Get input stream from {@link #TEST_XML}. */ private Reader xmlTestReader() throws IOException { return new StringReader(TEST_XML); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/SimpleTestBean.java0000644000175000017500000000425011226450007032062 0ustar twernertwerner/* $Id: SimpleTestBean.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** *

As it's name suggests just a simple bean used for testing. */ public class SimpleTestBean { private String alpha; private String beta; private String gamma; private String delta; public String getAlpha() { return alpha; } public void setAlpha(String alpha) { this.alpha = alpha; } public String getBeta() { return beta; } public void setBeta(String beta) { this.beta = beta; } public String getGamma() { return gamma; } public void setGamma(String gamma) { this.gamma = gamma; } public String getDeltaValue() { // Retrieves "write only" value return delta; } public void setDelta(String delta) { // "delta" is a write-only property this.delta = delta; } public void setAlphaBeta(String alpha, String beta) { setAlpha(alpha); setBeta(beta); } public String toString() { StringBuffer sb = new StringBuffer("[SimpleTestBean]"); sb.append(" alpha="); sb.append(alpha); sb.append(" beta="); sb.append(beta); sb.append(" gamma="); sb.append(gamma); sb.append(" delta="); sb.append(delta); return sb.toString(); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/RegexRulesTestCase.java0000644000175000017500000002363511226450007032734 0ustar twernertwerner/* $Id: RegexRulesTestCase.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.List; import junit.framework.TestCase; /** * Test case for RegexRules * * @author Robert Burrell Donkin * @version $Revision: 471661 $ $Date: 2006-11-06 03:09:25 -0500 (Mon, 06 Nov 2006) $ */ public class RegexRulesTestCase extends TestCase { /** Base constructor */ public RegexRulesTestCase(String name) { super(name); } /** Test regex that matches everything */ public void testMatchAll() { // set up which should match every rule RegexRules rules = new RegexRules( new RegexMatcher() { public boolean match(String pathPattern, String rulePattern) { return true; } }); rules.add("/a/b/b", new TestRule("alpha")); rules.add("/a/d", new TestRule("beta")); rules.add("/b", new TestRule("gamma")); // now test a few patterns // check that all are return in the order which they were added List matches = rules.match("", "x/g/e"); assertEquals("Wrong number of rules returned (1)", 3, matches.size()); assertEquals("Rule Out Of Order (1)", "alpha", ((TestRule) matches.get(0)).getIdentifier()); assertEquals("Rule Out Of Order (2)", "beta", ((TestRule) matches.get(1)).getIdentifier()); assertEquals("Rule Out Of Order (3)", "gamma", ((TestRule) matches.get(2)).getIdentifier()); matches = rules.match("", "/a"); assertEquals("Wrong number of rules returned (2)", 3, matches.size()); assertEquals("Rule Out Of Order (4)", "alpha", ((TestRule) matches.get(0)).getIdentifier()); assertEquals("Rule Out Of Order (5)", "beta", ((TestRule) matches.get(1)).getIdentifier()); assertEquals("Rule Out Of Order (6)", "gamma", ((TestRule) matches.get(2)).getIdentifier()); } /** Test regex matcher that matches nothing */ public void testMatchNothing() { // set up which should match every rule RegexRules rules = new RegexRules( new RegexMatcher() { public boolean match(String pathPattern, String rulePattern) { return false; } }); rules.add("/b/c/f", new TestRule("alpha")); rules.add("/c/f", new TestRule("beta")); rules.add("/b", new TestRule("gamma")); // now test a few patterns // check that all are return in the order which they were added List matches = rules.match("", "/b/c"); assertEquals("Wrong number of rules returned (1)", 0, matches.size()); matches = rules.match("", "/b/c/f"); assertEquals("Wrong number of rules returned (2)", 0, matches.size()); } /** Test a mixed regex - in other words, one that sometimes returns true and sometimes false */ public void testMatchMixed() { // set up which should match every rule RegexRules rules = new RegexRules( new RegexMatcher() { public boolean match(String pathPattern, String rulePattern) { return (rulePattern.equals("/match/me")); } }); rules.add("/match", new TestRule("alpha")); rules.add("/match/me", new TestRule("beta")); rules.add("/match", new TestRule("gamma")); // now test a few patterns // check that all are return in the order which they were added List matches = rules.match("", "/match"); assertEquals("Wrong number of rules returned (1)", 1, matches.size()); assertEquals("Wrong Rule (1)", "beta", ((TestRule) matches.get(0)).getIdentifier()); matches = rules.match("", "/a/match"); assertEquals("Wrong Rule (2)", "beta", ((TestRule) matches.get(0)).getIdentifier()); } /** Test rules and clear methods */ public void testClear() { // set up which should match every rule RegexRules rules = new RegexRules( new RegexMatcher() { public boolean match(String pathPattern, String rulePattern) { return true; } }); rules.add("/abba", new TestRule("alpha")); rules.add("/ad/ma", new TestRule("beta")); rules.add("/gamma", new TestRule("gamma")); // check that rules returns all rules in the order which they were added List matches = rules.rules(); assertEquals("Wrong number of rules returned (1)", 3, matches.size()); assertEquals("Rule Out Of Order (1)", "alpha", ((TestRule) matches.get(0)).getIdentifier()); assertEquals("Rule Out Of Order (2)", "beta", ((TestRule) matches.get(1)).getIdentifier()); assertEquals("Rule Out Of Order (3)", "gamma", ((TestRule) matches.get(2)).getIdentifier()); matches = rules.match("", "/eggs"); assertEquals("Wrong number of rules returned (2)", 3, matches.size()); assertEquals("Rule Out Of Order (4)", "alpha", ((TestRule) matches.get(0)).getIdentifier()); assertEquals("Rule Out Of Order (5)", "beta", ((TestRule) matches.get(1)).getIdentifier()); assertEquals("Rule Out Of Order (6)", "gamma", ((TestRule) matches.get(2)).getIdentifier()); rules.clear(); matches = rules.rules(); assertEquals("Wrong number of rules returned (3)", 0, matches.size()); matches = rules.match("", "/eggs"); assertEquals("Wrong number of rules returned (4)", 0, matches.size()); } public void testSimpleRegexMatch() { SimpleRegexMatcher matcher = new SimpleRegexMatcher(); // SimpleLog log = new SimpleLog("{testSimpleRegexMatch:SimpleRegexMatcher]"); // log.setLevel(SimpleLog.LOG_LEVEL_TRACE); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '/alpha/beta/gamma' ", true, matcher.match("/alpha/beta/gamma", "/alpha/beta/gamma")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '/alpha/beta/gamma/epsilon' ", false, matcher.match("/alpha/beta/gamma", "/alpha/beta/gamma/epsilon")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '/alpha/*' ", true, matcher.match("/alpha/beta/gamma", "/alpha/*")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '/alpha/*/gamma' ", true, matcher.match("/alpha/beta/gamma", "/alpha/*/gamma")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '/alpha/*me' ", false, matcher.match("/alpha/beta/gamma", "/alpha/*me")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '*/beta/gamma' ", true, matcher.match("/alpha/beta/gamma", "*/beta/gamma")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '*/alpha/beta/gamma' ", true, matcher.match("/alpha/beta/gamma", "*/alpha/beta/gamma")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '*/bet/gamma' ", false, matcher.match("/alpha/beta/gamma", "*/bet/gamma")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to 'alph?/beta/gamma' ", true, matcher.match("/alpha/beta/gamma", "/alph?/beta/gamma")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '/?lpha/beta/gamma' ", true, matcher.match("/alpha/beta/gamma", "/?lpha/beta/gamma")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '/alpha/?beta/gamma' ", false, matcher.match("/alpha/beta/gamma", "/alpha/?beta/gamma")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '/alpha/?eta/*' ", true, matcher.match("/alpha/beta/gamma", "/alpha/?eta/*")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '/alpha/?eta/*e' ", false, matcher.match("/alpha/beta/gamma", "/alpha/?eta/*e")); assertEquals( "Simple Regex Match '/alpha/beta/gamma' to '*/?et?/?amma' ", true, matcher.match("/alpha/beta/gamma", "*/?et?/?amma")); assertEquals( "Simple Regex Match '/alpha/beta/gamma/beta/epsilon/beta/gamma/epsilon' to " + " '*/beta/gamma/?p*n' ", true, matcher.match("/alpha/beta/gamma/beta/epsilon/beta/gamma/epsilon", "*/beta/gamma/?p*n")); assertEquals( "Simple Regex Match '/alpha/beta/gamma/beta/epsilon/beta/gamma/epsilon' to " + " '*/beta/gamma/?p*no' ", false, matcher.match("/alpha/beta/gamma", "*/beta/gamma/?p*no")); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test7.xml0000644000175000017500000000211711226450007030070 0ustar twernertwerner ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/OtherTestObjectCreationFactory.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/OtherTestObjectCreationFact0000644000175000017500000000213111226450007033612 0ustar twernertwerner/* $Id: OtherTestObjectCreationFactory.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * Another Object creation factory used for testing. * * @author Robert Burrell Donkin */ public class OtherTestObjectCreationFactory extends TestObjectCreationFactory {} libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/0000755000175000017500000000000011226450007030020 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test6.xml0000644000175000017500000000322311226450007031607 0ustar twernertwerner ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TextLabel2RuleInfo.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TextLabel2RuleInfo.0000644000175000017500000000273511226450007033442 0ustar twernertwerner/* $Id: TextLabel2RuleInfo.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import org.apache.commons.digester.Digester; public class TextLabel2RuleInfo { // define default rules public static void addRules(Digester digester, String pattern) { digester.addCallMethod(pattern+"/id", "setId", 0); digester.addCallMethod(pattern+"/label", "setLabel", 0); } // define different rules on this class public static void addAltRules(Digester digester, String pattern) { digester.addCallMethod(pattern+"/alt-id", "setId", 0); digester.addCallMethod(pattern+"/alt-label", "setLabel", 0); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TextLabel.java0000644000175000017500000000246011226450007032551 0ustar twernertwerner/* $Id: TextLabel.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; public class TextLabel implements Widget { private String id = "anonymous"; private String label = "nolabel"; public TextLabel() {} public String getId() { return id; } public void setId(String id) { this.id = id; } public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/Widget.java0000644000175000017500000000165611226450007032116 0ustar twernertwerner/* $Id: Widget.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; public interface Widget { } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/ContainerCustomRules.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/ContainerCustomRule0000644000175000017500000000317611226450007033717 0ustar twernertwerner/* $Id: ContainerCustomRules.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import org.apache.commons.digester.Digester; public class ContainerCustomRules { public static void addRules(Digester digester, String pattern) { // A Container object can have subtags called "widget" which // define any object of type Widget. Because a Container is // itself a widget, this allows us to build trees of objects. PluginCreateRule pcr = new PluginCreateRule(Widget.class); digester.addRule(pattern+"/widget", pcr); digester.addSetNext(pattern+"/widget", "addChild"); // allow users to declare plugins under a container as well PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule(pattern+"/plugin", pdr); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/DumperRule.java0000644000175000017500000000376111226450007032756 0ustar twernertwerner/* $Id: DumperRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import org.xml.sax.Attributes; import org.apache.commons.digester.Rule; /** * Demonstrates the behaviour of the Delegate interface. */ public class DumperRule extends Rule { public void begin(String namespace, String name, Attributes attributes) throws Exception { System.out.print("<"); System.out.print(name); int nAttributes = attributes.getLength(); for(int i=0; i"); } public void body(String namespace, String name, String text) throws Exception { System.out.print(text); } public void end(String namespace, String name) throws Exception { System.out.print(""); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TextLabel2.java0000644000175000017500000000246411226450007032637 0ustar twernertwerner/* $Id: TextLabel2.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; public class TextLabel2 implements Widget { private String id = "anonymous"; private String label = "nolabel"; public TextLabel2() {} public String getId() { return id; } public void setId(String id) { this.id = id; } public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test4a.xml0000644000175000017500000000224511226450007031751 0ustar twernertwerner 1 2 libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test2.xml0000644000175000017500000000174711226450007031614 0ustar twernertwerner ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestXmlRuleInfo.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestXmlRuleInfo.jav0000644000175000017500000001364611226450007033600 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.io.StringReader; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; /** * Test cases for the declaration of custom rules for a plugin using * xmlrules format files. */ public class TestXmlRuleInfo extends TestCase { /** Standard constructor */ public TestXmlRuleInfo(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestXmlRuleInfo.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testXmlRuleInfoExplicitFile() throws Exception { // * tests that custom rules can be declared on a // separate class by explicitly declaring a file containing // the rules, using a relative or absolute path name. StringBuffer input = new StringBuffer(); input.append(""); input.append(" "); input.append(" "); input.append(""); Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule pcr = new PluginCreateRule(TestObject.class); digester.addRule("root/object", pcr); try { digester.parse(new StringReader(input.toString())); } catch(Exception e) { throw e; } Object root = digester.getRoot(); assertEquals(TestObject.class, root.getClass()); TestObject testObject = (TestObject) root; assertEquals("xmlrules1", testObject.getValue()); } public void testXmlRuleInfoExplicitResource() throws Exception { // * tests that custom rules can be declared on a // separate class by explicitly declaring the rule class. // and explicitly declaring a file which is somewhere in the // classpath. StringBuffer input = new StringBuffer(); input.append(""); input.append(" "); input.append(" "); input.append(""); Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule pcr = new PluginCreateRule(TestObject.class); digester.addRule("root/object", pcr); try { digester.parse(new StringReader(input.toString())); } catch(Exception e) { throw e; } Object root = digester.getRoot(); assertEquals(TestObject.class, root.getClass()); TestObject testObject = (TestObject) root; assertEquals("xmlrules2", testObject.getValue()); } public void testXmlRuleImplicitResource() throws Exception { // * tests that custom rules can be declared on a // separate class by explicitly declaring the rule class. // and explicitly declaring a file which is somewhere in the // classpath. StringBuffer input = new StringBuffer(); input.append(""); input.append(" "); input.append(" "); input.append(""); Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule pcr = new PluginCreateRule(TestObject.class); digester.addRule("root/object", pcr); try { digester.parse(new StringReader(input.toString())); } catch(Exception e) { throw e; } Object root = digester.getRoot(); assertEquals(TestObject.class, root.getClass()); TestObject testObject = (TestObject) root; assertEquals("xmlrules-ruleinfo", testObject.getValue()); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/xmlrules2.xml0000644000175000017500000000224711226450007032504 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/Container.java0000644000175000017500000000232611226450007032610 0ustar twernertwerner/* $Id: Container.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import java.util.LinkedList; public class Container implements Widget { private LinkedList children = new LinkedList(); public Container() {} public void addChild(Widget child) { children.add(child); } public List getChildren() { return children; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test5a.xml0000644000175000017500000000210011226450007031740 0ustar twernertwerner alt label libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test7.xml0000644000175000017500000000415211226450007031612 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestRecursion.java0000644000175000017500000000617011226450007033500 0ustar twernertwerner/* $Id: TestRecursion.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import java.util.Iterator; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; /** * Test cases for plugins with custom rules which include PluginCreateRule * instances, allowing recursive datastructures to be processed. */ public class TestRecursion extends TestCase { /** Standard constructor */ public TestRecursion(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestRecursion.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testRecursiveRules() throws Exception { // * tests that a rule can declare custom PluginCreateRules // that allow it to plug in instances of itself below // itself. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("*/plugin", pdr); PluginCreateRule pcr = new PluginCreateRule(Widget.class); digester.addRule("root/widget", pcr); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test6.xml")); } catch(Exception e) { throw e; } int nDescendants = countWidgets(root); assertEquals(10, nDescendants); } private int countWidgets(Container c) { List l = c.getChildren(); int sum = 0; for(Iterator i = l.iterator(); i.hasNext(); ) { Widget w = (Widget) i.next(); ++sum; if (w instanceof Container) { sum += countWidgets((Container) w); } } return sum; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test1.xml0000644000175000017500000000171311226450007031604 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestDelegate.java0000644000175000017500000000475711226450007033252 0ustar twernertwerner/* $Id: TestDelegate.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; /** * Test cases for Delegate behaviour. */ public class TestDelegate extends TestCase { /** Standard constructor */ public TestDelegate(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestDelegate.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testDummy() { // it is an error if a TestSuite doesn't have at least one test, // so here is one... } public void ignoretestDelegate() throws Exception { // this method tests the Delegate functionality by capturing all // data below the specified pattern, and printing it to stdout. // I can't for the moment think how to turn this into a unit test, // so this test is disabled. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); DumperRule dr = new DumperRule(); digester.addRule("root", dr); try { digester.parse( TestAll.getInputStream(this, "test1.xml")); } catch(Exception e) { throw e; } } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestRuleInfo.java0000644000175000017500000001354211226450007033253 0ustar twernertwerner/* $Id: TestRuleInfo.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; /** * Test cases for the declaration of custom rules for a plugin using * a separate class to define the rules. */ public class TestRuleInfo extends TestCase { /** Standard constructor */ public TestRuleInfo(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestRuleInfo.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testRuleInfoExplicitClass() throws Exception { // * tests that custom rules can be declared on a // separate class by explicitly declaring the rule class. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule pcr = new PluginCreateRule(Widget.class); digester.addRule("root/widget", pcr); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test5a.xml")); } catch(Exception e) { throw e; } Object child; List children = root.getChildren(); assertTrue(children != null); assertEquals(1, children.size()); child = children.get(0); assertTrue(child != null); assertEquals(TextLabel2.class, child.getClass()); TextLabel2 label = (TextLabel2) child; // id should not be mapped, label should assertEquals("anonymous", label.getId()); assertEquals("std label", label.getLabel()); } public void testRuleInfoExplicitMethod() throws Exception { // * tests that custom rules can be declared on a // separate class by explicitly declaring the rule class. // and explicitly declaring the rule method name. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule pcr = new PluginCreateRule(Widget.class); digester.addRule("root/widget", pcr); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test5b.xml")); } catch(Exception e) { throw e; } Object child; List children = root.getChildren(); assertTrue(children != null); assertEquals(1, children.size()); child = children.get(0); assertTrue(child != null); assertEquals(TextLabel2.class, child.getClass()); TextLabel2 label = (TextLabel2) child; // id should not be mapped, altlabel should assertEquals("anonymous", label.getId()); assertEquals("alt label", label.getLabel()); } public void testRuleInfoAutoDetect() throws Exception { // * tests that custom rules can be declared on a // separate class with name {plugin-class}RuleInfo, // and they are automatically detected and loaded. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule pcr = new PluginCreateRule(Widget.class); digester.addRule("root/widget", pcr); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test5c.xml")); } catch(Exception e) { throw e; } Object child; List children = root.getChildren(); assertTrue(children != null); assertEquals(1, children.size()); child = children.get(0); assertTrue(child != null); assertEquals(TextLabel2.class, child.getClass()); TextLabel2 label = (TextLabel2) child; // id should not be mapped, label should assertEquals("anonymous", label.getId()); assertEquals("std label", label.getLabel()); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestDeclaration.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestDeclaration.jav0000644000175000017500000000604111226450007033610 0ustar twernertwerner/* $Id: TestDeclaration.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; /** * Test cases for basic PluginDeclarationRule behaviour. */ public class TestDeclaration extends TestCase { /** Standard constructor */ public TestDeclaration(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestDeclaration.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testPredeclaration() throws Exception { // * tests that rules can be declared via a PluginDeclarationRule Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule pcr = new PluginCreateRule(Widget.class); digester.addRule("root/widget", pcr); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test3.xml")); } catch(Exception e) { throw e; } Object child; List children = root.getChildren(); assertTrue(children != null); assertEquals(2, children.size()); child = children.get(0); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); assertEquals("label1", ((TextLabel)child).getLabel()); child = children.get(1); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); assertEquals("label2", ((TextLabel)child).getLabel()); } } ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestConfigurablePluginAttributes.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestConfigurablePlu0000644000175000017500000002155711226450007033676 0ustar twernertwerner/* $Id: TestConfigurablePluginAttributes.java 561583 2007-07-31 22:48:00Z dennisl $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import java.util.LinkedList; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; /** * Test cases for functionality which sets what xml attributes specify * the plugin class or plugin declaration id. */ public class TestConfigurablePluginAttributes extends TestCase { /** Standard constructor */ public TestConfigurablePluginAttributes(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestConfigurablePluginAttributes.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testDefaultBehaviour() throws Exception { // tests that by default the attributes used are // named "plugin-class" and "plugin-id" Digester digester = new Digester(); digester.setNamespaceAware(true); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule widgetPluginRule = new PluginCreateRule(Widget.class); digester.addRule("root/widget", widgetPluginRule); digester.addSetNext("root/widget", "addWidget"); PluginCreateRule gadgetPluginRule = new PluginCreateRule(Widget.class); digester.addRule("root/gadget", gadgetPluginRule); digester.addSetNext("root/gadget", "addGadget"); MultiContainer root = new MultiContainer(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test7.xml")); } catch(Exception e) { throw e; } List widgets = root.getWidgets(); assertTrue(widgets != null); assertEquals(4, widgets.size()); assertEquals(TextLabel.class, widgets.get(0).getClass()); assertEquals(TextLabel.class, widgets.get(1).getClass()); assertEquals(TextLabel.class, widgets.get(2).getClass()); assertEquals(TextLabel.class, widgets.get(3).getClass()); List gadgets = root.getGadgets(); assertTrue(gadgets != null); assertEquals(4, gadgets.size()); assertEquals(TextLabel.class, gadgets.get(0).getClass()); assertEquals(TextLabel.class, gadgets.get(1).getClass()); assertEquals(TextLabel.class, gadgets.get(2).getClass()); assertEquals(TextLabel.class, gadgets.get(3).getClass()); } public void testGlobalOverride() throws Exception { // Tests that using setDefaultPluginXXXX overrides behaviour for all // PluginCreateRule instances. Also tests specifying attributes // with "null" for namespace (ie attributes not in any namespace). // // note that in order not to screw up all other tests, we need // to reset the global names after we finish here! Digester digester = new Digester(); digester.setNamespaceAware(true); PluginRules rc = new PluginRules(); digester.setRules(rc); rc.setPluginIdAttribute(null, "id"); rc.setPluginClassAttribute(null, "class"); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule widgetPluginRule = new PluginCreateRule(Widget.class); digester.addRule("root/widget", widgetPluginRule); digester.addSetNext("root/widget", "addWidget"); PluginCreateRule gadgetPluginRule = new PluginCreateRule(Widget.class); digester.addRule("root/gadget", gadgetPluginRule); digester.addSetNext("root/gadget", "addGadget"); MultiContainer root = new MultiContainer(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test7.xml")); } catch(Exception e) { throw e; } List widgets = root.getWidgets(); assertTrue(widgets != null); assertEquals(4, widgets.size()); assertEquals(Slider.class, widgets.get(0).getClass()); assertEquals(Slider.class, widgets.get(1).getClass()); assertEquals(Slider.class, widgets.get(2).getClass()); assertEquals(Slider.class, widgets.get(3).getClass()); List gadgets = root.getGadgets(); assertTrue(gadgets != null); assertEquals(4, gadgets.size()); assertEquals(Slider.class, gadgets.get(0).getClass()); assertEquals(Slider.class, gadgets.get(1).getClass()); assertEquals(Slider.class, gadgets.get(2).getClass()); assertEquals(Slider.class, gadgets.get(3).getClass()); } public void testInstanceOverride() throws Exception { // Tests that using setPluginXXXX overrides behaviour for only // that particular PluginCreateRule instance. Also tests that // attributes can be in namespaces. Digester digester = new Digester(); digester.setNamespaceAware(true); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); // for plugins at pattern "root/widget", use xml attributes "id" and // "class" in the custom namespace as the values for plugin id and // class, not the default (and non-namespaced) values of // "plugin-id" and "plugin-class". PluginCreateRule widgetPluginRule = new PluginCreateRule(Widget.class); widgetPluginRule.setPluginIdAttribute( "http://commons.apache.org/digester/plugins", "id"); widgetPluginRule.setPluginClassAttribute( "http://commons.apache.org/digester/plugins", "class"); digester.addRule("root/widget", widgetPluginRule); digester.addSetNext("root/widget", "addWidget"); PluginCreateRule gadgetPluginRule = new PluginCreateRule(Widget.class); digester.addRule("root/gadget", gadgetPluginRule); digester.addSetNext("root/gadget", "addGadget"); MultiContainer root = new MultiContainer(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test7.xml")); } catch(Exception e) { throw e; } List widgets = root.getWidgets(); assertTrue(widgets != null); assertEquals(4, widgets.size()); assertEquals(TextLabel2.class, widgets.get(0).getClass()); assertEquals(TextLabel2.class, widgets.get(1).getClass()); assertEquals(TextLabel2.class, widgets.get(2).getClass()); assertEquals(TextLabel2.class, widgets.get(3).getClass()); List gadgets = root.getGadgets(); assertTrue(gadgets != null); assertEquals(4, gadgets.size()); assertEquals(TextLabel.class, gadgets.get(0).getClass()); assertEquals(TextLabel.class, gadgets.get(1).getClass()); assertEquals(TextLabel.class, gadgets.get(2).getClass()); assertEquals(TextLabel.class, gadgets.get(3).getClass()); } // inner classes used for testing public static class MultiContainer { private LinkedList widgets = new LinkedList(); private LinkedList gadgets = new LinkedList(); public MultiContainer() {} public void addWidget(Widget child) { widgets.add(child); } public List getWidgets() { return widgets; } public void addGadget(Widget child) { gadgets.add(child); } public List getGadgets() { return gadgets; } } } ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestLocalRules.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestLocalRules.java0000644000175000017500000001423411226450007033574 0ustar twernertwerner/* $Id: TestLocalRules.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; /** * Test cases for defining custom rules on the plugin class itself. */ public class TestLocalRules extends TestCase { /** Standard constructor */ public TestLocalRules(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestLocalRules.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testLocalRules() throws Exception { // * tests that the plugin class can define an addRules method, // which gets detected and executed. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule pcr2 = new PluginCreateRule(Widget.class); digester.addRule("root/widget", pcr2); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test4a.xml")); } catch(Exception e) { throw e; } Object child; List children = root.getChildren(); assertTrue(children != null); assertEquals(3, children.size()); // min/max rules should be in effect // setproperties should be in effect child = children.get(0); assertTrue(child != null); assertEquals(Slider.class, child.getClass()); Slider slider1 = (Slider) child; assertEquals("slider1", slider1.getLabel()); assertEquals(1, slider1.getMin()); assertEquals(2, slider1.getMax()); // range rules should not be in effect // setproperties should be in effect child = children.get(1); assertTrue(child != null); assertEquals(Slider.class, child.getClass()); Slider slider2 = (Slider) child; assertEquals("slider2", slider2.getLabel()); assertEquals(0, slider2.getMin()); assertEquals(0, slider2.getMax()); // setproperties should be working on text label child = children.get(2); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); assertEquals("text1", ((TextLabel)child).getLabel()); } public void testNonStandardLocalRules() throws Exception { // * tests that using PluginDeclarationRule to declare an alternate // rule method name invokes that alternate method instead (the // input xml specifies that a method other than addRules is to // be used) // * tests that if a rule method is defined, then a SetProperties // rule is not automatically added. // * tests that a SetProperties rule applying to one class doesn't // apply to different plugin classes mounted at the same rule. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginDeclarationRule pdr = new PluginDeclarationRule(); digester.addRule("root/plugin", pdr); PluginCreateRule pcr2 = new PluginCreateRule(Widget.class); digester.addRule("root/widget", pcr2); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test4b.xml")); } catch(Exception e) { throw e; } Object child; List children = root.getChildren(); assertTrue(children != null); assertEquals(3, children.size()); // min/max rules should not be in effect // setproperties should not be in effect child = children.get(0); assertTrue(child != null); assertEquals(Slider.class, child.getClass()); Slider slider1 = (Slider) child; assertEquals("nolabel", slider1.getLabel()); assertEquals(0, slider1.getMin()); assertEquals(0, slider1.getMax()); // range rules should be in effect // setproperties should not be in effect child = children.get(1); assertTrue(child != null); assertEquals(Slider.class, child.getClass()); Slider slider2 = (Slider) child; assertEquals("nolabel", slider2.getLabel()); assertEquals(10, slider2.getMin()); assertEquals(20, slider2.getMax()); // setproperties should be working on text label child = children.get(2); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); assertEquals("text1", ((TextLabel)child).getLabel()); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestObject.java0000644000175000017500000000215611226450007032735 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; /** * Test harness object for holding results of digestion. */ public class TestObject { private String value; public TestObject() { } public void setValue(String val) { value = val; } public String getValue() { return value; } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test4b.xml0000644000175000017500000000231711226450007031752 0ustar twernertwerner 1 2 libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/xmlrules1.xml0000644000175000017500000000224711226450007032503 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test5b.xml0000644000175000017500000000213211226450007031746 0ustar twernertwerner alt label libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test5c.xml0000644000175000017500000000167711226450007031764 0ustar twernertwerner alt label libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestAll.java0000644000175000017500000000606711226450007032244 0ustar twernertwerner/* $Id: TestAll.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import java.io.InputStream; import java.io.IOException; /** * Entry point for all plugins package tests. * * @author Simon Kitching */ public class TestAll extends TestCase { public TestAll(String testName) { super(testName); } // MORE TESTS REQUIRED:: // test that problem is detected if rules object not PluginRules // test that problem is detected if wildcard pattern used // test that problem is detected if rule mounted with multiple patterns // test that problem is detected if specified class doesn't descend // from required base class. // test scenario where bodytext of actual plugin element is accessed // test rules in resource // test rules in explicit file // test autosetdefaults on/off public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(TestXmlRuleInfo.suite()); suite.addTest(TestInline.suite()); suite.addTest(TestDelegate.suite()); suite.addTest(TestDeclaration.suite()); suite.addTest(TestDefaultPlugin.suite()); suite.addTest(TestLocalRules.suite()); suite.addTest(TestRuleInfo.suite()); suite.addTest(TestRecursion.suite()); suite.addTest(TestConfigurablePluginAttributes.suite()); return suite; } public static void main(String args[]) { String[] testCaseName = { TestAll.class.getName() }; junit.textui.TestRunner.main(testCaseName); } // ------------------------------------------------ Utility Support Methods /** * Return an appropriate InputStream for the specified test file (which * must be inside our current package. * * @param caller is always "this" for the calling object. * @param name is the test file we want * * @exception IOException if an input/output error occurs */ public static InputStream getInputStream(Object caller, String name) throws IOException { return (caller.getClass().getResourceAsStream ("/org/apache/commons/digester/plugins/" + name)); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/test3.xml0000644000175000017500000000174311226450007031611 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/Slider.java0000644000175000017500000000456611226450007032120 0ustar twernertwerner/* $Id: Slider.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import org.apache.commons.digester.Digester; public class Slider implements Widget { private String label = "nolabel"; private int min = 0; private int max = 0; // define rules on this class public static void addRules(Digester digester, String pattern) { digester.addSetProperties(pattern); Class[] paramtypes = {Integer.class}; digester.addCallMethod(pattern+"/min", "setMin", 0, paramtypes); digester.addCallMethod(pattern+"/max", "setMax", 0, paramtypes); } // define different rules on this class public static void addRangeRules(Digester digester, String pattern) { // note: deliberately no addSetProperties rule Class[] paramtypes = {Integer.class, Integer.class}; digester.addCallMethod(pattern+"/range", "setRange", 2, paramtypes); digester.addCallParam(pattern+"/range", 0, "min"); digester.addCallParam(pattern+"/range", 1, "max"); } public Slider() {} public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } public void setMin(int min) { this.min = min; } public int getMin() { return min; } public void setMax(int max) { this.max = max; } public int getMax() { return max; } public void setRange(int min, int max) { this.min = min; this.max = max; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestDefaultPlugin.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestDefaultPlugin.j0000644000175000017500000001346711226450007033611 0ustar twernertwerner/* $Id: TestDefaultPlugin.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; import org.apache.commons.logging.Log; import org.apache.commons.logging.impl.NoOpLog; /** * Test cases for the use of default plugin classes. */ import org.xml.sax.SAXParseException; public class TestDefaultPlugin extends TestCase { /** Standard constructor */ public TestDefaultPlugin(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestDefaultPlugin.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testDefaultPlugins1() throws Exception { // * tests that when a PluginCreateRule is defined with a default // class, that the default class is instantiated when no class // or id is specified in the xml file. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginCreateRule pcr = new PluginCreateRule(Widget.class, TextLabel.class); digester.addRule("root/widget", pcr); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test2.xml")); } catch(Exception e) { throw e; } Object child; List children = root.getChildren(); assertTrue(children != null); assertEquals(3, children.size()); child = children.get(0); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); TextLabel label1 = (TextLabel) child; assertEquals("label1", label1.getLabel()); child = children.get(1); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); TextLabel label2 = (TextLabel) child; assertEquals("label2", label2.getLabel()); child = children.get(2); assertTrue(child != null); assertEquals(Slider.class, child.getClass()); Slider slider1 = (Slider) child; assertEquals("slider1", slider1.getLabel()); } public void testDefaultPlugins2() throws Exception { // * tests that when there is no default plugin, it is an error // not to have one of plugin-class or plugin-id specified Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginCreateRule pcr = new PluginCreateRule(Widget.class); digester.addRule("root/widget", pcr); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); Exception exception = null; Log oldLog = digester.getLogger(); try { digester.setLogger(new NoOpLog()); digester.parse( TestAll.getInputStream(this, "test2.xml")); } catch(Exception e) { exception = e; } finally { digester.setLogger(oldLog); } assertTrue(exception != null); assertEquals(SAXParseException.class, exception.getClass()); assertEquals( PluginInvalidInputException.class, ((SAXParseException)exception).getException().getClass()); } public void testDefaultPlugins3() throws Exception { // * tests that the default plugin must implement or extend the // plugin base class. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginCreateRule pcr = new PluginCreateRule(Widget.class, Object.class); digester.addRule("root/widget", pcr); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); Exception exception = null; Log oldLog = digester.getLogger(); try { digester.setLogger(new NoOpLog()); digester.parse( TestAll.getInputStream(this, "test2.xml")); } catch(Exception e) { exception = e; } finally { digester.setLogger(oldLog); } assertTrue(exception != null); assertEquals(SAXParseException.class, exception.getClass()); assertEquals( PluginConfigurationException.class, ((SAXParseException)exception).getException().getClass()); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestInline.java0000644000175000017500000001154011226450007032742 0ustar twernertwerner/* $Id: TestInline.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.digester.Digester; /** * Test cases for declaration of plugin classes "inline" (ie by specifying * plugin-class). */ public class TestInline extends TestCase { /** Standard constructor */ public TestInline(String name) { super(name); } /** Set up instance variables required by this test case. */ public void setUp() {} /** Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(TestInline.class)); } /** Tear down instance variables required by this test case.*/ public void tearDown() {} // --------------------------------------------------------------- Test cases public void testInlineDeclaration() throws Exception { // * tests that plugins can be specified by class, and that the // correct class gets loaded. // * tests that autosetproperties works // * tests that multiple different classes can be loaded via the // same plugin rule (ie at the same pattern). Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginCreateRule pcr = new PluginCreateRule(Widget.class); digester.addRule("root/widget", pcr); digester.addSetNext("root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test1.xml")); } catch(Exception e) { throw e; } Object child; List children = root.getChildren(); assertTrue(children != null); assertEquals(2, children.size()); child = children.get(0); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); TextLabel label1 = (TextLabel) child; assertEquals("anonymous", label1.getId()); assertEquals("1", label1.getLabel()); child = children.get(1); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); TextLabel label2 = (TextLabel) child; assertEquals("L1", label2.getId()); assertEquals("2", label2.getLabel()); } public void testLeadingSlash() throws Exception { // Tests that PluginRules handles patterns with a leading slash. // // This test doesn't really belong in this class. If a separate test // case class is created for PluginRules, then this method should be // moved there. Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); PluginCreateRule pcr = new PluginCreateRule(Widget.class); digester.addRule("/root/widget", pcr); digester.addSetNext("/root/widget", "addChild"); Container root = new Container(); digester.push(root); try { digester.parse( TestAll.getInputStream(this, "test1.xml")); } catch(Exception e) { throw e; } Object child; List children = root.getChildren(); assertTrue(children != null); assertEquals(2, children.size()); child = children.get(0); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); TextLabel label1 = (TextLabel) child; assertEquals("anonymous", label1.getId()); assertEquals("1", label1.getLabel()); child = children.get(1); assertTrue(child != null); assertEquals(TextLabel.class, child.getClass()); TextLabel label2 = (TextLabel) child; assertEquals("L1", label2.getId()); assertEquals("2", label2.getLabel()); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestObjectRuleInfo.xmllibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/plugins/TestObjectRuleInfo.0000644000175000017500000000225711226450007033541 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test6.xml0000644000175000017500000000177111226450007030074 0ustar twernertwerner Value 1 Value 2 Value 3 Value 4 ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/BeanPropertySetterRuleTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/BeanPropertySetterRuleTestC0000644000175000017500000002621311226450007033662 0ustar twernertwerner/* $Id: BeanPropertySetterRuleTestCase.java 472840 2006-11-09 10:18:34Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.SAXException; /** *

Test case for BeanPropertySetterRule. * This contains tests for the main applications of the rule * and two more general tests of digester functionality used by this rule. */ public class BeanPropertySetterRuleTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * Simple test xml document used in the tests. */ protected final static String TEST_XML = "" + "ROOT BODY" + "ALPHA BODY" + "BETA BODY" + "GAMMA BODY" + "DELTA BODY" + ""; /** * The digester instance we will be processing. */ protected Digester digester = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public BeanPropertySetterRuleTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(BeanPropertySetterRuleTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods /** * This is a general digester test but it fits into here pretty well. * This tests that the rule calling order is properly enforced. */ public void testDigesterRuleCallOrder() throws SAXException, IOException { List callOrder = new ArrayList(); // use the standard rules digester.setRules(new RulesBase()); // add first test rule TestRule firstRule = new TestRule("first"); firstRule.setOrder(callOrder); digester.addRule("root/alpha", firstRule); // add second test rule TestRule secondRule = new TestRule("second"); secondRule.setOrder(callOrder); digester.addRule("root/alpha", secondRule); // add third test rule TestRule thirdRule = new TestRule("third"); thirdRule.setOrder(callOrder); digester.addRule("root/alpha", thirdRule); digester.parse(xmlTestReader()); // we should have nine entries in our list of calls assertEquals( "Nine calls should have been made.", 9, callOrder.size()); // begin should be called in the order added assertEquals( "First rule begin not called first.", "first", ((TestRule) callOrder.get(0)).getIdentifier()); assertEquals( "Second rule begin not called second.", "second", ((TestRule) callOrder.get(1)).getIdentifier()); assertEquals( "Third rule begin not called third.", "third", ((TestRule) callOrder.get(2)).getIdentifier()); // body text should be called in the order added assertEquals( "First rule body text not called first.", "first", ((TestRule) callOrder.get(3)).getIdentifier()); assertEquals( "Second rule body text not called second.", "second", ((TestRule) callOrder.get(4)).getIdentifier()); assertEquals( "Third rule body text not called third.", "third", ((TestRule) callOrder.get(5)).getIdentifier()); // end should be called in reverse order assertEquals( "Third rule end not called first.", "third", ((TestRule) callOrder.get(6)).getIdentifier()); assertEquals( "Second rule end not called second.", "second", ((TestRule) callOrder.get(7)).getIdentifier()); assertEquals( "First rule end not called third.", "first", ((TestRule) callOrder.get(8)).getIdentifier()); } /** * This is a general digester test but it fits into here pretty well. * This tests that the body text stack is functioning correctly. */ public void testDigesterBodyTextStack() throws SAXException, IOException { // use the standard rules digester.setRules(new RulesBase()); // add test rule to catch body text TestRule rootRule = new TestRule("root"); digester.addRule("root", rootRule); // add test rule to catch body text TestRule alphaRule = new TestRule("root/alpha"); digester.addRule("root/alpha", alphaRule); // add test rule to catch body text TestRule betaRule = new TestRule("root/beta"); digester.addRule("root/beta", betaRule); // add test rule to catch body text TestRule gammaRule = new TestRule("root/gamma"); digester.addRule("root/gamma", gammaRule); digester.parse(xmlTestReader()); assertEquals( "Root body text not set correct.", "ROOT BODY", rootRule.getBodyText()); assertEquals( "Alpha body text not set correct.", "ALPHA BODY", alphaRule.getBodyText()); assertEquals( "Beta body text not set correct.", "BETA BODY", betaRule.getBodyText()); assertEquals( "Gamma body text not set correct.", "GAMMA BODY", gammaRule.getBodyText()); } /** * Test that you can successfully set a given property */ public void testSetGivenProperty() throws SAXException, IOException { // use the standard rules digester.setRules(new RulesBase()); // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); // we'll set property alpha with the body text of root digester.addRule("root", new BeanPropertySetterRule("alpha")); // we'll set property beta with the body text of child element alpha digester.addRule("root/alpha", new BeanPropertySetterRule("beta")); // we'll leave property gamma alone // we'll set property delta (a write-only property) also digester.addRule("root/delta", new BeanPropertySetterRule("delta")); SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader()); // check properties are set correctly assertEquals( "Property alpha not set correctly", "ROOT BODY", bean.getAlpha()); assertEquals( "Property beta not set correctly", "ALPHA BODY", bean.getBeta()); assertTrue( "Property gamma not set correctly", bean.getGamma() == null); assertEquals("Property delta not set correctly", "DELTA BODY", bean.getDeltaValue()); } /** * Test that trying to set an unknown property throws an exception. */ public void testSetUnknownProperty() { // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); // attempt to set an unknown property name digester.addRule("root/alpha", new BeanPropertySetterRule("unknown")); // Attempt to parse the input try { SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader()); fail("Should have thrown NoSuchMethodException"); assertNotNull(bean); // just to avoid compiler warning on unused variable } catch (Exception e) { if (e instanceof InvocationTargetException) { Throwable t = ((InvocationTargetException) e).getTargetException(); if (t instanceof NoSuchMethodException) { ; // Expected result } else { fail("Should have thrown NoSuchMethodException, threw " + t); } } } } /** * Test that you can successfully automatically set properties. */ public void testAutomaticallySetProperties() throws SAXException, IOException { // need the extended rules digester.setRules(new ExtendedBaseRules()); // going to be setting properties on a SimpleTestBean digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); // match all children of root with this rule digester.addRule("root/?", new BeanPropertySetterRule()); SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader()); // check properties are set correctly assertEquals( "Property alpha not set correctly", "ALPHA BODY", bean.getAlpha()); assertEquals( "Property beta not set correctly", "BETA BODY", bean.getBeta()); assertEquals( "Property gamma not set correctly", "GAMMA BODY", bean.getGamma()); } /** * Get input stream from {@link #TEST_XML}. */ private Reader xmlTestReader() throws IOException { return new StringReader(TEST_XML); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/AlphaBean.java0000644000175000017500000000323211226450007031015 0ustar twernertwerner/* $Id: AlphaBean.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; public class AlphaBean implements Nameable { private String name = "ALPHA"; private Nameable child; private Nameable parent; public AlphaBean() {} public AlphaBean(String name) { setName(name); } public String getName() { return name; } public void setName(String name) { this.name = name; } public void setParent(Nameable parent) { this.parent = parent; } public Nameable getParent() { return parent; } public void setChild(Nameable child) { this.child = child; } public Nameable getChild() { return child; } public String toString() { return "[AlphaBean] name=" + name + " child=" + child; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/SetPropertiesRuleTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/SetPropertiesRuleTestCase.j0000644000175000017500000001723711226450007033620 0ustar twernertwerner/* $Id: SetPropertiesRuleTestCase.java 472840 2006-11-09 10:18:34Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.SAXException; /** *

Test case for SetPropertiesRule.

*/ public class SetPropertiesRuleTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * Simple test xml document used in the tests. */ protected final static String TEST_XML_1 = ""; /** * Simple test xml document used in the tests. */ protected final static String TEST_XML_2 = ""; /** * Simple test xml document used in the tests. */ protected final static String TEST_XML_3 = ""; /** * The digester instance we will be processing. */ protected Digester digester = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public SetPropertiesRuleTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(SetPropertiesRuleTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods /** * Positive test for SetPropertiesRule. */ public void testPositive() throws Exception { // Set up the rules we need digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); digester.addSetProperties("root"); // Parse the input SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader(TEST_XML_1)); // Check that the properties were set correctly assertEquals("alpha property set", "ALPHA VALUE", bean.getAlpha()); assertEquals("beta property set", "BETA VALUE", bean.getBeta()); assertNull("gamma property not set", bean.getGamma()); assertEquals("delta property set", "DELTA VALUE", bean.getDeltaValue()); } /** * Positive test for SetPropertyRule ignoring missing properties. */ public void testIgnoreMissing() throws Exception { // Set up the rules we need digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); digester.addSetProperties("root"); // Parse the input SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader(TEST_XML_2)); // Check that the properties were set correctly assertNull("alpha property not set", bean.getAlpha()); assertEquals("beta property set", "BETA VALUE", bean.getBeta()); assertNull("gamma property not set", bean.getGamma()); assertEquals("delta property set", "DELTA VALUE", bean.getDeltaValue()); } /** * Negative test for SetPropertyRule ignoring missing properties. */ public void testNegativeNotIgnoreMissing() throws Exception { // Set up the rules we need digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); SetPropertiesRule rule = new SetPropertiesRule(); rule.setIgnoreMissingProperty(false); digester.addRule("root", rule); try { // Parse the input SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader(TEST_XML_2)); fail("Should have thrown NoSuchMethodException"); assertNotNull(bean); // just to prevent compiler warning on unused var } catch (Exception e) { if (e instanceof NoSuchMethodException) { // Expected; } else if (e instanceof SAXException) { Exception ee = ((SAXException) e).getException(); if (ee != null) { if (ee instanceof NoSuchMethodException) { ; // Expected result } else { fail("Should have thrown SE->NoSuchMethodException, threw " + ee); } } else { fail("Should have thrown NoSuchMethodException, threw " + e.getClass().getName()); } } else { fail("Should have thrown NoSuchMethodException, threw " + e); } } } /** * Negative test for SetPropertyRule ignoring missing properties. */ public void testPositiveNotIgnoreMissingWithIgnoreAttributes() throws Exception { // Set up the rules we need digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); SetPropertiesRule rule = new SetPropertiesRule(new String[] {"ignore"}, new String[] {}); rule.setIgnoreMissingProperty(false); digester.addRule("root", rule); // Parse the input SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader(TEST_XML_3)); // Check that the properties were set correctly assertEquals("alpha property set", "ALPHA VALUE", bean.getAlpha()); assertEquals("beta property set", "BETA VALUE", bean.getBeta()); assertNull("gamma property not set", bean.getGamma()); assertEquals("delta property set", "DELTA VALUE", bean.getDeltaValue()); } /** * Get input stream from specified String containing XML data. */ private Reader xmlTestReader(String xml) throws IOException { return new StringReader(xml); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/Test1.xml0000644000175000017500000000212411226450007030060 0ustar twernertwerner
././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/NodeCreateRuleTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/NodeCreateRuleTestCase.java0000644000175000017500000004576211226450007033515 0ustar twernertwerner/* $Id: NodeCreateRuleTestCase.java 730332 2008-12-31 07:09:35Z rahul $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.w3c.dom.Document; import org.w3c.dom.DocumentFragment; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.xml.sax.SAXException; /** *

Test case for the NodeCreateRule. * * @author Christopher Lenz * @version $Revision: 730332 $ $Date: 2008-12-31 02:09:35 -0500 (Wed, 31 Dec 2008) $ */ public class NodeCreateRuleTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * Simple test xml document used in the tests. */ protected final static String TEST_XML = "ROOT BODYALPHA BODY" + "BETA BODYGAMMA BODY"; /** * The digester instance we will be processing. */ protected Digester digester = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public NodeCreateRuleTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(NodeCreateRuleTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods /** * Tests simple element construction, using the {@link #TEST_XML} * XML input data. */ public void testInvalidNodeTypes() throws SAXException, ParserConfigurationException, IOException { try { Rule rule = new NodeCreateRule(Node.ATTRIBUTE_NODE); fail("IllegalArgumentException expected for type ATTRIBUTE_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } try { Rule rule = new NodeCreateRule(Node.CDATA_SECTION_NODE); fail("IllegalArgumentException expected for type " + "CDATA_SECTION_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } try { Rule rule = new NodeCreateRule(Node.COMMENT_NODE); fail("IllegalArgumentException expected for type COMMENT_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } try { Rule rule = new NodeCreateRule(Node.DOCUMENT_NODE); fail("IllegalArgumentException expected for type DOCUMENT_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } try { Rule rule = new NodeCreateRule(Node.DOCUMENT_TYPE_NODE); fail("IllegalArgumentException expected for type " + "DOCUMENT_TYPE_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } try { Rule rule = new NodeCreateRule(Node.ENTITY_NODE); fail("IllegalArgumentException expected for type ENTITY_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } try { Rule rule = new NodeCreateRule(Node.ENTITY_REFERENCE_NODE); fail("IllegalArgumentException expected for type " + "ENTITY_REFERENCE_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } try { Rule rule = new NodeCreateRule(Node.NOTATION_NODE); fail("IllegalArgumentException expected for type NOTATION_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } try { Rule rule = new NodeCreateRule(Node.PROCESSING_INSTRUCTION_NODE); fail("IllegalArgumentException expected for type " + "PROCESSING_INSTRUCTION_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } try { Rule rule = new NodeCreateRule(Node.TEXT_NODE); fail("IllegalArgumentException expected for type TEXT_NODE"); assertNotNull(rule); // just to prevent compiler warning on unused var } catch (IllegalArgumentException iae) { // expected } } /** * Tests simple element construction, using the {@link #TEST_XML} * XML input data. */ public void testElement() throws SAXException, ParserConfigurationException, IOException { digester.addRule("root/alpha", new NodeCreateRule()); Object result = digester.parse(new StringReader(TEST_XML)); assertNotNull(result); assertTrue(result instanceof Element); Element element = (Element)result; assertEquals("alpha", element.getNodeName()); assertNull(((Element)element).getLocalName()); assertNull(((Element)element).getNamespaceURI()); assertEquals(1, element.getChildNodes().getLength()); assertEquals("ALPHA BODY", element.getFirstChild().getNodeValue()); } /** * Tests simple fragment construction, using the {@link #TEST_XML} * XML input data. */ public void testDocumentFragment() throws SAXException, ParserConfigurationException, IOException { digester.addRule("root", new NodeCreateRule(Node.DOCUMENT_FRAGMENT_NODE)); Object result = digester.parse(new StringReader(TEST_XML)); assertNotNull(result); assertTrue(result instanceof DocumentFragment); DocumentFragment fragment = (DocumentFragment)result; assertEquals(4, fragment.getChildNodes().getLength()); Node rootBody = fragment.getFirstChild(); assertEquals(Node.TEXT_NODE, rootBody.getNodeType()); assertEquals("ROOT BODY", rootBody.getNodeValue()); Node alpha = fragment.getChildNodes().item(1); assertEquals(Node.ELEMENT_NODE, alpha.getNodeType()); assertEquals("alpha", alpha.getNodeName()); assertNull(((Element)alpha).getLocalName()); assertNull(((Element)alpha).getNamespaceURI()); assertEquals(1, alpha.getChildNodes().getLength()); assertEquals("ALPHA BODY", alpha.getFirstChild().getNodeValue()); Node beta = fragment.getChildNodes().item(2); assertEquals(Node.ELEMENT_NODE, beta.getNodeType()); assertEquals("beta", beta.getNodeName()); assertNull(((Element)beta).getLocalName()); assertNull(((Element)beta).getNamespaceURI()); assertEquals(1, beta.getChildNodes().getLength()); assertEquals("BETA BODY", beta.getFirstChild().getNodeValue()); Node gamma = fragment.getChildNodes().item(3); assertEquals(Node.ELEMENT_NODE, gamma.getNodeType()); assertEquals("gamma", gamma.getNodeName()); assertNull(((Element)gamma).getLocalName()); assertNull(((Element)gamma).getNamespaceURI()); assertEquals(1, gamma.getChildNodes().getLength()); assertEquals("GAMMA BODY", gamma.getFirstChild().getNodeValue()); } /** * Tests whether control is returned to digester after fragment * construction. */ public void testNested() throws SAXException, ParserConfigurationException, IOException { digester.addObjectCreate("root", ArrayList.class); digester.addRule("root/a/b", new NodeCreateRule(Node.DOCUMENT_FRAGMENT_NODE)); digester.addSetRoot("root/a/b", "add"); digester.addObjectCreate("root/b", String.class); digester.addSetRoot("root/b", "add"); Object result = digester.parse(getInputStream("Test4.xml")); assertNotNull(result); assertTrue(result instanceof List); List list = (List)result; assertEquals(2, list.size()); assertTrue(list.get(0) instanceof DocumentFragment); DocumentFragment fragment = (DocumentFragment)list.get(0); assertEquals(Node.ELEMENT_NODE, fragment.getFirstChild().getNodeType()); Element a = (Element)fragment.getFirstChild(); assertEquals("a", a.getNodeName()); assertEquals(1, a.getAttributes().getLength()); assertEquals("THREE", a.getAttribute("name")); assertTrue(list.get(1) instanceof String); } /** * Tests whether attributes are correctly imported into the fragment, using * the example in the Test1 XML file. */ public void testAttributes() throws SAXException, ParserConfigurationException, IOException { digester.addRule("employee", new NodeCreateRule(Node.DOCUMENT_FRAGMENT_NODE)); Object result = digester.parse(getInputStream("Test1.xml")); assertNotNull(result); assertTrue(result instanceof DocumentFragment); DocumentFragment fragment = (DocumentFragment)result; assertEquals(2, fragment.getChildNodes().getLength()); assertEquals(Node.ELEMENT_NODE, fragment.getFirstChild().getNodeType()); Element address1 = (Element)fragment.getFirstChild(); assertEquals("address", address1.getNodeName()); assertEquals(5, address1.getAttributes().getLength()); assertEquals("home", address1.getAttribute("type")); assertEquals("Home Street", address1.getAttribute("street")); assertEquals("Home City", address1.getAttribute("city")); assertEquals("HS", address1.getAttribute("state")); assertEquals("HmZip", address1.getAttribute("zipCode")); assertEquals(Node.ELEMENT_NODE, fragment.getLastChild().getNodeType()); Element address2 = (Element)fragment.getLastChild(); assertEquals("address", address2.getNodeName()); assertEquals(5, address2.getAttributes().getLength()); assertEquals("office", address2.getAttribute("type")); assertEquals("Office Street", address2.getAttribute("street")); assertEquals("Office City", address2.getAttribute("city")); assertEquals("OS", address2.getAttribute("state")); assertEquals("OfZip", address2.getAttribute("zipCode")); } /** * Tests whether namespaces are handled correctly, using the example from * the file Test3 XML file. */ public void testNamespaces() throws SAXException, ParserConfigurationException, IOException { digester.setNamespaceAware(true); digester.setRuleNamespaceURI(null); digester.addRule("employee", new NodeCreateRule(Node.DOCUMENT_FRAGMENT_NODE)); Object result = digester.parse(getInputStream("Test3.xml")); assertNotNull(result); assertTrue(result instanceof DocumentFragment); DocumentFragment fragment = (DocumentFragment)result; assertEquals(2, fragment.getChildNodes().getLength()); assertEquals(Node.ELEMENT_NODE, fragment.getFirstChild().getNodeType()); Element address1 = (Element)fragment.getFirstChild(); assertEquals("address", address1.getNodeName()); assertEquals("http://commons.apache.org/digester/Bar", address1.getNamespaceURI()); assertEquals("address", address1.getLocalName()); assertEquals(5, address1.getAttributes().getLength()); assertEquals("home", address1.getAttribute("type")); assertEquals("Home Street", address1.getAttribute("street")); assertEquals("Home City", address1.getAttribute("city")); assertEquals("HS", address1.getAttribute("state")); assertEquals("HmZip", address1.getAttribute("zipCode")); assertEquals(Node.ELEMENT_NODE, fragment.getLastChild().getNodeType()); Element address2 = (Element)fragment.getLastChild(); assertEquals("address", address2.getNodeName()); assertEquals("http://commons.apache.org/digester/Bar", address2.getNamespaceURI()); assertEquals("address", address2.getLocalName()); assertEquals(5, address2.getAttributes().getLength()); assertEquals("office", address2.getAttribute("type")); assertEquals("Office Street", address2.getAttribute("street")); assertEquals("Office City", address2.getAttribute("city")); assertEquals("OS", address2.getAttribute("state")); assertEquals("OfZip", address2.getAttribute("zipCode")); } /** * Tests whether namespaced attributes are handled correctly, using the example from * the file Test10 XML file. */ public void testNamespacedAttribute() throws SAXException, ParserConfigurationException, IOException { digester.setNamespaceAware(true); digester.setRuleNamespaceURI(null); digester.addRule("employee", new NodeCreateRule(Node.ELEMENT_NODE)); Object result = digester.parse(getInputStream("Test10.xml")); assertNotNull(result); assertTrue(result instanceof Element); Element element = (Element)result; assertNotNull(element.getAttributeNodeNS("http://commons.apache.org/digester/Bar", "test")); assertEquals("MyTestAttribute", element.getAttributeNodeNS("http://commons.apache.org/digester/Bar", "test").getNodeValue()); assertEquals("test", element.getAttributeNodeNS("http://commons.apache.org/digester/Bar", "test").getLocalName()); assertEquals("bar", element.getAttributeNodeNS("http://commons.apache.org/digester/Bar", "test").getPrefix()); assertEquals("bar:test", element.getAttributeNodeNS("http://commons.apache.org/digester/Bar", "test").getName()); } /** * Tests whether non-namespaced attributes are handled correctly, using the example from * the file Test11 XML file. */ public void testNonNamespacedAttribute() throws SAXException, ParserConfigurationException, IOException { digester.setNamespaceAware(true); digester.setRuleNamespaceURI(null); digester.addRule("employee", new NodeCreateRule(Node.ELEMENT_NODE)); Object result = digester.parse(getInputStream("Test10.xml")); assertNotNull(result); assertTrue(result instanceof Element); Element element = (Element)result; assertNotNull(element.getAttributeNode("firstName")); assertEquals("First Name", element.getAttributeNode("firstName").getNodeValue()); assertEquals("firstName", element.getAttributeNode("firstName").getLocalName()); assertEquals(null, element.getAttributeNode("firstName").getPrefix()); assertEquals("firstName", element.getAttributeNode("firstName").getName()); } /** * Tests whether the created fragment can be imported into an existing * document. */ public void testImport() throws SAXException, ParserConfigurationException, IOException { digester.addRule("root", new NodeCreateRule(Node.DOCUMENT_FRAGMENT_NODE)); Object result = digester.parse(new StringReader(TEST_XML)); DocumentFragment fragment = (DocumentFragment)result; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); Node importedFragment = doc.importNode(fragment, true); doc.appendChild(doc.createElement("root")); doc.getFirstChild().appendChild(importedFragment); } /** * This unit test checks that text nodes are correctly created when * xml entities are used. In particular, this usually causes the xml * parser to make multiple invocations of the characters(..) sax * callback, rather than just one. */ public void testEntityText() throws Exception { String TEST_XML2 = "A A"; digester.addRule("root/alpha", new NodeCreateRule()); Object result = digester.parse(new StringReader(TEST_XML2)); assertNotNull(result); assertTrue(result instanceof Element); Element element = (Element)result; assertEquals("alpha", element.getNodeName()); assertNull(((Element)element).getLocalName()); assertNull(((Element)element).getNamespaceURI()); assertEquals(1, element.getChildNodes().getLength()); assertEquals("A A", element.getFirstChild().getNodeValue()); } // ------------------------------------------------ Utility Support Methods /** * Return an appropriate InputStream for the specified test file (which * must be inside our current package. * * @param name Name of the test file we want * * @exception IOException if an input/output error occurs */ protected InputStream getInputStream(String name) throws IOException { return (this.getClass().getResourceAsStream ("/org/apache/commons/digester/" + name)); } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/OverlappingCallMethodRuleTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/OverlappingCallMethodRuleTe0000644000175000017500000002132411226450007033630 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.StringReader; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.SAXException; /** *

Tests for situations where CallMethodRule instances and their * parameters overlap each other.

*/ public class OverlappingCallMethodRuleTestCase extends TestCase { // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public OverlappingCallMethodRuleTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(OverlappingCallMethodRuleTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { } String itemId; String itemName; public void setItemId(String id) { itemId = id; } public void setItemName(String name) { itemName = name; } // ------------------------------------------------ Individual Test Methods public void testItem1() throws SAXException, IOException { StringBuffer input = new StringBuffer(); input.append(""); input.append(" anitem"); input.append(""); Digester digester = new Digester(); digester.addCallMethod("root/item", "setItemId", 1); digester.addCallParam("root/item", 0, "id"); digester.addCallMethod("root/item", "setItemName", 1); digester.addCallParam("root/item", 0); this.itemId = null; this.itemName = null; digester.push(this); digester.parse(new StringReader(input.toString())); assertEquals("1", this.itemId); assertEquals("anitem", this.itemName); } public void testItem2() throws SAXException, IOException { StringBuffer input = new StringBuffer(); input.append(""); input.append(" anitem"); input.append(""); Digester digester = new Digester(); digester.addCallMethod("root/item", "setItemName", 1); digester.addCallParam("root/item", 0); digester.addCallMethod("root/item", "setItemId", 1); digester.addCallParam("root/item", 0, "id"); this.itemId = null; this.itemName = null; digester.push(this); digester.parse(new StringReader(input.toString())); assertEquals("1", this.itemId); assertEquals("anitem", this.itemName); } public void testItem3() throws SAXException, IOException { StringBuffer input = new StringBuffer(); input.append(""); input.append(" 1"); input.append(""); Digester digester = new Digester(); digester.addCallMethod("root/item", "setItemId", 1); digester.addCallParam("root/item", 0); digester.addCallMethod("root/item", "setItemName", 1); digester.addCallParam("root/item", 0); this.itemId = null; this.itemName = null; digester.push(this); digester.parse(new StringReader(input.toString())); assertEquals("1", this.itemId); assertEquals("1", this.itemName); } /** * This is an "anti-test" that demonstrates how digester can fails * to produce the correct results, due to a design flaw (or at least * limitation) in the way that CallMethodRule and CallParamRule work. *

* The following sequence always fails: *

    *
  • CallMethodRule A fires (pushing params array)
  • *
  • CallMethodRule B fires (pushing params array)
  • *
  • params rule for A fires --> writes to params of method B!
  • *
  • params rule for B fires --> overwrites params for method B
  • *
* The result is that method "b" appears to work ok, but method "a" * loses its input parameters. *

* One solution is for CallParamRule objects to know which CallMethodRule * they are associated with. Even this might fail in corner cases where * the same rule is associated with multiple patterns, or with wildcard * patterns which cause a rule to fire in a "recursive" manner. However * implementing this is not possible with the current digester design. */ public void testItem4() throws SAXException, IOException { StringBuffer input = new StringBuffer(); input.append(""); input.append(" "); input.append(" "); input.append(" "); input.append(" "); input.append(""); Digester digester = new Digester(); digester.addCallMethod("root/item", "setItemId", 1); digester.addCallParam("root/item/id", 0, "value"); digester.addCallMethod("root/item", "setItemName", 1); digester.addCallParam("root/item/name", 0, "value"); this.itemId = null; this.itemName = null; digester.push(this); digester.parse(new StringReader(input.toString())); // These are the "correct" results //assertEquals("1", this.itemId); //assertEquals("name", this.itemName); // These are what actually happens assertEquals(null, this.itemId); assertEquals("name", this.itemName); } /** * This test checks that CallParamRule instances which fetch data * from xml attributes work ok when invoked "recursively", * ie a rule instances' methods gets called in the order * begin[1]/begin[2]/body[2]/end[2]/body[1]/end[1] */ public void testWildcard1() throws SAXException, IOException { StringBuffer input = new StringBuffer(); input.append(""); input.append(" "); input.append(" "); input.append(" "); input.append(" "); input.append(""); Digester digester = new Digester(); digester.addObjectCreate("*/box", Box.class); digester.addCallMethod("*/box", "setId", 1); digester.addCallParam("*/box", 0, "id"); digester.addSetNext("*/box", "addChild"); Box root = new Box(); root.setId("root"); digester.push(root); digester.parse(new StringReader(input.toString())); // walk the object tree, concatenating the id strings String ids = root.getIds(); assertEquals("root A1 B1 C1 C2", ids); } /** * This test checks that CallParamRule instances which fetch data * from the xml element body work ok when invoked "recursively", * ie a rule instances' methods gets called in the order * begin[1]/begin[2]/body[2]/end[2]/body[1]/end[1] */ public void testWildcard2() throws SAXException, IOException { StringBuffer input = new StringBuffer(); input.append("A1"); input.append(" B1"); input.append(" C1"); input.append(" C2"); input.append(" "); input.append(""); Digester digester = new Digester(); digester.addObjectCreate("*/box", Box.class); digester.addCallMethod("*/box", "setId", 1); digester.addCallParam("*/box", 0); digester.addSetNext("*/box", "addChild"); Box root = new Box(); root.setId("root"); digester.push(root); digester.parse(new StringReader(input.toString())); // walk the object tree, concatenating the id strings String ids = root.getIds(); assertEquals("root A1 B1 C1 C2", ids); } } libcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/PrimitiveBean.java0000644000175000017500000000314411226450007031742 0ustar twernertwerner/* $Id: PrimitiveBean.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * A simple bean with primitive properties. * At the moment only need a boolean property. * Feel free to add others later. * * @author robert burrell donkin */ public class PrimitiveBean { private boolean booleanValue; private boolean setBooleanCalled; public PrimitiveBean() {} public boolean getBoolean() { return booleanValue; } public boolean getSetBooleanCalled() { return setBooleanCalled; } public void setBoolean(boolean booleanValue) { this.booleanValue = booleanValue; setBooleanCalled = true; } public void testSetBoolean(String ignored, boolean booleanValue) { setBoolean(booleanValue); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/SetPropertyRuleTestCase.javalibcommons-digester-java-1.8.1.orig/src/test/org/apache/commons/digester/SetPropertyRuleTestCase.jav0000644000175000017500000001465211226450007033635 0ustar twernertwerner/* $Id: SetPropertyRuleTestCase.java 568192 2007-08-21 16:41:16Z bayard $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.lang.reflect.InvocationTargetException; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.xml.sax.SAXException; /** *

Test case for SetPropertyRule.

*/ public class SetPropertyRuleTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * Simple test xml document used in the tests. */ protected final static String TEST_XML_1 = "" + "" + "" + "" + ""; /** * Simple test xml document used in the tests. */ protected final static String TEST_XML_2 = "" + "" + ""; /** * The digester instance we will be processing. */ protected Digester digester = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public SetPropertyRuleTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { digester = new Digester(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(SetPropertyRuleTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { digester = null; } // ------------------------------------------------ Individual Test Methods /** * Positive test for SetPropertyRule. */ public void testPositive() throws Exception { // Set up the rules we need digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); digester.addSetProperty("root/set", "name", "value"); // Parse the input SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader(TEST_XML_1)); // Check that the properties were set correctly assertEquals("alpha property set", "ALPHA VALUE", bean.getAlpha()); assertEquals("beta property set", "BETA VALUE", bean.getBeta()); assertNull("gamma property not set", bean.getGamma()); assertEquals("delta property set", "DELTA VALUE", bean.getDeltaValue()); } /** * Negative test for SetPropertyRule. */ public void testNegative() { // Set up the rules we need digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); digester.addSetProperty("root/set", "name", "value"); // Parse the input (should fail) try { SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader(TEST_XML_2)); fail("Should have thrown NoSuchMethodException"); assertNotNull(bean); // just to prevent compiler warning on unused var } catch (Exception e) { if (e instanceof NoSuchMethodException) { ; // Expected result } else if (e instanceof InvocationTargetException) { Throwable t = ((InvocationTargetException) e).getTargetException(); if (t instanceof NoSuchMethodException) { ; // Expected result } else { fail("Should have thrown ITE->NoSuchMethodException, threw " + t); } } else if (e instanceof SAXException) { Exception ee = ((SAXException) e).getException(); if (ee != null) { if (ee instanceof NoSuchMethodException) { ; // Expected result } else { fail("Should have thrown SE->NoSuchMethodException, threw " + ee); } } else { fail("Should have thrown NoSuchMethodException, threw " + e.getClass().getName()); } } else { fail("Should have thrown NoSuchMethodException, threw " + e); } } } /** * Get input stream from specified String containing XML data. */ private Reader xmlTestReader(String xml) throws IOException { return new StringReader(xml); } /** * Test SetPropertyRule when matched XML element has no attributes. * See: DIGESTER-114 */ public void testElementWithNoAttributes() throws Exception { String TEST_XML_3 = ""; // Set up the rules we need digester.addObjectCreate("root", "org.apache.commons.digester.SimpleTestBean"); digester.addSetProperty("root/set", "name", "value"); // Parse the input - should not throw an exception SimpleTestBean bean = (SimpleTestBean) digester.parse(xmlTestReader(TEST_XML_3)); } } libcommons-digester-java-1.8.1.orig/src/examples/0000755000175000017500000000000011226450007021705 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/api/0000755000175000017500000000000011226450007022456 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/api/document-markup/0000755000175000017500000000000011226450007025571 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/api/document-markup/TextSegmentHandler.java0000644000175000017500000000202111226450007032174 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ /** * Public interface for any Rule subclass which is interested in handling * text segments as well as the complete body text. */ public interface TextSegmentHandler { public void textSegment(String text) throws Exception; } libcommons-digester-java-1.8.1.orig/src/examples/api/document-markup/SetTextSegmentRule.java0000644000175000017500000000355211226450007032214 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import org.apache.commons.beanutils.MethodUtils; import org.apache.commons.digester.Rule; /** * When a text segment is discovered, it calls a specific method on the top * object on the stack. */ public class SetTextSegmentRule extends Rule implements TextSegmentHandler { // ----------------------------------------------------------- Constructors public SetTextSegmentRule(String methodName) { this.methodName = methodName; } // ----------------------------------------------------- Instance Variables /** * The method name to call on the parent object. */ protected String methodName = null; // --------------------------------------------------------- Public Methods /** * Process the end of this element. */ public void textSegment(String text) throws Exception { Object target = digester.peek(0); // Call the specified method Class paramTypes[] = new Class[] {String.class}; MethodUtils.invokeMethod(target, methodName, new Object[]{ text }, paramTypes); } } libcommons-digester-java-1.8.1.orig/src/examples/api/document-markup/Main.java0000644000175000017500000000621311226450007027322 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ /** * A simple "test harness" which demonstrates how the MarkupDigester class * (plus the supporting interface/rule classes) can process "document-markup" * style xml data. *

* See the readme file included with this example for more information. */ public class Main { /** The input xml to be parsed by this example. */ String in = "

Hi, this is an example of some bold text.

"; /** Invoked when a text segment is present in the parsed input. */ public void addSegment(String text) { System.out.println("Text segment: [" + text + "]"); } /** Invoked when an <i> node is found in the parsed input. */ public void addItalic(String text) { System.out.println("Italic: [" + text + "]"); } /** Invoked when an <b> node is found in the parsed input. */ public void addBold(String text) { System.out.println("Bold: [" + text + "]"); } /** * Invoked via a standard Digester CallMethodRule, passing the * "body text" of the top-level xml element. This demonstrates * the default behaviour of Digester (which is not suitable for * processing markup-style xml). */ public void addAllText(String text) { System.out.println( "And the merged text for the p element is [" + text + "]"); } /** * Main method of this test harness. Set up some digester rules, * then parse the input xml contained in the "in" member variable. * The rules cause methods on this object to be invoked, which just * dump information to standard output, to show the callbacks that * a real program could arrange to get when parsing markup input. */ public void run() throws Exception { System.out.println("Started."); MarkupDigester d = new MarkupDigester(); d.push(this); SetTextSegmentRule r = new SetTextSegmentRule("addSegment"); d.addRule("p", r); d.addCallMethod("p", "addAllText", 0); d.addCallMethod("p/i", "addItalic", 0); d.addCallMethod("p/b", "addBold", 0); d.parse(new java.io.StringReader(in)); System.out.println("Finished."); } /** See the run method. */ public static void main(String[] args) throws Exception { new Main().run(); } } libcommons-digester-java-1.8.1.orig/src/examples/api/document-markup/MarkupDigester.java0000644000175000017500000001312011226450007031357 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import org.apache.commons.digester.Digester; import org.apache.commons.digester.Rule; import java.util.List; import javax.xml.parsers.SAXParser; import org.xml.sax.XMLReader; import org.xml.sax.SAXException; import org.xml.sax.Attributes; /** * This is a subclass of digester which supports rules which implement * the TextSegmentHandler interface, causing the "textSegment" method * on each matching rule (of the appropriate type) to be invoked when * an element contains a segment of text followed by a child element. *

* See the readme file included with this example for more information. */ public class MarkupDigester extends Digester { /** See equivalent constructor in Digester class. */ public MarkupDigester() { } /** See equivalent constructor in Digester class. */ public MarkupDigester(SAXParser parser) { super(parser); } /** See equivalent constructor in Digester class. */ public MarkupDigester(XMLReader reader) { super(reader); } //=================================================================== /** * The text found in the current element since the last child element. */ protected StringBuffer currTextSegment = new StringBuffer(); /** * Process notification of character data received from the body of * an XML element. * * @param buffer The characters from the XML document * @param start Starting offset into the buffer * @param length Number of characters from the buffer * * @exception SAXException if a parsing error is to be reported */ public void characters(char buffer[], int start, int length) throws SAXException { super.characters(buffer, start, length); currTextSegment.append(buffer, start, length); } /** * Process notification of the start of an XML element being reached. * * @param namespaceURI The Namespace URI, or the empty string if the element * has no Namespace URI or if Namespace processing is not being performed. * @param localName The local name (without prefix), or the empty * string if Namespace processing is not being performed. * @param qName The qualified name (with prefix), or the empty * string if qualified names are not available. * @param list The attributes attached to the element. If there are * no attributes, it shall be an empty Attributes object. * @exception SAXException if a parsing error is to be reported */ public void startElement(String namespaceURI, String localName, String qName, Attributes list) throws SAXException { handleTextSegments(); // Unlike bodyText, which accumulates despite intervening child // elements, currTextSegment gets cleared here. This means that // we don't need to save it on a stack either. currTextSegment.setLength(0); super.startElement(namespaceURI, localName, qName, list); } /** * Process notification of the end of an XML element being reached. * * @param namespaceURI - The Namespace URI, or the empty string if the * element has no Namespace URI or if Namespace processing is not * being performed. * @param localName - The local name (without prefix), or the empty * string if Namespace processing is not being performed. * @param qName - The qualified XML 1.0 name (with prefix), or the * empty string if qualified names are not available. * @exception SAXException if a parsing error is to be reported */ public void endElement(String namespaceURI, String localName, String qName) throws SAXException { handleTextSegments(); currTextSegment.setLength(0); super.endElement(namespaceURI, localName, qName); } /** * Iterate over the list of rules most recently matched, and * if any of them implement the TextSegmentHandler interface then * invoke that rule's textSegment method passing the current * segment of text from the xml element body. */ private void handleTextSegments() throws SAXException { if (currTextSegment.length() > 0) { String segment = currTextSegment.toString(); List parentMatches = (List) matches.peek(); int len = parentMatches.size(); for(int i=0; iHi, this is some document-style xml.

" Topics covered: * how to subclass digester * how to process markup-style xml. == compiling and running First rename the build.properties.sample file in the parent directory to build.properties and edit it to suit your environment. Then in this directory: * to compile: ant compile * to run: ant run Alternatively, you can set up your CLASSPATH appropriately, and run the example directly. See the build.properties and build.xml files for details. == Notes The primary use of the Digester is to process xml configuration files. Such files do not typically interleave text and child elements in the style encountered with document markup. The standard Digester behaviour is therefore to accumulate all text within an xml element's body (of which there is expected to be only one "segment") and present it to a Rule or user method as a single string. While this significantly simplifies the implementation of Rule classes for the primary Digester goal of parsing configuration files, this process of simplifying all text within an element into a single string "loses" critical information necessary to correctly parse "document-markup" xml. This example shows one method of extending the Digester class to resolve this issue.. At some time the ability to process "document-markup" style xml may be built into the standard Digester class. libcommons-digester-java-1.8.1.orig/src/examples/api/document-markup/build.xml0000644000175000017500000001125311226450007027414 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/examples/api/dbinsert/0000755000175000017500000000000011226450007024270 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/api/dbinsert/example.xml0000644000175000017500000000240611226450007026447 0ustar twernertwerner Kermit green worrying Miss Piggy pink karate
Drums Animal
libcommons-digester-java-1.8.1.orig/src/examples/api/dbinsert/Main.java0000644000175000017500000001433511226450007026025 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import org.apache.commons.digester.Digester; /** * A simple program to demonstrate that the Commons Digester module can be * used to trigger actions as the xml is parsed, rather than just build * up in-memory representations of the parsed data. This example also shows * how to write a custom Rule class. *

* This code will parse the provided "example.xml" file, and immediately * insert the processed data into a database as each row tag is parsed, * instead of building up an in-memory representation. Actually, in order * to keep this example simple and easy to run, sql insert statements are * printed out rather than actually performing database inserts, but the * principle remains. *

* Very verbose comments are included here, as this class is intended * as a tutorial; if you look closely at method "addRules", you will * see that the amount of code required to use the Digester is actually * quite low. *

* Usage: java Main example.xml */ public class Main { /** * Main method : entry point for running this example program. *

* Usage: java Main example.xml */ public static void main(String[] args) { if (args.length != 1) { usage(); System.exit(-1); } String filename = args[0]; // Create a Digester instance Digester d = new Digester(); // Here you would establish a real connection. // There would also be a finally clause to ensure it is // closed after parsing terminates, etc. java.sql.Connection connection = null; // Add rules to the digester that will be triggered while // parsing occurs. addRules(d, connection); // Process the input file. System.out.println("Parsing commencing..."); try { java.io.File srcfile = new java.io.File(filename); d.parse(srcfile); } catch(java.io.IOException ioe) { System.out.println("Error reading input file:" + ioe.getMessage()); System.exit(-1); } catch(org.xml.sax.SAXException se) { System.out.println("Error parsing input file:" + se.getMessage()); System.exit(-1); } // And here there is nothing to do. The digester rules have // (deliberately) not built a representation of the input, but // instead processed the data as it was read. System.out.println("Parsing complete."); } private static void addRules(Digester d, java.sql.Connection conn) { //-------------------------------------------------- // when we encounter a "table" tag, do the following: // Create a new instance of class Table, and push that // object onto the digester stack of objects. We only need // this so that when a row is inserted, it can find out what // the enclosing tablename was. // // Note that the object is popped off the stack at the end of the // "table" tag (normal behaviour for ObjectCreateRule). Because we // never added the table object to some parent object, when it is // popped off the digester stack it becomes garbage-collected. That // is fine in this situation; we've done all the necessary work and // don't need the table object any more. d.addObjectCreate("database/table", Table.class); // Map *any* attributes on the table tag to appropriate // setter-methods on the top object on the stack (the Table // instance created by the preceeding rule). We only expect one // attribute, though: a 'name' attribute specifying what table // we are inserting rows into. d.addSetProperties("database/table"); //-------------------------------------------------- // When we encounter a "row" tag, invoke methods on the provided // RowInserterRule instance. // // This rule creates a Row instance and pushes it on the digester // object stack, rather like ObjectCreateRule, so that the column // tags have somewhere to store their information. And when the // end tag is found, the rule will trigger to remove this // object from the stack, and also do an actual database insert. // // Note that the rule instance we are passing to the digester has // been initialised with some useful data (the SQL connection). // // Note also that in this case we are not using the digester's // factory methods to create the rule instance; that's just a // convenience - and obviously not an option for Rule classes // that are not part of the digester core implementation. RowInserterRule rowInserterRule = new RowInserterRule(conn); d.addRule("database/table/row", rowInserterRule); //-------------------------------------------------- // when we encounter a "column" tag, call setColumn on the top // object on the stack, passing two parameters: the "name" // attribute, and the text within the tag body. d.addCallMethod("database/table/row/column", "addColumn", 2); d.addCallParam("database/table/row/column", 0, "name"); d.addCallParam("database/table/row/column", 1); } private static void usage() { System.out.println("Usage: java Main example.xml"); } }libcommons-digester-java-1.8.1.orig/src/examples/api/dbinsert/RowInserterRule.java0000644000175000017500000000743611226450007030260 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.Map; import java.util.Iterator; /** * See Main.java. */ public class RowInserterRule extends org.apache.commons.digester.Rule { private java.sql.Connection conn; public RowInserterRule(java.sql.Connection conn) { this.conn = conn; } /** * This method is invoked when the start tag for an xml element representing * a database row is encountered. It pushes a new Row instance onto the * digester stack (rather like an ObjectCreateRule) so that column data * can be stored on it. */ public void begin(String namespace, String name, org.xml.sax.Attributes attrs) { digester.push(new Row()); } /** * This method is invoked when the end tag for an xml element representing * a database row is encountered. It pops a fully-configured Row instance * off the digester stack, accesses the object below it on the stack (a * Table object) to get the tablename, then does an SQL insert). Actually, * here we just print out text rather than do the sql insert, but the * real implementation should be fairly simple. *

* Note that after this rule completes, the row/column information is * discarded, ie this rule performs actions as the input is * parsed. This contrasts with the more usual way digester is used, * which is to build trees of objects for later use. But it's a perfectly * valid use of Digester. */ public void end(String namespace, String name) { Row row = (Row) digester.pop(); Table table = (Table) digester.peek(); // Obviously, all this would be replaced by code like: // stmt = conn.prepareStatement(); // stmt.setString(n, value); // // Many improvements can then be implemented, such as using the // PreparedStatement.getParameterMetaData method to retrieve // retrieve parameter types, etc. StringBuffer colnames = new StringBuffer(); StringBuffer colvalues = new StringBuffer(); for(Iterator i = row.getColumns().iterator(); i.hasNext();) { Row.Column column = (Row.Column) i.next(); if (colnames.length() > 0) { colnames.append(", "); colvalues.append(", "); } colnames.append("'"); colnames.append(column.getName()); colnames.append("'"); colvalues.append("'"); colvalues.append(column.getValue()); colvalues.append("'"); } StringBuffer buf = new StringBuffer(); buf.append("insert into "); buf.append(table.getName()); buf.append(" ("); buf.append(colnames.toString()); buf.append(") values ("); buf.append(colvalues.toString()); buf.append(")"); // here the prepared statement would be executed.... System.out.println(buf.toString()); } } libcommons-digester-java-1.8.1.orig/src/examples/api/dbinsert/readme.txt0000644000175000017500000000313311226450007026266 0ustar twernertwerner######################################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. ######################################################################### == overview The files in this directory are intended as an example of how to use the Apache Digester's basic functionality via its java interface. Topics covered: * how to write a custom Rule class. * How to use digester to perform actions during parsing, rather than just build in-memory models of the input. == compiling and running First rename the build.properties.sample file in the parent directory to build.properties and edit it to suit your environment. Then in this directory: * to compile: ant compile * to run: ant run Alternatively, you can set up your CLASSPATH appropriately, and run the example directly. See the build.properties and build.xml files for details. libcommons-digester-java-1.8.1.orig/src/examples/api/dbinsert/build.xml0000644000175000017500000001132711226450007026115 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/examples/api/dbinsert/Row.java0000644000175000017500000000371111226450007025704 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.List; import java.util.LinkedList; /** * See Main.java. */ public class Row { /** * Alas, we can't just use a Map to store the (name, value) pairs * because the output will look weird if we don't preserve the column * order. This wouldn't be a problem if we were really inserting into * a database; it only matters because we are displaying the SQL statements * via stdout instead. The LinkedHashMap class would be nice to use, but * that would require java 1.4, so we'll use a list instead, and may as * well call the entries in the list 'Column' objects. */ public static class Column { private String name, value; public Column(String name, String value) { this.name = name; this.value = value; } public String getName() { return name; } public String getValue() { return value; } } private LinkedList columns = new LinkedList(); public Row() { } public void addColumn(String name, String value) { columns.add(new Column(name, value)); } public List getColumns() { return columns; } } libcommons-digester-java-1.8.1.orig/src/examples/api/dbinsert/Table.java0000644000175000017500000000200411226450007026156 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ /** * See Main.java. */ public class Table { private String name; public Table() { } public void setName(String name) { this.name = name; } public String getName() { return name; } } libcommons-digester-java-1.8.1.orig/src/examples/api/addressbook/0000755000175000017500000000000011226450007024756 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/api/addressbook/example.xml0000644000175000017500000000331111226450007027131 0ustar twernertwerner Gonzo gonzo@muppets.com

home 123 Maine Ave. Las Vegas NV 01234 USA
business 234 Maple Dr. Los Angeles CA 98765 USA
Kermit kermit@muppets.com kermie@acme.com
business 987 Brown Rd Las Cruces NM 75321 USA
libcommons-digester-java-1.8.1.orig/src/examples/api/addressbook/Main.java0000644000175000017500000001466611226450007026522 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import org.apache.commons.digester.Digester; /** * A simple program to demonstrate the basic functionality of the * Commons Digester module. *

* This code will parse the provided "example.xml" file to build a tree * of java objects, then cause those objects to print out their values * to demonstrate that the input file has been processed correctly. *

* As with all code, there are many ways of achieving the same goal; * the solution here is only one possible solution to the problem. *

* Very verbose comments are included here, as this class is intended * as a tutorial; if you look closely at method "addRules", you will * see that the amount of code required to use the Digester is actually * quite low. *

* Usage: java Main example.xml */ public class Main { /** * Main method : entry point for running this example program. *

* Usage: java Example example.xml */ public static void main(String[] args) { if (args.length != 1) { usage(); System.exit(-1); } String filename = args[0]; // Create a Digester instance Digester d = new Digester(); // Prime the digester stack with an object for rules to // operate on. Note that it is quite common for "this" // to be the object pushed. AddressBook book = new AddressBook(); d.push(book); // Add rules to the digester that will be triggered while // parsing occurs. addRules(d); // Process the input file. try { java.io.File srcfile = new java.io.File(filename); d.parse(srcfile); } catch(java.io.IOException ioe) { System.out.println("Error reading input file:" + ioe.getMessage()); System.exit(-1); } catch(org.xml.sax.SAXException se) { System.out.println("Error parsing input file:" + se.getMessage()); System.exit(-1); } // Print out all the contents of the address book, as loaded from // the input file. book.print(); } private static void addRules(Digester d) { //-------------------------------------------------- // when we encounter a "person" tag, do the following: // create a new instance of class Person, and push that // object onto the digester stack of objects d.addObjectCreate("address-book/person", Person.class); // map *any* attributes on the tag to appropriate // setter-methods on the top object on the stack (the Person // instance created by the preceeding rule). // // For example: // if attribute "id" exists on the xml tag, and method setId // with one parameter exists on the object that is on top of // the digester object stack, then a call will be made to that // method. The value will be type-converted from string to // whatever type the target method declares (where possible), // using the commons ConvertUtils functionality. // // Attributes on the xml tag for which no setter methods exist // on the top object on the stack are just ignored. d.addSetProperties("address-book/person"); // call the addPerson method on the second-to-top object on // the stack (the AddressBook object), passing the top object // on the stack (the recently created Person object). d.addSetNext("address-book/person", "addPerson"); //-------------------------------------------------- // when we encounter a "name" tag, call setName on the top // object on the stack, passing the text contained within the // body of that name element [specifying a zero parameter count // implies one actual parameter, being the body text]. // The top object on the stack will be a person object, because // the pattern address-book/person always triggers the // ObjectCreateRule we added previously. d.addCallMethod("address-book/person/name", "setName", 0); //-------------------------------------------------- // when we encounter an "email" tag, call addEmail on the top // object on the stack, passing two parameters: the "type" // attribute, and the text within the tag body. d.addCallMethod("address-book/person/email", "addEmail", 2); d.addCallParam("address-book/person/email", 0, "type"); d.addCallParam("address-book/person/email", 1); //-------------------------------------------------- // When we encounter an "address" tag, create an instance of class // Address and push it on the digester stack of objects. After // doing that, call addAddress on the second-to-top object on the // digester stack (a "Person" object), passing the top object on // the digester stack (the "Address" object). And also set things // up so that for each child xml element encountered between the start // of the address tag and the end of the address tag, the text // contained in that element is passed to a setXXX method on the // Address object where XXX is the name of the xml element found. d.addObjectCreate("address-book/person/address", Address.class); d.addSetNext("address-book/person/address", "addAddress"); d.addSetNestedProperties("address-book/person/address"); } private static void usage() { System.out.println("Usage: java Main example.xml"); } }libcommons-digester-java-1.8.1.orig/src/examples/api/addressbook/Address.java0000644000175000017500000000725211226450007027214 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.HashMap; import java.util.Iterator; /** * See Main.java. */ public class Address { private String type; private String street; private String city; private String state; private String zip; private String country; public String toString() { StringBuffer sb = new StringBuffer(); sb.append( " address (type "+ type + ")\n"); sb.append( " " + street + "\n"); sb.append( " " + city + " " + state + " " + zip + "\n"); sb.append( " " + country + "\n"); return sb.toString(); } public void print(java.io.PrintStream out, int indentAmount) { StringBuffer indentStr = new StringBuffer(indentAmount); for(; indentAmount > 0; --indentAmount) { indentStr.append(' '); } out.print(indentStr); out.print("address type: "); out.println(type); out.print(indentStr); out.println(" " + street); out.print(indentStr); out.println(" " + city + " " + state + " " + zip); out.print(indentStr); out.println(" " + country); } /** * Returns the value of street. */ public String getStreet() { return street; } /** * Sets the value of street. * @param street The value to assign to street. */ public void setStreet(String street) { this.street = street; } /** * Returns the value of city. */ public String getCity() { return city; } /** * Sets the value of city. * @param city The value to assign to city. */ public void setCity(String city) { this.city = city; } /** * Returns the value of state. */ public String getState() { return state; } /** * Sets the value of state. * @param state The value to assign to state. */ public void setState(String state) { this.state = state; } /** * Returns the value of zip. */ public String getZip() { return zip; } /** * Sets the value of zip. * @param zip The value to assign to zip. */ public void setZip(String zip) { this.zip = zip; } /** * Returns the value of country. */ public String getCountry() { return country; } /** * Sets the value of country. * @param country The value to assign to country. */ public void setCountry(String country) { this.country = country; } /** * Returns the value of type. */ public String getType() { return type; } /** * Sets the value of type. * @param type The value to assign to type. */ public void setType(String type) { this.type = type; } } libcommons-digester-java-1.8.1.orig/src/examples/api/addressbook/Person.java0000644000175000017500000000432311226450007027071 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; /** * See Main.java. */ public class Person { private int id; private String category; private String name; private HashMap emails = new HashMap(); private List addresses = new ArrayList(); /** * A unique id for this person. Note that the Digester automatically * converts the id to an integer. */ public void setId(int id) { this.id = id; } public void setCategory(String category) { this.category = category; } public void setName(String name) { this.name = name; } /** we assume only one email of each type... */ public void addEmail(String type, String address) { emails.put(type, address); } public void addAddress( Address addr ) { addresses.add( addr ); } public void print() { System.out.println("Person #" + id); System.out.println(" category=" + category); System.out.println(" name=" + name); for(Iterator i = emails.keySet().iterator(); i.hasNext(); ) { String type = (String) i.next(); String address = (String) emails.get(type); System.out.println(" email (type " + type + ") : " + address); } for(Iterator i = addresses.iterator(); i.hasNext(); ) { Address addr = (Address) i.next(); addr.print(System.out, 2); } } } libcommons-digester-java-1.8.1.orig/src/examples/api/addressbook/readme.txt0000644000175000017500000000370411226450007026760 0ustar twernertwerner######################################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. ######################################################################### == overview The files in this directory are intended as an example of how to use the Apache Digester's basic functionality via its java interface. Topics covered: * how to create a digester instance * how to parse a file * how to use the "object create" rule to create java objects * how to use the "set properties" rule (basic usage) to map xml attributes to java bean properties. * how to use the "set next" rule to build trees of java objects. * how to use the "call method rule" (basic usage) * how to use the "call parameter rule" to process the text contained in a tag's body * how to use the "call parameter rule" to process the contents of an xml attribute. == compiling and running First rename the build.properties.sample file in the parent directory to build.properties and edit it to suit your environment. Then in this directory: * to compile: ant compile * to run: ant run Alternatively, you can set up your CLASSPATH appropriately, and run the example directly. See the build.properties and build.xml files for details. libcommons-digester-java-1.8.1.orig/src/examples/api/addressbook/build.xml0000644000175000017500000001132711226450007026603 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/examples/api/addressbook/AddressBook.java0000644000175000017500000000241111226450007030017 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.LinkedList; import java.util.Iterator; /** * See Main.java. */ public class AddressBook { LinkedList people = new LinkedList(); public void addPerson(Person p) { people.addLast(p); } public void print() { System.out.println("Address book has " + people.size() + " entries"); for(Iterator i = people.iterator(); i.hasNext(); ) { Person p = (Person) i.next(); p.print(); } } } libcommons-digester-java-1.8.1.orig/src/examples/api/readme.txt0000644000175000017500000000310011226450007024446 0ustar twernertwerner######################################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. ######################################################################### The subdirectories of this directory provide examples of how to use the Apache Digester's java API. With the API approach, java code is used to configure the digester with a set of rules to execute when xml is processed. It is these rules that determine how the input xml is mapped into a tree of java objects. An alternative is to use the "xmlrules" digester extension, which allows the digester rules to be configured via an xml file. This allows the mapping between input xml and java objects to be modified without recompilation of any source code. The examples are graduated in the following order: 1. addressbook 2. catalog 3. dbinsert 4. document-markup libcommons-digester-java-1.8.1.orig/src/examples/api/build.xml0000644000175000017500000000631411226450007024303 0ustar twernertwerner ******************************************************* API Examples Script =================== Provides helpful services to get folks up and running the examples quickly. * Compile - compiles all the examples to the directories in which the their source files reside. * Run - runs each example in turn. Note: These examples will only build and run if the rights jars are in the classpath. The classpath can be set by copying the build.properties.sample file in this directory to build.properties and then setting the properties appropriately. Or by editing the build.properties file (based on the build.properties.sample file in CVS) so that it contains absolute paths. Note: build.xml files are provided in each subdirectory. This provide similar fuctionality for each example individually. Note: The examples are graduated. It is best to look at them in order. Please consult the documentation for more details. ******************************************************* libcommons-digester-java-1.8.1.orig/src/examples/api/build.properties.sample0000644000175000017500000000237611226450007027163 0ustar twernertwerner##################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. #################################################### # # Example build properties # # Copy this to build.properties and then edit the properties to # provide local references. # myjars=/home/me/jakarta-commons-jars commons-beanutils.jar=${myjars}/commons-beanutils.jar commons-collections.jar=${myjars}/commons-collections.jar commons-logging.jar=${myjars}/commons-logging.jar commons-digester.jar=${myjars}/commons-digester.jar libcommons-digester-java-1.8.1.orig/src/examples/api/catalog/0000755000175000017500000000000011226450007024070 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/api/catalog/Item.java0000644000175000017500000000156411226450007025637 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ /** * See Main.java. */ public interface Item { public void print(); } libcommons-digester-java-1.8.1.orig/src/examples/api/catalog/Catalog.java0000644000175000017500000000240311226450007026304 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.LinkedList; import java.util.Iterator; /** * See Main.java. */ public class Catalog { LinkedList items = new LinkedList(); public void addItem(Item item) { items.addLast(item); } public void print() { System.out.println("This catalog has " + items.size() + " items"); for(Iterator i = items.iterator(); i.hasNext(); ) { Item item = (Item) i.next(); item.print(); } } } libcommons-digester-java-1.8.1.orig/src/examples/api/catalog/example.xml0000644000175000017500000000315511226450007026251 0ustar twernertwerner Ant, The Definitive Guide Jesse Tilly & Eric M. Burke Complete build management for Java. Effective Java Joshua Bloch Tips for experienced Java software developers. libcommons-digester-java-1.8.1.orig/src/examples/api/catalog/Main.java0000644000175000017500000002237611226450007025631 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import org.apache.commons.digester.Digester; import org.apache.commons.digester.AbstractObjectCreationFactory; /** * A simple program to demonstrate some of the functionality of the * Commons Digester module. *

* This code will parse the provided "example.xml" file to build a tree * of java objects, then cause those objects to print out their values * to demonstrate that the input file has been processed correctly. The * input file represents a catalog of items in a library. *

* As with all code, there are many ways of achieving the same goal; * the solution here is only one possible implementation. *

* Very verbose comments are included here, as this class is intended * as a tutorial; if you look closely at method "addRules", you will * see that the amount of code required to use the Digester is actually * quite low. *

* Usage: java Main example.xml */ public class Main { /** * Main method : entry point for running this example program. *

* Usage: java CatalogDigester example.xml */ public static void main(String[] args) { if (args.length != 1) { usage(); System.exit(-1); } String filename = args[0]; // Create a Digester instance Digester d = new Digester(); // Add rules to the digester that will be triggered while // parsing occurs. addRules(d); // Process the input file. try { java.io.Reader reader = getInputData(filename); d.parse(reader); } catch(java.io.IOException ioe) { System.out.println("Error reading input file:" + ioe.getMessage()); System.exit(-1); } catch(org.xml.sax.SAXException se) { System.out.println("Error parsing input file:" + se.getMessage()); System.exit(-1); } // Get the first object created by the digester's rules // (the "root" object). Note that this is exactly the same object // returned by the Digester.parse method; either approach works. Catalog catalog = (Catalog) d.getRoot(); // Print out all the contents of the catalog, as loaded from // the input file. catalog.print(); } private static void addRules(Digester d) { //-------------------------------------------------- // when we encounter the root "catalog" tag, create an // instance of the Catalog class. // // Note that this approach is different from the approach taken in // the AddressBook example, where an initial "root" object was // explicitly created and pushed onto the digester stack before // parsing started instead // // Either approach is fine. d.addObjectCreate("catalog", Catalog.class); //-------------------------------------------------- // when we encounter a book tag, we want to create a Book // instance. However the Book class doesn't have a default // constructor (one with no arguments), so we can't use // the ObjectCreateRule. Instead, we use the FactoryCreateRule. BookFactory factory = new BookFactory(); d.addFactoryCreate("catalog/book", factory); // and add the book to the parent catalog object (which is // the next-to-top object on the digester object stack). d.addSetNext("catalog/book", "addItem"); // we want each subtag of book to map the text contents of // the tag into a bean property with the same name as the tag. // eg foo --> setTitle("foo") d.addSetNestedProperties("catalog/book"); //----------------------------------------------- // We are using the "AudioVisual" class to represent both // dvds and videos, so when the "dvd" tag is encountered, // create an AudioVisual object. d.addObjectCreate("catalog/dvd", AudioVisual.class); // add this dvd to the parent catalog object d.addSetNext("catalog/dvd", "addItem"); // We want to map every xml attribute onto a corresponding // property-setter method on the Dvd class instance. However // this doesn't work with the xml attribute "year-made", because // of the internal hyphen. We could use explicit CallMethodRule // rules instead, or use a version of the SetPropertiesRule that // allows us to override any troublesome mappings... // // If there was more than one troublesome mapping, we could // use the method variant that takes arrays of xml-attribute-names // and bean-property-names to override multiple mappings. // // For any attributes not explicitly mapped here, the default // processing is applied, so xml attribute "category" --> setCategory. d.addSetProperties("catalog/dvd", "year-made", "yearMade"); // We also need to tell this AudioVisual object that it is actually // a dvd; we can use the ObjectParamRule to pass a string to any // method. This usage is a little artificial - normally in this // situation there would be separate Dvd and Video classes. // Note also that equivalent behaviour could be implemented by // using factory objects to create & initialise the AudioVisual // objects with their type rather than using ObjectCreateRule. d.addCallMethod("catalog/dvd", "setType", 1); d.addObjectParam("catalog/dvd", 0, "dvd"); // pass literal "dvd" string // Each tag of form " needs to map // to a call to setFoo("bar"). // // This is an alternative to the syntax used for books above (see // method addSetNestedProperties), where the name of the subtag // indicated which property to set. Using this syntax in the xml has // advantages and disadvantages both for the user and the application // developer. It is commonly used with the FactoryCreateRule variant // which allows the target class to be created to be specified in an // xml attribute; this feature of FactoryCreateRule is not demonstrated // in this example, but see the Apache Tomcat configuration files for // an example of this usage. // // Note that despite the name similarity, there is no link // between SetPropertyRule and SetPropertiesRule. d.addSetProperty("catalog/dvd/attr", "id", "value"); //----------------------------------------------- // and here we repeat the dvd rules, but for the video tag. d.addObjectCreate("catalog/video", AudioVisual.class); d.addSetNext("catalog/video", "addItem"); d.addSetProperties("catalog/video", "year-made", "yearMade"); d.addCallMethod("catalog/video", "setType", 1); d.addObjectParam("catalog/video", 0, "video"); d.addSetProperty("catalog/video/attr", "id", "value"); } /* * Reads the specified file into memory, and returns a StringReader * object which reads from that in-memory buffer. *

* This method exists just to demonstrate that the input to the * digester doesn't need to be from a file; for example, xml could * be read from a database or generated dynamically; any old buffer * in memory can be processed by the digester. *

* Clearly, if the data is always coming from a file, then calling * the Digester.parse method that takes a File object would be * more sensible (see AddressBook example). */ private static java.io.Reader getInputData(String filename) throws java.io.IOException { java.io.File srcfile = new java.io.File(filename); java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(1000); byte[] buf = new byte[100]; java.io.FileInputStream fis = new java.io.FileInputStream(srcfile); for(;;) { int nread = fis.read(buf); if (nread == -1) { break; } baos.write(buf, 0, nread); } fis.close(); return new java.io.StringReader( baos.toString() ); } private static void usage() { System.out.println("Usage: java Main example.xml"); } }libcommons-digester-java-1.8.1.orig/src/examples/api/catalog/Book.java0000644000175000017500000000272111226450007025627 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ /** * See Main.java. */ public class Book implements Item { private String isbn; private String title; private String author; private String desc; public Book(String isbn) { this.isbn = isbn; } public void setTitle(String title) { this.title = title; } public void setAuthor(String author) { this.author = author; } public void setDesc(String desc) { this.desc = desc; } public void print() { System.out.println("Book:"); System.out.println(" isbn=" + isbn); System.out.println(" title=" + title); System.out.println(" author=" + author); System.out.println(" desc=" + desc); } } libcommons-digester-java-1.8.1.orig/src/examples/api/catalog/readme.txt0000644000175000017500000000417111226450007026071 0ustar twernertwerner######################################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. ######################################################################### == overview The files in this directory are intended as an example of how to use the Apache Digester's basic functionality via its java interface. Topics covered: * how to read xml from a string (instead of a file) * how to use Digester.getRoot() to retrieve the "root" object created when parsing an input file. * how to use the "factory create" rule to create java objects which do not have default (no-argument) constructors. * how to use the "set properties" rule (advanced usage) to map xml attributes to java bean properties with names different from the xml attribute name. * how to use the SetPropertyRule. * how to use the ObjectParamRule to pass a constant string to a method. If you haven't read the "addressbook" example, it is recommended that you start there first. This example demonstrates more advanced features of the digester. == compiling and running First rename the build.properties.sample file in the parent directory to build.properties and edit it to suit your environment. Then in this directory: * to compile: ant compile * to run: ant run Alternatively, you can set up your CLASSPATH appropriately, and run the example directly. See the build.properties and build.xml files for details. libcommons-digester-java-1.8.1.orig/src/examples/api/catalog/build.xml0000644000175000017500000001131611226450007025713 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/examples/api/catalog/AudioVisual.java0000644000175000017500000000376311226450007027171 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ /** * See Main.java. */ public class AudioVisual implements Item { private int yearMade; private String category; private String name; private String desc; private Integer runtime; private String type; // note: digester can convert a string in the xml file to an int. public void setYearMade(int yearMade) { this.yearMade = yearMade; } public void setCategory(String category) { this.category = category; } public void setName(String name) { this.name = name; } public void setDesc(String desc) { this.desc = desc; } // note: digester can convert a string in the xml file to an Integer public void setRuntime(Integer runtime) { this.runtime = runtime; } public void setType(String type) { this.type = type; } public void print() { System.out.println("AudioVisual:"); System.out.println(" type=" + type); System.out.println(" yearMade=" + yearMade); System.out.println(" category=" + category); System.out.println(" name=" + name); System.out.println(" desc=" + desc); System.out.println(" runtime=" + runtime); } } libcommons-digester-java-1.8.1.orig/src/examples/api/catalog/BookFactory.java0000644000175000017500000000550711226450007027164 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import org.apache.commons.digester.AbstractObjectCreationFactory; /** * The Book class doesn't have a no-argument constructor, so the * standard digester ObjectCreateRule can't be used to create instances * of it. *

* To resolve this issue, the FactoryCreateRule can be used in * conjunction with an appropriate factory class, like this one. * The "createObject" method of the factory is invoked to generate * object instances when required. *

* The factory object can access any xml attributes, plus of course * any values set up within it before digester parsing starts (like * JNDI references, database connections, etc) that it may in the * process of generating an appropriate object. *

* Note that it is not possible for any data to be extracted * from the body or subelements of the xml element that caused the * createObject method on this factory to be invoked. For example: *

 *  [book isdn="12345"]
 * 
* is fine; the isdn value can be accessed during the createObject method. * However, given the xml: *
 * [book]
 *   [isdn]12345[/isdn]
 *   ...
 * 
* it is not possible to access the isdn number until after the * Book instance has been created. *

* Note that even if the class to be created does have a default constructor, * you may wish to use a factory class, in order to initialise the created * object in specific ways, or insert created objects into a central * register, etc. *

* And don't forget, either, that factories may be implemented as * inner classes or anonymous classes if appropriate, reducing the * overhead of using this functionality in many cases. */ public class BookFactory extends AbstractObjectCreationFactory { public Object createObject(org.xml.sax.Attributes attributes) throws Exception { String isbn = attributes.getValue("isbn"); if (isbn == null) { throw new Exception( "Mandatory isbn attribute not present on book tag."); } return new Book(isbn); } } libcommons-digester-java-1.8.1.orig/src/examples/rss/0000755000175000017500000000000011226450007022514 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/rss/LICENSE.txt0000644000175000017500000002613611226450007024347 0ustar twernertwerner 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. libcommons-digester-java-1.8.1.orig/src/examples/rss/readme.txt0000644000175000017500000000277111226450007024521 0ustar twernertwerner######################################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. ######################################################################### This directory contains the example code for parsing RSS (Really Simple Syndication) newsfeeds, which was originally included directly in the commons-digester.jar file, in package "org.apache.commons.digester.rss". The package name has not been changed, so the only impact on applications relying on these classes will be the need to include an additional JAR file (commons-digester-rss.jar) in their classpath. A packaged distribution can be created by using ant: 1 Copy build.properties.sample to build.properties and edit the properties to match those on your local system 2 run ant dist libcommons-digester-java-1.8.1.orig/src/examples/rss/src/0000755000175000017500000000000011126627040023305 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/0000755000175000017500000000000011126627037024234 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/0000755000175000017500000000000011126627037025023 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/0000755000175000017500000000000011126627037026244 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/0000755000175000017500000000000011126627037027717 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/0000755000175000017500000000000011126627037031525 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/0000755000175000017500000000000011226450007032324 5ustar twernertwerner././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/Item.javalibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/Item.j0000644000175000017500000000532711226450007033404 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.rss; import java.io.PrintWriter; import java.io.Serializable; /** *

Implementation object representing an item in the * Rich Site Summary DTD, version 0.91. This class may be subclassed * to further specialize its behavior.

*/ public class Item implements Serializable { // ------------------------------------------------------------- Properties /** * The item description (1-500 characters). */ protected String description = null; public String getDescription() { return (this.description); } public void setDescription(String description) { this.description = description; } /** * The item link (1-500 characters). */ protected String link = null; public String getLink() { return (this.link); } public void setLink(String link) { this.link = link; } /** * The item title (1-100 characters). */ protected String title = null; public String getTitle() { return (this.title); } public void setTitle(String title) { this.title = title; } // -------------------------------------------------------- Package Methods /** * Render this channel as XML conforming to the RSS 0.91 specification, * to the specified writer. * * @param writer The writer to render output to */ void render(PrintWriter writer) { writer.println(" "); writer.print(" "); writer.print(title); writer.println(""); writer.print(" "); writer.print(link); writer.println(""); if (description != null) { writer.print(" "); writer.print(description); writer.println(""); } writer.println(" "); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/Channel.javalibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/Channe0000644000175000017500000003456611226450007033461 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.rss; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.io.Writer; import java.util.ArrayList; /** *

Implementation object representing a channel in the * Rich Site Summary DTD, version 0.91. This class may be subclassed * to further specialize its behavior.

*/ public class Channel implements Serializable { // ----------------------------------------------------- Instance Variables /** * The set of items associated with this Channel. */ protected ArrayList items = new ArrayList(); /** * The set of skip days for this channel. */ protected ArrayList skipDays = new ArrayList(); /** * The set of skip hours for this channel. */ protected ArrayList skipHours = new ArrayList(); // ------------------------------------------------------------- Properties /** * The channel copyright (1-100 characters). */ protected String copyright = null; public String getCopyright() { return (this.copyright); } public void setCopyright(String copyright) { this.copyright = copyright; } /** * The channel description (1-500 characters). */ protected String description = null; public String getDescription() { return (this.description); } public void setDescription(String description) { this.description = description; } /** * The channel description file URL (1-500 characters). */ protected String docs = null; public String getDocs() { return (this.docs); } public void setDocs(String docs) { this.docs = docs; } /** * The image describing this channel. */ protected Image image = null; public Image getImage() { return (this.image); } public void setImage(Image image) { this.image = image; } /** * The channel language (2-5 characters). */ protected String language = null; public String getLanguage() { return (this.language); } public void setLanguage(String language) { this.language = language; } /** * The channel last build date (1-100 characters). */ protected String lastBuildDate = null; public String getLastBuildDate() { return (this.lastBuildDate); } public void setLastBuildDate(String lastBuildDate) { this.lastBuildDate = lastBuildDate; } /** * The channel link (1-500 characters). */ protected String link = null; public String getLink() { return (this.link); } public void setLink(String link) { this.link = link; } /** * The managing editor (1-100 characters). */ protected String managingEditor = null; public String getManagingEditor() { return (this.managingEditor); } public void setManagingEditor(String managingEditor) { this.managingEditor = managingEditor; } /** * The channel publication date (1-100 characters). */ protected String pubDate = null; public String getPubDate() { return (this.pubDate); } public void setPubDate(String pubDate) { this.pubDate = pubDate; } /** * The channel rating (20-500 characters). */ protected String rating = null; public String getRating() { return (this.rating); } public void setRating(String rating) { this.rating = rating; } /** * The text input description for this channel. */ protected TextInput textInput = null; public TextInput getTextInput() { return (this.textInput); } public void setTextInput(TextInput textInput) { this.textInput = textInput; } /** * The channel title (1-100 characters). */ protected String title = null; public String getTitle() { return (this.title); } public void setTitle(String title) { this.title = title; } /** * The RSS specification version number used to create this Channel. */ protected double version = 0.91; public double getVersion() { return (this.version); } public void setVersion(double version) { this.version = version; } /** * The webmaster email address (1-100 characters). */ protected String webMaster = null; public String getWebMaster() { return (this.webMaster); } public void setWebMaster(String webMaster) { this.webMaster = webMaster; } // --------------------------------------------------------- Public Methods /** * Add an additional item. * * @param item The item to be added */ public void addItem(Item item) { synchronized (items) { items.add(item); } } /** * Add an additional skip day name. * * @param skipDay The skip day to be added */ public void addSkipDay(String skipDay) { synchronized (skipDays) { skipDays.add(skipDay); } } /** * Add an additional skip hour name. * * @param skipHour The skip hour to be added */ public void addSkipHour(String skipHour) { synchronized (skipHours) { skipHours.add(skipHour); } } /** * Return the items for this channel. */ public Item[] findItems() { synchronized (items) { Item items[] = new Item[this.items.size()]; return ((Item[]) this.items.toArray(items)); } } /** * Return the items for this channel. */ public Item[] getItems() { return findItems(); } /** * Return the skip days for this channel. */ public String[] findSkipDays() { synchronized (skipDays) { String skipDays[] = new String[this.skipDays.size()]; return ((String[]) this.skipDays.toArray(skipDays)); } } /** * Return the skip hours for this channel. */ public String[] getSkipHours() { return findSkipHours(); } /** * Return the skip hours for this channel. */ public String[] findSkipHours() { synchronized (skipHours) { String skipHours[] = new String[this.skipHours.size()]; return ((String[]) this.skipHours.toArray(skipHours)); } } /** * Return the skip days for this channel. */ public String[] getSkipDays() { return findSkipDays(); } /** * Remove an item for this channel. * * @param item The item to be removed */ public void removeItem(Item item) { synchronized (items) { items.remove(item); } } /** * Remove a skip day for this channel. * * @param skipDay The skip day to be removed */ public void removeSkipDay(String skipDay) { synchronized (skipDays) { skipDays.remove(skipDay); } } /** * Remove a skip hour for this channel. * * @param skipHour The skip hour to be removed */ public void removeSkipHour(String skipHour) { synchronized (skipHours) { skipHours.remove(skipHour); } } /** * Render this channel as XML conforming to the RSS 0.91 specification, * to the specified output stream, with no indication of character * encoding. * * @param stream The output stream to write to */ public void render(OutputStream stream) { try { render(stream, null); } catch (UnsupportedEncodingException e) { ; // Can not happen } } /** * Render this channel as XML conforming to the RSS 0.91 specification, * to the specified output stream, with the specified character encoding. * * @param stream The output stream to write to * @param encoding The character encoding to declare, or null * for no declaration * * @exception UnsupportedEncodingException if the named encoding * is not supported */ public void render(OutputStream stream, String encoding) throws UnsupportedEncodingException { PrintWriter pw = null; if (encoding == null) { pw = new PrintWriter(stream); } else { pw = new PrintWriter(new OutputStreamWriter(stream, encoding)); } render(pw, encoding); pw.flush(); } /** * Render this channel as XML conforming to the RSS 0.91 specification, * to the specified writer, with no indication of character encoding. * * @param writer The writer to render output to */ public void render(Writer writer) { render(writer, null); } /** * Render this channel as XML conforming to the RSS 0.91 specification, * to the specified writer, indicating the specified character encoding. * * @param writer The writer to render output to * @param encoding The character encoding to declare, or null * for no declaration */ public void render(Writer writer, String encoding) { PrintWriter pw = new PrintWriter(writer); render(pw, encoding); pw.flush(); } /** * Render this channel as XML conforming to the RSS 0.91 specification, * to the specified writer, with no indication of character encoding. * * @param writer The writer to render output to */ public void render(PrintWriter writer) { render(writer, null); } /** * Render this channel as XML conforming to the RSS 0.91 specification, * to the specified writer, indicating the specified character encoding. * * @param writer The writer to render output to * @param encoding The character encoding to declare, or null * for no declaration */ public void render(PrintWriter writer, String encoding) { writer.print(""); writer.println(); writer.println(""); writer.println(); writer.println(""); writer.println(); writer.println(" "); writer.println(); writer.print(" "); writer.print(title); writer.println(""); writer.print(" "); writer.print(description); writer.println(""); writer.print(" "); writer.print(link); writer.println(""); writer.print(" "); writer.print(language); writer.println(""); if (rating != null) { writer.print(" "); writer.print(rating); writer.println(""); } if (copyright != null) { writer.print(" "); writer.print(copyright); writer.print(""); } if (pubDate != null) { writer.print(" "); writer.print(pubDate); writer.println(""); } if (lastBuildDate != null) { writer.print(" "); writer.print(lastBuildDate); writer.println(""); } if (docs != null) { writer.print(" "); writer.print(docs); writer.println(""); } if (managingEditor != null) { writer.print(" "); writer.print(managingEditor); writer.println(""); } if (webMaster != null) { writer.print(" "); writer.print(webMaster); writer.println(""); } writer.println(); if (image != null) { image.render(writer); writer.println(); } if (textInput != null) { textInput.render(writer); writer.println(); } String skipDays[] = findSkipDays(); if (skipDays.length > 0) { writer.println(" "); for (int i = 0; i < skipDays.length; i++) { writer.print(" "); writer.print(skipDays[i]); writer.println(""); } writer.println(" "); } String skipHours[] = findSkipHours(); if (skipHours.length > 0) { writer.println(" "); for (int i = 0; i < skipHours.length; i++) { writer.print(" "); writer.print(skipHours[i]); writer.println(""); } writer.println(" "); writer.println(); } Item items[] = findItems(); for (int i = 0; i < items.length; i++) { items[i].render(writer); writer.println(); } writer.println(" "); writer.println(); writer.println(""); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/rss-example.xmllibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/rss-ex0000644000175000017500000000512711226450007033475 0ustar twernertwerner Apache http://www.apache.org The Apache Software Foundation en-US (PICS-1.1 "http://www.rsac.org/ratingsv01.html" 2 gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0)) Apache http://jakarta.apache.org/images/jakarta-logo.gif http://jakarta.apache.org 505 480 The Jakarta project. Open source, serverside java. Commons Attributes 2.1 Released http://jakarta.apache.org/site/news/news-2004-2ndHalf.html#20040815.1 The Apache Commons team is happy to announce the release of Commons Attributes 2.1. This is the first release of the new Commons-Attributes code. Cloudscape Becomes Apache Derby http://jakarta.apache.org/site/news/elsewhere-2004-2ndHalf.html#20040803.1 IBM has submitted a proposal to the Apache DB project for a Java-based package to be called 'Derby'. Commons BeanUtils 1.7 Released http://jakarta.apache.org/site/news/news-2004-2ndHalf.html#20040802.1 Commons JXPath 1.2 Released http://jakarta.apache.org/site/news/news-2004-2ndHalf.html#20040801.2 ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/RSSDigester.javalibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/RSSDig0000644000175000017500000002534211226450007033350 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.rss; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; import org.apache.commons.digester.Digester; import org.apache.commons.logging.LogFactory; import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** *

Implementation of org.apache.commons.digester.Digester * designed to process input streams that conform to the Rich Site * Summary DTD, version 0.91. For more information about this format, * see the My Netscape site.

* *

The default implementation object returned by calling * parse() (an instance of * org.apache.commons.digester.rss.Channel) * knows how to render itself in XML format via the render() * method. See the test main() method below for an * example of using these classes.

*/ public class RSSDigester extends Digester { // ----------------------------------------------------------- Constructors // ----------------------------------------------------- Instance Variables /** * Have we been configured yet? */ protected boolean configured = false; /** * The set of public identifiers, and corresponding resource names, * for the versions of the DTDs that we know about. */ protected static final String registrations[] = { "-//Netscape Communications//DTD RSS 0.9//EN", "/org/apache/commons/digester/rss/rss-0.9.dtd", "-//Netscape Communications//DTD RSS 0.91//EN", "/org/apache/commons/digester/rss/rss-0.91.dtd", }; // ------------------------------------------------------------- Properties /** * The fully qualified class name of the Channel * implementation class. */ protected String channelClass = "org.apache.commons.digester.rss.Channel"; public String getChannelClass() { return (this.channelClass); } public void setChannelClass(String channelClass) { this.channelClass = channelClass; } /** * The fully qualified class name of the Image * implementation class. */ protected String imageClass = "org.apache.commons.digester.rss.Image"; public String getImageClass() { return (this.imageClass); } public void setImageClass(String imageClass) { this.imageClass = imageClass; } /** * The fully qualified class name of the Item * implementation class. */ protected String itemClass = "org.apache.commons.digester.rss.Item"; public String getItemClass() { return (this.itemClass); } public void setItemClass(String itemClass) { this.itemClass = itemClass; } /** * The fully qualified class name of the TextInput * implementation class. */ protected String textInputClass = "org.apache.commons.digester.rss.TextInput"; public String getTextInputClass() { return (this.textInputClass); } public void setTextInputClass(String textInputClass) { this.textInputClass = textInputClass; } // --------------------------------------------------------- Public Methods /** * Parse the content of the specified file using this Digester. Returns * the root element from the object stack (which will be the Channel). * * @param file File containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Object parse(File file) throws IOException, SAXException { configure(); return (super.parse(file)); } /** * Parse the content of the specified input source using this Digester. * Returns the root element from the object stack (which will be the * Channel). * * @param input Input source containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Object parse(InputSource input) throws IOException, SAXException { configure(); return (super.parse(input)); } /** * Parse the content of the specified input stream using this Digester. * Returns the root element from the object stack (which will be * the Channel). * * @param input Input stream containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Object parse(InputStream input) throws IOException, SAXException { configure(); return (super.parse(input)); } /** * Parse the content of the specified URI using this Digester. * Returns the root element from the object stack (which will be * the Channel). * * @param uri URI containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Object parse(String uri) throws IOException, SAXException { configure(); return (super.parse(uri)); } // -------------------------------------------------------- Package Methods // ------------------------------------------------------ Protected Methods /** * Configure the parsing rules that will be used to process RSS input. */ protected void configure() { if (configured) { return; } // Register local copies of the DTDs we understand for (int i = 0; i < registrations.length; i += 2) { URL url = this.getClass().getResource(registrations[i + 1]); if (url != null) { register(registrations[i], url.toString()); } } // FIXME - validate the "version" attribute of the rss element? // Add the rules for the Channel object addObjectCreate("rss/channel", channelClass); addCallMethod("rss/channel/copyright", "setCopyright", 0); addCallMethod("rss/channel/description", "setDescription", 0); addCallMethod("rss/channel/docs", "setDocs", 0); addCallMethod("rss/channel/language", "setLanguage", 0); addCallMethod("rss/channel/lastBuildDate", "setLastBuildDate", 0); addCallMethod("rss/channel/link", "setLink", 0); addCallMethod("rss/channel/managingEditor", "setManagingEditor", 0); addCallMethod("rss/channel/pubDate", "setPubDate", 0); addCallMethod("rss/channel/rating", "setRating", 0); addCallMethod("rss/channel/skipDays/day", "addSkipDay", 0); addCallMethod("rss/channel/skipHours/hour", "addSkipHour", 0); addCallMethod("rss/channel/title", "setTitle", 0); addCallMethod("rss/channel/webMaster", "setWebMaster", 0); // Add the rules for the Image object addObjectCreate("rss/channel/image", imageClass); addSetNext("rss/channel/image", "setImage", "org.apache.commons.digester.rss.Image"); addCallMethod("rss/channel/image/description", "setDescription", 0); addCallMethod("rss/channel/image/height", "setHeight", 0, new Class[]{ Integer.TYPE }); addCallMethod("rss/channel/image/link", "setLink", 0); addCallMethod("rss/channel/image/title", "setTitle", 0); addCallMethod("rss/channel/image/url", "setURL", 0); addCallMethod("rss/channel/image/width", "setWidth", 0, new Class[]{ Integer.TYPE }); // Add the rules for the Item object addObjectCreate("rss/channel/item", itemClass); addSetNext("rss/channel/item", "addItem", "org.apache.commons.digester.rss.Item"); addCallMethod("rss/channel/item/description", "setDescription", 0); addCallMethod("rss/channel/item/link", "setLink", 0); addCallMethod("rss/channel/item/title", "setTitle", 0); // Add the rules for the TextInput object addObjectCreate("rss/channel/textinput", textInputClass); addSetNext("rss/channel/textinput", "setTextInput", "org.apache.commons.digester.rss.TextInput"); addCallMethod("rss/channel/textinput/description", "setDescription", 0); addCallMethod("rss/channel/textinput/link", "setLink", 0); addCallMethod("rss/channel/textinput/name", "setName", 0); addCallMethod("rss/channel/textinput/title", "setTitle", 0); // Mark this digester as having been configured configured = true; } // ------------------------------------------------------ Test Main Program /** * Test main program that parses the channel description included in this * package as a static resource. * * @param args The command line arguments (ignored) */ public static void main(String args[]) { try { System.out.println("RSSDigester Test Program"); System.out.println("Opening input stream ..."); InputStream is = RSSDigester.class.getResourceAsStream ("/org/apache/commons/digester/rss/rss-example.xml"); System.out.println("Creating new digester ..."); RSSDigester digester = new RSSDigester(); if ((args.length > 0) && (args[0].equals("-debug"))) { digester.setLogger(LogFactory.getLog("RSSDigester")); } System.out.println("Parsing input stream ..."); Channel channel = (Channel) digester.parse(is); System.out.println("Closing input stream ..."); is.close(); System.out.println("Dumping channel info ..."); channel.render(System.out); } catch (Exception e) { System.out.println("-->Exception"); e.printStackTrace(System.out); } } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/package.htmllibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/packag0000644000175000017500000000206411226450007033477 0ustar twernertwerner Package Documentation for org.apache.commons.digester.rss Package

Example usage of Digester to parse XML documents compatible with the Rich Site Summary format used by many newsfeeds.

././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/Image.javalibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/Image.0000644000175000017500000000740711226450007033357 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.rss; import java.io.PrintWriter; import java.io.Serializable; /** *

Implementation object representing an image in the * Rich Site Summary DTD, version 0.91. This class may be subclassed * to further specialize its behavior.

*/ public class Image implements Serializable { // ------------------------------------------------------------- Properties /** * The image description (1-100 characters). */ protected String description = null; public String getDescription() { return (this.description); } public void setDescription(String description) { this.description = description; } /** * The image height in pixels (1-400). */ protected int height = 31; public int getHeight() { return (this.height); } public void setHeight(int height) { this.height = height; } /** * The image link (1-500 characters). */ protected String link = null; public String getLink() { return (this.link); } public void setLink(String link) { this.link = link; } /** * The image alternate text (1-100 characters). */ protected String title = null; public String getTitle() { return (this.title); } public void setTitle(String title) { this.title = title; } /** * The image location URL (1-500 characters). */ protected String url = null; public String getURL() { return (this.url); } public void setURL(String url) { this.url = url; } /** * The image width in pixels (1-400). */ protected int width = 31; public int getWidth() { return (this.width); } public void setWidth(int width) { this.width = width; } // -------------------------------------------------------- Package Methods /** * Render this channel as XML conforming to the RSS 0.91 specification, * to the specified writer. * * @param writer The writer to render output to */ void render(PrintWriter writer) { writer.println(" "); writer.print(" "); writer.print(title); writer.println(""); writer.print(" "); writer.print(url); writer.println(""); if (link != null) { writer.print(" "); writer.print(link); writer.println(""); } writer.print(" "); writer.print(width); writer.println(""); writer.print(" "); writer.print(height); writer.println(""); if (description != null) { writer.print(" "); writer.print(description); writer.println(""); } writer.println(" "); } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/TextInput.javalibcommons-digester-java-1.8.1.orig/src/examples/rss/src/java/org/apache/commons/digester/rss/TextIn0000644000175000017500000000605111226450007033464 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.rss; import java.io.PrintWriter; import java.io.Serializable; /** *

Implementation object representing a textinput in the * Rich Site Summary DTD, version 0.91. This class may be subclassed * to further specialize its behavior.

*/ public class TextInput implements Serializable { // ------------------------------------------------------------- Properties /** * The text input description (1-100 characters). */ protected String description = null; public String getDescription() { return (this.description); } public void setDescription(String description) { this.description = description; } /** * The text input link (1-500 characters). */ protected String link = null; public String getLink() { return (this.link); } public void setLink(String link) { this.link = link; } /** * The text input field name (1-100 characters). */ protected String name = null; public String getName() { return (this.name); } public void setName(String name) { this.name = name; } /** * The text input submit button label (1-100 characters). */ protected String title = null; public String getTitle() { return (this.title); } public void setTitle(String title) { this.title = title; } // -------------------------------------------------------- Package Methods /** * Render this channel as XML conforming to the RSS 0.91 specification, * to the specified writer. * * @param writer The writer to render output to */ void render(PrintWriter writer) { writer.println(" "); writer.print(" "); writer.print(title); writer.println(""); writer.print(" "); writer.print(description); writer.println(""); writer.print(" "); writer.print(name); writer.println(""); writer.print(" "); writer.print(link); writer.println(""); writer.println(" "); } } libcommons-digester-java-1.8.1.orig/src/examples/rss/src/conf/0000755000175000017500000000000011226450007024230 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/rss/src/conf/MANIFEST.MF0000644000175000017500000000051311226450007025661 0ustar twernertwernerExtension-Name: org.apache.commons.digester.rss Specification-Title: "Jakarta Commons Digester RSS Example" Specification-Vendor: "Apache Software Foundation" Specification-Version: "1.8.1" Implementation-Title: "org.apache.commons.digester.rss" Implementation-Vendor: "Apache Software Foundation" Implementation-Version: "1.8.1" libcommons-digester-java-1.8.1.orig/src/examples/rss/build.xml0000644000175000017500000002535311226450007024345 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/examples/rss/build.properties.sample0000644000175000017500000000237611226450007027221 0ustar twernertwerner##################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. #################################################### # # Example build properties # # Copy this to build.properties and then edit the properties to # provide local references. # myjars=/home/me/jakarta-commons-jars commons-beanutils.jar=${myjars}/commons-beanutils.jar commons-collections.jar=${myjars}/commons-collections.jar commons-logging.jar=${myjars}/commons-logging.jar commons-digester.jar=${myjars}/commons-digester.jar libcommons-digester-java-1.8.1.orig/src/examples/readme.txt0000644000175000017500000000055711226450007023712 0ustar twernertwernerThe subdirectories of this directory divide the examples into topics. The examples in API deal with the main Digester API. The xmlrules directory deals with the xmlrules extension which allows the digester rules to be configured via an xml file. This allows the mapping between input xml and java objects to be modified without recompilation of any source code. libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/0000755000175000017500000000000011226450007023560 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/0000755000175000017500000000000011226450007026060 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/xmlrules.xml0000644000175000017500000000333511226450007030461 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/example.xml0000644000175000017500000000331111226450007030233 0ustar twernertwerner Gonzo gonzo@muppets.com
home 123 Maine Ave. Las Vegas NV 01234 USA
business 234 Maple Dr. Los Angeles CA 98765 USA
Kermit kermit@muppets.com kermie@acme.com
business 987 Brown Rd Las Cruces NM 75321 USA
libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/Main.java0000644000175000017500000000765111226450007027620 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import org.apache.commons.digester.Digester; import org.apache.commons.digester.xmlrules.DigesterLoader; import org.xml.sax.InputSource; import java.net.URL; /** * A simple program to demonstrate the basic functionality of the * Commons Digester module with the xmlrules extension. *

* This code will parse the provided "example.xml" file to build a tree * of java objects, then cause those objects to print out their values * to demonstrate that the input file has been processed correctly. *

* Unlike the "addressbook" example in the "api" section, this implementation * has no parsing rules hard-wired into the code in this class. Instead, the * parsing rules are loaded from an external file at runtime. This allows * the parsing rules to be modified without compiling the code, and * potentially makes it somewhat easier to review the parsing rules. *

* Note, however, that there is tyically quite a tight coupling between * the parsing rules and the purpose of the application which means * that it may not be all that common for parsing rules to be altered * without the application code also being altered, so only in some cases * will this prove of benefit. As with all software, it must be determined * whether this feature provides a true benefit in the context of the * application it is being applied to. *

* Usage: java Main xmlrules.xml example.xml */ public class Main { /** * Main method : entry point for running this example program. *

* Usage: java Example example.xml */ public static void main(String[] args) throws Exception { if (args.length != 2) { usage(); System.exit(-1); } String rulesfileName = args[0]; String datafileName = args[1]; // Create a Digester instance which has been initialised with // rules loaded from the specified file. URL rulesURL = ClassLoader.getSystemResource(rulesfileName); if (rulesURL == null) { System.out.println("Unable to find rules file."); System.exit(-1); } Digester d = DigesterLoader.createDigester(rulesURL); // Prime the digester stack with an object for rules to // operate on. Note that it is quite common for "this" // to be the object pushed. AddressBook book = new AddressBook(); d.push(book); // Process the input file. try { java.io.File srcfile = new java.io.File(datafileName); d.parse(srcfile); } catch(java.io.IOException ioe) { System.out.println("Error reading input file:" + ioe.getMessage()); System.exit(-1); } catch(org.xml.sax.SAXException se) { System.out.println("Error parsing input file:" + se.getMessage()); System.exit(-1); } // Print out all the contents of the address book, as loaded from // the input file. book.print(); } private static void usage() { System.out.println("Usage: java Main xmlrules.xml example.xml"); } }libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/Address.java0000644000175000017500000000725211226450007030316 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.HashMap; import java.util.Iterator; /** * See Main.java. */ public class Address { private String type; private String street; private String city; private String state; private String zip; private String country; public String toString() { StringBuffer sb = new StringBuffer(); sb.append( " address (type "+ type + ")\n"); sb.append( " " + street + "\n"); sb.append( " " + city + " " + state + " " + zip + "\n"); sb.append( " " + country + "\n"); return sb.toString(); } public void print(java.io.PrintStream out, int indentAmount) { StringBuffer indentStr = new StringBuffer(indentAmount); for(; indentAmount > 0; --indentAmount) { indentStr.append(' '); } out.print(indentStr); out.print("address type: "); out.println(type); out.print(indentStr); out.println(" " + street); out.print(indentStr); out.println(" " + city + " " + state + " " + zip); out.print(indentStr); out.println(" " + country); } /** * Returns the value of street. */ public String getStreet() { return street; } /** * Sets the value of street. * @param street The value to assign to street. */ public void setStreet(String street) { this.street = street; } /** * Returns the value of city. */ public String getCity() { return city; } /** * Sets the value of city. * @param city The value to assign to city. */ public void setCity(String city) { this.city = city; } /** * Returns the value of state. */ public String getState() { return state; } /** * Sets the value of state. * @param state The value to assign to state. */ public void setState(String state) { this.state = state; } /** * Returns the value of zip. */ public String getZip() { return zip; } /** * Sets the value of zip. * @param zip The value to assign to zip. */ public void setZip(String zip) { this.zip = zip; } /** * Returns the value of country. */ public String getCountry() { return country; } /** * Sets the value of country. * @param country The value to assign to country. */ public void setCountry(String country) { this.country = country; } /** * Returns the value of type. */ public String getType() { return type; } /** * Sets the value of type. * @param type The value to assign to type. */ public void setType(String type) { this.type = type; } } libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/Person.java0000644000175000017500000000432311226450007030173 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; /** * See Main.java. */ public class Person { private int id; private String category; private String name; private HashMap emails = new HashMap(); private List addresses = new ArrayList(); /** * A unique id for this person. Note that the Digester automatically * converts the id to an integer. */ public void setId(int id) { this.id = id; } public void setCategory(String category) { this.category = category; } public void setName(String name) { this.name = name; } /** we assume only one email of each type... */ public void addEmail(String type, String address) { emails.put(type, address); } public void addAddress( Address addr ) { addresses.add( addr ); } public void print() { System.out.println("Person #" + id); System.out.println(" category=" + category); System.out.println(" name=" + name); for(Iterator i = emails.keySet().iterator(); i.hasNext(); ) { String type = (String) i.next(); String address = (String) emails.get(type); System.out.println(" email (type " + type + ") : " + address); } for(Iterator i = addresses.iterator(); i.hasNext(); ) { Address addr = (Address) i.next(); addr.print(System.out, 2); } } } libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/readme.txt0000644000175000017500000000415611226450007030064 0ustar twernertwerner######################################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. ######################################################################### == overview The files in this directory are intended as an example of how to use the Apache Digester's basic functionality via its xmlrules interface. Topics covered: * how to create a digester instance initialised with rules specified in an external file. * how to parse a file * how to use the "object create" rule to create java objects * how to use the "set properties" rule (basic usage) to map xml attributes to java bean properties. * how to use the "set nested properties" rule (basic usage) to map nested elements to java bean properties. * how to use the "set next" rule to build trees of java objects. * how to use the "call method rule" (basic usage) * how to use the "call parameter rule" to process the text contained in a tag's body * how to use the "call parameter rule" to process the contents of an xml attribute. == compiling and running First rename the build.properties.sample file in the parent directory to build.properties and edit it to suit your environment. Then in this directory: * to compile: ant compile * to run: ant run Alternatively, you can set up your CLASSPATH appropriately, and run the example directly. See the build.properties and build.xml files for details. libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/build.xml0000644000175000017500000001136711226450007027711 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/build.properties.sample0000644000175000017500000000237611226450007032565 0ustar twernertwerner##################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. #################################################### # # Example build properties # # Copy this to build.properties and then edit the properties to # provide local references. # myjars=/home/me/jakarta-commons-jars commons-beanutils.jar=${myjars}/commons-beanutils.jar commons-collections.jar=${myjars}/commons-collections.jar commons-logging.jar=${myjars}/commons-logging.jar commons-digester.jar=${myjars}/commons-digester.jar libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/addressbook/AddressBook.java0000644000175000017500000000241111226450007031121 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.LinkedList; import java.util.Iterator; /** * See Main.java. */ public class AddressBook { LinkedList people = new LinkedList(); public void addPerson(Person p) { people.addLast(p); } public void print() { System.out.println("Address book has " + people.size() + " entries"); for(Iterator i = people.iterator(); i.hasNext(); ) { Person p = (Person) i.next(); p.print(); } } } libcommons-digester-java-1.8.1.orig/src/examples/xmlrules/readme.txt0000644000175000017500000000222011226450007025552 0ustar twernertwerner######################################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. ######################################################################### This directory deals with the xmlrules extension which allows the digester rules to be configured via an xml file. This allows the mapping between input xml and java objects to be modified without recompilation of any source code. libcommons-digester-java-1.8.1.orig/src/examples/plugins/0000755000175000017500000000000011126627037023376 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/0000755000175000017500000000000011226450007025173 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/CompoundTransform.java0000644000175000017500000000366111226450007031524 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.LinkedList; import java.util.Iterator; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.PluginCreateRule; /** * An implementation of the Transform interface which is configured with * a sequence of "subtransforms", and applies them one by one to the input * data. *

* This demonstrates that a plugged-in class can itself define plugin-points * for user-defined classes if it wishes. */ public class CompoundTransform implements Transform { private LinkedList transforms = new LinkedList(); public void addTransform(Transform transform) { transforms.add(transform); } public String transform(String s) { for(Iterator i = transforms.iterator(); i.hasNext(); ) { Transform t = (Transform) i.next(); s = t.transform(s); } return s; } public static void addRules(Digester d, String patternPrefix) { PluginCreateRule pcr = new PluginCreateRule(Transform.class); d.addRule(patternPrefix+"/subtransform", pcr); d.addSetNext(patternPrefix+"/subtransform", "addTransform"); } } libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/Pipeline.java0000644000175000017500000001030011226450007027575 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.PluginRules; import org.apache.commons.digester.plugins.PluginCreateRule; import java.io.*; /** * This is the "main" class for this example. *

* It can be run via java Pipeline config-file-name. *

* The specified config file is parsed using the Apache Commons Digester. * This config file specifies an input file to be read, a number of * user-defined transform classes to be instantiated and configured from * the config file, and an output file. *

* The contents of the input file is then passed to the transform objects, * and the output written to the output file. *

* Why not try writing your own transform classes, and plugging them in. * Note that they can configure themselves from the main config file in * any manner the Digester supports, without changing a line of this * application. */ public class Pipeline { private String source; private String dest; private Transform transformer; public static void main(String[] args) { if (args.length != 1) { System.err.println("usage: pipeline config-file"); System.exit(-1); } String configFile = args[0]; Digester digester = new Digester(); PluginRules rc = new PluginRules(); digester.setRules(rc); digester.addObjectCreate("pipeline", Pipeline.class); digester.addCallMethod("pipeline/source", "setSource", 1); digester.addCallParam("pipeline/source", 0, "file"); PluginCreateRule pcr = new PluginCreateRule(Transform.class); digester.addRule("pipeline/transform", pcr); digester.addSetNext("pipeline/transform", "setTransform"); digester.addCallMethod("pipeline/destination", "setDest", 1); digester.addCallParam("pipeline/destination", 0, "file"); Pipeline pipeline = null; try { pipeline = (Pipeline) digester.parse(configFile); } catch(Exception e) { System.err.println("oops exception occurred during parse."); e.printStackTrace(); System.exit(-1); } try { pipeline.execute(); } catch (Exception e) { System.err.println("oops exception occurred during pipeline execution."); e.printStackTrace(); System.exit(-1); } } public void setSource(String source) { this.source = source; } public void setDest(String dest) { this.dest = dest; } public void setTransform(Transform transformer) { this.transformer = transformer; } private void execute() throws IOException { FileReader inRaw = new FileReader(source); FileWriter out = new FileWriter(dest); BufferedReader in = new BufferedReader(inRaw); while(true) { String inStr = in.readLine(); if (inStr==null) break; String outStr = transformer.transform(inStr); out.write(outStr); out.write('\n'); } inRaw.close(); out.close(); System.out.println( "Contents of file " + source + " have been transformed, and" + " written to file " + dest + "."); } } libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/SubstituteTransform.java0000644000175000017500000000407711226450007032115 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import org.apache.commons.digester.Digester; /** * An implementation of the Transform interface which replaces all occurrences * of a specified string with a different string. *

* Because this class wishes to configure instances via nested "from" and * "to" tags, it needs to define an addRules method to add rules to the * Digester dynamically. Note that there are different ways of defining the * rules though; for example they can be defined in a separate * SubstituteTransformRuleInfo class. */ public class SubstituteTransform implements Transform { private String from; private String to; public void setFrom(String from) { this.from = from; } public void setTo(String to) { this.to = to; } public String transform(String s) { StringBuffer buf = new StringBuffer(s); while (true) { int idx = buf.indexOf(from); if (idx == -1) break; StringBuffer buf2 = buf.replace(idx, idx+from.length(), to); } return buf.toString(); } public static void addRules(Digester d, String patternPrefix) { d.addCallMethod(patternPrefix+"/from", "setFrom", 0); d.addCallMethod(patternPrefix+"/to", "setTo", 0); } } libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/input.txt0000644000175000017500000000053711226450007027100 0ustar twernertwernerThis is a test input file for the pipeline demo. It has multiple lines of text, which are transformed one-by-one using plugin classes. HERE IS SOME ALL-UPPERCASE TEXT and here some lowercase text which demonstrates the Case Transform plugin. Here are some lines to demonstrate the substitution plugin: changeme 1 and changeme2 and changeme again. libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/substitute.xml0000644000175000017500000000205211226450007030127 0ustar twernertwerner changeme changed libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/uppercase.xml0000644000175000017500000000175511226450007027714 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/readme.txt0000644000175000017500000000332311226450007027172 0ustar twernertwerner######################################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. ######################################################################### == overview The files in this directory are intended as an example of how to use the Apache Digester's "plugins" functionality. Topics covered: * how to declare "plugin points" using PluginCreateRule. * how to write plugin classes. If you're just starting with Digester, try the "api" examples first. This example demonstrates more advanced features of the digester. == compiling and running First rename the build.properties.sample file in the parent directory to build.properties and edit it to suit your environment. Then in this directory: * to compile: ant compile * to run the examples: ant run-uppercase ant run-substitute ant run-compound Alternatively, you can set up your CLASSPATH appropriately, and run the example directly. See the build.properties and build.xml files for details. libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/build.xml0000644000175000017500000001240211226450007027013 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/build.properties.sample0000644000175000017500000000237611226450007031700 0ustar twernertwerner##################################################### # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. #################################################### # # Example build properties # # Copy this to build.properties and then edit the properties to # provide local references. # myjars=/home/me/jakarta-commons-jars commons-beanutils.jar=${myjars}/commons-beanutils.jar commons-collections.jar=${myjars}/commons-collections.jar commons-logging.jar=${myjars}/commons-logging.jar commons-digester.jar=${myjars}/commons-digester.jar libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/CaseTransform.java0000644000175000017500000000307411226450007030611 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ /** * An implementation of the Transform interface which converts all * input text to either upper or lower case. *

* Note that because it doesn't use any nested tags for configuration, * just xml attributes which map 1:1 onto bean property-setter methods, * there is no need to define any custom addRules method to use this * as a Digester plugin class. */ public class CaseTransform implements Transform { private boolean toLower = true; public void setCase(String caseType) { if (caseType.equalsIgnoreCase("upper")) toLower = false; else toLower = true; } public String transform(String s) { if (toLower) return s.toLowerCase(); else return s.toUpperCase(); } } libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/compound.xml0000644000175000017500000000222011226450007027535 0ustar twernertwerner changeme transformed libcommons-digester-java-1.8.1.orig/src/examples/plugins/pipeline/Transform.java0000644000175000017500000000177411226450007030022 0ustar twernertwerner/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ /** * An interface that any user class must implement if it wishes to be * plugged in at the "transform" tag of a pipeline configuration file. */ public interface Transform { String transform(String s); } libcommons-digester-java-1.8.1.orig/src/java/0000755000175000017500000000000011226450007021010 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/java/overview.html0000644000175000017500000000241111226450007023542 0ustar twernertwerner Overview Documentation for COMMONS-DIGESTER The Digester component of the Apache Commons subproject supports rules-based processing of arbitrary XML documents.

See the Package Description for the org.apache.commons.digester package for more information.

libcommons-digester-java-1.8.1.orig/src/java/org/0000755000175000017500000000000011126627034021604 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/java/org/apache/0000755000175000017500000000000011126627034023025 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/0000755000175000017500000000000011126627034024500 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/0000755000175000017500000000000011226450007026301 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/SetTopRule.java0000644000175000017500000001633411226450007031221 0ustar twernertwerner/* $Id: SetTopRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.apache.commons.beanutils.MethodUtils; /** *

Rule implementation that calls a "set parent" method on the top (child) * object, passing the (top-1) (parent) object as an argument.

* *

This rule now supports more flexible method matching by default. * It is possible that this may break (some) code * written against release 1.1.1 or earlier. * See {@link #isExactMatch()} for more details.

*/ public class SetTopRule extends Rule { // ----------------------------------------------------------- Constructors /** * Construct a "set parent" rule with the specified method name. The * "set parent" method's argument type is assumed to be the class of the * parent object. * * @param digester The associated Digester * @param methodName Method name of the "set parent" method to call * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #SetTopRule(String methodName)} instead. */ public SetTopRule(Digester digester, String methodName) { this(methodName); } /** * Construct a "set parent" rule with the specified method name. * * @param digester The associated Digester * @param methodName Method name of the "set parent" method to call * @param paramType Java class of the "set parent" method's argument * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #SetTopRule(String methodName, String paramType)} instead. */ public SetTopRule(Digester digester, String methodName, String paramType) { this(methodName, paramType); } /** * Construct a "set parent" rule with the specified method name. The * "set parent" method's argument type is assumed to be the class of the * parent object. * * @param methodName Method name of the "set parent" method to call */ public SetTopRule(String methodName) { this(methodName, null); } /** * Construct a "set parent" rule with the specified method name. * * @param methodName Method name of the "set parent" method to call * @param paramType Java class of the "set parent" method's argument * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) */ public SetTopRule(String methodName, String paramType) { this.methodName = methodName; this.paramType = paramType; } // ----------------------------------------------------- Instance Variables /** * The method name to call on the child object. */ protected String methodName = null; /** * The Java class name of the parameter type expected by the method. */ protected String paramType = null; /** * Should we use exact matching. Default is no. */ protected boolean useExactMatch = false; // --------------------------------------------------------- Public Methods /** *

Is exact matching being used.

* *

This rule uses org.apache.commons.beanutils.MethodUtils * to introspect the relevent objects so that the right method can be called. * Originally, MethodUtils.invokeExactMethod was used. * This matches methods very strictly * and so may not find a matching method when one exists. * This is still the behaviour when exact matching is enabled.

* *

When exact matching is disabled, MethodUtils.invokeMethod is used. * This method finds more methods but is less precise when there are several methods * with correct signatures. * So, if you want to choose an exact signature you might need to enable this property.

* *

The default setting is to disable exact matches.

* * @return true iff exact matching is enabled * @since Digester Release 1.1.1 */ public boolean isExactMatch() { return useExactMatch; } /** *

Set whether exact matching is enabled.

* *

See {@link #isExactMatch()}.

* * @param useExactMatch should this rule use exact method matching * @since Digester Release 1.1.1 */ public void setExactMatch(boolean useExactMatch) { this.useExactMatch = useExactMatch; } /** * Process the end of this element. */ public void end() throws Exception { // Identify the objects to be used Object child = digester.peek(0); Object parent = digester.peek(1); if (digester.log.isDebugEnabled()) { if (child == null) { digester.log.debug("[SetTopRule]{" + digester.match + "} Call [NULL CHILD]." + methodName + "(" + parent + ")"); } else { digester.log.debug("[SetTopRule]{" + digester.match + "} Call " + child.getClass().getName() + "." + methodName + "(" + parent + ")"); } } // Call the specified method Class paramTypes[] = new Class[1]; if (paramType != null) { paramTypes[0] = digester.getClassLoader().loadClass(paramType); } else { paramTypes[0] = parent.getClass(); } if (useExactMatch) { MethodUtils.invokeExactMethod(child, methodName, new Object[]{ parent }, paramTypes); } else { MethodUtils.invokeMethod(child, methodName, new Object[]{ parent }, paramTypes); } } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("SetTopRule["); sb.append("methodName="); sb.append(methodName); sb.append(", paramType="); sb.append(paramType); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/CallParamRule.java0000644000175000017500000002122411226450007031631 0ustar twernertwerner/* $Id: CallParamRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; import org.apache.commons.collections.ArrayStack; /** *

Rule implementation that saves a parameter for use by a surrounding * CallMethodRule.

* *

This parameter may be: *

    *
  • from an attribute of the current element * See {@link #CallParamRule(int paramIndex, String attributeName)} *
  • from current the element body * See {@link #CallParamRule(int paramIndex)} *
  • from the top object on the stack. * See {@link #CallParamRule(int paramIndex, boolean fromStack)} *
  • the current path being processed (separate Rule). * See {@link PathCallParamRule} *
*

*/ public class CallParamRule extends Rule { // ----------------------------------------------------------- Constructors /** * Construct a "call parameter" rule that will save the body text of this * element as the parameter value. * *

Note that if the element is empty the an empty string is * passed to the target method, not null. And if automatic type conversion * is being applied (ie if the target function takes something other than * a string as a parameter) then the conversion will fail if the converter * class does not accept an empty string as valid input.

* * @param digester The associated Digester * @param paramIndex The zero-relative parameter number * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #CallParamRule(int paramIndex)} instead. */ public CallParamRule(Digester digester, int paramIndex) { this(paramIndex); } /** * Construct a "call parameter" rule that will save the value of the * specified attribute as the parameter value. * * @param digester The associated Digester * @param paramIndex The zero-relative parameter number * @param attributeName The name of the attribute to save * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #CallParamRule(int paramIndex, String attributeName)} instead. */ public CallParamRule(Digester digester, int paramIndex, String attributeName) { this(paramIndex, attributeName); } /** * Construct a "call parameter" rule that will save the body text of this * element as the parameter value. * *

Note that if the element is empty the an empty string is * passed to the target method, not null. And if automatic type conversion * is being applied (ie if the target function takes something other than * a string as a parameter) then the conversion will fail if the converter * class does not accept an empty string as valid input.

* * @param paramIndex The zero-relative parameter number */ public CallParamRule(int paramIndex) { this(paramIndex, null); } /** * Construct a "call parameter" rule that will save the value of the * specified attribute as the parameter value. * * @param paramIndex The zero-relative parameter number * @param attributeName The name of the attribute to save */ public CallParamRule(int paramIndex, String attributeName) { this.paramIndex = paramIndex; this.attributeName = attributeName; } /** * Construct a "call parameter" rule. * * @param paramIndex The zero-relative parameter number * @param fromStack should this parameter be taken from the top of the stack? */ public CallParamRule(int paramIndex, boolean fromStack) { this.paramIndex = paramIndex; this.fromStack = fromStack; } /** * Constructs a "call parameter" rule which sets a parameter from the stack. * If the stack contains too few objects, then the parameter will be set to null. * * @param paramIndex The zero-relative parameter number * @param stackIndex the index of the object which will be passed as a parameter. * The zeroth object is the top of the stack, 1 is the next object down and so on. */ public CallParamRule(int paramIndex, int stackIndex) { this.paramIndex = paramIndex; this.fromStack = true; this.stackIndex = stackIndex; } // ----------------------------------------------------- Instance Variables /** * The attribute from which to save the parameter value */ protected String attributeName = null; /** * The zero-relative index of the parameter we are saving. */ protected int paramIndex = 0; /** * Is the parameter to be set from the stack? */ protected boolean fromStack = false; /** * The position of the object from the top of the stack */ protected int stackIndex = 0; /** * Stack is used to allow nested body text to be processed. * Lazy creation. */ protected ArrayStack bodyTextStack; // --------------------------------------------------------- Public Methods /** * Process the start of this element. * * @param attributes The attribute list for this element */ public void begin(Attributes attributes) throws Exception { Object param = null; if (attributeName != null) { param = attributes.getValue(attributeName); } else if(fromStack) { param = digester.peek(stackIndex); if (digester.log.isDebugEnabled()) { StringBuffer sb = new StringBuffer("[CallParamRule]{"); sb.append(digester.match); sb.append("} Save from stack; from stack?").append(fromStack); sb.append("; object=").append(param); digester.log.debug(sb.toString()); } } // Have to save the param object to the param stack frame here. // Can't wait until end(). Otherwise, the object will be lost. // We can't save the object as instance variables, as // the instance variables will be overwritten // if this CallParamRule is reused in subsequent nesting. if(param != null) { Object parameters[] = (Object[]) digester.peekParams(); parameters[paramIndex] = param; } } /** * Process the body text of this element. * * @param bodyText The body text of this element */ public void body(String bodyText) throws Exception { if (attributeName == null && !fromStack) { // We must wait to set the parameter until end // so that we can make sure that the right set of parameters // is at the top of the stack if (bodyTextStack == null) { bodyTextStack = new ArrayStack(); } bodyTextStack.push(bodyText.trim()); } } /** * Process any body texts now. */ public void end(String namespace, String name) { if (bodyTextStack != null && !bodyTextStack.empty()) { // what we do now is push one parameter onto the top set of parameters Object parameters[] = (Object[]) digester.peekParams(); parameters[paramIndex] = bodyTextStack.pop(); } } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("CallParamRule["); sb.append("paramIndex="); sb.append(paramIndex); sb.append(", attributeName="); sb.append(attributeName); sb.append(", from stack="); sb.append(fromStack); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/StackAction.java0000644000175000017500000000642711226450007031360 0ustar twernertwerner/* $Id: StackAction.java 476205 2006-11-17 16:43:10Z dennisl $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * An interface that can be implemented in order to get notifications of * objects being pushed onto a digester stack or popped from one. *

* Because objects are pushed onto the main object stack when a rule * has created a new object, this gives the ability to intercept such * operations and perform modifications on created objects. *

* One use expected for this interface is to store information about the xml * line that a particular object was created from. An implementation of this * interface can detect whenever an object is pushed onto the digester object * stack, call Digester.getDocumentLocator() to get the location within the * current xml file, and store this either on the object on the stack (if it * supports some user-specific interface for this purpose), or build a map of * (object->locationinfo) separately. *

* It is recommended that objects implementing this interface provide * a method to set a "next" action, and invoke it from the callback * methods. This allows multiple actions to be "chained" together. *

* See also Digester.setStackAction. * * @since 1.8 */ public interface StackAction { /** * Invoked just before an object is to be pushed onto a digester stack. * * @param d is the digester instance. * * @param stackName is the name of the stack onto which the object * has been pushed. Null is passed to indicate the default stack. * * @param o is the object that has just been pushed. Calling peek on the * specified stack will return the same object. * * @return the object to be pushed. Normally, parameter o is returned * but this method could return an alternate object to be pushed * instead (eg a proxy for the provided object). */ public Object onPush(Digester d, String stackName, Object o); /** * Invoked just after an object has been popped from a digester stack. * * @param d is the digester instance. * * @param stackName is the name of the stack from which the object * has been popped. Null is passed to indicate the default stack. * * @param o is the object that has just been popped. * * @return the object to be returned to the called. Normally, parameter * o is returned but this method could return an alternate object. */ public Object onPop(Digester d, String stackName, Object o); } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/0000755000175000017500000000000011226450007031055 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/package.html0000644000175000017500000000433611226450007033344 0ustar twernertwerner Package Documentation for org.apache.commons.digester.substitution Package Provides for manipulation of xml attributes and element body text before the data is processed by any Rule objects.

The class org.apache.commons.digester.Substitutor defines an abstract interface for mechanisms which manipulate xml attributes and body text. The Digester method setSubstitutor can be used to define a concrete substitutor that will be applied to the data before it is passed to the matching rules.

This package provides some useful concrete implementations of the abstract Substitutor class. In particular, it provides an implementation that allows the application to define "variables" which the input data can reference using a syntax such as "${user.name}".

Here's an example of setting up the VariableSubstitutor:

  // set up the variables the input xml can reference
  Map vars = new HashMap();
  vars.put("user.name", "me");
  vars.put("os", "Linux");
  
  // map ${varname} to the entries in the var map
  MultiVariableExpander expander = new MultiVariableExpander();
  expander.addSource("$", vars);

  // allow expansion in both xml attributes and element text
  Substitutor substitutor = new VariableSubstitutor(expander);

  Digester digester = new Digester();
  digester.setSubstitutor(substitutor);
././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/VariableAttributes.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/VariableAttrib0000644000175000017500000001021511226450007033672 0ustar twernertwerner/* $Id: VariableAttributes.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.substitution; import org.xml.sax.Attributes; import java.util.ArrayList; /** *

Wrapper for an org.xml.sax.Attributes object which expands any * "variables" referenced in the attribute value via ${foo} or similar. * This is only done when something actually asks for the attribute value, * thereby imposing no performance penalty if the attribute is not used.

* * @since 1.6 */ public class VariableAttributes implements Attributes { // list of mapped attributes. private ArrayList values = new ArrayList(10); private Attributes attrs; private VariableExpander expander; // ------------------- Public Methods /** * Specify which attributes class this object is a proxy for. */ public void init(Attributes attrs, VariableExpander expander) { this.attrs = attrs; this.expander = expander; // I hope this doesn't release the memory for this array; for // efficiency, this should just mark the array as being size 0. values.clear(); } public String getValue(int index) { if (index >= values.size()) { // Expand the values array with null elements, so the later // call to set(index, s) works ok. // // Unfortunately, there is no easy way to set the size of // an arraylist; we must repeatedly add null elements to it.. values.ensureCapacity(index+1); for(int i = values.size(); i<= index; ++i) { values.add(null); } } String s = (String) values.get(index); if (s == null) { // we have never been asked for this value before. // get the real attribute value and perform substitution // on it. s = attrs.getValue(index); if (s != null) { s = expander.expand(s); values.set(index, s); } } return s; } public String getValue(String qname) { int index = attrs.getIndex(qname); if (index == -1) { return null; } return getValue(index); } public String getValue(String uri, String localname) { int index = attrs.getIndex(uri, localname); if (index == -1) { return null; } return getValue(index); } // plain proxy methods follow : nothing interesting :-) public int getIndex(String qname) { return attrs.getIndex(qname); } public int getIndex(String uri, String localpart) { return attrs.getIndex(uri, localpart); } public int getLength() { return attrs.getLength(); } public String getLocalName(int index) { return attrs.getLocalName(index); } public String getQName(int index) { return attrs.getQName(index); } public String getType(int index) { return attrs.getType(index); } public String getType(String qname) { return attrs.getType(qname); } public String getType(String uri, String localname) { return attrs.getType(uri, localname); } public String getURI(int index) { return attrs.getURI(index); } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/VariableExpander.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/VariableExpand0000644000175000017500000000274011226450007033670 0ustar twernertwerner/* $Id: VariableExpander.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.substitution; /** *

An Interface describing a class capable of expanding strings which * may contain variable references. The exact syntax of the "reference", * and the mechanism for determining the corresponding value to be used * is up to the concrete implementation.

* * @since 1.6 */ public interface VariableExpander { /** * Return the input string with any variables replaced by their * corresponding value. If there are no variables in the string, * then the input parameter is returned unaltered. */ public String expand(String param); } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/VariableSubstitutor.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/VariableSubsti0000644000175000017500000000762711226450007033733 0ustar twernertwerner/* $Id: VariableSubstitutor.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.substitution; import org.apache.commons.digester.Substitutor; import org.xml.sax.Attributes; /** * Substitutor implementation that support variable replacement * for both attributes and body text. * The actual expansion of variables into text is delegated to {@link VariableExpander} * implementations. * Supports setting an expander just for body text or just for attributes. * Also supported is setting no expanders for body text and for attributes. * * @since 1.6 */ public class VariableSubstitutor extends Substitutor { /** * The expander to be used to expand variables in the attributes. * Null when no expansion should be performed. */ private VariableExpander attributesExpander; /** * Attributes implementation that (lazily) performs variable substitution. * Will be lazily created when needed then reused. */ private VariableAttributes variableAttributes; /** * The expander to be used to expand variables in the body text. * Null when no expansion should be performed. */ private VariableExpander bodyTextExpander; /** * Constructs a Substitutor which uses the same VariableExpander for both * body text and attibutes. * @param expander VariableExpander implementation, * null if no substitutions are to be performed */ public VariableSubstitutor(VariableExpander expander) { this(expander, expander); } /** * Constructs a Substitutor. * @param attributesExpander VariableExpander implementation to be used for attributes, * null if no attribute substitutions are to be performed * @param bodyTextExpander VariableExpander implementation to be used for bodyTextExpander, * null if no attribute substitutions are to be performed */ public VariableSubstitutor(VariableExpander attributesExpander, VariableExpander bodyTextExpander) { this.attributesExpander = attributesExpander; this.bodyTextExpander = bodyTextExpander; variableAttributes = new VariableAttributes(); } /** * Substitutes the attributes (before they are passed to the * Rule implementations's) */ public Attributes substitute(Attributes attributes) { Attributes results = attributes; if (attributesExpander != null) { variableAttributes.init(attributes, attributesExpander); results = variableAttributes; } return results; } /** * Substitutes for the body text. * This method may substitute values into the body text of the * elements that Digester parses. * * @param bodyText the body text (as passed to Digester) * @return the body text to be passed to the Rule implementations */ public String substitute(String bodyText) { String result = bodyText; if (bodyTextExpander != null) { result = bodyTextExpander.expand(bodyText); } return result; } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/MultiVariableExpander.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/substitution/MultiVariableE0000644000175000017500000000745011226450007033653 0ustar twernertwerner/* $Id: MultiVariableExpander.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.substitution; import java.util.Map; import java.util.ArrayList; /** *

Expands variable references from multiple sources.

* * @since 1.6 */ public class MultiVariableExpander implements VariableExpander { private int nEntries = 0; private ArrayList markers = new ArrayList(2); private ArrayList sources = new ArrayList(2); public MultiVariableExpander() { } public void addSource(String marker, Map source) { ++nEntries; markers.add(marker); sources.add(source); } /* * Expands any variable declarations using any of the known * variable marker strings. * * @throws IllegalArgumentException if the input param references * a variable which is not known to the specified source. */ public String expand(String param) { for(int i=0; i * Commonly, the variable marker is "$", in which case variables * are indicated by ${key} in the string. *

* Returns the string after performing all substitutions. *

* If no substitutions were made, the input string object is * returned (not a copy). * * @throws IllegalArgumentException if the input param references * a variable which is not known to the specified source. */ public String expand(String str, String marker, Map source) { String startMark = marker + "{"; int markLen = startMark.length(); int index = 0; for(;;) { index = str.indexOf(startMark, index); if (index == -1) { return str; } int startIndex = index + markLen; if (startIndex > str.length()) { throw new IllegalArgumentException( "var expression starts at end of string"); } int endIndex = str.indexOf("}", index + markLen); if (endIndex == -1) { throw new IllegalArgumentException( "var expression starts but does not end"); } String key = str.substring(index+markLen, endIndex); Object value = source.get(key); if (value == null) { throw new IllegalArgumentException( "parameter [" + key + "] is not defined."); } String varValue = value.toString(); str = str.substring(0, index) + varValue + str.substring(endIndex+1); index += varValue.length(); } } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/ExtendedBaseRules.java0000644000175000017500000004420211226450007032514 0ustar twernertwerner/* $Id: ExtendedBaseRules.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** *

Extension of {@link RulesBase} for complex schema.

* *

This is an extension of the basic pattern matching scheme * intended to improve support for mapping complex xml-schema. * It is intended to be a minimal extension of the standard rules * big enough to support complex schema but without the full generality * offered by more exotic matching pattern rules.

* *

When should you use this rather than the original?

* *

* This pattern-matching engine is complex and slower than the basic * default RulesBase class, but offers more functionality: *

    *
  • Universal patterns allow patterns to be specified which will match * regardless of whether there are "better matching" patterns available.
  • *
  • Parent-match patterns (eg "a/b/?") allow matching for all direct * children of a specified element.
  • *
  • Ancestor-match patterns (eg "a/b/*") allow matching all elements * nested within a specified element to any nesting depth.
  • *
  • Completely-wild patterns ("*" or "!*") allow matching all elements.
  • *
*

* *

Universal Match Patterns

* *

The default RulesBase pattern-matching engine always attempts to find * the "best matching pattern", and will ignore rules associated with other * patterns that match but are not "as good". As an example, if the pattern * "a/b/c" is associated with rules 1 and 2, and "*/c" is associated with * rules 3 and 4 then element "a/b/c" will cause only rules 1 and 2 to execute. * Rules 3 and 4 do have matching patterns, but because the patterns are shorter * and include wildcard characters they are regarded as being "not as good" as * a direct match. In general, exact patterns are better than wildcard patterns, * and among multiple patterns with wildcards, the longest is preferred. * See the RulesBase class for more information.

* *

This feature of preferring "better" patterns can be a powerful tool. * However it also means that patterns can interact in unexpected ways.

* *

When using the ExtendedBaseRules, any pattern prefixed with '!' bypasses * the "best match" feature. Even if there is an exact match or a longer * wildcard match, patterns prefixed by '!' will still be tested to see if * they match, and if so their associated Rule objects will be included in * the set of rules to be executed in the normal manner.

* *
    *
  • Pattern "!*/a/b" matches whenever an 'b' element * is inside an 'a'.
  • *
  • Pattern "!a/b/?" matches any child of a parent * matching "a/b" (see "Parent Match Patterns").
  • *
  • Pattern "!*/a/b/?" matches any child of a parent * matching "!*/a/b" (see "Parent Match Patterns").
  • *
  • Pattern "!a/b/*" matches any element whose path * starts with "a" then "b" (see "Ancestor Match Patterns").
  • *
  • Pattern "!*/a/b/*" matches any elements whose path * contains 'a/b' (see "Ancestor Match Patterns").
  • *
* *

Parent Match Patterns

* *

* These will match direct child elements of a particular parent element. *

    *
  • * "a/b/c/?" matches any child whose parent matches * "a/b/c". Exact parent rules take precedence over Ancestor * Match patterns. *
  • *
  • * "*/a/b/c/?" matches any child whose parent matches * "*/a/b/c". The longest matching still applies to parent * matches but the length excludes the '?', which effectively means * that standard wildcard matches with the same level of depth are * chosen in preference. *
  • *
*

* *

Ancestor Match Patterns

* *

* These will match elements whose parentage includes a particular sequence * of elements. *

    *
  • * "a/b/*" matches any element whose path starts with * 'a' then 'b'. Exact parent and parent match rules take precedence. * The longest ancestor match will take precedence. *
  • *
  • * "*/a/b/*" matches any elements whose path contains * an element 'a' followed by an element 'b'. The longest matching still * applies but the length excludes the '*' at the end. *
  • *
*

* *

Completely Wild Patterns

* *

Pattern "*" matches every pattern that isn't matched by * any other basic rule.

* *

Pattern "!*" matches every pattern.

* *

Using The Extended Rules

* *

By default, a Digester instance uses a {@link RulesBase} instance as * its pattern matching engine. To use an ExtendedBaseRules instance, call * the Digester.setRules method before adding any Rule objects to the digester * instance: *

 *     Digester digester = new Digester();
 *     digester.setRules( new ExtendedBaseRules() );
 * 

* *

The most important thing to remember when using the extended rules is * that universal and non-universal patterns are completely independent. * Universal patterns are never affected by the addition of new patterns * or the removal of existing ones. Non-universal patterns are never affected * by the addition of new universal patterns or the removal of * existing universal patterns. As in the basic matching rules, * non-universal (basic) patterns can be affected by the * addition of new non-universal patterns or the removal of existing * non-universal patterns, because only rules associated with the * "best matching" pattern for each xml element are executed. * *

This means that you can use universal patterns to build up the simple * parts of your structure - for example defining universal creation and * property setting rules. More sophisticated and complex mapping will require * non-universal patterns and this might mean that some of the universal rules * will need to be replaced by a series of special cases using non-universal * rules. But by using universal rules as your backbone, these additions * should not break your existing rules.

*/ public class ExtendedBaseRules extends RulesBase { // ----------------------------------------------------- Instance Variables /** * Counts the entry number for the rules. */ private int counter = 0; /** * The decision algorithm used (unfortunately) doesn't preserve the entry * order. * This map is used by a comparator which orders the list of matches * before it's returned. * This map stores the entry number keyed by the rule. */ private Map order = new HashMap(); // --------------------------------------------------------- Public Methods /** * Register a new Rule instance matching the specified pattern. * * @param pattern Nesting pattern to be matched for this Rule * @param rule Rule instance to be registered */ public void add(String pattern, Rule rule) { super.add(pattern, rule); counter++; order.put(rule, new Integer(counter)); } /** * Return a List of all registered Rule instances that match the specified * nesting pattern, or a zero-length List if there are no matches. If more * than one Rule instance matches, they must be returned * in the order originally registered through the add() * method. * * @param pattern Nesting pattern to be matched */ public List match(String namespace, String pattern) { // calculate the pattern of the parent // (if the element has one) String parentPattern = ""; int lastIndex = pattern.lastIndexOf('/'); boolean hasParent = true; if (lastIndex == -1) { // element has no parent hasParent = false; } else { // calculate the pattern of the parent parentPattern = pattern.substring(0, lastIndex); } // we keep the list of universal matches separate List universalList = new ArrayList(counter); // Universal all wildards ('!*') // These are always matched so always add them List tempList = (List) this.cache.get("!*"); if (tempList != null) { universalList.addAll(tempList); } // Universal exact parent match // need to get this now since only wildcards are considered later tempList = (List) this.cache.get("!" + parentPattern + "/?"); if (tempList != null) { universalList.addAll(tempList); } // base behaviour means that if we certain matches, we don't continue // but we just have a single combined loop and so we have to set // a variable boolean ignoreBasicMatches = false; // see if we have an exact basic pattern match List rulesList = (List) this.cache.get(pattern); if (rulesList != null) { // we have a match! // so ignore all basic matches from now on ignoreBasicMatches = true; } else { // see if we have an exact child match if (hasParent) { // matching children takes preference rulesList = (List) this.cache.get(parentPattern + "/?"); if (rulesList != null) { // we have a match! // so ignore all basic matches from now on ignoreBasicMatches = true; } else { // we don't have a match yet - so try exact ancester // rulesList = findExactAncesterMatch(pattern); if (rulesList != null) { // we have a match! // so ignore all basic matches from now on ignoreBasicMatches = true; } } } } // OK - we're ready for the big loop! // Unlike the basic rules case, // we have to go through for all those universal rules in all cases. // Find the longest key, ie more discriminant String longKey = ""; int longKeyLength = 0; Iterator keys = this.cache.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); // find out if it's a univeral pattern // set a flag boolean isUniversal = key.startsWith("!"); if (isUniversal) { // and find the underlying key key = key.substring(1, key.length()); } // don't need to check exact matches boolean wildcardMatchStart = key.startsWith("*/"); boolean wildcardMatchEnd = key.endsWith("/*"); if (wildcardMatchStart || (isUniversal && wildcardMatchEnd)) { boolean parentMatched = false; boolean basicMatched = false; boolean ancesterMatched = false; boolean parentMatchEnd = key.endsWith("/?"); if (parentMatchEnd) { // try for a parent match parentMatched = parentMatch(key, pattern, parentPattern); } else if (wildcardMatchEnd) { // check for ancester match if (wildcardMatchStart) { String patternBody = key.substring(2, key.length() - 2); if (pattern.endsWith(patternBody)) { ancesterMatched = true; } else { ancesterMatched = (pattern.indexOf(patternBody + "/") > -1); } } else { String bodyPattern = key.substring(0, key.length() - 2); if (pattern.startsWith(bodyPattern)) { if (pattern.length() == bodyPattern.length()) { // exact match ancesterMatched = true; } else { ancesterMatched = ( pattern.charAt(bodyPattern.length()) == '/' ); } } else { ancesterMatched = false; } } } else { // try for a base match basicMatched = basicMatch(key, pattern); } if (parentMatched || basicMatched || ancesterMatched) { if (isUniversal) { // universal rules go straight in // (no longest matching rule) tempList = (List) this.cache.get("!" + key); if (tempList != null) { universalList.addAll(tempList); } } else { if (!ignoreBasicMatches) { // ensure that all parent matches are SHORTER // than rules with same level of matching. // // the calculations below don't work for universal // matching, but we don't care because in that case // this if-stmt is not entered. int keyLength = key.length(); if (wildcardMatchStart) { --keyLength; } if (wildcardMatchEnd) { --keyLength; } else if (parentMatchEnd) { --keyLength; } if (keyLength > longKeyLength) { rulesList = (List) this.cache.get(key); longKey = key; longKeyLength = keyLength; } } } } } } // '*' works in practice as a default matching // (this is because anything is a deeper match!) if (rulesList == null) { rulesList = (List) this.cache.get("*"); } // if we've matched a basic pattern, then add to the universal list if (rulesList != null) { universalList.addAll(rulesList); } // don't filter if namespace is null if (namespace != null) { // remove invalid namespaces Iterator it = universalList.iterator(); while (it.hasNext()) { Rule rule = (Rule) it.next(); String ns_uri = rule.getNamespaceURI(); if (ns_uri != null && !ns_uri.equals(namespace)) { it.remove(); } } } // need to make sure that the collection is sort in the order // of addition. We use a custom comparator for this Collections.sort( universalList, new Comparator() { public int compare(Object o1, Object o2) throws ClassCastException { // Get the entry order from the map Integer i1 = (Integer) order.get(o1); Integer i2 = (Integer) order.get(o2); // and use that to perform the comparison if (i1 == null) { if (i2 == null) { return 0; } else { return -1; } } else if (i2 == null) { return 1; } return (i1.intValue() - i2.intValue()); } }); return universalList; } /** * Matching parent. */ private boolean parentMatch(String key, String pattern, String parentPattern) { return parentPattern.endsWith(key.substring(1, key.length() - 2)); } /** * Standard match. * Matches the end of the pattern to the key. */ private boolean basicMatch(String key, String pattern) { return (pattern.equals(key.substring(2)) || pattern.endsWith(key.substring(1))); } /** * Finds an exact ancester match for given pattern */ private List findExactAncesterMatch(String parentPattern) { List matchingRules = null; int lastIndex = parentPattern.length(); while (lastIndex-- > 0) { lastIndex = parentPattern.lastIndexOf('/', lastIndex); if (lastIndex > 0) { matchingRules = (List) this.cache.get(parentPattern.substring(0, lastIndex) + "/*"); if (matchingRules != null) { return matchingRules; } } } return null; } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/RulesBase.java0000644000175000017500000002230211226450007031030 0ustar twernertwerner/* $Id: RulesBase.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; /** *

Default implementation of the Rules interface that supports * the standard rule matching behavior. This class can also be used as a * base class for specialized Rules implementations.

* *

The matching policies implemented by this class support two different * types of pattern matching rules:

*
    *
  • Exact Match - A pattern "a/b/c" exactly matches a * <c> element, nested inside a <b> * element, which is nested inside an <a> element.
  • *
  • Tail Match - A pattern "*/a/b" matches a * <b> element, nested inside an <a> * element, no matter how deeply the pair is nested.
  • *
* *

Note that wildcard patterns are ignored if an explicit match can be found * (and when multiple wildcard patterns match, only the longest, ie most * explicit, pattern is considered a match).

* *

See the package documentation for package org.apache.commons.digester * for more information.

*/ public class RulesBase implements Rules { // ----------------------------------------------------- Instance Variables /** * The set of registered Rule instances, keyed by the matching pattern. * Each value is a List containing the Rules for that pattern, in the * order that they were orginally registered. */ protected HashMap cache = new HashMap(); /** * The Digester instance with which this Rules instance is associated. */ protected Digester digester = null; /** * The namespace URI for which subsequently added Rule * objects are relevant, or null for matching independent * of namespaces. */ protected String namespaceURI = null; /** * The set of registered Rule instances, in the order that they were * originally registered. */ protected ArrayList rules = new ArrayList(); // ------------------------------------------------------------- Properties /** * Return the Digester instance with which this Rules instance is * associated. */ public Digester getDigester() { return (this.digester); } /** * Set the Digester instance with which this Rules instance is associated. * * @param digester The newly associated Digester instance */ public void setDigester(Digester digester) { this.digester = digester; Iterator items = rules.iterator(); while (items.hasNext()) { Rule item = (Rule) items.next(); item.setDigester(digester); } } /** * Return the namespace URI that will be applied to all subsequently * added Rule objects. */ public String getNamespaceURI() { return (this.namespaceURI); } /** * Set the namespace URI that will be applied to all subsequently * added Rule objects. * * @param namespaceURI Namespace URI that must match on all * subsequently added rules, or null for matching * regardless of the current namespace URI */ public void setNamespaceURI(String namespaceURI) { this.namespaceURI = namespaceURI; } // --------------------------------------------------------- Public Methods /** * Register a new Rule instance matching the specified pattern. * * @param pattern Nesting pattern to be matched for this Rule * @param rule Rule instance to be registered */ public void add(String pattern, Rule rule) { // to help users who accidently add '/' to the end of their patterns int patternLength = pattern.length(); if (patternLength>1 && pattern.endsWith("/")) { pattern = pattern.substring(0, patternLength-1); } List list = (List) cache.get(pattern); if (list == null) { list = new ArrayList(); cache.put(pattern, list); } list.add(rule); rules.add(rule); if (this.digester != null) { rule.setDigester(this.digester); } if (this.namespaceURI != null) { rule.setNamespaceURI(this.namespaceURI); } } /** * Clear all existing Rule instance registrations. */ public void clear() { cache.clear(); rules.clear(); } /** * Return a List of all registered Rule instances that match the specified * nesting pattern, or a zero-length List if there are no matches. If more * than one Rule instance matches, they must be returned * in the order originally registered through the add() * method. * * @param pattern Nesting pattern to be matched * * @deprecated Call match(namespaceURI,pattern) instead. */ public List match(String pattern) { return (match(null, pattern)); } /** * Return a List of all registered Rule instances that match the specified * nesting pattern, or a zero-length List if there are no matches. If more * than one Rule instance matches, they must be returned * in the order originally registered through the add() * method. * * @param namespaceURI Namespace URI for which to select matching rules, * or null to match regardless of namespace URI * @param pattern Nesting pattern to be matched */ public List match(String namespaceURI, String pattern) { // List rulesList = (List) this.cache.get(pattern); List rulesList = lookup(namespaceURI, pattern); if ((rulesList == null) || (rulesList.size() < 1)) { // Find the longest key, ie more discriminant String longKey = ""; Iterator keys = this.cache.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); if (key.startsWith("*/")) { if (pattern.equals(key.substring(2)) || pattern.endsWith(key.substring(1))) { if (key.length() > longKey.length()) { // rulesList = (List) this.cache.get(key); rulesList = lookup(namespaceURI, key); longKey = key; } } } } } if (rulesList == null) { rulesList = new ArrayList(); } return (rulesList); } /** * Return a List of all registered Rule instances, or a zero-length List * if there are no registered Rule instances. If more than one Rule * instance has been registered, they must be returned * in the order originally registered through the add() * method. */ public List rules() { return (this.rules); } // ------------------------------------------------------ Protected Methods /** * Return a List of Rule instances for the specified pattern that also * match the specified namespace URI (if any). If there are no such * rules, return null. * * @param namespaceURI Namespace URI to match, or null to * select matching rules regardless of namespace URI * @param pattern Pattern to be matched */ protected List lookup(String namespaceURI, String pattern) { // Optimize when no namespace URI is specified List list = (List) this.cache.get(pattern); if (list == null) { return (null); } if ((namespaceURI == null) || (namespaceURI.length() == 0)) { return (list); } // Select only Rules that match on the specified namespace URI ArrayList results = new ArrayList(); Iterator items = list.iterator(); while (items.hasNext()) { Rule item = (Rule) items.next(); if ((namespaceURI.equals(item.getNamespaceURI())) || (item.getNamespaceURI() == null)) { results.add(item); } } return (results); } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/WithDefaultsRulesWrapper.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/WithDefaultsRulesWrapper.ja0000644000175000017500000001266011226450007033601 0ustar twernertwerner/* $Id: WithDefaultsRulesWrapper.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** *

Rules Decorator that returns default rules * when no matches are returned by the wrapped implementation.

* *

This allows default Rule instances to be added to any * existing Rules implementation. These default Rule * instances will be returned for any match for which the wrapped * implementation does not return any matches.

*

For example, *

 *   Rule alpha;
 *   ...
 *   WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new BaseRules());
 *   rules.addDefault(alpha);
 *   ...
 *   digester.setRules(rules);
 *   ...
 * 
* when a pattern does not match any other rule, then rule alpha will be called. *

*

WithDefaultsRulesWrapper follows the Decorator pattern.

* * @since 1.6 */ public class WithDefaultsRulesWrapper implements Rules { // --------------------------------------------------------- Fields /** The Rules implementation that this class wraps. */ private Rules wrappedRules; /** Rules to be fired when the wrapped implementations returns none. */ private List defaultRules = new ArrayList(); /** All rules (preserves order in which they were originally added) */ private List allRules = new ArrayList(); // --------------------------------------------------------- Constructor /** * Base constructor. * * @param wrappedRules the wrapped Rules implementation, not null * @throws IllegalArgumentException when wrappedRules is null */ public WithDefaultsRulesWrapper(Rules wrappedRules) { if (wrappedRules == null) { throw new IllegalArgumentException("Wrapped rules must not be null"); } this.wrappedRules = wrappedRules; } // --------------------------------------------------------- Properties /** Gets digester using these Rules */ public Digester getDigester() { return wrappedRules.getDigester(); } /** Sets digeseter using these Rules */ public void setDigester(Digester digester) { wrappedRules.setDigester(digester); Iterator it = defaultRules.iterator(); while (it.hasNext()) { Rule rule = (Rule) it.next(); rule.setDigester(digester); } } /** Gets namespace to apply to Rule's added */ public String getNamespaceURI() { return wrappedRules.getNamespaceURI(); } /** Sets namespace to apply to Rule's added subsequently */ public void setNamespaceURI(String namespaceURI) { wrappedRules.setNamespaceURI(namespaceURI); } /** Gets Rule's which will be fired when the wrapped implementation returns no matches */ public List getDefaults() { return defaultRules; } // --------------------------------------------------------- Public Methods public List match(String pattern) { return match("", pattern); } /** * Return list of rules matching given pattern. * If wrapped implementation returns any matches return those. * Otherwise, return default matches. */ public List match(String namespaceURI, String pattern) { List matches = wrappedRules.match(namespaceURI, pattern); if (matches == null || matches.isEmpty()) { // a little bit of defensive programming return new ArrayList(defaultRules); } // otherwise return matches; } /** Adds a rule to be fired when wrapped implementation returns no matches */ public void addDefault(Rule rule) { // set up rule if (wrappedRules.getDigester() != null) { rule.setDigester(wrappedRules.getDigester()); } if (wrappedRules.getNamespaceURI() != null) { rule.setNamespaceURI(wrappedRules.getNamespaceURI()); } defaultRules.add(rule); allRules.add(rule); } /** Gets all rules */ public List rules() { return allRules; } /** Clears all Rule's */ public void clear() { wrappedRules.clear(); allRules.clear(); defaultRules.clear(); } /** * Adds a Rule to be fired on given pattern. * Pattern matching is delegated to wrapped implementation. */ public void add(String pattern, Rule rule) { wrappedRules.add(pattern, rule); allRules.add(rule); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/SetNextRule.java0000644000175000017500000001730311226450007031372 0ustar twernertwerner/* $Id: SetNextRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.apache.commons.beanutils.MethodUtils; /** *

Rule implementation that calls a method on the (top-1) (parent) * object, passing the top object (child) as an argument. It is * commonly used to establish parent-child relationships.

* *

This rule now supports more flexible method matching by default. * It is possible that this may break (some) code * written against release 1.1.1 or earlier. * See {@link #isExactMatch()} for more details.

* *

Note that while CallMethodRule uses commons-beanutils' data-conversion * functionality (ConvertUtils class) to convert parameter values into * the appropriate type for the parameter to the called method, this * rule does not. Needing to use ConvertUtils functionality when building * parent-child relationships is expected to be very rare; however if you * do need this then instead of using this rule, create a CallMethodRule * specifying targetOffset of 1 in the constructor.

*/ public class SetNextRule extends Rule { // ----------------------------------------------------------- Constructors /** * Construct a "set next" rule with the specified method name. The * method's argument type is assumed to be the class of the * child object. * * @param digester The associated Digester * @param methodName Method name of the parent method to call * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #SetNextRule(String methodName)} instead. */ public SetNextRule(Digester digester, String methodName) { this(methodName); } /** * Construct a "set next" rule with the specified method name. * * @param digester The associated Digester * @param methodName Method name of the parent method to call * @param paramType Java class of the parent method's argument * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #SetNextRule(String methodName,String paramType)} instead. */ public SetNextRule(Digester digester, String methodName, String paramType) { this(methodName, paramType); } /** * Construct a "set next" rule with the specified method name. The * method's argument type is assumed to be the class of the * child object. * * @param methodName Method name of the parent method to call */ public SetNextRule(String methodName) { this(methodName, null); } /** * Construct a "set next" rule with the specified method name. * * @param methodName Method name of the parent method to call * @param paramType Java class of the parent method's argument * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) */ public SetNextRule(String methodName, String paramType) { this.methodName = methodName; this.paramType = paramType; } // ----------------------------------------------------- Instance Variables /** * The method name to call on the parent object. */ protected String methodName = null; /** * The Java class name of the parameter type expected by the method. */ protected String paramType = null; /** * Should we use exact matching. Default is no. */ protected boolean useExactMatch = false; // --------------------------------------------------------- Public Methods /** *

Is exact matching being used.

* *

This rule uses org.apache.commons.beanutils.MethodUtils * to introspect the relevent objects so that the right method can be called. * Originally, MethodUtils.invokeExactMethod was used. * This matches methods very strictly * and so may not find a matching method when one exists. * This is still the behaviour when exact matching is enabled.

* *

When exact matching is disabled, MethodUtils.invokeMethod is used. * This method finds more methods but is less precise when there are several methods * with correct signatures. * So, if you want to choose an exact signature you might need to enable this property.

* *

The default setting is to disable exact matches.

* * @return true iff exact matching is enabled * @since Digester Release 1.1.1 */ public boolean isExactMatch() { return useExactMatch; } /** *

Set whether exact matching is enabled.

* *

See {@link #isExactMatch()}.

* * @param useExactMatch should this rule use exact method matching * @since Digester Release 1.1.1 */ public void setExactMatch(boolean useExactMatch) { this.useExactMatch = useExactMatch; } /** * Process the end of this element. */ public void end() throws Exception { // Identify the objects to be used Object child = digester.peek(0); Object parent = digester.peek(1); if (digester.log.isDebugEnabled()) { if (parent == null) { digester.log.debug("[SetNextRule]{" + digester.match + "} Call [NULL PARENT]." + methodName + "(" + child + ")"); } else { digester.log.debug("[SetNextRule]{" + digester.match + "} Call " + parent.getClass().getName() + "." + methodName + "(" + child + ")"); } } // Call the specified method Class paramTypes[] = new Class[1]; if (paramType != null) { paramTypes[0] = digester.getClassLoader().loadClass(paramType); } else { paramTypes[0] = child.getClass(); } if (useExactMatch) { MethodUtils.invokeExactMethod(parent, methodName, new Object[]{ child }, paramTypes); } else { MethodUtils.invokeMethod(parent, methodName, new Object[]{ child }, paramTypes); } } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("SetNextRule["); sb.append("methodName="); sb.append(methodName); sb.append(", paramType="); sb.append(paramType); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/SetRootRule.java0000644000175000017500000001633011226450007031376 0ustar twernertwerner/* $Id: SetRootRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.apache.commons.beanutils.MethodUtils; /** *

Rule implementation that calls a method on the root object on the stack, * passing the top object (child) as an argument. * It is important to remember that this rule acts on end.

* *

This rule now supports more flexible method matching by default. * It is possible that this may break (some) code * written against release 1.1.1 or earlier. * See {@link #isExactMatch()} for more details.

*/ public class SetRootRule extends Rule { // ----------------------------------------------------------- Constructors /** * Construct a "set root" rule with the specified method name. The * method's argument type is assumed to be the class of the * child object. * * @param digester The associated Digester * @param methodName Method name of the parent method to call * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #SetRootRule(String methodName)} instead. */ public SetRootRule(Digester digester, String methodName) { this(methodName); } /** * Construct a "set root" rule with the specified method name. * * @param digester The associated Digester * @param methodName Method name of the parent method to call * @param paramType Java class of the parent method's argument * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #SetRootRule(String methodName,String paramType)} instead. */ public SetRootRule(Digester digester, String methodName, String paramType) { this(methodName, paramType); } /** * Construct a "set root" rule with the specified method name. The * method's argument type is assumed to be the class of the * child object. * * @param methodName Method name of the parent method to call */ public SetRootRule(String methodName) { this(methodName, null); } /** * Construct a "set root" rule with the specified method name. * * @param methodName Method name of the parent method to call * @param paramType Java class of the parent method's argument * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) */ public SetRootRule(String methodName, String paramType) { this.methodName = methodName; this.paramType = paramType; } // ----------------------------------------------------- Instance Variables /** * The method name to call on the parent object. */ protected String methodName = null; /** * The Java class name of the parameter type expected by the method. */ protected String paramType = null; /** * Should we use exact matching. Default is no. */ protected boolean useExactMatch = false; // --------------------------------------------------------- Public Methods /** *

Is exact matching being used.

* *

This rule uses org.apache.commons.beanutils.MethodUtils * to introspect the relevent objects so that the right method can be called. * Originally, MethodUtils.invokeExactMethod was used. * This matches methods very strictly * and so may not find a matching method when one exists. * This is still the behaviour when exact matching is enabled.

* *

When exact matching is disabled, MethodUtils.invokeMethod is used. * This method finds more methods but is less precise when there are several methods * with correct signatures. * So, if you want to choose an exact signature you might need to enable this property.

* *

The default setting is to disable exact matches.

* * @return true iff exact matching is enabled * @since Digester Release 1.1.1 */ public boolean isExactMatch() { return useExactMatch; } /** *

Set whether exact matching is enabled.

* *

See {@link #isExactMatch()}.

* * @param useExactMatch should this rule use exact method matching * @since Digester Release 1.1.1 */ public void setExactMatch(boolean useExactMatch) { this.useExactMatch = useExactMatch; } /** * Process the end of this element. */ public void end() throws Exception { // Identify the objects to be used Object child = digester.peek(0); Object parent = digester.root; if (digester.log.isDebugEnabled()) { if (parent == null) { digester.log.debug("[SetRootRule]{" + digester.match + "} Call [NULL ROOT]." + methodName + "(" + child + ")"); } else { digester.log.debug("[SetRootRule]{" + digester.match + "} Call " + parent.getClass().getName() + "." + methodName + "(" + child + ")"); } } // Call the specified method Class paramTypes[] = new Class[1]; if (paramType != null) { paramTypes[0] = digester.getClassLoader().loadClass(paramType); } else { paramTypes[0] = child.getClass(); } if (useExactMatch) { MethodUtils.invokeExactMethod(parent, methodName, new Object[]{ child }, paramTypes); } else { MethodUtils.invokeMethod(parent, methodName, new Object[]{ child }, paramTypes); } } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("SetRootRule["); sb.append("methodName="); sb.append(methodName); sb.append(", paramType="); sb.append(paramType); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/ObjectCreateRule.java0000644000175000017500000001600111226450007032324 0ustar twernertwerner/* $Id: ObjectCreateRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; /** * Rule implementation that creates a new object and pushes it * onto the object stack. When the element is complete, the * object will be popped */ public class ObjectCreateRule extends Rule { // ----------------------------------------------------------- Constructors /** * Construct an object create rule with the specified class name. * * @param digester The associated Digester * @param className Java class name of the object to be created * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #ObjectCreateRule(String className)} instead. */ public ObjectCreateRule(Digester digester, String className) { this(className); } /** * Construct an object create rule with the specified class. * * @param digester The associated Digester * @param clazz Java class name of the object to be created * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #ObjectCreateRule(Class clazz)} instead. */ public ObjectCreateRule(Digester digester, Class clazz) { this(clazz); } /** * Construct an object create rule with the specified class name and an * optional attribute name containing an override. * * @param digester The associated Digester * @param className Java class name of the object to be created * @param attributeName Attribute name which, if present, contains an * override of the class name to create * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #ObjectCreateRule(String className, String attributeName)} instead. */ public ObjectCreateRule(Digester digester, String className, String attributeName) { this (className, attributeName); } /** * Construct an object create rule with the specified class and an * optional attribute name containing an override. * * @param digester The associated Digester * @param attributeName Attribute name which, if present, contains an * @param clazz Java class name of the object to be created * override of the class name to create * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #ObjectCreateRule(String attributeName, Class clazz)} instead. */ public ObjectCreateRule(Digester digester, String attributeName, Class clazz) { this(attributeName, clazz); } /** * Construct an object create rule with the specified class name. * * @param className Java class name of the object to be created */ public ObjectCreateRule(String className) { this(className, (String) null); } /** * Construct an object create rule with the specified class. * * @param clazz Java class name of the object to be created */ public ObjectCreateRule(Class clazz) { this(clazz.getName(), (String) null); } /** * Construct an object create rule with the specified class name and an * optional attribute name containing an override. * * @param className Java class name of the object to be created * @param attributeName Attribute name which, if present, contains an * override of the class name to create */ public ObjectCreateRule(String className, String attributeName) { this.className = className; this.attributeName = attributeName; } /** * Construct an object create rule with the specified class and an * optional attribute name containing an override. * * @param attributeName Attribute name which, if present, contains an * @param clazz Java class name of the object to be created * override of the class name to create */ public ObjectCreateRule(String attributeName, Class clazz) { this(clazz.getName(), attributeName); } // ----------------------------------------------------- Instance Variables /** * The attribute containing an override class name if it is present. */ protected String attributeName = null; /** * The Java class name of the object to be created. */ protected String className = null; // --------------------------------------------------------- Public Methods /** * Process the beginning of this element. * * @param attributes The attribute list of this element */ public void begin(Attributes attributes) throws Exception { // Identify the name of the class to instantiate String realClassName = className; if (attributeName != null) { String value = attributes.getValue(attributeName); if (value != null) { realClassName = value; } } if (digester.log.isDebugEnabled()) { digester.log.debug("[ObjectCreateRule]{" + digester.match + "}New " + realClassName); } // Instantiate the new object and push it on the context stack Class clazz = digester.getClassLoader().loadClass(realClassName); Object instance = clazz.newInstance(); digester.push(instance); } /** * Process the end of this element. */ public void end() throws Exception { Object top = digester.pop(); if (digester.log.isDebugEnabled()) { digester.log.debug("[ObjectCreateRule]{" + digester.match + "} Pop " + top.getClass().getName()); } } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("ObjectCreateRule["); sb.append("className="); sb.append(className); sb.append(", attributeName="); sb.append(attributeName); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/package.html0000644000175000017500000020074711226450007030574 0ustar twernertwerner Package Documentation for org.apache.commons.digester Package The Digester package provides for rules-based processing of arbitrary XML documents.

External Dependencies

The Digester component is dependent upon implementations of the following standard libraries:

It is also dependent on a compatible set of Apache Commons library components. The recommended dependency set is:

Recommended Dependency Set
Digester+Logging 1.1.x+BeanUtils 1.8.0

Other compatible dependency sets include:

Compatible Dependency Sets
Digester+Logging 1.1.x+BeanUtils 1.x+Collections 2.x
Digester+Logging 1.1.x+BeanUtils 1.x+Collections 3.x

It is also possible to use Logging 1.0.x or BeanUtils 1.7.0 instead.

Introduction

In many application environments that deal with XML-formatted data, it is useful to be able to process an XML document in an "event driven" manner, where particular Java objects are created (or methods of existing objects are invoked) when particular patterns of nested XML elements have been recognized. Developers familiar with the Simple API for XML Parsing (SAX) approach to processing XML documents will recognize that the Digester provides a higher level, more developer-friendly interface to SAX events, because most of the details of navigating the XML element hierarchy are hidden -- allowing the developer to focus on the processing to be performed.

In order to use a Digester, the following basic steps are required:

  • Create a new instance of the org.apache.commons.digester.Digester class. Previously created Digester instances may be safely reused, as long as you have completed any previously requested parse, and you do not try to utilize a particular Digester instance from more than one thread at a time.
  • Set any desired configuration properties that will customize the operation of the Digester when you next initiate a parse operation.
  • Optionally, push any desired initial object(s) onto the Digester's object stack.
  • Register all of the element matching patterns for which you wish to have processing rules fired when this pattern is recognized in an input document. You may register as many rules as you like for any particular pattern. If there is more than one rule for a given pattern, the rules will be executed in the order that they were listed.
  • Call the digester.parse() method, passing a reference to the XML document to be parsed in one of a variety of forms. See the Digester.parse() documentation for details. Note that you will need to be prepared to catch any IOException or SAXException that is thrown by the parser, or any runtime expression that is thrown by one of the processing rules.

Alternatively a Digester may be used as a sax event hander, as follows:

  • Create an instance of a sax parser (using the JAXP APIs or otherwise).
  • Set any desired configuration properties on that parser object.
  • Create an instance of org.apache.commons.digester.Digester.
  • Optionally, push any desired initial object(s) onto the Digester's object stack.
  • Register patterns and rules with the digester instance.
  • Call parser.parse(inputSource, digester).

For example code, see the usage examples, and the FAQ .

Digester Configuration Properties

A org.apache.commons.digester.Digester instance contains several configuration properties that can be used to customize its operation. These properties must be configured before you call one of the parse() variants, in order for them to take effect on that parse.

Property Description
classLoader You can optionally specify the class loader that will be used to load classes when required by the ObjectCreateRule and FactoryCreateRule rules. If not specified, application classes will be loaded from the thread's context class loader (if the useContextClassLoader property is set to true) or the same class loader that was used to load the Digester class itself.
errorHandler You can optionally specify a SAX ErrorHandler that is notified when parsing errors occur. By default, any parsing errors that are encountered are logged, but Digester will continue processing as well.
namespaceAware A boolean that is set to true to perform parsing in a manner that is aware of XML namespaces. Among other things, this setting affects how elements are matched to processing rules. See Namespace Aware Parsing for more information.
ruleNamespaceURI The public URI of the namespace for which all subsequently added rules are associated, or null for adding rules that are not associated with any namespace. See Namespace Aware Parsing for more information.
rules The Rules component that actually performs matching of Rule instances against the current element nesting pattern is pluggable. By default, Digester includes a Rules implementation that behaves as described in this document. See Pluggable Rules Processing for more information.
useContextClassLoader A boolean that is set to true if you want application classes required by FactoryCreateRule and ObjectCreateRule to be loaded from the context class loader of the current thread. By default, classes will be loaded from the class loader that loaded this Digester class. NOTE - This property is ignored if you set a value for the classLoader property; that class loader will be used unconditionally.
validating A boolean that is set to true if you wish to validate the XML document against a Document Type Definition (DTD) that is specified in its DOCTYPE declaration. The default value of false requests a parse that only detects "well formed" XML documents, rather than "valid" ones.

In addition to the scalar properties defined above, you can also register a local copy of a Document Type Definition (DTD) that is referenced in a DOCTYPE declaration. Such a registration tells the XML parser that, whenever it encounters a DOCTYPE declaration with the specified public identifier, it should utilize the actual DTD content at the registered system identifier (a URL), rather than the one in the DOCTYPE declaration.

For example, the Struts framework controller servlet uses the following registration in order to tell Struts to use a local copy of the DTD for the Struts configuration file. This allows usage of Struts in environments that are not connected to the Internet, and speeds up processing even at Internet connected sites (because it avoids the need to go across the network).

    URL url = new URL("/org/apache/struts/resources/struts-config_1_0.dtd");
    digester.register
      ("-//Apache Software Foundation//DTD Struts Configuration 1.0//EN",
       url.toString());

As a side note, the system identifier used in this example is the path that would be passed to java.lang.ClassLoader.getResource() or java.lang.ClassLoader.getResourceAsStream(). The actual DTD resource is loaded through the same class loader that loads all of the Struts classes -- typically from the struts.jar file.

The Object Stack

One very common use of org.apache.commons.digester.Digester technology is to dynamically construct a tree of Java objects, whose internal organization, as well as the details of property settings on these objects, are configured based on the contents of the XML document. In fact, the primary reason that the Digester package was created (it was originally part of Struts, and then moved to the Commons project because it was recognized as being generally useful) was to facilitate the way that the Struts controller servlet configures itself based on the contents of your application's struts-config.xml file.

To facilitate this usage, the Digester exposes a stack that can be manipulated by processing rules that are fired when element matching patterns are satisfied. The usual stack-related operations are made available, including the following:

  • clear() - Clear the current contents of the object stack.
  • peek() - Return a reference to the top object on the stack, without removing it.
  • pop() - Remove the top object from the stack and return it.
  • push() - Push a new object onto the top of the stack.

A typical design pattern, then, is to fire a rule that creates a new object and pushes it on the stack when the beginning of a particular XML element is encountered. The object will remain there while the nested content of this element is processed, and it will be popped off when the end of the element is encountered. As we will see, the standard "object create" processing rule supports exactly this functionalility in a very convenient way.

Several potential issues with this design pattern are addressed by other features of the Digester functionality:

  • How do I relate the objects being created to each other? - The Digester supports standard processing rules that pass the top object on the stack as an argument to a named method on the next-to-top object on the stack (or vice versa). This rule makes it easy to establish parent-child relationships between these objects. One-to-one and one-to-many relationships are both easy to construct.
  • How do I retain a reference to the first object that was created? As you review the description of what the "object create" processing rule does, it would appear that the first object you create (i.e. the object created by the outermost XML element you process) will disappear from the stack by the time that XML parsing is completed, because the end of the element would have been encountered. However, Digester will maintain a reference to the very first object ever pushed onto the object stack, and will return it to you as the return value from the parse() call. Alternatively, you can push a reference to some application object onto the stack before calling parse(), and arrange that a parent-child relationship be created (by appropriate processing rules) between this manually pushed object and the ones that are dynamically created. In this way, the pushed object will retain a reference to the dynamically created objects (and therefore all of their children), and will be returned to you after the parse finishes as well.

Element Matching Patterns

A primary feature of the org.apache.commons.digester.Digester parser is that the Digester automatically navigates the element hierarchy of the XML document you are parsing for you, without requiring any developer attention to this process. Instead, you focus on deciding what functions you would like to have performed whenver a certain arrangement of nested elements is encountered in the XML document being parsed. The mechanism for specifying such arrangements are called element matching patterns.

The Digester can be configured to use different pattern-matching algorithms via the Digester.setRules method. However for the vast majority of cases, the default matching algorithm works fine. The default pattern matching behaviour is described below.

A very simple element matching pattern is a simple string like "a". This pattern is matched whenever an <a> top-level element is encountered in the XML document, no matter how many times it occurs. Note that nested <a> elements will not match this pattern -- we will describe means to support this kind of matching later.

The next step up in matching pattern complexity is "a/b". This pattern will be matched when a <b> element is found nested inside a top-level <a> element. Again, this match can occur as many times as desired, depending on the content of the XML document being parsed. You can use multiple slashes to define a hierarchy of any desired depth that will be matched appropriately.

For example, assume you have registered processing rules that match patterns "a", "a/b", and "a/b/c". For an input XML document with the following contents, the indicated patterns will be matched when the corresponding element is parsed:

  <a>         -- Matches pattern "a"
    <b>       -- Matches pattern "a/b"
      <c/>    -- Matches pattern "a/b/c"
      <c/>    -- Matches pattern "a/b/c"
    </b>
    <b>       -- Matches pattern "a/b"
      <c/>    -- Matches pattern "a/b/c"
      <c/>    -- Matches pattern "a/b/c"
      <c/>    -- Matches pattern "a/b/c"
    </b>
  </a>

It is also possible to match a particular XML element, no matter how it is nested (or not nested) in the XML document, by using the "*" wildcard character in your matching pattern strings. For example, an element matching pattern of "*/a" will match an <a> element at any nesting position within the document.

It is quite possible that, when a particular XML element is being parsed, the pattern for more than one registered processing rule will be matched because you registered more than one processing rule with the exact same matching pattern.

When this occurs, the corresponding processing rules will all be fired in order. Rule methods begin (and body) are executed in the order that the Rules were initially registered with the Digester, whilst end method calls are executed in reverse order. In other words - the order is first in, last out.

Note that wildcard patterns are ignored if an explicit match can be found (and when multiple wildcard patterns match, only the longest, ie most explicit, pattern is considered a match). The result is that rules can be added for "an <a> tag anywhere", but then for that behaviour to be explicitly overridden for specific cases, eg "but not an <a> that is a direct child of an <x>". Therefore if you have rules A and B registered for pattern "*/a" then want to add an additional rule C for pattern "x/a" only, then what you need to do is add *three* rules for "x/a": A, B and C. Note that by using:

  Rule ruleA = new ObjectCreateRule();
  Rule ruleB = new SetNextRule();
  Rule ruleC = new SetPropertiesRule();

  digester.addRule("*/a", ruleA);
  digester.addRule("*/a", ruleB);
  digester.addRule("x/a", ruleA);
  digester.addRule("x/a", ruleB);
  digester.addRule("x/a", ruleC);
you have associated the same rule instances A and B with multiple patterns, thus avoiding creating extra rule object instances.

Processing Rules

The previous section documented how you identify when you wish to have certain actions take place. The purpose of processing rules is to define what should happen when the patterns are matched.

Formally, a processing rule is a Java class that subclasses the org.apache.commons.digester.Rule interface. Each Rule implements one or more of the following event methods that are called at well-defined times when the matching patterns corresponding to this rule trigger it:

  • begin() - Called when the beginning of the matched XML element is encountered. A data structure containing all of the attributes corresponding to this element are passed as well.
  • body() - Called when nested content (that is not itself XML elements) of the matched element is encountered. Any leading or trailing whitespace will have been removed as part of the parsing process.
  • end() - Called when the ending of the matched XML element is encountered. If nested XML elements that matched other processing rules was included in the body of this element, the appropriate processing rules for the matched rules will have already been completed before this method is called.
  • finish() - Called when the parse has been completed, to give each rule a chance to clean up any temporary data they might have created and cached.

As you are configuring your digester, you can call the addRule() method to register a specific element matching pattern, along with an instance of a Rule class that will have its event handling methods called at the appropriate times, as described above. This mechanism allows you to create Rule implementation classes dynamically, to implement any desired application specific functionality.

In addition, a set of processing rule implementation classes are provided, which deal with many common programming scenarios. These classes include the following:

  • ObjectCreateRule - When the begin() method is called, this rule instantiates a new instance of a specified Java class, and pushes it on the stack. The class name to be used is defaulted according to a parameter passed to this rule's constructor, but can optionally be overridden by a classname passed via the specified attribute to the XML element being processed. When the end() method is called, the top object on the stack (presumably, the one we added in the begin() method) will be popped, and any reference to it (within the Digester) will be discarded.
  • FactoryCreateRule - A variation of ObjectCreateRule that is useful when the Java class with which you wish to create an object instance does not have a no-arguments constructor, or where you wish to perform other setup processing before the object is handed over to the Digester.
  • SetPropertiesRule - When the begin() method is called, the digester uses the standard Java Reflection API to identify any JavaBeans property setter methods (on the object at the top of the digester's stack) who have property names that match the attributes specified on this XML element, and then call them individually, passing the corresponding attribute values. These natural mappings can be overridden. This allows (for example) a class attribute to be mapped correctly. It is recommended that this feature should not be overused - in most cases, it's better to use the standard BeanInfo mechanism. A very common idiom is to define an object create rule, followed by a set properties rule, with the same element matching pattern. This causes the creation of a new Java object, followed by "configuration" of that object's properties based on the attributes of the same XML element that created this object.
  • SetPropertyRule - When the begin() method is called, the digester calls a specified property setter (where the property itself is named by an attribute) with a specified value (where the value is named by another attribute), on the object at the top of the digester's stack. This is useful when your XML file conforms to a particular DTD, and you wish to configure a particular property that does not have a corresponding attribute in the DTD.
  • SetNextRule - When the end() method is called, the digester analyzes the next-to-top element on the stack, looking for a property setter method for a specified property. It then calls this method, passing the object at the top of the stack as an argument. This rule is commonly used to establish one-to-many relationships between the two objects, with the method name commonly being something like "addChild".
  • SetTopRule - When the end() method is called, the digester analyzes the top element on the stack, looking for a property setter method for a specified property. It then calls this method, passing the next-to-top object on the stack as an argument. This rule would be used as an alternative to a SetNextRule, with a typical method name "setParent", if the API supported by your object classes prefers this approach.
  • CallMethodRule - This rule sets up a method call to a named method of the top object on the digester's stack, which will actually take place when the end() method is called. You configure this rule by specifying the name of the method to be called, the number of arguments it takes, and (optionally) the Java class name(s) defining the type(s) of the method's arguments. The actual parameter values, if any, will typically be accumulated from the body content of nested elements within the element that triggered this rule, using the CallParamRule discussed next.
  • CallParamRule - This rule identifies the source of a particular numbered (zero-relative) parameter for a CallMethodRule within which we are nested. You can specify that the parameter value be taken from a particular named attribute, or from the nested body content of this element.
  • NodeCreateRule - A specialized rule that converts part of the tree into a DOM Node and then pushes it onto the stack.

You can create instances of the standard Rule classes and register them by calling digester.addRule(), as described above. However, because their usage is so common, shorthand registration methods are defined for each of the standard rules, directly on the Digester class. For example, the following code sequence:

    Rule rule = new SetNextRule(digester, "addChild",
                                "com.mycompany.mypackage.MyChildClass");
    digester.addRule("a/b/c", rule);

can be replaced by:

    digester.addSetNext("a/b/c", "addChild",
                        "com.mycompany.mypackage.MyChildClass");

Logging

Logging is a vital tool for debugging Digester rulesets. Digester can log copious amounts of debugging information. So, you need to know how logging works before you start using Digester seriously.

Digester uses Apache Commons Logging. This component is not really a logging framework - rather an extensible, configurable bridge. It can be configured to swallow all log messages, to provide very basic logging by itself or to pass logging messages on to more sophisticated logging frameworks. Commons-Logging comes with connectors for many popular logging frameworks. Consult the commons-logging documentation for more information.

Two main logs are used by Digester:

  • SAX-related messages are logged to org.apache.commons.digester.Digester.sax. This log gives information about the basic SAX events received by Digester.
  • org.apache.commons.digester.Digester is used for everything else. You'll probably want to have this log turned up during debugging but turned down during production due to the high message volume.

Complete documentation of how to configure Commons-Logging can be found in the Commons Logging package documentation. However, as a simple example, let's assume that you want to use the SimpleLog implementation that is included in Commons-Logging, and set up Digester to log events from the Digester logger at the DEBUG level, while you want to log events from the Digester.log logger at the INFO level. You can accomplish this by creating a commons-logging.properties file in your classpath (or setting corresponding system properties on the command line that starts your application) with the following contents:

  org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
  org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester=debug
  org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester.sax=info

Usage Examples

Creating a Simple Object Tree

Let's assume that you have two simple JavaBeans, Foo and Bar, with the following method signatures:

  package mypackage;
  public class Foo {
    public void addBar(Bar bar);
    public Bar findBar(int id);
    public Iterator getBars();
    public String getName();
    public void setName(String name);
  }

  package mypackage;
  public class Bar {
    public int getId();
    public void setId(int id);
    public String getTitle();
    public void setTitle(String title);
  }

and you wish to use Digester to parse the following XML document:

  <foo name="The Parent">
    <bar id="123" title="The First Child"/>
    <bar id="456" title="The Second Child"/>
  </foo>

A simple approach will be to use the following Digester in the following way to set up the parsing rules, and then process an input file containing this document:

  Digester digester = new Digester();
  digester.setValidating(false);
  digester.addObjectCreate("foo", "mypackage.Foo");
  digester.addSetProperties("foo");
  digester.addObjectCreate("foo/bar", "mypackage.Bar");
  digester.addSetProperties("foo/bar");
  digester.addSetNext("foo/bar", "addBar", "mypackage.Bar");
  Foo foo = (Foo) digester.parse();

In order, these rules do the following tasks:

  1. When the outermost <foo> element is encountered, create a new instance of mypackage.Foo and push it on to the object stack. At the end of the <foo> element, this object will be popped off of the stack.
  2. Cause properties of the top object on the stack (i.e. the Foo object that was just created and pushed) to be set based on the values of the attributes of this XML element.
  3. When a nested <bar> element is encountered, create a new instance of mypackage.Bar and push it on to the object stack. At the end of the <bar> element, this object will be popped off of the stack (i.e. after the remaining rules matching foo/bar are processed).
  4. Cause properties of the top object on the stack (i.e. the Bar object that was just created and pushed) to be set based on the values of the attributes of this XML element. Note that type conversions are automatically performed (such as String to int for the id property), for all converters registered with the ConvertUtils class from commons-beanutils package.
  5. Cause the addBar method of the next-to-top element on the object stack (which is why this is called the "set next" rule) to be called, passing the element that is on the top of the stack, which must be of type mypackage.Bar. This is the rule that causes the parent/child relationship to be created.

Once the parse is completed, the first object that was ever pushed on to the stack (the Foo object in this case) is returned to you. It will have had its properties set, and all of its child Bar objects created for you.

Processing A Struts Configuration File

As stated earlier, the primary reason that the Digester package was created is because the Struts controller servlet itself needed a robust, flexible, easy to extend mechanism for processing the contents of the struts-config.xml configuration that describes nearly every aspect of a Struts-based application. Because of this, the controller servlet contains a comprehensive, real world, example of how the Digester can be employed for this type of a use case. See the initDigester() method of class org.apache.struts.action.ActionServlet for the code that creates and configures the Digester to be used, and the initMapping() method for where the parsing actually takes place.

(Struts binary and source distributions can be acquired at http://struts.apache.org.)

The following discussion highlights a few of the matching patterns and processing rules that are configured, to illustrate the use of some of the Digester features. First, let's look at how the Digester instance is created and initialized:

    Digester digester = new Digester();
    digester.push(this); // Push controller servlet onto the stack
    digester.setValidating(true);

We see that a new Digester instance is created, and is configured to use a validating parser. Validation will occur against the struts-config_1_0.dtd DTD that is included with Struts (as discussed earlier). In order to provide a means of tracking the configured objects, the controller servlet instance itself will be added to the digester's stack.

    digester.addObjectCreate("struts-config/global-forwards/forward",
                             forwardClass, "className");
    digester.addSetProperties("struts-config/global-forwards/forward");
    digester.addSetNext("struts-config/global-forwards/forward",
                        "addForward",
                        "org.apache.struts.action.ActionForward");
    digester.addSetProperty
      ("struts-config/global-forwards/forward/set-property",
       "property", "value");

The rules created by these lines are used to process the global forward declarations. When a <forward> element is encountered, the following actions take place:

  • A new object instance is created -- the ActionForward instance that will represent this definition. The Java class name defaults to that specified as an initialization parameter (which we have stored in the String variable forwardClass), but can be overridden by using the "className" attribute (if it is present in the XML element we are currently parsing). The new ActionForward instance is pushed onto the stack.
  • The properties of the ActionForward instance (at the top of the stack) are configured based on the attributes of the <forward> element.
  • Nested occurrences of the <set-property> element cause calls to additional property setter methods to occur. This is required only if you have provided a custom implementation of the ActionForward class with additional properties that are not included in the DTD.
  • The addForward() method of the next-to-top object on the stack (i.e. the controller servlet itself) will be called, passing the object at the top of the stack (i.e. the ActionForward instance) as an argument. This causes the global forward to be registered, and as a result of this it will be remembered even after the stack is popped.
  • At the end of the <forward> element, the top element (i.e. the ActionForward instance) will be popped off the stack.

Later on, the digester is actually executed as follows:

    InputStream input =
      getServletContext().getResourceAsStream(config);
    ...
    try {
        digester.parse(input);
        input.close();
    } catch (SAXException e) {
        ... deal with the problem ...
    }

As a result of the call to parse(), all of the configuration information that was defined in the struts-config.xml file is now represented as collections of objects cached within the Struts controller servlet, as well as being exposed as servlet context attributes.

Parsing Body Text In XML Files

The Digester module also allows you to process the nested body text in an XML file, not just the elements and attributes that are encountered. The following example is based on an assumed need to parse the web application deployment descriptor (/WEB-INF/web.xml) for the current web application, and record the configuration information for a particular servlet. To record this information, assume the existence of a bean class with the following method signatures (among others):

  package com.mycompany;
  public class ServletBean {
    public void setServletName(String servletName);
    public void setServletClass(String servletClass);
    public void addInitParam(String name, String value);
  }

We are going to process the web.xml file that declares the controller servlet in a typical Struts-based application (abridged for brevity in this example):

  <web-app>
    ...
    <servlet>
      <servlet-name>action</servlet-name>
      <servlet-class>org.apache.struts.action.ActionServlet<servlet-class>
      <init-param>
        <param-name>application</param-name>
        <param-value>org.apache.struts.example.ApplicationResources<param-value>
      </init-param>
      <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml<param-value>
      </init-param>
    </servlet>
    ...
  </web-app>

Next, lets define some Digester processing rules for this input file:

  digester.addObjectCreate("web-app/servlet",
                           "com.mycompany.ServletBean");
  digester.addCallMethod("web-app/servlet/servlet-name", "setServletName", 0);
  digester.addCallMethod("web-app/servlet/servlet-class",
                         "setServletClass", 0);
  digester.addCallMethod("web-app/servlet/init-param",
                         "addInitParam", 2);
  digester.addCallParam("web-app/servlet/init-param/param-name", 0);
  digester.addCallParam("web-app/servlet/init-param/param-value", 1);

Now, as elements are parsed, the following processing occurs:

  • <servlet> - A new com.mycompany.ServletBean object is created, and pushed on to the object stack.
  • <servlet-name> - The setServletName() method of the top object on the stack (our ServletBean) is called, passing the body content of this element as a single parameter.
  • <servlet-class> - The setServletClass() method of the top object on the stack (our ServletBean) is called, passing the body content of this element as a single parameter.
  • <init-param> - A call to the addInitParam method of the top object on the stack (our ServletBean) is set up, but it is not called yet. The call will be expecting two String parameters, which must be set up by subsequent call parameter rules.
  • <param-name> - The body content of this element is assigned as the first (zero-relative) argument to the call we are setting up.
  • <param-value> - The body content of this element is assigned as the second (zero-relative) argument to the call we are setting up.
  • </init-param> - The call to addInitParam() that we have set up is now executed, which will cause a new name-value combination to be recorded in our bean.
  • <init-param> - The same set of processing rules are fired again, causing a second call to addInitParam() with the second parameter's name and value.
  • </servlet> - The element on the top of the object stack (which should be the ServletBean we pushed earlier) is popped off the object stack.

Namespace Aware Parsing

For digesting XML documents that do not use XML namespaces, the default behavior of Digester, as described above, is generally sufficient. However, if the document you are processing uses namespaces, it is often convenient to have sets of Rule instances that are only matched on elements that use the prefix of a particular namespace. This approach, for example, makes it possible to deal with element names that are the same in different namespaces, but where you want to perform different processing for each namespace.

Digester does not provide full support for namespaces, but does provide sufficient to accomplish most tasks. Enabling digester's namespace support is done by following these steps:

  1. Tell Digester that you will be doing namespace aware parsing, by adding this statement in your initalization of the Digester's properties:
        digester.setNamespaceAware(true);
        
  2. Declare the public namespace URI of the namespace with which following rules will be associated. Note that you do not make any assumptions about the prefix - the XML document author is free to pick whatever prefix they want:
        digester.setRuleNamespaceURI("http://www.mycompany.com/MyNamespace");
        
  3. Add the rules that correspond to this namespace, in the usual way, by calling methods like addObjectCreate() or addSetProperties(). In the matching patterns you specify, use only the local name portion of the elements (i.e. the part after the prefix and associated colon (":") character:
        digester.addObjectCreate("foo/bar", "com.mycompany.MyFoo");
        digester.addSetProperties("foo/bar");
        
  4. Repeat the previous two steps for each additional public namespace URI that should be recognized on this Digester run.

Now, consider that you might wish to digest the following document, using the rules that were set up in the steps above:

<m:foo
   xmlns:m="http://www.mycompany.com/MyNamespace"
   xmlns:y="http://www.yourcompany.com/YourNamespace">

  <m:bar name="My Name" value="My Value"/>

  <y:bar id="123" product="Product Description"/>L

</x:foo>

Note that your object create and set properties rules will be fired for the first occurrence of the bar element, but not the second one. This is because we declared that our rules only matched for the particular namespace we are interested in. Any elements in the document that are associated with other namespaces (or no namespaces at all) will not be processed. In this way, you can easily create rules that digest only the portions of a compound document that they understand, without placing any restrictions on what other content is present in the document.

You might also want to look at Encapsulated Rule Sets if you wish to reuse a particular set of rules, associated with a particular namespace, in more than one application context.

Using Namespace Prefixes In Pattern Matching

Using rules with namespaces is very useful when you have orthogonal rulesets. One ruleset applies to a namespace and is independent of other rulesets applying to other namespaces. However, if your rule logic requires mixed namespaces, then matching namespace prefix patterns might be a better strategy.

When you set the NamespaceAware property to false, digester uses the qualified element name (which includes the namespace prefix) rather than the local name as the patten component for the element. This means that your pattern matches can include namespace prefixes as well as element names. So, rather than create namespace-aware rules, create pattern matches including the namespace prefixes.

For example, (with NamespaceAware false), the pattern 'foo:bar' will match a top level element named 'bar' in the namespace with (local) prefix 'foo'.

Limitations of Digester Namespace support

Digester does not provide general "xpath-compliant" matching; only the namespace attached to the last element in the match path is involved in the matching process. Namespaces attached to parent elements are ignored for matching purposes.

Pluggable Rules Processing

By default, Digester selects the rules that match a particular pattern of nested elements as described under Element Matching Patterns. If you prefer to use different selection policies, however, you can create your own implementation of the org.apache.commons.digester.Rules interface, or subclass the corresponding convenience base class org.apache.commons.digester.RulesBase. Your implementation of the match() method will be called when the processing for a particular element is started or ended, and you must return a List of the rules that are relevant for the current nesting pattern. The order of the rules you return is significant, and should match the order in which rules were initally added.

Your policy for rule selection should generally be sensitive to whether Namespace Aware Parsing is taking place. In general, if namespaceAware is true, you should select only rules that:

  • Are registered for the public namespace URI that corresponds to the prefix being used on this element.
  • Match on the "local name" portion of the element (so that the document creator can use any prefix that they like).

ExtendedBaseRules

ExtendedBaseRules, adds some additional expression syntax for pattern matching to the default mechanism, but it also executes more slowly. See the JavaDocs for more details on the new pattern matching syntax, and suggestions on when this implementation should be used. To use it, simply do the following as part of your Digester initialization:

  Digester digester = ...
  ...
  digester.setRules(new ExtendedBaseRules());
  ...

RegexRules

RegexRules is an advanced Rules implementation which does not build on the default pattern matching rules. It uses a pluggable RegexMatcher implementation to test if a path matches the pattern for a Rule. All matching rules are returned (note that this behaviour differs from longest matching rule of the default pattern matching rules). See the Java Docs for more details.

Example usage:

  Digester digester = ...
  ...
  digester.setRules(new RegexRules(new SimpleRegexMatcher()));
  ...
RegexMatchers

Digester ships only with one RegexMatcher implementation: SimpleRegexMatcher. This implementation is unsophisticated and lacks many good features lacking in more power Regex libraries. There are some good reasons why this approach was adopted. The first is that SimpleRegexMatcher is simple, it is easy to write and runs quickly. The second has to do with the way that RegexRules is intended to be used.

There are many good regex libraries available. (For example Jakarta ORO, Jakarta Regex, GNU Regex and Java 1.4 Regex) Not only do different people have different personal tastes when it comes to regular expression matching but these products all offer different functionality and different strengths.

The pluggable RegexMatcher is a thin bridge designed to adapt other Regex systems. This allows any Regex library the user desires to be plugged in and used just by creating one class. Digester does not (currently) ship with bridges to the major regex (to allow the dependencies required by Digester to be kept to a minimum).

WithDefaultsRulesWrapper

WithDefaultsRulesWrapper allows default Rule instances to be added to any existing Rules implementation. These default Rule instances will be returned for any match for which the wrapped implementation does not return any matches.

For example,

    Rule alpha;
    ...
    WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new BaseRules());
    rules.addDefault(alpha);
    ...
    digester.setRules(rules);
    ...
when a pattern does not match any other rule, then rule alpha will be called.

WithDefaultsRulesWrapper follows the Decorator pattern.

Encapsulated Rule Sets

All of the examples above have described a scenario where the rules to be processed are registered with a Digester instance immediately after it is created. However, this approach makes it difficult to reuse the same set of rules in more than one application environment. Ideally, one could package a set of rules into a single class, which could be easily loaded and registered with a Digester instance in one easy step.

The RuleSet interface (and the convenience base class RuleSetBase) make it possible to do this. In addition, the rule instances registered with a particular RuleSet can optionally be associated with a particular namespace, as described under Namespace Aware Processing.

An example of creating a RuleSet might be something like this:

public class MyRuleSet extends RuleSetBase {

  public MyRuleSet() {
    this("");
  }

  public MyRuleSet(String prefix) {
    super();
    this.prefix = prefix;
    this.namespaceURI = "http://www.mycompany.com/MyNamespace";
  }

  protected String prefix = null;

  public void addRuleInstances(Digester digester) {
    digester.addObjectCreate(prefix + "foo/bar",
      "com.mycompany.MyFoo");
    digester.addSetProperties(prefix + "foo/bar");
  }

}

You might use this RuleSet as follow to initialize a Digester instance:

  Digester digester = new Digester();
  ... configure Digester properties ...
  digester.addRuleSet(new MyRuleSet("baz/"));

A couple of interesting notes about this approach:

  • The application that is using these rules does not need to know anything about the fact that the RuleSet being used is associated with a particular namespace URI. That knowledge is emedded inside the RuleSet class itself.
  • If desired, you could make a set of rules work for more than one namespace URI by providing constructors on the RuleSet to allow this to be specified dynamically.
  • The MyRuleSet example above illustrates another technique that increases reusability -- you can specify (as an argument to the constructor) the leading portion of the matching pattern to be used. In this way, you can construct a Digester that recognizes the same set of nested elements at different nesting levels within an XML document.

Using Named Stacks For Inter-Rule Communication

Digester is based on Rule instances working together to process xml. For anything other than the most trival processing, communication between Rule instances is necessary. Since Rule instances are processed in sequence, this usually means storing an Object somewhere where later instances can retrieve it.

Digester is based on SAX. The most natural data structure to use with SAX based xml processing is the stack. This allows more powerful processes to be specified more simply since the pushing and popping of objects can mimic the nested structure of the xml.

Digester uses two basic stacks: one for the main beans and the other for parameters for method calls. These are inadequate for complex processing where many different Rule instances need to communicate through different channels.

In this case, it is recommended that named stacks are used. In addition to the two basic stacks, Digester allows rules to use an unlimited number of other stacks referred to by an identifying string (the name). (That's where the term named stack comes from.) These stacks are accessed through calls to:

Note: all stack names beginning with org.apache.commons.digester are reserved for future use by the Digester component. It is also recommended that users choose stack names prefixed by the name of their own domain to avoid conflicts with other Rule implementations.

Registering DTDs

Brief (But Still Too Long) Introduction To System and Public Identifiers

A definition for an external entity comes in one of two forms:

  1. SYSTEM system-identifier
  2. PUBLIC public-identifier system-identifier

The system-identifier is an URI from which the resource can be obtained (either directly or indirectly). Many valid URIs may identify the same resource. The public-identifier is an additional free identifier which may be used (by the parser) to locate the resource.

In practice, the weakness with a system-identifier is that most parsers will attempt to interprete this URI as an URL, try to download the resource directly from the URL and stop the parsing if this download fails. So, this means that almost always the URI will have to be an URL from which the declaration can be downloaded.

URLs may be local or remote but if the URL is chosen to be local, it is likely only to function correctly on a small number of machines (which are configured precisely to allow the xml to be parsed). This is usually unsatisfactory and so a universally accessable URL is preferred. This usually means an internet URL.

To recap, in practice the system-identifier will (most likely) be an internet URL. Unfortunately downloading from an internet URL is not only slow but unreliable (since successfully downloading a document from the internet relies on the client being connect to the internet and the server being able to satisfy the request).

The public-identifier is a freely defined name but (in practice) it is strongly recommended that a unique, readable and open format is used (for reasons that should become clear later). A Formal Public Identifier (FPI) is a very common choice. This public identifier is often used to provide a unique and location independent key which can be used to subsistute local resources for remote ones (hint: this is why ;).

By using the second (PUBLIC) form combined with some form of local catalog (which matches public-identifiers to local resources) and where the public-identifier is a unique name and the system-identifier is an internet URL, the practical disadvantages of specifying just a system-identifier can be avoided. Those external entities which have been store locally (on the machine parsing the document) can be identified and used. Only when no local copy exists is it necessary to download the document from the internet URL. This naming scheme is recommended when using Digester.

External Entity Resolution Using Digester

SAX factors out the resolution of external entities into an EntityResolver. Digester supports the use of custom EntityResolver but ships with a simple internal implementation. This implementation allows local URLs to be easily associated with public-identifiers.

For example:

    digester.register("-//Example Dot Com //DTD Sample Example//EN", "assets/sample.dtd");

will make digester return the relative file path assets/sample.dtd whenever an external entity with public id -//Example Dot Com //DTD Sample Example//EN is needed.

Note: This is a simple (but useful) implementation. Greater sophistication requires a custom EntityResolver.

Troubleshooting

Debugging Exceptions

Digester is based on SAX. Digestion throws two kinds of Exception:

  • java.io.IOException
  • org.xml.sax.SAXException

The first is rarely thrown and indicates the kind of fundemental IO exception that developers know all about. The second is thrown by SAX parsers when the processing of the XML cannot be completed. So, to diagnose the cause a certain familiarity with the way that SAX error handling works is very useful.

Diagnosing SAX Exceptions

This is a short, potted guide to SAX error handling strategies. It's not intended as a proper guide to error handling in SAX.

When a SAX parser encounters a problem with the xml (well, ok - sometime after it encounters a problem) it will throw a SAXParseException. This is a subclass of SAXException and contains a bit of extra information about what exactly when wrong - and more importantly, where it went wrong. If you catch an exception of this sort, you can be sure that the problem is with the XML and not Digester or your rules. It is usually a good idea to catch this exception and log the extra information to help with diagnosing the reason for the failure.

General SAXException instances may wrap a causal exception. When exceptions are throw by Digester each of these will be wrapped into a SAXException and rethrown. So, catch these and examine the wrapped exception to diagnose what went wrong.

Frequently Asked Questions

  • Why do I get warnings when using a JAXP 1.1 parser?

    If you're using a JAXP 1.1 parser, you might see the following warning (in your log):

    [WARN] Digester - -Error: JAXP SAXParser property not recognized: http://java.sun.com/xml/jaxp/properties/schemaLanguage
    
    This property is needed for JAXP 1.2 (XML Schema support) as required for the Servlet Spec. 2.4 but is not recognized by JAXP 1.1 parsers. This warning is harmless.

  • Why Doesn't Schema Validation Work With Parser XXX Out Of The Box?

    Schema location and language settings are often need for validation using schemas. Unfortunately, there isn't a single standard approach to how these properties are configured on a parser. Digester tries to guess the parser being used and configure it appropriately but it's not infallible. You might need to grab an instance, configure it and pass it to Digester.

    If you want to support more than one parser in a portable manner, then you'll probably want to take a look at the org.apache.commons.digester.parsers package and add a new class to support the particular parser that's causing problems.

  • Help! I'm Validating Against Schema But Digester Ignores Errors!

    Digester is based on SAX. The convention for SAX parsers is that all errors are reported (to any registered ErrorHandler) but processing continues. Digester (by default) registers its own ErrorHandler implementation. This logs details but does not stop the processing (following the usual convention for SAX based processors).

    This means that the errors reported by the validation of the schema will appear in the Digester logs but the processing will continue. To change this behaviour, call digester.setErrorHandler with a more suitable implementation.

  • Where Can I Find Example Code?

    Digester ships with a sample application: a mapping for the Rich Site Summary format used by many newsfeeds. Download the source distribution to see how it works.

    Digester also ships with a set of examples demonstrating most of the features described in this document. See the "src/examples" subdirectory of the source distribution.

  • When Are You Going To Support Rich Site Summary Version x.y.z?

    The Rich Site Summary application is intended to be a sample application. It works but we have no plans to add support for other versions of the format.

    We would consider donations of standard digester applications but it's unlikely that these would ever be shipped with the base digester distribution. If you want to discuss this, please post to commons dev mailing list

Extensions

Three extension packages are included within the Digester distribution. These provide extra functionality extending the core Digester concepts. Detailed descriptions are contained within their own package documentation.

  • plugins provides a framework for the easy dynamic addition of rules during a Digestion. Rules can trigger the dynamic addition of other rules in an intuitive fashion.
  • substitution provides for manipulation of attributes and element body text before it is processed by the rules.
  • xmlrules package contains a system allowing digester rule configurations to be specifed through an xml file.

Known Limitations

Accessing Public Methods In A Default Access Superclass

There is an issue when invoking public methods contained in a default access superclass. Reflection locates these methods fine and correctly assigns them as public. However, an IllegalAccessException is thrown if the method is invoked.

MethodUtils contains a workaround for this situation. It will attempt to call setAccessible on this method. If this call succeeds, then the method can be invoked as normal. This call will only succeed when the application has sufficient security privilages. If this call fails then a warning will be logged and the method may fail.

Digester uses MethodUtils and so there may be an issue accessing methods of this kind from a high security environment. If you think that you might be experiencing this problem, please ask on the mailing list.

libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/CallMethodRule.java0000644000175000017500000006332211226450007032016 0ustar twernertwerner/* $Id: CallMethodRule.java 499574 2007-01-24 21:25:51Z nuttycom $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.MethodUtils; import org.xml.sax.Attributes; /** *

Rule implementation that calls a method on an object on the stack * (normally the top/parent object), passing arguments collected from * subsequent CallParamRule rules or from the body of this * element.

* *

By using {@link #CallMethodRule(String methodName)} * a method call can be made to a method which accepts no * arguments.

* *

Incompatible method parameter types are converted * using org.apache.commons.beanutils.ConvertUtils. *

* *

This rule now uses {@link MethodUtils#invokeMethod} by default. * This increases the kinds of methods successfully and allows primitives * to be matched by passing in wrapper classes. * There are rare cases when {@link MethodUtils#invokeExactMethod} * (the old default) is required. * This method is much stricter in it's reflection. * Setting the UseExactMatch to true reverts to the use of this * method.

* *

Note that the target method is invoked when the end of * the tag the CallMethodRule fired on is encountered, not when the * last parameter becomes available. This implies that rules which fire on * tags nested within the one associated with the CallMethodRule will * fire before the CallMethodRule invokes the target method. This behaviour is * not configurable.

* *

Note also that if a CallMethodRule is expecting exactly one parameter * and that parameter is not available (eg CallParamRule is used with an * attribute name but the attribute does not exist) then the method will * not be invoked. If a CallMethodRule is expecting more than one parameter, * then it is always invoked, regardless of whether the parameters were * available or not; missing parameters are converted to the appropriate target * type by calling ConvertUtils.convert. Note that the default ConvertUtils * converters for the String type returns a null when passed a null, meaning * that CallMethodRule will passed null for all String parameters for which * there is no parameter info available from the XML. However parameters of * type Float and Integer will be passed a real object containing a zero value * as that is the output of the default ConvertUtils converters for those * types when passed a null. You can register custom converters to change * this behaviour; see the beautils library documentation for more info.

* *

Note that when a constructor is used with paramCount=0, indicating that * the body of the element is to be passed to the target method, an empty * element will cause an empty string to be passed to the target method, * not null. And if automatic type conversion is being applied (ie if the * target function takes something other than a string as a parameter) then * the conversion will fail if the converter class does not accept an empty * string as valid input.

* *

CallMethodRule has a design flaw which can cause it to fail under * certain rule configurations. All CallMethodRule instances share a single * parameter stack, and all CallParamRule instances simply store their data * into the parameter-info structure that is on the top of the stack. This * means that two CallMethodRule instances cannot be associated with the * same pattern without getting scrambled parameter data. This same issue * also applies when a CallMethodRule matches some element X, a different * CallMethodRule matches a child element Y and some of the CallParamRules * associated with the first CallMethodRule match element Y or one of its * child elements. This issue has been present since the very first release * of Digester. Note, however, that this configuration of CallMethodRule * instances is not commonly required.

*/ public class CallMethodRule extends Rule { // ----------------------------------------------------------- Constructors /** * Construct a "call method" rule with the specified method name. The * parameter types (if any) default to java.lang.String. * * @param digester The associated Digester * @param methodName Method name of the parent method to call * @param paramCount The number of parameters to collect, or * zero for a single argument from the body of this element. * * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #CallMethodRule(String methodName,int paramCount)} instead. */ public CallMethodRule(Digester digester, String methodName, int paramCount) { this(methodName, paramCount); } /** * Construct a "call method" rule with the specified method name. * * @param digester The associated Digester * @param methodName Method name of the parent method to call * @param paramCount The number of parameters to collect, or * zero for a single argument from the body of ths element * @param paramTypes The Java class names of the arguments * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #CallMethodRule(String methodName,int paramCount, String [] paramTypes)} instead. */ public CallMethodRule(Digester digester, String methodName, int paramCount, String paramTypes[]) { this(methodName, paramCount, paramTypes); } /** * Construct a "call method" rule with the specified method name. * * @param digester The associated Digester * @param methodName Method name of the parent method to call * @param paramCount The number of parameters to collect, or * zero for a single argument from the body of ths element * @param paramTypes The Java classes that represent the * parameter types of the method arguments * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean.TYPE * for a boolean parameter) * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #CallMethodRule(String methodName,int paramCount, Class [] paramTypes)} instead. */ public CallMethodRule(Digester digester, String methodName, int paramCount, Class paramTypes[]) { this(methodName, paramCount, paramTypes); } /** * Construct a "call method" rule with the specified method name. The * parameter types (if any) default to java.lang.String. * * @param methodName Method name of the parent method to call * @param paramCount The number of parameters to collect, or * zero for a single argument from the body of this element. */ public CallMethodRule(String methodName, int paramCount) { this(0, methodName, paramCount); } /** * Construct a "call method" rule with the specified method name. The * parameter types (if any) default to java.lang.String. * * @param targetOffset location of the target object. Positive numbers are * relative to the top of the digester object stack. Negative numbers * are relative to the bottom of the stack. Zero implies the top * object on the stack. * @param methodName Method name of the parent method to call * @param paramCount The number of parameters to collect, or * zero for a single argument from the body of this element. */ public CallMethodRule(int targetOffset, String methodName, int paramCount) { this.targetOffset = targetOffset; this.methodName = methodName; this.paramCount = paramCount; if (paramCount == 0) { this.paramTypes = new Class[] { String.class }; } else { this.paramTypes = new Class[paramCount]; for (int i = 0; i < this.paramTypes.length; i++) { this.paramTypes[i] = String.class; } } } /** * Construct a "call method" rule with the specified method name. * The method should accept no parameters. * * @param methodName Method name of the parent method to call */ public CallMethodRule(String methodName) { this(0, methodName, 0, (Class[]) null); } /** * Construct a "call method" rule with the specified method name. * The method should accept no parameters. * * @param targetOffset location of the target object. Positive numbers are * relative to the top of the digester object stack. Negative numbers * are relative to the bottom of the stack. Zero implies the top * object on the stack. * @param methodName Method name of the parent method to call */ public CallMethodRule(int targetOffset, String methodName) { this(targetOffset, methodName, 0, (Class[]) null); } /** * Construct a "call method" rule with the specified method name and * parameter types. If paramCount is set to zero the rule * will use the body of this element as the single argument of the * method, unless paramTypes is null or empty, in this * case the rule will call the specified method with no arguments. * * @param methodName Method name of the parent method to call * @param paramCount The number of parameters to collect, or * zero for a single argument from the body of ths element * @param paramTypes The Java class names of the arguments * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) */ public CallMethodRule( String methodName, int paramCount, String paramTypes[]) { this(0, methodName, paramCount, paramTypes); } /** * Construct a "call method" rule with the specified method name and * parameter types. If paramCount is set to zero the rule * will use the body of this element as the single argument of the * method, unless paramTypes is null or empty, in this * case the rule will call the specified method with no arguments. * * @param targetOffset location of the target object. Positive numbers are * relative to the top of the digester object stack. Negative numbers * are relative to the bottom of the stack. Zero implies the top * object on the stack. * @param methodName Method name of the parent method to call * @param paramCount The number of parameters to collect, or * zero for a single argument from the body of ths element * @param paramTypes The Java class names of the arguments * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) */ public CallMethodRule( int targetOffset, String methodName, int paramCount, String paramTypes[]) { this.targetOffset = targetOffset; this.methodName = methodName; this.paramCount = paramCount; if (paramTypes == null) { this.paramTypes = new Class[paramCount]; for (int i = 0; i < this.paramTypes.length; i++) { this.paramTypes[i] = String.class; } } else { // copy the parameter class names into an array // the classes will be loaded when the digester is set this.paramClassNames = new String[paramTypes.length]; for (int i = 0; i < this.paramClassNames.length; i++) { this.paramClassNames[i] = paramTypes[i]; } } } /** * Construct a "call method" rule with the specified method name and * parameter types. If paramCount is set to zero the rule * will use the body of this element as the single argument of the * method, unless paramTypes is null or empty, in this * case the rule will call the specified method with no arguments. * * @param methodName Method name of the parent method to call * @param paramCount The number of parameters to collect, or * zero for a single argument from the body of ths element * @param paramTypes The Java classes that represent the * parameter types of the method arguments * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean.TYPE * for a boolean parameter) */ public CallMethodRule( String methodName, int paramCount, Class paramTypes[]) { this(0, methodName, paramCount, paramTypes); } /** * Construct a "call method" rule with the specified method name and * parameter types. If paramCount is set to zero the rule * will use the body of this element as the single argument of the * method, unless paramTypes is null or empty, in this * case the rule will call the specified method with no arguments. * * @param targetOffset location of the target object. Positive numbers are * relative to the top of the digester object stack. Negative numbers * are relative to the bottom of the stack. Zero implies the top * object on the stack. * @param methodName Method name of the parent method to call * @param paramCount The number of parameters to collect, or * zero for a single argument from the body of ths element * @param paramTypes The Java classes that represent the * parameter types of the method arguments * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean.TYPE * for a boolean parameter) */ public CallMethodRule( int targetOffset, String methodName, int paramCount, Class paramTypes[]) { this.targetOffset = targetOffset; this.methodName = methodName; this.paramCount = paramCount; if (paramTypes == null) { this.paramTypes = new Class[paramCount]; for (int i = 0; i < this.paramTypes.length; i++) { this.paramTypes[i] = String.class; } } else { this.paramTypes = new Class[paramTypes.length]; for (int i = 0; i < this.paramTypes.length; i++) { this.paramTypes[i] = paramTypes[i]; } } } // ----------------------------------------------------- Instance Variables /** * The body text collected from this element. */ protected String bodyText = null; /** * location of the target object for the call, relative to the * top of the digester object stack. The default value of zero * means the target object is the one on top of the stack. */ protected int targetOffset = 0; /** * The method name to call on the parent object. */ protected String methodName = null; /** * The number of parameters to collect from MethodParam rules. * If this value is zero, a single parameter will be collected from the * body of this element. */ protected int paramCount = 0; /** * The parameter types of the parameters to be collected. */ protected Class paramTypes[] = null; /** * The names of the classes of the parameters to be collected. * This attribute allows creation of the classes to be postponed until the digester is set. */ private String paramClassNames[] = null; /** * Should MethodUtils.invokeExactMethod be used for reflection. */ protected boolean useExactMatch = false; // --------------------------------------------------------- Public Methods /** * Should MethodUtils.invokeExactMethod * be used for the reflection. */ public boolean getUseExactMatch() { return useExactMatch; } /** * Set whether MethodUtils.invokeExactMethod * should be used for the reflection. */ public void setUseExactMatch(boolean useExactMatch) { this.useExactMatch = useExactMatch; } /** * Set the associated digester. * If needed, this class loads the parameter classes from their names. */ public void setDigester(Digester digester) { // call superclass super.setDigester(digester); // if necessary, load parameter classes if (this.paramClassNames != null) { this.paramTypes = new Class[paramClassNames.length]; for (int i = 0; i < this.paramClassNames.length; i++) { try { this.paramTypes[i] = digester.getClassLoader().loadClass(this.paramClassNames[i]); } catch (ClassNotFoundException e) { // use the digester log digester.getLogger().error("(CallMethodRule) Cannot load class " + this.paramClassNames[i], e); this.paramTypes[i] = null; // Will cause NPE later } } } } /** * Process the start of this element. * * @param attributes The attribute list for this element */ public void begin(Attributes attributes) throws Exception { // Push an array to capture the parameter values if necessary if (paramCount > 0) { Object parameters[] = new Object[paramCount]; for (int i = 0; i < parameters.length; i++) { parameters[i] = null; } digester.pushParams(parameters); } } /** * Process the body text of this element. * * @param bodyText The body text of this element */ public void body(String bodyText) throws Exception { if (paramCount == 0) { this.bodyText = bodyText.trim(); } } /** * Process the end of this element. */ public void end() throws Exception { // Retrieve or construct the parameter values array Object parameters[] = null; if (paramCount > 0) { parameters = (Object[]) digester.popParams(); if (digester.log.isTraceEnabled()) { for (int i=0,size=parameters.length;i= 0) { target = digester.peek(targetOffset); } else { target = digester.peek( digester.getCount() + targetOffset ); } if (target == null) { StringBuffer sb = new StringBuffer(); sb.append("[CallMethodRule]{"); sb.append(digester.match); sb.append("} Call target is null ("); sb.append("targetOffset="); sb.append(targetOffset); sb.append(",stackdepth="); sb.append(digester.getCount()); sb.append(")"); throw new org.xml.sax.SAXException(sb.toString()); } // Invoke the required method on the top object if (digester.log.isDebugEnabled()) { StringBuffer sb = new StringBuffer("[CallMethodRule]{"); sb.append(digester.match); sb.append("} Call "); sb.append(target.getClass().getName()); sb.append("."); sb.append(methodName); sb.append("("); for (int i = 0; i < paramValues.length; i++) { if (i > 0) { sb.append(","); } if (paramValues[i] == null) { sb.append("null"); } else { sb.append(paramValues[i].toString()); } sb.append("/"); if (paramTypes[i] == null) { sb.append("null"); } else { sb.append(paramTypes[i].getName()); } } sb.append(")"); digester.log.debug(sb.toString()); } Object result = null; if (useExactMatch) { // invoke using exact match result = MethodUtils.invokeExactMethod(target, methodName, paramValues, paramTypes); } else { // invoke using fuzzier match result = MethodUtils.invokeMethod(target, methodName, paramValues, paramTypes); } processMethodCallResult(result); } /** * Clean up after parsing is complete. */ public void finish() throws Exception { bodyText = null; } /** * Subclasses may override this method to perform additional processing of the * invoked method's result. * * @param result the Object returned by the method invoked, possibly null */ protected void processMethodCallResult(Object result) { // do nothing } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("CallMethodRule["); sb.append("methodName="); sb.append(methodName); sb.append(", paramCount="); sb.append(paramCount); sb.append(", paramTypes={"); if (paramTypes != null) { for (int i = 0; i < paramTypes.length; i++) { if (i > 0) { sb.append(", "); } sb.append(paramTypes[i].getName()); } } sb.append("}"); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/SetPropertiesRule.java0000644000175000017500000002775111226450007032620 0ustar twernertwerner/* $Id: SetPropertiesRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.HashMap; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.PropertyUtils; import org.xml.sax.Attributes; /** *

Rule implementation that sets properties on the object at the top of the * stack, based on attributes with corresponding names.

* *

This rule supports custom mapping of attribute names to property names. * The default mapping for particular attributes can be overridden by using * {@link #SetPropertiesRule(String[] attributeNames, String[] propertyNames)}. * This allows attributes to be mapped to properties with different names. * Certain attributes can also be marked to be ignored.

*/ public class SetPropertiesRule extends Rule { // ----------------------------------------------------------- Constructors /** * Default constructor sets only the the associated Digester. * * @param digester The digester with which this rule is associated * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #SetPropertiesRule()} instead. */ public SetPropertiesRule(Digester digester) { this(); } /** * Base constructor. */ public SetPropertiesRule() { // nothing to set up } /** *

Convenience constructor overrides the mapping for just one property.

* *

For details about how this works, see * {@link #SetPropertiesRule(String[] attributeNames, String[] propertyNames)}.

* * @param attributeName map this attribute * @param propertyName to a property with this name */ public SetPropertiesRule(String attributeName, String propertyName) { attributeNames = new String[1]; attributeNames[0] = attributeName; propertyNames = new String[1]; propertyNames[0] = propertyName; } /** *

Constructor allows attribute->property mapping to be overriden.

* *

Two arrays are passed in. * One contains the attribute names and the other the property names. * The attribute name / property name pairs are match by position * In order words, the first string in the attribute name list matches * to the first string in the property name list and so on.

* *

If a property name is null or the attribute name has no matching * property name, then this indicates that the attibute should be ignored.

* *
Example One
*

The following constructs a rule that maps the alt-city * attribute to the city property and the alt-state * to the state property. * All other attributes are mapped as usual using exact name matching. *

     *      SetPropertiesRule(
     *                new String[] {"alt-city", "alt-state"}, 
     *                new String[] {"city", "state"});
     * 
* *
Example Two
*

The following constructs a rule that maps the class * attribute to the className property. * The attribute ignore-me is not mapped. * All other attributes are mapped as usual using exact name matching. *

     *      SetPropertiesRule(
     *                new String[] {"class", "ignore-me"}, 
     *                new String[] {"className"});
     * 
* * @param attributeNames names of attributes to map * @param propertyNames names of properties mapped to */ public SetPropertiesRule(String[] attributeNames, String[] propertyNames) { // create local copies this.attributeNames = new String[attributeNames.length]; for (int i=0, size=attributeNames.length; iproperty mapping */ private String [] attributeNames; /** * Property names used to override natural attribute->property mapping */ private String [] propertyNames; /** * Used to determine whether the parsing should fail if an property specified * in the XML is missing from the bean. Default is true for backward compatibility. */ private boolean ignoreMissingProperty = true; // --------------------------------------------------------- Public Methods /** * Process the beginning of this element. * * @param attributes The attribute list of this element */ public void begin(Attributes attributes) throws Exception { // Build a set of attribute names and corresponding values HashMap values = new HashMap(); // set up variables for custom names mappings int attNamesLength = 0; if (attributeNames != null) { attNamesLength = attributeNames.length; } int propNamesLength = 0; if (propertyNames != null) { propNamesLength = propertyNames.length; } for (int i = 0; i < attributes.getLength(); i++) { String name = attributes.getLocalName(i); if ("".equals(name)) { name = attributes.getQName(i); } String value = attributes.getValue(i); // we'll now check for custom mappings for (int n = 0; nAdd an additional attribute name to property name mapping. * This is intended to be used from the xml rules. */ public void addAlias(String attributeName, String propertyName) { // this is a bit tricky. // we'll need to resize the array. // probably should be synchronized but digester's not thread safe anyway if (attributeNames == null) { attributeNames = new String[1]; attributeNames[0] = attributeName; propertyNames = new String[1]; propertyNames[0] = propertyName; } else { int length = attributeNames.length; String [] tempAttributes = new String[length + 1]; for (int i=0; iAre attributes found in the xml without matching properties to be ignored? *

* If false, the parsing will interrupt with an NoSuchMethodException * if a property specified in the XML is not found. The default is true. *

* @return true if skipping the unmatched attributes. */ public boolean isIgnoreMissingProperty() { return this.ignoreMissingProperty; } /** * Sets whether attributes found in the xml without matching properties * should be ignored. * If set to false, the parsing will throw an NoSuchMethodException * if an unmatched * attribute is found. This allows to trap misspellings in the XML file. * @param ignoreMissingProperty false to stop the parsing on unmatched attributes. */ public void setIgnoreMissingProperty(boolean ignoreMissingProperty) { this.ignoreMissingProperty = ignoreMissingProperty; } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/RegexMatcher.java0000644000175000017500000000272511226450007031530 0ustar twernertwerner/* $Id: RegexMatcher.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** * Regular expression matching strategy for RegexRules. * * @since 1.5 */ abstract public class RegexMatcher { /** * Returns true if the given pattern matches the given path * according to the regex algorithm that this strategy applies. * * @param pathPattern the standard digester path representing the element * @param rulePattern the regex pattern the path will be tested against * @return true if the given pattern matches the given path */ abstract public boolean match(String pathPattern, String rulePattern); } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/ObjectCreationFactory.java0000644000175000017500000000414211226450007033370 0ustar twernertwerner/* $Id: ObjectCreationFactory.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; /** *

Interface for use with {@link FactoryCreateRule}. * The rule calls {@link #createObject} to create an object * to be pushed onto the Digester stack * whenever it is matched.

* *

{@link AbstractObjectCreationFactory} is an abstract * implementation suitable for creating anonymous * ObjectCreationFactory implementations. */ public interface ObjectCreationFactory { /** *

Factory method called by {@link FactoryCreateRule} to supply an * object based on the element's attributes. * * @param attributes the element's attributes * * @throws Exception any exception thrown will be propagated upwards */ public Object createObject(Attributes attributes) throws Exception; /** *

Returns the {@link Digester} that was set by the * {@link FactoryCreateRule} upon initialization. */ public Digester getDigester(); /** *

Set the {@link Digester} to allow the implementation to do logging, * classloading based on the digester's classloader, etc. * * @param digester parent Digester object */ public void setDigester(Digester digester); } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/RuleSetBase.java0000644000175000017500000000427511226450007031332 0ustar twernertwerner/* $Id: RuleSetBase.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** *

Convenience base class that implements the {@link RuleSet} interface. * Concrete implementations should list all of their actual rule creation * logic in the addRuleSet() implementation.

*/ public abstract class RuleSetBase implements RuleSet { // ----------------------------------------------------- Instance Variables /** * The namespace URI that all Rule instances created by this RuleSet * will be associated with. */ protected String namespaceURI = null; // ------------------------------------------------------------- Properties /** * Return the namespace URI that will be applied to all Rule instances * created from this RuleSet. */ public String getNamespaceURI() { return (this.namespaceURI); } // --------------------------------------------------------- Public Methods /** * Add the set of Rule instances defined in this RuleSet to the * specified Digester instance, associating them with * our namespace URI (if any). This method should only be called * by a Digester instance. * * @param digester Digester instance to which the new Rule instances * should be added. */ public abstract void addRuleInstances(Digester digester); } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/ParserFeatureSetterFactory.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/ParserFeatureSetterFactory.0000644000175000017500000000542311226450007033575 0ustar twernertwerner/* $Id: ParserFeatureSetterFactory.java 476205 2006-11-17 16:43:10Z dennisl $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.Properties; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.commons.digester.parser.GenericParser; import org.apache.commons.digester.parser.XercesParser; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; /** * Creates a SAXParser based on the underlying parser. * Allows logical properties depending on logical parser versions * to be set. * * @since 1.6 */ public class ParserFeatureSetterFactory { /** * true is Xerces is used. */ private static boolean isXercesUsed; static { try{ // Use reflection to avoid a build dependency with Xerces. // // Note that this does not detect Sun's repackaging of // Xerces as com.sun.org.apache.xerces; perhaps it should? SAXParserFactory factory = SAXParserFactory.newInstance(); if (factory.getClass().getName().startsWith("org.apache.xerces")) { isXercesUsed = true; } } catch (Exception ex) { isXercesUsed = false; } } /** * Create a new SAXParser * @param properties (logical) properties to be set on parser * @return a SAXParser configured based on the underlying * parser implementation. */ public static SAXParser newSAXParser(Properties properties) throws ParserConfigurationException, SAXException, SAXNotRecognizedException, SAXNotSupportedException { if (isXercesUsed){ return XercesParser.newSAXParser(properties); } else { return GenericParser.newSAXParser(properties); } } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/RegexRules.java0000644000175000017500000001237611226450007031242 0ustar twernertwerner/* $Id: RegexRules.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** *

Rules implementation that uses regular expression matching for paths.

* *

The regex implementation is pluggable, allowing different strategies to be used. * The basic way that this class work does not vary. * All patterns are tested to see if they match the path using the regex matcher. * All those that do are return in the order which the rules were added.

* * @since 1.5 */ public class RegexRules extends AbstractRulesImpl { // --------------------------------------------------------- Fields /** All registered Rule's */ private ArrayList registeredRules = new ArrayList(); /** The regex strategy used by this RegexRules */ private RegexMatcher matcher; // --------------------------------------------------------- Constructor /** * Construct sets the Regex matching strategy. * * @param matcher the regex strategy to be used, not null * @throws IllegalArgumentException if the strategy is null */ public RegexRules(RegexMatcher matcher) { setRegexMatcher(matcher); } // --------------------------------------------------------- Properties /** * Gets the current regex matching strategy. */ public RegexMatcher getRegexMatcher() { return matcher; } /** * Sets the current regex matching strategy. * * @param matcher use this RegexMatcher, not null * @throws IllegalArgumentException if the strategy is null */ public void setRegexMatcher(RegexMatcher matcher) { if (matcher == null) { throw new IllegalArgumentException("RegexMatcher must not be null."); } this.matcher = matcher; } // --------------------------------------------------------- Public Methods /** * Register a new Rule instance matching the specified pattern. * * @param pattern Nesting pattern to be matched for this Rule * @param rule Rule instance to be registered */ protected void registerRule(String pattern, Rule rule) { registeredRules.add(new RegisteredRule(pattern, rule)); } /** * Clear all existing Rule instance registrations. */ public void clear() { registeredRules.clear(); } /** * Finds matching rules by using current regex matching strategy. * The rule associated with each path that matches is added to the list of matches. * The order of matching rules is the same order that they were added. * * @param namespaceURI Namespace URI for which to select matching rules, * or null to match regardless of namespace URI * @param pattern Nesting pattern to be matched * @return a list of matching Rule's */ public List match(String namespaceURI, String pattern) { // // not a particularly quick implementation // regex is probably going to be slower than string equality // so probably should have a set of strings // and test each only once // // XXX FIX ME - Time And Optimize // ArrayList rules = new ArrayList(registeredRules.size()); Iterator it = registeredRules.iterator(); while (it.hasNext()) { RegisteredRule next = (RegisteredRule) it.next(); if (matcher.match(pattern, next.pattern)) { rules.add(next.rule); } } return rules; } /** * Return a List of all registered Rule instances, or a zero-length List * if there are no registered Rule instances. If more than one Rule * instance has been registered, they must be returned * in the order originally registered through the add() * method. */ public List rules() { ArrayList rules = new ArrayList(registeredRules.size()); Iterator it = registeredRules.iterator(); while (it.hasNext()) { rules.add(((RegisteredRule) it.next()).rule); } return rules; } /** Used to associate rules with paths in the rules list */ private class RegisteredRule { String pattern; Rule rule; RegisteredRule(String pattern, Rule rule) { this.pattern = pattern; this.rule = rule; } } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/Rules.java0000644000175000017500000001001011226450007030226 0ustar twernertwerner/* $Id: Rules.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.List; /** * Public interface defining a collection of Rule instances (and corresponding * matching patterns) plus an implementation of a matching policy that selects * the rules that match a particular pattern of nested elements discovered * during parsing. */ public interface Rules { // ------------------------------------------------------------- Properties /** * Return the Digester instance with which this Rules instance is * associated. */ public Digester getDigester(); /** * Set the Digester instance with which this Rules instance is associated. * * @param digester The newly associated Digester instance */ public void setDigester(Digester digester); /** * Return the namespace URI that will be applied to all subsequently * added Rule objects. */ public String getNamespaceURI(); /** * Set the namespace URI that will be applied to all subsequently * added Rule objects. * * @param namespaceURI Namespace URI that must match on all * subsequently added rules, or null for matching * regardless of the current namespace URI */ public void setNamespaceURI(String namespaceURI); // --------------------------------------------------------- Public Methods /** * Register a new Rule instance matching the specified pattern. * * @param pattern Nesting pattern to be matched for this Rule * @param rule Rule instance to be registered */ public void add(String pattern, Rule rule); /** * Clear all existing Rule instance registrations. */ public void clear(); /** * Return a List of all registered Rule instances that match the specified * nesting pattern, or a zero-length List if there are no matches. If more * than one Rule instance matches, they must be returned * in the order originally registered through the add() * method. * * @param pattern Nesting pattern to be matched * * @deprecated Call match(namespaceURI,pattern) instead. */ public List match(String pattern); /** * Return a List of all registered Rule instances that match the specified * nesting pattern, or a zero-length List if there are no matches. If more * than one Rule instance matches, they must be returned * in the order originally registered through the add() * method. * * @param namespaceURI Namespace URI for which to select matching rules, * or null to match regardless of namespace URI * @param pattern Nesting pattern to be matched */ public List match(String namespaceURI, String pattern); /** * Return a List of all registered Rule instances, or a zero-length List * if there are no registered Rule instances. If more than one Rule * instance has been registered, they must be returned * in the order originally registered through the add() * method. */ public List rules(); } ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/BeanPropertySetterRule.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/BeanPropertySetterRule.java0000644000175000017500000001546511226450007033610 0ustar twernertwerner/* $Id: BeanPropertySetterRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.beans.PropertyDescriptor; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.beanutils.DynaProperty; import org.apache.commons.beanutils.PropertyUtils; /** *

Rule implements sets a bean property on the top object * to the body text.

* *

The property set:

*
  • can be specified when the rule is created
  • *
  • or can match the current element when the rule is called.
* *

Using the second method and the {@link ExtendedBaseRules} child match * pattern, all the child elements can be automatically mapped to properties * on the parent object.

*/ public class BeanPropertySetterRule extends Rule { // ----------------------------------------------------------- Constructors /** *

Construct rule that sets the given property from the body text.

* * @param digester associated Digester * @param propertyName name of property to set * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #BeanPropertySetterRule(String propertyName)} instead. */ public BeanPropertySetterRule(Digester digester, String propertyName) { this(propertyName); } /** *

Construct rule that automatically sets a property from the body text. * *

This construct creates a rule that sets the property * on the top object named the same as the current element. * * @param digester associated Digester * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #BeanPropertySetterRule()} instead. */ public BeanPropertySetterRule(Digester digester) { this(); } /** *

Construct rule that sets the given property from the body text.

* * @param propertyName name of property to set */ public BeanPropertySetterRule(String propertyName) { this.propertyName = propertyName; } /** *

Construct rule that automatically sets a property from the body text. * *

This construct creates a rule that sets the property * on the top object named the same as the current element. */ public BeanPropertySetterRule() { this((String)null); } // ----------------------------------------------------- Instance Variables /** * Set this property on the top object. */ protected String propertyName = null; /** * The body text used to set the property. */ protected String bodyText = null; // --------------------------------------------------------- Public Methods /** * Process the body text of this element. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param text The text of the body of this element */ public void body(String namespace, String name, String text) throws Exception { // log some debugging information if (digester.log.isDebugEnabled()) { digester.log.debug("[BeanPropertySetterRule]{" + digester.match + "} Called with text '" + text + "'"); } bodyText = text.trim(); } /** * Process the end of this element. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * * @exception NoSuchMethodException if the bean does not * have a writeable property of the specified name */ public void end(String namespace, String name) throws Exception { String property = propertyName; if (property == null) { // If we don't have a specific property name, // use the element name. property = name; } // Get a reference to the top object Object top = digester.peek(); // log some debugging information if (digester.log.isDebugEnabled()) { digester.log.debug("[BeanPropertySetterRule]{" + digester.match + "} Set " + top.getClass().getName() + " property " + property + " with text " + bodyText); } // Force an exception if the property does not exist // (BeanUtils.setProperty() silently returns in this case) if (top instanceof DynaBean) { DynaProperty desc = ((DynaBean) top).getDynaClass().getDynaProperty(property); if (desc == null) { throw new NoSuchMethodException ("Bean has no property named " + property); } } else /* this is a standard JavaBean */ { PropertyDescriptor desc = PropertyUtils.getPropertyDescriptor(top, property); if (desc == null) { throw new NoSuchMethodException ("Bean has no property named " + property); } } // Set the property (with conversion as necessary) BeanUtils.setProperty(top, property, bodyText); } /** * Clean up after parsing is complete. */ public void finish() throws Exception { bodyText = null; } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("BeanPropertySetterRule["); sb.append("propertyName="); sb.append(propertyName); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/Rule.java0000644000175000017500000002060711226450007030060 0ustar twernertwerner/* $Id: Rule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; /** * Concrete implementations of this class implement actions to be taken when * a corresponding nested pattern of XML elements has been matched. *

* Writing a custom Rule is considered perfectly normal when using Digester, * and is encouraged whenever the default set of Rule classes don't meet your * requirements; the digester framework can help process xml even when the * built-in rules aren't quite what is needed. Creating a custom Rule is * just as easy as subclassing javax.servlet.http.HttpServlet for webapps, * or javax.swing.Action for GUI applications. *

* If a rule wishes to manipulate a digester stack (the default object stack, * a named stack, or the parameter stack) then it should only ever push * objects in the rule's begin method and always pop exactly the same * number of objects off the stack during the rule's end method. Of course * peeking at the objects on the stacks can be done from anywhere. *

* Rule objects should be stateless, ie they should not update any instance * member during the parsing process. A rule instance that changes state * will encounter problems if invoked in a "nested" manner; this can happen * if the same instance is added to digester multiple times or if a * wildcard pattern is used which can match both an element and a child of the * same element. The digester object stack and named stacks should be used to * store any state that a rule requires, making the rule class safe under all * possible uses. */ public abstract class Rule { // ----------------------------------------------------------- Constructors /** * Constructor sets the associated Digester. * * @param digester The digester with which this rule is associated * @deprecated The digester instance is now set in the {@link Digester#addRule} method. Use {@link #Rule()} instead. */ public Rule(Digester digester) { super(); setDigester(digester); } /** *

Base constructor. * Now the digester will be set when the rule is added.

*/ public Rule() {} // ----------------------------------------------------- Instance Variables /** * The Digester with which this Rule is associated. */ protected Digester digester = null; /** * The namespace URI for which this Rule is relevant, if any. */ protected String namespaceURI = null; // ------------------------------------------------------------- Properties /** * Return the Digester with which this Rule is associated. */ public Digester getDigester() { return (this.digester); } /** * Set the Digester with which this Rule is associated. */ public void setDigester(Digester digester) { this.digester = digester; } /** * Return the namespace URI for which this Rule is relevant, if any. */ public String getNamespaceURI() { return (this.namespaceURI); } /** * Set the namespace URI for which this Rule is relevant, if any. * * @param namespaceURI Namespace URI for which this Rule is relevant, * or null to match independent of namespace. */ public void setNamespaceURI(String namespaceURI) { this.namespaceURI = namespaceURI; } // --------------------------------------------------------- Public Methods /** * This method is called when the beginning of a matching XML element * is encountered. * * @param attributes The attribute list of this element * @deprecated Use the {@link #begin(String,String,Attributes) begin} * method with namespace and name * parameters instead. */ public void begin(Attributes attributes) throws Exception { ; // The default implementation does nothing } /** * This method is called when the beginning of a matching XML element * is encountered. The default implementation delegates to the deprecated * method {@link #begin(Attributes) begin} without the * namespace and name parameters, to retain * backwards compatibility. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param attributes The attribute list of this element * @since Digester 1.4 */ public void begin(String namespace, String name, Attributes attributes) throws Exception { begin(attributes); } /** * This method is called when the body of a matching XML element * is encountered. If the element has no body, this method is * called with an empty string as the body text. * * @param text The text of the body of this element * @deprecated Use the {@link #body(String,String,String) body} method * with namespace and name parameters * instead. */ public void body(String text) throws Exception { ; // The default implementation does nothing } /** * This method is called when the body of a matching XML element is * encountered. If the element has no body, this method is * called with an empty string as the body text. *

* The default implementation delegates to the deprecated method * {@link #body(String) body} without the namespace and * name parameters, to retain backwards compatibility. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param text The text of the body of this element * @since Digester 1.4 */ public void body(String namespace, String name, String text) throws Exception { body(text); } /** * This method is called when the end of a matching XML element * is encountered. * * @deprecated Use the {@link #end(String,String) end} method with * namespace and name parameters instead. */ public void end() throws Exception { ; // The default implementation does nothing } /** * This method is called when the end of a matching XML element * is encountered. The default implementation delegates to the deprecated * method {@link #end end} without the * namespace and name parameters, to retain * backwards compatibility. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @since Digester 1.4 */ public void end(String namespace, String name) throws Exception { end(); } /** * This method is called after all parsing methods have been * called, to allow Rules to remove temporary data. */ public void finish() throws Exception { ; // The default implementation does nothing } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/parser/0000755000175000017500000000000011226450007027575 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/parser/XercesParser.java0000644000175000017500000001461411226450007033054 0ustar twernertwerner/* $Id: XercesParser.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.parser; import java.lang.reflect.Method; import java.util.Properties; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; /** * Create a SAXParser based on the underlying Xerces version. * Currently, Xerces 2.3 and up doesn't implement schema validation the same way * 2.1 was. In other to support schema validation in a portable way between * parser, some features/properties need to be set. * * @since 1.6 */ public class XercesParser{ /** * The Log to which all SAX event related logging calls will be made. */ protected static Log log = LogFactory.getLog("org.apache.commons.digester.Digester.sax"); /** * The JAXP 1.2 property required to set up the schema location. */ private static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; /** * The JAXP 1.2 property to set up the schemaLanguage used. */ protected static String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; /** * Xerces dynamic validation property */ protected static String XERCES_DYNAMIC = "http://apache.org/xml/features/validation/dynamic"; /** * Xerces schema validation property */ protected static String XERCES_SCHEMA = "http://apache.org/xml/features/validation/schema"; /** * A float representing the underlying Xerces version */ protected static float version; /** * The current Xerces version. */ protected static String versionNumber = null; /** * Return the current Xerces version. * @return the current Xerces version. */ private static String getXercesVersion() { // If for some reason we can't get the version, set it to 1.0. String versionNumber = "1.0"; try{ // Use reflection to avoid a build dependency with Xerces. Class versionClass = Class.forName("org.apache.xerces.impl.Version"); // Will return Xerces-J 2.x.0 Method method = versionClass.getMethod("getVersion", (Class[])null); String version = (String)method.invoke(null, (Object[])null); versionNumber = version.substring( "Xerces-J".length() , version.lastIndexOf(".") ); } catch (Exception ex){ // Do nothing. } return versionNumber; } /** * Create a SAXParser based on the underlying * Xerces version. * @param properties parser specific properties/features * @return an XML Schema/DTD enabled SAXParser */ public static SAXParser newSAXParser(Properties properties) throws ParserConfigurationException, SAXException, SAXNotSupportedException { SAXParserFactory factory = (SAXParserFactory)properties.get("SAXParserFactory"); if (versionNumber == null){ versionNumber = getXercesVersion(); version = new Float( versionNumber ).floatValue(); } // Note: 2.2 is completely broken (with XML Schema). if (version > 2.1) { configureXerces(factory); return factory.newSAXParser(); } else { SAXParser parser = factory.newSAXParser(); configureOldXerces(parser,properties); return parser; } } /** * Configure schema validation as recommended by the JAXP 1.2 spec. * The properties object may contains information about * the schema local and language. * @param properties parser optional info */ private static void configureOldXerces(SAXParser parser, Properties properties) throws ParserConfigurationException, SAXNotSupportedException { String schemaLocation = (String)properties.get("schemaLocation"); String schemaLanguage = (String)properties.get("schemaLanguage"); try{ if (schemaLocation != null) { parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage); parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation); } } catch (SAXNotRecognizedException e){ log.info(parser.getClass().getName() + ": " + e.getMessage() + " not supported."); } } /** * Configure schema validation as recommended by the Xerces spec. * Both DTD and Schema validation will be enabled simultaneously. *

* NOTE: This method is broken. It is supposed to set up validation * against the schema specified in property "schemaLocation", but * it doesn't. * * @param factory SAXParserFactory to be configured */ private static void configureXerces(SAXParserFactory factory) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { factory.setFeature(XERCES_DYNAMIC, true); factory.setFeature(XERCES_SCHEMA, true); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/parser/package.html0000644000175000017500000000440311226450007032057 0ustar twernertwerner Package Documentation for org.apache.commons.digester.parser Package Provides for parser recognition and parser dependent code.

Digester aims to support the widest range possible of parsers. Unfortunately, there are a few parser settings which have not been standardized. In most cases, the best practice is for the user to configure the parser themselves and pass it to Digester to use.

There are a few reasonable exceptions which Digester makes to this general rule. There are a small number of common use cases where insisting that the user configure the parser may reduce the portability of applications using Digester. These are outlined below.

Validating With Schema

When validating using schemas (rather than DTDs), settings for schema language and schema location are commonly needed. Unfortunately, there is a lack of standardization for these settings. In particular, for older versions of Xerces, these are set differently from newer versions.

In order to aid portability for this common use case, Digester uses the classes in this package (together with ParserFeatureSetterFactory) to guess the parser and set these properties appropriately. The aim is for Digester to automagically recognize and configure each parser. Help would be gratefully appreciated to maintain and improve the support in this area.

libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/parser/GenericParser.java0000644000175000017500000000611411226450007033173 0ustar twernertwerner/* $Id: GenericParser.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.parser; import java.util.Properties; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; /** * Create a SAXParser configured to support XML Schema and DTD. * * @since 1.6 */ public class GenericParser{ /** * The Log to which all SAX event related logging calls will be made. */ protected static Log log = LogFactory.getLog("org.apache.commons.digester.Digester.sax"); /** * The JAXP 1.2 property required to set up the schema location. */ private static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; /** * The JAXP 1.2 property to set up the schemaLanguage used. */ protected static String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; /** * Create a SAXParser configured to support XML Scheman and DTD * @param properties parser specific properties/features * @return an XML Schema/DTD enabled SAXParser */ public static SAXParser newSAXParser(Properties properties) throws ParserConfigurationException, SAXException, SAXNotRecognizedException{ SAXParserFactory factory = (SAXParserFactory)properties.get("SAXParserFactory"); SAXParser parser = factory.newSAXParser(); String schemaLocation = (String)properties.get("schemaLocation"); String schemaLanguage = (String)properties.get("schemaLanguage"); try{ if (schemaLocation != null) { parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage); parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation); } } catch (SAXNotRecognizedException e){ log.info(parser.getClass().getName() + ": " + e.getMessage() + " not supported."); } return parser; } }././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/SetNestedPropertiesRule.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/SetNestedPropertiesRule.jav0000644000175000017500000004441611226450007033617 0ustar twernertwerner/* $Id: SetNestedPropertiesRule.java 472836 2006-11-09 10:06:56Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.List; import java.util.LinkedList; import java.util.ArrayList; import java.util.HashMap; import java.beans.PropertyDescriptor; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.beanutils.DynaProperty; import org.apache.commons.beanutils.PropertyUtils; import org.xml.sax.Attributes; import org.apache.commons.logging.Log; /** *

Rule implementation that sets properties on the object at the top of the * stack, based on child elements with names matching properties on that * object.

* *

Example input that can be processed by this rule:

*
 *   [widget]
 *    [height]7[/height]
 *    [width]8[/width]
 *    [label]Hello, world[/label]
 *   [/widget]
 * 
* *

For each child element of [widget], a corresponding setter method is * located on the object on the top of the digester stack, the body text of * the child element is converted to the type specified for the (sole) * parameter to the setter method, then the setter method is invoked.

* *

This rule supports custom mapping of xml element names to property names. * The default mapping for particular elements can be overridden by using * {@link #SetNestedPropertiesRule(String[] elementNames, * String[] propertyNames)}. * This allows child elements to be mapped to properties with different names. * Certain elements can also be marked to be ignored.

* *

A very similar effect can be achieved using a combination of the * BeanPropertySetterRule and the ExtendedBaseRules * rules manager; this Rule, however, works fine with the default * RulesBase rules manager.

* *

Note that this rule is designed to be used to set only "primitive" * bean properties, eg String, int, boolean. If some of the child xml elements * match ObjectCreateRule rules (ie cause objects to be created) then you must * use one of the more complex constructors to this rule to explicitly skip * processing of that xml element, and define a SetNextRule (or equivalent) to * handle assigning the child object to the appropriate property instead.

* *

Implementation Notes

* *

This class works by creating its own simple Rules implementation. When * begin is invoked on this rule, the digester's current rules object is * replaced by a custom one. When end is invoked for this rule, the original * rules object is restored. The digester rules objects therefore behave in * a stack-like manner.

* *

For each child element encountered, the custom Rules implementation * ensures that a special AnyChildRule instance is included in the matches * returned to the digester, and it is this rule instance that is responsible * for setting the appropriate property on the target object (if such a property * exists). The effect is therefore like a "trailing wildcard pattern". The * custom Rules implementation also returns the matches provided by the * underlying Rules implementation for the same pattern, so other rules * are not "disabled" during processing of a SetNestedPropertiesRule.

* *

TODO: Optimise this class. Currently, each time begin is called, * new AnyChildRules and AnyChildRule objects are created. It should be * possible to cache these in normal use (though watch out for when a rule * instance is invoked re-entrantly!).

* * @since 1.6 */ public class SetNestedPropertiesRule extends Rule { private Log log = null; private boolean trimData = true; private boolean allowUnknownChildElements = false; private HashMap elementNames = new HashMap(); // ----------------------------------------------------------- Constructors /** * Base constructor, which maps every child element into a bean property * with the same name as the xml element. * *

It is an error if a child xml element exists but the target java * bean has no such property (unless setAllowUnknownChildElements has been * set to true).

*/ public SetNestedPropertiesRule() { // nothing to set up } /** *

Convenience constructor which overrides the default mappings for * just one property.

* *

For details about how this works, see * {@link #SetNestedPropertiesRule(String[] elementNames, * String[] propertyNames)}.

* * @param elementName is the child xml element to match * @param propertyName is the java bean property to be assigned the value * of the specified xml element. This may be null, in which case the * specified xml element will be ignored. */ public SetNestedPropertiesRule(String elementName, String propertyName) { elementNames.put(elementName, propertyName); } /** *

Constructor which allows element->property mapping to be overridden. *

* *

Two arrays are passed in. One contains xml element names and the * other java bean property names. The element name / property name pairs * are matched by position; in order words, the first string in the element * name array corresponds to the first string in the property name array * and so on.

* *

If a property name is null or the xml element name has no matching * property name due to the arrays being of different lengths then this * indicates that the xml element should be ignored.

* *
Example One
*

The following constructs a rule that maps the alt-city * element to the city property and the alt-state * to the state property. All other child elements are mapped * as usual using exact name matching. *

     *      SetNestedPropertiesRule(
     *                new String[] {"alt-city", "alt-state"}, 
     *                new String[] {"city", "state"});
     * 
*

* *
Example Two
*

The following constructs a rule that maps the class * xml element to the className property. The xml element * ignore-me is not mapped, ie is ignored. All other elements * are mapped as usual using exact name matching. *

     *      SetPropertiesRule(
     *                new String[] {"class", "ignore-me"}, 
     *                new String[] {"className"});
     * 
*

* * @param elementNames names of elements to map * @param propertyNames names of properties mapped to */ public SetNestedPropertiesRule(String[] elementNames, String[] propertyNames) { for (int i=0, size=elementNames.length; i * When set to false, any child element for which there is no * corresponding object property will cause an error to be reported. *

* When set to true, any child element for which there is no * corresponding object property will simply be ignored. *

* The default value of this attribute is false (unknown child elements * are not allowed). */ public void setAllowUnknownChildElements(boolean allowUnknownChildElements) { this.allowUnknownChildElements = allowUnknownChildElements; } /** See {@link #setAllowUnknownChildElements}. */ public boolean getAllowUnknownChildElements() { return allowUnknownChildElements; } /** * Process the beginning of this element. * * @param namespace is the namespace this attribute is in, or null * @param name is the name of the current xml element * @param attributes is the attribute list of this element */ public void begin(String namespace, String name, Attributes attributes) throws Exception { Rules oldRules = digester.getRules(); AnyChildRule anyChildRule = new AnyChildRule(); anyChildRule.setDigester(digester); AnyChildRules newRules = new AnyChildRules(anyChildRule); newRules.init(digester.getMatch()+"/", oldRules); digester.setRules(newRules); } /** * This is only invoked after all child elements have been processed, * so we can remove the custom Rules object that does the * child-element-matching. */ public void body(String bodyText) throws Exception { AnyChildRules newRules = (AnyChildRules) digester.getRules(); digester.setRules(newRules.getOldRules()); } /** * Add an additional custom xml-element -> property mapping. *

* This is primarily intended to be used from the xml rules module * (as it is not possible there to pass the necessary parameters to the * constructor for this class). However it is valid to use this method * directly if desired. */ public void addAlias(String elementName, String propertyName) { elementNames.put(elementName, propertyName); } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("SetNestedPropertiesRule["); sb.append("allowUnknownChildElements="); sb.append(allowUnknownChildElements); sb.append(", trimData="); sb.append(trimData); sb.append(", elementNames="); sb.append(elementNames); sb.append("]"); return sb.toString(); } //----------------------------------------- local classes /** Private Rules implementation */ private class AnyChildRules implements Rules { private String matchPrefix = null; private Rules decoratedRules = null; private ArrayList rules = new ArrayList(1); private AnyChildRule rule; public AnyChildRules(AnyChildRule rule) { this.rule = rule; rules.add(rule); } public Digester getDigester() { return null; } public void setDigester(Digester digester) {} public String getNamespaceURI() {return null;} public void setNamespaceURI(String namespaceURI) {} public void add(String pattern, Rule rule) {} public void clear() {} public List match(String matchPath) { return match(null,matchPath); } public List match(String namespaceURI, String matchPath) { List match = decoratedRules.match(namespaceURI, matchPath); if ((matchPath.startsWith(matchPrefix)) && (matchPath.indexOf('/', matchPrefix.length()) == -1)) { // The current element is a direct child of the element // specified in the init method, so we want to ensure that // the rule passed to this object's constructor is included // in the returned list of matching rules. if ((match == null || match.size()==0)) { // The "real" rules class doesn't have any matches for // the specified path, so we return a list containing // just one rule: the one passed to this object's // constructor. return rules; } else { // The "real" rules class has rules that match the current // node, so we return this list *plus* the rule passed to // this object's constructor. // // It might not be safe to modify the returned list, // so clone it first. LinkedList newMatch = new LinkedList(match); newMatch.addLast(rule); return newMatch; } } else { return match; } } public List rules() { // This is not actually expected to be called during normal // processing. // // There is only one known case where this is called; when a rule // returned from AnyChildRules.match is invoked and throws a // SAXException then method Digester.endDocument will be called // without having "uninstalled" the AnyChildRules ionstance. That // method attempts to invoke the "finish" method for every Rule // instance - and thus needs to call rules() on its Rules object, // which is this one. Actually, java 1.5 and 1.6beta2 have a // bug in their xml implementation such that endDocument is not // called after a SAXException, but other parsers (eg Aelfred) // do call endDocument. Here, we therefore need to return the // rules registered with the underlying Rules object. log.debug("AnyChildRules.rules invoked."); return decoratedRules.rules(); } public void init(String prefix, Rules rules) { matchPrefix = prefix; decoratedRules = rules; } public Rules getOldRules() { return decoratedRules; } } private class AnyChildRule extends Rule { private String currChildNamespaceURI = null; private String currChildElementName = null; public void begin(String namespaceURI, String name, Attributes attributes) throws Exception { currChildNamespaceURI = namespaceURI; currChildElementName = name; } public void body(String value) throws Exception { String propName = currChildElementName; if (elementNames.containsKey(currChildElementName)) { // overide propName propName = (String) elementNames.get(currChildElementName); if (propName == null) { // user wants us to ignore this element return; } } boolean debug = log.isDebugEnabled(); if (debug) { log.debug("[SetNestedPropertiesRule]{" + digester.match + "} Setting property '" + propName + "' to '" + value + "'"); } // Populate the corresponding properties of the top object Object top = digester.peek(); if (debug) { if (top != null) { log.debug("[SetNestedPropertiesRule]{" + digester.match + "} Set " + top.getClass().getName() + " properties"); } else { log.debug("[SetPropertiesRule]{" + digester.match + "} Set NULL properties"); } } if (trimData) { value = value.trim(); } if (!allowUnknownChildElements) { // Force an exception if the property does not exist // (BeanUtils.setProperty() silently returns in this case) if (top instanceof DynaBean) { DynaProperty desc = ((DynaBean) top).getDynaClass().getDynaProperty(propName); if (desc == null) { throw new NoSuchMethodException ("Bean has no property named " + propName); } } else /* this is a standard JavaBean */ { PropertyDescriptor desc = PropertyUtils.getPropertyDescriptor(top, propName); if (desc == null) { throw new NoSuchMethodException ("Bean has no property named " + propName); } } } try { BeanUtils.setProperty(top, propName, value); } catch(NullPointerException e) { log.error("NullPointerException: " + "top=" + top + ",propName=" + propName + ",value=" + value + "!"); throw e; } } public void end(String namespace, String name) throws Exception { currChildElementName = null; } } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/RuleSet.java0000644000175000017500000000472111226450007030533 0ustar twernertwerner/* $Id: RuleSet.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; /** *

Public interface defining a shorthand means of configuring a complete * set of related Rule definitions, possibly associated with * a particular namespace URI, in one operation. To use an instance of a * class that imlements this interface:

*
    *
  • Create a concrete implementation of this interface.
  • *
  • Optionally, you can configure a RuleSet to be relevant * only for a particular namespace URI by configuring the value to be * returned by getNamespaceURI().
  • *
  • As you are configuring your Digester instance, call * digester.addRuleSet() and pass the RuleSet instance.
  • *
  • Digester will call the addRuleInstances() method of * your RuleSet to configure the necessary rules.
  • *
*/ public interface RuleSet { // ------------------------------------------------------------- Properties /** * Return the namespace URI that will be applied to all Rule instances * created from this RuleSet. */ public String getNamespaceURI(); // --------------------------------------------------------- Public Methods /** * Add the set of Rule instances defined in this RuleSet to the * specified Digester instance, associating them with * our namespace URI (if any). This method should only be called * by a Digester instance. * * @param digester Digester instance to which the new Rule instances * should be added. */ public void addRuleInstances(Digester digester); } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/SimpleRegexMatcher.java0000644000175000017500000001267511226450007032707 0ustar twernertwerner/* $Id: SimpleRegexMatcher.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** *

Simple regex pattern matching algorithm.

* *

This uses just two wildcards: *

    *
  • * matches any sequence of none, one or more characters *
  • ? matches any one character *
* Escaping these wildcards is not supported .

* * @since 1.5 */ public class SimpleRegexMatcher extends RegexMatcher { // --------------------------------------------------------- Fields /** Default log (class wide) */ private static final Log baseLog = LogFactory.getLog(SimpleRegexMatcher.class); /** Custom log (can be set per object) */ private Log log = baseLog; // --------------------------------------------------------- Properties /** * Gets the Log implementation. */ public Log getLog() { return log; } /** * Sets the current Log implementation used by this class. */ public void setLog(Log log) { this.log = log; } // --------------------------------------------------------- Public Methods /** * Matches using simple regex algorithm. * * * @param basePattern the standard digester path representing the element * @param regexPattern the regex pattern the path will be tested against * @return true if the given pattern matches the given path */ public boolean match(String basePattern, String regexPattern) { // check for nulls if (basePattern == null || regexPattern == null) { return false; } return match(basePattern, regexPattern, 0, 0); } // --------------------------------------------------------- Implementations Methods /** * Implementation of regex matching algorithm. * This calls itself recursively. */ private boolean match(String basePattern, String regexPattern, int baseAt, int regexAt) { if (log.isTraceEnabled()) { log.trace("Base: " + basePattern); log.trace("Regex: " + regexPattern); log.trace("Base@" + baseAt); log.trace("Regex@" + regexAt); } // check bounds if (regexAt >= regexPattern.length()) { // maybe we've got a match if (baseAt >= basePattern.length()) { // ok! return true; } // run out early return false; } else { if (baseAt >= basePattern.length()) { // run out early return false; } } // ok both within bounds char regexCurrent = regexPattern.charAt(regexAt); switch (regexCurrent) { case '*': // this is the tricky case // check for terminal if (++regexAt >= regexPattern.length()) { // this matches anything let - so return true return true; } // go through every subsequent apperance of the next character // and so if the rest of the regex matches char nextRegex = regexPattern.charAt(regexAt); if (log.isTraceEnabled()) { log.trace("Searching for next '" + nextRegex + "' char"); } int nextMatch = basePattern.indexOf(nextRegex, baseAt); while (nextMatch != -1) { if (log.isTraceEnabled()) { log.trace("Trying '*' match@" + nextMatch); } if (match(basePattern, regexPattern, nextMatch, regexAt)) { return true; } nextMatch = basePattern.indexOf(nextRegex, nextMatch + 1); } log.trace("No matches found."); return false; case '?': // this matches anything return match(basePattern, regexPattern, ++baseAt, ++regexAt); default: if (log.isTraceEnabled()) { log.trace("Camparing " + regexCurrent + " to " + basePattern.charAt(baseAt)); } if (regexCurrent == basePattern.charAt(baseAt)) { // still got more to go return match(basePattern, regexPattern, ++baseAt, ++regexAt); } return false; } } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/0000755000175000017500000000000011226450007030154 5ustar twernertwerner././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/CircularIncludeException.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/CircularIncludeExc0000644000175000017500000000256311226450007033615 0ustar twernertwerner/* $Id: CircularIncludeException.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; /** * Thrown when parsing XML into Digester rules, if a circular inclusion occurred * in the xml digester rules files. * * @since 1.2 */ public class CircularIncludeException extends XmlLoadException { /** * @param fileName the name of the XML file suspected of causing the * circular inclusion */ public CircularIncludeException(String fileName) { super("Circular file inclusion detected for file: " + fileName); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/DigesterLoader.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/DigesterLoader.jav0000644000175000017500000002614611226450007033564 0ustar twernertwerner/* $Id: DigesterLoader.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.net.URL; import org.apache.commons.digester.Digester; import org.apache.commons.digester.RuleSet; import org.xml.sax.SAXException; import org.xml.sax.InputSource; /** * This class manages the creation of Digester instances from XML digester * rules files. * * @since 1.2 */ public class DigesterLoader { /** * Creates a new digester and initializes it from the specified InputSource * @param rulesSource load the xml rules from this InputSource * @return a new Digester initialized with the rules */ public static Digester createDigester(InputSource rulesSource) { RuleSet ruleSet = new FromXmlRuleSet(rulesSource); Digester digester = new Digester(); digester.addRuleSet(ruleSet); return digester; } /** * Creates a new digester and initializes it from the specified InputSource. * This constructor allows the digester to be used to load the rules to be specified. * This allows properties to be configured on the Digester instance before it is used. * * @param rulesSource load the xml rules from this InputSource * @param rulesDigester digester to load the specified XML file. * @return a new Digester initialized with the rules */ public static Digester createDigester(InputSource rulesSource, Digester rulesDigester) { RuleSet ruleSet = new FromXmlRuleSet(rulesSource, rulesDigester); Digester digester = new Digester(); digester.addRuleSet(ruleSet); return digester; } /** * Creates a new digester and initializes it from the specified XML file * @param rulesXml URL to the XML file defining the digester rules * @return a new Digester initialized with the rules */ public static Digester createDigester(URL rulesXml) { RuleSet ruleSet = new FromXmlRuleSet(rulesXml); Digester digester = new Digester(); digester.addRuleSet(ruleSet); return digester; } /** * Creates a new digester and initializes it from the specified XML file. * This constructor allows specifing a rulesDigester to do the XML file * loading; thus no matter the XML files is packed into a jar, a war, or a * ear, the rulesDigester can always find the XML files with properly set * ClassLoader. * * @param rulesXml URL to the XML file defining the digester rules * @param rulesDigester digester to load the specified XML file. * @return a new Digester initialized with the rules */ public static Digester createDigester(URL rulesXml, Digester rulesDigester) { RuleSet ruleSet = new FromXmlRuleSet(rulesXml, rulesDigester); Digester digester = new Digester(); digester.addRuleSet(ruleSet); return digester; } /** * Given the digester rules XML file, a class loader, and an XML input file, * this method parses the input file into Java objects. The class loader * is used by the digester to create the Java objects. * @param digesterRules URL to the XML document defining the digester rules * @param classLoader the ClassLoader to register with the digester * @param fileURL URL to the XML file to parse into Java objects * @return an Object which is the root of the network of Java objects * created by digesting fileURL */ public static Object load(URL digesterRules, ClassLoader classLoader, URL fileURL) throws IOException, SAXException, DigesterLoadingException { return load(digesterRules, classLoader, fileURL.openStream()); } /** * Given the digester rules XML file, a class loader, and an input stream, * this method parses the input into Java objects. The class loader * is used by the digester to create the Java objects. * @param digesterRules URL to the XML document defining the digester rules * @param classLoader the ClassLoader to register with the digester * @param input InputStream over the XML file to parse into Java objects * @return an Object which is the root of the network of Java objects * created by digesting fileURL */ public static Object load(URL digesterRules, ClassLoader classLoader, InputStream input) throws IOException, SAXException, DigesterLoadingException { Digester digester = createDigester(digesterRules); digester.setClassLoader(classLoader); try { return digester.parse(input); } catch (XmlLoadException ex) { // This is a runtime exception that can be thrown by // FromXmlRuleSet#addRuleInstances, which is called by the Digester // before it parses the file. throw new DigesterLoadingException(ex.getMessage(), ex); } } /** * Given the digester rules XML file, a class loader, and an input stream, * this method parses the input into Java objects. The class loader * is used by the digester to create the Java objects. * @param digesterRules URL to the XML document defining the digester rules * @param classLoader the ClassLoader to register with the digester * @param reader Reader over the XML file to parse into Java objects * @return an Object which is the root of the network of Java objects * created by digesting fileURL */ public static Object load( URL digesterRules, ClassLoader classLoader, Reader reader) throws IOException, SAXException, DigesterLoadingException { Digester digester = createDigester(digesterRules); digester.setClassLoader(classLoader); try { return digester.parse(reader); } catch (XmlLoadException ex) { // This is a runtime exception that can be thrown by // FromXmlRuleSet#addRuleInstances, which is called by the Digester // before it parses the file. throw new DigesterLoadingException(ex.getMessage(), ex); } } /** * Given the digester rules XML file, a class loader, and an XML input file, * this method parses the input file into Java objects. The class loader * is used by the digester to create the Java objects. * @param digesterRules URL to the XML document defining the digester rules * @param classLoader the ClassLoader to register with the digester * @param fileURL URL to the XML file to parse into Java objects * @param rootObject an Object to push onto the digester's stack, prior * to parsing the input * @return an Object which is the root of the network of Java objects. * Usually, this will be the same object as rootObject * created by digesting fileURL */ public static Object load(URL digesterRules, ClassLoader classLoader, URL fileURL, Object rootObject) throws IOException, SAXException, DigesterLoadingException { return load(digesterRules, classLoader, fileURL.openStream(), rootObject); } /** * Given the digester rules XML file, a class loader, and an input stream, * this method parses the input into Java objects. The class loader * is used by the digester to create the Java objects. * @param digesterRules URL to the XML document defining the digester rules * @param classLoader the ClassLoader to register with the digester * @param input InputStream over the XML file to parse into Java objects * @param rootObject an Object to push onto the digester's stack, prior * to parsing the input * @return an Object which is the root of the network of Java objects * created by digesting fileURL */ public static Object load(URL digesterRules, ClassLoader classLoader, InputStream input, Object rootObject) throws IOException, SAXException, DigesterLoadingException { Digester digester = createDigester(digesterRules); digester.setClassLoader(classLoader); digester.push(rootObject); try { return digester.parse(input); } catch (XmlLoadException ex) { // This is a runtime exception that can be thrown by // FromXmlRuleSet#addRuleInstances, which is called by the Digester // before it parses the file. throw new DigesterLoadingException(ex.getMessage(), ex); } } /** * Given the digester rules XML file, a class loader, and an input stream, * this method parses the input into Java objects. The class loader * is used by the digester to create the Java objects. * @param digesterRules URL to the XML document defining the digester rules * @param classLoader the ClassLoader to register with the digester * @param input Reader over the XML file to parse into Java objects * @param rootObject an Object to push onto the digester's stack, prior * to parsing the input * @return an Object which is the root of the network of Java objects * created by digesting fileURL */ public static Object load( URL digesterRules, ClassLoader classLoader, Reader input, Object rootObject) throws IOException, SAXException, DigesterLoadingException { Digester digester = createDigester(digesterRules); digester.setClassLoader(classLoader); digester.push(rootObject); try { return digester.parse(input); } catch (XmlLoadException ex) { // This is a runtime exception that can be thrown by // FromXmlRuleSet#addRuleInstances, which is called by the Digester // before it parses the file. throw new DigesterLoadingException(ex.getMessage(), ex); } } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/package.html0000644000175000017500000002426511226450007032446 0ustar twernertwerner Documentation for org.apache.commons.digester.xmlrules

The xmlrules package provides for XML-based definition of rules for Digester. This improves maintainability of Java code, as rules are now defined in XML and read into Digester at run-time.



Introduction

This is a brief overview of the digester-rules-in-XML feature. Briefly, this feature lets you define Digester rules in XML, instead of creating and initializing the Rules objects programmatically, which can become tedious. In addition, it allows for including of one XML rules file within another, inclusion of programmatically created rule sets within an XML file (via reflection), and recursively nested matching pattern specifications.

Overview of digester-rules.dtd

A DTD, named digester-rules.dtd has been defined to help in the understanding of how the loader operates.

The DTD is distributed in the commons-digester.jar. It can be found at org/apache/commons/digester/xmlrules/digester-rules.dtd. It is not available for download from the Apache website since users are best advised to use a copy stored on their local system.

Digester input documents wishing to cite this DTD should include the following DOCTYPE declaration:

  <!DOCTYPE digester-rules PUBLIC
   "-//Jakarta Apache //DTD digester-rules XML V1.0//EN"
   "digester-rules.dtd">

Rule elements:

The DTD defines an element type corresponding to each predefined Digester rule. Each rule element type includes attributes for values needed to initialize the rule, and an optional pattern attribute specifying the pattern to associate with the rule.

The DigesterLoader adds the rules to the digester in the order in which they occur in the XML.

The use of each rule element type should be self-explanatory, if you compare them to the API documentation for the Digester rules classes.

Defining matching patterns:

The matching pattern is a simple, xpath-like string which the Digester uses to determine which elements to apply each rule to. See the Digester documentation for more details.
There are two methods for associating patterns to rules in the XML file. One is for each rule element to directly define its pattern in a pattern attribute. An example would like something like:

      <digester-rules>
        <object-create-rule pattern="*/foo" classname="Foo"/>
        <set-properties-rule pattern="*/foo"/>
      </digester-rules>

In the above example, an ObjectCreateRule is created and associated with the pattern "*/foo"; then a SetPropertiesRule is created and associated with the pattern "*/foo".

The other method is to nest rules elements inside a <pattern> element. In this way, the same pattern can be defined for a group of rules. The following example has the same effect as the previous example:
       <digester-rules>
         <pattern value="*/foo">
           <object-create-rule classname="Foo"/>
           <set-properties-rule/>
         </pattern>
       </digester-rules>


Pattern elements can be recursively nested. If patterns are nested, the pattern string is formed by concatenating all the patterns together. Example:
       <digester-rules>
         <pattern value="*/foo">
           <pattern value="bar">
             <object-create-rule classname="Foobar"/>
             <set-properties-rule/>
           </pattern>
         </pattern>
       </digester-rules>

In the above example, an ObjectCreateRule and a SetPropertiesRule are associated with the matching pattern "*/foo/bar".
The use of pattern elements and the use of the pattern attribute inside rules elements can be freely mixed. The next example has the same effect as the previous example:
       <digester-rules>
         <pattern value="*/foo">
           <object-create-rule pattern="bar" classname="Foobar"/>
           <set-properties-rule pattern="bar"/>
         </pattern>
       </digester-rules>

Including rules XML files within other rules XML files:

The <include> element lets you include one rules file within another. With respect to pattern concatenation, the DigesterLoader behaves as if the include file was 'macro-expanded'. Example:

      File rules1.xml:
         <?xml version="1.0"?>
         <!DOCTYPE digester-rules SYSTEM "digester-rules.dtd">

         <digester-rules>
           <pattern value="root/foo">
             <object-create-rule classname="Foo"/>

             <include path="rules2.xml"/>
           </pattern>
         </digester-rules>


      File rules2.xml:
         <?xml version="1.0"?>
         <!DOCTYPE digester-rules SYSTEM "digester-rules.dtd">

         <digester-rules>
           <pattern value="bar">
             <object-create-rule classname="Bar"/>
           </pattern>
         </digester-rules>

Parsing rule1.xml would result in a Digester initialized with these pattern/rule pairs:

    root/foo -> ObjectCreateRule(Foo)
    root/foo/bar -> ObjectCreateRule(Bar)

Note that the pattern for the 'bar' rule has been prepended with the 'root/foo' pattern. If rule2.xml was parsed by itself, it would yield a Digester initialized with this pattern/rule:

    bar -> ObjectCreateRule(Bar)

Including programmatically-created rules:

Sometimes rules cannot be easily defined via XML. Rule sets that are created programmatically can still be included within a digester-rules XML file. This is done by using an <include> element with a class attribute, containing the name of a class that implements org.apache.commons.digester.xmlrules.DigesterRulesSource. This interface defines one method, getRules(Digester), which creates rules and adds them to the supplied Digester. The pattern concatenation works exactly as if the rules had been included from an XML file. Example:

      File rules3.xml:
         <?xml version="1.0"?>
         <!DOCTYPE digester-rules SYSTEM "digester-rules.dtd">

         <digester-rules>
           <pattern value="root/foo">
             <object-create-rule classname="Foo"/>

             <include class="BarRuleCreator"/>
           </pattern>
         </digester-rules>

BarRuleCreator class definition:
          public class BarRuleCreator implements DigesterRulesSource {
              public void getRules(Digester digester) {
                  digester.addObjectCreate("bar", "Bar");
              }
          }

Parsing rules3.xml yields the same results as rules1.xml above:

    root/foo -> ObjectCreateRule(Foo)
    root/foo/bar -> ObjectCreateRule(Bar)

Creating a digester from XML:

FromXmlRuleSet is a RuleSet implementation that initializes its Digester from rules defined in an XML file. The path to the XML file is passed to constructor.

Alternatively, the convenience class
DigesterLoader
defines a static method, Digester createDigester(String rulesXml) throws DigesterLoaderException". When passing the name of the file that contains your digester rules, this method returns a Digester instance initialized with the rules.

To add your own rules, you need to:

  • Update the DTD
    You should add an element type for your rule. The element should have an attribute corresponding to each of the rule's initialization parameters.
  • Define an ObjectCreationFactory
  • Extend DigesterRuleParser
    DigesterRuleParser is a RuleSet for parsing a rules XML file. You should extend this, and override the addRuleInstances() method to add the rules for parsing your new element. Look in DigesterRuleParser.java to see how its done.

././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/FromXmlRuleSet.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/FromXmlRuleSet.jav0000644000175000017500000001705011226450007033551 0ustar twernertwerner/* $Id: FromXmlRuleSet.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import java.net.URL; import org.apache.commons.digester.Digester; import org.apache.commons.digester.RuleSetBase; import org.xml.sax.InputSource; /** * A Digester rule set where the rules come from an XML file. * * @since 1.2 */ public class FromXmlRuleSet extends RuleSetBase { public static final String DIGESTER_DTD_PATH = "org/apache/commons/digester/xmlrules/digester-rules.dtd"; /** * The file containing the Digester rules, in XML. */ private XMLRulesLoader rulesLoader; /** * The rule set for parsing the Digester rules */ private DigesterRuleParser parser; /** * The digester for loading the rules xml. */ private Digester rulesDigester; /** * Constructs a FromXmlRuleSet using the default DigesterRuleParser and * rulesDigester. * @param rulesXml the path to the XML document defining the Digester rules */ public FromXmlRuleSet(URL rulesXml) { this(rulesXml, new DigesterRuleParser(), new Digester()); } /** * Constructs a FromXmlRuleSet using the default DigesterRuleParser and * a ruleDigester for loading the rules xml. * @param rulesXml the path to the XML document defining the Digester rules * @param rulesDigester the digester to read the rules xml. */ public FromXmlRuleSet(URL rulesXml, Digester rulesDigester) { this(rulesXml, new DigesterRuleParser(), rulesDigester); } /** * @param rulesXml the path to the XML document defining the Digester rules * @param parser an instance of DigesterRuleParser, for parsing the rules from XML */ public FromXmlRuleSet(URL rulesXml, DigesterRuleParser parser) { this(rulesXml, parser, new Digester()); } /** * @param rulesXml the path to the XML document defining the Digester rules * @param parser an instance of DigesterRuleParser, for parsing the rules from XML * @param rulesDigester the digester used to load the Xml rules. */ public FromXmlRuleSet(URL rulesXml, DigesterRuleParser parser, Digester rulesDigester) { init(new URLXMLRulesLoader(rulesXml), parser, rulesDigester); } /** * Constructs a FromXmlRuleSet using the default DigesterRuleParser and * rulesDigester. * @param inputSource load the xml rules from this InputSource */ public FromXmlRuleSet(InputSource inputSource) { this(inputSource, new DigesterRuleParser(), new Digester()); } /** * Constructs a FromXmlRuleSet using the default DigesterRuleParser and * a ruleDigester for loading the rules xml. * @param inputSource load the xml rules from this InputSource * @param rulesDigester the digester to read the rules xml. */ public FromXmlRuleSet(InputSource inputSource, Digester rulesDigester) { this(inputSource, new DigesterRuleParser(), rulesDigester); } /** * @param inputSource load the xml rules from this InputSource * @param parser an instance of DigesterRuleParser, for parsing the rules from XML */ public FromXmlRuleSet(InputSource inputSource, DigesterRuleParser parser) { this(inputSource, parser, new Digester()); } /** * @param inputSource load the xml rules from this InputSource * @param parser an instance of DigesterRuleParser, for parsing the rules from XML * @param rulesDigester the digester used to load the Xml rules. */ public FromXmlRuleSet(InputSource inputSource, DigesterRuleParser parser, Digester rulesDigester) { init(new InputSourceXMLRulesLoader(inputSource), parser, rulesDigester); } /** * Base constructor */ private void init(XMLRulesLoader rulesLoader, DigesterRuleParser parser, Digester rulesDigester) { this.rulesLoader = rulesLoader; this.parser = parser; this.rulesDigester = rulesDigester; } /** * Adds to the digester the set of Rule instances defined in the * XML file for this rule set. * @see org.apache.commons.digester.RuleSetBase */ public void addRuleInstances(org.apache.commons.digester.Digester digester) throws XmlLoadException { addRuleInstances(digester, null); } /** * Adds to the digester the set of Rule instances defined in the * XML file for this rule set. *

* Note that this method doesn't have a matching one on the DigesterLoader * class, because it is not expected to be widely used, and DigesterLoader's * load method is already heavily overloaded. * * @param digester is the digester that rules will be added to. * @param basePath is a path that will be prefixed to every * pattern string defined in the xmlrules input file. * * @see org.apache.commons.digester.RuleSetBase * @since 1.6 */ public void addRuleInstances( org.apache.commons.digester.Digester digester, String basePath) throws XmlLoadException { URL dtdURL = getClass().getClassLoader().getResource(DIGESTER_DTD_PATH); if (dtdURL == null) { throw new XmlLoadException("Cannot find resource \"" + DIGESTER_DTD_PATH + "\""); } parser.setDigesterRulesDTD(dtdURL.toString()); parser.setTarget(digester); parser.setBasePath(basePath); rulesDigester.addRuleSet(parser); rulesDigester.push(parser); rulesLoader.loadRules(); } /** * Worker class encapsulates loading mechanisms. * Private until some reason is found to make it public. */ private abstract static class XMLRulesLoader { /** Load rules now */ public abstract void loadRules() throws XmlLoadException; } /** Loads XMLRules from an URL */ private class URLXMLRulesLoader extends XMLRulesLoader { private URL url; public URLXMLRulesLoader(URL url) { this.url = url; } public void loadRules() throws XmlLoadException { try { rulesDigester.parse(url.openStream()); } catch (Exception ex) { throw new XmlLoadException(ex); } } } /** Loads XMLRules from an InputSource */ private class InputSourceXMLRulesLoader extends XMLRulesLoader { private InputSource inputSource; public InputSourceXMLRulesLoader(InputSource inputSource) { this.inputSource = inputSource; } public void loadRules() throws XmlLoadException { try { rulesDigester.parse(inputSource); } catch (Exception ex) { throw new XmlLoadException(ex); } } } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/XmlLoadException.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/XmlLoadException.j0000644000175000017500000000322611226450007033551 0ustar twernertwerner/* $Id: XmlLoadException.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; /** * Thrown when an error occurs while parsing XML into Digester rules. * * @since 1.2 */ public class XmlLoadException extends RuntimeException { private Throwable cause = null; /** * @param cause underlying exception that caused this to be thrown */ public XmlLoadException(Throwable cause) { this(cause.getMessage()); this.cause = cause; } public XmlLoadException(String msg) { super(msg); } public XmlLoadException(String msg, Throwable cause) { this(msg); this.cause = cause; } /** * Returns the cause of this throwable or null if the cause is * nonexistent or unknown. */ public Throwable getCause() { return cause; } } ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtdlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd0000644000175000017500000002011211226450007033603 0ustar twernertwerner ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser0000644000175000017500000010102411226450007033650 0ustar twernertwerner/* $Id: DigesterRuleParser.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.StringTokenizer; import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.collections.ArrayStack; import org.apache.commons.digester.AbstractObjectCreationFactory; import org.apache.commons.digester.BeanPropertySetterRule; import org.apache.commons.digester.CallMethodRule; import org.apache.commons.digester.CallParamRule; import org.apache.commons.digester.Digester; import org.apache.commons.digester.FactoryCreateRule; import org.apache.commons.digester.NodeCreateRule; import org.apache.commons.digester.ObjectCreateRule; import org.apache.commons.digester.Rule; import org.apache.commons.digester.RuleSetBase; import org.apache.commons.digester.Rules; import org.apache.commons.digester.SetNestedPropertiesRule; import org.apache.commons.digester.SetNextRule; import org.apache.commons.digester.SetPropertiesRule; import org.apache.commons.digester.SetPropertyRule; import org.apache.commons.digester.SetRootRule; import org.apache.commons.digester.SetTopRule; import org.apache.commons.digester.ObjectParamRule; import org.w3c.dom.Node; import org.xml.sax.Attributes; import org.xml.sax.SAXException; /** * This is a RuleSet that parses XML into Digester rules, and then * adds those rules to a 'target' Digester. * * @since 1.2 */ public class DigesterRuleParser extends RuleSetBase { public static final String DIGESTER_PUBLIC_ID = "-//Jakarta Apache //DTD digester-rules XML V1.0//EN"; /** * path to the DTD */ private String digesterDtdUrl; /** * This is the digester to which we are adding the rules that we parse * from the Rules XML document. */ protected Digester targetDigester; /** See {@link #setBasePath}. */ protected String basePath = ""; /** * A stack whose toString method returns a '/'-separated concatenation * of all the elements in the stack. */ protected class PatternStack extends ArrayStack { public String toString() { StringBuffer str = new StringBuffer(); for (int i = 0; i < size(); i++) { String elem = get(i).toString(); if (elem.length() > 0) { if (str.length() > 0) { str.append('/'); } str.append(elem); } } return str.toString(); } } /** * A stack used to maintain the current pattern. The Rules XML document * type allows nesting of patterns. If an element defines a matching * pattern, the resulting pattern is a concatenation of that pattern with * all the ancestor elements' patterns. Hence the need for a stack. */ protected PatternStack patternStack; /** * Used to detect circular includes */ private Set includedFiles = new HashSet(); /** * Constructs a DigesterRuleParser. This object will be inoperable * until the target digester is set, via setTarget(Digester) */ public DigesterRuleParser() { patternStack = new PatternStack(); } /** * Constructs a rule set for converting XML digester rule descriptions * into Rule objects, and adding them to the given Digester * @param targetDigester the Digester to add the rules to */ public DigesterRuleParser(Digester targetDigester) { this.targetDigester = targetDigester; patternStack = new PatternStack(); } /** * Constructs a rule set for parsing an XML digester rule file that * has been included within an outer XML digester rule file. In this * case, we must pass the pattern stack and the target digester * to the rule set, as well as the list of files that have already * been included, for cycle detection. * @param targetDigester the Digester to add the rules to * @param stack Stack containing the prefix pattern string to be prepended * to any pattern parsed by this rule set. */ private DigesterRuleParser(Digester targetDigester, PatternStack stack, Set includedFiles) { this.targetDigester = targetDigester; patternStack = stack; this.includedFiles = includedFiles; } /** * Sets the digester into which to add the parsed rules * @param d the Digester to add the rules to */ public void setTarget(Digester d) { targetDigester = d; } /** * Set a base pattern beneath which all the rules loaded by this * object will be registered. If this string is not empty, and does * not end in a "/", then one will be added. * * @since 1.6 */ public void setBasePath(String path) { if (path == null) { basePath = ""; } else if ((path.length() > 0) && !path.endsWith("/")) { basePath = path + "/"; } else { basePath = path; } } /** * Sets the location of the digester rules DTD. This is the DTD used * to validate the rules XML file. */ public void setDigesterRulesDTD(String dtdURL) { digesterDtdUrl = dtdURL; } /** * Returns the location of the DTD used to validate the digester rules * XML document. */ protected String getDigesterRulesDTD() { //ClassLoader classLoader = getClass().getClassLoader(); //URL url = classLoader.getResource(DIGESTER_DTD_PATH); //return url.toString(); return digesterDtdUrl; } /** * Adds a rule the the target digester. After a rule has been created by * parsing the XML, it is added to the digester by calling this method. * Typically, this method is called via reflection, when executing * a SetNextRule, from the Digester that is parsing the rules XML. * @param rule a Rule to add to the target digester. */ public void add(Rule rule) { targetDigester.addRule( basePath + patternStack.toString(), rule); } /** * Add to the given digester the set of Rule instances used to parse an XML * document defining Digester rules. When the digester parses an XML file, * it will add the resulting rules & patterns to the 'target digester' * that was passed in this RuleSet's constructor.

* If you extend this class to support additional rules, your implementation * should of this method should call this implementation first: i.e. * super.addRuleInstances(digester); */ public void addRuleInstances(Digester digester) { final String ruleClassName = Rule.class.getName(); digester.register(DIGESTER_PUBLIC_ID, getDigesterRulesDTD()); digester.addRule("*/pattern", new PatternRule("value")); digester.addRule("*/include", new IncludeRule()); digester.addFactoryCreate("*/bean-property-setter-rule", new BeanPropertySetterRuleFactory()); digester.addRule("*/bean-property-setter-rule", new PatternRule("pattern")); digester.addSetNext("*/bean-property-setter-rule", "add", ruleClassName); digester.addFactoryCreate("*/call-method-rule", new CallMethodRuleFactory()); digester.addRule("*/call-method-rule", new PatternRule("pattern")); digester.addSetNext("*/call-method-rule", "add", ruleClassName); digester.addFactoryCreate("*/object-param-rule", new ObjectParamRuleFactory()); digester.addRule("*/object-param-rule", new PatternRule("pattern")); digester.addSetNext("*/object-param-rule", "add", ruleClassName); digester.addFactoryCreate("*/call-param-rule", new CallParamRuleFactory()); digester.addRule("*/call-param-rule", new PatternRule("pattern")); digester.addSetNext("*/call-param-rule", "add", ruleClassName); digester.addFactoryCreate("*/factory-create-rule", new FactoryCreateRuleFactory()); digester.addRule("*/factory-create-rule", new PatternRule("pattern")); digester.addSetNext("*/factory-create-rule", "add", ruleClassName); digester.addFactoryCreate("*/object-create-rule", new ObjectCreateRuleFactory()); digester.addRule("*/object-create-rule", new PatternRule("pattern")); digester.addSetNext("*/object-create-rule", "add", ruleClassName); digester.addFactoryCreate("*/node-create-rule", new NodeCreateRuleFactory()); digester.addRule("*/node-create-rule", new PatternRule("pattern")); digester.addSetNext("*/node-create-rule", "add", ruleClassName); digester.addFactoryCreate("*/set-properties-rule", new SetPropertiesRuleFactory()); digester.addRule("*/set-properties-rule", new PatternRule("pattern")); digester.addSetNext("*/set-properties-rule", "add", ruleClassName); digester.addRule("*/set-properties-rule/alias", new SetPropertiesAliasRule()); digester.addFactoryCreate("*/set-property-rule", new SetPropertyRuleFactory()); digester.addRule("*/set-property-rule", new PatternRule("pattern")); digester.addSetNext("*/set-property-rule", "add", ruleClassName); digester.addFactoryCreate("*/set-nested-properties-rule", new SetNestedPropertiesRuleFactory()); digester.addRule("*/set-nested-properties-rule", new PatternRule("pattern")); digester.addSetNext("*/set-nested-properties-rule", "add", ruleClassName); digester.addRule("*/set-nested-properties-rule/alias", new SetNestedPropertiesAliasRule()); digester.addFactoryCreate("*/set-top-rule", new SetTopRuleFactory()); digester.addRule("*/set-top-rule", new PatternRule("pattern")); digester.addSetNext("*/set-top-rule", "add", ruleClassName); digester.addFactoryCreate("*/set-next-rule", new SetNextRuleFactory()); digester.addRule("*/set-next-rule", new PatternRule("pattern")); digester.addSetNext("*/set-next-rule", "add", ruleClassName); digester.addFactoryCreate("*/set-root-rule", new SetRootRuleFactory()); digester.addRule("*/set-root-rule", new PatternRule("pattern")); digester.addSetNext("*/set-root-rule", "add", ruleClassName); } /** * A rule for extracting the pattern matching strings from the rules XML. * In the digester-rules document type, a pattern can either be declared * in the 'value' attribute of a element (in which case the pattern * applies to all rules elements contained within the element), * or it can be declared in the optional 'pattern' attribute of a rule * element. */ private class PatternRule extends Rule { private String attrName; private String pattern = null; /** * @param attrName The name of the attribute containing the pattern */ public PatternRule(String attrName) { super(); this.attrName = attrName; } /** * If a pattern is defined for the attribute, push it onto the * pattern stack. */ public void begin(Attributes attributes) { pattern = attributes.getValue(attrName); if (pattern != null) { patternStack.push(pattern); } } /** * If there was a pattern for this element, pop it off the pattern * stack. */ public void end() { if (pattern != null) { patternStack.pop(); } } } /** * A rule for including one rules XML file within another. Included files * behave as if they are 'macro-expanded' within the includer. This means * that the values of the pattern stack are prefixed to every pattern * in the included rules.

This rule will detect 'circular' includes, * which would result in infinite recursion. It throws a * CircularIncludeException when a cycle is detected, which will terminate * the parse. */ private class IncludeRule extends Rule { public IncludeRule() { super(); } /** * To include a rules xml file, we instantiate another Digester, and * another DigesterRulesRuleSet. We pass the * pattern stack and the target Digester to the new rule set, and * tell the Digester to parse the file. */ public void begin(Attributes attributes) throws Exception { // The path attribute gives the URI to another digester rules xml file String fileName = attributes.getValue("path"); if (fileName != null && fileName.length() > 0) { includeXMLRules(fileName); } // The class attribute gives the name of a class that implements // the DigesterRulesSource interface String className = attributes.getValue("class"); if (className != null && className.length() > 0) { includeProgrammaticRules(className); } } /** * Creates another DigesterRuleParser, and uses it to extract the rules * out of the give XML file. The contents of the current pattern stack * will be prepended to all of the pattern strings parsed from the file. */ private void includeXMLRules(String fileName) throws IOException, SAXException, CircularIncludeException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = DigesterRuleParser.this.getClass().getClassLoader(); } URL fileURL = cl.getResource(fileName); if (fileURL == null) { throw new FileNotFoundException("File \"" + fileName + "\" not found."); } fileName = fileURL.toExternalForm(); if (includedFiles.add(fileName) == false) { // circular include detected throw new CircularIncludeException(fileName); } // parse the included xml file DigesterRuleParser includedSet = new DigesterRuleParser(targetDigester, patternStack, includedFiles); includedSet.setDigesterRulesDTD(getDigesterRulesDTD()); Digester digester = new Digester(); digester.addRuleSet(includedSet); digester.push(DigesterRuleParser.this); digester.parse(fileName); includedFiles.remove(fileName); } /** * Creates an instance of the indicated class. The class must implement * the DigesterRulesSource interface. Passes the target digester to * that instance. The DigesterRulesSource instance is supposed to add * rules into the digester. The contents of the current pattern stack * will be automatically prepended to all of the pattern strings added * by the DigesterRulesSource instance. */ private void includeProgrammaticRules(String className) throws ClassNotFoundException, ClassCastException, InstantiationException, IllegalAccessException { Class cls = Class.forName(className); DigesterRulesSource rulesSource = (DigesterRulesSource) cls.newInstance(); // wrap the digester's Rules object, to prepend pattern Rules digesterRules = targetDigester.getRules(); Rules prefixWrapper = new RulesPrefixAdapter(patternStack.toString(), digesterRules); targetDigester.setRules(prefixWrapper); try { rulesSource.getRules(targetDigester); } finally { // Put the unwrapped rules back targetDigester.setRules(digesterRules); } } } /** * Wraps a Rules object. Delegates all the Rules interface methods * to the underlying Rules object. Overrides the add method to prepend * a prefix to the pattern string. */ private class RulesPrefixAdapter implements Rules { private Rules delegate; private String prefix; /** * @param patternPrefix the pattern string to prepend to the pattern * passed to the add method. * @param rules The wrapped Rules object. All of this class's methods * pass through to this object. */ public RulesPrefixAdapter(String patternPrefix, Rules rules) { prefix = patternPrefix; delegate = rules; } /** * Register a new Rule instance matching a pattern which is constructed * by concatenating the pattern prefix with the given pattern. */ public void add(String pattern, Rule rule) { StringBuffer buffer = new StringBuffer(); buffer.append(prefix); if (!pattern.startsWith("/")) { buffer.append('/'); } buffer.append(pattern); delegate.add(buffer.toString(), rule); } /** * This method passes through to the underlying Rules object. */ public void clear() { delegate.clear(); } /** * This method passes through to the underlying Rules object. */ public Digester getDigester() { return delegate.getDigester(); } /** * This method passes through to the underlying Rules object. */ public String getNamespaceURI() { return delegate.getNamespaceURI(); } /** * @deprecated Call match(namespaceURI,pattern) instead. */ public List match(String pattern) { return delegate.match(pattern); } /** * This method passes through to the underlying Rules object. */ public List match(String namespaceURI, String pattern) { return delegate.match(namespaceURI, pattern); } /** * This method passes through to the underlying Rules object. */ public List rules() { return delegate.rules(); } /** * This method passes through to the underlying Rules object. */ public void setDigester(Digester digester) { delegate.setDigester(digester); } /** * This method passes through to the underlying Rules object. */ public void setNamespaceURI(String namespaceURI) { delegate.setNamespaceURI(namespaceURI); } } /////////////////////////////////////////////////////////////////////// // Classes beyond this point are ObjectCreationFactory implementations, // used to create Rule objects and initialize them from SAX attributes. /////////////////////////////////////////////////////////////////////// /** * Factory for creating a BeanPropertySetterRule. */ private class BeanPropertySetterRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) throws Exception { Rule beanPropertySetterRule = null; String propertyname = attributes.getValue("propertyname"); if (propertyname == null) { // call the setter method corresponding to the element name. beanPropertySetterRule = new BeanPropertySetterRule(); } else { beanPropertySetterRule = new BeanPropertySetterRule(propertyname); } return beanPropertySetterRule; } } /** * Factory for creating a CallMethodRule. */ protected class CallMethodRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { Rule callMethodRule = null; String methodName = attributes.getValue("methodname"); // Select which element is to be the target. Default to zero, // ie the top object on the stack. int targetOffset = 0; String targetOffsetStr = attributes.getValue("targetoffset"); if (targetOffsetStr != null) { targetOffset = Integer.parseInt(targetOffsetStr); } if (attributes.getValue("paramcount") == null) { // call against empty method callMethodRule = new CallMethodRule(targetOffset, methodName); } else { int paramCount = Integer.parseInt(attributes.getValue("paramcount")); String paramTypesAttr = attributes.getValue("paramtypes"); if (paramTypesAttr == null || paramTypesAttr.length() == 0) { callMethodRule = new CallMethodRule(targetOffset, methodName, paramCount); } else { String[] paramTypes = getParamTypes(paramTypesAttr); callMethodRule = new CallMethodRule( targetOffset, methodName, paramCount, paramTypes); } } return callMethodRule; } /** * Process the comma separated list of paramTypes * into an array of String class names */ private String[] getParamTypes(String paramTypes) { String[] paramTypesArray; if( paramTypes != null ) { ArrayList paramTypesList = new ArrayList(); StringTokenizer tokens = new StringTokenizer( paramTypes, " \t\n\r,"); while (tokens.hasMoreTokens()) { paramTypesList.add(tokens.nextToken()); } paramTypesArray = (String[])paramTypesList.toArray(new String[0]); } else { paramTypesArray = new String[0]; } return paramTypesArray; } } /** * Factory for creating a CallParamRule. */ protected class CallParamRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { // create callparamrule int paramIndex = Integer.parseInt(attributes.getValue("paramnumber")); String attributeName = attributes.getValue("attrname"); String fromStack = attributes.getValue("from-stack"); String stackIndex = attributes.getValue("stack-index"); Rule callParamRule = null; if (attributeName == null) { if (stackIndex != null) { callParamRule = new CallParamRule( paramIndex, Integer.parseInt(stackIndex)); } else if (fromStack != null) { callParamRule = new CallParamRule( paramIndex, Boolean.valueOf(fromStack).booleanValue()); } else { callParamRule = new CallParamRule(paramIndex); } } else { if (fromStack == null) { callParamRule = new CallParamRule(paramIndex, attributeName); } else { // specifying both from-stack and attribute name is not allowed throw new RuntimeException( "Attributes from-stack and attrname cannot both be present."); } } return callParamRule; } } /** * Factory for creating a ObjectParamRule */ protected class ObjectParamRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) throws Exception { // create callparamrule int paramIndex = Integer.parseInt(attributes.getValue("paramnumber")); String attributeName = attributes.getValue("attrname"); String type = attributes.getValue("type"); String value = attributes.getValue("value"); Rule objectParamRule = null; // type name is requried if (type == null) { throw new RuntimeException("Attribute 'type' is required."); } // create object instance Object param = null; Class clazz = Class.forName(type); if (value == null) { param = clazz.newInstance(); } else { param = ConvertUtils.convert(value, clazz); } if (attributeName == null) { objectParamRule = new ObjectParamRule(paramIndex, param); } else { objectParamRule = new ObjectParamRule(paramIndex, attributeName, param); } return objectParamRule; } } /** * Factory for creating a NodeCreateRule */ protected class NodeCreateRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) throws Exception { String nodeType = attributes.getValue("type"); if (nodeType == null || "".equals(nodeType)) { // uses Node.ELEMENT_NODE return new NodeCreateRule(); } else if ("element".equals(nodeType)) { return new NodeCreateRule(Node.ELEMENT_NODE); } else if ("fragment".equals(nodeType)) { return new NodeCreateRule(Node.DOCUMENT_FRAGMENT_NODE); } else { throw new RuntimeException( "Unrecognized node type: " + nodeType + ". This attribute is optional or can have a value of element|fragment."); } } } /** * Factory for creating a FactoryCreateRule */ protected class FactoryCreateRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { String className = attributes.getValue("classname"); String attrName = attributes.getValue("attrname"); boolean ignoreExceptions = "true".equalsIgnoreCase(attributes.getValue("ignore-exceptions")); return (attrName == null || attrName.length() == 0) ? new FactoryCreateRule( className, ignoreExceptions) : new FactoryCreateRule( className, attrName, ignoreExceptions); } } /** * Factory for creating a ObjectCreateRule */ protected class ObjectCreateRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { String className = attributes.getValue("classname"); String attrName = attributes.getValue("attrname"); return (attrName == null || attrName.length() == 0) ? new ObjectCreateRule( className) : new ObjectCreateRule( className, attrName); } } /** * Factory for creating a SetPropertiesRule */ protected class SetPropertiesRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { return new SetPropertiesRule(); } } /** * Factory for creating a SetPropertyRule */ protected class SetPropertyRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { String name = attributes.getValue("name"); String value = attributes.getValue("value"); return new SetPropertyRule( name, value); } } /** * Factory for creating a SetNestedPropertiesRule */ protected class SetNestedPropertiesRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { boolean allowUnknownChildElements = "true".equalsIgnoreCase(attributes.getValue("allow-unknown-child-elements")); SetNestedPropertiesRule snpr = new SetNestedPropertiesRule(); snpr.setAllowUnknownChildElements( allowUnknownChildElements ); return snpr; } } /** * Factory for creating a SetTopRuleFactory */ protected class SetTopRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { String methodName = attributes.getValue("methodname"); String paramType = attributes.getValue("paramtype"); return (paramType == null || paramType.length() == 0) ? new SetTopRule( methodName) : new SetTopRule( methodName, paramType); } } /** * Factory for creating a SetNextRuleFactory */ protected class SetNextRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { String methodName = attributes.getValue("methodname"); String paramType = attributes.getValue("paramtype"); return (paramType == null || paramType.length() == 0) ? new SetNextRule( methodName) : new SetNextRule( methodName, paramType); } } /** * Factory for creating a SetRootRuleFactory */ protected class SetRootRuleFactory extends AbstractObjectCreationFactory { public Object createObject(Attributes attributes) { String methodName = attributes.getValue("methodname"); String paramType = attributes.getValue("paramtype"); return (paramType == null || paramType.length() == 0) ? new SetRootRule( methodName) : new SetRootRule( methodName, paramType); } } /** * A rule for adding a attribute-property alias to the custom alias mappings of * the containing SetPropertiesRule rule. */ protected class SetPropertiesAliasRule extends Rule { /** *

Base constructor.

*/ public SetPropertiesAliasRule() { super(); } /** * Add the alias to the SetPropertiesRule object created by the * enclosing tag. */ public void begin(Attributes attributes) { String attrName = attributes.getValue("attr-name"); String propName = attributes.getValue("prop-name"); SetPropertiesRule rule = (SetPropertiesRule) digester.peek(); rule.addAlias(attrName, propName); } } /** * A rule for adding a attribute-property alias to the custom alias mappings of * the containing SetNestedPropertiesRule rule. */ protected class SetNestedPropertiesAliasRule extends Rule { /** *

Base constructor.

*/ public SetNestedPropertiesAliasRule() { super(); } /** * Add the alias to the SetNestedPropertiesRule object created by the * enclosing tag. */ public void begin(Attributes attributes) { String attrName = attributes.getValue("attr-name"); String propName = attributes.getValue("prop-name"); SetNestedPropertiesRule rule = (SetNestedPropertiesRule) digester.peek(); rule.addAlias(attrName, propName); } } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/DigesterRulesSource.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/DigesterRulesSourc0000644000175000017500000000244711226450007033703 0ustar twernertwerner/* $Id: DigesterRulesSource.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; import org.apache.commons.digester.Digester; /** * Interface for classes that initialize a Digester Rules object with * Digester Rules. * * @since 1.2 */ public interface DigesterRulesSource { /** * Creates and adds Digester Rules to a given Rules object * @param digester the Digester to add the new Rule objects to */ void getRules(Digester digester); } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/DigesterLoadingException.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/xmlrules/DigesterLoadingExc0000644000175000017500000000366711226450007033617 0ustar twernertwerner/* $Id: DigesterLoadingException.java 476205 2006-11-17 16:43:10Z dennisl $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.xmlrules; /** * Thrown when an error occurs while parsing XML into Digester rules. * * @since 1.2 */ public class DigesterLoadingException extends Exception { private Throwable cause = null; /** * @param msg a String detailing the reason for the exception */ public DigesterLoadingException(String msg) { super(msg); } /** * @param cause underlying exception that caused this to be thrown */ public DigesterLoadingException(Throwable cause) { this(cause.getMessage()); this.cause = cause; } /** * @param msg a String detailing the reason for the exception * @param cause underlying exception that caused this to be thrown */ public DigesterLoadingException(String msg, Throwable cause) { this(msg); this.cause = cause; } /** * Return the cause of this exception (if any) as specified in the * exception constructor. * * @since 1.8 */ public Throwable getCause() { return cause; } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/SetPropertyRule.java0000644000175000017500000001307311226450007032300 0ustar twernertwerner/* $Id: SetPropertyRule.java 568192 2007-08-21 16:41:16Z bayard $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.beans.PropertyDescriptor; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.DynaBean; import org.apache.commons.beanutils.DynaProperty; import org.apache.commons.beanutils.PropertyUtils; import org.xml.sax.Attributes; /** * Rule implementation that sets an individual property on the object at the * top of the stack, based on attributes with specified names. */ public class SetPropertyRule extends Rule { // ----------------------------------------------------------- Constructors /** * Construct a "set property" rule with the specified name and value * attributes. * * @param digester The digester with which this rule is associated * @param name Name of the attribute that will contain the name of the * property to be set * @param value Name of the attribute that will contain the value to which * the property should be set * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #SetPropertyRule(String name, String value)} instead. */ public SetPropertyRule(Digester digester, String name, String value) { this(name, value); } /** * Construct a "set property" rule with the specified name and value * attributes. * * @param name Name of the attribute that will contain the name of the * property to be set * @param value Name of the attribute that will contain the value to which * the property should be set */ public SetPropertyRule(String name, String value) { this.name = name; this.value = value; } // ----------------------------------------------------- Instance Variables /** * The attribute that will contain the property name. */ protected String name = null; /** * The attribute that will contain the property value. */ protected String value = null; // --------------------------------------------------------- Public Methods /** * Process the beginning of this element. * * @param attributes The attribute list of this element * * @exception NoSuchMethodException if the bean does not * have a writeable property of the specified name */ public void begin(Attributes attributes) throws Exception { if (attributes.getLength() == 0 ) { return; } // Identify the actual property name and value to be used String actualName = null; String actualValue = null; for (int i = 0; i < attributes.getLength(); i++) { String name = attributes.getLocalName(i); if ("".equals(name)) { name = attributes.getQName(i); } String value = attributes.getValue(i); if (name.equals(this.name)) { actualName = value; } else if (name.equals(this.value)) { actualValue = value; } } // Get a reference to the top object Object top = digester.peek(); // Log some debugging information if (digester.log.isDebugEnabled()) { digester.log.debug("[SetPropertyRule]{" + digester.match + "} Set " + top.getClass().getName() + " property " + actualName + " to " + actualValue); } // Force an exception if the property does not exist // (BeanUtils.setProperty() silently returns in this case) // // This code should probably use PropertyUtils.isWriteable(), // like SetPropertiesRule does. if (top instanceof DynaBean) { DynaProperty desc = ((DynaBean) top).getDynaClass().getDynaProperty(actualName); if (desc == null) { throw new NoSuchMethodException ("Bean has no property named " + actualName); } } else /* this is a standard JavaBean */ { PropertyDescriptor desc = PropertyUtils.getPropertyDescriptor(top, actualName); if (desc == null) { throw new NoSuchMethodException ("Bean has no property named " + actualName); } } // Set the property (with conversion as necessary) BeanUtils.setProperty(top, actualName, actualValue); } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("SetPropertyRule["); sb.append("name="); sb.append(name); sb.append(", value="); sb.append(value); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/PathCallParamRule.java0000644000175000017500000000561211226450007032451 0ustar twernertwerner/* $Id: PathCallParamRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; /** *

Rule implementation that saves a parameter containing the * Digester matching path for use by a surrounding * CallMethodRule. This Rule is most useful when making * extensive use of wildcards in rule patterns.

* * @since 1.6 */ public class PathCallParamRule extends Rule { // ----------------------------------------------------------- Constructors /** * Construct a "call parameter" rule that will save the body text of this * element as the parameter value. * * @param paramIndex The zero-relative parameter number */ public PathCallParamRule(int paramIndex) { this.paramIndex = paramIndex; } // ----------------------------------------------------- Instance Variables /** * The zero-relative index of the parameter we are saving. */ protected int paramIndex = 0; // --------------------------------------------------------- Public Methods /** * Process the start of this element. * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param attributes The attribute list for this element */ public void begin(String namespace, String name, Attributes attributes) throws Exception { String param = getDigester().getMatch(); if(param != null) { Object parameters[] = (Object[]) digester.peekParams(); parameters[paramIndex] = param; } } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("PathCallParamRule["); sb.append("paramIndex="); sb.append(paramIndex); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/Digester.java0000644000175000017500000031050011226450007030711 0ustar twernertwerner/* $Id: Digester.java 728881 2008-12-23 06:16:55Z rahul $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.net.URLConnection; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.EmptyStackException; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.collections.ArrayStack; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; /** *

A Digester processes an XML input stream by matching a * series of element nesting patterns to execute Rules that have been added * prior to the start of parsing. This package was inspired by the * XmlMapper class that was part of Tomcat 3.0 and 3.1, * but is organized somewhat differently.

* *

See the Digester * Developer Guide for more information.

* *

IMPLEMENTATION NOTE - A single Digester instance may * only be used within the context of a single thread at a time, and a call * to parse() must be completed before another can be initiated * even from the same thread.

* *

A Digester instance should not be used for parsing more than one input * document. The problem is that the Digester class has quite a few member * variables whose values "evolve" as SAX events are received during a parse. * When reusing the Digester instance, all these members must be reset back * to their initial states before the second parse begins. The "clear()" * method makes a stab at resetting these, but it is actually rather a * difficult problem. If you are determined to reuse Digester instances, then * at the least you should call the clear() method before each parse, and must * call it if the Digester parse terminates due to an exception during a parse. *

* *

IMPLEMENTATION NOTE - A bug in Xerces 2.0.2 prevents * the support of XML schema. You need Xerces 2.1/2.3 and up to make * this class working with XML schema

*/ public class Digester extends DefaultHandler { // --------------------------------------------------------- Constructors /** * Construct a new Digester with default properties. */ public Digester() { super(); } /** * Construct a new Digester, allowing a SAXParser to be passed in. This * allows Digester to be used in environments which are unfriendly to * JAXP1.1 (such as WebLogic 6.0). This may help in places where * you are able to load JAXP 1.1 classes yourself. */ public Digester(SAXParser parser) { super(); this.parser = parser; } /** * Construct a new Digester, allowing an XMLReader to be passed in. This * allows Digester to be used in environments which are unfriendly to * JAXP1.1 (such as WebLogic 6.0). Note that if you use this option you * have to configure namespace and validation support yourself, as these * properties only affect the SAXParser and emtpy constructor. */ public Digester(XMLReader reader) { super(); this.reader = reader; } // --------------------------------------------------- Instance Variables /** * The body text of the current element. */ protected StringBuffer bodyText = new StringBuffer(); /** * The stack of body text string buffers for surrounding elements. */ protected ArrayStack bodyTexts = new ArrayStack(); /** * Stack whose elements are List objects, each containing a list of * Rule objects as returned from Rules.getMatch(). As each xml element * in the input is entered, the matching rules are pushed onto this * stack. After the end tag is reached, the matches are popped again. * The depth of is stack is therefore exactly the same as the current * "nesting" level of the input xml. * * @since 1.6 */ protected ArrayStack matches = new ArrayStack(10); /** * The class loader to use for instantiating application objects. * If not specified, the context class loader, or the class loader * used to load Digester itself, is used, based on the value of the * useContextClassLoader variable. */ protected ClassLoader classLoader = null; /** * Has this Digester been configured yet. */ protected boolean configured = false; /** * The EntityResolver used by the SAX parser. By default it use this class */ protected EntityResolver entityResolver; /** * The URLs of entityValidator that have been registered, keyed by the public * identifier that corresponds. */ protected HashMap entityValidator = new HashMap(); /** * The application-supplied error handler that is notified when parsing * warnings, errors, or fatal errors occur. */ protected ErrorHandler errorHandler = null; /** * The SAXParserFactory that is created the first time we need it. */ protected SAXParserFactory factory = null; /** * @deprecated This is now managed by {@link ParserFeatureSetterFactory} */ protected String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; /** * The Locator associated with our parser. */ protected Locator locator = null; /** * The current match pattern for nested element processing. */ protected String match = ""; /** * Do we want a "namespace aware" parser. */ protected boolean namespaceAware = false; /** * Registered namespaces we are currently processing. The key is the * namespace prefix that was declared in the document. The value is an * ArrayStack of the namespace URIs this prefix has been mapped to -- * the top Stack element is the most current one. (This architecture * is required because documents can declare nested uses of the same * prefix for different Namespace URIs). */ protected HashMap namespaces = new HashMap(); /** * The parameters stack being utilized by CallMethodRule and * CallParamRule rules. */ protected ArrayStack params = new ArrayStack(); /** * The SAXParser we will use to parse the input stream. */ protected SAXParser parser = null; /** * The public identifier of the DTD we are currently parsing under * (if any). */ protected String publicId = null; /** * The XMLReader used to parse digester rules. */ protected XMLReader reader = null; /** * The "root" element of the stack (in other words, the last object * that was popped. */ protected Object root = null; /** * The Rules implementation containing our collection of * Rule instances and associated matching policy. If not * established before the first rule is added, a default implementation * will be provided. */ protected Rules rules = null; /** * The XML schema language to use for validating an XML instance. By * default this value is set to W3C_XML_SCHEMA */ protected String schemaLanguage = W3C_XML_SCHEMA; /** * The XML schema to use for validating an XML instance. */ protected String schemaLocation = null; /** * The object stack being constructed. */ protected ArrayStack stack = new ArrayStack(); /** * Do we want to use the Context ClassLoader when loading classes * for instantiating new objects. Default is false. */ protected boolean useContextClassLoader = false; /** * Do we want to use a validating parser. */ protected boolean validating = false; /** * The Log to which most logging calls will be made. */ protected Log log = LogFactory.getLog("org.apache.commons.digester.Digester"); /** * The Log to which all SAX event related logging calls will be made. */ protected Log saxLog = LogFactory.getLog("org.apache.commons.digester.Digester.sax"); /** * The schema language supported. By default, we use this one. */ protected static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; /** * An optional class that substitutes values in attributes and body text. * This may be null and so a null check is always required before use. */ protected Substitutor substitutor; /** Stacks used for interrule communication, indexed by name String */ private HashMap stacksByName = new HashMap(); /** * If not null, then calls by the parser to this object's characters, * startElement, endElement and processingInstruction methods are * forwarded to the specified object. This is intended to allow rules * to temporarily "take control" of the sax events. In particular, * this is used by NodeCreateRule. *

* See setCustomContentHandler. */ private ContentHandler customContentHandler = null; /** * Object which will receive callbacks for every pop/push action * on the default stack or named stacks. */ private StackAction stackAction = null; // ------------------------------------------------------------- Properties /** * Return the currently mapped namespace URI for the specified prefix, * if any; otherwise return null. These mappings come and * go dynamically as the document is parsed. * * @param prefix Prefix to look up */ public String findNamespaceURI(String prefix) { ArrayStack nsStack = (ArrayStack) namespaces.get(prefix); if (nsStack == null) { return null; } try { return ((String) nsStack.peek()); } catch (EmptyStackException e) { return null; } } /** * Return the class loader to be used for instantiating application objects * when required. This is determined based upon the following rules: *

    *
  • The class loader set by setClassLoader(), if any
  • *
  • The thread context class loader, if it exists and the * useContextClassLoader property is set to true
  • *
  • The class loader used to load the Digester class itself. *
*/ public ClassLoader getClassLoader() { if (this.classLoader != null) { return (this.classLoader); } if (this.useContextClassLoader) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader != null) { return (classLoader); } } return (this.getClass().getClassLoader()); } /** * Set the class loader to be used for instantiating application objects * when required. * * @param classLoader The new class loader to use, or null * to revert to the standard rules */ public void setClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } /** * Return the current depth of the element stack. */ public int getCount() { return (stack.size()); } /** * Return the name of the XML element that is currently being processed. */ public String getCurrentElementName() { String elementName = match; int lastSlash = elementName.lastIndexOf('/'); if (lastSlash >= 0) { elementName = elementName.substring(lastSlash + 1); } return (elementName); } /** * Return the debugging detail level of our currently enabled logger. * * @deprecated This method now always returns 0. Digester uses the apache * jakarta commons-logging library; see the documentation for that library * for more information. */ public int getDebug() { return (0); } /** * Set the debugging detail level of our currently enabled logger. * * @param debug New debugging detail level (0=off, increasing integers * for more detail) * * @deprecated This method now has no effect at all. Digester uses * the apache jakarta comons-logging library; see the documentation * for that library for more information. */ public void setDebug(int debug) { ; // No action is taken } /** * Return the error handler for this Digester. */ public ErrorHandler getErrorHandler() { return (this.errorHandler); } /** * Set the error handler for this Digester. * * @param errorHandler The new error handler */ public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; } /** * Return the SAXParserFactory we will use, creating one if necessary. */ public SAXParserFactory getFactory() { if (factory == null) { factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(namespaceAware); factory.setValidating(validating); } return (factory); } /** * Returns a flag indicating whether the requested feature is supported * by the underlying implementation of org.xml.sax.XMLReader. * See the saxproject website * for information about the standard SAX2 feature flags. * * @param feature Name of the feature to inquire about * * @exception ParserConfigurationException if a parser configuration error * occurs * @exception SAXNotRecognizedException if the property name is * not recognized * @exception SAXNotSupportedException if the property name is * recognized but not supported */ public boolean getFeature(String feature) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { return (getFactory().getFeature(feature)); } /** * Sets a flag indicating whether the requested feature is supported * by the underlying implementation of org.xml.sax.XMLReader. * See the saxproject website * for information about the standard SAX2 feature flags. In order to be * effective, this method must be called before the * getParser() method is called for the first time, either * directly or indirectly. * * @param feature Name of the feature to set the status for * @param value The new value for this feature * * @exception ParserConfigurationException if a parser configuration error * occurs * @exception SAXNotRecognizedException if the property name is * not recognized * @exception SAXNotSupportedException if the property name is * recognized but not supported */ public void setFeature(String feature, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { getFactory().setFeature(feature, value); } /** * Return the current Logger associated with this instance of the Digester */ public Log getLogger() { return log; } /** * Set the current logger for this Digester. */ public void setLogger(Log log) { this.log = log; } /** * Gets the logger used for logging SAX-related information. * Note the output is finely grained. * * @since 1.6 */ public Log getSAXLogger() { return saxLog; } /** * Sets the logger used for logging SAX-related information. * Note the output is finely grained. * @param saxLog Log, not null * * @since 1.6 */ public void setSAXLogger(Log saxLog) { this.saxLog = saxLog; } /** * Return the current rule match path */ public String getMatch() { return match; } /** * Return the "namespace aware" flag for parsers we create. */ public boolean getNamespaceAware() { return (this.namespaceAware); } /** * Set the "namespace aware" flag for parsers we create. * * @param namespaceAware The new "namespace aware" flag */ public void setNamespaceAware(boolean namespaceAware) { this.namespaceAware = namespaceAware; } /** * Set the publid id of the current file being parse. * @param publicId the DTD/Schema public's id. */ public void setPublicId(String publicId){ this.publicId = publicId; } /** * Return the public identifier of the DTD we are currently * parsing under, if any. */ public String getPublicId() { return (this.publicId); } /** * Return the namespace URI that will be applied to all subsequently * added Rule objects. */ public String getRuleNamespaceURI() { return (getRules().getNamespaceURI()); } /** * Set the namespace URI that will be applied to all subsequently * added Rule objects. * * @param ruleNamespaceURI Namespace URI that must match on all * subsequently added rules, or null for matching * regardless of the current namespace URI */ public void setRuleNamespaceURI(String ruleNamespaceURI) { getRules().setNamespaceURI(ruleNamespaceURI); } /** * Return the SAXParser we will use to parse the input stream. If there * is a problem creating the parser, return null. */ public SAXParser getParser() { // Return the parser we already created (if any) if (parser != null) { return (parser); } // Create a new parser try { if (validating && (schemaLocation != null)) { // There is no portable way to specify the location of // an xml schema to be applied to the input document, so // we have to use parser-specific code for this. That code // is hidden behind the ParserFeatureSetterFactory class. Properties properties = new Properties(); properties.put("SAXParserFactory", getFactory()); if (schemaLocation != null) { properties.put("schemaLocation", schemaLocation); properties.put("schemaLanguage", schemaLanguage); } parser = ParserFeatureSetterFactory.newSAXParser(properties); } else { // The user doesn't want to use any non-portable parsing features, // so we can just use the portable API here. Note that method // getFactory returns a factory already configured with the // appropriate namespaceAware and validating properties. parser = getFactory().newSAXParser(); } } catch (Exception e) { log.error("Digester.getParser: ", e); return (null); } return (parser); } /** * Return the current value of the specified property for the underlying * XMLReader implementation. * See the saxproject website * for information about the standard SAX2 properties. * * @param property Property name to be retrieved * * @exception SAXNotRecognizedException if the property name is * not recognized * @exception SAXNotSupportedException if the property name is * recognized but not supported */ public Object getProperty(String property) throws SAXNotRecognizedException, SAXNotSupportedException { return (getParser().getProperty(property)); } /** * Set the current value of the specified property for the underlying * XMLReader implementation. * See the saxproject website * for information about the standard SAX2 properties. * * @param property Property name to be set * @param value Property value to be set * * @exception SAXNotRecognizedException if the property name is * not recognized * @exception SAXNotSupportedException if the property name is * recognized but not supported */ public void setProperty(String property, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { getParser().setProperty(property, value); } /** * By setting the reader in the constructor, you can bypass JAXP and * be able to use digester in Weblogic 6.0. * * @deprecated Use getXMLReader() instead, which can throw a * SAXException if the reader cannot be instantiated */ public XMLReader getReader() { try { return (getXMLReader()); } catch (SAXException e) { log.error("Cannot get XMLReader", e); return (null); } } /** * Return the Rules implementation object containing our * rules collection and associated matching policy. If none has been * established, a default implementation will be created and returned. */ public Rules getRules() { if (this.rules == null) { this.rules = new RulesBase(); this.rules.setDigester(this); } return (this.rules); } /** * Set the Rules implementation object containing our * rules collection and associated matching policy. * * @param rules New Rules implementation */ public void setRules(Rules rules) { this.rules = rules; this.rules.setDigester(this); } /** * Return the XML Schema URI used for validating an XML instance. */ public String getSchema() { return (this.schemaLocation); } /** * Set the XML Schema URI used for validating the input XML. *

* It is often desirable to force the input document to be * validated against a particular schema regardless of what type * the input document declares itself to be. This method allows that * to be done. *

* Note, however, that there is no standard API for enabling this * feature on the underlying SAX parser; this method therefore only works * for those parsers explicitly supported by Digester's * ParserFeatureSetterFactory class. If the underlying parser does not * support the feature, or is not one of the supported parsers, then * an exception will be thrown when getParser is called (explicitly, * or implicitly via the parse method). *

* See also method setSchemaLanguage which allows the type of the schema * specified here to be defined. By default, the schema is expected to * be a W3C xml schema definition. *

* IMPORTANT NOTE: This functionality was never very reliable, and has * been horribly broken since the 1.6 release of Digester. There are * currently no plans to fix it, so you are strongly recommended to * avoid using this method. Instead, create an XMLParser instance * yourself, configure validation appropriately, and pass it as a * parameter to the Digester constructor. * * @param schemaLocation a URI to the schema. */ public void setSchema(String schemaLocation){ this.schemaLocation = schemaLocation; } /** * Return the XML Schema language used when parsing. */ public String getSchemaLanguage() { return (this.schemaLanguage); } /** * Set the XML Schema language used when parsing. By default, we use W3C. * * @param schemaLanguage a URI to the schema language. */ public void setSchemaLanguage(String schemaLanguage){ this.schemaLanguage = schemaLanguage; } /** * Return the boolean as to whether the context classloader should be used. */ public boolean getUseContextClassLoader() { return useContextClassLoader; } /** * Determine whether to use the Context ClassLoader (the one found by * calling Thread.currentThread().getContextClassLoader()) * to resolve/load classes that are defined in various rules. If not * using Context ClassLoader, then the class-loading defaults to * using the calling-class' ClassLoader. * * @param use determines whether to use Context ClassLoader. */ public void setUseContextClassLoader(boolean use) { useContextClassLoader = use; } /** * Return the validating parser flag. */ public boolean getValidating() { return (this.validating); } /** * Set the validating parser flag. This must be called before * parse() is called the first time. * * @param validating The new validating parser flag. */ public void setValidating(boolean validating) { this.validating = validating; } /** * Return the XMLReader to be used for parsing the input document. * * FIX ME: there is a bug in JAXP/XERCES that prevent the use of a * parser that contains a schema with a DTD. * @exception SAXException if no XMLReader can be instantiated */ public XMLReader getXMLReader() throws SAXException { if (reader == null){ reader = getParser().getXMLReader(); } reader.setDTDHandler(this); reader.setContentHandler(this); if (entityResolver == null){ reader.setEntityResolver(this); } else { reader.setEntityResolver(entityResolver); } reader.setErrorHandler(this); return reader; } /** * Gets the Substitutor used to convert attributes and body text. * @return Substitutor, null if not substitutions are to be performed. */ public Substitutor getSubstitutor() { return substitutor; } /** * Sets the Substitutor to be used to convert attributes and body text. * @param substitutor the Substitutor to be used to convert attributes and body text * or null if not substitution of these values is to be performed. */ public void setSubstitutor(Substitutor substitutor) { this.substitutor = substitutor; } /* * See setCustomContentHandler. * * @since 1.7 */ public ContentHandler getCustomContentHandler() { return customContentHandler; } /** * Redirects (or cancels redirecting) of SAX ContentHandler events to an * external object. *

* When this object's customContentHandler is non-null, any SAX events * received from the parser will simply be passed on to the specified * object instead of this object handling them. This allows Rule classes * to take control of the SAX event stream for a while in order to do * custom processing. Such a rule should save the old value before setting * a new one, and restore the old value in order to resume normal digester * processing. *

* An example of a Rule which needs this feature is NodeCreateRule. *

* Note that saving the old value is probably not needed as it should always * be null; a custom rule that wants to take control could only have been * called when there was no custom content handler. But it seems cleaner * to properly save/restore the value and maybe some day this will come in * useful. *

* Note also that this is not quite equivalent to *

     * digester.getXMLReader().setContentHandler(handler)
     * 
* for these reasons: *
    *
  • Some xml parsers don't like having setContentHandler called after * parsing has started. The Aelfred parser is one example.
  • *
  • Directing the events via the Digester object potentially allows * us to log information about those SAX events at the digester level.
  • *
* * @since 1.7 */ public void setCustomContentHandler(ContentHandler handler) { customContentHandler = handler; } /** * Define a callback object which is invoked whever an object is pushed onto * a digester object stack, or popped off one. * * @since 1.8 */ public void setStackAction(StackAction stackAction) { this.stackAction = stackAction; } /** * See setStackAction. * * @since 1.8 */ public StackAction getStackAction() { return stackAction; } /** * Get the most current namespaces for all prefixes. * * @return Map A map with namespace prefixes as keys and most current * namespace URIs for the corresponding prefixes as values * * @since 1.8 */ public Map getCurrentNamespaces() { if (!namespaceAware) { log.warn("Digester is not namespace aware"); } Map currentNamespaces = new HashMap(); Iterator nsIterator = namespaces.entrySet().iterator(); while (nsIterator.hasNext()) { Map.Entry nsEntry = (Map.Entry) nsIterator.next(); try { currentNamespaces.put(nsEntry.getKey(), ((ArrayStack) nsEntry.getValue()).peek()); } catch (RuntimeException e) { // rethrow, after logging log.error(e.getMessage(), e); throw e; } } return currentNamespaces; } // ------------------------------------------------- ContentHandler Methods /** * Process notification of character data received from the body of * an XML element. * * @param buffer The characters from the XML document * @param start Starting offset into the buffer * @param length Number of characters from the buffer * * @exception SAXException if a parsing error is to be reported */ public void characters(char buffer[], int start, int length) throws SAXException { if (customContentHandler != null) { // forward calls instead of handling them here customContentHandler.characters(buffer, start, length); return; } if (saxLog.isDebugEnabled()) { saxLog.debug("characters(" + new String(buffer, start, length) + ")"); } bodyText.append(buffer, start, length); } /** * Process notification of the end of the document being reached. * * @exception SAXException if a parsing error is to be reported */ public void endDocument() throws SAXException { if (saxLog.isDebugEnabled()) { if (getCount() > 1) { saxLog.debug("endDocument(): " + getCount() + " elements left"); } else { saxLog.debug("endDocument()"); } } // Fire "finish" events for all defined rules Iterator rules = getRules().rules().iterator(); while (rules.hasNext()) { Rule rule = (Rule) rules.next(); try { rule.finish(); } catch (Exception e) { log.error("Finish event threw exception", e); throw createSAXException(e); } catch (Error e) { log.error("Finish event threw error", e); throw e; } } // Perform final cleanup clear(); } /** * Process notification of the end of an XML element being reached. * * @param namespaceURI - The Namespace URI, or the empty string if the * element has no Namespace URI or if Namespace processing is not * being performed. * @param localName - The local name (without prefix), or the empty * string if Namespace processing is not being performed. * @param qName - The qualified XML 1.0 name (with prefix), or the * empty string if qualified names are not available. * @exception SAXException if a parsing error is to be reported */ public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (customContentHandler != null) { // forward calls instead of handling them here customContentHandler.endElement(namespaceURI, localName, qName); return; } boolean debug = log.isDebugEnabled(); if (debug) { if (saxLog.isDebugEnabled()) { saxLog.debug("endElement(" + namespaceURI + "," + localName + "," + qName + ")"); } log.debug(" match='" + match + "'"); log.debug(" bodyText='" + bodyText + "'"); } // the actual element name is either in localName or qName, depending // on whether the parser is namespace aware String name = localName; if ((name == null) || (name.length() < 1)) { name = qName; } // Fire "body" events for all relevant rules List rules = (List) matches.pop(); if ((rules != null) && (rules.size() > 0)) { String bodyText = this.bodyText.toString(); Substitutor substitutor = getSubstitutor(); if (substitutor!= null) { bodyText = substitutor.substitute(bodyText); } for (int i = 0; i < rules.size(); i++) { try { Rule rule = (Rule) rules.get(i); if (debug) { log.debug(" Fire body() for " + rule); } rule.body(namespaceURI, name, bodyText); } catch (Exception e) { log.error("Body event threw exception", e); throw createSAXException(e); } catch (Error e) { log.error("Body event threw error", e); throw e; } } } else { if (debug) { log.debug(" No rules found matching '" + match + "'."); } } // Recover the body text from the surrounding element bodyText = (StringBuffer) bodyTexts.pop(); if (debug) { log.debug(" Popping body text '" + bodyText.toString() + "'"); } // Fire "end" events for all relevant rules in reverse order if (rules != null) { for (int i = 0; i < rules.size(); i++) { int j = (rules.size() - i) - 1; try { Rule rule = (Rule) rules.get(j); if (debug) { log.debug(" Fire end() for " + rule); } rule.end(namespaceURI, name); } catch (Exception e) { log.error("End event threw exception", e); throw createSAXException(e); } catch (Error e) { log.error("End event threw error", e); throw e; } } } // Recover the previous match expression int slash = match.lastIndexOf('/'); if (slash >= 0) { match = match.substring(0, slash); } else { match = ""; } } /** * Process notification that a namespace prefix is going out of scope. * * @param prefix Prefix that is going out of scope * * @exception SAXException if a parsing error is to be reported */ public void endPrefixMapping(String prefix) throws SAXException { if (saxLog.isDebugEnabled()) { saxLog.debug("endPrefixMapping(" + prefix + ")"); } // Deregister this prefix mapping ArrayStack stack = (ArrayStack) namespaces.get(prefix); if (stack == null) { return; } try { stack.pop(); if (stack.empty()) namespaces.remove(prefix); } catch (EmptyStackException e) { throw createSAXException("endPrefixMapping popped too many times"); } } /** * Process notification of ignorable whitespace received from the body of * an XML element. * * @param buffer The characters from the XML document * @param start Starting offset into the buffer * @param len Number of characters from the buffer * * @exception SAXException if a parsing error is to be reported */ public void ignorableWhitespace(char buffer[], int start, int len) throws SAXException { if (saxLog.isDebugEnabled()) { saxLog.debug("ignorableWhitespace(" + new String(buffer, start, len) + ")"); } ; // No processing required } /** * Process notification of a processing instruction that was encountered. * * @param target The processing instruction target * @param data The processing instruction data (if any) * * @exception SAXException if a parsing error is to be reported */ public void processingInstruction(String target, String data) throws SAXException { if (customContentHandler != null) { // forward calls instead of handling them here customContentHandler.processingInstruction(target, data); return; } if (saxLog.isDebugEnabled()) { saxLog.debug("processingInstruction('" + target + "','" + data + "')"); } ; // No processing is required } /** * Gets the document locator associated with our parser. * * @return the Locator supplied by the document parser */ public Locator getDocumentLocator() { return locator; } /** * Sets the document locator associated with our parser. * * @param locator The new locator */ public void setDocumentLocator(Locator locator) { if (saxLog.isDebugEnabled()) { saxLog.debug("setDocumentLocator(" + locator + ")"); } this.locator = locator; } /** * Process notification of a skipped entity. * * @param name Name of the skipped entity * * @exception SAXException if a parsing error is to be reported */ public void skippedEntity(String name) throws SAXException { if (saxLog.isDebugEnabled()) { saxLog.debug("skippedEntity(" + name + ")"); } ; // No processing required } /** * Process notification of the beginning of the document being reached. * * @exception SAXException if a parsing error is to be reported */ public void startDocument() throws SAXException { if (saxLog.isDebugEnabled()) { saxLog.debug("startDocument()"); } // ensure that the digester is properly configured, as // the digester could be used as a SAX ContentHandler // rather than via the parse() methods. configure(); } /** * Process notification of the start of an XML element being reached. * * @param namespaceURI The Namespace URI, or the empty string if the element * has no Namespace URI or if Namespace processing is not being performed. * @param localName The local name (without prefix), or the empty * string if Namespace processing is not being performed. * @param qName The qualified name (with prefix), or the empty * string if qualified names are not available.\ * @param list The attributes attached to the element. If there are * no attributes, it shall be an empty Attributes object. * @exception SAXException if a parsing error is to be reported */ public void startElement(String namespaceURI, String localName, String qName, Attributes list) throws SAXException { boolean debug = log.isDebugEnabled(); if (customContentHandler != null) { // forward calls instead of handling them here customContentHandler.startElement(namespaceURI, localName, qName, list); return; } if (saxLog.isDebugEnabled()) { saxLog.debug("startElement(" + namespaceURI + "," + localName + "," + qName + ")"); } // Save the body text accumulated for our surrounding element bodyTexts.push(bodyText); if (debug) { log.debug(" Pushing body text '" + bodyText.toString() + "'"); } bodyText = new StringBuffer(); // the actual element name is either in localName or qName, depending // on whether the parser is namespace aware String name = localName; if ((name == null) || (name.length() < 1)) { name = qName; } // Compute the current matching rule StringBuffer sb = new StringBuffer(match); if (match.length() > 0) { sb.append('/'); } sb.append(name); match = sb.toString(); if (debug) { log.debug(" New match='" + match + "'"); } // Fire "begin" events for all relevant rules List rules = getRules().match(namespaceURI, match); matches.push(rules); if ((rules != null) && (rules.size() > 0)) { Substitutor substitutor = getSubstitutor(); if (substitutor!= null) { list = substitutor.substitute(list); } for (int i = 0; i < rules.size(); i++) { try { Rule rule = (Rule) rules.get(i); if (debug) { log.debug(" Fire begin() for " + rule); } rule.begin(namespaceURI, name, list); } catch (Exception e) { log.error("Begin event threw exception", e); throw createSAXException(e); } catch (Error e) { log.error("Begin event threw error", e); throw e; } } } else { if (debug) { log.debug(" No rules found matching '" + match + "'."); } } } /** * Process notification that a namespace prefix is coming in to scope. * * @param prefix Prefix that is being declared * @param namespaceURI Corresponding namespace URI being mapped to * * @exception SAXException if a parsing error is to be reported */ public void startPrefixMapping(String prefix, String namespaceURI) throws SAXException { if (saxLog.isDebugEnabled()) { saxLog.debug("startPrefixMapping(" + prefix + "," + namespaceURI + ")"); } // Register this prefix mapping ArrayStack stack = (ArrayStack) namespaces.get(prefix); if (stack == null) { stack = new ArrayStack(); namespaces.put(prefix, stack); } stack.push(namespaceURI); } // ----------------------------------------------------- DTDHandler Methods /** * Receive notification of a notation declaration event. * * @param name The notation name * @param publicId The public identifier (if any) * @param systemId The system identifier (if any) */ public void notationDecl(String name, String publicId, String systemId) { if (saxLog.isDebugEnabled()) { saxLog.debug("notationDecl(" + name + "," + publicId + "," + systemId + ")"); } } /** * Receive notification of an unparsed entity declaration event. * * @param name The unparsed entity name * @param publicId The public identifier (if any) * @param systemId The system identifier (if any) * @param notation The name of the associated notation */ public void unparsedEntityDecl(String name, String publicId, String systemId, String notation) { if (saxLog.isDebugEnabled()) { saxLog.debug("unparsedEntityDecl(" + name + "," + publicId + "," + systemId + "," + notation + ")"); } } // ----------------------------------------------- EntityResolver Methods /** * Set the EntityResolver used by SAX when resolving * public id and system id. * This must be called before the first call to parse(). * @param entityResolver a class that implement the EntityResolver interface. */ public void setEntityResolver(EntityResolver entityResolver){ this.entityResolver = entityResolver; } /** * Return the Entity Resolver used by the SAX parser. * @return Return the Entity Resolver used by the SAX parser. */ public EntityResolver getEntityResolver(){ return entityResolver; } /** * Resolve the requested external entity. * * @param publicId The public identifier of the entity being referenced * @param systemId The system identifier of the entity being referenced * * @exception SAXException if a parsing exception occurs * */ public InputSource resolveEntity(String publicId, String systemId) throws SAXException { if (saxLog.isDebugEnabled()) { saxLog.debug("resolveEntity('" + publicId + "', '" + systemId + "')"); } if (publicId != null) this.publicId = publicId; // Has this system identifier been registered? URL entityURL = null; if (publicId != null) { entityURL = (URL) entityValidator.get(publicId); } // Redirect the schema location to a local destination if (schemaLocation != null && entityURL == null && systemId != null){ entityURL = (URL) entityValidator.get(systemId); } if (entityURL == null) { if (systemId == null) { // cannot resolve if (log.isDebugEnabled()) { log.debug(" Cannot resolve null entity, returning null InputSource"); } return (null); } else { // try to resolve using system ID if (log.isDebugEnabled()) { log.debug(" Trying to resolve using system ID '" + systemId + "'"); } try { entityURL = new URL(systemId); } catch (MalformedURLException e) { throw new IllegalArgumentException("Malformed URL '" + systemId + "' : " + e.getMessage()); } } } // Return an input source to our alternative URL if (log.isDebugEnabled()) { log.debug(" Resolving to alternate DTD '" + entityURL + "'"); } try { return createInputSourceFromURL(entityURL); } catch (Exception e) { throw createSAXException(e); } } // ------------------------------------------------- ErrorHandler Methods /** * Forward notification of a parsing error to the application supplied * error handler (if any). * * @param exception The error information * * @exception SAXException if a parsing exception occurs */ public void error(SAXParseException exception) throws SAXException { log.error("Parse Error at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": " + exception.getMessage(), exception); if (errorHandler != null) { errorHandler.error(exception); } } /** * Forward notification of a fatal parsing error to the application * supplied error handler (if any). * * @param exception The fatal error information * * @exception SAXException if a parsing exception occurs */ public void fatalError(SAXParseException exception) throws SAXException { log.error("Parse Fatal Error at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": " + exception.getMessage(), exception); if (errorHandler != null) { errorHandler.fatalError(exception); } } /** * Forward notification of a parse warning to the application supplied * error handler (if any). * * @param exception The warning information * * @exception SAXException if a parsing exception occurs */ public void warning(SAXParseException exception) throws SAXException { if (errorHandler != null) { log.warn("Parse Warning Error at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": " + exception.getMessage(), exception); errorHandler.warning(exception); } } // ------------------------------------------------------- Public Methods /** * Log a message to our associated logger. * * @param message The message to be logged * @deprecated Call getLogger() and use it's logging methods */ public void log(String message) { log.info(message); } /** * Log a message and exception to our associated logger. * * @param message The message to be logged * @deprecated Call getLogger() and use it's logging methods */ public void log(String message, Throwable exception) { log.error(message, exception); } /** * Parse the content of the specified file using this Digester. Returns * the root element from the object stack (if any). * * @param file File containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Object parse(File file) throws IOException, SAXException { if (file == null) { throw new IllegalArgumentException("File to parse is null"); } configure(); InputSource input = new InputSource(new FileInputStream(file)); input.setSystemId(file.toURL().toString()); getXMLReader().parse(input); cleanup(); return (root); } /** * Parse the content of the specified input source using this Digester. * Returns the root element from the object stack (if any). * * @param input Input source containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Object parse(InputSource input) throws IOException, SAXException { if (input == null) { throw new IllegalArgumentException("InputSource to parse is null"); } configure(); getXMLReader().parse(input); cleanup(); return (root); } /** * Parse the content of the specified input stream using this Digester. * Returns the root element from the object stack (if any). * * @param input Input stream containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Object parse(InputStream input) throws IOException, SAXException { if (input == null) { throw new IllegalArgumentException("InputStream to parse is null"); } configure(); InputSource is = new InputSource(input); getXMLReader().parse(is); cleanup(); return (root); } /** * Parse the content of the specified reader using this Digester. * Returns the root element from the object stack (if any). * * @param reader Reader containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Object parse(Reader reader) throws IOException, SAXException { if (reader == null) { throw new IllegalArgumentException("Reader to parse is null"); } configure(); InputSource is = new InputSource(reader); getXMLReader().parse(is); cleanup(); return (root); } /** * Parse the content of the specified URI using this Digester. * Returns the root element from the object stack (if any). * * @param uri URI containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs */ public Object parse(String uri) throws IOException, SAXException { if (uri == null) { throw new IllegalArgumentException("String URI to parse is null"); } configure(); InputSource is = createInputSourceFromURL(uri); getXMLReader().parse(is); cleanup(); return (root); } /** * Parse the content of the specified URL using this Digester. * Returns the root element from the object stack (if any). * * @param url URL containing the XML data to be parsed * * @exception IOException if an input/output error occurs * @exception SAXException if a parsing exception occurs * * @since 1.8 */ public Object parse(URL url) throws IOException, SAXException { if (url == null) { throw new IllegalArgumentException("URL to parse is null"); } configure(); InputSource is = createInputSourceFromURL(url); getXMLReader().parse(is); cleanup(); return (root); } /** *

Register the specified DTD URL for the specified public identifier. * This must be called before the first call to parse(). *

* Digester contains an internal EntityResolver * implementation. This maps PUBLICID's to URLs * (from which the resource will be loaded). A common use case for this * method is to register local URLs (possibly computed at runtime by a * classloader) for DTDs. This allows the performance advantage of using * a local version without having to ensure every SYSTEM * URI on every processed xml document is local. This implementation provides * only basic functionality. If more sophisticated features are required, * using {@link #setEntityResolver} to set a custom resolver is recommended. *

* Note: This method will have no effect when a custom * EntityResolver has been set. (Setting a custom * EntityResolver overrides the internal implementation.) *

* @param publicId Public identifier of the DTD to be resolved * @param entityURL The URL to use for reading this DTD * * @since 1.8 */ public void register(String publicId, URL entityURL) { if (log.isDebugEnabled()) { log.debug("register('" + publicId + "', '" + entityURL + "'"); } entityValidator.put(publicId, entityURL); } /** *

Convenience method that registers the string version of an entity URL * instead of a URL version.

* * @param publicId Public identifier of the entity to be resolved * @param entityURL The URL to use for reading this entity */ public void register(String publicId, String entityURL) { if (log.isDebugEnabled()) { log.debug("register('" + publicId + "', '" + entityURL + "'"); } try { entityValidator.put(publicId, new URL(entityURL)); } catch (MalformedURLException e) { throw new IllegalArgumentException("Malformed URL '" + entityURL + "' : " + e.getMessage()); } } /** *

List of InputSource instances * created by a createInputSourceFromURL() method * call. These represent open input streams that need to be * closed to avoid resource leaks, as well as potentially locked * JAR files on Windows.

*/ protected List inputSources = new ArrayList(5); /** * Given a URL, return an InputSource that reads from that URL. *

* Ideally this function would not be needed and code could just use * new InputSource(entityURL). Unfortunately it appears * that when the entityURL points to a file within a jar archive a * caching mechanism inside the InputSource implementation causes a * file-handle to the jar file to remain open. On Windows systems * this then causes the jar archive file to be locked on disk * ("in use") which makes it impossible to delete the jar file - * and that really stuffs up "undeploy" in webapps in particular. *

* In JDK1.4 and later, Apache XercesJ is used as the xml parser. * The InputSource object provided is converted into an XMLInputSource, * and eventually passed to an instance of XMLDocumentScannerImpl to * specify the source data to be converted into tokens for the rest * of the XMLReader code to handle. XMLDocumentScannerImpl calls * fEntityManager.startDocumentEntity(source), where fEntityManager * is declared in ancestor class XMLScanner to be an XMLEntityManager. In * that class, if the input source stream is null, then: *

     *  URL location = new URL(expandedSystemId);
     *  URLConnection connect = location.openConnection();
     *  if (connect instanceof HttpURLConnection) {
     *    setHttpProperties(connect,xmlInputSource);
     *  }
     *  stream = connect.getInputStream();
     * 
* This method pretty much duplicates the standard behaviour, except * that it calls URLConnection.setUseCaches(false) before opening * the connection. * * @since 1.8 */ public InputSource createInputSourceFromURL(URL url) throws MalformedURLException, IOException { URLConnection connection = url.openConnection(); connection.setUseCaches(false); InputStream stream = connection.getInputStream(); InputSource source = new InputSource(stream); source.setSystemId(url.toExternalForm()); inputSources.add(source); return source; } /** *

Convenience method that creates an InputSource * from the string version of a URL.

* * @param url URL for which to create an InputSource * * @since 1.8 */ public InputSource createInputSourceFromURL(String url) throws MalformedURLException, IOException { return createInputSourceFromURL(new URL(url)); } // --------------------------------------------------------- Rule Methods /** *

Register a new Rule matching the specified pattern. * This method sets the Digester property on the rule.

* * @param pattern Element matching pattern * @param rule Rule to be registered */ public void addRule(String pattern, Rule rule) { rule.setDigester(this); getRules().add(pattern, rule); } /** * Register a set of Rule instances defined in a RuleSet. * * @param ruleSet The RuleSet instance to configure from */ public void addRuleSet(RuleSet ruleSet) { String oldNamespaceURI = getRuleNamespaceURI(); String newNamespaceURI = ruleSet.getNamespaceURI(); if (log.isDebugEnabled()) { if (newNamespaceURI == null) { log.debug("addRuleSet() with no namespace URI"); } else { log.debug("addRuleSet() with namespace URI " + newNamespaceURI); } } setRuleNamespaceURI(newNamespaceURI); ruleSet.addRuleInstances(this); setRuleNamespaceURI(oldNamespaceURI); } /** * Add a "bean property setter" rule for the specified parameters. * * @param pattern Element matching pattern * @see BeanPropertySetterRule */ public void addBeanPropertySetter(String pattern) { addRule(pattern, new BeanPropertySetterRule()); } /** * Add a "bean property setter" rule for the specified parameters. * * @param pattern Element matching pattern * @param propertyName Name of property to set * @see BeanPropertySetterRule */ public void addBeanPropertySetter(String pattern, String propertyName) { addRule(pattern, new BeanPropertySetterRule(propertyName)); } /** * Add an "call method" rule for a method which accepts no arguments. * * @param pattern Element matching pattern * @param methodName Method name to be called * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName) { addRule( pattern, new CallMethodRule(methodName)); } /** * Add an "call method" rule for the specified parameters. * * @param pattern Element matching pattern * @param methodName Method name to be called * @param paramCount Number of expected parameters (or zero * for a single parameter from the body of this element) * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName, int paramCount) { addRule(pattern, new CallMethodRule(methodName, paramCount)); } /** * Add an "call method" rule for the specified parameters. * If paramCount is set to zero the rule will use * the body of the matched element as the single argument of the * method, unless paramTypes is null or empty, in this * case the rule will call the specified method with no arguments. * * @param pattern Element matching pattern * @param methodName Method name to be called * @param paramCount Number of expected parameters (or zero * for a single parameter from the body of this element) * @param paramTypes Set of Java class names for the types * of the expected parameters * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName, int paramCount, String paramTypes[]) { addRule(pattern, new CallMethodRule( methodName, paramCount, paramTypes)); } /** * Add an "call method" rule for the specified parameters. * If paramCount is set to zero the rule will use * the body of the matched element as the single argument of the * method, unless paramTypes is null or empty, in this * case the rule will call the specified method with no arguments. * * @param pattern Element matching pattern * @param methodName Method name to be called * @param paramCount Number of expected parameters (or zero * for a single parameter from the body of this element) * @param paramTypes The Java class names of the arguments * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName, int paramCount, Class paramTypes[]) { addRule(pattern, new CallMethodRule( methodName, paramCount, paramTypes)); } /** * Add a "call parameter" rule for the specified parameters. * * @param pattern Element matching pattern * @param paramIndex Zero-relative parameter index to set * (from the body of this element) * @see CallParamRule */ public void addCallParam(String pattern, int paramIndex) { addRule(pattern, new CallParamRule(paramIndex)); } /** * Add a "call parameter" rule for the specified parameters. * * @param pattern Element matching pattern * @param paramIndex Zero-relative parameter index to set * (from the specified attribute) * @param attributeName Attribute whose value is used as the * parameter value * @see CallParamRule */ public void addCallParam(String pattern, int paramIndex, String attributeName) { addRule(pattern, new CallParamRule(paramIndex, attributeName)); } /** * Add a "call parameter" rule. * This will either take a parameter from the stack * or from the current element body text. * * @param paramIndex The zero-relative parameter number * @param fromStack Should the call parameter be taken from the top of the stack? * @see CallParamRule */ public void addCallParam(String pattern, int paramIndex, boolean fromStack) { addRule(pattern, new CallParamRule(paramIndex, fromStack)); } /** * Add a "call parameter" rule that sets a parameter from the stack. * This takes a parameter from the given position on the stack. * * @param paramIndex The zero-relative parameter number * @param stackIndex set the call parameter to the stackIndex'th object down the stack, * where 0 is the top of the stack, 1 the next element down and so on * @see CallMethodRule */ public void addCallParam(String pattern, int paramIndex, int stackIndex) { addRule(pattern, new CallParamRule(paramIndex, stackIndex)); } /** * Add a "call parameter" rule that sets a parameter from the current * Digester matching path. * This is sometimes useful when using rules that support wildcards. * * @param pattern the pattern that this rule should match * @param paramIndex The zero-relative parameter number * @see CallMethodRule */ public void addCallParamPath(String pattern,int paramIndex) { addRule(pattern, new PathCallParamRule(paramIndex)); } /** * Add a "call parameter" rule that sets a parameter from a * caller-provided object. This can be used to pass constants such as * strings to methods; it can also be used to pass mutable objects, * providing ways for objects to do things like "register" themselves * with some shared object. *

* Note that when attempting to locate a matching method to invoke, * the true type of the paramObj is used, so that despite the paramObj * being passed in here as type Object, the target method can declare * its parameters as being the true type of the object (or some ancestor * type, according to the usual type-conversion rules). * * @param paramIndex The zero-relative parameter number * @param paramObj Any arbitrary object to be passed to the target * method. * @see CallMethodRule * * @since 1.6 */ public void addObjectParam(String pattern, int paramIndex, Object paramObj) { addRule(pattern, new ObjectParamRule(paramIndex, paramObj)); } /** * Add a "factory create" rule for the specified parameters. * Exceptions thrown during the object creation process will be propagated. * * @param pattern Element matching pattern * @param className Java class name of the object creation factory class * @see FactoryCreateRule */ public void addFactoryCreate(String pattern, String className) { addFactoryCreate(pattern, className, false); } /** * Add a "factory create" rule for the specified parameters. * Exceptions thrown during the object creation process will be propagated. * * @param pattern Element matching pattern * @param clazz Java class of the object creation factory class * @see FactoryCreateRule */ public void addFactoryCreate(String pattern, Class clazz) { addFactoryCreate(pattern, clazz, false); } /** * Add a "factory create" rule for the specified parameters. * Exceptions thrown during the object creation process will be propagated. * * @param pattern Element matching pattern * @param className Java class name of the object creation factory class * @param attributeName Attribute name which, if present, overrides the * value specified by className * @see FactoryCreateRule */ public void addFactoryCreate(String pattern, String className, String attributeName) { addFactoryCreate(pattern, className, attributeName, false); } /** * Add a "factory create" rule for the specified parameters. * Exceptions thrown during the object creation process will be propagated. * * @param pattern Element matching pattern * @param clazz Java class of the object creation factory class * @param attributeName Attribute name which, if present, overrides the * value specified by className * @see FactoryCreateRule */ public void addFactoryCreate(String pattern, Class clazz, String attributeName) { addFactoryCreate(pattern, clazz, attributeName, false); } /** * Add a "factory create" rule for the specified parameters. * Exceptions thrown during the object creation process will be propagated. * * @param pattern Element matching pattern * @param creationFactory Previously instantiated ObjectCreationFactory * to be utilized * @see FactoryCreateRule */ public void addFactoryCreate(String pattern, ObjectCreationFactory creationFactory) { addFactoryCreate(pattern, creationFactory, false); } /** * Add a "factory create" rule for the specified parameters. * * @param pattern Element matching pattern * @param className Java class name of the object creation factory class * @param ignoreCreateExceptions when true any exceptions thrown during * object creation will be ignored. * @see FactoryCreateRule */ public void addFactoryCreate( String pattern, String className, boolean ignoreCreateExceptions) { addRule( pattern, new FactoryCreateRule(className, ignoreCreateExceptions)); } /** * Add a "factory create" rule for the specified parameters. * * @param pattern Element matching pattern * @param clazz Java class of the object creation factory class * @param ignoreCreateExceptions when true any exceptions thrown during * object creation will be ignored. * @see FactoryCreateRule */ public void addFactoryCreate( String pattern, Class clazz, boolean ignoreCreateExceptions) { addRule( pattern, new FactoryCreateRule(clazz, ignoreCreateExceptions)); } /** * Add a "factory create" rule for the specified parameters. * * @param pattern Element matching pattern * @param className Java class name of the object creation factory class * @param attributeName Attribute name which, if present, overrides the * value specified by className * @param ignoreCreateExceptions when true any exceptions thrown during * object creation will be ignored. * @see FactoryCreateRule */ public void addFactoryCreate( String pattern, String className, String attributeName, boolean ignoreCreateExceptions) { addRule( pattern, new FactoryCreateRule(className, attributeName, ignoreCreateExceptions)); } /** * Add a "factory create" rule for the specified parameters. * * @param pattern Element matching pattern * @param clazz Java class of the object creation factory class * @param attributeName Attribute name which, if present, overrides the * value specified by className * @param ignoreCreateExceptions when true any exceptions thrown during * object creation will be ignored. * @see FactoryCreateRule */ public void addFactoryCreate( String pattern, Class clazz, String attributeName, boolean ignoreCreateExceptions) { addRule( pattern, new FactoryCreateRule(clazz, attributeName, ignoreCreateExceptions)); } /** * Add a "factory create" rule for the specified parameters. * * @param pattern Element matching pattern * @param creationFactory Previously instantiated ObjectCreationFactory * to be utilized * @param ignoreCreateExceptions when true any exceptions thrown during * object creation will be ignored. * @see FactoryCreateRule */ public void addFactoryCreate(String pattern, ObjectCreationFactory creationFactory, boolean ignoreCreateExceptions) { creationFactory.setDigester(this); addRule(pattern, new FactoryCreateRule(creationFactory, ignoreCreateExceptions)); } /** * Add an "object create" rule for the specified parameters. * * @param pattern Element matching pattern * @param className Java class name to be created * @see ObjectCreateRule */ public void addObjectCreate(String pattern, String className) { addRule(pattern, new ObjectCreateRule(className)); } /** * Add an "object create" rule for the specified parameters. * * @param pattern Element matching pattern * @param clazz Java class to be created * @see ObjectCreateRule */ public void addObjectCreate(String pattern, Class clazz) { addRule(pattern, new ObjectCreateRule(clazz)); } /** * Add an "object create" rule for the specified parameters. * * @param pattern Element matching pattern * @param className Default Java class name to be created * @param attributeName Attribute name that optionally overrides * the default Java class name to be created * @see ObjectCreateRule */ public void addObjectCreate(String pattern, String className, String attributeName) { addRule(pattern, new ObjectCreateRule(className, attributeName)); } /** * Add an "object create" rule for the specified parameters. * * @param pattern Element matching pattern * @param attributeName Attribute name that optionally overrides * @param clazz Default Java class to be created * the default Java class name to be created * @see ObjectCreateRule */ public void addObjectCreate(String pattern, String attributeName, Class clazz) { addRule(pattern, new ObjectCreateRule(attributeName, clazz)); } /** * Adds an {@link SetNestedPropertiesRule}. * * @param pattern register the rule with this pattern * * @since 1.6 */ public void addSetNestedProperties(String pattern) { addRule(pattern, new SetNestedPropertiesRule()); } /** * Adds an {@link SetNestedPropertiesRule}. * * @param pattern register the rule with this pattern * @param elementName elment name that a property maps to * @param propertyName property name of the element mapped from * * @since 1.6 */ public void addSetNestedProperties(String pattern, String elementName, String propertyName) { addRule(pattern, new SetNestedPropertiesRule(elementName, propertyName)); } /** * Adds an {@link SetNestedPropertiesRule}. * * @param pattern register the rule with this pattern * @param elementNames elment names that (in order) map to properties * @param propertyNames property names that (in order) elements are mapped to * * @since 1.6 */ public void addSetNestedProperties(String pattern, String[] elementNames, String[] propertyNames) { addRule(pattern, new SetNestedPropertiesRule(elementNames, propertyNames)); } /** * Add a "set next" rule for the specified parameters. * * @param pattern Element matching pattern * @param methodName Method name to call on the parent element * @see SetNextRule */ public void addSetNext(String pattern, String methodName) { addRule(pattern, new SetNextRule(methodName)); } /** * Add a "set next" rule for the specified parameters. * * @param pattern Element matching pattern * @param methodName Method name to call on the parent element * @param paramType Java class name of the expected parameter type * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) * @see SetNextRule */ public void addSetNext(String pattern, String methodName, String paramType) { addRule(pattern, new SetNextRule(methodName, paramType)); } /** * Add {@link SetRootRule} with the specified parameters. * * @param pattern Element matching pattern * @param methodName Method name to call on the root object * @see SetRootRule */ public void addSetRoot(String pattern, String methodName) { addRule(pattern, new SetRootRule(methodName)); } /** * Add {@link SetRootRule} with the specified parameters. * * @param pattern Element matching pattern * @param methodName Method name to call on the root object * @param paramType Java class name of the expected parameter type * @see SetRootRule */ public void addSetRoot(String pattern, String methodName, String paramType) { addRule(pattern, new SetRootRule(methodName, paramType)); } /** * Add a "set properties" rule for the specified parameters. * * @param pattern Element matching pattern * @see SetPropertiesRule */ public void addSetProperties(String pattern) { addRule(pattern, new SetPropertiesRule()); } /** * Add a "set properties" rule with a single overridden parameter. * See {@link SetPropertiesRule#SetPropertiesRule(String attributeName, String propertyName)} * * @param pattern Element matching pattern * @param attributeName map this attribute * @param propertyName to this property * @see SetPropertiesRule */ public void addSetProperties( String pattern, String attributeName, String propertyName) { addRule(pattern, new SetPropertiesRule(attributeName, propertyName)); } /** * Add a "set properties" rule with overridden parameters. * See {@link SetPropertiesRule#SetPropertiesRule(String [] attributeNames, String [] propertyNames)} * * @param pattern Element matching pattern * @param attributeNames names of attributes with custom mappings * @param propertyNames property names these attributes map to * @see SetPropertiesRule */ public void addSetProperties( String pattern, String [] attributeNames, String [] propertyNames) { addRule(pattern, new SetPropertiesRule(attributeNames, propertyNames)); } /** * Add a "set property" rule for the specified parameters. * * @param pattern Element matching pattern * @param name Attribute name containing the property name to be set * @param value Attribute name containing the property value to set * @see SetPropertyRule */ public void addSetProperty(String pattern, String name, String value) { addRule(pattern, new SetPropertyRule(name, value)); } /** * Add a "set top" rule for the specified parameters. * * @param pattern Element matching pattern * @param methodName Method name to call on the parent element * @see SetTopRule */ public void addSetTop(String pattern, String methodName) { addRule(pattern, new SetTopRule(methodName)); } /** * Add a "set top" rule for the specified parameters. * * @param pattern Element matching pattern * @param methodName Method name to call on the parent element * @param paramType Java class name of the expected parameter type * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as java.lang.Boolean * for a boolean parameter) * @see SetTopRule */ public void addSetTop(String pattern, String methodName, String paramType) { addRule(pattern, new SetTopRule(methodName, paramType)); } // --------------------------------------------------- Object Stack Methods /** * Clear the current contents of the default object stack, the param stack, * all named stacks, and other internal variables. *

* Calling this method might allow another document of the same type * to be correctly parsed. However this method was not intended for this * purpose (just to tidy up memory usage). In general, a separate Digester * object should be created for each document to be parsed. *

* Note that this method is called automatically after a document has been * successfully parsed by a Digester instance. However it is not invoked * automatically when a parse fails, so when reusing a Digester instance * (which is not recommended) this method must be called manually * after a parse failure. */ public void clear() { match = ""; bodyTexts.clear(); params.clear(); publicId = null; stack.clear(); stacksByName.clear(); customContentHandler = null; } /** * Return the top object on the stack without removing it. If there are * no objects on the stack, return null. */ public Object peek() { try { return (stack.peek()); } catch (EmptyStackException e) { log.warn("Empty stack (returning null)"); return (null); } } /** * Return the n'th object down the stack, where 0 is the top element * and [getCount()-1] is the bottom element. If the specified index * is out of range, return null. * * @param n Index of the desired element, where 0 is the top of the stack, * 1 is the next element down, and so on. */ public Object peek(int n) { try { return (stack.peek(n)); } catch (EmptyStackException e) { log.warn("Empty stack (returning null)"); return (null); } } /** * Pop the top object off of the stack, and return it. If there are * no objects on the stack, return null. */ public Object pop() { try { Object popped = stack.pop(); if (stackAction != null) { popped = stackAction.onPop(this, null, popped); } return popped; } catch (EmptyStackException e) { log.warn("Empty stack (returning null)"); return (null); } } /** * Push a new object onto the top of the object stack. * * @param object The new object */ public void push(Object object) { if (stackAction != null) { object = stackAction.onPush(this, null, object); } if (stack.size() == 0) { root = object; } stack.push(object); } /** * Pushes the given object onto the stack with the given name. * If no stack already exists with the given name then one will be created. * * @param stackName the name of the stack onto which the object should be pushed * @param value the Object to be pushed onto the named stack. * * @since 1.6 */ public void push(String stackName, Object value) { if (stackAction != null) { value = stackAction.onPush(this, stackName, value); } ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName); if (namedStack == null) { namedStack = new ArrayStack(); stacksByName.put(stackName, namedStack); } namedStack.push(value); } /** *

Pops (gets and removes) the top object from the stack with the given name.

* *

Note: a stack is considered empty * if no objects have been pushed onto it yet.

* * @param stackName the name of the stack from which the top value is to be popped. * @return the top Object on the stack or or null if the stack is either * empty or has not been created yet * @throws EmptyStackException if the named stack is empty * * @since 1.6 */ public Object pop(String stackName) { Object result = null; ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName); if (namedStack == null) { if (log.isDebugEnabled()) { log.debug("Stack '" + stackName + "' is empty"); } throw new EmptyStackException(); } result = namedStack.pop(); if (stackAction != null) { result = stackAction.onPop(this, stackName, result); } return result; } /** *

Gets the top object from the stack with the given name. * This method does not remove the object from the stack. *

*

Note: a stack is considered empty * if no objects have been pushed onto it yet.

* * @param stackName the name of the stack to be peeked * @return the top Object on the stack or null if the stack is either * empty or has not been created yet * @throws EmptyStackException if the named stack is empty * * @since 1.6 */ public Object peek(String stackName) { return peek(stackName, 0); } /** *

Gets the top object from the stack with the given name. * This method does not remove the object from the stack. *

*

Note: a stack is considered empty * if no objects have been pushed onto it yet.

* * @param stackName the name of the stack to be peeked * @param n Index of the desired element, where 0 is the top of the stack, * 1 is the next element down, and so on. * @return the specified Object on the stack. * @throws EmptyStackException if the named stack is empty * * @since 1.6 */ public Object peek(String stackName, int n) { Object result = null; ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName); if (namedStack == null ) { if (log.isDebugEnabled()) { log.debug("Stack '" + stackName + "' is empty"); } throw new EmptyStackException(); } else { result = namedStack.peek(n); } return result; } /** *

Is the stack with the given name empty?

*

Note: a stack is considered empty * if no objects have been pushed onto it yet.

* @param stackName the name of the stack whose emptiness * should be evaluated * @return true if the given stack if empty * * @since 1.6 */ public boolean isEmpty(String stackName) { boolean result = true; ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName); if (namedStack != null ) { result = namedStack.isEmpty(); } return result; } /** * Returns the root element of the tree of objects created as a result * of applying the rule objects to the input XML. *

* If the digester stack was "primed" by explicitly pushing a root * object onto the stack before parsing started, then that root object * is returned here. *

* Alternatively, if a Rule which creates an object (eg ObjectCreateRule) * matched the root element of the xml, then the object created will be * returned here. *

* In other cases, the object most recently pushed onto an empty digester * stack is returned. This would be a most unusual use of digester, however; * one of the previous configurations is much more likely. *

* Note that when using one of the Digester.parse methods, the return * value from the parse method is exactly the same as the return value * from this method. However when the Digester is being used as a * SAXContentHandler, no such return value is available; in this case, this * method allows you to access the root object that has been created * after parsing has completed. * * @return the root object that has been created after parsing * or null if the digester has not parsed any XML yet. */ public Object getRoot() { return root; } /** * This method allows the "root" variable to be reset to null. *

* It is not considered safe for a digester instance to be reused * to parse multiple xml documents. However if you are determined to * do so, then you should call both clear() and resetRoot() before * each parse. * * @since 1.7 */ public void resetRoot() { root = null; } // ------------------------------------------------ Parameter Stack Methods // ------------------------------------------------------ Protected Methods /** *

Clean up allocated resources after parsing is complete. The * default method closes input streams that have been created by * Digester itself. If you override this method in a subclass, be * sure to call super.cleanup() to invoke this logic.

* * @since 1.8 */ protected void cleanup() { // If we created any InputSource objects in this instance, // they each have an input stream that should be closed Iterator sources = inputSources.iterator(); while (sources.hasNext()) { InputSource source = (InputSource) sources.next(); try { source.getByteStream().close(); } catch (IOException e) { ; // Fall through so we get them all } } inputSources.clear(); } /** *

* Provide a hook for lazy configuration of this Digester * instance. The default implementation does nothing, but subclasses * can override as needed. *

* *

* Note This method may be called more than once. * Once only initialization code should be placed in {@link #initialize} * or the code should take responsibility by checking and setting the * {@link #configured} flag. *

*/ protected void configure() { // Do not configure more than once if (configured) { return; } // Perform lazy configuration as needed initialize(); // call hook method for subclasses that want to be initialized once only // Nothing else required by default // Set the configuration flag to avoid repeating configured = true; } /** *

* Provides a hook for lazy initialization of this Digester * instance. * The default implementation does nothing, but subclasses * can override as needed. * Digester (by default) only calls this method once. *

* *

* Note This method will be called by {@link #configure} * only when the {@link #configured} flag is false. * Subclasses that override configure or who set configured * may find that this method may be called more than once. *

* * @since 1.6 */ protected void initialize() { // Perform lazy initialization as needed ; // Nothing required by default } // -------------------------------------------------------- Package Methods /** * Return the set of DTD URL registrations, keyed by public identifier. */ Map getRegistrations() { return (entityValidator); } /** * Return the set of rules that apply to the specified match position. * The selected rules are those that match exactly, or those rules * that specify a suffix match and the tail of the rule matches the * current match position. Exact matches have precedence over * suffix matches, then (among suffix matches) the longest match * is preferred. * * @param match The current match position * * @deprecated Call match() on the Rules * implementation returned by getRules() */ List getRules(String match) { return (getRules().match(match)); } /** *

Return the top object on the parameters stack without removing it. If there are * no objects on the stack, return null.

* *

The parameters stack is used to store CallMethodRule parameters. * See {@link #params}.

*/ public Object peekParams() { try { return (params.peek()); } catch (EmptyStackException e) { log.warn("Empty stack (returning null)"); return (null); } } /** *

Return the n'th object down the parameters stack, where 0 is the top element * and [getCount()-1] is the bottom element. If the specified index * is out of range, return null.

* *

The parameters stack is used to store CallMethodRule parameters. * See {@link #params}.

* * @param n Index of the desired element, where 0 is the top of the stack, * 1 is the next element down, and so on. */ public Object peekParams(int n) { try { return (params.peek(n)); } catch (EmptyStackException e) { log.warn("Empty stack (returning null)"); return (null); } } /** *

Pop the top object off of the parameters stack, and return it. If there are * no objects on the stack, return null.

* *

The parameters stack is used to store CallMethodRule parameters. * See {@link #params}.

*/ public Object popParams() { try { if (log.isTraceEnabled()) { log.trace("Popping params"); } return (params.pop()); } catch (EmptyStackException e) { log.warn("Empty stack (returning null)"); return (null); } } /** *

Push a new object onto the top of the parameters stack.

* *

The parameters stack is used to store CallMethodRule parameters. * See {@link #params}.

* * @param object The new object */ public void pushParams(Object object) { if (log.isTraceEnabled()) { log.trace("Pushing params"); } params.push(object); } /** * Create a SAX exception which also understands about the location in * the digester file where the exception occurs * * @return the new exception */ public SAXException createSAXException(String message, Exception e) { if ((e != null) && (e instanceof InvocationTargetException)) { Throwable t = ((InvocationTargetException) e).getTargetException(); if ((t != null) && (t instanceof Exception)) { e = (Exception) t; } } if (locator != null) { String error = "Error at line " + locator.getLineNumber() + " char " + locator.getColumnNumber() + ": " + message; if (e != null) { return new SAXParseException(error, locator, e); } else { return new SAXParseException(error, locator); } } log.error("No Locator!"); if (e != null) { return new SAXException(message, e); } else { return new SAXException(message); } } /** * Create a SAX exception which also understands about the location in * the digester file where the exception occurs * * @return the new exception */ public SAXException createSAXException(Exception e) { if (e instanceof InvocationTargetException) { Throwable t = ((InvocationTargetException) e).getTargetException(); if ((t != null) && (t instanceof Exception)) { e = (Exception) t; } } return createSAXException(e.getMessage(), e); } /** * Create a SAX exception which also understands about the location in * the digester file where the exception occurs * * @return the new exception */ public SAXException createSAXException(String message) { return createSAXException(message, null); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/0000755000175000017500000000000011226450007027762 5ustar twernertwerner././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginInvalidInputException.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginInvalidInputE0000644000175000017500000000373111226450007033603 0ustar twernertwerner/* $Id: PluginInvalidInputException.java 476205 2006-11-17 16:43:10Z dennisl $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; /** * Thrown when an error occurs due to bad data in the file being parsed. * * @since 1.6 */ public class PluginInvalidInputException extends PluginException { private Throwable cause = null; /** * @param cause underlying exception that caused this to be thrown */ public PluginInvalidInputException(Throwable cause) { this(cause.getMessage()); this.cause = cause; } /** * @param msg describes the reason this exception is being thrown. */ public PluginInvalidInputException(String msg) { super(msg); } /** * @param msg describes the reason this exception is being thrown. * @param cause underlying exception that caused this to be thrown */ public PluginInvalidInputException(String msg, Throwable cause) { this(msg); this.cause = cause; } /** * Return the cause of this exception (if any) as specified in the * exception constructor. * * @since 1.8 */ public Throwable getCause() { return cause; } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginConfigurationException.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginConfiguration0000644000175000017500000000434711226450007033703 0ustar twernertwerner/* $Id: PluginConfigurationException.java 476205 2006-11-17 16:43:10Z dennisl $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; /** * Thrown when an error occurs due to the way the calling application uses * the plugins module. Because the pre-existing Digester API doesn't provide * any option for throwing checked exceptions at some points where Plugins * can potentially fail, this exception extends RuntimeException so that it * can "tunnel" through these points. * * @since 1.6 */ public class PluginConfigurationException extends RuntimeException { private Throwable cause = null; /** * @param cause underlying exception that caused this to be thrown */ public PluginConfigurationException(Throwable cause) { this(cause.getMessage()); this.cause = cause; } /** * @param msg describes the reason this exception is being thrown. */ public PluginConfigurationException(String msg) { super(msg); } /** * @param msg describes the reason this exception is being thrown. * @param cause underlying exception that caused this to be thrown */ public PluginConfigurationException(String msg, Throwable cause) { this(msg); this.cause = cause; } /** * Return the cause of this exception (if any) as specified in the * exception constructor. * * @since 1.8 */ public Throwable getCause() { return cause; } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/LogUtils.java0000644000175000017500000000576011226450007032377 0ustar twernertwerner/* $Id: LogUtils.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import org.apache.commons.digester.Digester; import org.apache.commons.logging.Log; /** * Simple utility class to assist in logging. *

* This class is intended only for the use of the code in the * plugins packages. No "user" code should use this package. *

* The Digester module has an interesting approach to logging: * all logging should be done via the Log object stored on the * digester instance that the object *doing* the logging is associated * with. *

* This is done because apparently some "container"-type applications * such as Avalon and Tomcat need to be able to configure different logging * for different instances of the Digester class which have been * loaded from the same ClassLoader [info from Craig McClanahan]. * Not only the logging of the Digester instance should be affected; all * objects associated with that Digester instance should obey the * reconfiguration of their owning Digester instance's logging. The current * solution is to force all objects to output logging info via a single * Log object stored on the Digester instance they are associated with. *

* Of course this causes problems if logging is attempted before an * object has a valid reference to its owning Digester. The * getLogging method provided here resolves this issue by returning a * Log object which silently discards all logging output in this * situation. *

* And it also implies that logging filtering can no longer be applied * to subcomponents of the Digester, because all logging is done via * a single Log object (a single Category). C'est la vie... * * @since 1.6 */ class LogUtils { /** * Get the Log object associated with the specified Digester instance, * or a "no-op" logging object if the digester reference is null. *

* You should use this method instead of digester.getLogger() in * any situation where the digester might be null. */ static Log getLogger(Digester digester) { if (digester == null) { return new org.apache.commons.logging.impl.NoOpLog(); } return digester.getLogger(); } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/InitializableRule.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/InitializableRule.j0000644000175000017500000000343311226450007033550 0ustar twernertwerner/* $Id: InitializableRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; /** * Defines an interface that a Rule class can implement if it wishes to get an * initialisation callback after the rule has been added to the set of Rules * within a PluginRules instance. * * @since 1.6 */ public interface InitializableRule { /** * Called after this Rule object has been added to the list of all Rules. * Note that if a single InitializableRule instance is associated with * more than one pattern, then this method will be called more than once. * * @param pattern is the digester match pattern that will trigger this * rule. * @exception * PluginConfigurationException is thrown if the InitializableRule * determines that it cannot correctly initialise itself for any reason. */ public void postRegisterInit(String pattern) throws PluginConfigurationException; } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginCreateRule.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginCreateRule.ja0000644000175000017500000005462111226450007033520 0ustar twernertwerner/* $Id: PluginCreateRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import org.apache.commons.digester.Rule; import org.apache.commons.logging.Log; /** * Allows the original rules for parsing the configuration file to define * points at which plugins are allowed, by configuring a PluginCreateRule * with the appropriate pattern. * * @since 1.6 */ public class PluginCreateRule extends Rule implements InitializableRule { // see setPluginClassAttribute private String pluginClassAttrNs = null; private String pluginClassAttr = null; // see setPluginIdAttribute private String pluginIdAttrNs = null; private String pluginIdAttr = null; /** * In order to invoke the addRules method on the plugin class correctly, * we need to know the pattern which this rule is matched by. */ private String pattern; /** A base class that any plugin must derive from. */ private Class baseClass = null; /** * Info about optional default plugin to be used if no plugin-id is * specified in the input data. This can simplify the syntax where one * particular plugin is usually used. */ private Declaration defaultPlugin; /** * Currently, none of the Rules methods allow exceptions to be thrown. * Therefore if this class cannot initialise itself properly, it cannot * cause the digester to stop. Instead, we cache the exception and throw * it the first time the begin() method is called. */ private PluginConfigurationException initException; //-------------------- constructors ------------------------------------- /** * Create a plugin rule where the user must specify a plugin-class * or plugin-id. * * @param baseClass is the class which any specified plugin must be * descended from. */ public PluginCreateRule(Class baseClass) { this.baseClass = baseClass; } /** * Create a plugin rule where the user may specify a plugin. * If the user doesn't specify a plugin, then the default class specified * in this constructor is used. * * @param baseClass is the class which any specified plugin must be * descended from. * @param dfltPluginClass is the class which will be used if the user * doesn't specify any plugin-class or plugin-id. This class will have * custom rules installed for it just like a declared plugin. */ public PluginCreateRule(Class baseClass, Class dfltPluginClass) { this.baseClass = baseClass; if (dfltPluginClass != null) { defaultPlugin = new Declaration(dfltPluginClass); } } /** * Create a plugin rule where the user may specify a plugin. * If the user doesn't specify a plugin, then the default class specified * in this constructor is used. * * @param baseClass is the class which any specified plugin must be * descended from. * @param dfltPluginClass is the class which will be used if the user * doesn't specify any plugin-class or plugin-id. This class will have * custom rules installed for it just like a declared plugin. * @param dfltPluginRuleLoader is a RuleLoader instance which knows how * to load the custom rules associated with this default plugin. */ public PluginCreateRule(Class baseClass, Class dfltPluginClass, RuleLoader dfltPluginRuleLoader) { this.baseClass = baseClass; if (dfltPluginClass != null) { defaultPlugin = new Declaration(dfltPluginClass, dfltPluginRuleLoader); } } //------------------- properties --------------------------------------- /** * Sets the xml attribute which the input xml uses to indicate to a * PluginCreateRule which class should be instantiated. *

* See {@link PluginRules#setPluginClassAttribute} for more info. */ public void setPluginClassAttribute(String namespaceUri, String attrName) { pluginClassAttrNs = namespaceUri; pluginClassAttr = attrName; } /** * Sets the xml attribute which the input xml uses to indicate to a * PluginCreateRule which plugin declaration is being referenced. *

* See {@link PluginRules#setPluginIdAttribute} for more info. */ public void setPluginIdAttribute(String namespaceUri, String attrName) { pluginIdAttrNs = namespaceUri; pluginIdAttr = attrName; } //------------------- methods -------------------------------------------- /** * Invoked after this rule has been added to the set of digester rules, * associated with the specified pattern. Check all configuration data is * valid and remember the pattern for later. * * @param matchPattern is the digester match pattern that is associated * with this rule instance, eg "root/widget". * @exception PluginConfigurationException */ public void postRegisterInit(String matchPattern) throws PluginConfigurationException { Log log = LogUtils.getLogger(digester); boolean debug = log.isDebugEnabled(); if (debug) { log.debug("PluginCreateRule.postRegisterInit" + ": rule registered for pattern [" + matchPattern + "]"); } if (digester == null) { // We require setDigester to be called before this method. // Note that this means that PluginCreateRule cannot be added // to a Rules object which has not yet been added to a // Digester object. initException = new PluginConfigurationException( "Invalid invocation of postRegisterInit" + ": digester not set."); throw initException; } if (pattern != null) { // We have been called twice, ie a single instance has been // associated with multiple patterns. // // Generally, Digester Rule instances can be associated with // multiple patterns. However for plugins, this creates some // complications. Some day this may be supported; however for // now we just reject this situation. initException = new PluginConfigurationException( "A single PluginCreateRule instance has been mapped to" + " multiple patterns; this is not supported."); throw initException; } if (matchPattern.indexOf('*') != -1) { // having wildcards in patterns is extremely difficult to // deal with. For now, we refuse to allow this. // // TODO: check for any chars not valid in xml element name // rather than just *. // // Reasons include: // (a) handling recursive plugins, and // (b) determining whether one pattern is "below" another, // as done by PluginRules. Without wildcards, "below" // just means startsWith, which is easy to check. initException = new PluginConfigurationException( "A PluginCreateRule instance has been mapped to" + " pattern [" + matchPattern + "]." + " This pattern includes a wildcard character." + " This is not supported by the plugin architecture."); throw initException; } if (baseClass == null) { baseClass = Object.class; } PluginRules rules = (PluginRules) digester.getRules(); PluginManager pm = rules.getPluginManager(); // check default class is valid if (defaultPlugin != null) { if (!baseClass.isAssignableFrom(defaultPlugin.getPluginClass())) { initException = new PluginConfigurationException( "Default class [" + defaultPlugin.getPluginClass().getName() + "] does not inherit from [" + baseClass.getName() + "]."); throw initException; } try { defaultPlugin.init(digester, pm); } catch(PluginException pwe) { throw new PluginConfigurationException( pwe.getMessage(), pwe.getCause()); } } // remember the pattern for later pattern = matchPattern; if (pluginClassAttr == null) { // the user hasn't set explicit xml attr names on this rule, // so fetch the default values pluginClassAttrNs = rules.getPluginClassAttrNs(); pluginClassAttr = rules.getPluginClassAttr(); if (debug) { log.debug( "init: pluginClassAttr set to per-digester values [" + "ns=" + pluginClassAttrNs + ", name=" + pluginClassAttr + "]"); } } else { if (debug) { log.debug( "init: pluginClassAttr set to rule-specific values [" + "ns=" + pluginClassAttrNs + ", name=" + pluginClassAttr + "]"); } } if (pluginIdAttr == null) { // the user hasn't set explicit xml attr names on this rule, // so fetch the default values pluginIdAttrNs = rules.getPluginIdAttrNs(); pluginIdAttr = rules.getPluginIdAttr(); if (debug) { log.debug( "init: pluginIdAttr set to per-digester values [" + "ns=" + pluginIdAttrNs + ", name=" + pluginIdAttr + "]"); } } else { if (debug) { log.debug( "init: pluginIdAttr set to rule-specific values [" + "ns=" + pluginIdAttrNs + ", name=" + pluginIdAttr + "]"); } } } /** * Invoked when the Digester matches this rule against an xml element. *

* A new instance of the target class is created, and pushed onto the * stack. A new "private" PluginRules object is then created and set as * the digester's default Rules object. Any custom rules associated with * the plugin class are then loaded into that new Rules object. * Finally, any custom rules that are associated with the current pattern * (such as SetPropertiesRules) have their begin methods executed. * * @param namespace * @param name * @param attributes * * @throws ClassNotFoundException * @throws PluginInvalidInputException * @throws PluginConfigurationException */ public void begin(String namespace, String name, org.xml.sax.Attributes attributes) throws java.lang.Exception { Log log = digester.getLogger(); boolean debug = log.isDebugEnabled(); if (debug) { log.debug("PluginCreateRule.begin" + ": pattern=[" + pattern + "]" + " match=[" + digester.getMatch() + "]"); } if (initException != null) { // we had a problem during initialisation that we could // not report then; report it now. throw initException; } // load any custom rules associated with the plugin PluginRules oldRules = (PluginRules) digester.getRules(); PluginManager pluginManager = oldRules.getPluginManager(); Declaration currDeclaration = null; String pluginClassName; if (pluginClassAttrNs == null) { // Yep, this is ugly. // // In a namespace-aware parser, the one-param version will // return attributes with no namespace. // // In a non-namespace-aware parser, the two-param version will // never return any attributes, ever. pluginClassName = attributes.getValue(pluginClassAttr); } else { pluginClassName = attributes.getValue(pluginClassAttrNs, pluginClassAttr); } String pluginId; if (pluginIdAttrNs == null) { pluginId = attributes.getValue(pluginIdAttr); } else { pluginId = attributes.getValue(pluginIdAttrNs, pluginIdAttr); } if (pluginClassName != null) { // The user is using a plugin "inline", ie without a previous // explicit declaration. If they have used the same plugin class // before, we have already gone to the effort of creating a // Declaration object, so retrieve it. If there is no existing // declaration object for this class, then create one. currDeclaration = pluginManager.getDeclarationByClass( pluginClassName); if (currDeclaration == null) { currDeclaration = new Declaration(pluginClassName); try { currDeclaration.init(digester, pluginManager); } catch(PluginException pwe) { throw new PluginInvalidInputException( pwe.getMessage(), pwe.getCause()); } pluginManager.addDeclaration(currDeclaration); } } else if (pluginId != null) { currDeclaration = pluginManager.getDeclarationById(pluginId); if (currDeclaration == null) { throw new PluginInvalidInputException( "Plugin id [" + pluginId + "] is not defined."); } } else if (defaultPlugin != null) { currDeclaration = defaultPlugin; } else { throw new PluginInvalidInputException( "No plugin class specified for element " + pattern); } // get the class of the user plugged-in type Class pluginClass = currDeclaration.getPluginClass(); String path = digester.getMatch(); // create a new Rules object and effectively push it onto a stack of // rules objects. The stack is actually a linked list; using the // PluginRules constructor below causes the new instance to link // to the previous head-of-stack, then the Digester.setRules() makes // the new instance the new head-of-stack. PluginRules newRules = new PluginRules(digester, path, oldRules, pluginClass); digester.setRules(newRules); if (debug) { log.debug("PluginCreateRule.begin: installing new plugin: " + "oldrules=" + oldRules.toString() + ", newrules=" + newRules.toString()); } // load up the custom rules currDeclaration.configure(digester, pattern); // create an instance of the plugin class Object instance = pluginClass.newInstance(); getDigester().push(instance); if (debug) { log.debug( "PluginCreateRule.begin" + ": pattern=[" + pattern + "]" + " match=[" + digester.getMatch() + "]" + " pushed instance of plugin [" + pluginClass.getName() + "]"); } // and now we have to fire any custom rules which would have // been matched by the same path that matched this rule, had // they been loaded at that time. List rules = newRules.getDecoratedRules().match(namespace, path); fireBeginMethods(rules, namespace, name, attributes); } /** * Process the body text of this element. * * @param text The body text of this element */ public void body(String namespace, String name, String text) throws Exception { // While this class itself has no work to do in the body method, // we do need to fire the body methods of all dynamically-added // rules matching the same path as this rule. During begin, we had // to manually execute the dynamic rules' begin methods because they // didn't exist in the digester's Rules object when the match begin. // So in order to ensure consistent ordering of rule execution, the // PluginRules class deliberately avoids returning any such rules // in later calls to the match method, instead relying on this // object to execute them at the appropriate time. // // Note that this applies only to rules matching exactly the path // which is also matched by this PluginCreateRule. String path = digester.getMatch(); PluginRules newRules = (PluginRules) digester.getRules(); List rules = newRules.getDecoratedRules().match(namespace, path); fireBodyMethods(rules, namespace, name, text); } /** * Invoked by the digester when the closing tag matching this Rule's * pattern is encountered. *

* * @param namespace Description of the Parameter * @param name Description of the Parameter * @exception Exception Description of the Exception * * @see #begin */ public void end(String namespace, String name) throws Exception { // see body method for more info String path = digester.getMatch(); PluginRules newRules = (PluginRules) digester.getRules(); List rules = newRules.getDecoratedRules().match(namespace, path); fireEndMethods(rules, namespace, name); // pop the stack of PluginRules instances, which // discards all custom rules associated with this plugin digester.setRules(newRules.getParent()); // and get rid of the instance of the plugin class from the // digester object stack. digester.pop(); } /** * Return the pattern that this Rule is associated with. *

* In general, Rule instances can be associated with multiple * patterns. A PluginCreateRule, however, will only function correctly * when associated with a single pattern. It is possible to fix this, but * I can't be bothered just now because this feature is unlikely to be * used. *

* * @return The pattern value */ public String getPattern() { return pattern; } /** * Duplicate the processing that the Digester does when firing the * begin methods of rules. It would be really nice if the Digester * class provided a way for this functionality to just be invoked * directly. */ public void fireBeginMethods(List rules, String namespace, String name, org.xml.sax.Attributes list) throws java.lang.Exception { if ((rules != null) && (rules.size() > 0)) { Log log = digester.getLogger(); boolean debug = log.isDebugEnabled(); for (int i = 0; i < rules.size(); i++) { try { Rule rule = (Rule) rules.get(i); if (debug) { log.debug(" Fire begin() for " + rule); } rule.begin(namespace, name, list); } catch (Exception e) { throw digester.createSAXException(e); } catch (Error e) { throw e; } } } } /** * Duplicate the processing that the Digester does when firing the * body methods of rules. It would be really nice if the Digester * class provided a way for this functionality to just be invoked * directly. */ private void fireBodyMethods(List rules, String namespaceURI, String name, String text) throws Exception { if ((rules != null) && (rules.size() > 0)) { Log log = digester.getLogger(); boolean debug = log.isDebugEnabled(); for (int i = 0; i < rules.size(); i++) { try { Rule rule = (Rule) rules.get(i); if (debug) { log.debug(" Fire body() for " + rule); } rule.body(namespaceURI, name, text); } catch (Exception e) { throw digester.createSAXException(e); } catch (Error e) { throw e; } } } } /** * Duplicate the processing that the Digester does when firing the * end methods of rules. It would be really nice if the Digester * class provided a way for this functionality to just be invoked * directly. */ public void fireEndMethods(List rules, String namespaceURI, String name) throws Exception { // Fire "end" events for all relevant rules in reverse order if (rules != null) { Log log = digester.getLogger(); boolean debug = log.isDebugEnabled(); for (int i = 0; i < rules.size(); i++) { int j = (rules.size() - i) - 1; try { Rule rule = (Rule) rules.get(j); if (debug) { log.debug(" Fire end() for " + rule); } rule.end(namespaceURI, name); } catch (Exception e) { throw digester.createSAXException(e); } catch (Error e) { throw e; } } } } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/package.html0000644000175000017500000002371211226450007032250 0ustar twernertwerner An overview of the Digester Plugins module.

Provides an easy mechanism whereby new digestion rules can be added dynamically during a digestion.

Introduction.

Many applications have xml configuration files which are "extensible". Some examples of this are:
  • Apache log4j allows user-provided "Appender" classes to be specified in its configuration file
  • Apache Avalon allows "components" of a user-specified class
  • Apache Ant allows custom tasks to be defined
The Digester "plugins" module can be used to add this kind of functionality to your own applications.

An Example

Let's start off with an example.

Given the following digester rules in the main "parsing" application:

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
        
        digester.addObjectCreate("pipeline", Pipeline.class);
        
        digester.addCallMethod("pipeline/source", "setSource", 1);
        digester.addCallParam("pipeline/source", 0, "file");
        
        PluginCreateRule pcr = new PluginCreateRule(Transform.class);
        digester.addRule("pipeline/transform", pcr);
        digester.addSetNext("pipeline/transform", "setTransform");
        
        digester.addCallMethod("pipeline/destination", "setDest", 1);
        digester.addCallParam("pipeline/destination", 0, "file");

        digester.parse(filename);

the following input can be processed:

    <pipeline>
      <source file="input.txt"/>
      <transform plugin-class="SubstituteTransform">
        <from>changeme</from>
        <to>changed</to>
      </transform>
      <destination file="output.txt"/>
    </pipeline>

Note that the "SubstituteTransform" class is not hard-wired into the application, and also that this class is configuring itself from the same configuration file.

The user can specify any class they like here, and (provided that class follows the plugins conventions) it can use any Digester functionality to process the configuration data within the transform tag and its subtags.

The original application simply defined a "plugin point" of "pipeline/transform" at which user classes could be plugged in. However it did not specify what classes were permitted, other than that they must implement the Transform interface. It is the input file which has defined exactly which class should be instantiated when the transform element is encountered, and furthermore the "plugin" class itself has dynamically added rules for parsing elements nested within itself.

A class used as a plugin may dynamically add its own rules to the digester, in order to process its attributes and any subtags in any manner it wishes. This may be done by several mechanisms, including:

  • declaring a method public static void addRules(Digester d, String pattern) on the class being "plugged in", or
  • providing a separate "rule info" class, somewhat in the spirit of "BeanInfo" classes for java beans, or
  • providing an xmlrules file which defines the associated parsing rules.
If a plugin class has a no-parameter constructor, does not expect any subtags, and is satisfied with mapping any attributes on the parent xml tag to bean-property-setter methods on itself, then no rules need to be defined at all; the class can be used as a plugin without any coding.

In the example above, an end user may create their own classes which implement the required Transform interface, then cause these custom classes to be used instead of, or in addition to, classes distributed with the application.

Plugin Declarations

As well as the syntax shown above, where plugin classnames were defined as they were used, plugin classes can be pre-declared (provided the application associates a PluginDeclarationRule with a tag for that purpose). Example:

The plugin class can be declared once:

  <plugin id="widget" class="com.acme.Widget"/>
and later referenced via the short "id" value:
  <sometag plugin-id="widget" ... >

Suggested Applications

Any application where user-specific operations may need to be performed that cannot be known in advance by the initial application developer may benefit from this module. Applications in the style of the Apache projects listed at the top of this page (Log4j, Cocoon, Ant) are examples.

Note also that plugged-in classes can themselves allow user-defined classes to be plugged in within their configuration. This allows a very simple framework to be extended almost without limit by the end user.

Terminology

The term "plugin declaration" refers to an xml element which matches a PluginDeclarationRule, where the user specifies an id-to-class mapping.

The term "plugin point" refers to a pattern associated with a PluginCreateRule. An xml element matching that pattern is expected to have a plugin-id attribute (but see note on "default plugins" elsewhere in this document).

Limitations

The user cannot replace the name of the tag used as the plugin-point; <statement plugin-id="if"> cannot become <if>.

An instance of "PluginRules" must be used as the Rules implementation for the Digester (see example). However a PluginRules can use any other Rules implementation as its rule-matching engine, so this is not a significant issue. Plugged-in classes may only use the default RulesBase matching for the rules they add dynamically.

For technical reasons, a single instance of PluginCreateRule cannot currently be associated with multiple patterns; multiple instances are required. This is not expected to be a problem.

Performance

For patterns which do not involve "plugin points" there is minimal performance impact when adding rules to the Digester, and none when processing input data.

Processing elements which match patterns added dynamically by plugin classes does have a performance impact, but not excessively so.

Alternatives

The "xmlrules" digester module allows modification of parsing rules without code changes or recompilation. However this feature is aimed at the developer, not the end user of an application. The differences between xmlrules functionality and plugins functionality are:
  • With xmlrules, the full set of parsing rules for the whole configuration file is exposed. This is good for developers, but in most cases both too complex and too dangerous to require end users to edit directly.
  • Using xmlrules requires a fair level of knowledge of the Apache Digester. How an end user (not a plugin developer) can use plugins can be explained in about 3 paragraphs.

How to write plugin classes

In order to be useful, the problem domain needs to involve a base class or interface which can have multiple implementations. This section assumes that this is the case, that you have already created a concrete implementation of that base class or interface, and are wondering what changes need to be made to that class to make it suitable for a "plugin".

Well, if the class has a no-argument constuctor, and only simple configuration needs that can be met by a SetPropertiesRule, then no changes need to be made at all.

In other circumstances, you may either define an "addRules" method on the class which adds any necessary rules to the digester, a separate class containing that information, or write an xmlrules-format file defining the necessary rules. In the "separate rule info class" approach, the class containing the rule info may have any name of your choice, but the original class + "RuleInfo" is recommended.

Here is the addRules method on class SubstituteTransform, from the example:

    public static void addRules(Digester d, String pathPrefix) {
        d.addCallMethod(pathPrefix+"/from", "setFrom", 0);
        d.addCallMethod(pathPrefix+"/to", "setTo", 0);
    }
A "rule info" class consists of nothing but a static method defined as above.

If a plugin class does not define an "addRules" method, and the plugin declaration does not associate a rule info class with it, then the plugins module will define a "SetPropertiesRule" by default. However if any custom rules are defined for the plugin class, then that implementation is required to define a SetPropertiesRule for itself if it desires one.

Note that when adding any rules, the pattern passed to the digester must start with the pathPrefix provided. A plugin cannot define rules with absolute paths. And as defined in the limitations, the pattern should not include any wildcard characters.

Other features

Multiple plugin declarations are permitted; the latest simply overrides earlier ones.

In situations where a user might want to specify a custom class, but will often want "default" behaviour, a PluginCreateRule can specify a default class. If the user then omits the "plugin-id" attribute on the matching xml element, an instance of the default class will be created. libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/RuleFinder.java0000644000175000017500000000636011226450007032671 0ustar twernertwerner/* $Id: RuleFinder.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.Properties; import org.apache.commons.digester.Digester; /** * Each concrete implementation of RuleFinder is an algorithm for * locating a source of digester rules for a plugin. The algorithm may * use info explicitly provided by the user as part of the plugin * declaration, or not (in which case the concrete RuleFinder subclass * typically has Dflt as part of its name). *

* Instances of this class can also be regarded as a Factory for RuleLoaders, * except that an instance of a RuleLoader is only created if the particular * finder algorithm can locate a suitable source of rules given the plugin * class and associated properties. *

* This is an abstract class rather than an interface in order to make * it possible to enhance this class in future without breaking binary * compatibility; it is possible to add methods to an abstract class, but * not to an interface. * * @since 1.6 */ public abstract class RuleFinder { /** * Apply the finder algorithm to attempt to locate a source of * digester rules for the specified plugin class. *

* This method is invoked when a plugin is declared by the user, either * via an explicit use of PluginDeclarationRule, or implicitly via an * "inline declaration" where the declaration and use are simultaneous. *

* If dynamic rules for the specified plugin class are located, then * the RuleFinder will return a RuleLoader object encapsulating those * rules, and this object will be invoked each time the user actually * requests an instance of the declared plugin class, to load the * custom rules associated with that plugin instance. *

* If no dynamic rules can be found, null is returned. This is not an * error; merely an indication that this particular algorithm found * no matches. *

* The properties object holds any xml attributes the user may have * specified on the plugin declaration in order to indicate how to locate * the plugin rules. *

* @throws PluginConfigurationException if the algorithm finds a source * of rules, but there is something invalid about that source. */ public abstract RuleLoader findLoader( Digester d, Class pluginClass, Properties p) throws PluginException; } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginAssertionFailure.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginAssertionFail0000644000175000017500000000555211226450007033636 0ustar twernertwerner/* $Id: PluginAssertionFailure.java 476205 2006-11-17 16:43:10Z dennisl $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; /** * Thrown when a bug is detected in the plugins code. *

* This class is intended to be used in assertion statements, similar to * the way that java 1.4's native assertion mechanism is used. However there * is a difference: when a java 1.4 assertion fails, an AssertionError * is thrown, which is a subclass of Error; here, the PluginAssertionFailure * class extends RuntimeException rather than Error. *

* This difference in design is because throwing Error objects is not * good in a container-based architecture. *

* Example: *

 *   if (impossibleCondition) {
 *     throw new PluginAssertionFailure(
 *       "internal error: impossible condition is true");
 *   }
 * 
*

* Note that PluginAssertionFailure should not be thrown when user * input is bad, or when code external to the Digester module passes invalid * parameters to a plugins method. It should be used only in checks for * problems which indicate internal bugs within the plugins module. * * @since 1.6 */ public class PluginAssertionFailure extends RuntimeException { private Throwable cause = null; /** * @param cause underlying exception that caused this to be thrown */ public PluginAssertionFailure(Throwable cause) { this(cause.getMessage()); this.cause = cause; } /** * @param msg describes the reason this exception is being thrown. */ public PluginAssertionFailure(String msg) { super(msg); } /** * @param msg describes the reason this exception is being thrown. * @param cause underlying exception that caused this to be thrown */ public PluginAssertionFailure(String msg, Throwable cause) { this(msg); this.cause = cause; } /** * Return the cause of this exception (if any) as specified in the * exception constructor. * * @since 1.8 */ public Throwable getCause() { return cause; } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginContext.java0000644000175000017500000002272411226450007033437 0ustar twernertwerner/* $Id: PluginContext.java 476312 2006-11-17 20:59:09Z rahul $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import java.util.LinkedList; import org.apache.commons.digester.plugins.strategies.FinderFromFile; import org.apache.commons.digester.plugins.strategies.FinderFromResource; import org.apache.commons.digester.plugins.strategies.FinderFromClass; import org.apache.commons.digester.plugins.strategies.FinderFromMethod; import org.apache.commons.digester.plugins.strategies.FinderFromDfltMethod; import org.apache.commons.digester.plugins.strategies.FinderFromDfltClass; import org.apache.commons.digester.plugins.strategies.FinderFromDfltResource; import org.apache.commons.digester.plugins.strategies.FinderSetProperties; /** * Provides data and services which should exist only once per digester. *

* This class holds a number of useful items which should be shared by all * plugin objects. Such data cannot be stored on the PluginRules or * PluginManager classes, as there can be multiple instances of these at * various times during a parse. *

* The name "Context" refers to the similarity between this class and a * ServletContext class in a servlet engine. A ServletContext object provides * access to the container's services such as obtaining global configuration * parameters for the container, or getting access to logging services. For * plugins, a Digester instance can be regarded as "the container". * * @since 1.6 */ public class PluginContext { // TODO: Consider making following four constants static in 2.0 // the xml attribute the user uses on an xml element to specify // the plugin's class public final String DFLT_PLUGIN_CLASS_ATTR_NS = null; public final String DFLT_PLUGIN_CLASS_ATTR = "plugin-class"; // the xml attribute the user uses on an xml element to specify // the plugin's class public final String DFLT_PLUGIN_ID_ATTR_NS = null; public final String DFLT_PLUGIN_ID_ATTR = "plugin-id"; /** See {@link #setPluginClassAttribute}. */ private String pluginClassAttrNs = DFLT_PLUGIN_CLASS_ATTR_NS; /** See {@link #setPluginClassAttribute}. */ private String pluginClassAttr = DFLT_PLUGIN_CLASS_ATTR; /** See {@link #setPluginClassAttribute}. */ private String pluginIdAttrNs = DFLT_PLUGIN_ID_ATTR_NS; /** See {@link #setPluginClassAttribute}. */ private String pluginIdAttr = DFLT_PLUGIN_ID_ATTR; /** * A list of RuleFinder objects used by all Declarations (and thus * indirectly by all PluginCreateRules to locate the custom rules * for plugin classes. */ private List ruleFinders; //------------------- constructors --------------------------------------- public PluginContext() { } //------------------- methods --------------------------------------- /** * Return the list of RuleFinder objects. Under normal circumstances * this method creates a default list of these objects when first called * (ie "on-demand" or "lazy initialization"). However if setRuleFinders * has been called first, then the list specified there is returned. *

* It is explicitly permitted for the caller to modify this list * by inserting or removing RuleFinder objects. */ public List getRuleFinders() { if (ruleFinders == null) { // when processing a plugin declaration, attempts are made to // find custom rules in the order in which the Finder objects // are added below. However this list can be modified ruleFinders = new LinkedList(); ruleFinders.add(new FinderFromFile()); ruleFinders.add(new FinderFromResource()); ruleFinders.add(new FinderFromClass()); ruleFinders.add(new FinderFromMethod()); ruleFinders.add(new FinderFromDfltMethod()); ruleFinders.add(new FinderFromDfltClass()); ruleFinders.add(new FinderFromDfltResource()); ruleFinders.add(new FinderFromDfltResource(".xml")); ruleFinders.add(new FinderSetProperties()); } return ruleFinders; } /** * Set the list of RuleFinder objects. This may be useful if working * in a non-english language, allowing the application developer to * replace the standard list with a list of objects which look for xml * attributes in the local language. *

* If the intent is just to add an additional rule-finding algorithm, then * it may be better to call #getRuleFinders, and insert a new object into * the start of the list. */ public void setRuleFinders(List ruleFinders) { this.ruleFinders = ruleFinders; } /** * Sets the xml attribute which the input xml uses to indicate to a * PluginCreateRule which class should be instantiated. *

* Example: *

     * setPluginClassAttribute(null, "class");
     * 
* will allow this in the input xml: *
     *  <root>
     *    <some-plugin class="com.acme.widget"> ......
     * 
* instead of the default syntax: *
     *  <root>
     *    <some-plugin plugin-class="com.acme.widget"> ......
     * 
* This is particularly useful if the input xml document is not in * English. *

* Note that the xml attributes used by PluginDeclarationRules are not * affected by this method. * * @param namespaceUri is the namespace uri that the specified attribute * is in. If the attribute is in no namespace, then this should be null. * Note that if a namespace is used, the attrName value should not * contain any kind of namespace-prefix. Note also that if you are using * a non-namespace-aware parser, this parameter must be null. * * @param attrName is the attribute whose value contains the name of the * class to be instantiated. */ public void setPluginClassAttribute(String namespaceUri, String attrName) { pluginClassAttrNs = namespaceUri; pluginClassAttr = attrName; } /** * Sets the xml attribute which the input xml uses to indicate to a * PluginCreateRule which plugin declaration is being referenced. *

* Example: *

     * setPluginIdAttribute(null, "id");
     * 
* will allow this in the input xml: *
     *  <root>
     *    <some-plugin id="widget"> ......
     * 
* rather than the default behaviour: *
     *  <root>
     *    <some-plugin plugin-id="widget"> ......
     * 
* This is particularly useful if the input xml document is not in * English. *

* Note that the xml attributes used by PluginDeclarationRules are not * affected by this method. * * @param namespaceUri is the namespace uri that the specified attribute * is in. If the attribute is in no namespace, then this should be null. * Note that if a namespace is used, the attrName value should not * contain any kind of namespace-prefix. Note also that if you are using * a non-namespace-aware parser, this parameter must be null. * * @param attrName is the attribute whose value contains the id of the * plugin declaration to be used when instantiating an object. */ public void setPluginIdAttribute(String namespaceUri, String attrName) { pluginIdAttrNs = namespaceUri; pluginIdAttr = attrName; } /** * Get the namespace for the xml attribute which indicates to a * PluginCreateRule which class is to be plugged in. *

* May be null (in fact, normally will be). */ public String getPluginClassAttrNs() { return pluginClassAttrNs; } /** * Get the namespace for the xml attribute which indicates to a * PluginCreateRule which class is to be plugged in. *

* The return value is never null. */ public String getPluginClassAttr() { return pluginClassAttr; } /** * Get the namespace for the xml attribute which indicates to a * PluginCreateRule which previous plugin declaration should be used. *

* May be null (in fact, normally will be). */ public String getPluginIdAttrNs() { return pluginIdAttrNs; } /** * Get the namespace for the xml attribute which indicates to a * PluginCreateRule which previous plugin declaration should be used. *

* The return value is never null. */ public String getPluginIdAttr() { return pluginIdAttr; } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/Declaration.java0000644000175000017500000001614711226450007033063 0ustar twernertwerner/* $Id: Declaration.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.digester.Digester; /** * Represents a Class that can be instantiated by a PluginCreateRule, plus * info on how to load custom digester rules for mapping xml into that * plugged-in class. * * @since 1.6 */ public class Declaration { /** The class of the object to be instantiated. */ private Class pluginClass; /** The name of the class of the object to be instantiated. */ private String pluginClassName; /** See {@link #setId}. */ private String id; /** See {@link #setProperties}. */ private Properties properties = new Properties(); /** See {@link #init}. */ private boolean initialized = false; /** * Class which is responsible for dynamically loading this * plugin's rules on demand. */ private RuleLoader ruleLoader = null; //---------------------- constructors ---------------------------------- /** * Constructor. */ public Declaration(String pluginClassName) { // We can't load the pluginClass at this time, because we don't // have a digester instance yet to load it through. So just // save the name away, and we'll load the Class object in the // init method. this.pluginClassName = pluginClassName; } /** * Constructor. */ public Declaration(Class pluginClass) { this.pluginClass = pluginClass; this.pluginClassName = pluginClass.getName(); } /** * Create an instance where a fully-initialised ruleLoader instance * is provided by the caller instead of having the PluginManager * "discover" an appropriate one. */ public Declaration(Class pluginClass, RuleLoader ruleLoader) { this.pluginClass = pluginClass; this.pluginClassName = pluginClass.getName(); this.ruleLoader = ruleLoader; } //---------------------- properties ----------------------------------- /** * The id that the user associated with a particular plugin declaration * in the input xml. This id is later used in the input xml to refer * back to the original declaration. *

* For plugins declared "in-line", the id is null. */ public void setId(String id) { this.id = id; } /** * Return the id associated with this declaration. For plugins * declared "inline", null will be returned. * * @return The id value. May be null. */ public String getId() { return id; } /** * Copy all (key,value) pairs in the param into the properties member of * this object. *

* The declaration properties cannot be explicit member variables, * because the set of useful properties a user can provide on a declaration * depends on what RuleFinder classes are available - and extra RuleFinders * can be added by the user. So here we keep a map of the settings, and * let the RuleFinder objects look for whatever properties they consider * significant. *

* The "id" and "class" properties are treated differently. */ public void setProperties(Properties p) { properties.putAll(p); } /** * Return plugin class associated with this declaration. * * @return The pluginClass. */ public Class getPluginClass() { return pluginClass; } //---------------------- methods ----------------------------------- /** * Must be called exactly once, and must be called before any call * to the configure method. */ public void init(Digester digester, PluginManager pm) throws PluginException { Log log = digester.getLogger(); boolean debug = log.isDebugEnabled(); if (debug) { log.debug("init being called!"); } if (initialized) { throw new PluginAssertionFailure("Init called multiple times."); } if ((pluginClass == null) && (pluginClassName != null)) { try { // load the plugin class object pluginClass = digester.getClassLoader().loadClass(pluginClassName); } catch(ClassNotFoundException cnfe) { throw new PluginException( "Unable to load class " + pluginClassName, cnfe); } } if (ruleLoader == null) { // the caller didn't provide a ruleLoader to the constructor, // so get the plugin manager to "discover" one. log.debug("Searching for ruleloader..."); ruleLoader = pm.findLoader(digester, id, pluginClass, properties); } else { log.debug("This declaration has an explicit ruleLoader."); } if (debug) { if (ruleLoader == null) { log.debug( "No ruleLoader found for plugin declaration" + " id [" + id + "]" + ", class [" + pluginClass.getClass().getName() + "]."); } else { log.debug( "RuleLoader of type [" + ruleLoader.getClass().getName() + "] associated with plugin declaration" + " id [" + id + "]" + ", class [" + pluginClass.getClass().getName() + "]."); } } initialized = true; } /** * Attempt to load custom rules for the target class at the specified * pattern. *

* On return, any custom rules associated with the plugin class have * been loaded into the Rules object currently associated with the * specified digester object. */ public void configure(Digester digester, String pattern) throws PluginException { Log log = digester.getLogger(); boolean debug = log.isDebugEnabled(); if (debug) { log.debug("configure being called!"); } if (!initialized) { throw new PluginAssertionFailure("Not initialized."); } if (ruleLoader != null) { ruleLoader.addRules(digester, pattern); } } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginException.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginException.jav0000644000175000017500000000361111226450007033602 0ustar twernertwerner/* $Id: PluginException.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; /** * Thrown when some plugin-related error has occurred, and none of the * other exception types are appropriate. * * @since 1.6 */ public class PluginException extends Exception { private Throwable cause = null; /** * @param cause underlying exception that caused this to be thrown */ public PluginException(Throwable cause) { this(cause.getMessage()); this.cause = cause; } /** * @param msg describes the reason this exception is being thrown. */ public PluginException(String msg) { super(msg); } /** * @param msg describes the reason this exception is being thrown. * @param cause underlying exception that caused this to be thrown */ public PluginException(String msg, Throwable cause) { this(msg); this.cause = cause; } /** * @return the underlying exception that caused this to be thrown */ public Throwable getCause() { return cause; } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginRules.java0000644000175000017500000003554411226450007033111 0ustar twernertwerner/* $Id: PluginRules.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.List; import org.apache.commons.digester.Digester; import org.apache.commons.digester.Rule; import org.apache.commons.digester.Rules; import org.apache.commons.digester.RulesBase; import org.apache.commons.logging.Log; /** * A custom digester Rules manager which must be used as the Rules object * when using the plugins module functionality. *

* During parsing, a linked list of PluginCreateRule instances develop, and * this list also acts like a stack. The original instance that was set before * the Digester started parsing is always at the tail of the list, and the * Digester always holds a reference to the instance at the head of the list * in the rules member. Initially, this list/stack holds just one instance, * ie head and tail are the same object. *

* When the start of an xml element causes a PluginCreateRule to fire, a new * PluginRules instance is created and inserted at the head of the list (ie * pushed onto the stack of Rules objects). Digester.getRules() therefore * returns this new Rules object, and any custom rules associated with that * plugin are added to that instance. *

* When the end of the xml element is encountered (and therefore the * PluginCreateRule end method fires), the stack of Rules objects is popped, * so that Digester.getRules returns the previous Rules object. * * @since 1.6 */ public class PluginRules implements Rules { /** * The Digester instance with which this Rules instance is associated. */ protected Digester digester = null; /** * The (optional) object which generates new rules instances. */ private RulesFactory rulesFactory; /** * The rules implementation that we are "enhancing" with plugins * functionality, as per the Decorator pattern. */ private Rules decoratedRules; /** Object which contains information about all known plugins. */ private PluginManager pluginManager; /** * The path below which this rules object has responsibility. * For paths shorter than or equal the mountpoint, the parent's * match is called. */ private String mountPoint = null; /** * The Rules object that holds rules applying "above" the mountpoint, * ie the next Rules object down in the stack. */ private PluginRules parent = null; /** * A reference to the object that holds all data which should only * exist once per digester instance. */ private PluginContext pluginContext = null; // ------------------------------------------------------------- Constructor /** * Constructor for top-level Rules objects. Exactly one of these must * be created and installed into the Digester instance as the Rules * object before parsing starts. */ public PluginRules() { this(new RulesBase()); } /** * Constructor for top-level Rules object which handles rule-matching * using the specified implementation. */ public PluginRules(Rules decoratedRules) { this.decoratedRules = decoratedRules; pluginContext = new PluginContext(); pluginManager = new PluginManager(pluginContext); } /** * Constructs a Rules instance which has a parent Rules object * (which is different from having a delegate rules object). *

* One of these is created each time a PluginCreateRule's begin method * fires, in order to manage the custom rules associated with whatever * concrete plugin class the user has specified. * * @param digester is the object this rules will be associated with. * @param mountPoint is the digester match path for the element * matching a PluginCreateRule which caused this "nested parsing scope" * to begin. This is expected to be equal to digester.getMatch(). * @param parent must be non-null. * @param pluginClass is the plugin class whose custom rules will be * loaded into this new PluginRules object. */ PluginRules( Digester digester, String mountPoint, PluginRules parent, Class pluginClass) throws PluginException { // no need to set digester or decoratedRules.digester, // because when Digester.setRules is called, the setDigester // method on this object will be called. this.digester = digester; this.mountPoint = mountPoint; this.parent = parent; this.rulesFactory = parent.rulesFactory; if (rulesFactory == null) { decoratedRules = new RulesBase(); } else { decoratedRules = rulesFactory.newRules(digester, pluginClass); } pluginContext = parent.pluginContext; pluginManager = new PluginManager(parent.pluginManager); } // ------------------------------------------------------------- Properties /** * Return the parent Rules object. */ public Rules getParent() { return parent; } /** * Return the Digester instance with which this instance is associated. */ public Digester getDigester() { return digester; } /** * Set the Digester instance with which this Rules instance is associated. * * @param digester The newly associated Digester instance */ public void setDigester(Digester digester) { this.digester = digester; decoratedRules.setDigester(digester); } /** * Return the namespace URI that will be applied to all subsequently * added Rule objects. */ public String getNamespaceURI() { return decoratedRules.getNamespaceURI(); } /** * Set the namespace URI that will be applied to all subsequently * added Rule objects. * * @param namespaceURI Namespace URI that must match on all * subsequently added rules, or null for matching * regardless of the current namespace URI */ public void setNamespaceURI(String namespaceURI) { decoratedRules.setNamespaceURI(namespaceURI); } /** * Return the object which "knows" about all declared plugins. * * @return The pluginManager value */ public PluginManager getPluginManager() { return pluginManager; } /** * See {@link PluginContext#getRuleFinders}. */ public List getRuleFinders() { return pluginContext.getRuleFinders(); } /** * See {@link PluginContext#setRuleFinders}. */ public void setRuleFinders(List ruleFinders) { pluginContext.setRuleFinders(ruleFinders); } /** * Return the rules factory object (or null if one has not been specified). */ public RulesFactory getRulesFactory() { return rulesFactory; } /** * Set the object which is used to generate the new Rules instances created * to hold and process the rules associated with each plugged-in class. */ public void setRulesFactory(RulesFactory factory) { rulesFactory = factory; } // --------------------------------------------------------- Public Methods /** * This package-scope method is used by the PluginCreateRule class to * get direct access to the rules that were dynamically added by the * plugin. No other class should need access to this object. */ Rules getDecoratedRules() { return decoratedRules; } /** * Return the list of rules registered with this object, in the order * they were registered with this object. *

* Note that Rule objects stored in parent Rules objects are not * returned by this method. * * @return list of all Rule objects known to this Rules instance. */ public List rules() { return decoratedRules.rules(); } /** * Register a new Rule instance matching the specified pattern. * * @param pattern Nesting pattern to be matched for this Rule. * This parameter treats equally patterns that begin with and without * a leading slash ('/'). * @param rule Rule instance to be registered */ public void add(String pattern, Rule rule) { Log log = LogUtils.getLogger(digester); boolean debug = log.isDebugEnabled(); if (debug) { log.debug("add entry" + ": mapping pattern [" + pattern + "]" + " to rule of type [" + rule.getClass().getName() + "]"); } // allow patterns with a leading slash character if (pattern.startsWith("/")) { pattern = pattern.substring(1); } if (mountPoint != null) { if (!pattern.equals(mountPoint) && !pattern.startsWith(mountPoint + "/")) { // This can only occur if a plugin attempts to add a // rule with a pattern that doesn't start with the // prefix passed to the addRules method. Plugins mustn't // add rules outside the scope of the tag they were specified // on, so refuse this. // alas, can't throw exception log.warn( "An attempt was made to add a rule with a pattern that" + "is not at or below the mountpoint of the current" + " PluginRules object." + " Rule pattern: " + pattern + ", mountpoint: " + mountPoint + ", rule type: " + rule.getClass().getName()); return; } } decoratedRules.add(pattern, rule); if (rule instanceof InitializableRule) { try { ((InitializableRule)rule).postRegisterInit(pattern); } catch (PluginConfigurationException e) { // Currently, Digester doesn't handle exceptions well // from the add method. The workaround is for the // initialisable rule to remember that its initialisation // failed, and to throw the exception when begin is // called for the first time. if (debug) { log.debug("Rule initialisation failed", e); } // throw e; -- alas, can't do this return; } } if (debug) { log.debug("add exit" + ": mapped pattern [" + pattern + "]" + " to rule of type [" + rule.getClass().getName() + "]"); } } /** * Clear all rules. */ public void clear() { decoratedRules.clear(); } /** * Return a List of all registered Rule instances that match the specified * nesting pattern, or a zero-length List if there are no matches. If more * than one Rule instance matches, they must be returned * in the order originally registered through the add() * method. * * @param path the path to the xml nodes to be matched. * * @deprecated Call match(namespaceURI,pattern) instead. */ public List match(String path) { return (match(null, path)); } /** * Return a List of all registered Rule instances that match the specified * nodepath, or a zero-length List if there are no matches. If more * than one Rule instance matches, they must be returned * in the order originally registered through the add() * method. *

* @param namespaceURI Namespace URI for which to select matching rules, * or null to match regardless of namespace URI * @param path the path to the xml nodes to be matched. */ public List match(String namespaceURI, String path) { Log log = LogUtils.getLogger(digester); boolean debug = log.isDebugEnabled(); if (debug) { log.debug( "Matching path [" + path + "] on rules object " + this.toString()); } List matches; if ((mountPoint != null) && (path.length() <= mountPoint.length())) { if (debug) { log.debug( "Path [" + path + "] delegated to parent."); } matches = parent.match(namespaceURI, path); // Note that in the case where path equals mountPoint, // we deliberately return only the rules from the parent, // even though this object may hold some rules matching // this same path. See PluginCreateRule's begin, body and end // methods for the reason. } else { log.debug("delegating to decorated rules."); matches = decoratedRules.match(namespaceURI, path); } return matches; } /** See {@link PluginContext#setPluginClassAttribute}. */ public void setPluginClassAttribute(String namespaceUri, String attrName) { pluginContext.setPluginClassAttribute(namespaceUri, attrName); } /** See {@link PluginContext#setPluginIdAttribute}. */ public void setPluginIdAttribute(String namespaceUri, String attrName) { pluginContext.setPluginIdAttribute(namespaceUri, attrName); } /** See {@link PluginContext#getPluginClassAttrNs}. */ public String getPluginClassAttrNs() { return pluginContext.getPluginClassAttrNs(); } /** See {@link PluginContext#getPluginClassAttr}. */ public String getPluginClassAttr() { return pluginContext.getPluginClassAttr(); } /** See {@link PluginContext#getPluginIdAttrNs}. */ public String getPluginIdAttrNs() { return pluginContext.getPluginIdAttrNs(); } /** See {@link PluginContext#getPluginIdAttr}. */ public String getPluginIdAttr() { return pluginContext.getPluginIdAttr(); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/0000755000175000017500000000000011226450007032134 5ustar twernertwerner././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFromDfltClass.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFr0000644000175000017500000000675611226450007033574 0ustar twernertwerner/* $Id: FinderFromDfltClass.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.util.Properties; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.RuleFinder; import org.apache.commons.digester.plugins.RuleLoader; import org.apache.commons.digester.plugins.PluginException; /** * A rule-finding algorithm which looks for a method with a specific name * on a class whose name is derived from the plugin class name. * * @since 1.6 */ public class FinderFromDfltClass extends RuleFinder { public static String DFLT_RULECLASS_SUFFIX = "RuleInfo"; public static String DFLT_METHOD_NAME = "addRules"; private String rulesClassSuffix; private String methodName; /** See {@link #findLoader}. */ public FinderFromDfltClass() { this(DFLT_RULECLASS_SUFFIX, DFLT_METHOD_NAME); } /** * Create a rule-finder which invokes a method on a class whenever * dynamic rules for a plugin need to be loaded. See the findRules * method for more info. * * @param rulesClassSuffix must be non-null. * @param methodName may be null. */ public FinderFromDfltClass(String rulesClassSuffix, String methodName) { this.rulesClassSuffix = rulesClassSuffix; this.methodName = methodName; } /** * If there exists a class whose name is the plugin class name + the * suffix specified to the constructor, then load that class, locate * the appropriate rules-adding method on that class, and return an * object encapsulating that info. *

* If there is no such class, then just return null. *

* The returned object (when non-null) will invoke the target method * on the selected class whenever its addRules method is invoked. The * target method is expected to have the following prototype: * public static void xxxxx(Digester d, String patternPrefix); */ public RuleLoader findLoader(Digester digester, Class pluginClass, Properties p) throws PluginException { String rulesClassName = pluginClass.getName() + rulesClassSuffix; Class rulesClass = null; try { rulesClass = digester.getClassLoader().loadClass(rulesClassName); } catch(ClassNotFoundException cnfe) { // ok, ignore } if (rulesClass == null) { // nope, no rule-info class in the classpath return null; } if (methodName == null) { methodName = DFLT_METHOD_NAME; } return new LoaderFromClass(rulesClass, methodName); } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFromDfltMethod.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFr0000644000175000017500000000557211226450007033567 0ustar twernertwerner/* $Id: FinderFromDfltMethod.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.util.Properties; import java.lang.reflect.Method; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.RuleFinder; import org.apache.commons.digester.plugins.RuleLoader; import org.apache.commons.digester.plugins.PluginException; /** * A rule-finding algorithm which looks for a method with a specific name * on the plugin class. * * @since 1.6 */ public class FinderFromDfltMethod extends RuleFinder { public static String DFLT_METHOD_NAME = "addRules"; private String methodName; /** See {@link #findLoader}. */ public FinderFromDfltMethod() { this(DFLT_METHOD_NAME); } /** * Create a rule-finder which invokes a specific method on the plugin * class whenever dynamic rules for a plugin need to be loaded. See the * findRules method for more info. * * @param methodName must be non-null. */ public FinderFromDfltMethod(String methodName) { this.methodName = methodName; } /** * If there exists on the plugin class a method with name matching the * constructor's methodName value then locate the appropriate Method on * the plugin class and return an object encapsulating that info. *

* If there is no matching method then just return null. *

* The returned object (when non-null) will invoke the target method * on the plugin class whenever its addRules method is invoked. The * target method is expected to have the following prototype: * public static void xxxxx(Digester d, String patternPrefix); */ public RuleLoader findLoader(Digester d, Class pluginClass, Properties p) throws PluginException { Method rulesMethod = LoaderFromClass.locateMethod(pluginClass, methodName); if (rulesMethod == null) { return null; } return new LoaderFromClass(pluginClass, rulesMethod); } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/LoaderSetProperties.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/LoaderSe0000644000175000017500000000364611226450007033566 0ustar twernertwerner/* $Id: LoaderSetProperties.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import org.apache.commons.digester.Digester; import org.apache.commons.logging.Log; import org.apache.commons.digester.plugins.RuleLoader; /** * A RuleLoader which creates a single SetPropertiesRule and adds it to the * digester when its addRules() method is invoked. *

* This loader ensures that any xml attributes on the plugin tag get * mapped to equivalent properties on a javabean. This allows JavaBean * classes to be used as plugins without any requirement to create custom * plugin rules. * * @since 1.6 */ public class LoaderSetProperties extends RuleLoader { /** * Just add a SetPropertiesRule at the specified path. */ public void addRules(Digester digester, String path) { Log log = digester.getLogger(); boolean debug = log.isDebugEnabled(); if (debug) { log.debug( "LoaderSetProperties loading rules for plugin at path [" + path + "]"); } digester.addSetProperties(path); } } ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFromMethod.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFr0000644000175000017500000000561311226450007033563 0ustar twernertwerner/* $Id: FinderFromMethod.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.util.Properties; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.RuleFinder; import org.apache.commons.digester.plugins.RuleLoader; import org.apache.commons.digester.plugins.PluginException; /** * A rule-finding algorithm which expects the caller to specify a methodname * as a plugin property, where the method exists on the plugin class. * * @since 1.6 */ public class FinderFromMethod extends RuleFinder { /** * Xml attribute that needs to be present on a plugin declaration * in order to specify the method to load rules from. */ public static String DFLT_METHOD_ATTR = "method"; /** See {@link #findLoader}. */ private String methodAttr; /** Constructor. */ public FinderFromMethod() { this(DFLT_METHOD_ATTR); } /** See {@link #findLoader}. */ public FinderFromMethod(String methodAttr) { this.methodAttr = methodAttr; } /** * If there exists a property with the name matching constructor param * methodAttr, then locate the appropriate Method on the plugin class * and return an object encapsulating that info. *

* If there is no matching property provided, then just return null. *

* The returned object (when non-null) will invoke the target method * on the plugin class whenever its addRules method is invoked. The * target method is expected to have the following prototype: * public static void xxxxx(Digester d, String patternPrefix); */ public RuleLoader findLoader(Digester d, Class pluginClass, Properties p) throws PluginException { String methodName = p.getProperty(methodAttr); if (methodName == null) { // nope, user hasn't requested dynamic rules to be loaded // from a specific class. return null; } return new LoaderFromClass(pluginClass, methodName); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/package.htmllibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/package.0000644000175000017500000000770011226450007033534 0ustar twernertwerner The digester.plugins.strategies package.

This package contains "rule-finding" strategy classes, and their associated "helper" loader classes.

Note that you do not need to understand or deal with any of the classes in this package in order to use the plugins functionality. If you wish to use plugins functionality in non-english languages and therefore want to change the attribute names used on plugin declaration tags ("id", "file", etc) then you will need some familiarity with this package. Otherwise, this package is only relevant to people really wishing to tweak plugins in unexpected ways. If this is the case, come and talk to us on the digester email lists as we would be interested in knowing about your requirements.

When the plugins module is being used and the input xml indicates that a specific plugin class is to be instantiated, that class may then wish to configure itself from the xml attributes on that tag or xml attributes and elements nested within that tag.

The question is: how is the digester going to figure out where the plugin keeps its custom rules which are to be applied to the xml within that plugin tag?

Well, the answer is that there is a list of "rule finding strategies", generally containing an instance of each of the Finder classes in this package in a specific order. The strategies provided here should satisfy just about everyone, but if they don't you can add extra strategies if desired.

A RuleFinder is essentially a "strategy" or "algorithm" for finding the dynamic rules associated with a plugin class. When a plugin declaration is encountered in the input xml, the PluginContext object is asked for the list of RuleFinder objects, then each RuleFinder instance in turn is passed the declaration parameters, and asked "are you able to locate custom parsing rules for this declaration?". When one can, it returns a RuleLoader instance which is remembered. When the input xml indicates that an instance of the declared plugin class is to be created, that RuleLoader is invoked to temporarily add the relevant custom rules to the Digester in order to map xml attributes/elements/etc into the instantiated plugin object. Once the end of the plugin tag is encountered, those temporary rules are removed. This repeats each time the input xml indicates that an instance of a plugin class is to be instantiated.

If the plugin is declared "inline", using the "plugin-class" attribute instead of using "plugin-id" to reference a previous declaration then the process is exactly the same, except that the RuleFinder objects don't have any user-provided attribute "hints" to tell them where the custom rules are.

The RuleFinder list is carefully ordered; classes which look at the user-provided data in the declaration come first, and classes which look in "well-known places" come later so that users can override default behaviour by providing the appropriate tags on the plugin declaration.

See the javadoc on the different Finder classes for information on what each does, and what attribute (if any) it looks for in the declaration. ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFromFile.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFr0000644000175000017500000000717111226450007033564 0ustar twernertwerner/* $Id: FinderFromFile.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.util.Properties; import java.io.InputStream; import java.io.FileInputStream; import java.io.IOException; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.RuleFinder; import org.apache.commons.digester.plugins.RuleLoader; import org.apache.commons.digester.plugins.PluginException; /** * A rule-finding algorithm which expects the user to specify an absolute * or relative path in the plugin declaration. *

* The file is expected to contain Digester rules in xmlrules format. * * @since 1.6 */ public class FinderFromFile extends RuleFinder { /** * Xml attribute that needs to be present on a plugin declaration * in order to specify the file to load rules from. */ public static String DFLT_FILENAME_ATTR = "file"; /** See {@link #findLoader}. */ private String filenameAttr; /** See {@link #findLoader}. */ public FinderFromFile() { this(DFLT_FILENAME_ATTR); } /** See {@link #findLoader}. */ public FinderFromFile(String filenameAttr) { this.filenameAttr = filenameAttr; } /** * If there exists a property with the name specified in the constructor, * then load that file, run it through the xmlrules module and return an * object encapsulating those rules. *

* If there is no matching property provided, then just return null. *

* The returned object (when non-null) will add the selected rules to * the digester whenever its addRules method is invoked. */ public RuleLoader findLoader(Digester d, Class pluginClass, Properties p) throws PluginException { String rulesFileName = p.getProperty(filenameAttr); if (rulesFileName == null) { // nope, user hasn't requested dynamic rules to be loaded // from a specific file. return null; } InputStream is = null; try { is = new FileInputStream(rulesFileName); } catch(IOException ioe) { throw new PluginException( "Unable to process file [" + rulesFileName + "]", ioe); } try { RuleLoader loader = new LoaderFromStream(is); return loader; } catch(Exception e) { throw new PluginException( "Unable to load xmlrules from file [" + rulesFileName + "]", e); } finally { try { is.close(); } catch(java.io.IOException ioe) { throw new PluginException( "Unable to close stream for file [" + rulesFileName + "]", ioe); } } } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFromResource.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFr0000644000175000017500000001063011226450007033556 0ustar twernertwerner/* $Id: FinderFromResource.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.util.Properties; import java.io.InputStream; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.RuleFinder; import org.apache.commons.digester.plugins.RuleLoader; import org.apache.commons.digester.plugins.PluginException; /** * A rule-finding algorithm which expects the user to specify a resource * name (ie a file in the classpath). The file is expected to contain Digester * rules in xmlrules format. * * @since 1.6 */ public class FinderFromResource extends RuleFinder { /** * Name of xml attribute on the plugin declaration which is used * to configure rule-loading for that declaration. */ public static String DFLT_RESOURCE_ATTR = "resource"; /** See {@link #findLoader}. */ private String resourceAttr; /** Constructor. */ public FinderFromResource() { this(DFLT_RESOURCE_ATTR); } /** See {@link #findLoader}. */ public FinderFromResource(String resourceAttr) { this.resourceAttr = resourceAttr; } /** * If there exists a property with the name matching constructor param * resourceAttr, then load that file, run it through the xmlrules * module and return an object encapsulating those rules. *

* If there is no matching property provided, then just return null. *

* The returned object (when non-null) will add the selected rules to * the digester whenever its addRules method is invoked. */ public RuleLoader findLoader(Digester d, Class pluginClass, Properties p) throws PluginException { String resourceName = p.getProperty(resourceAttr); if (resourceName == null) { // nope, user hasn't requested dynamic rules to be loaded // from a specific file. return null; } InputStream is = pluginClass.getClassLoader().getResourceAsStream( resourceName); if (is == null) { throw new PluginException( "Resource " + resourceName + " not found."); } return loadRules(d, pluginClass, is, resourceName); } /** * Open the specified resource file (ie a file in the classpath, * including being within a jar in the classpath), run it through * the xmlrules module and return an object encapsulating those rules. * * @param d is the digester into which rules will eventually be loaded. * @param pluginClass is the class whose xml params the rules are parsing. * @param is is where the xmlrules will be read from, and must be non-null. * @param resourceName is a string describing the source of the xmlrules, * for use in generating error messages. */ public static RuleLoader loadRules(Digester d, Class pluginClass, InputStream is, String resourceName) throws PluginException { try { RuleLoader loader = new LoaderFromStream(is); return loader; } catch(Exception e) { throw new PluginException( "Unable to load xmlrules from resource [" + resourceName + "]", e); } finally { try { is.close(); } catch(java.io.IOException ioe) { throw new PluginException( "Unable to close stream for resource [" + resourceName + "]", ioe); } } } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/LoaderFromClass.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/LoaderFr0000644000175000017500000000671011226450007033561 0ustar twernertwerner/* $Id: LoaderFromClass.java 472842 2006-11-09 10:19:56Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.lang.reflect.Method; import org.apache.commons.digester.Digester; import org.apache.commons.beanutils.MethodUtils; import org.apache.commons.logging.Log; import org.apache.commons.digester.plugins.RuleLoader; import org.apache.commons.digester.plugins.PluginException; /** * A RuleLoader which invokes a static method on a target class, leaving that * method to actually instantiate and add new rules to a Digester instance. * * @since 1.6 */ public class LoaderFromClass extends RuleLoader { private Class rulesClass; private Method rulesMethod; /** Constructor. */ public LoaderFromClass(Class rulesClass, Method rulesMethod) { this.rulesClass = rulesClass; this.rulesMethod = rulesMethod; } /** Constructor. */ public LoaderFromClass(Class rulesClass, String methodName) throws PluginException { Method method = locateMethod(rulesClass, methodName); if (method == null) { throw new PluginException( "rule class " + rulesClass.getName() + " does not have method " + methodName + " or that method has an invalid signature."); } this.rulesClass = rulesClass; this.rulesMethod = method; } /** * Just invoke the target method. */ public void addRules(Digester d, String path) throws PluginException { Log log = d.getLogger(); boolean debug = log.isDebugEnabled(); if (debug) { log.debug( "LoaderFromClass loading rules for plugin at path [" + path + "]"); } try { Object[] params = {d, path}; rulesMethod.invoke(null, params); } catch (Exception e) { throw new PluginException( "Unable to invoke rules method " + rulesMethod + " on rules class " + rulesClass, e); } } /** * Find a method on the specified class whose name matches methodName, * and whose signature is: * public static void foo(Digester d, String patternPrefix);. * * @return null if no such method exists. */ public static Method locateMethod(Class rulesClass, String methodName) throws PluginException { Class[] paramSpec = { Digester.class, String.class }; Method rulesMethod = MethodUtils.getAccessibleMethod( rulesClass, methodName, paramSpec); return rulesMethod; } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderSetProperties.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderSe0000644000175000017500000000741211226450007033562 0ustar twernertwerner/* $Id: FinderSetProperties.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.util.Properties; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.RuleFinder; import org.apache.commons.digester.plugins.RuleLoader; /** * A rule-finding algorithm which expects the user to specify whether * "automatic property setting" is desired. If this class discovers that * this is in fact the case for a declaration, then a RuleLoader is returned * which, when invoked, adds a single SetPropertiesRule instance to the * digester. *

* This allows ordinary JavaBean classes to be used as plugins, and have * xml attributes be mapped to bean properties of the same name, without * any custom plugin rules being created for them. *

* This RuleFinder is typically used as the last RuleFinder, so that * automatic property setting only occurs if there is no other source of * custom rules available. * * @since 1.6 */ public class FinderSetProperties extends RuleFinder { public static String DFLT_PROPS_ATTR = "setprops"; public static String DFLT_FALSEVAL = "false"; private String propsAttr; private String falseval; /** See {@link #findLoader}. */ public FinderSetProperties() { this(DFLT_PROPS_ATTR, DFLT_FALSEVAL); } /** * Create a rule-finder which will arrange for a SetPropertiesRule to * be defined for each instance of a plugin, so that xml attributes * map to bean properties. *

* Param falseval will commonly be the string "false" for config files * written in English. * * @param propsAttr must be non-null. * @param falseval must be non-null. */ public FinderSetProperties(String propsAttr, String falseval) { this.propsAttr = propsAttr; this.falseval = falseval; } /** * Returns a RuleLoader unless the properties contain an entry * with the name matching constructor param propsAttr, and the value * matching what is in falseval. *

* If no custom source of rules for a plugin is found, then the user * almost always wants xml attributes to map to java bean properties, * so this is the default behaviour unless the user explicitly indicates * that they do not want a SetPropertiesRule to be provided for * the plugged-in class. *

* The returned object (when non-null) will add a SetPropertiesRule to * the digester whenever its addRules method is invoked. */ public RuleLoader findLoader(Digester d, Class pluginClass, Properties p) { String state = p.getProperty(propsAttr); if ((state != null) && state.equals(falseval)) { // user has explicitly disabled automatic setting of properties. // this is not expected to be common, but allowed. return null; } return new LoaderSetProperties(); } } ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/LoaderFromStream.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/LoaderFr0000644000175000017500000000630411226450007033560 0ustar twernertwerner/* $Id: LoaderFromStream.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.io.InputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import org.xml.sax.InputSource; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.RuleLoader; import org.apache.commons.digester.plugins.PluginException; import org.apache.commons.digester.xmlrules.FromXmlRuleSet; import org.apache.commons.logging.Log; /** * A rule-finding algorithm which loads an xmlplugins-format file. *

* Note that the "include" feature of xmlrules is not supported. * * @since 1.6 */ public class LoaderFromStream extends RuleLoader { private byte[] input; private FromXmlRuleSet ruleSet; /** See {@link #load}. */ public LoaderFromStream(InputStream s) throws Exception { load(s); } /** * The contents of the input stream are loaded into memory, and * cached for later use. *

* The caller is responsible for closing the input stream after this * method has returned. */ private void load(InputStream s) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[256]; for(;;) { int i = s.read(buf); if (i == -1) break; baos.write(buf, 0, i); } input = baos.toByteArray(); } /** * Add the rules previously loaded from the input stream into the * specified digester. */ public void addRules(Digester d, String path) throws PluginException { Log log = d.getLogger(); boolean debug = log.isDebugEnabled(); if (debug) { log.debug( "LoaderFromStream: loading rules for plugin at path [" + path + "]"); } // Note that this input-source doesn't have any idea of its // system id, so it has no way of resolving relative URLs // such as the "include" feature of xmlrules. This is ok, // because that doesn't work well with our approach of // caching the input data in memory anyway. InputSource source = new InputSource(new ByteArrayInputStream(input)); FromXmlRuleSet ruleSet = new FromXmlRuleSet(source); ruleSet.addRuleInstances(d, path); } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFromDfltResource.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFr0000644000175000017500000000621711226450007033564 0ustar twernertwerner/* $Id: FinderFromDfltResource.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.io.InputStream; import java.util.Properties; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.RuleFinder; import org.apache.commons.digester.plugins.RuleLoader; import org.apache.commons.digester.plugins.PluginException; /** * A rule-finding algorithm which looks for a resource file in the classpath * whose name is derived from the plugin class name plus a specified suffix. *

* If the resource-file is found, then it is expected to define a set of * Digester rules in xmlrules format. * * @since 1.6 */ public class FinderFromDfltResource extends RuleFinder { public static String DFLT_RESOURCE_SUFFIX = "RuleInfo.xml"; private String resourceSuffix; /** See {@link #findLoader}. */ public FinderFromDfltResource() { this(DFLT_RESOURCE_SUFFIX); } /** * Create a rule-finder which can load an xmlrules file, cache * the rules away, and later add them as a plugin's custom rules * when that plugin is referenced. * * @param resourceSuffix must be non-null. */ public FinderFromDfltResource(String resourceSuffix) { this.resourceSuffix = resourceSuffix; } /** * If there exists a resource file whose name is equal to the plugin * class name + the suffix specified in the constructor, then * load that file, run it through the xmlrules module and return an object * encapsulating those rules. *

* If there is no such resource file, then just return null. *

* The returned object (when non-null) will add the selected rules to * the digester whenever its addRules method is invoked. */ public RuleLoader findLoader(Digester d, Class pluginClass, Properties p) throws PluginException { String resourceName = pluginClass.getName().replace('.', '/') + resourceSuffix; InputStream is = pluginClass.getClassLoader().getResourceAsStream( resourceName); if (is == null) { // ok, no such resource return null; } return FinderFromResource.loadRules(d, pluginClass, is, resourceName); } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFromClass.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/strategies/FinderFr0000644000175000017500000001173311226450007033563 0ustar twernertwerner/* $Id: FinderFromClass.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins.strategies; import java.util.Properties; import org.apache.commons.digester.Digester; import org.apache.commons.digester.plugins.RuleFinder; import org.apache.commons.digester.plugins.RuleLoader; import org.apache.commons.digester.plugins.PluginException; /** * A rule-finding algorithm which expects the caller to specify a classname and * methodname as plugin properties. * * @since 1.6 */ public class FinderFromClass extends RuleFinder { public static String DFLT_RULECLASS_ATTR = "ruleclass"; public static String DFLT_METHOD_ATTR = "method"; public static String DFLT_METHOD_NAME = "addRules"; private String ruleClassAttr; private String methodAttr; private String dfltMethodName; /** * See {@link #findLoader}. */ public FinderFromClass() { this(DFLT_RULECLASS_ATTR, DFLT_METHOD_ATTR, DFLT_METHOD_NAME); } /** * Create a rule-finder which invokes a user-specified method on a * user-specified class whenever dynamic rules for a plugin need to be * loaded. See the findRules method for more info. * * @param ruleClassAttr must be non-null. * @param methodAttr may be null. * @param dfltMethodName may be null. */ public FinderFromClass(String ruleClassAttr, String methodAttr, String dfltMethodName) { this.ruleClassAttr = ruleClassAttr; this.methodAttr = methodAttr; this.dfltMethodName = dfltMethodName; } /** * If there exists a property with the name matching constructor param * ruleClassAttr, then load the specified class, locate the appropriate * rules-adding method on that class, and return an object encapsulating * that info. *

* If there is no matching property provided, then just return null. *

* The returned object (when non-null) will invoke the target method * on the selected class whenever its addRules method is invoked. The * target method is expected to have the following prototype: * public static void xxxxx(Digester d, String patternPrefix); *

* The target method can be specified in several ways. If this object's * constructor was passed a non-null methodAttr parameter, and the * properties defines a value with that key, then that is taken as the * target method name. If there is no matching property, or the constructor * was passed null for methodAttr, then the dfltMethodName passed to the * constructor is used as the name of the method on the target class. And * if that was null, then DFLT_METHOD_NAME will be used. *

* When the user explicitly declares a plugin in the input xml, the * xml attributes on the declaration tag are passed here as properties, * so the user can select any class in the classpath (and any method on * that class provided it has the correct prototype) as the source of * dynamic rules for the plugged-in class. */ public RuleLoader findLoader(Digester digester, Class pluginClass, Properties p) throws PluginException { String ruleClassName = p.getProperty(ruleClassAttr); if (ruleClassName == null) { // nope, user hasn't requested dynamic rules to be loaded // from a specific class. return null; } // ok, we are in business String methodName = null; if (methodAttr != null) { methodName = p.getProperty(methodAttr); } if (methodName == null) { methodName = dfltMethodName; } if (methodName == null) { methodName = DFLT_METHOD_NAME; } Class ruleClass; try { // load the plugin class object ruleClass = digester.getClassLoader().loadClass(ruleClassName); } catch(ClassNotFoundException cnfe) { throw new PluginException( "Unable to load class " + ruleClassName, cnfe); } return new LoaderFromClass(ruleClass, methodName); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/RuleLoader.java0000644000175000017500000000375111226450007032671 0ustar twernertwerner/* $Id: RuleLoader.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import org.apache.commons.digester.Digester; /** * Interface for classes which can dynamically load custom * plugin rules associated with a user's plugin class. *

* Each plugin declaration has an associated RuleLoader instance, and that * instance's addRules method is invoked each time the input xml specifies * that an instance of that plugged-in class is to be created. *

* This is an abstract class rather than an interface in order to make * it possible to enhance this class in future without breaking binary * compatibility; it is possible to add methods to an abstract class, but * not to an interface. * * @since 1.6 */ public abstract class RuleLoader { /** * Configures the digester with custom rules for some plugged-in * class. *

* This method is invoked when the start of an xml tag is encountered * which maps to a PluginCreateRule. Any rules added here are removed * from the digester when the end of that xml tag is encountered. */ public abstract void addRules(Digester d, String path) throws PluginException; } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginDeclarationRule.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/PluginDeclarationRu0000644000175000017500000001026411226450007033623 0ustar twernertwerner/* $Id: PluginDeclarationRule.java 472837 2006-11-09 10:07:51Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import java.util.Properties; import org.apache.commons.digester.Digester; import org.apache.commons.digester.Rule; /** * A Digester rule which allows the user to pre-declare a class which is to * be referenced later at a plugin point by a PluginCreateRule. *

* Normally, a PluginDeclarationRule is added to a Digester instance with * the pattern "{root}/plugin" or "* /plugin" where {root} is the name of * the root tag in the input document. * * @since 1.6 */ public class PluginDeclarationRule extends Rule { //------------------- constructors --------------------------------------- /** constructor */ public PluginDeclarationRule() { super(); } //------------------- methods -------------------------------------------- /** * Invoked upon reading a tag defining a plugin declaration. The tag * must have the following mandatory attributes: *

    *
  • id
  • *
  • class
  • *
* *@param namespace The xml namespace in which the xml element which * triggered this rule resides. *@param name The name of the xml element which triggered this rule. *@param attributes The set of attributes on the xml element which * triggered this rule. *@exception java.lang.Exception */ public void begin(String namespace, String name, org.xml.sax.Attributes attributes) throws java.lang.Exception { int nAttrs = attributes.getLength(); Properties props = new Properties(); for(int i=0; i * One instance of this class exists per PluginRules instance. * * @since 1.6 */ public class PluginManager { /** Map of classname->Declaration */ private HashMap declarationsByClass = new HashMap(); /** Map of id->Declaration */ private HashMap declarationsById = new HashMap(); /** the parent manager to which this one may delegate lookups. */ private PluginManager parent; /** * The object containing data that should only exist once for each * Digester instance. */ private PluginContext pluginContext; //------------------- constructors --------------------------------------- /** Construct a "root" PluginManager, ie one with no parent. */ public PluginManager(PluginContext r) { pluginContext = r; } /** * Construct a "child" PluginManager. When declarations are added to * a "child", they are stored within the child and do not modify the * parent, so when the child goes out of scope, those declarations * disappear. When asking a "child" to retrieve a declaration, it * delegates the search to its parent if it does not hold a matching * entry itself. *

* @param parent must be non-null. */ public PluginManager(PluginManager parent) { this.parent = parent; this.pluginContext = parent.pluginContext; } //------------------- methods -------------------------------------------- /** * Add the declaration to the set of known declarations. *

* TODO: somehow get a reference to a Digester object * so that we can really log here. Currently, all * logging is disabled from this method. * *@param decl an object representing a plugin class. */ public void addDeclaration(Declaration decl) { Log log = LogUtils.getLogger(null); boolean debug = log.isDebugEnabled(); Class pluginClass = decl.getPluginClass(); String id = decl.getId(); declarationsByClass.put(pluginClass.getName(), decl); if (id != null) { declarationsById.put(id, decl); if (debug) { log.debug( "Indexing plugin-id [" + id + "]" + " -> class [" + pluginClass.getName() + "]"); } } } /** * Return the declaration object with the specified class. * If no such plugin is known, null is returned. */ public Declaration getDeclarationByClass(String className) { Declaration decl = (Declaration) declarationsByClass.get(className); if ((decl == null) && (parent != null)) { decl = parent.getDeclarationByClass(className); } return decl; } /** * Return the declaration object with the specified id. * If no such plugin is known, null is returned. * *@param id Description of the Parameter *@return The declaration value */ public Declaration getDeclarationById(String id) { Declaration decl = (Declaration) declarationsById.get(id); if ((decl == null) && (parent != null)) { decl = parent.getDeclarationById(id); } return decl; } /** * Given a plugin class and some associated properties, scan the * list of known RuleFinder instances until one detects a source of * custom rules for this plugin (aka a RuleLoader). *

* If no source of custom rules can be found, null is returned. */ public RuleLoader findLoader(Digester digester, String id, Class pluginClass, Properties props) throws PluginException { // iterate over the list of RuleFinders, trying each one // until one of them locates a source of dynamic rules given // this specific plugin class and the associated declaration // properties. Log log = LogUtils.getLogger(digester); boolean debug = log.isDebugEnabled(); log.debug("scanning ruleFinders to locate loader.."); List ruleFinders = pluginContext.getRuleFinders(); RuleLoader ruleLoader = null; try { for(Iterator i = ruleFinders.iterator(); i.hasNext() && ruleLoader == null; ) { RuleFinder finder = (RuleFinder) i.next(); if (debug) { log.debug("checking finder of type " + finder.getClass().getName()); } ruleLoader = finder.findLoader(digester, pluginClass, props); } } catch(PluginException e) { throw new PluginException( "Unable to locate plugin rules for plugin" + " with id [" + id + "]" + ", and class [" + pluginClass.getName() + "]" + ":" + e.getMessage(), e.getCause()); } log.debug("scanned ruleFinders."); return ruleLoader; } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/plugins/RulesFactory.java0000644000175000017500000000413411226450007033251 0ustar twernertwerner/* $Id: RulesFactory.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester.plugins; import org.apache.commons.digester.Digester; import org.apache.commons.digester.Rules; /** * Whenever the scope of a plugin tag is entered, the PluginRules class * creates a new Rules instance and configures it with the appropriate * parsing rules for the plugged-in class. *

* Users of the plugins module can specify a subclass of this one to * control the creation of that Rules object. In particular, it can * set up default rules within the returned instance which are applicable * to all plugged-in classes. * * @since 1.6 */ public abstract class RulesFactory { /** * Return an instance of some Rules implementation that the plugged-in * class shall use to match its private parsing rules. *

* @param d is the digester that the returned rules object will be * associated with. * * @param pluginClass is the class that is to be configured using rules * added to the returnedobject. * * @throws PluginException if the algorithm finds a source * of rules, but there is something invalid about that source. */ public abstract Rules newRules(Digester d, Class pluginClass) throws PluginException; } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/NodeCreateRule.java0000644000175000017500000004204511226450007032012 0ustar twernertwerner/* $Id: NodeCreateRule.java 730333 2008-12-31 07:20:47Z rahul $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Attr; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; /** * A rule implementation that creates a DOM * {@link org.w3c.dom.Node Node} containing the XML at the element that matched * the rule. Two concrete types of nodes can be created by this rule: *

    *
  • the default is to create an {@link org.w3c.dom.Element Element} node. * The created element will correspond to the element that matched the rule, * containing all XML content underneath that element.
  • *
  • alternatively, this rule can create nodes of type * {@link org.w3c.dom.DocumentFragment DocumentFragment}, which will contain * only the XML content under the element the rule was trigged on.
  • *
* The created node will be normalized, meaning it will not contain text nodes * that only contain white space characters. * * *

The created Node will be pushed on Digester's object stack * when done. To use it in the context of another DOM * {@link org.w3c.dom.Document Document}, it must be imported first, using the * Document method * {@link org.w3c.dom.Document#importNode(org.w3c.dom.Node, boolean) importNode()}. *

* *

Important Note: This is implemented by replacing the SAX * {@link org.xml.sax.ContentHandler ContentHandler} in the parser used by * Digester, and resetting it when the matched element is closed. As a side * effect, rules that would match XML nodes under the element that matches * a NodeCreateRule will never be triggered by Digester, which * usually is the behavior one would expect.

* *

Note that the current implementation does not set the namespace prefixes * in the exported nodes. The (usually more important) namespace URIs are set, * of course.

* * @since Digester 1.4 */ public class NodeCreateRule extends Rule { // ---------------------------------------------------------- Inner Classes /** * The SAX content handler that does all the actual work of assembling the * DOM node tree from the SAX events. */ private class NodeBuilder extends DefaultHandler { // ------------------------------------------------------- Constructors /** * Constructor. * *

Stores the content handler currently used by Digester so it can * be reset when done, and initializes the DOM objects needed to * build the node.

* * @param doc the document to use to create nodes * @param root the root node * @throws ParserConfigurationException if the DocumentBuilderFactory * could not be instantiated * @throws SAXException if the XMLReader could not be instantiated by * Digester (should not happen) */ public NodeBuilder(Document doc, Node root) throws ParserConfigurationException, SAXException { this.doc = doc; this.root = root; this.top = root; oldContentHandler = digester.getCustomContentHandler(); } // ------------------------------------------------- Instance Variables /** * The content handler used by Digester before it was set to this * content handler. */ protected ContentHandler oldContentHandler = null; /** * Depth of the current node, relative to the element where the content * handler was put into action. */ protected int depth = 0; /** * A DOM Document used to create the various Node instances. */ protected Document doc = null; /** * The DOM node that will be pushed on Digester's stack. */ protected Node root = null; /** * The current top DOM mode. */ protected Node top = null; /** * The text content of the current top DOM node. */ protected StringBuffer topText = new StringBuffer(); // --------------------------------------------- Helper Methods /** * Appends a {@link org.w3c.dom.Text Text} node to the current node * if the content reported by the parser is not purely whitespace. */ private void addTextIfPresent() throws SAXException { if (topText.length() > 0) { String str = topText.toString(); topText.setLength(0); if (str.trim().length() > 0) { // The contained text is not *pure* whitespace, so create // a text node to hold it. Note that the "untrimmed" text // is stored in the node. try { top.appendChild(doc.createTextNode(str)); } catch (DOMException e) { throw new SAXException(e.getMessage()); } } } } // --------------------------------------------- ContentHandler Methods /** * Handle notification about text embedded within the current node. *

* An xml parser calls this when text is found. We need to ensure that this * text gets attached to the new Node we are creating - except in the case * where the only text in the node is whitespace. *

* There is a catch, however. According to the sax specification, a parser * does not need to pass all of the text content of a node in one go; it can * make multiple calls passing part of the data on each call. In particular, * when the body of an element includes xml entity-references, at least some * parsers make a separate call to this method to pass just the entity content. *

* In this method, we therefore just append the provided text to a * "current text" buffer. When the element end is found, or a child element * is found then we can check whether we have all-whitespace. See method * addTextIfPresent. * * @param ch the characters from the XML document * @param start the start position in the array * @param length the number of characters to read from the array * @throws SAXException if the DOM implementation throws an exception */ public void characters(char[] ch, int start, int length) throws SAXException { topText.append(ch, start, length); } /** * Checks whether control needs to be returned to Digester. * * @param namespaceURI the namespace URI * @param localName the local name * @param qName the qualified (prefixed) name * @throws SAXException if the DOM implementation throws an exception */ public void endElement(String namespaceURI, String localName, String qName) throws SAXException { addTextIfPresent(); try { if (depth == 0) { getDigester().setCustomContentHandler(oldContentHandler); getDigester().push(root); getDigester().endElement(namespaceURI, localName, qName); } top = top.getParentNode(); depth--; } catch (DOMException e) { throw new SAXException(e.getMessage()); } } /** * Adds a new * {@link org.w3c.dom.ProcessingInstruction ProcessingInstruction} to * the current node. * * @param target the processing instruction target * @param data the processing instruction data, or null if none was * supplied * @throws SAXException if the DOM implementation throws an exception */ public void processingInstruction(String target, String data) throws SAXException { try { top.appendChild(doc.createProcessingInstruction(target, data)); } catch (DOMException e) { throw new SAXException(e.getMessage()); } } /** * Adds a new child {@link org.w3c.dom.Element Element} to the current * node. * * @param namespaceURI the namespace URI * @param localName the local name * @param qName the qualified (prefixed) name * @param atts the list of attributes * @throws SAXException if the DOM implementation throws an exception */ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { addTextIfPresent(); try { Node previousTop = top; if ((localName == null) || (localName.length() == 0)) { top = doc.createElement(qName); } else { top = doc.createElementNS(namespaceURI, localName); } for (int i = 0; i < atts.getLength(); i++) { Attr attr = null; if ((atts.getLocalName(i) == null) || (atts.getLocalName(i).length() == 0)) { attr = doc.createAttribute(atts.getQName(i)); attr.setNodeValue(atts.getValue(i)); ((Element)top).setAttributeNode(attr); } else { attr = doc.createAttributeNS(atts.getURI(i), atts.getLocalName(i)); attr.setNodeValue(atts.getValue(i)); ((Element)top).setAttributeNodeNS(attr); } } previousTop.appendChild(top); depth++; } catch (DOMException e) { throw new SAXException(e.getMessage()); } } } // ----------------------------------------------------------- Constructors /** * Default constructor. Creates an instance of this rule that will create a * DOM {@link org.w3c.dom.Element Element}. */ public NodeCreateRule() throws ParserConfigurationException { this(Node.ELEMENT_NODE); } /** * Constructor. Creates an instance of this rule that will create a DOM * {@link org.w3c.dom.Element Element}, but lets you specify the JAXP * DocumentBuilder that should be used when constructing the * node tree. * * @param documentBuilder the JAXP DocumentBuilder to use */ public NodeCreateRule(DocumentBuilder documentBuilder) { this(Node.ELEMENT_NODE, documentBuilder); } /** * Constructor. Creates an instance of this rule that will create either a * DOM {@link org.w3c.dom.Element Element} or a DOM * {@link org.w3c.dom.DocumentFragment DocumentFragment}, depending on the * value of the nodeType parameter. * * @param nodeType the type of node to create, which can be either * {@link org.w3c.dom.Node#ELEMENT_NODE Node.ELEMENT_NODE} or * {@link org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE Node.DOCUMENT_FRAGMENT_NODE} * @throws IllegalArgumentException if the node type is not supported */ public NodeCreateRule(int nodeType) throws ParserConfigurationException { this(nodeType, DocumentBuilderFactory.newInstance().newDocumentBuilder()); } /** * Constructor. Creates an instance of this rule that will create either a * DOM {@link org.w3c.dom.Element Element} or a DOM * {@link org.w3c.dom.DocumentFragment DocumentFragment}, depending on the * value of the nodeType parameter. This constructor lets you * specify the JAXP DocumentBuilder that should be used when * constructing the node tree. * * @param nodeType the type of node to create, which can be either * {@link org.w3c.dom.Node#ELEMENT_NODE Node.ELEMENT_NODE} or * {@link org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE Node.DOCUMENT_FRAGMENT_NODE} * @param documentBuilder the JAXP DocumentBuilder to use * @throws IllegalArgumentException if the node type is not supported */ public NodeCreateRule(int nodeType, DocumentBuilder documentBuilder) { if (!((nodeType == Node.DOCUMENT_FRAGMENT_NODE) || (nodeType == Node.ELEMENT_NODE))) { throw new IllegalArgumentException( "Can only create nodes of type DocumentFragment and Element"); } this.nodeType = nodeType; this.documentBuilder = documentBuilder; } // ----------------------------------------------------- Instance Variables /** * The JAXP DocumentBuilder to use. */ private DocumentBuilder documentBuilder = null; /** * The type of the node that should be created. Must be one of the * constants defined in {@link org.w3c.dom.Node Node}, but currently only * {@link org.w3c.dom.Node#ELEMENT_NODE Node.ELEMENT_NODE} and * {@link org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE Node.DOCUMENT_FRAGMENT_NODE} * are allowed values. */ private int nodeType = Node.ELEMENT_NODE; // ----------------------------------------------------------- Rule Methods /** * When this method fires, the digester is told to forward all SAX * ContentHandler events to the builder object, resulting in a DOM being * built instead of normal digester rule-handling occurring. When the * end of the current xml element is encountered, the original content * handler is restored (expected to be NULL, allowing normal Digester * operations to continue). * * @param namespaceURI the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param attributes The attribute list of this element * @throws Exception indicates a JAXP configuration problem */ public void begin(String namespaceURI, String name, Attributes attributes) throws Exception { Document doc = documentBuilder.newDocument(); NodeBuilder builder = null; if (nodeType == Node.ELEMENT_NODE) { Element element = null; if (getDigester().getNamespaceAware()) { element = doc.createElementNS(namespaceURI, name); for (int i = 0; i < attributes.getLength(); i++) { element.setAttributeNS(attributes.getURI(i), attributes.getQName(i), attributes.getValue(i)); } } else { element = doc.createElement(name); for (int i = 0; i < attributes.getLength(); i++) { element.setAttribute(attributes.getQName(i), attributes.getValue(i)); } } builder = new NodeBuilder(doc, element); } else { builder = new NodeBuilder(doc, doc.createDocumentFragment()); } // the NodeBuilder constructor has already saved the original // value of the digester's custom content handler (expected to // be null, but we save it just in case). So now we just // need to tell the digester to forward events to the builder. getDigester().setCustomContentHandler(builder); } /** * Pop the Node off the top of the stack. */ public void end() throws Exception { digester.pop(); } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootlibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/AbstractObjectCreationFactory.javalibcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/AbstractObjectCreationFacto0000644000175000017500000000447511226450007033572 0ustar twernertwerner/* $Id: AbstractObjectCreationFactory.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; /** *

Abstract base class for ObjectCreationFactory * implementations.

*/ abstract public class AbstractObjectCreationFactory implements ObjectCreationFactory { // ----------------------------------------------------- Instance Variables /** * The associated Digester instance that was set up by * {@link FactoryCreateRule} upon initialization. */ protected Digester digester = null; // --------------------------------------------------------- Public Methods /** *

Factory method called by {@link FactoryCreateRule} to supply an * object based on the element's attributes. * * @param attributes the element's attributes * * @throws Exception any exception thrown will be propagated upwards */ public abstract Object createObject(Attributes attributes) throws Exception; /** *

Returns the {@link Digester} that was set by the * {@link FactoryCreateRule} upon initialization. */ public Digester getDigester() { return (this.digester); } /** *

Set the {@link Digester} to allow the implementation to do logging, * classloading based on the digester's classloader, etc. * * @param digester parent Digester object */ public void setDigester(Digester digester) { this.digester = digester; } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/FactoryCreateRule.java0000644000175000017500000004253711226450007032542 0ustar twernertwerner/* $Id: FactoryCreateRule.java 728882 2008-12-23 06:27:54Z rahul $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; import org.apache.commons.collections.ArrayStack; /** *

Rule implementation that uses an {@link ObjectCreationFactory} to create * a new object which it pushes onto the object stack. When the element is * complete, the object will be popped.

* *

This rule is intended in situations where the element's attributes are * needed before the object can be created. A common senario is for the * ObjectCreationFactory implementation to use the attributes as parameters * in a call to either a factory method or to a non-empty constructor. */ public class FactoryCreateRule extends Rule { // ----------------------------------------------------------- Fields /** Should exceptions thrown by the factory be ignored? */ private boolean ignoreCreateExceptions; /** Stock to manage */ private ArrayStack exceptionIgnoredStack; // ----------------------------------------------------------- Constructors /** * Construct a factory create rule that will use the specified * class name to create an {@link ObjectCreationFactory} which will * then be used to create an object and push it on the stack. * * @param digester The associated Digester * @param className Java class name of the object creation factory class * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #FactoryCreateRule(String className)} instead. */ public FactoryCreateRule(Digester digester, String className) { this(className); } /** * Construct a factory create rule that will use the specified * class to create an {@link ObjectCreationFactory} which will * then be used to create an object and push it on the stack. * * @param digester The associated Digester * @param clazz Java class name of the object creation factory class * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #FactoryCreateRule(Class clazz)} instead. */ public FactoryCreateRule(Digester digester, Class clazz) { this(clazz); } /** * Construct a factory create rule that will use the specified * class name (possibly overridden by the specified attribute if present) * to create an {@link ObjectCreationFactory}, which will then be used * to instantiate an object instance and push it onto the stack. * * @param digester The associated Digester * @param className Default Java class name of the factory class * @param attributeName Attribute name which, if present, contains an * override of the class name of the object creation factory to create. * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #FactoryCreateRule(String className, String attributeName)} instead. */ public FactoryCreateRule(Digester digester, String className, String attributeName) { this(className, attributeName); } /** * Construct a factory create rule that will use the specified * class (possibly overridden by the specified attribute if present) * to create an {@link ObjectCreationFactory}, which will then be used * to instantiate an object instance and push it onto the stack. * * @param digester The associated Digester * @param clazz Default Java class name of the factory class * @param attributeName Attribute name which, if present, contains an * override of the class name of the object creation factory to create. * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #FactoryCreateRule(Class clazz, String attributeName)} instead. */ public FactoryCreateRule(Digester digester, Class clazz, String attributeName) { this(clazz, attributeName); } /** * Construct a factory create rule using the given, already instantiated, * {@link ObjectCreationFactory}. * * @param digester The associated Digester * @param creationFactory called on to create the object. * * @deprecated The digester instance is now set in the {@link Digester#addRule} method. * Use {@link #FactoryCreateRule(ObjectCreationFactory creationFactory)} instead. */ public FactoryCreateRule(Digester digester, ObjectCreationFactory creationFactory) { this(creationFactory); } /** *

Construct a factory create rule that will use the specified * class name to create an {@link ObjectCreationFactory} which will * then be used to create an object and push it on the stack.

* *

Exceptions thrown during the object creation process will be propagated.

* * @param className Java class name of the object creation factory class */ public FactoryCreateRule(String className) { this(className, false); } /** *

Construct a factory create rule that will use the specified * class to create an {@link ObjectCreationFactory} which will * then be used to create an object and push it on the stack.

* *

Exceptions thrown during the object creation process will be propagated.

* * @param clazz Java class name of the object creation factory class */ public FactoryCreateRule(Class clazz) { this(clazz, false); } /** *

Construct a factory create rule that will use the specified * class name (possibly overridden by the specified attribute if present) * to create an {@link ObjectCreationFactory}, which will then be used * to instantiate an object instance and push it onto the stack.

* *

Exceptions thrown during the object creation process will be propagated.

* * @param className Default Java class name of the factory class * @param attributeName Attribute name which, if present, contains an * override of the class name of the object creation factory to create. */ public FactoryCreateRule(String className, String attributeName) { this(className, attributeName, false); } /** *

Construct a factory create rule that will use the specified * class (possibly overridden by the specified attribute if present) * to create an {@link ObjectCreationFactory}, which will then be used * to instantiate an object instance and push it onto the stack.

* *

Exceptions thrown during the object creation process will be propagated.

* * @param clazz Default Java class name of the factory class * @param attributeName Attribute name which, if present, contains an * override of the class name of the object creation factory to create. */ public FactoryCreateRule(Class clazz, String attributeName) { this(clazz, attributeName, false); } /** *

Construct a factory create rule using the given, already instantiated, * {@link ObjectCreationFactory}.

* *

Exceptions thrown during the object creation process will be propagated.

* * @param creationFactory called on to create the object. */ public FactoryCreateRule(ObjectCreationFactory creationFactory) { this(creationFactory, false); } /** * Construct a factory create rule that will use the specified * class name to create an {@link ObjectCreationFactory} which will * then be used to create an object and push it on the stack. * * @param className Java class name of the object creation factory class * @param ignoreCreateExceptions if true, exceptions thrown by the object * creation factory * will be ignored. */ public FactoryCreateRule(String className, boolean ignoreCreateExceptions) { this(className, null, ignoreCreateExceptions); } /** * Construct a factory create rule that will use the specified * class to create an {@link ObjectCreationFactory} which will * then be used to create an object and push it on the stack. * * @param clazz Java class name of the object creation factory class * @param ignoreCreateExceptions if true, exceptions thrown by the * object creation factory * will be ignored. */ public FactoryCreateRule(Class clazz, boolean ignoreCreateExceptions) { this(clazz, null, ignoreCreateExceptions); } /** * Construct a factory create rule that will use the specified * class name (possibly overridden by the specified attribute if present) * to create an {@link ObjectCreationFactory}, which will then be used * to instantiate an object instance and push it onto the stack. * * @param className Default Java class name of the factory class * @param attributeName Attribute name which, if present, contains an * override of the class name of the object creation factory to create. * @param ignoreCreateExceptions if true, exceptions thrown by the object * creation factory will be ignored. */ public FactoryCreateRule( String className, String attributeName, boolean ignoreCreateExceptions) { this.className = className; this.attributeName = attributeName; this.ignoreCreateExceptions = ignoreCreateExceptions; } /** * Construct a factory create rule that will use the specified * class (possibly overridden by the specified attribute if present) * to create an {@link ObjectCreationFactory}, which will then be used * to instantiate an object instance and push it onto the stack. * * @param clazz Default Java class name of the factory class * @param attributeName Attribute name which, if present, contains an * override of the class name of the object creation factory to create. * @param ignoreCreateExceptions if true, exceptions thrown by the object * creation factory will be ignored. */ public FactoryCreateRule( Class clazz, String attributeName, boolean ignoreCreateExceptions) { this(clazz.getName(), attributeName, ignoreCreateExceptions); } /** * Construct a factory create rule using the given, already instantiated, * {@link ObjectCreationFactory}. * * @param creationFactory called on to create the object. * @param ignoreCreateExceptions if true, exceptions thrown by the object * creation factory will be ignored. */ public FactoryCreateRule( ObjectCreationFactory creationFactory, boolean ignoreCreateExceptions) { this.creationFactory = creationFactory; this.ignoreCreateExceptions = ignoreCreateExceptions; } // ----------------------------------------------------- Instance Variables /** * The attribute containing an override class name if it is present. */ protected String attributeName = null; /** * The Java class name of the ObjectCreationFactory to be created. * This class must have a no-arguments constructor. */ protected String className = null; /** * The object creation factory we will use to instantiate objects * as required based on the attributes specified in the matched XML * element. */ protected ObjectCreationFactory creationFactory = null; // --------------------------------------------------------- Public Methods /** * Process the beginning of this element. * * @param attributes The attribute list of this element */ public void begin(String namespace, String name, Attributes attributes) throws Exception { if (ignoreCreateExceptions) { if (exceptionIgnoredStack == null) { exceptionIgnoredStack = new ArrayStack(); } try { Object instance = getFactory(attributes).createObject(attributes); if (digester.log.isDebugEnabled()) { digester.log.debug("[FactoryCreateRule]{" + digester.match + "} New " + (instance == null ? "null object" : instance.getClass().getName())); } digester.push(instance); exceptionIgnoredStack.push(Boolean.FALSE); } catch (Exception e) { // log message and error if (digester.log.isInfoEnabled()) { digester.log.info("[FactoryCreateRule] Create exception ignored: " + ((e.getMessage() == null) ? e.getClass().getName() : e.getMessage())); if (digester.log.isDebugEnabled()) { digester.log.debug("[FactoryCreateRule] Ignored exception:", e); } } exceptionIgnoredStack.push(Boolean.TRUE); } } else { Object instance = getFactory(attributes).createObject(attributes); if (digester.log.isDebugEnabled()) { digester.log.debug("[FactoryCreateRule]{" + digester.match + "} New " + (instance == null ? "null object" : instance.getClass().getName())); } digester.push(instance); } } /** * Process the end of this element. */ public void end(String namespace, String name) throws Exception { // check if object was created // this only happens if an exception was thrown and we're ignoring them if ( ignoreCreateExceptions && exceptionIgnoredStack != null && !(exceptionIgnoredStack.empty())) { if (((Boolean) exceptionIgnoredStack.pop()).booleanValue()) { // creation exception was ignored // nothing was put onto the stack if (digester.log.isTraceEnabled()) { digester.log.trace("[FactoryCreateRule] No creation so no push so no pop"); } return; } } Object top = digester.pop(); if (digester.log.isDebugEnabled()) { digester.log.debug("[FactoryCreateRule]{" + digester.match + "} Pop " + top.getClass().getName()); } } /** * Clean up after parsing is complete. */ public void finish() throws Exception { if (attributeName != null) { creationFactory = null; } } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("FactoryCreateRule["); sb.append("className="); sb.append(className); sb.append(", attributeName="); sb.append(attributeName); if (creationFactory != null) { sb.append(", creationFactory="); sb.append(creationFactory); } sb.append("]"); return (sb.toString()); } // ------------------------------------------------------ Protected Methods /** * Return an instance of our associated object creation factory, * creating one if necessary. * * @param attributes Attributes passed to our factory creation element * * @exception Exception if any error occurs */ protected ObjectCreationFactory getFactory(Attributes attributes) throws Exception { if (creationFactory == null) { String realClassName = className; if (attributeName != null) { String value = attributes.getValue(attributeName); if (value != null) { realClassName = value; } } if (digester.log.isDebugEnabled()) { digester.log.debug("[FactoryCreateRule]{" + digester.match + "} New factory " + realClassName); } Class clazz = digester.getClassLoader().loadClass(realClassName); creationFactory = (ObjectCreationFactory) clazz.newInstance(); creationFactory.setDigester(digester); } return (creationFactory); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/AbstractRulesImpl.java0000644000175000017500000001346711226450007032557 0ustar twernertwerner/* $Id: AbstractRulesImpl.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.List; /** *

AbstractRuleImpl provides basic services for Rules implementations. * Extending this class should make it easier to create a Rules implementation.

* *

AbstractRuleImpl manages the Digester * and namespaceUri properties. * If the subclass overrides {@link #registerRule} (rather than {@link #add}), * then the Digester and namespaceURI of the Rule * will be set correctly before it is passed to registerRule. * The subclass can then perform whatever it needs to do to register the rule.

* * @since 1.5 */ abstract public class AbstractRulesImpl implements Rules { // ------------------------------------------------------------- Fields /** Digester using this Rules implementation */ private Digester digester; /** Namespace uri to assoicate with subsequent Rule's */ private String namespaceURI; // ------------------------------------------------------------- Properties /** * Return the Digester instance with which this Rules instance is * associated. */ public Digester getDigester() { return digester; } /** * Set the Digester instance with which this Rules instance is associated. * * @param digester The newly associated Digester instance */ public void setDigester(Digester digester) { this.digester = digester; } /** * Return the namespace URI that will be applied to all subsequently * added Rule objects. */ public String getNamespaceURI() { return namespaceURI; } /** * Set the namespace URI that will be applied to all subsequently * added Rule objects. * * @param namespaceURI Namespace URI that must match on all * subsequently added rules, or null for matching * regardless of the current namespace URI */ public void setNamespaceURI(String namespaceURI) { this.namespaceURI = namespaceURI; } // --------------------------------------------------------- Public Methods /** * Registers a new Rule instance matching the specified pattern. * This implementation sets the Digester and the * namespaceURI on the Rule before calling {@link #registerRule}. * * @param pattern Nesting pattern to be matched for this Rule * @param rule Rule instance to be registered */ public void add(String pattern, Rule rule) { // set up rule if (this.digester != null) { rule.setDigester(this.digester); } if (this.namespaceURI != null) { rule.setNamespaceURI(this.namespaceURI); } registerRule(pattern, rule); } /** * Register rule at given pattern. * The the Digester and namespaceURI properties of the given Rule * can be assumed to have been set properly before this method is called. * * @param pattern Nesting pattern to be matched for this Rule * @param rule Rule instance to be registered */ abstract protected void registerRule(String pattern, Rule rule); /** * Clear all existing Rule instance registrations. */ abstract public void clear(); /** * Return a List of all registered Rule instances that match the specified * nesting pattern, or a zero-length List if there are no matches. If more * than one Rule instance matches, they must be returned * in the order originally registered through the add() * method. * * @param pattern Nesting pattern to be matched * * @deprecated Call match(namespaceURI,pattern) instead. */ public List match(String pattern) { return match(namespaceURI, pattern); } /** * Return a List of all registered Rule instances that match the specified * nesting pattern, or a zero-length List if there are no matches. If more * than one Rule instance matches, they must be returned * in the order originally registered through the add() * method. * * @param namespaceURI Namespace URI for which to select matching rules, * or null to match regardless of namespace URI * @param pattern Nesting pattern to be matched */ abstract public List match(String namespaceURI, String pattern); /** * Return a List of all registered Rule instances, or a zero-length List * if there are no registered Rule instances. If more than one Rule * instance has been registered, they must be returned * in the order originally registered through the add() * method. */ abstract public List rules(); } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/ObjectParamRule.java0000644000175000017500000001017511226450007032167 0ustar twernertwerner/* $Id: ObjectParamRule.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; /** *

Rule implementation that saves a parameter for use by a surrounding * CallMethodRule.

* *

This parameter may be: *

    *
  • an arbitrary Object defined programatically, assigned when the element * pattern associated with the Rule is matched. See * {@link #ObjectParamRule(int paramIndex, Object param)}. *
  • an arbitrary Object defined programatically, assigned if the element * pattern AND specified attribute name are matched. See * {@link #ObjectParamRule(int paramIndex, String attributeName, Object param)}. *
*

* * @since 1.4 */ public class ObjectParamRule extends Rule { // ----------------------------------------------------------- Constructors /** * Construct a "call parameter" rule that will save the given Object as * the parameter value. * * @param paramIndex The zero-relative parameter number * @param param the parameter to pass along */ public ObjectParamRule(int paramIndex, Object param) { this(paramIndex, null, param); } /** * Construct a "call parameter" rule that will save the given Object as * the parameter value, provided that the specified attribute exists. * * @param paramIndex The zero-relative parameter number * @param attributeName The name of the attribute to match * @param param the parameter to pass along */ public ObjectParamRule(int paramIndex, String attributeName, Object param) { this.paramIndex = paramIndex; this.attributeName = attributeName; this.param = param; } // ----------------------------------------------------- Instance Variables /** * The attribute which we are attempting to match */ protected String attributeName = null; /** * The zero-relative index of the parameter we are saving. */ protected int paramIndex = 0; /** * The parameter we wish to pass to the method call */ protected Object param = null; // --------------------------------------------------------- Public Methods /** * Process the start of this element. * * @param attributes The attribute list for this element */ public void begin(String namespace, String name, Attributes attributes) throws Exception { Object anAttribute = null; Object parameters[] = (Object[]) digester.peekParams(); if (attributeName != null) { anAttribute = attributes.getValue(attributeName); if(anAttribute != null) { parameters[paramIndex] = param; } // note -- if attributeName != null and anAttribute == null, this rule // will pass null as its parameter! }else{ parameters[paramIndex] = param; } } /** * Render a printable version of this Rule. */ public String toString() { StringBuffer sb = new StringBuffer("ObjectParamRule["); sb.append("paramIndex="); sb.append(paramIndex); sb.append(", attributeName="); sb.append(attributeName); sb.append(", param="); sb.append(param); sb.append("]"); return (sb.toString()); } } libcommons-digester-java-1.8.1.orig/src/java/org/apache/commons/digester/Substitutor.java0000644000175000017500000000541711226450007031522 0ustar twernertwerner/* $Id: Substitutor.java 471661 2006-11-06 08:09:25Z skitching $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import org.xml.sax.Attributes; /** *

(Logical) Interface for substitution strategies. * (It happens to be implemented as a Java abstract class to allow * future additions to be made without breaking backwards compatibility.) *

*

* Usage: When {@link Digester#setSubstitutor} is set, Digester * calls the methods in this interface to create substitute values which will * be passed into the Rule implementations. * Of course, it is perfectly acceptable for implementations not to make * substitutions and simply return the inputs. *

*

Different strategies are supported for attributes and body text.

* * @since 1.6 */ public abstract class Substitutor { /** *

Substitutes the attributes (before they are passed to the * Rule implementations's).

* *

Digester will only call this method a second time * once the original Attributes instance can be safely reused. * The implementation is therefore free to reuse the same Attributes instance * for all calls.

* * @param attributes the Attributes passed into Digester by the SAX parser, * not null (but may be empty) * @return Attributes to be passed to the Rule implementations. * This method may pass back the Attributes passed in. * Not null but possibly empty. */ public abstract Attributes substitute(Attributes attributes); /** * Substitutes for the body text. * This method may substitute values into the body text of the * elements that Digester parses. * * @param bodyText the body text (as passed to Digester) * @return the body text to be passed to the Rule implementations */ public abstract String substitute(String bodyText); } libcommons-digester-java-1.8.1.orig/src/conf/0000755000175000017500000000000011226450007021014 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/conf/MANIFEST.MF0000644000175000017500000000066011226450007022450 0ustar twernertwernerManifest-Version: 1.0 Package: org.apache.commons.digester Extension-Name: commons-digester Specification-Title: Rule based XML->Java object mapping module Specification-Vendor: The Apache Software Foundation Implementation-Title: org.apache.commons.digester Implementation-Vendor: The Apache Software Foundation Implementation-Version: 1.8.1 Implementation-Vendor-Id: org.apache X-Compile-Source-JDK: 1.2 X-Compile-Target-JDK: 1.2 libcommons-digester-java-1.8.1.orig/src/assembly/0000755000175000017500000000000011226450007021706 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/assembly/bin.xml0000644000175000017500000000273411226450007023206 0ustar twernertwerner bin tar.gz zip false LICENSE* NOTICE* RELEASE-NOTES.txt target *.jar target/site/apidocs apidocs libcommons-digester-java-1.8.1.orig/src/assembly/src.xml0000644000175000017500000000320011226450007023212 0ustar twernertwerner src tar.gz zip ${project.artifactId}-1.8.1-src LICENSE* NOTICE* pom.xml project.xml project.properties maven.xml build.xml build.properties.sample checkstyle.xml file-header.txt RELEASE-NOTES* src xdocs libcommons-digester-java-1.8.1.orig/src/media/0000755000175000017500000000000011226450007021146 5ustar twernertwernerlibcommons-digester-java-1.8.1.orig/src/media/logo.xcf0000644000175000017500000005230111226450007022611 0ustar twernertwernergimp xcf file,dBB/ gimp-commentCreated with The GIMP &5;S., Text Layer#2     0W,s u ,    8/qU8+UUU*U8,U-U8U/U9U9U9U9U2UUU 8 U8qUq q8 UqU8qU88UUqq8U88UUU8UUqqUU8qUUUUUUU8UUUU8UUUUq8UqUU8UUU8UUUU 8UU8UU UU8 UUqUUqU8UUUqqqUUUq  8UU 8 8UU8U Uq, 8q8*U U)8q U)U 8(8 ƍ)Uq 8*qUUq+U .8 18U    k8<U;;:9qUU U8UU8U8qq8qq8UUUqUUUUUU8qUUUUqU8UUUqUqUUq8UqUUq U UUqUU8UUU8U8U UUU8UUq UUU8Uqq8UUq8q88qUqqUƪUq88qUqUUq88UUU UU U8 88U888UqUUUUUq8UUUUUUUUU qU U UUUUUU888q8 8UU8K% <Drop-Shadow#2h     - 7< S%&< k!/( %    #    ! ""  )./+#   )1550( ,8?@;0#   -:EKKD7)'6DNOH;+(9JYa`WG5%+@;2&  %+.136:?CFFC=5)17:;;?FTf{nS:+%(1>KSUOC3# ",5:<==@EMU[^[TJ  ,7@DDA><>FTg|oS<-)/4..6E[toS<.+3D[p}iP7#(;N]dbXKA>ESgzr> $6HW_^TF7+$$+;RlmR;,)1CZrnT:% 1F\kqk\K=8=Lbwt-AUchbTB0""3Je}lQ9*&.@XqqV<'%8Ofvzr`K;37E[rr "6LamoeS=*,D_xkP8(#*VkvtgQ:%(?[ujO7&!'9QlqW=()=Wo|iQ=11=Pfx~xg .F_s}yiQ8# &=XsiO6% &7PjqW=(';TmnWC75>Obqwp_2Key}kR8" %'&=XrjO6%%6NiqW<&(( 0BUcklhaYRLGA:1( !6Nh~xfUICDM]rv\E3,/>UmtZ@*$5I\iqqmg`YTNHA9/'+AZptf[TSYfvt\F6/3AVnt[B,)4 !4I_r~zqg`^ait}lXD615BVk}pZB.!!.AWkz|wsplgaZPE &8K]luxvqjd``dkrvul^M=2/4@ReszviU@."$1EZn||zwtoi`U(7GU`fhfb]XVWZ]_]VJ>2+*/:IXdjf\L;,#!'4G[ly~|{zywupj` %2>HOSSQMHEDEFFD>6-&""'0<7/'"!%0>N\ehfb^[YYZ[]_aa^ "%'&%" #'((%! )7GV`db[RKFDCDFIMPST    .?Q`hhaVJ@95456:>CHJ   !2F[ksqgYJ>61//038=AC  "5Lbt|{qcTG=743469=>?>;4-(*4F^wqYC1$&,2L<.# %-5<@BCFLS]ejiaTC3'"%.:ELMJFBABDEB<4--6G`ypWA0$#+3:?WD4*&*26/-5F]wkR<,#!%.8BHJ\G7.-4?KSVSNIGKTap}ubN?8;FU`eaXLB<<>AA<4-+2BZt~eL6("$,9FQUU]G814>LYaa[SKGIQ^o}|kWF?BN^joj_QD<9:;;70)(.>Vpx`F1%"(5ET^a^[F73:HXfljaVLGGNZix{kXIBERbpwtiZLA;8751*%$+;Smu\B.##-=QakleWC76@QcquqfXMFEJT`mvwqcSE?CPbr{|tgYMD=83-&! (9QksZ@-$&3F[lusjR?68EXly|tgWJB@BIS\ce_TG<8EVmu\C2+2D\tm!/E`xnV?,!&*/4:AJWeto[KDHXnx`G5.3C[sv+A[tzdN:+"#%&&%&(,02346>AGOTUPE8,&)4EZkvyrfVG;55;HXgtSD5)##*6ET`immje^UKA6+"#-6=@?=;;=AEGD>4) '6GWbfbYL>3+(,5BP]XJ:,!&0 $ $ $           "'+/120,&  &)++E,.132-% */49>BEEA:0&(2:@BA@ACFGE?4'7;?DJQVYWPE7+# #,9FRY[YVUVXZWNA0! ACEJQZcijeZJ;0+.9IZhprniecdd`WH6% JHGKR]jtzwm\K<58CUiy~umhfd`VH6$ PKGIP\kyzjWF<=I\rylc^ZUM?0  UMGGMYiyr^K@@K^uveXOID=2&ZOHFKVdtq^K?>I]up[I>61+# ]PHEHP\itxthWF;;FZrhP<.%  ]ND@AGOYaebXJ=45AVoyaG1" YJ>87:@FLNKD:1,0>Tmu\A+ TB5-*+.25761+&%+;RksY>' Q<-$!#%%#  )9QjrX<% Q:)(9QjrW<$ U>*):QkrW<$ _G2#"+;RkrW<$ lU@/$"$%%$&.=TlsX=% zfSB6.++,./.,)*0?UntZ?' wfWKB=;;:850++2AVnu\A) vj_VPKHD>81,+2AWnu]C,vmd]VOH?6.))1@Uk}r\D.{~|wph`WND:0($%.=Pdt{xkXB. flnlg`XOE:/&  )6GXekh^N<+ MTWWTOH?6,#!-:GQUTL@2% 5;>?>:4-&"+4;>=80&  %')(%! #')(%          S) Text Layer      &&5#5/&*.38qU8Uq8q8q q UU88UU8qUqUUUqUUUqUUq8U8 UU 8q8U8 q   8U 8U UU UU UU 8UU U 8 88 U q 8888 q8 q8qUUUUUqU UUUU U 8qUq q8UqUU8qU 8q8U8 8UqU8qqq88qqUUqUUUqƪUqUUUU8Uqq q8UUU 88UUqq UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU qUq qUqU8qU88qU8UƍUUUU8q qq q8  8qUU88qU 88 8UU UUUU8U8UUUUUUUUU8q 8UqUUU UUUUU 8UUUU UUUUU UUUU UUUU UUUUUU UUUUUU UUUUU UUUUUU UUUUU8 UUUU qUUUUq UUUUq8UUUUUUUUqUqU88UUqqU8q8qUU 8Uq8 q 8VVV UU ⪪88888Uqqq88  q 8 qU  qU qq8qƪq888UUk 5$ Drop-ShadowD       5$5SS"$6>!FyN   L          &.49<=<80% &-38<>=:4," & +7BJOTX\_^WI7%   -:CJOSWZ]]ZQE5% #1@L &8HTZ\\]bkwu_D*  )beD( ;eQ*=e]9 &BhoD$*Ky0V}zT0 )LtrI'.TwK'*Mzȳ\3 >m BmoD"  3QlxoV7 >ji<  8dŢrC  6f+Sd8 0BJE5"'M~_2)QϴR) 3c5b\0  $" /[ȷX, CuԿ^1 2b ?oX,   6e̸V*8iƝh8 2b !GxW+ ;lѺW+1_ʣn<2b $L¶Z- >pԾZ-,Yʤp>2b%NǼa3 >o×a2*UȢn<2b %Mßl<  ;kɠj:)TÝh8 2b "I|ʬ}K& 6cΪvD +Vʼ_1 2b Bsѻa7  0YҴP(.[ıS) 2b8gɨ{O-  !,/*)K|Ӿ`35cuE! 2b-WӾpJ. )7@?2" =iŢrC!  @n`6 2b !EtϷpQ;-%#%,7EPQF2-SȰX1 *NzuJ&3c3[ͷgVLHJQZabXC+ m*Krƻs[@' -Lo|aI:35>Ocu|t]@% )Jw .MpĽw^C*  -IgveWPPV_hleT<% !8X~ -Gd~oX?)  )?Vjvyume`]][SF4!  )A\z &:Napz~|uiYG4"   1AOY]][WSNH@5( (<82+# +7AIM !##      !$&     ?   @         !! )   ! )&(4>DE@6(  ,8AFFA6) !(*% ,8AFD=2# PI:+%*8HYgqtoaM6#,=N^ksuoaM5  (6EOOE4'%-mѽ`4  #5YʰW2 3Yʹ]6ĶnI, 6V~ƺuO1 6U}ĶpL2%$.Deb?&&AdıhEmO5!(>ZysU:&)>ZxnR<0/9LgcF-.GeiLzm[F1!'9Nbs~|q_K7&'9Nbs}zm[I90/7EWiw~vgT?,,@ViwykXDNLF<1$)5@HMOMG?4')5@HMNLF=3*%$)1;DJNNJC9-  -:DJNNKE;0&%# !$&&$  !$&&%# #%&&%" "%&&%#         >   A      "       "$0;CGE>2#  #+17;=><7/&  $+.+"%1$ .Hfmceo|acgn{a6 %A`y}kTA516CXra?$1MpʸnfejtOHEHTlwG"  <`yZ='&9Uw^9)DiãfTJHN_z6)$&1JpdzU+ 1WjD' 7Z~R.4ZuR:,'+;Y 3Zȼa3 #FrY1 !@kɽk? (M~Һb<#"@l&Lžj:1ZyJ$,T˰Q*"ExͱR+  1^  Fxţp??mo?  Bsҿb5 CuɫzH" +W  CvƦsA &K}i85cɣp? CuȨvD )T  BuƦtB",UÜf6,WέzG$!CuǧuB (R  BuǧtC#0[ƞg6&NвL'!CuǧuB (R  BuǧtC#2^ʢl: "H|гN("CuǧuB (R  BuǧuC#1^ͨs@  ExαL'!CuǧuB (R  BuǧuC#/YѰ}I"  DwʬzH$!CuǧuB (R  BuǧuC"*RԸS) FyĢp@ CuǧuB (R  BuǧuC!$Hza3 $K~ûc6 BuǧuB (R  BuǧuB 43:H\p|yfJ-  1X˰X3 "@k*'@cb@& &@]x{j[QOS\eki[E- "=b­c@'/Nu3!/GddG. "7Odsywpha^]]\WK:(  (CcdG/#7Sr0!-@Uhw~~vhU@-+=94.& *7CJNNJC:.!%2>G "%&&%"    "%&&%"  $      ?       -  &-13321/,)! U>' )8BGHHJKNNI<) eE( 1FUZWRNMRZeljX< ĩf?  0LdmgXI@?GVj{~kI'W/&Fh}|hL6)'0B\upN*ɾm> 4[d@%+EaqhK)ȭ~K$ ?kf=  /I[XB%̷U* !EtsI( 3CE5 ̽\. Etc@'".0& `0 >leH1!a12\sXA.!b2%GrµlS=+ b2 0S{fL5" ̶b2 5UxȽx[?' b24PnŸeD(b2 .D^zf@"b2 %7MgĬ[3b2 )-$$,=XupM+ƾ}U4$@b|yeQB;;BPbquiP3 xX;$3Mcli_TLHINV^`YH2|}sbL5""3AHIGDCCEHJJD9*MOMH@4&"&()+-/121.' &$!     )p8 ,d Background     S,dSTTT,dT)T5TATMTYTeTqT}TT               0002K% libcommons-digester-java-1.8.1.orig/build.xml0000644000175000017500000002552211226450007021127 0ustar twernertwerner libcommons-digester-java-1.8.1.orig/build.properties.sample0000644000175000017500000000455611226450007024007 0ustar twernertwerner# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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. ########################################################################## # Sample Ant build.properties file # # This setup assumes dependent jars are in a local maven 1 repository. # However the jars are located, the properties ending in ".jar" need # expand to full paths to the jars. # # Copy this file (build.properties.sample) to "build.properties" then edit # entries below as appropriate before running any Ant commands. ########################################################################## # Repository base path repository=${user.home}/.maven/repository # JUnit junit.home=${repository}/junit/jars junit.jar=${junit.home}/junit-3.8.1.jar # XML parser # When using java 1.3 or earlier, JAXP is not included in the standard # libraries, so external jar files are required. If you are using Java # 1.4 or later, you can omit these libraries jaxp.parser.home=${repository}/xerces/jars jaxp.parser.jar=${jaxp.parser.home}/xerces-2.0.2.jar jaxp.jaxp.home=${repository}/xml-apis/jars jaxp.jaxp.jar=${jaxp.jaxp.home}/xml-apis-1.0.b2.jar # Commons logging commons-logging.home=${repository}/commons-logging/jars commons-logging.jar=${commons-logging.home}/commons-logging-1.1.1.jar # Commons beanutils commons-beanutils.home=${repository}/commons-beanutils/jars commons-beanutils.jar=${commons-beanutils.home}/commons-beanutils-1.8.0.jar # The digester tests output logging information (including Exceptions) # which can often be confusing to new developers. # This output is suppressed by default but can be re-enabled by #suppressLogOutputDuringTests=false suppressLogOutputDuringTests=true libcommons-digester-java-1.8.1.orig/file-header.txt0000644000175000017500000000145511226450007022213 0ustar twernertwerner/* $Id$ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ libcommons-digester-java-1.8.1.orig/NOTICE.txt0000644000175000017500000000026111226450007021021 0ustar twernertwernerApache Commons Digester Copyright 2001-2008 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). libcommons-digester-java-1.8.1.orig/pom.xml0000644000175000017500000002276011226450007020624 0ustar twernertwerner org.apache.commons commons-parent 11 4.0.0 Commons Digester commons-digester commons-digester 1.8.1 2001 The Digester package lets you configure an XML to Java object mapping module which triggers certain actions called rules whenever a particular pattern of nested XML elements is recognized. http://commons.apache.org/digester/ jira http://issues.apache.org/jira/browse/DIGESTER scm:svn:http://svn.apache.org/repos/asf/commons/proper/digester/tags/DIGESTER_1_8_1 scm:svn:https://svn.apache.org/repos/asf/commons/proper/digester/tags/DIGESTER_1_8_1 http://svn.apache.org/viewvc/commons/proper/digester/tags/DIGESTER_1_8_1 Craig McClanahan craigmcc craigmcc@apache.org Robert Burrell Donkin rdonkin rdonkin@apache.org Scott Sanders sanders sanders@totalsync.com James Strachan jstrachan jstrachan@apache.org Jason van Zyl jvanzyl jvanzyl@apache.org Tim OBrien tobrien tobrien@apache.org Jean-Francois Arcand jfarcand jfarcand@apache.org Simon Kitching skitching skitching@apache.org Rahul Akolkar rahul rahul AT apache DOT org Bradley M. Handy bhandy@users.sf.net Christopher Lenz Ted Husted David H. Martin Henri Chen Janek Bogucki Mark Huisman Paul Jack Anton Maslovsky Matt Cleveland Gabriele Carcassi Wendy Smoak java@wendysmoak.com Kevin Ross kevin.ross@iverticalleap.com apache.website Apache Commons Site ${commons.deployment.protocol}://people.apache.org/www/commons.apache.org/digester 1.2 1.2 digester 1.8.1 RC1 DIGESTER 12310471 src/java src/test . META-INF NOTICE.txt LICENSE.txt src/java false **/*.dtd src/test false **/*.xml maven-surefire-plugin **/TestBean.java **/TestRule.java **/TestRuleSet.java **/Test*$*.java maven-assembly-plugin src/assembly/bin.xml src/assembly/src.xml gnu commons-beanutils commons-beanutils 1.8.0 commons-logging commons-logging 1.1.1 xml-apis xml-apis 1.0.b2 provided junit junit 3.8.1 test org.apache.maven.plugins maven-changes-plugin 2.0 %URL%/../%ISSUE% changes-report jira-report org.apache.maven.plugins maven-checkstyle-plugin 2.1 ${basedir}/checkstyle.xml false ${basedir}/file-header.txt org.apache.maven.plugins maven-pmd-plugin 2.3 org.codehaus.mojo clirr-maven-plugin 2.2.1 1.8 rc apache.website Apache Commons Release Candidate Staging Site ${commons.deployment.protocol}://people.apache.org/www/people.apache.org/builds/commons/${commons.componentid}/${commons.release.version}/${commons.rc.version}/site