*** empty log message ***
This commit is contained in:
commit
b80fa05ed1
28
.cvsignore
Normal file
28
.cvsignore
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# CVS default ignores begin
|
||||||
|
tags
|
||||||
|
TAGS
|
||||||
|
.make.state
|
||||||
|
.nse_depinfo
|
||||||
|
*~
|
||||||
|
#*
|
||||||
|
.#*
|
||||||
|
,*
|
||||||
|
_$*
|
||||||
|
*$
|
||||||
|
*.old
|
||||||
|
*.bak
|
||||||
|
*.BAK
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
.del-*
|
||||||
|
*.a
|
||||||
|
*.olb
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.so
|
||||||
|
*.exe
|
||||||
|
*.Z
|
||||||
|
*.elc
|
||||||
|
*.ln
|
||||||
|
core
|
||||||
|
# CVS default ignores end
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
assembly
|
||||||
|
build.properties
|
||||||
|
jars
|
||||||
|
javadocs
|
||||||
|
OLD
|
||||||
|
workingarea
|
52
INSTALL
Normal file
52
INSTALL
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
INSTALLATION INSTRUCTIONS
|
||||||
|
=========================
|
||||||
|
|
||||||
|
THE JDK INSTALLATION
|
||||||
|
--------------------
|
||||||
|
This version of Venice runs under JDK 1.4.1. The following extensions should
|
||||||
|
be installed to the $JAVA_HOME/jre/lib/ext directory:
|
||||||
|
- JavaMail 1.3
|
||||||
|
- JavaBeans Activation Framework 1.0.2
|
||||||
|
- Java Advanced Imaging 1.1.1, plus the JAI ImageIO extensions
|
||||||
|
|
||||||
|
In addition, the Xalan 2.4.1 and Xerces 2.2.1 XML tools should be installed
|
||||||
|
as "endorsed standards overrides" in the $JAVA_HOME/jre/lib/endorsed directory.
|
||||||
|
|
||||||
|
APACHE TOMCAT
|
||||||
|
-------------
|
||||||
|
A recent version of Apache Tomcat, such as version 4.1.24, must be installed.
|
||||||
|
|
||||||
|
JAKARTA ANT
|
||||||
|
-----------
|
||||||
|
A recent version of Jakarta Ant, such as 1.5.1, must be installed to build
|
||||||
|
Venice.
|
||||||
|
|
||||||
|
PACKAGES REQUIRED FOR VENICE
|
||||||
|
----------------------------
|
||||||
|
The following packages must be referenced from within build.properties:
|
||||||
|
- Java Servlet API 2.3 (use the servlet.jar file from Tomcat)
|
||||||
|
- Jakarta Bean Scripting Framework 2.3
|
||||||
|
- Jakarta Commons Collections Library, 2.1
|
||||||
|
- Jakarta Commons Lang Library, 1.0.1
|
||||||
|
- Mozilla.org Rhino, 1.5R3
|
||||||
|
- Jakarta Log4J, 1.2.7
|
||||||
|
- Jakarta Velocity, 1.3.1
|
||||||
|
|
||||||
|
Optionally:
|
||||||
|
- SourceID-SSO 1.0
|
||||||
|
|
||||||
|
DATABASE DRIVERS REQUIRED FOR VENICE
|
||||||
|
------------------------------------
|
||||||
|
Currently, the only database supported with Venice is MySQL. The MySQL
|
||||||
|
Connector 3.0.7 should be copied to the drivers/ subdirectory.
|
||||||
|
|
||||||
|
BUILDING AND DEPLOYING
|
||||||
|
----------------------
|
||||||
|
When built, the complete installation of Venice will be copied to the
|
||||||
|
subdirectory "assembly/venice". This directory may be deployed into Tomcat
|
||||||
|
directly by editing $CATALINA_HOME/conf/server.xml.
|
||||||
|
|
||||||
|
INITIALIZING THE DATABASE
|
||||||
|
-------------------------
|
||||||
|
The script "conf/venice-db-init-mysql.sql" can be used to initialize the
|
||||||
|
database.
|
470
LICENSE
Normal file
470
LICENSE
Normal file
|
@ -0,0 +1,470 @@
|
||||||
|
MOZILLA PUBLIC LICENSE
|
||||||
|
Version 1.1
|
||||||
|
|
||||||
|
---------------
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
1.0.1. "Commercial Use" means distribution or otherwise making the
|
||||||
|
Covered Code available to a third party.
|
||||||
|
|
||||||
|
1.1. "Contributor" means each entity that creates or contributes to
|
||||||
|
the creation of Modifications.
|
||||||
|
|
||||||
|
1.2. "Contributor Version" means the combination of the Original
|
||||||
|
Code, prior Modifications used by a Contributor, and the Modifications
|
||||||
|
made by that particular Contributor.
|
||||||
|
|
||||||
|
1.3. "Covered Code" means the Original Code or Modifications or the
|
||||||
|
combination of the Original Code and Modifications, in each case
|
||||||
|
including portions thereof.
|
||||||
|
|
||||||
|
1.4. "Electronic Distribution Mechanism" means a mechanism generally
|
||||||
|
accepted in the software development community for the electronic
|
||||||
|
transfer of data.
|
||||||
|
|
||||||
|
1.5. "Executable" means Covered Code in any form other than Source
|
||||||
|
Code.
|
||||||
|
|
||||||
|
1.6. "Initial Developer" means the individual or entity identified
|
||||||
|
as the Initial Developer in the Source Code notice required by Exhibit
|
||||||
|
A.
|
||||||
|
|
||||||
|
1.7. "Larger Work" means a work which combines Covered Code or
|
||||||
|
portions thereof with code not governed by the terms of this License.
|
||||||
|
|
||||||
|
1.8. "License" means this document.
|
||||||
|
|
||||||
|
1.8.1. "Licensable" means having the right to grant, to the maximum
|
||||||
|
extent possible, whether at the time of the initial grant or
|
||||||
|
subsequently acquired, any and all of the rights conveyed herein.
|
||||||
|
|
||||||
|
1.9. "Modifications" means any addition to or deletion from the
|
||||||
|
substance or structure of either the Original Code or any previous
|
||||||
|
Modifications. When Covered Code is released as a series of files, a
|
||||||
|
Modification is:
|
||||||
|
A. Any addition to or deletion from the contents of a file
|
||||||
|
containing Original Code or previous Modifications.
|
||||||
|
|
||||||
|
B. Any new file that contains any part of the Original Code or
|
||||||
|
previous Modifications.
|
||||||
|
|
||||||
|
1.10. "Original Code" means Source Code of computer software code
|
||||||
|
which is described in the Source Code notice required by Exhibit A as
|
||||||
|
Original Code, and which, at the time of its release under this
|
||||||
|
License is not already Covered Code governed by this License.
|
||||||
|
|
||||||
|
1.10.1. "Patent Claims" means any patent claim(s), now owned or
|
||||||
|
hereafter acquired, including without limitation, method, process,
|
||||||
|
and apparatus claims, in any patent Licensable by grantor.
|
||||||
|
|
||||||
|
1.11. "Source Code" means the preferred form of the Covered Code for
|
||||||
|
making modifications to it, including all modules it contains, plus
|
||||||
|
any associated interface definition files, scripts used to control
|
||||||
|
compilation and installation of an Executable, or source code
|
||||||
|
differential comparisons against either the Original Code or another
|
||||||
|
well known, available Covered Code of the Contributor's choice. The
|
||||||
|
Source Code can be in a compressed or archival form, provided the
|
||||||
|
appropriate decompression or de-archiving software is widely available
|
||||||
|
for no charge.
|
||||||
|
|
||||||
|
1.12. "You" (or "Your") means an individual or a legal entity
|
||||||
|
exercising rights under, and complying with all of the terms of, this
|
||||||
|
License or a future version of this License issued under Section 6.1.
|
||||||
|
For legal entities, "You" includes any entity which controls, is
|
||||||
|
controlled by, or is under common control with You. For purposes of
|
||||||
|
this definition, "control" means (a) the power, direct or indirect,
|
||||||
|
to cause the direction or management of such entity, whether by
|
||||||
|
contract or otherwise, or (b) ownership of more than fifty percent
|
||||||
|
(50%) of the outstanding shares or beneficial ownership of such
|
||||||
|
entity.
|
||||||
|
|
||||||
|
2. Source Code License.
|
||||||
|
|
||||||
|
2.1. The Initial Developer Grant.
|
||||||
|
The Initial Developer hereby grants You a world-wide, royalty-free,
|
||||||
|
non-exclusive license, subject to third party intellectual property
|
||||||
|
claims:
|
||||||
|
(a) under intellectual property rights (other than patent or
|
||||||
|
trademark) Licensable by Initial Developer to use, reproduce,
|
||||||
|
modify, display, perform, sublicense and distribute the Original
|
||||||
|
Code (or portions thereof) with or without Modifications, and/or
|
||||||
|
as part of a Larger Work; and
|
||||||
|
|
||||||
|
(b) under Patents Claims infringed by the making, using or
|
||||||
|
selling of Original Code, to make, have made, use, practice,
|
||||||
|
sell, and offer for sale, and/or otherwise dispose of the
|
||||||
|
Original Code (or portions thereof).
|
||||||
|
|
||||||
|
(c) the licenses granted in this Section 2.1(a) and (b) are
|
||||||
|
effective on the date Initial Developer first distributes
|
||||||
|
Original Code under the terms of this License.
|
||||||
|
|
||||||
|
(d) Notwithstanding Section 2.1(b) above, no patent license is
|
||||||
|
granted: 1) for code that You delete from the Original Code; 2)
|
||||||
|
separate from the Original Code; or 3) for infringements caused
|
||||||
|
by: i) the modification of the Original Code or ii) the
|
||||||
|
combination of the Original Code with other software or devices.
|
||||||
|
|
||||||
|
2.2. Contributor Grant.
|
||||||
|
Subject to third party intellectual property claims, each Contributor
|
||||||
|
hereby grants You a world-wide, royalty-free, non-exclusive license
|
||||||
|
|
||||||
|
(a) under intellectual property rights (other than patent or
|
||||||
|
trademark) Licensable by Contributor, to use, reproduce, modify,
|
||||||
|
display, perform, sublicense and distribute the Modifications
|
||||||
|
created by such Contributor (or portions thereof) either on an
|
||||||
|
unmodified basis, with other Modifications, as Covered Code
|
||||||
|
and/or as part of a Larger Work; and
|
||||||
|
|
||||||
|
(b) under Patent Claims infringed by the making, using, or
|
||||||
|
selling of Modifications made by that Contributor either alone
|
||||||
|
and/or in combination with its Contributor Version (or portions
|
||||||
|
of such combination), to make, use, sell, offer for sale, have
|
||||||
|
made, and/or otherwise dispose of: 1) Modifications made by that
|
||||||
|
Contributor (or portions thereof); and 2) the combination of
|
||||||
|
Modifications made by that Contributor with its Contributor
|
||||||
|
Version (or portions of such combination).
|
||||||
|
|
||||||
|
(c) the licenses granted in Sections 2.2(a) and 2.2(b) are
|
||||||
|
effective on the date Contributor first makes Commercial Use of
|
||||||
|
the Covered Code.
|
||||||
|
|
||||||
|
(d) Notwithstanding Section 2.2(b) above, no patent license is
|
||||||
|
granted: 1) for any code that Contributor has deleted from the
|
||||||
|
Contributor Version; 2) separate from the Contributor Version;
|
||||||
|
3) for infringements caused by: i) third party modifications of
|
||||||
|
Contributor Version or ii) the combination of Modifications made
|
||||||
|
by that Contributor with other software (except as part of the
|
||||||
|
Contributor Version) or other devices; or 4) under Patent Claims
|
||||||
|
infringed by Covered Code in the absence of Modifications made by
|
||||||
|
that Contributor.
|
||||||
|
|
||||||
|
3. Distribution Obligations.
|
||||||
|
|
||||||
|
3.1. Application of License.
|
||||||
|
The Modifications which You create or to which You contribute are
|
||||||
|
governed by the terms of this License, including without limitation
|
||||||
|
Section 2.2. The Source Code version of Covered Code may be
|
||||||
|
distributed only under the terms of this License or a future version
|
||||||
|
of this License released under Section 6.1, and You must include a
|
||||||
|
copy of this License with every copy of the Source Code You
|
||||||
|
distribute. You may not offer or impose any terms on any Source Code
|
||||||
|
version that alters or restricts the applicable version of this
|
||||||
|
License or the recipients' rights hereunder. However, You may include
|
||||||
|
an additional document offering the additional rights described in
|
||||||
|
Section 3.5.
|
||||||
|
|
||||||
|
3.2. Availability of Source Code.
|
||||||
|
Any Modification which You create or to which You contribute must be
|
||||||
|
made available in Source Code form under the terms of this License
|
||||||
|
either on the same media as an Executable version or via an accepted
|
||||||
|
Electronic Distribution Mechanism to anyone to whom you made an
|
||||||
|
Executable version available; and if made available via Electronic
|
||||||
|
Distribution Mechanism, must remain available for at least twelve (12)
|
||||||
|
months after the date it initially became available, or at least six
|
||||||
|
(6) months after a subsequent version of that particular Modification
|
||||||
|
has been made available to such recipients. You are responsible for
|
||||||
|
ensuring that the Source Code version remains available even if the
|
||||||
|
Electronic Distribution Mechanism is maintained by a third party.
|
||||||
|
|
||||||
|
3.3. Description of Modifications.
|
||||||
|
You must cause all Covered Code to which You contribute to contain a
|
||||||
|
file documenting the changes You made to create that Covered Code and
|
||||||
|
the date of any change. You must include a prominent statement that
|
||||||
|
the Modification is derived, directly or indirectly, from Original
|
||||||
|
Code provided by the Initial Developer and including the name of the
|
||||||
|
Initial Developer in (a) the Source Code, and (b) in any notice in an
|
||||||
|
Executable version or related documentation in which You describe the
|
||||||
|
origin or ownership of the Covered Code.
|
||||||
|
|
||||||
|
3.4. Intellectual Property Matters
|
||||||
|
(a) Third Party Claims.
|
||||||
|
If Contributor has knowledge that a license under a third party's
|
||||||
|
intellectual property rights is required to exercise the rights
|
||||||
|
granted by such Contributor under Sections 2.1 or 2.2,
|
||||||
|
Contributor must include a text file with the Source Code
|
||||||
|
distribution titled "LEGAL" which describes the claim and the
|
||||||
|
party making the claim in sufficient detail that a recipient will
|
||||||
|
know whom to contact. If Contributor obtains such knowledge after
|
||||||
|
the Modification is made available as described in Section 3.2,
|
||||||
|
Contributor shall promptly modify the LEGAL file in all copies
|
||||||
|
Contributor makes available thereafter and shall take other steps
|
||||||
|
(such as notifying appropriate mailing lists or newsgroups)
|
||||||
|
reasonably calculated to inform those who received the Covered
|
||||||
|
Code that new knowledge has been obtained.
|
||||||
|
|
||||||
|
(b) Contributor APIs.
|
||||||
|
If Contributor's Modifications include an application programming
|
||||||
|
interface and Contributor has knowledge of patent licenses which
|
||||||
|
are reasonably necessary to implement that API, Contributor must
|
||||||
|
also include this information in the LEGAL file.
|
||||||
|
|
||||||
|
(c) Representations.
|
||||||
|
Contributor represents that, except as disclosed pursuant to
|
||||||
|
Section 3.4(a) above, Contributor believes that Contributor's
|
||||||
|
Modifications are Contributor's original creation(s) and/or
|
||||||
|
Contributor has sufficient rights to grant the rights conveyed by
|
||||||
|
this License.
|
||||||
|
|
||||||
|
3.5. Required Notices.
|
||||||
|
You must duplicate the notice in Exhibit A in each file of the Source
|
||||||
|
Code. If it is not possible to put such notice in a particular Source
|
||||||
|
Code file due to its structure, then You must include such notice in a
|
||||||
|
location (such as a relevant directory) where a user would be likely
|
||||||
|
to look for such a notice. If You created one or more Modification(s)
|
||||||
|
You may add your name as a Contributor to the notice described in
|
||||||
|
Exhibit A. You must also duplicate this License in any documentation
|
||||||
|
for the Source Code where You describe recipients' rights or ownership
|
||||||
|
rights relating to Covered Code. You may choose to offer, and to
|
||||||
|
charge a fee for, warranty, support, indemnity or liability
|
||||||
|
obligations to one or more recipients of Covered Code. However, You
|
||||||
|
may do so only on Your own behalf, and not on behalf of the Initial
|
||||||
|
Developer or any Contributor. You must make it absolutely clear than
|
||||||
|
any such warranty, support, indemnity or liability obligation is
|
||||||
|
offered by You alone, and You hereby agree to indemnify the Initial
|
||||||
|
Developer and every Contributor for any liability incurred by the
|
||||||
|
Initial Developer or such Contributor as a result of warranty,
|
||||||
|
support, indemnity or liability terms You offer.
|
||||||
|
|
||||||
|
3.6. Distribution of Executable Versions.
|
||||||
|
You may distribute Covered Code in Executable form only if the
|
||||||
|
requirements of Section 3.1-3.5 have been met for that Covered Code,
|
||||||
|
and if You include a notice stating that the Source Code version of
|
||||||
|
the Covered Code is available under the terms of this License,
|
||||||
|
including a description of how and where You have fulfilled the
|
||||||
|
obligations of Section 3.2. The notice must be conspicuously included
|
||||||
|
in any notice in an Executable version, related documentation or
|
||||||
|
collateral in which You describe recipients' rights relating to the
|
||||||
|
Covered Code. You may distribute the Executable version of Covered
|
||||||
|
Code or ownership rights under a license of Your choice, which may
|
||||||
|
contain terms different from this License, provided that You are in
|
||||||
|
compliance with the terms of this License and that the license for the
|
||||||
|
Executable version does not attempt to limit or alter the recipient's
|
||||||
|
rights in the Source Code version from the rights set forth in this
|
||||||
|
License. If You distribute the Executable version under a different
|
||||||
|
license You must make it absolutely clear that any terms which differ
|
||||||
|
from this License are offered by You alone, not by the Initial
|
||||||
|
Developer or any Contributor. You hereby agree to indemnify the
|
||||||
|
Initial Developer and every Contributor for any liability incurred by
|
||||||
|
the Initial Developer or such Contributor as a result of any such
|
||||||
|
terms You offer.
|
||||||
|
|
||||||
|
3.7. Larger Works.
|
||||||
|
You may create a Larger Work by combining Covered Code with other code
|
||||||
|
not governed by the terms of this License and distribute the Larger
|
||||||
|
Work as a single product. In such a case, You must make sure the
|
||||||
|
requirements of this License are fulfilled for the Covered Code.
|
||||||
|
|
||||||
|
4. Inability to Comply Due to Statute or Regulation.
|
||||||
|
|
||||||
|
If it is impossible for You to comply with any of the terms of this
|
||||||
|
License with respect to some or all of the Covered Code due to
|
||||||
|
statute, judicial order, or regulation then You must: (a) comply with
|
||||||
|
the terms of this License to the maximum extent possible; and (b)
|
||||||
|
describe the limitations and the code they affect. Such description
|
||||||
|
must be included in the LEGAL file described in Section 3.4 and must
|
||||||
|
be included with all distributions of the Source Code. Except to the
|
||||||
|
extent prohibited by statute or regulation, such description must be
|
||||||
|
sufficiently detailed for a recipient of ordinary skill to be able to
|
||||||
|
understand it.
|
||||||
|
|
||||||
|
5. Application of this License.
|
||||||
|
|
||||||
|
This License applies to code to which the Initial Developer has
|
||||||
|
attached the notice in Exhibit A and to related Covered Code.
|
||||||
|
|
||||||
|
6. Versions of the License.
|
||||||
|
|
||||||
|
6.1. New Versions.
|
||||||
|
Netscape Communications Corporation ("Netscape") may publish revised
|
||||||
|
and/or new versions of the License from time to time. Each version
|
||||||
|
will be given a distinguishing version number.
|
||||||
|
|
||||||
|
6.2. Effect of New Versions.
|
||||||
|
Once Covered Code has been published under a particular version of the
|
||||||
|
License, You may always continue to use it under the terms of that
|
||||||
|
version. You may also choose to use such Covered Code under the terms
|
||||||
|
of any subsequent version of the License published by Netscape. No one
|
||||||
|
other than Netscape has the right to modify the terms applicable to
|
||||||
|
Covered Code created under this License.
|
||||||
|
|
||||||
|
6.3. Derivative Works.
|
||||||
|
If You create or use a modified version of this License (which you may
|
||||||
|
only do in order to apply it to code which is not already Covered Code
|
||||||
|
governed by this License), You must (a) rename Your license so that
|
||||||
|
the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
|
||||||
|
"MPL", "NPL" or any confusingly similar phrase do not appear in your
|
||||||
|
license (except to note that your license differs from this License)
|
||||||
|
and (b) otherwise make it clear that Your version of the license
|
||||||
|
contains terms which differ from the Mozilla Public License and
|
||||||
|
Netscape Public License. (Filling in the name of the Initial
|
||||||
|
Developer, Original Code or Contributor in the notice described in
|
||||||
|
Exhibit A shall not of themselves be deemed to be modifications of
|
||||||
|
this License.)
|
||||||
|
|
||||||
|
7. DISCLAIMER OF WARRANTY.
|
||||||
|
|
||||||
|
COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
||||||
|
WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
|
||||||
|
DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
|
||||||
|
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
|
||||||
|
IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
|
||||||
|
YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
|
||||||
|
COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
|
||||||
|
OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
|
||||||
|
ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
|
||||||
|
|
||||||
|
8. TERMINATION.
|
||||||
|
|
||||||
|
8.1. This License and the rights granted hereunder will terminate
|
||||||
|
automatically if You fail to comply with terms herein and fail to cure
|
||||||
|
such breach within 30 days of becoming aware of the breach. All
|
||||||
|
sublicenses to the Covered Code which are properly granted shall
|
||||||
|
survive any termination of this License. Provisions which, by their
|
||||||
|
nature, must remain in effect beyond the termination of this License
|
||||||
|
shall survive.
|
||||||
|
|
||||||
|
8.2. If You initiate litigation by asserting a patent infringement
|
||||||
|
claim (excluding declatory judgment actions) against Initial Developer
|
||||||
|
or a Contributor (the Initial Developer or Contributor against whom
|
||||||
|
You file such action is referred to as "Participant") alleging that:
|
||||||
|
|
||||||
|
(a) such Participant's Contributor Version directly or indirectly
|
||||||
|
infringes any patent, then any and all rights granted by such
|
||||||
|
Participant to You under Sections 2.1 and/or 2.2 of this License
|
||||||
|
shall, upon 60 days notice from Participant terminate prospectively,
|
||||||
|
unless if within 60 days after receipt of notice You either: (i)
|
||||||
|
agree in writing to pay Participant a mutually agreeable reasonable
|
||||||
|
royalty for Your past and future use of Modifications made by such
|
||||||
|
Participant, or (ii) withdraw Your litigation claim with respect to
|
||||||
|
the Contributor Version against such Participant. If within 60 days
|
||||||
|
of notice, a reasonable royalty and payment arrangement are not
|
||||||
|
mutually agreed upon in writing by the parties or the litigation claim
|
||||||
|
is not withdrawn, the rights granted by Participant to You under
|
||||||
|
Sections 2.1 and/or 2.2 automatically terminate at the expiration of
|
||||||
|
the 60 day notice period specified above.
|
||||||
|
|
||||||
|
(b) any software, hardware, or device, other than such Participant's
|
||||||
|
Contributor Version, directly or indirectly infringes any patent, then
|
||||||
|
any rights granted to You by such Participant under Sections 2.1(b)
|
||||||
|
and 2.2(b) are revoked effective as of the date You first made, used,
|
||||||
|
sold, distributed, or had made, Modifications made by that
|
||||||
|
Participant.
|
||||||
|
|
||||||
|
8.3. If You assert a patent infringement claim against Participant
|
||||||
|
alleging that such Participant's Contributor Version directly or
|
||||||
|
indirectly infringes any patent where such claim is resolved (such as
|
||||||
|
by license or settlement) prior to the initiation of patent
|
||||||
|
infringement litigation, then the reasonable value of the licenses
|
||||||
|
granted by such Participant under Sections 2.1 or 2.2 shall be taken
|
||||||
|
into account in determining the amount or value of any payment or
|
||||||
|
license.
|
||||||
|
|
||||||
|
8.4. In the event of termination under Sections 8.1 or 8.2 above,
|
||||||
|
all end user license agreements (excluding distributors and resellers)
|
||||||
|
which have been validly granted by You or any distributor hereunder
|
||||||
|
prior to termination shall survive termination.
|
||||||
|
|
||||||
|
9. LIMITATION OF LIABILITY.
|
||||||
|
|
||||||
|
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
|
||||||
|
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
|
||||||
|
DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
|
||||||
|
OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
|
||||||
|
ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
|
||||||
|
CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
|
||||||
|
WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
|
||||||
|
COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
|
||||||
|
INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
|
||||||
|
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
|
||||||
|
RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
|
||||||
|
PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
|
||||||
|
EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
|
||||||
|
THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
|
||||||
|
|
||||||
|
10. U.S. GOVERNMENT END USERS.
|
||||||
|
|
||||||
|
The Covered Code is a "commercial item," as that term is defined in
|
||||||
|
48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
|
||||||
|
software" and "commercial computer software documentation," as such
|
||||||
|
terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
|
||||||
|
C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
|
||||||
|
all U.S. Government End Users acquire Covered Code with only those
|
||||||
|
rights set forth herein.
|
||||||
|
|
||||||
|
11. MISCELLANEOUS.
|
||||||
|
|
||||||
|
This License represents the complete agreement concerning subject
|
||||||
|
matter hereof. If any provision of this License is held to be
|
||||||
|
unenforceable, such provision shall be reformed only to the extent
|
||||||
|
necessary to make it enforceable. This License shall be governed by
|
||||||
|
California law provisions (except to the extent applicable law, if
|
||||||
|
any, provides otherwise), excluding its conflict-of-law provisions.
|
||||||
|
With respect to disputes in which at least one party is a citizen of,
|
||||||
|
or an entity chartered or registered to do business in the United
|
||||||
|
States of America, any litigation relating to this License shall be
|
||||||
|
subject to the jurisdiction of the Federal Courts of the Northern
|
||||||
|
District of California, with venue lying in Santa Clara County,
|
||||||
|
California, with the losing party responsible for costs, including
|
||||||
|
without limitation, court costs and reasonable attorneys' fees and
|
||||||
|
expenses. The application of the United Nations Convention on
|
||||||
|
Contracts for the International Sale of Goods is expressly excluded.
|
||||||
|
Any law or regulation which provides that the language of a contract
|
||||||
|
shall be construed against the drafter shall not apply to this
|
||||||
|
License.
|
||||||
|
|
||||||
|
12. RESPONSIBILITY FOR CLAIMS.
|
||||||
|
|
||||||
|
As between Initial Developer and the Contributors, each party is
|
||||||
|
responsible for claims and damages arising, directly or indirectly,
|
||||||
|
out of its utilization of rights under this License and You agree to
|
||||||
|
work with Initial Developer and Contributors to distribute such
|
||||||
|
responsibility on an equitable basis. Nothing herein is intended or
|
||||||
|
shall be deemed to constitute any admission of liability.
|
||||||
|
|
||||||
|
13. MULTIPLE-LICENSED CODE.
|
||||||
|
|
||||||
|
Initial Developer may designate portions of the Covered Code as
|
||||||
|
"Multiple-Licensed". "Multiple-Licensed" means that the Initial
|
||||||
|
Developer permits you to utilize portions of the Covered Code under
|
||||||
|
Your choice of the NPL or the alternative licenses, if any, specified
|
||||||
|
by the Initial Developer in the file described in Exhibit A.
|
||||||
|
|
||||||
|
EXHIBIT A -Mozilla Public License.
|
||||||
|
|
||||||
|
``The contents of this file are subject to the Mozilla Public License
|
||||||
|
Version 1.1 (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.mozilla.org/MPL/
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS"
|
||||||
|
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||||
|
License for the specific language governing rights and limitations
|
||||||
|
under the License.
|
||||||
|
|
||||||
|
The Original Code is ______________________________________.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is ________________________.
|
||||||
|
Portions created by ______________________ are Copyright (C) ______
|
||||||
|
_______________________. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s): ______________________________________.
|
||||||
|
|
||||||
|
Alternatively, the contents of this file may be used under the terms
|
||||||
|
of the _____ license (the "[___] License"), in which case the
|
||||||
|
provisions of [______] License are applicable instead of those
|
||||||
|
above. If you wish to allow use of your version of this file only
|
||||||
|
under the terms of the [____] License and not to allow others to use
|
||||||
|
your version of this file under the MPL, indicate your decision by
|
||||||
|
deleting the provisions above and replace them with the notice and
|
||||||
|
other provisions required by the [___] License. If you do not delete
|
||||||
|
the provisions above, a recipient may use your version of this file
|
||||||
|
under either the MPL or the [___] License."
|
||||||
|
|
||||||
|
[NOTE: The text of this Exhibit A may differ slightly from the text of
|
||||||
|
the notices in the Source Code files of the Original Code. You should
|
||||||
|
use the text of this Exhibit A rather than the text found in the
|
||||||
|
Original Code Source Code for Your Modifications.]
|
||||||
|
|
2
README
Normal file
2
README
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
This branch of the code is not really usable yet. New instructions will
|
||||||
|
be posted when it is.
|
60
build.properties.sample
Normal file
60
build.properties.sample
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
#########################################################################################
|
||||||
|
|
||||||
|
# [Compilation control flags]
|
||||||
|
# compile.debug=on
|
||||||
|
# compile.deprecation=off
|
||||||
|
# compile.optimize=on
|
||||||
|
# build.compiler=modern
|
||||||
|
|
||||||
|
# [Location of Servlet API 2.3]
|
||||||
|
servlet.base=/usr/local/jakarta/jakarta-tomcat-4.1.24-LE-jdk14
|
||||||
|
servlet.lib=${servlet.base}/common/lib
|
||||||
|
# servlet.jarfile=servlet.jar
|
||||||
|
|
||||||
|
# [Location of Bean Scripting Framework 2.3]
|
||||||
|
bsf.base=/usr/local/jakarta/bsf-2.3.0
|
||||||
|
# bsf.lib=${bsf.base}/lib
|
||||||
|
# bsf.jarfile=bsf.jar
|
||||||
|
|
||||||
|
# [Location of Commons Collections Library 2.1]
|
||||||
|
collections.base=/usr/local/jakarta/commons-collections-2.1
|
||||||
|
# collections.lib=${collections.base}
|
||||||
|
# collections.jarfile=commons-collections.jar
|
||||||
|
|
||||||
|
# [Location of Commons Lang Library 1.0.1]
|
||||||
|
commlang.base=/usr/local/jakarta/commons-lang-1.0.1
|
||||||
|
# commlang.lib=${commlang.base}
|
||||||
|
commlang.jarfile=commons-lang-1.0.1.jar
|
||||||
|
|
||||||
|
# [Location of Rhino 1.5R3]
|
||||||
|
rhino.base=/usr/local/java/rhino1_5R3
|
||||||
|
# rhino.lib=${rhino.base}
|
||||||
|
# rhino.jarfile=js.jar
|
||||||
|
|
||||||
|
# [Location of Log4J 1.2.7]
|
||||||
|
log4j.base=/usr/local/jakarta/jakarta-log4j-1.2.7
|
||||||
|
# log4j.lib=${log4j.base}/dist/lib
|
||||||
|
log4j.jarfile=log4j-1.2.7.jar
|
||||||
|
|
||||||
|
# [Location of Velocity 1.3.1]
|
||||||
|
velocity.base=/usr/local/jakarta/velocity-1.3.1
|
||||||
|
# velocity.lib=${velocity.base}
|
||||||
|
velocity.jarfile=velocity-1.3.1.jar
|
||||||
|
|
||||||
|
# [Location of SourceID SSO 1.0b7/1.0 (optional)]
|
||||||
|
# sourceid.base=${user.home}/sso
|
439
build.xml
Normal file
439
build.xml
Normal file
|
@ -0,0 +1,439 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<project name="venice" default="all">
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
Load build properties
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<property file="build.properties"/>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
Default build properties
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<!-- [Compilation control flags] -->
|
||||||
|
<property name="compile.debug" value="on"/>
|
||||||
|
<property name="compile.deprecation" value="on"/>
|
||||||
|
<property name="compile.optimize" value="off"/>
|
||||||
|
<property name="build.compiler" value="modern"/>
|
||||||
|
|
||||||
|
<!-- [Location of Servlet API 2.3] -->
|
||||||
|
<property name="servlet.base" value="../servletapi"/>
|
||||||
|
<property name="servlet.lib" value="${servlet.base}/lib"/>
|
||||||
|
<property name="servlet.jarfile" value="servlet.jar"/>
|
||||||
|
|
||||||
|
<!-- [Location of Bean Scripting Framework 2.3] -->
|
||||||
|
<property name="bsf.base" value="../bsf"/>
|
||||||
|
<property name="bsf.lib" value="${bsf.base}/lib"/>
|
||||||
|
<property name="bsf.jarfile" value="bsf.jar"/>
|
||||||
|
|
||||||
|
<!-- [Location of Commons Collections Library 2.1] -->
|
||||||
|
<property name="collections.base" value="../commons-collections"/>
|
||||||
|
<property name="collections.lib" value="${collections.base}"/>
|
||||||
|
<property name="collections.jarfile" value="commons-collections.jar"/>
|
||||||
|
|
||||||
|
<!-- [Location of Commons Lang Library 1.0.1] -->
|
||||||
|
<property name="commlang.base" value="../commons-lang"/>
|
||||||
|
<property name="commlang.lib" value="${commlang.base}"/>
|
||||||
|
<property name="commlang.jarfile" value="commons-lang.jar"/>
|
||||||
|
|
||||||
|
<!-- [Location of Rhino 1.5R3] -->
|
||||||
|
<property name="rhino.base" value="../rhino"/>
|
||||||
|
<property name="rhino.lib" value="${rhino.base}"/>
|
||||||
|
<property name="rhino.jarfile" value="js.jar"/>
|
||||||
|
|
||||||
|
<!-- [Location of Log4J 1.2.7] -->
|
||||||
|
<property name="log4j.base" value="../log4j"/>
|
||||||
|
<property name="log4j.lib" value="${log4j.base}/dist/lib"/>
|
||||||
|
<property name="log4j.jarfile" value="log4j.jar"/>
|
||||||
|
|
||||||
|
<!-- [Location of Velocity 1.3.1] -->
|
||||||
|
<property name="velocity.base" value="../velocity"/>
|
||||||
|
<property name="velocity.lib" value="${velocity.base}"/>
|
||||||
|
<property name="velocity.jarfile" value="velocity.jar"/>
|
||||||
|
|
||||||
|
<!-- [Location of SourceID SSO 1.0b7/1.0 (optional)] -->
|
||||||
|
<!-- <property name="sourceid.base" value=""/> -->
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
Path references
|
||||||
|
============================================================================ -->
|
||||||
|
<path id="base.build.path">
|
||||||
|
<fileset dir="${bsf.lib}" includes="${bsf.jarfile}"/>
|
||||||
|
<fileset dir="${servlet.lib}" includes="${servlet.jarfile}"/>
|
||||||
|
<fileset dir="${collections.lib}" includes="${collections.jarfile}"/>
|
||||||
|
<fileset dir="${commlang.lib}" includes="${commlang.jarfile}"/>
|
||||||
|
<fileset dir="${log4j.lib}" includes="${log4j.jarfile}"/>
|
||||||
|
<fileset dir="${velocity.lib}" includes="${velocity.jarfile}"/>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"init" - Initializes the build.
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<target name="init">
|
||||||
|
<condition property="sourceid.present">
|
||||||
|
<and>
|
||||||
|
<isset property="sourceid.base"/>
|
||||||
|
<available file="${sourceid.base}/sourceid-sso.jar"/>
|
||||||
|
</and>
|
||||||
|
</condition>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"init-jars" - Initializes the target directory for compiled JAR files.
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="init-jars" depends="init">
|
||||||
|
<mkdir dir="jars"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"build-baseutil" - Builds the "base utility" classes (com.silverwrist.util.*).
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="build-baseutil" depends="init">
|
||||||
|
<mkdir dir="workingarea/baseutil"/>
|
||||||
|
<javac srcdir="src/baseutil" destdir="workingarea/baseutil" source="1.4"
|
||||||
|
debug="${compile.debug}" optimize="${compile.optimize}" deprecation="${compile.deprecation}">
|
||||||
|
<classpath>
|
||||||
|
<path refid="base.build.path"/>
|
||||||
|
</classpath>
|
||||||
|
</javac>
|
||||||
|
<copy todir="workingarea/baseutil">
|
||||||
|
<fileset dir="src/baseutil" includes="**/*.properties"/>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"jar-baseutil" - Jars up the "base utility" classes (com.silverwrist.util.*).
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="jar-baseutil" depends="init-jars,build-baseutil">
|
||||||
|
<jar destfile="jars/baseutil.jar" basedir="workingarea/baseutil"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"build-dynamo" - Builds the Dynamo framework classes (com.silverwrist.dynamo.*).
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="build-dynamo" depends="jar-baseutil">
|
||||||
|
<mkdir dir="workingarea/dynamo-framework"/>
|
||||||
|
<javac srcdir="src/dynamo-framework" destdir="workingarea/dynamo-framework" source="1.4"
|
||||||
|
debug="${compile.debug}" optimize="${compile.optimize}" deprecation="${compile.deprecation}">
|
||||||
|
<classpath>
|
||||||
|
<filelist dir="jars" files="baseutil.jar"/>
|
||||||
|
<path refid="base.build.path"/>
|
||||||
|
</classpath>
|
||||||
|
</javac>
|
||||||
|
<copy todir="workingarea/dynamo-framework">
|
||||||
|
<fileset dir="src/dynamo-framework" includes="**/*.properties"/>
|
||||||
|
<fileset dir="src/dynamo-framework" includes="**/*.ini"/>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"jar-dynamo" - Jars up the Dynamo framework classes (com.silverwrist.dynamo.*).
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="jar-dynamo" depends="init-jars,build-dynamo">
|
||||||
|
<jar destfile="jars/dynamo-framework.jar" basedir="workingarea/dynamo-framework"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"build-dynamo-test" - Builds the Dynamo test classes
|
||||||
|
(com.silverwrist.dynamo.test.*).
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="build-dynamo-test" depends="jar-baseutil,jar-dynamo">
|
||||||
|
<mkdir dir="workingarea/dynamo-test"/>
|
||||||
|
<javac srcdir="src/dynamo-test" destdir="workingarea/dynamo-test" source="1.4"
|
||||||
|
debug="${compile.debug}" optimize="${compile.optimize}" deprecation="${compile.deprecation}">
|
||||||
|
<classpath>
|
||||||
|
<filelist dir="jars" files="dynamo-framework.jar,baseutil.jar"/>
|
||||||
|
<path refid="base.build.path"/>
|
||||||
|
</classpath>
|
||||||
|
</javac>
|
||||||
|
<copy todir="workingarea/dynamo-test">
|
||||||
|
<fileset dir="src/dynamo-test" includes="**/*.properties"/>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"jar-dynamo-test" - Jars up the Dynamo test classes
|
||||||
|
(com.silverwrist.dynamo.test.*).
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<target name="jar-dynamo-test" depends="init-jars,build-dynamo-test">
|
||||||
|
<jar destfile="jars/dynamo-test.jar" basedir="workingarea/dynamo-test"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"build-test-module" - Builds the test module classes
|
||||||
|
(com.silverwrist.dynamo.testmod.*).
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<target name="build-test-module" depends="jar-baseutil,jar-dynamo">
|
||||||
|
<mkdir dir="workingarea/dynamo-test-module"/>
|
||||||
|
<javac srcdir="src/dynamo-test-module" destdir="workingarea/dynamo-test-module" source="1.4"
|
||||||
|
debug="${compile.debug}" optimize="${compile.optimize}" deprecation="${compile.deprecation}">
|
||||||
|
<classpath>
|
||||||
|
<filelist dir="jars" files="dynamo-framework.jar,baseutil.jar"/>
|
||||||
|
<path refid="base.build.path"/>
|
||||||
|
</classpath>
|
||||||
|
</javac>
|
||||||
|
<mkdir dir="workingarea/dynamo-test-module/resources"/>
|
||||||
|
<copy todir="workingarea/dynamo-test-module/resources">
|
||||||
|
<fileset dir="resources/dynamo-test-module" includes="**/*"/>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"jar-test-module" - Jars up the test module classes
|
||||||
|
(com.silverwrist.dynamo.testmod.*).
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<target name="jar-test-module" depends="init-jars,build-test-module">
|
||||||
|
<jar destfile="jars/dynamo-test-module.jar" basedir="workingarea/dynamo-test-module">
|
||||||
|
<manifest>
|
||||||
|
<attribute name="X-Dynamo-Module-Class" value="com.silverwrist.dynamo.testmod.Main"/>
|
||||||
|
<attribute name="X-Dynamo-Resource-Prefix" value="/resources"/>
|
||||||
|
</manifest>
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"build-venice-base" - Builds the Venice base classes (com.silverwrist.venice.*).
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<target name="build-venice-base" depends="jar-baseutil,jar-dynamo">
|
||||||
|
<mkdir dir="workingarea/venice-base"/>
|
||||||
|
<javac srcdir="src/venice-base" destdir="workingarea/venice-base" source="1.4"
|
||||||
|
debug="${compile.debug}" optimize="${compile.optimize}" deprecation="${compile.deprecation}">
|
||||||
|
<classpath>
|
||||||
|
<filelist dir="jars" files="dynamo-framework.jar,baseutil.jar"/>
|
||||||
|
<path refid="base.build.path"/>
|
||||||
|
</classpath>
|
||||||
|
</javac>
|
||||||
|
<copy todir="workingarea/venice-base">
|
||||||
|
<fileset dir="src/venice-base" includes="**/*.properties"/>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"jar-venice-base" - Jars up the Venice base classes (com.silverwrist.venice.*).
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<target name="jar-venice-base" depends="init-jars,build-venice-base">
|
||||||
|
<jar destfile="jars/venice-base.jar" basedir="workingarea/venice-base"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"build-venice-sso-helper" - Builds the Venice SourceID SSO helper classes.
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<target name="build-venice-sso-helper" depends="jar-baseutil,jar-dynamo,jar-venice-base" if="sourceid.present">
|
||||||
|
<mkdir dir="workingarea/venice-sso-helper"/>
|
||||||
|
<javac srcdir="src/venice-sso-helper" destdir="workingarea/venice-sso-helper" source="1.4"
|
||||||
|
debug="${compile.debug}" optimize="${compile.optimize}" deprecation="${compile.deprecation}">
|
||||||
|
<classpath>
|
||||||
|
<filelist dir="jars" files="venice-base.jar,dynamo-framework.jar,baseutil.jar"/>
|
||||||
|
<filelist dir="${sourceid.base}" files="sourceid-sso.jar"/>
|
||||||
|
<path refid="base.build.path"/>
|
||||||
|
</classpath>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"jar-venice-sso-helper" - Jars up the Venice SourceID SSO helper classes.
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<target name="jar-venice-sso-helper" depends="init-jars,build-venice-sso-helper" if="sourceid.present">
|
||||||
|
<jar destfile="jars/venice-sso-helper.jar" basedir="workingarea/venice-sso-helper"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"all-jars" - Pseudo-target that compiles all JAR files.
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="all-jars"
|
||||||
|
depends="init,jar-baseutil,jar-dynamo,jar-dynamo-test,jar-venice-base,jar-venice-sso-helper"/>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"assemble-test-app" - Pseudo-target that creates the directory structure for
|
||||||
|
the test application.
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="assemble-test-app" depends="init,all-jars,jar-test-module">
|
||||||
|
<mkdir dir="assembly/testapp"/>
|
||||||
|
<mkdir dir="assembly/testapp/WEB-INF/classes"/>
|
||||||
|
<mkdir dir="assembly/testapp/WEB-INF/lib"/>
|
||||||
|
<mkdir dir="assembly/testapp/WEB-INF/modules"/>
|
||||||
|
<copy todir="assembly/testapp/WEB-INF/lib">
|
||||||
|
<fileset dir="jars" includes="dynamo-test.jar,dynamo-framework.jar,baseutil.jar"/>
|
||||||
|
<fileset dir="drivers" includes="*.jar"/>
|
||||||
|
<fileset dir="${bsf.lib}" includes="${bsf.jarfile}"/>
|
||||||
|
<fileset dir="${collections.lib}" includes="${collections.jarfile}"/>
|
||||||
|
<fileset dir="${commlang.lib}" includes="${commlang.jarfile}"/>
|
||||||
|
<fileset dir="${rhino.lib}" includes="${rhino.jarfile}"/>
|
||||||
|
<fileset dir="${log4j.lib}" includes="${log4j.jarfile}"/>
|
||||||
|
<fileset dir="${velocity.lib}" includes="${velocity.jarfile}"/>
|
||||||
|
</copy>
|
||||||
|
<copy file="jars/dynamo-test-module.jar" todir="assembly/testapp/WEB-INF/modules"/>
|
||||||
|
<copy file="conf/dynamo-test.xml" tofile="assembly/testapp/WEB-INF/dynamo.xml"/>
|
||||||
|
<copy file="conf/logging-test.xml" tofile="assembly/testapp/WEB-INF/logging.xml"/>
|
||||||
|
<copy file="conf/web-test.xml" tofile="assembly/testapp/WEB-INF/web.xml"/>
|
||||||
|
<copy todir="assembly/testapp/WEB-INF">
|
||||||
|
<fileset dir="test-data" includes="**/*"/>
|
||||||
|
</copy>
|
||||||
|
<copy file="conf/std_render_macro_library.vm"
|
||||||
|
tofile="assembly/testapp/WEB-INF/velocity/VM_global_library.vm"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"assemble-venice" - Pseudo-target that creates the directory structure for
|
||||||
|
Venice itself.
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="assemble-venice" depends="init,all-jars">
|
||||||
|
<mkdir dir="assembly/venice"/>
|
||||||
|
<mkdir dir="assembly/venice/WEB-INF/classes"/>
|
||||||
|
<mkdir dir="assembly/venice/WEB-INF/lib"/>
|
||||||
|
<mkdir dir="assembly/venice/WEB-INF/modules"/>
|
||||||
|
<copy todir="assembly/venice/WEB-INF/lib">
|
||||||
|
<fileset dir="jars" includes="venice-base.jar,dynamo-framework.jar,baseutil.jar"/>
|
||||||
|
<fileset dir="drivers" includes="*.jar"/>
|
||||||
|
<fileset dir="${bsf.lib}" includes="${bsf.jarfile}"/>
|
||||||
|
<fileset dir="${collections.lib}" includes="${collections.jarfile}"/>
|
||||||
|
<fileset dir="${commlang.lib}" includes="${commlang.jarfile}"/>
|
||||||
|
<fileset dir="${rhino.lib}" includes="${rhino.jarfile}"/>
|
||||||
|
<fileset dir="${log4j.lib}" includes="${log4j.jarfile}"/>
|
||||||
|
<fileset dir="${velocity.lib}" includes="${velocity.jarfile}"/>
|
||||||
|
</copy>
|
||||||
|
<copy file="conf/dynamo-venice.xml" tofile="assembly/venice/WEB-INF/dynamo.xml"/>
|
||||||
|
<copy file="conf/logging-venice.xml" tofile="assembly/venice/WEB-INF/logging.xml"/>
|
||||||
|
<copy file="conf/web-venice.xml" tofile="assembly/venice/WEB-INF/web.xml"/>
|
||||||
|
<copy todir="assembly/venice/WEB-INF">
|
||||||
|
<fileset dir="venice-data" includes="**/*"/>
|
||||||
|
</copy>
|
||||||
|
<copy todir="assembly/venice">
|
||||||
|
<fileset dir="venice-web" includes="**/*"/>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"assemble-venice-sso-sp" - Pseudo-target that creates the directory structure
|
||||||
|
for Venice, with configuration as a SourceID-SSO
|
||||||
|
Service Provider.
|
||||||
|
============================================================================ -->
|
||||||
|
|
||||||
|
<target name="assemble-venice-sso-sp" depends="init,all-jars" if="sourceid.present">
|
||||||
|
<mkdir dir="assembly/venice-sp"/>
|
||||||
|
<mkdir dir="assembly/venice-sp/WEB-INF/classes"/>
|
||||||
|
<mkdir dir="assembly/venice-sp/WEB-INF/lib"/>
|
||||||
|
<mkdir dir="assembly/venice-sp/WEB-INF/modules"/>
|
||||||
|
<mkdir dir="assembly/venice-sp/WEB-INF/xsd"/>
|
||||||
|
<copy todir="assembly/venice-sp/WEB-INF/classes" preservelastmodified="yes">
|
||||||
|
<fileset dir="${sourceid.base}/conf">
|
||||||
|
<include name="commons-logging.properties"/>
|
||||||
|
<include name="ApplicationResources.properties"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
<copy todir="assembly/venice-sp/WEB-INF/lib">
|
||||||
|
<fileset dir="jars" includes="venice-sso-helper.jar,venice-base.jar,dynamo-framework.jar,baseutil.jar"/>
|
||||||
|
<fileset dir="drivers" includes="*.jar"/>
|
||||||
|
<fileset dir="${bsf.lib}" includes="${bsf.jarfile}"/>
|
||||||
|
<fileset dir="${collections.lib}" includes="${collections.jarfile}"/>
|
||||||
|
<fileset dir="${commlang.lib}" includes="${commlang.jarfile}"/>
|
||||||
|
<fileset dir="${rhino.lib}" includes="${rhino.jarfile}"/>
|
||||||
|
<fileset dir="${log4j.lib}" includes="${log4j.jarfile}"/>
|
||||||
|
<fileset dir="${velocity.lib}" includes="${velocity.jarfile}"/>
|
||||||
|
<fileset dir="${sourceid.base}" includes="sourceid-sso.jar"/>
|
||||||
|
<fileset dir="${sourceid.base}/webapp/WEB-INF/lib">
|
||||||
|
<include name="axis-ant.jar"/>
|
||||||
|
<include name="axis.jar"/>
|
||||||
|
<include name="castor-0.9.4.2-xml.jar"/>
|
||||||
|
<include name="commons-discovery.jar"/>
|
||||||
|
<include name="commons-logging.jar"/>
|
||||||
|
<include name="jaxrpc.jar"/>
|
||||||
|
<include name="saaj.jar"/>
|
||||||
|
<include name="wsdl4j.jar"/>
|
||||||
|
<include name="xalan.jar"/>
|
||||||
|
<include name="xml-apis.jar"/>
|
||||||
|
<include name="xmlsec.jar"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
<copy todir="assembly/venice-sp/WEB-INF/xsd" preservelastmodified="yes">
|
||||||
|
<fileset dir="${sourceid.base}/conf" includes="*.xsd"/>
|
||||||
|
</copy>
|
||||||
|
<copy todir="assembly/venice-sp/WEB-INF">
|
||||||
|
<fileset dir="conf-sso/sp">
|
||||||
|
<include name="logging.xml"/>
|
||||||
|
<include name="dynamo.xml"/>
|
||||||
|
<include name="web.xml"/>
|
||||||
|
<include name="sourceid-sso.xml"/>
|
||||||
|
<include name="sourceid-sso-providers.xml"/>
|
||||||
|
<include name="venice-sp.keystore"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
<copy file="${sourceid.base}/conf/server-config.wsdd" todir="assembly/venice-sp/WEB-INF"
|
||||||
|
preservelastmodified="yes"/>
|
||||||
|
<copy todir="assembly/venice-sp/WEB-INF">
|
||||||
|
<fileset dir="venice-data" includes="**/*"/>
|
||||||
|
</copy>
|
||||||
|
<copy todir="assembly/venice-sp/WEB-INF" overwrite="yes">
|
||||||
|
<fileset dir="venice-data-sso/sp" includes="**/*"/>
|
||||||
|
</copy>
|
||||||
|
<copy todir="assembly/venice-sp">
|
||||||
|
<fileset dir="venice-web" includes="**/*"/>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"all-assemblies" - Pseudo-target that assembles all Web application directory
|
||||||
|
structures.
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="all-assemblies" depends="init,assemble-test-app,assemble-venice,assemble-venice-sso-sp"/>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"all" - Pseudo-target that builds everything.
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="all" depends="init,all-jars,all-assemblies"/>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"javadoc" - Builds JavaDocs for the entire system.
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="javadoc">
|
||||||
|
<mkdir dir="javadocs"/>
|
||||||
|
<javadoc destdir="javadocs" access="package" source="1.4"
|
||||||
|
packagenames="com.silverwrist.util.*,com.silverwrist.dynamo.*,com.silverwrist.venice.*">
|
||||||
|
<sourcepath>
|
||||||
|
<pathelement location="src/baseutil"/>
|
||||||
|
<pathelement location="src/dynamo-framework"/>
|
||||||
|
<pathelement location="src/venice-base"/>
|
||||||
|
</sourcepath>
|
||||||
|
<classpath>
|
||||||
|
<path refid="base.build.path"/>
|
||||||
|
</classpath>
|
||||||
|
</javadoc>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- ============================================================================
|
||||||
|
"clean" - Cleans up all stuff that was built
|
||||||
|
============================================================================ -->
|
||||||
|
<target name="clean">
|
||||||
|
<delete dir="workingarea"/>
|
||||||
|
<delete dir="jars"/>
|
||||||
|
<delete dir="assembly"/>
|
||||||
|
<delete dir="javadocs"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</project>
|
33
conf-sso/extra-db-mysql.sql
Normal file
33
conf-sso/extra-db-mysql.sql
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
#
|
||||||
|
|
||||||
|
USE venice;
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Table Creation
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# The table which stores federations for a user ID. Each user ID may federate to one or more providers.
|
||||||
|
CREATE TABLE sso_federate (
|
||||||
|
uid INT NOT NULL,
|
||||||
|
provider VARCHAR(249) NOT NULL,
|
||||||
|
local_name VARCHAR(249) NOT NULL,
|
||||||
|
remote_name VARCHAR(249) NOT NULL,
|
||||||
|
PRIMARY KEY (uid, provider),
|
||||||
|
UNIQUE INDEX by_local (provider, local_name),
|
||||||
|
UNIQUE INDEX by_remote (provider, remote_name)
|
||||||
|
);
|
182
conf-sso/sp/dynamo.xml
Normal file
182
conf-sso/sp/dynamo.xml
Normal file
|
@ -0,0 +1,182 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<configuration>
|
||||||
|
|
||||||
|
<!-- Low-level Dynamo application container configuration -->
|
||||||
|
<control>
|
||||||
|
<background-threads normal="2" low="2"/>
|
||||||
|
<resource-root>${code.path}</resource-root>
|
||||||
|
<url-rewrite-rules>
|
||||||
|
<rule type="ABSOLUTE" encode="false">${url}</rule>
|
||||||
|
<rule type="SERVLET" encode="true">${context.path}/${url}</rule>
|
||||||
|
<rule type="IMAGE" encode="false">${context.path}/images/${url}</rule>
|
||||||
|
<rule type="IMAGEDATA" encode="false">${context.path}/imagedata/${url}</rule>
|
||||||
|
<rule type="FRAME" encode="true">${context.path}/frame/${url}</rule>
|
||||||
|
</url-rewrite-rules>
|
||||||
|
</control>
|
||||||
|
|
||||||
|
<!-- The database connection pool -->
|
||||||
|
<dbconnection name="data" classname="com.silverwrist.dynamo.db.DatabaseConnectionPool">
|
||||||
|
<dbtype>mysql</dbtype>
|
||||||
|
<!-- driver name is the new MySQL Connector for Java - replaces org.gjt.mm.mysql.Driver -->
|
||||||
|
<driver>com.mysql.jdbc.Driver</driver>
|
||||||
|
<uri>jdbc:mysql://localhost/venice</uri>
|
||||||
|
<username>veniceuser</username>
|
||||||
|
<password>XYZZY0099</password>
|
||||||
|
<connections initial="5" max="20" busywait="true"/>
|
||||||
|
<initialize test="true"/>
|
||||||
|
</dbconnection>
|
||||||
|
|
||||||
|
<!-- Infrastructure objects -->
|
||||||
|
<object name="connector" classname="com.silverwrist.dynamo.app.ConnectionManager" priority="0">
|
||||||
|
<connection-point name="srm_proxy" interface="com.silverwrist.dynamo.db.UserProxyManagement"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="module-manager" classname="com.silverwrist.dynamo.module.ModuleManager" priority="0">
|
||||||
|
<module-directory>${code.path}/modules</module-directory>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- Data-driven objects -->
|
||||||
|
<object name="nscache" classname="com.silverwrist.dynamo.db.NamespaceCacheObject" priority="0">
|
||||||
|
<database connection="data"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="srm" classname="com.silverwrist.dynamo.security.SRMObject" priority="1">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<user-manager cpoint="srm_proxy"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="globals" classname="com.silverwrist.dynamo.db.GlobalDataManagerObject" priority="2">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<security object="srm"/>
|
||||||
|
<block-cache hardlimit="5" softlimit="20"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="users" classname="com.silverwrist.dynamo.db.UserManagerObject" priority="2">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<security object="srm"/>
|
||||||
|
<connect-proxy-services cpoint="srm_proxy"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="images" classname="com.silverwrist.dynamo.db.ImageStoreObject" priority="2">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="audit" classname="com.silverwrist.dynamo.security.SystemAuditManager" priority="3">
|
||||||
|
<database connection="data" namespaces="nscache" userproxy="users"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- Presentation and interface objects -->
|
||||||
|
<object name="remapper" classname="com.silverwrist.dynamo.servlet.RemapperData" priority="0">
|
||||||
|
<remap path="/verifyemail">
|
||||||
|
<param name="tgt">top.js.vs</param>
|
||||||
|
<target type="SERVLET">verify_email.js.vs?tgt=${tgt}</target>
|
||||||
|
</remap>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="velocity" classname="com.silverwrist.dynamo.velocity.VelocityRenderer" priority="0">
|
||||||
|
<resource-prefix>/velocity</resource-prefix>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="xmlrpc" classname="com.silverwrist.dynamo.xmlrpc.XmlRpcSubSystem"
|
||||||
|
priority="-10" maxAge="3600">
|
||||||
|
<dispatch method="validator1\.\w+" classname="com.silverwrist.dynamo.xmlrpc.Validator1Suite"/>
|
||||||
|
<dispatch method="venice:siteinfo" classname="com.silverwrist.dynamo.xmlrpc.ScriptDispatcher">
|
||||||
|
<script>/xmlrpc/siteinfo.js</script>
|
||||||
|
<session param="0"/>
|
||||||
|
<metadata-file>/xmlrpc/siteinfo-metadata.xml</metadata-file>
|
||||||
|
</dispatch>
|
||||||
|
<dispatch method="venice:session\.create" classname="com.silverwrist.venice.xmlrpc.VeniceCreateSession"/>
|
||||||
|
<dispatch method="venice:session\.\w+" classname="com.silverwrist.dynamo.xmlrpc.ScriptDispatcher">
|
||||||
|
<script>/xmlrpc/session.js</script>
|
||||||
|
<session param="0"/>
|
||||||
|
<metadata-file>/xmlrpc/session-metadata.xml</metadata-file>
|
||||||
|
</dispatch>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="dialog" classname="com.silverwrist.dynamo.dialog.DialogManager" priority="0">
|
||||||
|
<resource-prefix>/dialogs</resource-prefix>
|
||||||
|
<resource-dialog-cache hardlimit="5" softlimit="20"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="mail" classname="com.silverwrist.dynamo.mail.MailSubSystem" priority="10">
|
||||||
|
<global-properties object="globals"
|
||||||
|
namespace="http://www.silverwrist.com/NS/venice/2002/12/28/mail.properties"/>
|
||||||
|
<smtp-host property="smtp.host"/>
|
||||||
|
<system-mail-name property="system.mail.from.name"/>
|
||||||
|
<system-mail-addr property="system.mail.from.addr"/>
|
||||||
|
<mailer property="mailer.name"/>
|
||||||
|
<template-resource-prefix>/mailmessages</template-resource-prefix>
|
||||||
|
<user-disclaimer block="user.disclaimer"/>
|
||||||
|
<user-info-header property="user.info.header"/>
|
||||||
|
<signature block="signature"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- Venice-layer objects -->
|
||||||
|
|
||||||
|
<object name="user-default-ns" classname="com.silverwrist.venice.app.UserDefaultNamespaceHolder" priority="50"/>
|
||||||
|
|
||||||
|
<object name="venice-session" classname="com.silverwrist.venice.session.VeniceSessionManager" priority="50">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
<user-manager object="users"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-menus" classname="com.silverwrist.venice.menu.MenuManager" priority="100">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<security object="srm"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-frame" classname="com.silverwrist.venice.frame.FrameAssembler" priority="101">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
<providers menu="venice-menus"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-content" classname="com.silverwrist.venice.content.StandardContentSupplier" priority="100">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-buttons" classname="com.silverwrist.venice.content.ButtonSupplier" priority="100">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-userphoto" classname="com.silverwrist.venice.content.UserPhotoRenderer" priority="100">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-dlg-manager" classname="com.silverwrist.venice.dialog.VeniceDialogManager" priority="101">
|
||||||
|
<providers button="venice-buttons" content="venice-content"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-auditor" classname="com.silverwrist.venice.app.StartupShutdownAuditor" priority="100"/>
|
||||||
|
|
||||||
|
<!-- Additional objects for SourceID interface -->
|
||||||
|
|
||||||
|
<object name="sso" classname="com.silverwrist.venice.sourceid.FederationManagerObject" priority="20">
|
||||||
|
<database connection="data" userproxy="users"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- The Venice application layer -->
|
||||||
|
<application name="venice" classname="com.silverwrist.venice.app.VeniceApplication">
|
||||||
|
<stylesheet-mappings>
|
||||||
|
<stylesheet path="/stylesheet-base.css" prefix="base"/>
|
||||||
|
<stylesheet path="/stylesheet-advanced.css" prefix="adv"/>
|
||||||
|
</stylesheet-mappings>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</configuration>
|
46
conf-sso/sp/logging.xml
Normal file
46
conf-sso/sp/logging.xml
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||||
|
|
||||||
|
<!-- Define the standard file appender. -->
|
||||||
|
<appender name="STDLOG" class="org.apache.log4j.RollingFileAppender">
|
||||||
|
<param name="File" value="/home/erbo/code/nvx/venice-sp.log"/>
|
||||||
|
<param name="Append" value="true"/>
|
||||||
|
<param name="MaxFileSize" value="10MB"/>
|
||||||
|
<param name="MaxBackupIndex" value="5"/>
|
||||||
|
<layout class="org.apache.log4j.PatternLayout">
|
||||||
|
<param name="ConversionPattern" value="%d %-5p %c{2} [%t %x] - %m%n"/>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
|
||||||
|
<layout class="org.apache.log4j.PatternLayout">
|
||||||
|
<param name="ConversionPattern" value="[%t] %-5p %c %x - %m%n"/>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- Define the root configuration for logging. -->
|
||||||
|
<root>
|
||||||
|
<priority value="debug"/>
|
||||||
|
<appender-ref ref="STDLOG"/>
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</log4j:configuration>
|
59
conf-sso/sp/sourceid-sso-providers.xml
Normal file
59
conf-sso/sp/sourceid-sso-providers.xml
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<ProviderDirectory xmlns:lib="http://projectliberty.org/schemas/core/2002/12"
|
||||||
|
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
|
||||||
|
xmlns="http://www.sourceid.org/schemas/sso/providers/2002/11">
|
||||||
|
<!--
|
||||||
|
Sample Identity Provider Descriptor. If this instance of SourceID-SSO is configured to
|
||||||
|
operate in the "sp" role, then the entry below describes an Identity Provider with which
|
||||||
|
we are federated. If this instance is configured to operate in the "idp" role, then the entry
|
||||||
|
below will be ignored.
|
||||||
|
-->
|
||||||
|
<lib:IDPDescriptor xmlns:lib="http://projectliberty.org/schemas/core/2002/12"
|
||||||
|
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
||||||
|
<!--
|
||||||
|
Customize the following line to match the ProviderID of the remote provider; if the other
|
||||||
|
provider is SourceID-SSO, then the ProviderID below should match the <provider-id> element
|
||||||
|
in the other deployment's sourceid-sso.xml.
|
||||||
|
-->
|
||||||
|
<lib:ProviderID>SourceID-Sample-IDP</lib:ProviderID>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The following KeyInfo represents the public key contained in the sample "sourceid.keystore"
|
||||||
|
file bundled with SourceID-SSO
|
||||||
|
-->
|
||||||
|
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
||||||
|
<ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
||||||
|
<ds:X509Certificate xmlns:ds="http://www.w3.org/2000/09/xmldsig#">MIICSjCCAbMCBD4coSAwDQYJKoZIhvcNAQEEBQAwbDEQMA4GA1UEBhMHVW5rbm93bjEQMA4GA1UECBMHVW5rbm93bjEQMA4GA1UEBxMHVW5rbm93bjEQMA4GA1UEChMHVW5rbm93bjEQMA4GA1UECxMHVW5rbm93bjEQMA4GA1UEAxMHVW5rbm93bjAeFw0wMzAxMDgyMjA3MjhaFw0wMzA0MDgyMjA3MjhaMGwxEDAOBgNVBAYTB1Vua25vd24xEDAOBgNVBAgTB1Vua25vd24xEDAOBgNVBAcTB1Vua25vd24xEDAOBgNVBAoTB1Vua25vd24xEDAOBgNVBAsTB1Vua25vd24xEDAOBgNVBAMTB1Vua25vd24wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMJhokczPBJlZe48d5oKZiX6vo7DBU5b54t9JjSHLOEZd0XK5w81BY4iX8QADMc7GyTrqDDrehfh4S5eQO89Fll50D4f6HpSI2QGtionDrj3kuET9nW9n98IzWc3eiLLH+5q3VGm04rylo4PTnJCeMYmDRqYJkWR1xQbNsrv9HHJAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAI16O969XJkYRJaTiPXMcJg8XRM9oHKqc4L6YEDXGvnQ8NfTPDuJEzKIcU8QWNnprcY+MOue+O2YvP7u9NQuKK4zDA14CcIRb8G+VMLFa2A+BYiD66yIBWsb89YNFYnvH379wGp+ankQBTdljpgFo6Bt+fXmZxB6mToBdXy0h5b8=</ds:X509Certificate>
|
||||||
|
</ds:X509Data>
|
||||||
|
</ds:KeyInfo>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The endpoints in the following URL's are correct for services offered by SourceID-SSO.
|
||||||
|
If federating this installation with another instance of SourceID-SSO, then all you need to do
|
||||||
|
is customize the URL's to match your deployment (e.g. replace "http://localhost:9080/sso-sample-idp"
|
||||||
|
with your server name and servlet context).
|
||||||
|
-->
|
||||||
|
|
||||||
|
<lib:SoapEndpoint>http://localhost:8080/sso-sample-idp/sso/soap/endpoint</lib:SoapEndpoint>
|
||||||
|
<lib:SingleLogoutServiceURL>http://localhost:8080/sso-sample-idp/sso/logout</lib:SingleLogoutServiceURL>
|
||||||
|
<lib:SingleLogoutServiceReturnURL>http://localhost:8080/sso-sample-idp/sso/logout</lib:SingleLogoutServiceReturnURL>
|
||||||
|
<lib:FederationTerminationServiceURL>http://localhost:8080/sso-sample-idp/sso/fedterm</lib:FederationTerminationServiceURL>
|
||||||
|
<lib:FederationTerminationServiceReturnURL>http://localhost:8080/sso-sample-idp/sso/fedterm</lib:FederationTerminationServiceReturnURL>
|
||||||
|
<lib:SingleSignOnServiceURL>http://localhost:8080/sso-sample-idp/sso/authn</lib:SingleSignOnServiceURL>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The following profile declarations indicate the variants of the Liberty Protocol which
|
||||||
|
this provider can speak.
|
||||||
|
-->
|
||||||
|
<lib:RegisterNameIdentifierProtocolProfile>http://projectliberty.org/profiles/rni-sp-soap</lib:RegisterNameIdentifierProtocolProfile>
|
||||||
|
<lib:FederationTerminationNotificationProtocolProfile>http://projectliberty.org/profiles/fedterm-sp-soap</lib:FederationTerminationNotificationProtocolProfile>
|
||||||
|
<lib:FederationTerminationNotificationProtocolProfile>http://projectliberty.org/profiles/fedterm-sp-http</lib:FederationTerminationNotificationProtocolProfile>
|
||||||
|
<lib:SingleLogoutProtocolProfile>http://projectliberty.org/profiles/slo-sp-soap</lib:SingleLogoutProtocolProfile>
|
||||||
|
<lib:SingleLogoutProtocolProfile>http://projectliberty.org/profiles/slo-sp-http</lib:SingleLogoutProtocolProfile>
|
||||||
|
<lib:SingleSignOnProtocolProfile>http://projectliberty.org/profiles/brws-art</lib:SingleSignOnProtocolProfile>
|
||||||
|
<lib:SingleSignOnProtocolProfile>http://projectliberty.org/profiles/brws-post</lib:SingleSignOnProtocolProfile>
|
||||||
|
<lib:SingleSignOnProtocolProfile>http://projectliberty.org/profiles/wml-post</lib:SingleSignOnProtocolProfile>
|
||||||
|
<lib:SingleSignOnProtocolProfile>http://projectliberty.org/profiles/lecp</lib:SingleSignOnProtocolProfile>
|
||||||
|
</lib:IDPDescriptor>
|
||||||
|
|
||||||
|
</ProviderDirectory>
|
68
conf-sso/sp/sourceid-sso.xml
Normal file
68
conf-sso/sp/sourceid-sso.xml
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<SourceID-SSO>
|
||||||
|
<!-- See SourceID-SSO documentation for more detailed documentation for these options -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The unique ProviderID of this installation. The value here should appear in other sites'
|
||||||
|
<SPDescriptor> or <IDPDescriptor> elements describing this site.
|
||||||
|
-->
|
||||||
|
<provider-id>Venice-SSO-SP</provider-id>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The role of this site with respect to the Liberty Protocol; valid values are "sp" and "idp".
|
||||||
|
-->
|
||||||
|
<provider-role>sp</provider-role>
|
||||||
|
<provider-directory>/WEB-INF/sourceid-sso-providers.xml</provider-directory>
|
||||||
|
|
||||||
|
<exception-handlers>
|
||||||
|
<default>/sourceid/errorHandler.js.vs</default>
|
||||||
|
</exception-handlers>
|
||||||
|
|
||||||
|
<signing-key>
|
||||||
|
<keystore-path>/WEB-INF/venice-sp.keystore</keystore-path>
|
||||||
|
<keystore-password>numenor</keystore-password>
|
||||||
|
<key-alias>mykey</key-alias>
|
||||||
|
<key-password>mithrandir</key-password>
|
||||||
|
</signing-key>
|
||||||
|
|
||||||
|
<!-- none of these matter for a Service Provider -->
|
||||||
|
<idp-authentication-uri>/idp/logon.jsp</idp-authentication-uri>
|
||||||
|
<idp-authn-lifespan>1800</idp-authn-lifespan>
|
||||||
|
<idp-logout-render-page>/idp/idpLogoutRender.jsp</idp-logout-render-page>
|
||||||
|
<idp-logout-done-image>/idp/checkmark.png</idp-logout-done-image>
|
||||||
|
<idp-post-assertion-render-page>/idp/idpPost.jsp</idp-post-assertion-render-page>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Here, you may optionally specify a Session-context attribute which SourceID-SSO should remove whenever
|
||||||
|
a user is logged off (either via a browser-based front-channel, or via a SOAP-based backchannel). SourceID-SSO
|
||||||
|
will already cleanup it's own session tracking info for the user, effectively logging them out of SourceID-SSO.
|
||||||
|
By putting an attribute key here, you can have SourceID-SSO log the user out of your application as well.
|
||||||
|
Future versions of SourceID-SSO will also support JAAS-based login/logout.
|
||||||
|
|
||||||
|
The sample value below works for the sample JSP-based application distributed with SourceID-SSO.
|
||||||
|
-->
|
||||||
|
<remove-session-attribute-on-logout>dynamo.session</remove-session-attribute-on-logout>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
When generating or consuming assertions, tolerances for "Not Before" and "Not On or After" are encoded in the
|
||||||
|
assertion document. Liberty Protocol recommends 1 minute for "Not Before", and 5 minutes for "Not On Or After".
|
||||||
|
Enter the number of SECONDS for these tolerances below (default values should work).
|
||||||
|
-->
|
||||||
|
<assert-tolerance-not-before>60</assert-tolerance-not-before>
|
||||||
|
<assert-tolerance-not-on-or-after>300</assert-tolerance-not-on-or-after>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Here, set the AccountHandler implementation class. The default configuration
|
||||||
|
is to use the "in-memory handler", which is really for demo and testing purposes only,
|
||||||
|
as it does not connect to any actual persistent storage. The SourceID-SSO User's Guide
|
||||||
|
describes how to implement an AccountHandler for your user directory. You may also use
|
||||||
|
the provided JDBC Account Handler, with simple table mappings described in the file
|
||||||
|
sourceid-sso-jdbc.xml. Or for LDAP access, use the JNDI Account Handler, with attribute
|
||||||
|
mappings described in the file sourceid-sso-jndi.xml.
|
||||||
|
-->
|
||||||
|
<account-handler>com.silverwrist.venice.sourceid.VeniceAccountHandler</account-handler>
|
||||||
|
|
||||||
|
<artifact-handler>org.sourceid.sso.handlers.ArtifactHandlerInMemoryImpl</artifact-handler>
|
||||||
|
|
||||||
|
</SourceID-SSO>
|
||||||
|
|
37
conf-sso/sp/sp-descriptor.xml
Normal file
37
conf-sso/sp/sp-descriptor.xml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<ProviderDirectory xmlns:lib="http://projectliberty.org/schemas/core/2002/12"
|
||||||
|
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
|
||||||
|
xmlns="http://www.sourceid.org/schemas/sso/providers/2002/11">
|
||||||
|
|
||||||
|
<lib:SPDescriptor xmlns:lib="http://projectliberty.org/schemas/core/2002/12"
|
||||||
|
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
||||||
|
<lib:ProviderID>Venice-SSO-SP</lib:ProviderID>
|
||||||
|
|
||||||
|
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
||||||
|
<ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
||||||
|
<ds:X509Certificate xmlns:ds="http://www.w3.org/2000/09/xmldsig#">MIICbjCCAdcCBD7AlmwwDQYJKoZIhvcNAQEEBQAwfjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNPMQ8wDQYDVQQHEwZEZW52ZXIxIzAhBgNVBAoTGlNpbHZlcndyaXN0IERlc2lnbiBTdHVkaW9zMRQwEgYDVQQLEwtEZXZlbG9wbWVudDEWMBQGA1UEAxMNRXJpYyBCb3dlcnNveDAeFw0wMzA1MTMwNjUzMzJaFw0wMzA4MTEwNjUzMzJaMH4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDTzEPMA0GA1UEBxMGRGVudmVyMSMwIQYDVQQKExpTaWx2ZXJ3cmlzdCBEZXNpZ24gU3R1ZGlvczEUMBIGA1UECxMLRGV2ZWxvcG1lbnQxFjAUBgNVBAMTDUVyaWMgQm93ZXJzb3gwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALvjYZPJwt16vTVIKleltTVDyvswVr2vCd9aHg7rKPhNKN+iVS2XY+Y5IopgcVtshQx/SbWnPNldtpGtFewaSQzCud/Lhja1xoGO/nTbjRr7MrPlR3yub8KO90tgslZ9yjEPZDWDEr3Y59ieDpMtAnYjS2GQ2LFRHq63kzd4AXg1AgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAVhJqkLZd59BiTjvRF0ZtBKXe+kxnvyclc0MeIzkzGFmnpMuSpSyZ3LlYp0uvFn5OADM6KkXj7DgXIqb1bqIvXmlwDds+oO3KL+WdHBO9KHW0KjR2jpIujpmJ8Eaf/cefcOxxA00CMrwBeL8EXyAaynpcT78nrT5iN3FZwMkBi9o=</ds:X509Certificate>
|
||||||
|
</ds:X509Data>
|
||||||
|
</ds:KeyInfo>
|
||||||
|
|
||||||
|
<lib:AssertionConsumerServiceURL>http://localhost:8080/venice-sp/sso/authnRequest</lib:AssertionConsumerServiceURL>
|
||||||
|
<lib:SoapEndpoint>http://localhost:8080/venice-sp/sso/soap/endpoint</lib:SoapEndpoint>
|
||||||
|
<lib:SingleLogoutServiceURL>http://localhost:8080/venice-sp/sso/logout</lib:SingleLogoutServiceURL>
|
||||||
|
<lib:SingleLogoutServiceReturnURL>http://localhost:8080/venice-sp/sso/logout</lib:SingleLogoutServiceReturnURL>
|
||||||
|
<lib:FederationTerminationServiceURL>http://localhost:8080/venice-sp/sso/fedterm</lib:FederationTerminationServiceURL>
|
||||||
|
<lib:FederationTerminationServiceReturnURL>http://localhost:8080/venice-sp/sso/fedterm</lib:FederationTerminationServiceReturnURL>
|
||||||
|
|
||||||
|
<lib:FederationTerminationNotificationProtocolProfile>http://projectliberty.org/profiles/fedterm-idp-soap</lib:FederationTerminationNotificationProtocolProfile>
|
||||||
|
<lib:FederationTerminationNotificationProtocolProfile>http://projectliberty.org/profiles/fedterm-idp-http</lib:FederationTerminationNotificationProtocolProfile>
|
||||||
|
<lib:SingleLogoutProtocolProfile>http://projectliberty.org/profiles/slo-idp-soap</lib:SingleLogoutProtocolProfile>
|
||||||
|
<lib:SingleLogoutProtocolProfile>http://projectliberty.org/profiles/slo-idp-http</lib:SingleLogoutProtocolProfile>
|
||||||
|
<lib:SingleLogoutProtocolProfile>http://projectliberty.org/profiles/slo-idp-http-get</lib:SingleLogoutProtocolProfile>
|
||||||
|
<lib:RegisterNameIdentifierProtocolProfile>http://projectliberty.org/profiles/rni-idp-soap</lib:RegisterNameIdentifierProtocolProfile>
|
||||||
|
<lib:RegisterNameIdentifierServiceURL>http://localhost:9080/sourceid-sso/sso/rni</lib:RegisterNameIdentifierServiceURL>
|
||||||
|
<lib:RegisterNameIdentifierServiceReturnURL>http://localhost:9080/sourceid-sso/sso/rni</lib:RegisterNameIdentifierServiceReturnURL>
|
||||||
|
<lib:RegisterNameIdentifierProtocolProfile>http://projectliberty.org/profiles/rni-idp-http</lib:RegisterNameIdentifierProtocolProfile>
|
||||||
|
<lib:AuthnRequestsSigned>false</lib:AuthnRequestsSigned>
|
||||||
|
|
||||||
|
</lib:SPDescriptor>
|
||||||
|
|
||||||
|
</ProviderDirectory>
|
BIN
conf-sso/sp/venice-sp.keystore
Normal file
BIN
conf-sso/sp/venice-sp.keystore
Normal file
Binary file not shown.
335
conf-sso/sp/web.xml
Normal file
335
conf-sso/sp/web.xml
Normal file
|
@ -0,0 +1,335 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<!DOCTYPE web-app
|
||||||
|
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||||
|
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||||
|
<web-app>
|
||||||
|
<display-name>Venice Web Communities System</display-name>
|
||||||
|
<description>
|
||||||
|
Venice Web Communities System (TODO: fill out description)
|
||||||
|
Contains SourceID-SSO, configured as Service Provider
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<!-- Context parameters -->
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>logging.config</param-name>
|
||||||
|
<param-value>WEB-INF/logging.xml</param-value>
|
||||||
|
<description>
|
||||||
|
The path and file name of the Log4J logger configuration file, relative to the application root.
|
||||||
|
</description>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>dynamo.config</param-name>
|
||||||
|
<param-value>WEB-INF/dynamo.xml</param-value>
|
||||||
|
<description>
|
||||||
|
The path and file name of the base Dynamo configuration file, relative to the application root.
|
||||||
|
The default, if not specified, is "WEB-INF/dynamo.xml".
|
||||||
|
</description>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>SSO.config.attrs</param-name>
|
||||||
|
<param-value>object=sso</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<!-- Servlet definitions -->
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>ScriptExec</servlet-name>
|
||||||
|
<description>Executes a scripting file as a servlet.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.servlet.ScriptExecServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>remove.extension</param-name>
|
||||||
|
<param-value>vs</param-value>
|
||||||
|
<description>
|
||||||
|
The extension which is used in the servlet mapping to distinguish scripts to execute. This
|
||||||
|
extension is removed from the servlet path to create the script name.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
<init-param>
|
||||||
|
<param-name>script.prefix</param-name>
|
||||||
|
<param-value>/scripts</param-value>
|
||||||
|
<description>
|
||||||
|
The resource prefix to use for scripts. This is prepended to the servlet path to create the
|
||||||
|
script name which is executed.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>XmlRpc</servlet-name>
|
||||||
|
<description>Executes XML-RPC requests.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.xmlrpc.XmlRpcServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>subsystem.object</param-name>
|
||||||
|
<param-value>xmlrpc</param-value>
|
||||||
|
<description>
|
||||||
|
The object name of the XML-RPC subsystem object. Must match the name configured for the
|
||||||
|
com.silverwrist.dynamo.xmlrpc.XmlRpcSubSystem object in dynamo.xml.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>Remapper</servlet-name>
|
||||||
|
<description>Remaps URLs to other URLs programmatically.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.servlet.RemapperServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>data.object</param-name>
|
||||||
|
<param-value>remapper</param-value>
|
||||||
|
<description>
|
||||||
|
The object name of the remapper data object. Must match the name configured for the
|
||||||
|
com.silverwrist.dynamo.servlet.RemapperData object in dynamo.xml.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>Image</servlet-name>
|
||||||
|
<description>Serves up images from the ImageStore.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.servlet.ImageServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>image.store</param-name>
|
||||||
|
<param-value>images</param-value>
|
||||||
|
<description>
|
||||||
|
The object name of the image store object. Must match the name configured for the
|
||||||
|
com.silverwrist.dynamo.db.ImageStoreObject object in dynamo.xml.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>StyleSheet</servlet-name>
|
||||||
|
<description>Serves up CSS stylesheets for use by the frame.</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.frame.StyleSheetServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>Frame</servlet-name>
|
||||||
|
<description>Frames static pages within the outer Venice frame.</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.servlet.FrameServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>content.prefix</param-name>
|
||||||
|
<param-value>static</param-value>
|
||||||
|
<description>
|
||||||
|
The prefix to apply to the static content path before retrieving it. Interpreted
|
||||||
|
relative to the Web application root (i.e. where Web content normally gets linked from).
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
<init-param>
|
||||||
|
<param-name>cache.hard.limit</param-name>
|
||||||
|
<param-value>5</param-value>
|
||||||
|
<description>
|
||||||
|
Maximum number of documents that will be hard-cached by this servlet. Must be at least 1.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
<init-param>
|
||||||
|
<param-name>cache.soft.limit</param-name>
|
||||||
|
<param-value>10</param-value>
|
||||||
|
<description>
|
||||||
|
Maximum number of documents that will be soft-cached by this servlet. Will always be at least
|
||||||
|
twice the number of hard-cached documents.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>PasswordRecovery</servlet-name>
|
||||||
|
<description>Used to access the password recovery feature; changes user passwords.</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.session.PasswordRecoveryServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>User</servlet-name>
|
||||||
|
<description>Displays user profiles.</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.servlet.UserServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- BEGIN SourceID-SSO Servlets -->
|
||||||
|
|
||||||
|
<!-- SourceID-SSO Manager Servlet (configuration is loaded here) -->
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>SourceID-SSO-Manager</servlet-name>
|
||||||
|
<description>Loads configuration at boot time, and provides instrumentation and admin control</description>
|
||||||
|
<servlet-class>org.sourceid.sso.servlets.Manager</servlet-class>
|
||||||
|
<load-on-startup>15</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- SourceID-SSO Authenticator Servlet -->
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>SourceID-SSO-Authenticator</servlet-name>
|
||||||
|
<description>Provides Identity Provider (IDP) Authentication Services</description>
|
||||||
|
<servlet-class>org.sourceid.sso.servlets.Authenticator</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- SourceID-SSO AuthnRequestor Servlet -->
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>SourceID-SSO-AuthnRequestor</servlet-name>
|
||||||
|
<description>Provides Service Provider (SP) Authentication Request Services</description>
|
||||||
|
<servlet-class>org.sourceid.sso.servlets.AuthnRequestor</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- SourceID-SSO Federation Terminator Servlet -->
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>SourceID-SSO-FederationTerminator</servlet-name>
|
||||||
|
<description>Provides Federation Termination Services</description>
|
||||||
|
<servlet-class>org.sourceid.sso.servlets.FederationTerminator</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- SourceID-SSO Federation Terminator Servlet -->
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>SourceID-SSO-Logout</servlet-name>
|
||||||
|
<description>Provides Single Logout Services</description>
|
||||||
|
<servlet-class>org.sourceid.sso.servlets.Logout</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- SourceID-SSO Federation Terminator Servlet -->
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>SourceID-SSO-NameRegistrar</servlet-name>
|
||||||
|
<description>Provides Single Logout Services</description>
|
||||||
|
<servlet-class>org.sourceid.sso.servlets.NameRegistrar</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- Apache Axis (SOAP) Servlets -->
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>AxisServlet</servlet-name>
|
||||||
|
<display-name>Apache-Axis Servlet</display-name>
|
||||||
|
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>AdminServlet</servlet-name>
|
||||||
|
<display-name>Axis Admin Servlet</display-name>
|
||||||
|
<servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
|
||||||
|
<load-on-startup>100</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>SOAPMonitorService</servlet-name>
|
||||||
|
<display-name>SOAPMonitorService</display-name>
|
||||||
|
<servlet-class>org.apache.axis.monitor.SOAPMonitorService</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>SOAPMonitorPort</param-name>
|
||||||
|
<param-value>5001</param-value>
|
||||||
|
</init-param>
|
||||||
|
<load-on-startup>100</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- END SourceID-SSO Servlets -->
|
||||||
|
|
||||||
|
<!-- Servlet mappings -->
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ScriptExec</servlet-name>
|
||||||
|
<url-pattern>*.vs</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>XmlRpc</servlet-name>
|
||||||
|
<url-pattern>/RPC2</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Remapper</servlet-name>
|
||||||
|
<url-pattern>/verifyemail</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Image</servlet-name>
|
||||||
|
<url-pattern>/imagedata/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>StyleSheet</servlet-name>
|
||||||
|
<url-pattern>/stylesheet-base.css</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>StyleSheet</servlet-name>
|
||||||
|
<url-pattern>/stylesheet-advanced.css</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Frame</servlet-name>
|
||||||
|
<url-pattern>/frame/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>PasswordRecovery</servlet-name>
|
||||||
|
<url-pattern>/passrecovery/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>User</servlet-name>
|
||||||
|
<url-pattern>/user/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- BEGIN SourceID-SSO Servlet Mappings -->
|
||||||
|
|
||||||
|
<!-- Authenticator Servlet -->
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>SourceID-SSO-Authenticator</servlet-name>
|
||||||
|
<url-pattern>/sso/authn</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- AuthnRequestor Servlet -->
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>SourceID-SSO-AuthnRequestor</servlet-name>
|
||||||
|
<url-pattern>/sso/authnRequest</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- FederationTerminator Servlet -->
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>SourceID-SSO-FederationTerminator</servlet-name>
|
||||||
|
<url-pattern>/sso/fedterm</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- Logout Servlet -->
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>SourceID-SSO-Logout</servlet-name>
|
||||||
|
<url-pattern>/sso/logout</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- NameRegistrar Servlet -->
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>SourceID-SSO-NameRegistrar</servlet-name>
|
||||||
|
<url-pattern>/sso/rni</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- SOAP Handler -->
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>AxisServlet</servlet-name>
|
||||||
|
<url-pattern>/sso/soap/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- END SourceID-SSO Servlet Mappings -->
|
||||||
|
|
||||||
|
<!-- Global parameters for the HTTP session -->
|
||||||
|
<session-config>
|
||||||
|
<session-timeout>60</session-timeout> <!-- 1 hour -->
|
||||||
|
</session-config>
|
||||||
|
|
||||||
|
<!-- The list of "welcome files" for the application -->
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>default.jsp</welcome-file>
|
||||||
|
<welcome-file>index.html</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
|
||||||
|
</web-app>
|
236
conf/db-init-mysql.sql
Normal file
236
conf/db-init-mysql.sql
Normal file
|
@ -0,0 +1,236 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Database Creation
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
DROP DATABASE IF EXISTS dbname;
|
||||||
|
CREATE DATABASE dbname;
|
||||||
|
USE dbname;
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Table Creation
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# The "namespace cache" table, used to map string namespaces (used in the code) to integer IDs
|
||||||
|
# (used in the database).
|
||||||
|
CREATE TABLE namespaces (
|
||||||
|
nsid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
namespace VARCHAR(255) BINARY NOT NULL,
|
||||||
|
UNIQUE INDEX on_namespace (namespace)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The global properties table.
|
||||||
|
CREATE TABLE globalprop (
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
prop_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
prop_value VARCHAR(255),
|
||||||
|
PRIMARY KEY (nsid, prop_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The global "blocks" table, used to store fragments of text/HTML for later use.
|
||||||
|
CREATE TABLE globalblock (
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
block_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
block TEXT,
|
||||||
|
PRIMARY KEY (nsid, block_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The main user information table.
|
||||||
|
CREATE TABLE users (
|
||||||
|
uid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
username VARCHAR(64) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL,
|
||||||
|
is_anon TINYINT DEFAULT 0,
|
||||||
|
locked TINYINT DEFAULT 0,
|
||||||
|
nospam TINYINT DEFAULT 0,
|
||||||
|
created DATETIME NOT NULL,
|
||||||
|
last_accessed DATETIME,
|
||||||
|
UNIQUE INDEX on_username (username)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The user authentication data table. We identify authentication methods by namespace ID
|
||||||
|
# and name, and provide "source data" to allow multiple sources for the same type of
|
||||||
|
# authentication (such as browser cookies for multiple browsers).
|
||||||
|
CREATE TABLE userauth (
|
||||||
|
uid INT NOT NULL,
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
method VARCHAR(255) BINARY NOT NULL,
|
||||||
|
source_data VARCHAR(255),
|
||||||
|
auth_data VARCHAR(255),
|
||||||
|
PRIMARY KEY (uid, nsid, method)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The user properties table.
|
||||||
|
CREATE TABLE userprop (
|
||||||
|
uid INT NOT NULL,
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
prop_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
prop_value VARCHAR(255),
|
||||||
|
PRIMARY KEY (uid, nsid, prop_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The groups table.
|
||||||
|
CREATE TABLE groups (
|
||||||
|
gid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
groupname VARCHAR(64) NOT NULL,
|
||||||
|
gaclid INT NOT NULL DEFAULT -1,
|
||||||
|
UNIQUE INDEX on_groupname (groupname)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The group membership table.
|
||||||
|
CREATE TABLE groupmembers (
|
||||||
|
gid INT NOT NULL,
|
||||||
|
uid INT NOT NULL,
|
||||||
|
PRIMARY KEY (gid, uid),
|
||||||
|
UNIQUE INDEX reverse_index (uid, gid)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The group properties table.
|
||||||
|
CREATE TABLE groupprop (
|
||||||
|
gid INT NOT NULL,
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
prop_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
prop_value VARCHAR(255),
|
||||||
|
PRIMARY KEY (gid, nsid, prop_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The main ACL table. Each ACL has a numeric ID, a name, an unordered collection of owners (which may
|
||||||
|
# be groups or users), and an ordered collection of entries (ACEs).
|
||||||
|
CREATE TABLE acl (
|
||||||
|
aclid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
aclname VARCHAR(255) NOT NULL,
|
||||||
|
INDEX on_name (aclname)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The table of owners for ACLs. Each ACL has one or more owners.
|
||||||
|
# Flags Bit 0: 0=user, 1=group
|
||||||
|
CREATE TABLE aclowner (
|
||||||
|
aclid INT NOT NULL,
|
||||||
|
ownerid INT NOT NULL,
|
||||||
|
flags TINYINT NOT NULL,
|
||||||
|
INDEX on_acl (aclid)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The table mapping ACLs to ACEs. Each ACL has zero or more ACEs.
|
||||||
|
CREATE TABLE acldata (
|
||||||
|
aclid INT NOT NULL,
|
||||||
|
seq INT NOT NULL,
|
||||||
|
aceid INT NOT NULL,
|
||||||
|
PRIMARY KEY (aclid, seq)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The main ACE table. Each ACE has a numeric ID, a principal reference (which may be a user or
|
||||||
|
# group ID), a "negative" flag, and an unordered collection of permissions.
|
||||||
|
# Flags Bit 0: 0=user, 1=group
|
||||||
|
# Flags Bit 4: 0=positive ACE, 1=negative ACE
|
||||||
|
CREATE TABLE ace (
|
||||||
|
aceid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
pri INT,
|
||||||
|
flags TINYINT NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
|
||||||
|
# The table mapping permissions into ACEs. Permissions are identified by namespace and name.
|
||||||
|
CREATE TABLE acedata (
|
||||||
|
aceid INT NOT NULL,
|
||||||
|
perm_nsid INT NOT NULL,
|
||||||
|
perm_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
INDEX on_ace (aceid)
|
||||||
|
);
|
||||||
|
|
||||||
|
# Global security data table.
|
||||||
|
CREATE TABLE globalsec (
|
||||||
|
admin_uid INT NOT NULL,
|
||||||
|
admin_gid INT NOT NULL,
|
||||||
|
global_aclid INT NOT NULL,
|
||||||
|
alluser_gid INT NOT NULL,
|
||||||
|
verified_gid INT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
# The audit information table. Each audit "event" can have up to 8 properties defined with it,
|
||||||
|
# which are serialized as other "properties."
|
||||||
|
CREATE TABLE audit (
|
||||||
|
record BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
on_date DATETIME NOT NULL,
|
||||||
|
event INT NOT NULL,
|
||||||
|
uid INT NOT NULL,
|
||||||
|
subid INT NOT NULL DEFAULT 0,
|
||||||
|
ip VARCHAR(48),
|
||||||
|
prop0 VARCHAR(255),
|
||||||
|
prop1 VARCHAR(255),
|
||||||
|
prop2 VARCHAR(255),
|
||||||
|
prop3 VARCHAR(255),
|
||||||
|
prop4 VARCHAR(255),
|
||||||
|
prop5 VARCHAR(255),
|
||||||
|
prop6 VARCHAR(255),
|
||||||
|
prop7 VARCHAR(255),
|
||||||
|
INDEX by_date (on_date),
|
||||||
|
INDEX sub_view (subid, on_date)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The table where events are assigned "event IDs" in the master audit record,
|
||||||
|
# to cut down on space usage in the audit table. Event IDs can be predefined
|
||||||
|
# at database create time, or defined dynamically, or both.
|
||||||
|
CREATE TABLE auditevent (
|
||||||
|
eventid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
event_nsid INT NOT NULL,
|
||||||
|
event_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
descr TINYTEXT,
|
||||||
|
UNIQUE INDEX by_event (event_nsid, event_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The image store table. This is used to store relatively small images like
|
||||||
|
# user photos and logos.
|
||||||
|
CREATE TABLE imagestore (
|
||||||
|
imageid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
typecode INT NOT NULL,
|
||||||
|
ownerid INT NOT NULL,
|
||||||
|
ownerflag TINYINT NOT NULL DEFAULT 0,
|
||||||
|
mimetype VARCHAR(128),
|
||||||
|
length INT,
|
||||||
|
data MEDIUMBLOB
|
||||||
|
);
|
||||||
|
|
||||||
|
# The image type table, used to differentiate between images stored in the table.
|
||||||
|
CREATE TABLE imagetype (
|
||||||
|
typecode INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
name VARCHAR(255) BINARY NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Set table access rights
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# this is a test only - remove when we go to production
|
||||||
|
GRANT ALL PRIVILEGES ON dbname.*
|
||||||
|
TO erbo@localhost IDENTIFIED BY 'meesatest'
|
||||||
|
WITH GRANT OPTION;
|
||||||
|
GRANT ALL PRIVILEGES ON dbname.*
|
||||||
|
TO erbo@'10.29.99.%' IDENTIFIED BY 'meesatest'
|
||||||
|
WITH GRANT OPTION;
|
||||||
|
|
||||||
|
GRANT INSERT, DELETE, UPDATE, SELECT ON dbname.*
|
||||||
|
TO testuser@localhost IDENTIFIED BY 'TestPassword';
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Initialization data
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
INSERT INTO users (uid, username, email, is_anon, nospam, created)
|
||||||
|
VALUES (1, 'Anonymous_Honyak', 'nobody@localhost', 1, 1, '2002-12-15 12:00:00');
|
70
conf/dynamo-test.xml
Normal file
70
conf/dynamo-test.xml
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<configuration>
|
||||||
|
|
||||||
|
<control>
|
||||||
|
<background-threads normal="2" low="2"/>
|
||||||
|
<resource-root>${code.path}</resource-root>
|
||||||
|
<url-rewrite-rules>
|
||||||
|
<rule type="ABSOLUTE" encode="false">${url}</rule>
|
||||||
|
<rule type="SERVLET" encode="true">${context.path}/${url}</rule>
|
||||||
|
</url-rewrite-rules>
|
||||||
|
</control>
|
||||||
|
|
||||||
|
<dbconnection name="data" classname="com.silverwrist.dynamo.db.DatabaseConnectionPool">
|
||||||
|
<dbtype>mysql</dbtype>
|
||||||
|
<!-- driver name is the new MySQL Connector for Java - replaces org.gjt.mm.mysql.Driver -->
|
||||||
|
<driver>com.mysql.jdbc.Driver</driver>
|
||||||
|
<uri>jdbc:mysql://localhost/dbname</uri>
|
||||||
|
<username>testuser</username>
|
||||||
|
<password>TestPassword</password>
|
||||||
|
<connections initial="5" max="20" busywait="true"/>
|
||||||
|
</dbconnection>
|
||||||
|
|
||||||
|
<object name="module-manager" classname="com.silverwrist.dynamo.module.ModuleManager" priority="0">
|
||||||
|
<module-directory>${code.path}/modules</module-directory>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="velocity" classname="com.silverwrist.dynamo.velocity.VelocityRenderer" priority="0">
|
||||||
|
<resource-prefix>/velocity</resource-prefix>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="xmlrpc" classname="com.silverwrist.dynamo.xmlrpc.XmlRpcSubSystem"
|
||||||
|
priority="-10" maxAge="3600">
|
||||||
|
<dispatch method="validator1\.\w+" classname="com.silverwrist.dynamo.xmlrpc.Validator1Suite"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="mail" classname="com.silverwrist.dynamo.mail.MailSubSystem" priority="-100">
|
||||||
|
<smtp-host>janelane</smtp-host>
|
||||||
|
<system-mail-name>Venice Mail System</system-mail-name>
|
||||||
|
<system-mail-addr>nobody@delenn.silverwrist.internal</system-mail-addr>
|
||||||
|
<mailer>Venice AutoMail System</mailer>
|
||||||
|
<template-resource-prefix>/mailmessages</template-resource-prefix>
|
||||||
|
<user-disclaimer><![CDATA[
|
||||||
|
Message sent via Venice Web Communities System - <http://venice.sourceforge.net>
|
||||||
|
The Venice Project is not responsible for the contents of this message
|
||||||
|
Report abuses to: <abuse@example.com>
|
||||||
|
]]></user-disclaimer>
|
||||||
|
<user-info-header>X-Venice-User-Info</user-info-header>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<application name="test_app" classname="com.silverwrist.dynamo.test.TestApplication">
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</configuration>
|
175
conf/dynamo-venice.xml
Normal file
175
conf/dynamo-venice.xml
Normal file
|
@ -0,0 +1,175 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<configuration>
|
||||||
|
|
||||||
|
<!-- Low-level Dynamo application container configuration -->
|
||||||
|
<control>
|
||||||
|
<background-threads normal="2" low="2"/>
|
||||||
|
<resource-root>${code.path}</resource-root>
|
||||||
|
<url-rewrite-rules>
|
||||||
|
<rule type="ABSOLUTE" encode="false">${url}</rule>
|
||||||
|
<rule type="SERVLET" encode="true">${context.path}/${url}</rule>
|
||||||
|
<rule type="IMAGE" encode="false">${context.path}/images/${url}</rule>
|
||||||
|
<rule type="IMAGEDATA" encode="false">${context.path}/imagedata/${url}</rule>
|
||||||
|
<rule type="FRAME" encode="true">${context.path}/frame/${url}</rule>
|
||||||
|
</url-rewrite-rules>
|
||||||
|
</control>
|
||||||
|
|
||||||
|
<!-- The database connection pool -->
|
||||||
|
<dbconnection name="data" classname="com.silverwrist.dynamo.db.DatabaseConnectionPool">
|
||||||
|
<dbtype>mysql</dbtype>
|
||||||
|
<!-- driver name is the new MySQL Connector for Java - replaces org.gjt.mm.mysql.Driver -->
|
||||||
|
<driver>com.mysql.jdbc.Driver</driver>
|
||||||
|
<uri>jdbc:mysql://localhost/venice</uri>
|
||||||
|
<username>veniceuser</username>
|
||||||
|
<password>XYZZY0099</password>
|
||||||
|
<connections initial="5" max="20" busywait="true"/>
|
||||||
|
</dbconnection>
|
||||||
|
|
||||||
|
<!-- Infrastructure objects -->
|
||||||
|
<object name="connector" classname="com.silverwrist.dynamo.app.ConnectionManager" priority="0">
|
||||||
|
<connection-point name="srm_proxy" interface="com.silverwrist.dynamo.db.UserProxyManagement"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="module-manager" classname="com.silverwrist.dynamo.module.ModuleManager" priority="0">
|
||||||
|
<module-directory>${code.path}/modules</module-directory>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- Data-driven objects -->
|
||||||
|
<object name="nscache" classname="com.silverwrist.dynamo.db.NamespaceCacheObject" priority="0">
|
||||||
|
<database connection="data"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="srm" classname="com.silverwrist.dynamo.security.SRMObject" priority="1">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<user-manager cpoint="srm_proxy"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="globals" classname="com.silverwrist.dynamo.db.GlobalDataManagerObject" priority="2">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<security object="srm"/>
|
||||||
|
<block-cache hardlimit="5" softlimit="20"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="users" classname="com.silverwrist.dynamo.db.UserManagerObject" priority="2">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<security object="srm"/>
|
||||||
|
<connect-proxy-services cpoint="srm_proxy"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="images" classname="com.silverwrist.dynamo.db.ImageStoreObject" priority="2">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="audit" classname="com.silverwrist.dynamo.security.SystemAuditManager" priority="3">
|
||||||
|
<database connection="data" namespaces="nscache" userproxy="users"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- Presentation and interface objects -->
|
||||||
|
<object name="remapper" classname="com.silverwrist.dynamo.servlet.RemapperData" priority="0">
|
||||||
|
<remap path="/verifyemail">
|
||||||
|
<param name="tgt">top.js.vs</param>
|
||||||
|
<target type="SERVLET">verify_email.js.vs?tgt=${tgt}</target>
|
||||||
|
</remap>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="velocity" classname="com.silverwrist.dynamo.velocity.VelocityRenderer" priority="0">
|
||||||
|
<resource-prefix>/velocity</resource-prefix>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="xmlrpc" classname="com.silverwrist.dynamo.xmlrpc.XmlRpcSubSystem"
|
||||||
|
priority="-10" maxAge="3600">
|
||||||
|
<dispatch method="validator1\.\w+" classname="com.silverwrist.dynamo.xmlrpc.Validator1Suite"/>
|
||||||
|
<dispatch method="venice:siteinfo" classname="com.silverwrist.dynamo.xmlrpc.ScriptDispatcher">
|
||||||
|
<script>/xmlrpc/siteinfo.js</script>
|
||||||
|
<session param="0"/>
|
||||||
|
<metadata-file>/xmlrpc/siteinfo-metadata.xml</metadata-file>
|
||||||
|
</dispatch>
|
||||||
|
<dispatch method="venice:session\.create" classname="com.silverwrist.venice.xmlrpc.VeniceCreateSession"/>
|
||||||
|
<dispatch method="venice:session\.\w+" classname="com.silverwrist.dynamo.xmlrpc.ScriptDispatcher">
|
||||||
|
<script>/xmlrpc/session.js</script>
|
||||||
|
<session param="0"/>
|
||||||
|
<metadata-file>/xmlrpc/session-metadata.xml</metadata-file>
|
||||||
|
</dispatch>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="dialog" classname="com.silverwrist.dynamo.dialog.DialogManager" priority="0">
|
||||||
|
<resource-prefix>/dialogs</resource-prefix>
|
||||||
|
<resource-dialog-cache hardlimit="5" softlimit="20"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="mail" classname="com.silverwrist.dynamo.mail.MailSubSystem" priority="10">
|
||||||
|
<global-properties object="globals"
|
||||||
|
namespace="http://www.silverwrist.com/NS/venice/2002/12/28/mail.properties"/>
|
||||||
|
<smtp-host property="smtp.host"/>
|
||||||
|
<system-mail-name property="system.mail.from.name"/>
|
||||||
|
<system-mail-addr property="system.mail.from.addr"/>
|
||||||
|
<mailer property="mailer.name"/>
|
||||||
|
<template-resource-prefix>/mailmessages</template-resource-prefix>
|
||||||
|
<user-disclaimer block="user.disclaimer"/>
|
||||||
|
<user-info-header property="user.info.header"/>
|
||||||
|
<signature block="signature"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- Venice-layer objects -->
|
||||||
|
|
||||||
|
<object name="user-default-ns" classname="com.silverwrist.venice.app.UserDefaultNamespaceHolder" priority="50"/>
|
||||||
|
|
||||||
|
<object name="venice-session" classname="com.silverwrist.venice.session.VeniceSessionManager" priority="50">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
<user-manager object="users"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-menus" classname="com.silverwrist.venice.menu.MenuManager" priority="100">
|
||||||
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<security object="srm"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-frame" classname="com.silverwrist.venice.frame.FrameAssembler" priority="101">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
<providers menu="venice-menus"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-content" classname="com.silverwrist.venice.content.StandardContentSupplier" priority="100">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-buttons" classname="com.silverwrist.venice.content.ButtonSupplier" priority="100">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-userphoto" classname="com.silverwrist.venice.content.UserPhotoRenderer" priority="100">
|
||||||
|
<global-properties object="globals"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-dlg-manager" classname="com.silverwrist.venice.dialog.VeniceDialogManager" priority="101">
|
||||||
|
<providers button="venice-buttons" content="venice-content"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<object name="venice-auditor" classname="com.silverwrist.venice.app.StartupShutdownAuditor" priority="100"/>
|
||||||
|
|
||||||
|
<!-- The Venice application layer -->
|
||||||
|
<application name="venice" classname="com.silverwrist.venice.app.VeniceApplication">
|
||||||
|
<stylesheet-mappings>
|
||||||
|
<stylesheet path="/stylesheet-base.css" prefix="base"/>
|
||||||
|
<stylesheet path="/stylesheet-advanced.css" prefix="adv"/>
|
||||||
|
</stylesheet-mappings>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</configuration>
|
39
conf/logging-test.xml
Normal file
39
conf/logging-test.xml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||||
|
|
||||||
|
<!-- Define the standard file appender. -->
|
||||||
|
<appender name="STDLOG" class="org.apache.log4j.RollingFileAppender">
|
||||||
|
<param name="File" value="/home/erbo/code/nvx/testapp.log"/>
|
||||||
|
<param name="Append" value="true"/>
|
||||||
|
<param name="MaxFileSize" value="10MB"/>
|
||||||
|
<param name="MaxBackupIndex" value="5"/>
|
||||||
|
<layout class="org.apache.log4j.PatternLayout">
|
||||||
|
<param name="ConversionPattern" value="%d %-5p %c{2} [%t %x] - %m%n"/>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- Define the root configuration for logging. -->
|
||||||
|
<root>
|
||||||
|
<priority value="debug"/>
|
||||||
|
<appender-ref ref="STDLOG"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</log4j:configuration>
|
39
conf/logging-venice.xml
Normal file
39
conf/logging-venice.xml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||||
|
|
||||||
|
<!-- Define the standard file appender. -->
|
||||||
|
<appender name="STDLOG" class="org.apache.log4j.RollingFileAppender">
|
||||||
|
<param name="File" value="/home/erbo/code/nvx/venice.log"/>
|
||||||
|
<param name="Append" value="true"/>
|
||||||
|
<param name="MaxFileSize" value="10MB"/>
|
||||||
|
<param name="MaxBackupIndex" value="5"/>
|
||||||
|
<layout class="org.apache.log4j.PatternLayout">
|
||||||
|
<param name="ConversionPattern" value="%d %-5p %c{2} [%t %x] - %m%n"/>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- Define the root configuration for logging. -->
|
||||||
|
<root>
|
||||||
|
<priority value="debug"/>
|
||||||
|
<appender-ref ref="STDLOG"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</log4j:configuration>
|
31
conf/std_render_macro_library.vm
Normal file
31
conf/std_render_macro_library.vm
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#*
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
*#
|
||||||
|
|
||||||
|
## Define macros around the "std" object.
|
||||||
|
#macro( formatURL $type $url )$std.formatURL($type,$url)#end
|
||||||
|
|
||||||
|
#macro( encodeHTML $data )$std.encodeHTML($data)#end
|
||||||
|
|
||||||
|
#macro( encodeURL $data )$std.encodeURL($data)#end
|
||||||
|
|
||||||
|
#macro( render $obj )$std.renderObject($obj)#end
|
||||||
|
|
||||||
|
#macro( renderDialog $dlg )$std.renderDialog($dlg)#end
|
||||||
|
|
||||||
|
#macro( stacktrace $thr )$std.getStackTrace($thr)#end
|
||||||
|
|
573
conf/venice-db-init-mysql.sql
Normal file
573
conf/venice-db-init-mysql.sql
Normal file
|
@ -0,0 +1,573 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Database Creation
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
DROP DATABASE IF EXISTS venice;
|
||||||
|
CREATE DATABASE venice;
|
||||||
|
USE venice;
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Table Creation
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# The "namespace cache" table, used to map string namespaces (used in the code) to integer IDs
|
||||||
|
# (used in the database).
|
||||||
|
CREATE TABLE namespaces (
|
||||||
|
nsid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
namespace VARCHAR(255) BINARY NOT NULL,
|
||||||
|
UNIQUE INDEX on_namespace (namespace)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The global properties table.
|
||||||
|
CREATE TABLE globalprop (
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
prop_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
prop_value VARCHAR(255),
|
||||||
|
PRIMARY KEY (nsid, prop_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The global "blocks" table, used to store fragments of text/HTML for later use.
|
||||||
|
CREATE TABLE globalblock (
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
block_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
block TEXT,
|
||||||
|
PRIMARY KEY (nsid, block_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The main user information table.
|
||||||
|
CREATE TABLE users (
|
||||||
|
uid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
username VARCHAR(64) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL,
|
||||||
|
is_anon TINYINT DEFAULT 0,
|
||||||
|
locked TINYINT DEFAULT 0,
|
||||||
|
nospam TINYINT DEFAULT 0,
|
||||||
|
created DATETIME NOT NULL,
|
||||||
|
last_accessed DATETIME,
|
||||||
|
UNIQUE INDEX on_username (username)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The user authentication data table. We identify authentication methods by namespace ID
|
||||||
|
# and name, and provide "source data" to allow multiple sources for the same type of
|
||||||
|
# authentication (such as browser cookies for multiple browsers).
|
||||||
|
CREATE TABLE userauth (
|
||||||
|
uid INT NOT NULL,
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
method VARCHAR(255) BINARY NOT NULL,
|
||||||
|
source_data VARCHAR(255),
|
||||||
|
auth_data VARCHAR(255),
|
||||||
|
PRIMARY KEY (uid, nsid, method)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The user properties table.
|
||||||
|
CREATE TABLE userprop (
|
||||||
|
uid INT NOT NULL,
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
prop_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
prop_value VARCHAR(255),
|
||||||
|
PRIMARY KEY (uid, nsid, prop_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The groups table.
|
||||||
|
CREATE TABLE groups (
|
||||||
|
gid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
groupname VARCHAR(64) NOT NULL,
|
||||||
|
gaclid INT NOT NULL DEFAULT -1,
|
||||||
|
UNIQUE INDEX on_groupname (groupname)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The group membership table.
|
||||||
|
CREATE TABLE groupmembers (
|
||||||
|
gid INT NOT NULL,
|
||||||
|
uid INT NOT NULL,
|
||||||
|
PRIMARY KEY (gid, uid),
|
||||||
|
UNIQUE INDEX reverse_index (uid, gid)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The group properties table.
|
||||||
|
CREATE TABLE groupprop (
|
||||||
|
gid INT NOT NULL,
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
prop_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
prop_value VARCHAR(255),
|
||||||
|
PRIMARY KEY (gid, nsid, prop_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The main ACL table. Each ACL has a numeric ID, a name, an unordered collection of owners (which may
|
||||||
|
# be groups or users), and an ordered collection of entries (ACEs).
|
||||||
|
CREATE TABLE acl (
|
||||||
|
aclid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
aclname VARCHAR(255) NOT NULL,
|
||||||
|
INDEX on_name (aclname)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The table of owners for ACLs. Each ACL has one or more owners.
|
||||||
|
# Flags Bit 0: 0=user, 1=group
|
||||||
|
CREATE TABLE aclowner (
|
||||||
|
aclid INT NOT NULL,
|
||||||
|
ownerid INT NOT NULL,
|
||||||
|
flags TINYINT NOT NULL,
|
||||||
|
INDEX on_acl (aclid)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The table mapping ACLs to ACEs. Each ACL has zero or more ACEs.
|
||||||
|
CREATE TABLE acldata (
|
||||||
|
aclid INT NOT NULL,
|
||||||
|
seq INT NOT NULL,
|
||||||
|
aceid INT NOT NULL,
|
||||||
|
PRIMARY KEY (aclid, seq)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The main ACE table. Each ACE has a numeric ID, a principal reference (which may be a user or
|
||||||
|
# group ID), a "negative" flag, and an unordered collection of permissions.
|
||||||
|
# Flags Bit 0: 0=user, 1=group
|
||||||
|
# Flags Bit 4: 0=positive ACE, 1=negative ACE
|
||||||
|
CREATE TABLE ace (
|
||||||
|
aceid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
pri INT,
|
||||||
|
flags TINYINT NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
|
||||||
|
# The table mapping permissions into ACEs. Permissions are identified by namespace and name.
|
||||||
|
CREATE TABLE acedata (
|
||||||
|
aceid INT NOT NULL,
|
||||||
|
perm_nsid INT NOT NULL,
|
||||||
|
perm_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
INDEX on_ace (aceid)
|
||||||
|
);
|
||||||
|
|
||||||
|
# Global security data table.
|
||||||
|
CREATE TABLE globalsec (
|
||||||
|
admin_uid INT NOT NULL,
|
||||||
|
admin_gid INT NOT NULL,
|
||||||
|
global_aclid INT NOT NULL,
|
||||||
|
alluser_gid INT NOT NULL,
|
||||||
|
verified_gid INT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
# The audit information table. Each audit "event" can have up to 8 properties defined with it,
|
||||||
|
# which are serialized as other "properties."
|
||||||
|
CREATE TABLE audit (
|
||||||
|
record BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
on_date DATETIME NOT NULL,
|
||||||
|
event INT NOT NULL,
|
||||||
|
uid INT NOT NULL,
|
||||||
|
subid INT NOT NULL DEFAULT 0,
|
||||||
|
ip VARCHAR(48),
|
||||||
|
prop0 VARCHAR(255),
|
||||||
|
prop1 VARCHAR(255),
|
||||||
|
prop2 VARCHAR(255),
|
||||||
|
prop3 VARCHAR(255),
|
||||||
|
prop4 VARCHAR(255),
|
||||||
|
prop5 VARCHAR(255),
|
||||||
|
prop6 VARCHAR(255),
|
||||||
|
prop7 VARCHAR(255),
|
||||||
|
INDEX by_date (on_date),
|
||||||
|
INDEX sub_view (subid, on_date)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The table where events are assigned "event IDs" in the master audit record,
|
||||||
|
# to cut down on space usage in the audit table. Event IDs can be predefined
|
||||||
|
# at database create time, or defined dynamically, or both.
|
||||||
|
CREATE TABLE auditevent (
|
||||||
|
eventid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
event_nsid INT NOT NULL,
|
||||||
|
event_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
descr TINYTEXT,
|
||||||
|
UNIQUE INDEX by_event (event_nsid, event_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# The image store table. This is used to store relatively small images like
|
||||||
|
# user photos and logos.
|
||||||
|
CREATE TABLE imagestore (
|
||||||
|
imageid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
typecode INT NOT NULL,
|
||||||
|
ownerid INT NOT NULL,
|
||||||
|
ownerflag TINYINT NOT NULL DEFAULT 0,
|
||||||
|
mimetype VARCHAR(128),
|
||||||
|
length INT,
|
||||||
|
data MEDIUMBLOB
|
||||||
|
);
|
||||||
|
|
||||||
|
# The image type table, used to differentiate between images stored in the table.
|
||||||
|
CREATE TABLE imagetype (
|
||||||
|
typecode INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
nsid INT NOT NULL,
|
||||||
|
name VARCHAR(255) BINARY NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
#### following this line are Venice-specific tables ####
|
||||||
|
|
||||||
|
# The table which defines menus.
|
||||||
|
CREATE TABLE menus (
|
||||||
|
menuid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
menu_nsid INT NOT NULL,
|
||||||
|
menu_name VARCHAR(255) BINARY NOT NULL,
|
||||||
|
title VARCHAR(255) NOT NULL,
|
||||||
|
subtitle VARCHAR(255) NULL,
|
||||||
|
UNIQUE INDEX by_name (menu_nsid, menu_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# Definitions of variables for menus.
|
||||||
|
CREATE TABLE menuvars (
|
||||||
|
menuid INT NOT NULL,
|
||||||
|
var_name VARCHAR(255) NOT NULL,
|
||||||
|
default_val VARCHAR(255) NULL,
|
||||||
|
PRIMARY KEY (menuid, var_name)
|
||||||
|
);
|
||||||
|
|
||||||
|
# Definitions of menu items.
|
||||||
|
CREATE TABLE menuitems (
|
||||||
|
menuid INT NOT NULL,
|
||||||
|
sequence INT NOT NULL,
|
||||||
|
itemtype VARCHAR(32) NOT NULL,
|
||||||
|
enable TINYINT NOT NULL DEFAULT 1,
|
||||||
|
indent INT NOT NULL DEFAULT 0,
|
||||||
|
text VARCHAR(255) NULL,
|
||||||
|
linktype VARCHAR(32) NULL,
|
||||||
|
link VARCHAR(255) NULL,
|
||||||
|
target VARCHAR(255) NULL,
|
||||||
|
title VARCHAR(255) NULL,
|
||||||
|
on_click VARCHAR(255) NULL,
|
||||||
|
perm_nsid INT NULL,
|
||||||
|
perm_name VARCHAR(255) BINARY NULL,
|
||||||
|
ifdef_var VARCHAR(255) NULL,
|
||||||
|
ifndef_var VARCHAR(255) NULL,
|
||||||
|
PRIMARY KEY (menuid, sequence)
|
||||||
|
);
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Set table access rights
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# this is a test only - remove when we go to production
|
||||||
|
GRANT ALL PRIVILEGES ON venice.*
|
||||||
|
TO erbo@localhost IDENTIFIED BY 'meesatest'
|
||||||
|
WITH GRANT OPTION;
|
||||||
|
|
||||||
|
GRANT INSERT, DELETE, UPDATE, SELECT, LOCK TABLES ON venice.*
|
||||||
|
TO veniceuser@localhost IDENTIFIED BY 'XYZZY0099';
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Initialization data
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Initial namespaces setup
|
||||||
|
INSERT INTO namespaces (nsid, namespace) VALUES
|
||||||
|
(1, 'http://www.silverwrist.com/NS/venice/2002/12/21/frame.look.and.feel' ),
|
||||||
|
(2, 'http://www.silverwrist.com/NS/venice/2002/12/22/stylesheets' ),
|
||||||
|
(3, 'http://www.silverwrist.com/NS/dynamo/2002/12/13/user.information' ),
|
||||||
|
(4, 'http://www.silverwrist.com/NS/dynamo/2002/12/27/group.permissions' ),
|
||||||
|
(5, 'http://www.silverwrist.com/NS/venice/2002/12/28/mail.properties' ),
|
||||||
|
(6, 'http://www.silverwrist.com/NS/venice/2002/12/28/content.look.and.feel'),
|
||||||
|
(7, 'http://www.silverwrist.com/NS/venice/2002/12/30/session.control' ),
|
||||||
|
(8, 'http://www.silverwrist.com/NS/venice/2002/12/31/system.events' ),
|
||||||
|
(9, 'http://www.silverwrist.com/NS/venice/2002/12/31/user.events' ),
|
||||||
|
(10, 'http://www.silverwrist.com/NS/venice/2002/12/31/user.settings' ),
|
||||||
|
(11, 'http://www.silverwrist.com/NS/venice/2002/12/31/user.profile' ),
|
||||||
|
(12, 'http://www.silverwrist.com/NS/venice/2003/01/03/system.mail.messages' );
|
||||||
|
|
||||||
|
# Initial global properties setup
|
||||||
|
INSERT INTO globalprop (nsid, prop_name, prop_value) VALUES
|
||||||
|
(1, 'site.title', '!Venice Test' ),
|
||||||
|
(1, 'optionset', '_OS:AC' ),
|
||||||
|
(1, 'site.url', '!http://localhost:8080/venice/' ),
|
||||||
|
(1, 'site.logo.url', '!temp/site-logo.jpg' ),
|
||||||
|
(1, 'site.logo.url.type', '!IMAGE' ),
|
||||||
|
(1, 'site.logo.width', 'I140' ),
|
||||||
|
(1, 'site.logo.height', 'I80' ),
|
||||||
|
(1, 'frame.template', '!frame.vm' ),
|
||||||
|
(1, 'footer.logo.scale', 'I100' ),
|
||||||
|
(1, 'page.icon.url', '!venice-icon.png' ),
|
||||||
|
(1, 'page.icon.url.type', '!IMAGE' ),
|
||||||
|
(1, 'page.icon.type', '!image/png' ),
|
||||||
|
(1, 'page.favicon.url', '!venice-favicon.ico' ),
|
||||||
|
(1, 'page.favicon.url.type', '!IMAGE' ),
|
||||||
|
(2, 'sheet.base.normal', '!stylesheets/normal_base.vm' ),
|
||||||
|
(2, 'sheet.adv.normal', '!stylesheets/adv_base.vm' ),
|
||||||
|
(5, 'smtp.host', '!localhost' ),
|
||||||
|
(5, 'system.mail.from.addr', '!nobody@delenn.silverwrist.internal'),
|
||||||
|
(5, 'system.mail.from.name', '!Venice Mail System' ),
|
||||||
|
(5, 'mailer.name', '!Venice AutoMail System' ),
|
||||||
|
(5, 'user.info.header', '!X-Venice-User-Info' ),
|
||||||
|
(6, 'subdir.buttons', '!buttons/classic' ),
|
||||||
|
(6, 'std.button.width', 'I80' ),
|
||||||
|
(6, 'std.button.height', 'I24' ),
|
||||||
|
(6, 'bn.cancel', '!cancel.jpg' ),
|
||||||
|
(6, 'bnc.cancel', '!Cancel' ),
|
||||||
|
(6, 'bn.create', '!create.jpg' ),
|
||||||
|
(6, 'bnc.create', '!Create' ),
|
||||||
|
(6, 'bn.i.accept', '!user_accept.jpg' ),
|
||||||
|
(6, 'bnc.i.accept', '!I Accept' ),
|
||||||
|
(6, 'bn.i.decline', '!user_decline.jpg' ),
|
||||||
|
(6, 'bnc.i.decline', '!I Decline' ),
|
||||||
|
(6, 'bn.login', '!login.jpg' ),
|
||||||
|
(6, 'bnc.login', '!Log In' ),
|
||||||
|
(6, 'bn.ok', '!ok.jpg' ),
|
||||||
|
(6, 'bnc.ok', '!OK' ),
|
||||||
|
(6, 'bn.reminder', '!reminder.jpg' ),
|
||||||
|
(6, 'bnc.reminder', '!Reminder' ),
|
||||||
|
(6, 'bn.send.again', '!send_again.jpg' ),
|
||||||
|
(6, 'bnc.send.again', '!Send Again' ),
|
||||||
|
(6, 'bn.send.email', '!send_email.jpg' ),
|
||||||
|
(6, 'bnc.send.email', '!Send E-Mail' ),
|
||||||
|
(6, 'bn.set', '!set.jpg' ),
|
||||||
|
(6, 'bnc.set', '!Set' ),
|
||||||
|
(6, 'bn.update', '!update.jpg' ),
|
||||||
|
(6, 'bnc.update', '!Update' ),
|
||||||
|
(6, 'user.agreement.title', '!Venice User Agreement' ),
|
||||||
|
(6, 'user.photo.width', 'I100' ),
|
||||||
|
(6, 'user.photo.height', 'I100' ),
|
||||||
|
(6, 'user.nophoto.url', '!photo_not_avail.gif' ),
|
||||||
|
(6, 'user.nophoto.url.type', '!IMAGE' ),
|
||||||
|
(7, 'session.init.script', '!/util/session_init.js' ),
|
||||||
|
(7, 'login.cookie', '!VeniceAuth' ),
|
||||||
|
(7, 'login.cookie.maxage', 'I365' ),
|
||||||
|
(7, 'password.recovery.time', 'I60' ),
|
||||||
|
(10, 'timezone', '_TZ:UTC' ),
|
||||||
|
(10, 'locale', '_LOC:en_US' ),
|
||||||
|
(10, 'admin.flags', '_OS:' ),
|
||||||
|
(11, 'privacy', '_OS:' ),
|
||||||
|
(12, 'confirm.message.title', '!Venice E-Mail Confirmation' ),
|
||||||
|
(12, 'password.change.message.title', '!Venice Password Changed' ),
|
||||||
|
(12, 'reminder.message.title', '!Venice Password Reminder Message' );
|
||||||
|
|
||||||
|
# Initial global blocks setup
|
||||||
|
INSERT INTO globalblock (nsid, block_name, block) VALUES
|
||||||
|
(1, 'footer',
|
||||||
|
'All trademarks and copyrights on this page are owned by their respective companies.
|
||||||
|
All messages posted by users on this page are owned by those users.
|
||||||
|
The rest: Copyright © 2002-2003 Silverwrist Design Studios, All Rights Reserved.
|
||||||
|
See our <a href="TODO">Policy Page</a> for our copyright and privacy policies.'),
|
||||||
|
(5, 'user.disclaimer',
|
||||||
|
'Message sent via Venice Web Communities System - <http://venice.sourceforge.net>
|
||||||
|
The Venice Project is not responsible for the contents of this message
|
||||||
|
Report abuses to: <abuse@example.com>'),
|
||||||
|
(5, 'signature',
|
||||||
|
'Venice - community services, conferencing and more. <http://venice.sourceforge.net>'),
|
||||||
|
(6, 'content.header',
|
||||||
|
'<span class="chdrtitle">$title</span>
|
||||||
|
#if( $subtitle )
|
||||||
|
<span class="chdrsubtitle">$subtitle</span>
|
||||||
|
#end
|
||||||
|
<hr align="left" size="2" width="90%" noshade="noshade" />'),
|
||||||
|
(6, 'std.bullet',
|
||||||
|
'<img src="#formatURL( "IMAGE" "purple-ball.gif" )" alt="*" width="14" height="14" border="0" />'),
|
||||||
|
(6, 'error.box',
|
||||||
|
'<p><table align="center" width="70%" border="1" cellpadding="2" cellspacing="1">
|
||||||
|
<tr valign="middle"><td class="errorhead">
|
||||||
|
#encodeHTML( $title )
|
||||||
|
</td></tr>
|
||||||
|
<tr valign="middle"><td class="errorbody">
|
||||||
|
<p>#encodeHTML( $message )</p>
|
||||||
|
<p>
|
||||||
|
#if( $back )
|
||||||
|
<a href="#formatURL( $backtype $back )">Go back.</a>
|
||||||
|
#else
|
||||||
|
Use your browser''s <b>Back</b> button to go back.
|
||||||
|
#end
|
||||||
|
</p>
|
||||||
|
</td></tr>
|
||||||
|
</table></p>
|
||||||
|
#if( $except )
|
||||||
|
<!--
|
||||||
|
#stacktrace( $except )
|
||||||
|
-->
|
||||||
|
#end'),
|
||||||
|
(6, 'user.agreement',
|
||||||
|
'Text of this agreement is to be determined.'),
|
||||||
|
(12, 'confirm.message',
|
||||||
|
'Welcome to the Venice Web Communities System! In order to fully activate your
|
||||||
|
account after you register or change your E-mail address, you must provide a
|
||||||
|
confirmation number to the system. Please enter this number into the "Confirm
|
||||||
|
E-mail Address" dialog on the system when indicated.
|
||||||
|
|
||||||
|
Your confirmation number for your account "$username" is $confnum.
|
||||||
|
|
||||||
|
Access the E-mail verification dialog at <http://localhost/venice/verifyemail>.
|
||||||
|
|
||||||
|
Thank you, and enjoy the Venice Web Communities System!
|
||||||
|
|
||||||
|
-- The Management'),
|
||||||
|
(12, 'password.change.message',
|
||||||
|
'The password for your account "$username" has been changed. The new
|
||||||
|
password is "$password".
|
||||||
|
|
||||||
|
You should log into Venice immediately and change the password to something
|
||||||
|
else. You can change the password for your account, once you are logged in,
|
||||||
|
by clicking on the "Profile" link in the top bar.
|
||||||
|
|
||||||
|
If you did NOT request a password change on your account, please notify the
|
||||||
|
system administrator IMMEDIATELY.
|
||||||
|
|
||||||
|
-- The Management'),
|
||||||
|
(12, 'reminder.message',
|
||||||
|
'Here is the password reminder for your account "$username" as you requested:
|
||||||
|
|
||||||
|
$reminder
|
||||||
|
|
||||||
|
If this reminder is not sufficient for you to remember what your password is,
|
||||||
|
then the system can change your password for you. To do so, please visit
|
||||||
|
the following URL:
|
||||||
|
|
||||||
|
http://localhost/venice/passrecovery/$uid/$auth
|
||||||
|
|
||||||
|
Your password will be changed and a new password will be E-mailed to you
|
||||||
|
at this address.
|
||||||
|
|
||||||
|
If you did NOT request a password reminder, then this message was sent
|
||||||
|
by someone attempting to access your account without your knowledge. Do
|
||||||
|
not panic! Nothing has happened to your account or password yet, but
|
||||||
|
please do notify the system administrator.
|
||||||
|
|
||||||
|
-- The Management');
|
||||||
|
|
||||||
|
# Initial users setup
|
||||||
|
# (UID 1 and 2)
|
||||||
|
INSERT INTO users (uid, username, email, is_anon, nospam, created) VALUES
|
||||||
|
(1, 'Anonymous_Honyak', 'nobody@localhost', 1, 1, '2002-12-15 12:00:00'),
|
||||||
|
(2, 'Administrator', 'root@localhost', 0, 0, '2002-12-26 18:00:00');
|
||||||
|
|
||||||
|
# Set up properties for Anonymous_Honyak.
|
||||||
|
INSERT INTO userprop (uid, nsid, prop_name, prop_value) VALUES
|
||||||
|
(1, 10, 'timezone', '_TZ:UTC' ),
|
||||||
|
(1, 10, 'locale', '_LOC:en_US'),
|
||||||
|
(1, 10, 'admin.flags', '_OS:A' ),
|
||||||
|
(1, 11, 'privacy', '_OS:' ),
|
||||||
|
(1, 11, 'name.given', '!Anonymous'),
|
||||||
|
(1, 11, 'name.family', '!Honyak' ),
|
||||||
|
(1, 11, 'locality', '!Nowhere' ),
|
||||||
|
(1, 11, 'region', '!XX' ),
|
||||||
|
(1, 11, 'postal.code', '!00000' ),
|
||||||
|
(1, 11, 'country', '_CTRY:US' );
|
||||||
|
|
||||||
|
# Add authentication for Administrator (no password by default)
|
||||||
|
INSERT INTO userauth (uid, nsid, method, source_data, auth_data) VALUES
|
||||||
|
(2, 3, 'default.hash.password', '', '');
|
||||||
|
|
||||||
|
# Set up properties for Administrator.
|
||||||
|
INSERT INTO userprop (uid, nsid, prop_name, prop_value) VALUES
|
||||||
|
(2, 10, 'timezone', '_TZ:UTC' ),
|
||||||
|
(2, 10, 'locale', '_LOC:en_US' ),
|
||||||
|
(2, 10, 'admin.flags', '_OS:' ),
|
||||||
|
(2, 11, 'privacy', '_OS:' ),
|
||||||
|
(2, 11, 'name.given', '!System' ),
|
||||||
|
(2, 11, 'name.family', '!Administrator'),
|
||||||
|
(2, 11, 'locality', '!Nowhere' ),
|
||||||
|
(2, 11, 'region', '!XX' ),
|
||||||
|
(2, 11, 'postal.code', '!00000' ),
|
||||||
|
(2, 11, 'country', '_CTRY:US' );
|
||||||
|
|
||||||
|
# Create a group for site administrators.
|
||||||
|
# (GID 1)
|
||||||
|
INSERT INTO groups (gid, groupname) VALUES (1, 'Site_Administration');
|
||||||
|
INSERT INTO groupmembers (gid, uid) VALUES (1, 2);
|
||||||
|
|
||||||
|
# Create an ACL for the site administrator group. The ACL is owned by Administrator
|
||||||
|
# and grants "add" and "remove" permissions to Administrator only.
|
||||||
|
# (ACL 1, ACE 1)
|
||||||
|
INSERT INTO acl (aclid, aclname) VALUES (1, 'Site_Administration');
|
||||||
|
INSERT INTO aclowner (aclid, ownerid, flags) VALUES (1, 2, 0);
|
||||||
|
INSERT INTO ace (aceid, pri, flags) VALUES (1, 2, 0);
|
||||||
|
INSERT INTO acldata (aclid, seq, aceid) VALUES (1, 0, 1);
|
||||||
|
INSERT INTO acedata (aceid, perm_nsid, perm_name) VALUES
|
||||||
|
(1, 4, 'add.member' ),
|
||||||
|
(1, 4, 'remove.member');
|
||||||
|
UPDATE groups SET gaclid = 1 WHERE gid = 1;
|
||||||
|
|
||||||
|
# Create the "all users" group.
|
||||||
|
# (GID 2)
|
||||||
|
INSERT INTO groups (gid, groupname) VALUES (2, 'All_Users');
|
||||||
|
INSERT INTO groupmembers (gid, uid) VALUES (2, 2);
|
||||||
|
|
||||||
|
# Create the "all verified users" group.
|
||||||
|
# (GID 3)
|
||||||
|
INSERT INTO groups (gid, groupname) VALUES (3, 'Verified_Users');
|
||||||
|
INSERT INTO groupmembers (gid, uid) VALUES (3, 2);
|
||||||
|
|
||||||
|
# Create the global ACL. This ACL is owned by the Administrator and grants
|
||||||
|
# permissions to the site administration group and to the Administrator specifically.
|
||||||
|
# (ACL 2, ACEs 2 and 3)
|
||||||
|
INSERT INTO acl (aclid, aclname) VALUES (2, 'Global_Permissions');
|
||||||
|
INSERT INTO aclowner (aclid, ownerid, flags) VALUES (2, 2, 0);
|
||||||
|
INSERT INTO ace (aceid, pri, flags) VALUES (2, 1, 1);
|
||||||
|
INSERT INTO acldata (aclid, seq, aceid) VALUES (2, 0, 2);
|
||||||
|
INSERT INTO acedata (aceid, perm_nsid, perm_name) VALUES
|
||||||
|
(2, 1, 'set.property' ),
|
||||||
|
(2, 1, 'set.block' ),
|
||||||
|
(2, 2, 'set.property' ),
|
||||||
|
(2, 3, 'edit.all' ),
|
||||||
|
(2, 3, 'bypass.email.verify'),
|
||||||
|
(2, 3, 'view.all' ),
|
||||||
|
(2, 5, 'set.property' ),
|
||||||
|
(2, 5, 'set.block' ),
|
||||||
|
(2, 6, 'set.property' ),
|
||||||
|
(2, 6, 'set.block' ),
|
||||||
|
(2, 7, 'set.property' ),
|
||||||
|
(2, 10, 'set.property' ),
|
||||||
|
(2, 10, 'remove.property' ),
|
||||||
|
(2, 11, 'set.property' ),
|
||||||
|
(2, 11, 'remove.property' ),
|
||||||
|
(2, 12, 'set.property' ),
|
||||||
|
(2, 12, 'set.block' );
|
||||||
|
INSERT INTO ace (aceid, pri, flags) VALUES (3, 2, 0);
|
||||||
|
INSERT INTO acldata (aclid, seq, aceid) VALUES (2, 1, 3);
|
||||||
|
INSERT INTO acedata (aceid, perm_nsid, perm_name) VALUES
|
||||||
|
(3, 1, 'remove.property'),
|
||||||
|
(3, 1, 'remove.block' ),
|
||||||
|
(3, 2, 'remove.property'),
|
||||||
|
(3, 5, 'remove.property'),
|
||||||
|
(3, 5, 'remove.block' ),
|
||||||
|
(3, 6, 'remove.property'),
|
||||||
|
(3, 6, 'remove.block' ),
|
||||||
|
(3, 7, 'remove.property'),
|
||||||
|
(3, 12, 'remove.property'),
|
||||||
|
(3, 12, 'remove.block' );
|
||||||
|
|
||||||
|
# Create the entries in the global security table.
|
||||||
|
INSERT INTO globalsec (admin_uid, admin_gid, global_aclid, alluser_gid, verified_gid)
|
||||||
|
VALUES (2, 1, 2, 2, 3);
|
||||||
|
|
||||||
|
# Insert some audit event type records.
|
||||||
|
INSERT INTO auditevent (eventid, event_nsid, event_name, descr) VALUES
|
||||||
|
(1, 8, 'system.startup', 'Venice Server Startup' ),
|
||||||
|
(2, 8, 'system.shutdown', 'Venice Server Shutdown' ),
|
||||||
|
(3, 9, 'login.ok', 'Successful User Login' ),
|
||||||
|
(4, 9, 'login.fail', 'Failed User Login' ),
|
||||||
|
(5, 9, 'verify.ok', 'Successful E-Mail Address Verification'),
|
||||||
|
(6, 9, 'verify.fail', 'Failed E-Mail Address Verification' ),
|
||||||
|
(7, 9, 'resend.confirm.email', 'Re-Sent E-Mail Confirmation Message' ),
|
||||||
|
(8, 9, 'send.confirm.email', 'Sent E-Mail Confirmation Message' ),
|
||||||
|
(9, 9, 'user.created', 'New User Created' );
|
||||||
|
|
||||||
|
# Insert some image types.
|
||||||
|
INSERT INTO imagetype (typecode, nsid, name) VALUES
|
||||||
|
(1, 11, 'user.photo');
|
||||||
|
|
||||||
|
#### following this line is initialization of Venice-specific tables ####
|
||||||
|
|
||||||
|
# Create the "global" menu.
|
||||||
|
INSERT INTO menus (menuid, menu_nsid, menu_name, title, subtitle)
|
||||||
|
VALUES (1, 1, 'fixed.menu', 'About This Site', NULL);
|
||||||
|
INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link) VALUES
|
||||||
|
(1, 0, 'TEXT', 'Documentation', 'ABSOLUTE', 'TODO' ),
|
||||||
|
(1, 1, 'TEXT', 'About Venice', 'FRAME', 'about-venice.html');
|
||||||
|
UPDATE menuitems SET enable = 0 WHERE menuid = 1 AND sequence = 0;
|
||||||
|
|
117
conf/web-test.xml
Normal file
117
conf/web-test.xml
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<!DOCTYPE web-app
|
||||||
|
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||||
|
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||||
|
<web-app>
|
||||||
|
<display-name>Dynamo Test Application</display-name>
|
||||||
|
<description>This is an application used to test components of the Dynamo framework.</description>
|
||||||
|
|
||||||
|
<!-- Context parameters -->
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>logging.config</param-name>
|
||||||
|
<param-value>WEB-INF/logging.xml</param-value>
|
||||||
|
<description>
|
||||||
|
The path and file name of the Log4J logger configuration file, relative to the application root.
|
||||||
|
</description>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>dynamo.config</param-name>
|
||||||
|
<param-value>WEB-INF/dynamo.xml</param-value>
|
||||||
|
<description>
|
||||||
|
The path and file name of the base Dynamo configuration file, relative to the application root.
|
||||||
|
The default, if not specified, is "WEB-INF/dynamo.xml".
|
||||||
|
</description>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<!-- Servlet definitions -->
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>ScriptExec</servlet-name>
|
||||||
|
<description>Executes a scripting file as a servlet.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.servlet.ScriptExecServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>remove.extension</param-name>
|
||||||
|
<param-value>vs</param-value>
|
||||||
|
<description>
|
||||||
|
The extension which is used in the servlet mapping to distinguish scripts to execute. This
|
||||||
|
extension is removed from the servlet path to create the script name.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
<init-param>
|
||||||
|
<param-name>script.prefix</param-name>
|
||||||
|
<param-value>/scripts</param-value>
|
||||||
|
<description>
|
||||||
|
The resource prefix to use for scripts. This is prepended to the servlet path to create the
|
||||||
|
script name which is executed.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>XmlRpc</servlet-name>
|
||||||
|
<description>Executes XML-RPC requests.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.xmlrpc.XmlRpcServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>subsystem.object</param-name>
|
||||||
|
<param-value>xmlrpc</param-value>
|
||||||
|
<description>
|
||||||
|
The object name of the XML-RPC subsystem object. Must match the name configured for the
|
||||||
|
com.silverwrist.dynamo.xmlrpc.XmlRpcSubSystem object in dynamo.xml.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>TestServlet1</servlet-name>
|
||||||
|
<description>Servlet test 1</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.test.TestServlet1</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>TestServlet2</servlet-name>
|
||||||
|
<description>Servlet test 2</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.test.TestServlet2</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- Servlet mappings -->
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ScriptExec</servlet-name>
|
||||||
|
<url-pattern>*.vs</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>XmlRpc</servlet-name>
|
||||||
|
<url-pattern>/RPC2</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>TestServlet1</servlet-name>
|
||||||
|
<url-pattern>/test1</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>TestServlet2</servlet-name>
|
||||||
|
<url-pattern>/test2</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
</web-app>
|
218
conf/web-venice.xml
Normal file
218
conf/web-venice.xml
Normal file
|
@ -0,0 +1,218 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
(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.mozilla.org/MPL/>.
|
||||||
|
|
||||||
|
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
language governing rights and limitations under the License.
|
||||||
|
|
||||||
|
The Original Code is the Venice Web Communities System.
|
||||||
|
|
||||||
|
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
|
||||||
|
Contributor(s):
|
||||||
|
-->
|
||||||
|
<!DOCTYPE web-app
|
||||||
|
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||||
|
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||||
|
<web-app>
|
||||||
|
<display-name>Venice Web Communities System</display-name>
|
||||||
|
<description>
|
||||||
|
Venice Web Communities System (TODO: fill out description)
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<!-- Context parameters -->
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>logging.config</param-name>
|
||||||
|
<param-value>WEB-INF/logging.xml</param-value>
|
||||||
|
<description>
|
||||||
|
The path and file name of the Log4J logger configuration file, relative to the application root.
|
||||||
|
</description>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<context-param>
|
||||||
|
<param-name>dynamo.config</param-name>
|
||||||
|
<param-value>WEB-INF/dynamo.xml</param-value>
|
||||||
|
<description>
|
||||||
|
The path and file name of the base Dynamo configuration file, relative to the application root.
|
||||||
|
The default, if not specified, is "WEB-INF/dynamo.xml".
|
||||||
|
</description>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<!-- Servlet definitions -->
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>ScriptExec</servlet-name>
|
||||||
|
<description>Executes a scripting file as a servlet.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.servlet.ScriptExecServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>remove.extension</param-name>
|
||||||
|
<param-value>vs</param-value>
|
||||||
|
<description>
|
||||||
|
The extension which is used in the servlet mapping to distinguish scripts to execute. This
|
||||||
|
extension is removed from the servlet path to create the script name.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
<init-param>
|
||||||
|
<param-name>script.prefix</param-name>
|
||||||
|
<param-value>/scripts</param-value>
|
||||||
|
<description>
|
||||||
|
The resource prefix to use for scripts. This is prepended to the servlet path to create the
|
||||||
|
script name which is executed.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>XmlRpc</servlet-name>
|
||||||
|
<description>Executes XML-RPC requests.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.xmlrpc.XmlRpcServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>subsystem.object</param-name>
|
||||||
|
<param-value>xmlrpc</param-value>
|
||||||
|
<description>
|
||||||
|
The object name of the XML-RPC subsystem object. Must match the name configured for the
|
||||||
|
com.silverwrist.dynamo.xmlrpc.XmlRpcSubSystem object in dynamo.xml.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>Remapper</servlet-name>
|
||||||
|
<description>Remaps URLs to other URLs programmatically.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.servlet.RemapperServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>data.object</param-name>
|
||||||
|
<param-value>remapper</param-value>
|
||||||
|
<description>
|
||||||
|
The object name of the remapper data object. Must match the name configured for the
|
||||||
|
com.silverwrist.dynamo.servlet.RemapperData object in dynamo.xml.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>Image</servlet-name>
|
||||||
|
<description>Serves up images from the ImageStore.</description>
|
||||||
|
<servlet-class>com.silverwrist.dynamo.servlet.ImageServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>image.store</param-name>
|
||||||
|
<param-value>images</param-value>
|
||||||
|
<description>
|
||||||
|
The object name of the image store object. Must match the name configured for the
|
||||||
|
com.silverwrist.dynamo.db.ImageStoreObject object in dynamo.xml.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>StyleSheet</servlet-name>
|
||||||
|
<description>Serves up CSS stylesheets for use by the frame.</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.frame.StyleSheetServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>Frame</servlet-name>
|
||||||
|
<description>Frames static pages within the outer Venice frame.</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.servlet.FrameServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>content.prefix</param-name>
|
||||||
|
<param-value>static</param-value>
|
||||||
|
<description>
|
||||||
|
The prefix to apply to the static content path before retrieving it. Interpreted
|
||||||
|
relative to the Web application root (i.e. where Web content normally gets linked from).
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
<init-param>
|
||||||
|
<param-name>cache.hard.limit</param-name>
|
||||||
|
<param-value>5</param-value>
|
||||||
|
<description>
|
||||||
|
Maximum number of documents that will be hard-cached by this servlet. Must be at least 1.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
<init-param>
|
||||||
|
<param-name>cache.soft.limit</param-name>
|
||||||
|
<param-value>10</param-value>
|
||||||
|
<description>
|
||||||
|
Maximum number of documents that will be soft-cached by this servlet. Will always be at least
|
||||||
|
twice the number of hard-cached documents.
|
||||||
|
</description>
|
||||||
|
</init-param>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>PasswordRecovery</servlet-name>
|
||||||
|
<description>Used to access the password recovery feature; changes user passwords.</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.session.PasswordRecoveryServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>User</servlet-name>
|
||||||
|
<description>Displays user profiles.</description>
|
||||||
|
<servlet-class>com.silverwrist.venice.servlet.UserServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<!-- Servlet mappings -->
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ScriptExec</servlet-name>
|
||||||
|
<url-pattern>*.vs</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>XmlRpc</servlet-name>
|
||||||
|
<url-pattern>/RPC2</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Remapper</servlet-name>
|
||||||
|
<url-pattern>/verifyemail</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Image</servlet-name>
|
||||||
|
<url-pattern>/imagedata/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>StyleSheet</servlet-name>
|
||||||
|
<url-pattern>/stylesheet-base.css</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>StyleSheet</servlet-name>
|
||||||
|
<url-pattern>/stylesheet-advanced.css</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Frame</servlet-name>
|
||||||
|
<url-pattern>/frame/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>PasswordRecovery</servlet-name>
|
||||||
|
<url-pattern>/passrecovery/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>User</servlet-name>
|
||||||
|
<url-pattern>/user/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- Global parameters for the HTTP session -->
|
||||||
|
<session-config>
|
||||||
|
<session-timeout>60</session-timeout> <!-- 1 hour -->
|
||||||
|
</session-config>
|
||||||
|
|
||||||
|
<!-- The list of "welcome files" for the application -->
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>default.jsp</welcome-file>
|
||||||
|
<welcome-file>index.html</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
|
||||||
|
</web-app>
|
1
docs/buttons/.gitignore
vendored
Normal file
1
docs/buttons/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.xvpics
|
BIN
docs/buttons/bn_blank80.png
Normal file
BIN
docs/buttons/bn_blank80.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
BIN
docs/buttons/bn_delete.png
Normal file
BIN
docs/buttons/bn_delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
BIN
docs/buttons/bn_save.png
Normal file
BIN
docs/buttons/bn_save.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
BIN
docs/buttons/classic.xcf
Normal file
BIN
docs/buttons/classic.xcf
Normal file
Binary file not shown.
BIN
docs/buttons/gelcap_green.xcf
Normal file
BIN
docs/buttons/gelcap_green.xcf
Normal file
Binary file not shown.
BIN
docs/buttons/gelcap_pink.xcf
Normal file
BIN
docs/buttons/gelcap_pink.xcf
Normal file
Binary file not shown.
BIN
docs/buttons/gelcap_red.xcf
Normal file
BIN
docs/buttons/gelcap_red.xcf
Normal file
Binary file not shown.
BIN
docs/buttons/gelcap_teal.xcf
Normal file
BIN
docs/buttons/gelcap_teal.xcf
Normal file
Binary file not shown.
BIN
docs/buttons/gelcap_violet.xcf
Normal file
BIN
docs/buttons/gelcap_violet.xcf
Normal file
Binary file not shown.
BIN
docs/buttons/gelcap_yellow.xcf
Normal file
BIN
docs/buttons/gelcap_yellow.xcf
Normal file
Binary file not shown.
103
docs/design-goals.html
Normal file
103
docs/design-goals.html
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Design Goals of Venice/Dynamo</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Design Goals of Venice/Dynamo</h1>
|
||||||
|
<em>Eric J. Bowersox, <<a href="mailto:erbo@silcom.com">erbo@silcom.com</a>> - May 2003</em>
|
||||||
|
<h2>Introduction - The Original Venice Goals</h2>
|
||||||
|
<p>As is well-known, the Venice Web Communities System was originally founded for the purpose of providing
|
||||||
|
code on which the new <a href="http://www.minds.nu">Electric Minds</a> server could be run. To this
|
||||||
|
end, it was designed along the lines of the CommunityWare platform, by Durand Communications, on which
|
||||||
|
Electric Minds was run for several years. (CommunityWare formed the nucleus of the WebbMe portal system
|
||||||
|
as well.) To that end, the original design goals of Venice looked like this:</p>
|
||||||
|
<ol>
|
||||||
|
<li>A replacement for the CommunityWare/WebbMe conferencing system</li>
|
||||||
|
<li>Java/JSP/servlets implementation running under Apache Tomcat, MySQL backend</li>
|
||||||
|
<li>Multiple communities hosted per server, each with multiple conferences
|
||||||
|
(and other features); users logged into one server can join multiple communities</li>
|
||||||
|
<li>Conferencing functionality similar to CW/WebbMe:
|
||||||
|
<ul>
|
||||||
|
<li>Linear topics composed of HTML messages</li>
|
||||||
|
<li>View topics by new messages/unread/all messages/hidden topics/archived topics</li>
|
||||||
|
<li>Topics can be deleted/archived/made read-only by the conference host</li>
|
||||||
|
<li>Topics can be hidden from a user's personal view</li>
|
||||||
|
<li>Individual posts can be "hidden" or "scribbled" by owner or conference host</li>
|
||||||
|
<li>Posts can be previewed, with spellchecking and HTML formatting</li>
|
||||||
|
<li>Files can be "attached" to posts (up to 1 Mb in size)</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>Enhancements to existing conference features:
|
||||||
|
<ul>
|
||||||
|
<li>Full text search of posts within a conference</li>
|
||||||
|
<li>Conference-level "bozo filters"</li>
|
||||||
|
<li>Individual posts can be "nuked" without a trace by the conference host</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>Later, replace other CW/WebbMe functions:
|
||||||
|
<ul>
|
||||||
|
<li>Activity logs</li>
|
||||||
|
<li>Instant messaging and chat (use Jabber)</li>
|
||||||
|
<li>Calendaring</li>
|
||||||
|
<li>Newsletters via e-mail</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>Features from CW/WebbMe we <em>won't</em> do:
|
||||||
|
<ul>
|
||||||
|
<li>Web hosting</li>
|
||||||
|
<li>Web-based email</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>Blue sky features:
|
||||||
|
<ul>
|
||||||
|
<li>Output uses XML and gets formatted into [X]HTML via XSLT; "themeable"/"skinnable" interface</li>
|
||||||
|
<li>Conferencing/other functionality available via XML-RPC or SOAP calls</li>
|
||||||
|
<li>News page creation (see Slash, Squishdot, Scoop)</li>
|
||||||
|
<li>Member trust metrics (see Slashdot "karma," Scoop "mojo," Advogato distributed trust metric)
|
||||||
|
<b><em>(Feature indefinitely shelved at the request of the EMinds community)</em></b></li>
|
||||||
|
<li>User diary pages (see Advogato, Kuro5hin)</li>
|
||||||
|
<li>Moderated discussions (see Slash, Scoop)</li>
|
||||||
|
<li>Collaborative database facility (see Wiki, Everything2)</li>
|
||||||
|
<li>Content management/distributed publishing</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
<h2>Evolution of The Original Venice Code</h2>
|
||||||
|
<p>As time went on and the Venice code was put to use on Electric Minds and elsewhere, gradually, the enhanced
|
||||||
|
feature set described in "Enhancements," above, was implemented, as well as some additional enhancements (user
|
||||||
|
photos in posts, some limited customization capabilities). This was in response to the needs of Electric Minds
|
||||||
|
and other communities</p>
|
||||||
|
<p>Perhaps the biggest change, however, was a changeover from the original UI front end, which used a great many
|
||||||
|
"magic servlets," to a generalized system which employed a scripting engine built into Venice (actually, the
|
||||||
|
Bean Scripting Framework, which supports many different scripting languages), so that UI-level operations could
|
||||||
|
be written as scripts and executed directly by means of a single servlet. The JSP-based display front ends, too,
|
||||||
|
were updated, making heavy use of JSP tag libraries to minimize the amount of embedded code on a page.</p>
|
||||||
|
<p>A partial XML-RPC API was also implemented, and the "mailgate" program was written to take advantage of this,
|
||||||
|
providing a gateway from a mailing list to a Venice conferencing topic, with some success.</p>
|
||||||
|
<h2>Dynamo - The Next Leap Forward</h2>
|
||||||
|
<p>Currently, the Venice code is being rewritten to be even more modular than before, carrying the advantages
|
||||||
|
of the modularized, scriptable UI into other aspects of the code. As part of this effort, the lower-level
|
||||||
|
support elements of the application are being factored out into a code framework referred to as "Dynamo" (for
|
||||||
|
"DYNAMic Objects"). The goals of the new Dynamo-based Venice are as follows:</p>
|
||||||
|
<ol>
|
||||||
|
<li>Even greater modularity than the original Venice, including dynamically-loadable modules. One should
|
||||||
|
be able to add a new service to Venice simply by dropping a JAR file into a directory on the server and
|
||||||
|
performing an installation process from within Venice's administrative UI.</li>
|
||||||
|
<li>Replacement of the JSP front-ends, which involve a high degree of overhead as well as the need to employ
|
||||||
|
external access protection to prevent them from being invoked directly by an end-user. Instead, a solution
|
||||||
|
based on the Velocity template system will be employed.</li>
|
||||||
|
<li>Refactoring of database access, to eventually allow the use of databases other than MySQL, especially
|
||||||
|
ones which employ stored procedures.</li>
|
||||||
|
<li>Improved search capabilities for posts, possibly employing the Lucene full-text search engine.</li>
|
||||||
|
<li>Shifting of configuration information from XML configuration files to the database, where it can be
|
||||||
|
modified without bringing down the server. A new "property" storage system will be employed for much of
|
||||||
|
this information.</li>
|
||||||
|
<li>Replacement of the original Venice security model, which employed a somewhat-confusing system of "security
|
||||||
|
levels." Instead, a more modern ACL-based system will be employed, for greater granularity.</li>
|
||||||
|
<li>Replacement of the front-page publishing model to allow people other than administrators to "publish"
|
||||||
|
posts there. Instead, a system of "channels" will be created, with each channel having its own ACL
|
||||||
|
to permit other people to access it.</li>
|
||||||
|
</ol>
|
||||||
|
</body>
|
||||||
|
</html>
|
46
docs/identifiers.html
Normal file
46
docs/identifiers.html
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>Doc: About Venice Identifiers</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
|
||||||
|
<BODY>
|
||||||
|
<H1>About Venice Identifiers</H1>
|
||||||
|
<EM>Eric J. Bowersox <<A HREF="mailto:erbo@silcom.com">erbo@silcom.com</A>> -
|
||||||
|
January 26, 2001</EM><P>
|
||||||
|
|
||||||
|
Venice identifiers are used for user IDs, community aliases, and conference aliases (and maybe other unique
|
||||||
|
identifiers in the future). A valid Venice ID consists of characters from the following character set
|
||||||
|
only:
|
||||||
|
<UL>
|
||||||
|
<LI>Alphanumerics [A-Z, a-z, and 0-9]</LI>
|
||||||
|
<LI>Dash [-]</LI>
|
||||||
|
<LI>Underscore [_]</LI>
|
||||||
|
<LI>Tilde [~]</LI>
|
||||||
|
<LI>Asterisk [*]</LI>
|
||||||
|
<LI>Apostrophe [']</LI>
|
||||||
|
<LI>Dollar sign [$]</LI>
|
||||||
|
</UL><P>
|
||||||
|
All characters are represented in the ISO 8859-1 character set. Also note that all Venice identifiers
|
||||||
|
are case-insensitive.<P>
|
||||||
|
<B>Rationale</B><P>
|
||||||
|
The character set was defined starting with the list of characters allowable in URL path components
|
||||||
|
("pchar" as defined in RFC 2396, section 3.3, page 14), so that Venice IDs would be usable as "path
|
||||||
|
information" in a URL.<P>
|
||||||
|
The ampersand [&] was eliminated because of its possible confusion with a URL parameter separator, and
|
||||||
|
because it requires HTML escaping.<P>
|
||||||
|
The at sign [@] was eliminated because of possible confusion with email addresses and Jabber IDs.<P>
|
||||||
|
The plus sign [+] was eliminated because of possible confusion with a URL-encoded space character.<P>
|
||||||
|
The comma [,] was eliminated because of its possible interpretation as a separator character.<P>
|
||||||
|
The equals sign [=] was eliminated because of its possible confusion with a URL parameter/value
|
||||||
|
separator.<P>
|
||||||
|
The colon [:] was withheld to provide for a possible future "namespace" expansion (as in XML
|
||||||
|
namespaces).<P>
|
||||||
|
The parentheses [(, )] were eliminated because of possible confusion with user link syntax in
|
||||||
|
conferencing.<P>
|
||||||
|
The period [.] was eliminated because of possible confusion with post link syntax in conferencing.<P>
|
||||||
|
The exclamation point [!] was eliminated because of possible confusion with extended post link syntax in
|
||||||
|
conferencing.
|
||||||
|
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
BIN
docs/user-acl-truth-table.sxc
Normal file
BIN
docs/user-acl-truth-table.sxc
Normal file
Binary file not shown.
1
drivers/.gitignore
vendored
Normal file
1
drivers/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
mysql-connector-java-3.0.7-stable-bin.jar
|
6
drivers/README.drivers
Normal file
6
drivers/README.drivers
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
This is the directory where JDBC drivers get placed.
|
||||||
|
|
||||||
|
MySQL
|
||||||
|
-----
|
||||||
|
Store the file "mysql-connector-java-3.0.7-stable-bin.jar" in this directory.
|
||||||
|
|
1
resources/dynamo-test-module/res1.txt
Normal file
1
resources/dynamo-test-module/res1.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
If you're reading this, we loaded the resource successfully!
|
160
src/baseutil/com/silverwrist/util/AnyCharMatcher.java
Normal file
160
src/baseutil/com/silverwrist/util/AnyCharMatcher.java
Normal file
|
@ -0,0 +1,160 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class which performs the equivalent of <CODE>String.indexOf(char)</CODE>, but using
|
||||||
|
* multiple characters. It locates the first instance within a string of <EM>any</EM> of
|
||||||
|
* the specified characters.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public final class AnyCharMatcher
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private char[] charset; // the set of characters to look for
|
||||||
|
private int[] locs; // a temporary array used for locations
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructors
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new character matcher that matches the specified characters.
|
||||||
|
*
|
||||||
|
* @param charset The set of characters to be matched by this object, expressed as a character array.
|
||||||
|
*/
|
||||||
|
public AnyCharMatcher(char[] charset)
|
||||||
|
{
|
||||||
|
this.charset = charset;
|
||||||
|
this.locs = new int[charset.length];
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new character matcher that matches the specified characters.
|
||||||
|
*
|
||||||
|
* @param charset The set of characters to be matched by this object, expressed as a string.
|
||||||
|
*/
|
||||||
|
public AnyCharMatcher(String charset)
|
||||||
|
{
|
||||||
|
this.charset = charset.toCharArray();
|
||||||
|
this.locs = new int[charset.length()];
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the offset within the string of the first instance of any character in this
|
||||||
|
* character set.
|
||||||
|
*
|
||||||
|
* @param str The string to look through. If this parameter is <B><CODE>null</CODE></B>,
|
||||||
|
* the method returns -1.
|
||||||
|
* @return The 0-based index of the first instance of any character from this character
|
||||||
|
* matcher within <CODE>str</CODE>. If <CODE>str</CODE> contains no instances of
|
||||||
|
* any character from this character matcher, -1 is returned.
|
||||||
|
*/
|
||||||
|
public final int get(String str)
|
||||||
|
{
|
||||||
|
if (str==null)
|
||||||
|
return -1;
|
||||||
|
int numindexes = 0;
|
||||||
|
int i;
|
||||||
|
for (i=0; i<charset.length; i++)
|
||||||
|
{ // locate the index of the first HTML character
|
||||||
|
int tmp = str.indexOf(charset[i]);
|
||||||
|
if (tmp>=0)
|
||||||
|
locs[numindexes++] = tmp;
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
if (numindexes==0)
|
||||||
|
return -1; // no characters found
|
||||||
|
else if (numindexes==1)
|
||||||
|
return locs[0]; // only one found
|
||||||
|
|
||||||
|
int rc = locs[0];
|
||||||
|
for (i=1; i<numindexes; i++)
|
||||||
|
{ // this loop determines the lowest possible return value
|
||||||
|
if (rc==0)
|
||||||
|
return 0; // can't get any lower!
|
||||||
|
if (locs[i]<rc)
|
||||||
|
rc = locs[i]; // this is now the lowest
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the offset within the string of the last instance of any character in this
|
||||||
|
* character set.
|
||||||
|
*
|
||||||
|
* @param str The string to look through. If this parameter is <B><CODE>null</CODE></B>,
|
||||||
|
* the method returns -1.
|
||||||
|
* @return The 0-based index of the last instance of any character from this character
|
||||||
|
* matcher within <CODE>str</CODE>. If <CODE>str</CODE> contains no instances of
|
||||||
|
* any character from this character matcher, -1 is returned.
|
||||||
|
*/
|
||||||
|
public final int getLast(String str)
|
||||||
|
{
|
||||||
|
if (str==null)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int numindexes = 0;
|
||||||
|
int i;
|
||||||
|
for (i=0; i<charset.length; i++)
|
||||||
|
{ // locate the index of the first HTML character
|
||||||
|
int tmp = str.lastIndexOf(charset[i]);
|
||||||
|
if (tmp>=0)
|
||||||
|
locs[numindexes++] = tmp;
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
if (numindexes==0)
|
||||||
|
return -1; // no characters found
|
||||||
|
else if (numindexes==1)
|
||||||
|
return locs[0]; // only one found
|
||||||
|
|
||||||
|
int rc = locs[0];
|
||||||
|
int limit = str.length() - 1;
|
||||||
|
for (i=1; i<numindexes; i++)
|
||||||
|
{ // this loop determines the highest possible return value
|
||||||
|
if (rc==limit)
|
||||||
|
return limit; // can't get any higher!
|
||||||
|
if (locs[i]>rc)
|
||||||
|
rc = locs[i]; // this is now the highest
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end getLast
|
||||||
|
|
||||||
|
} // end class AnyCharMatcher
|
19
src/baseutil/com/silverwrist/util/BooleanValues.properties
Normal file
19
src/baseutil/com/silverwrist/util/BooleanValues.properties
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
# ---------------------------------------------------------------------------------
|
||||||
|
# This file has been localized for the en_US locale
|
||||||
|
values.true=1|true|yes|on
|
||||||
|
values.false=0|false|no|off
|
159
src/baseutil/com/silverwrist/util/Country.java
Normal file
159
src/baseutil/com/silverwrist/util/Country.java
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A utility class used by <CODE>International</CODE> that stores a country code and name pair.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
* @see International
|
||||||
|
*/
|
||||||
|
public final class Country implements Comparable
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String m_code; // the country code
|
||||||
|
private String m_name; // the country name
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>Country</CODE> object.
|
||||||
|
*
|
||||||
|
* @param code The country code.
|
||||||
|
* @param name The country name.
|
||||||
|
*/
|
||||||
|
Country(String code, String name)
|
||||||
|
{
|
||||||
|
m_code = code.trim().toUpperCase();
|
||||||
|
m_name = name.trim();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class Object
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether some other object is "equal to" this one.
|
||||||
|
*
|
||||||
|
* @param o The reference object with which to compare.
|
||||||
|
* @return <CODE>true</CODE> if this object is the same as the <CODE>o</CODE> argument; <CODE>false</CODE> otherwise.
|
||||||
|
*/
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if ((o==null) || !(o instanceof Country))
|
||||||
|
return false;
|
||||||
|
if (this==(Country)o)
|
||||||
|
return true;
|
||||||
|
Country other = (Country)o;
|
||||||
|
return m_code.equals(other.m_code);
|
||||||
|
|
||||||
|
} // end equals
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those
|
||||||
|
* provided by <CODE>java.util.Hashtable</CODE>.
|
||||||
|
*
|
||||||
|
* @return A hash code value for this object.
|
||||||
|
*/
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return m_code.hashCode();
|
||||||
|
|
||||||
|
} // end hashCode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of the object. In general, the <CODE>toString</CODE> method returns a string
|
||||||
|
* that "textually represents" this object.
|
||||||
|
*
|
||||||
|
* @return A string representation of the object.
|
||||||
|
*/
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return m_name + " [" + m_code + "]";
|
||||||
|
|
||||||
|
} // end toString
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface Comparable
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares this object with the specified object for order. Returns a negative integer, zero, or a positive
|
||||||
|
* integer as this object is less than, equal to, or greater than the specified object. <CODE>Country</CODE>
|
||||||
|
* objects are compared on their country name.
|
||||||
|
*
|
||||||
|
* @param o The Object to be compared.
|
||||||
|
* @return A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than
|
||||||
|
* the specified object.
|
||||||
|
* @exception java.lang.ClassCastException If the specified object's type prevents it from being compared to
|
||||||
|
* this Object.
|
||||||
|
*/
|
||||||
|
public int compareTo(Object o)
|
||||||
|
{
|
||||||
|
if (o==null)
|
||||||
|
return 1;
|
||||||
|
if (o instanceof Country)
|
||||||
|
{ // compare country names
|
||||||
|
Country c = (Country)o;
|
||||||
|
return m_name.compareTo(c.m_name);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
return m_name.compareTo(o.toString());
|
||||||
|
|
||||||
|
} // end compareTo
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External getters
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the 2-letter country code for this country.
|
||||||
|
*
|
||||||
|
* @return The 2-letter country code for this country.
|
||||||
|
*/
|
||||||
|
public final String getCode()
|
||||||
|
{
|
||||||
|
return m_code;
|
||||||
|
|
||||||
|
} // end code
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of this country.
|
||||||
|
*
|
||||||
|
* @return The name of this country.
|
||||||
|
*/
|
||||||
|
public final String getName()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
|
||||||
|
} // end name
|
||||||
|
|
||||||
|
} // end class Country
|
329
src/baseutil/com/silverwrist/util/HardSoftCache.java
Normal file
329
src/baseutil/com/silverwrist/util/HardSoftCache.java
Normal file
|
@ -0,0 +1,329 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
import java.lang.ref.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class implementing a memory-sensitive cache. The cache is an LRU cache which uses two size limits,
|
||||||
|
* the <EM>soft limit</EM> and the <EM>hard limit</EM>. The soft limit dictates the maximum size of the
|
||||||
|
* cache; all elements in the cache have <CODE>SoftReference</CODE>s to them, which allows the JVM to expel
|
||||||
|
* them from memory if necessary. However, the most recent elements in the cache, up to the hard limit,
|
||||||
|
* have ordinary references on them, which prevents them from being expelled. Therefore, under low memory
|
||||||
|
* conditions, all elements in the cache may be discarded except for the most recent ones.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class HardSoftCache
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class to hold the hard hash entries
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static class HardHashMap extends LinkedHashMap
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Attributes
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
private int m_maxsize; // maximum size of the cache
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
private HardHashMap(int capacity)
|
||||||
|
{
|
||||||
|
super(capacity+2,0.95F,true);
|
||||||
|
m_maxsize = capacity;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class LinkedHashMap
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected boolean removeEldestEntry(Map.Entry eldest)
|
||||||
|
{
|
||||||
|
return (this.size()>m_maxsize);
|
||||||
|
|
||||||
|
} // end removeEldestEntry
|
||||||
|
|
||||||
|
} // end class HardHashMap
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class to hold the soft hash entries
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static class SoftHashMap extends LinkedHashMap
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Attributes
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
private int m_maxsize; // maximum size of the cache
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
private SoftHashMap(int capacity)
|
||||||
|
{
|
||||||
|
super(capacity+2,0.95F,true);
|
||||||
|
m_maxsize = capacity;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class HashMap
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Object put(Object key, Object value)
|
||||||
|
{
|
||||||
|
SoftReference newref = new SoftReference(value);
|
||||||
|
Reference r = (Reference)(super.put(key,newref));
|
||||||
|
Object rc = null;
|
||||||
|
if (r!=null)
|
||||||
|
{ // get the old object
|
||||||
|
rc = r.get();
|
||||||
|
r.clear();
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end put
|
||||||
|
|
||||||
|
public void putAll(Map t)
|
||||||
|
{
|
||||||
|
Iterator it = t.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{ // run each item through our modified put()
|
||||||
|
Map.Entry ntry = (Map.Entry)(it.next());
|
||||||
|
this.put(ntry.getKey(),ntry.getValue());
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end putAll
|
||||||
|
|
||||||
|
public Object remove(Object key)
|
||||||
|
{
|
||||||
|
Reference r = (Reference)(super.remove(key));
|
||||||
|
Object rc = null;
|
||||||
|
if (r!=null)
|
||||||
|
{ // get the old object
|
||||||
|
rc = r.get();
|
||||||
|
r.clear();
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end remove
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class LinkedHashMap
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
Iterator it = this.values().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{ // dump all the references we contain
|
||||||
|
Reference r = (Reference)(it.next());
|
||||||
|
r.clear();
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
super.clear();
|
||||||
|
|
||||||
|
} // end clear
|
||||||
|
|
||||||
|
public Object get(Object key)
|
||||||
|
{
|
||||||
|
Reference r = (Reference)(super.get(key));
|
||||||
|
if (r==null)
|
||||||
|
return null;
|
||||||
|
Object rc = r.get();
|
||||||
|
if (rc==null)
|
||||||
|
{ // reference has been dumped - remove it from the map
|
||||||
|
super.remove(key);
|
||||||
|
r.clear();
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
protected boolean removeEldestEntry(Map.Entry eldest)
|
||||||
|
{
|
||||||
|
if (this.size()<=m_maxsize)
|
||||||
|
return false;
|
||||||
|
Reference r = (Reference)(eldest.getValue());
|
||||||
|
r.clear();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} // end removeEldestEntry
|
||||||
|
|
||||||
|
} // end class SoftHashMap
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private HardHashMap m_hard_map; // the "hard map"
|
||||||
|
private SoftHashMap m_soft_map; // the "soft map"
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new cache object.
|
||||||
|
*
|
||||||
|
* @param hard_limit The "hard limit" for this cache. Has a minimum value of 1.
|
||||||
|
* @param soft_limit The "soft limit" for this cache. Has a minimum value of 2 times the value of the
|
||||||
|
* "hard limit."
|
||||||
|
*/
|
||||||
|
public HardSoftCache(int hard_limit, int soft_limit)
|
||||||
|
{
|
||||||
|
// Pre-condition the input parameters.
|
||||||
|
if (hard_limit<1)
|
||||||
|
hard_limit = 1;
|
||||||
|
if (soft_limit<(hard_limit * 2))
|
||||||
|
soft_limit = hard_limit * 2;
|
||||||
|
m_hard_map = new HardHashMap(hard_limit);
|
||||||
|
m_soft_map = new SoftHashMap(soft_limit);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value to which this cache maps the specified key. Returns <CODE>null</CODE> if the cache
|
||||||
|
* contains no mapping for this key.
|
||||||
|
*
|
||||||
|
* @param key The key whose associated value is to be returned.
|
||||||
|
* @return The value to which this cache maps the specified key.
|
||||||
|
*/
|
||||||
|
public synchronized Object get(Object key)
|
||||||
|
{
|
||||||
|
if (key==null)
|
||||||
|
throw new NullPointerException("HardSoftCache.get");
|
||||||
|
Object hard_rc = m_hard_map.get(key);
|
||||||
|
Object soft_rc = m_soft_map.get(key);
|
||||||
|
return ((hard_rc!=null) ? hard_rc : soft_rc);
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associates the specified value with the specified key in this cache. If the cache previously contained a
|
||||||
|
* mapping for this key, the old value is replaced.
|
||||||
|
*
|
||||||
|
* @param key The key with which the specified value is to be associated.
|
||||||
|
* @param value The value to be associated with the specified key.
|
||||||
|
*/
|
||||||
|
public synchronized void put(Object key, Object value)
|
||||||
|
{
|
||||||
|
if (key==null)
|
||||||
|
throw new NullPointerException("HardSoftCache.put(key)");
|
||||||
|
if (value==null)
|
||||||
|
throw new NullPointerException("HardSoftCache.put(value)");
|
||||||
|
m_hard_map.put(key,value);
|
||||||
|
m_soft_map.put(key,value);
|
||||||
|
|
||||||
|
} // end put
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the mapping for this key from this cache if present.
|
||||||
|
*
|
||||||
|
* @param key The key whose mapping is to be removed from the map.
|
||||||
|
*/
|
||||||
|
public synchronized void remove(Object key)
|
||||||
|
{
|
||||||
|
if (key==null)
|
||||||
|
throw new NullPointerException("HardSoftCache.remove");
|
||||||
|
m_hard_map.remove(key);
|
||||||
|
m_soft_map.remove(key);
|
||||||
|
|
||||||
|
} // end remove
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of key-value mappings in this cache.
|
||||||
|
*
|
||||||
|
* @return The number of key-value mappings in this cache.
|
||||||
|
*/
|
||||||
|
public synchronized int size()
|
||||||
|
{
|
||||||
|
return m_soft_map.size();
|
||||||
|
|
||||||
|
} // end size
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns <CODE>true</CODE> if this cache contains no key-value mappings.
|
||||||
|
*
|
||||||
|
* @return <CODE>true</CODE> if this cache contains no key-value mappings.
|
||||||
|
*/
|
||||||
|
public synchronized boolean isEmpty()
|
||||||
|
{
|
||||||
|
return m_hard_map.isEmpty();
|
||||||
|
|
||||||
|
} // end isEmpty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all mappings from this cache.
|
||||||
|
*/
|
||||||
|
public synchronized void clear()
|
||||||
|
{
|
||||||
|
m_hard_map.clear();
|
||||||
|
m_soft_map.clear();
|
||||||
|
|
||||||
|
} // end clear
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns <CODE>true</CODE> if this cache contains a mapping for the specified key.
|
||||||
|
*
|
||||||
|
* @param key The key whose presence in this cache is to be tested.
|
||||||
|
* @return <CODE>true</CODE> if this cache contains a mapping for the specified key.
|
||||||
|
*/
|
||||||
|
public synchronized boolean containsKey(Object key)
|
||||||
|
{
|
||||||
|
if (key==null)
|
||||||
|
throw new NullPointerException("HardSoftCache.containsKey");
|
||||||
|
return (m_soft_map.get(key)!=null);
|
||||||
|
|
||||||
|
} // end containsKey
|
||||||
|
|
||||||
|
} // end class HardSoftCache
|
378
src/baseutil/com/silverwrist/util/IOUtils.java
Normal file
378
src/baseutil/com/silverwrist/util/IOUtils.java
Normal file
|
@ -0,0 +1,378 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of IO-related static methods which are useful in various contexts.<P>
|
||||||
|
* Some of the concepts in this class have been borrowed from Apache Jakarta Avalon Excalibur 4.0.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class IOUtils
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default buffer size to use for copying, if none is specified.
|
||||||
|
*/
|
||||||
|
public static int DEFAULT_BUFSIZE = 4096;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IOUtils instances should NOT be constructed in standard programming.
|
||||||
|
* Instead, the class should be used as <code>IOUtils.shutdown(stm);</code>.
|
||||||
|
* This constructor is public to permit tools that require a JavaBean instance
|
||||||
|
* to operate.
|
||||||
|
*/
|
||||||
|
public IOUtils()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes an input stream cleanly, without throwing an exception.
|
||||||
|
*
|
||||||
|
* @param stm The stream to be closed.
|
||||||
|
* @see java.io.InputStream#close()
|
||||||
|
*/
|
||||||
|
public static void shutdown(InputStream stm)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // close the stream
|
||||||
|
stm.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // throw away the exception
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes an output stream cleanly, without throwing an exception.
|
||||||
|
*
|
||||||
|
* @param stm The stream to be closed.
|
||||||
|
* @see java.io.OutputStream#close()
|
||||||
|
*/
|
||||||
|
public static void shutdown(OutputStream stm)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // close the stream
|
||||||
|
stm.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // throw away the exception
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes an input reader cleanly, without throwing an exception.
|
||||||
|
*
|
||||||
|
* @param stm The stream to be closed.
|
||||||
|
* @see java.io.Reader#close()
|
||||||
|
*/
|
||||||
|
public static void shutdown(Reader rdr)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // close the stream
|
||||||
|
rdr.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // throw away the exception
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes an output reader cleanly, without throwing an exception.
|
||||||
|
*
|
||||||
|
* @param stm The stream to be closed.
|
||||||
|
* @see java.io.Writer#close()
|
||||||
|
*/
|
||||||
|
public static void shutdown(Writer wr)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // close the stream
|
||||||
|
wr.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // throw away the exception
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the contents of the given input stream to the given output stream.
|
||||||
|
*
|
||||||
|
* @param input The stream to copy binary data from.
|
||||||
|
* @param output The stream to copy binary data to.
|
||||||
|
* @param bufsize The size of the buffer to allocate for copying.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading or writing data.
|
||||||
|
*/
|
||||||
|
public static void copy(InputStream input, OutputStream output, int bufsize) throws IOException
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[bufsize];
|
||||||
|
int rd = input.read(buffer);
|
||||||
|
while (rd>=0)
|
||||||
|
{ // simple read-write loop to shove data out the door
|
||||||
|
if (rd>0)
|
||||||
|
output.write(buffer,0,rd);
|
||||||
|
rd = input.read(buffer);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end copy
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the contents of the given input stream to the given output stream. Uses a default
|
||||||
|
* buffer size.
|
||||||
|
*
|
||||||
|
* @param input The stream to copy binary data from.
|
||||||
|
* @param output The stream to copy binary data to.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading or writing data.
|
||||||
|
* @see #DEFAULT_BUFSIZE
|
||||||
|
* @see #copy(java.io.InputStream,java.io.OutputStream,int)
|
||||||
|
*/
|
||||||
|
public static void copy(InputStream input, OutputStream output) throws IOException
|
||||||
|
{
|
||||||
|
copy(input,output,DEFAULT_BUFSIZE);
|
||||||
|
|
||||||
|
} // end copy
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the contents of an input stream and returns it as an array of bytes.
|
||||||
|
*
|
||||||
|
* @param input The stream to load binary data from.
|
||||||
|
* @param bufsize The size of the buffer to allocate for copying.
|
||||||
|
* @return A new byte array containing the contents of the specified input stream.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading data.
|
||||||
|
* @see #copy(java.io.InputStream,java.io.OutputStream,int)
|
||||||
|
*/
|
||||||
|
public static byte[] load(InputStream input, int bufsize) throws IOException
|
||||||
|
{
|
||||||
|
ByteArrayOutputStream stm = new ByteArrayOutputStream();
|
||||||
|
try
|
||||||
|
{ // copy the data to the input stream
|
||||||
|
copy(input,stm,bufsize);
|
||||||
|
return stm.toByteArray();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
finally
|
||||||
|
{ // close our byte array stream before we go
|
||||||
|
shutdown(stm);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end load
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the contents of an input stream and returns it as an array of bytes. Uses a default
|
||||||
|
* buffer size.
|
||||||
|
*
|
||||||
|
* @param input The stream to load binary data from.
|
||||||
|
* @return A new byte array containing the contents of the specified input stream.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading data.
|
||||||
|
* @see #DEFAULT_BUFSIZE
|
||||||
|
* @see #load(java.io.InputStream,int)
|
||||||
|
*/
|
||||||
|
public static byte[] load(InputStream input) throws IOException
|
||||||
|
{
|
||||||
|
return load(input,DEFAULT_BUFSIZE);
|
||||||
|
|
||||||
|
} // end load
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the contents of a binary file and returns it as an array of bytes.
|
||||||
|
*
|
||||||
|
* @param file The file to load binary data from.
|
||||||
|
* @param bufsize The size of the buffer to allocate for copying.
|
||||||
|
* @return A new byte array containing the contents of the specified file.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading data.
|
||||||
|
* @see #load(java.io.InputStream,int)
|
||||||
|
*/
|
||||||
|
public static byte[] loadBinary(File file, int bufsize) throws IOException
|
||||||
|
{
|
||||||
|
FileInputStream stm = new FileInputStream(file);
|
||||||
|
try
|
||||||
|
{ // now just load from the stream
|
||||||
|
return load(stm,bufsize);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
finally
|
||||||
|
{ // close the file before we leave
|
||||||
|
shutdown(stm);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end loadBinary
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the contents of a binary file and returns it as an array of bytes. Uses a default
|
||||||
|
* buffer size.
|
||||||
|
*
|
||||||
|
* @param file The file to load binary data from.
|
||||||
|
* @return A new byte array containing the contents of the specified file.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading data.
|
||||||
|
* @see #DEFAULT_BUFSIZE
|
||||||
|
* @see #loadBinary(java.io.File,int)
|
||||||
|
*/
|
||||||
|
public static byte[] loadBinary(File file) throws IOException
|
||||||
|
{
|
||||||
|
return loadBinary(file,DEFAULT_BUFSIZE);
|
||||||
|
|
||||||
|
} // end loadBinary
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the contents of the given input reader to the given output writer.
|
||||||
|
*
|
||||||
|
* @param input The reader to copy character data from.
|
||||||
|
* @param output The writer to copy character data to.
|
||||||
|
* @param bufsize The size of the buffer to allocate for copying.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading or writing data.
|
||||||
|
*/
|
||||||
|
public static void copy(Reader input, Writer output, int bufsize) throws IOException
|
||||||
|
{
|
||||||
|
char[] buffer = new char[bufsize];
|
||||||
|
int rd = input.read(buffer);
|
||||||
|
while (rd>=0)
|
||||||
|
{ // simple read-write loop to shove data out the door
|
||||||
|
if (rd>0)
|
||||||
|
output.write(buffer,0,rd);
|
||||||
|
rd = input.read(buffer);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end copy
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the contents of the given input reader to the given output writer. Uses a default
|
||||||
|
* buffer size.
|
||||||
|
*
|
||||||
|
* @param input The reader to copy character data from.
|
||||||
|
* @param output The writer to copy character data to.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading or writing data.
|
||||||
|
* @see #DEFAULT_BUFSIZE
|
||||||
|
* @see #copy(java.io.Reader,java.io.Writer,int)
|
||||||
|
*/
|
||||||
|
public static void copy(Reader input, Writer output) throws IOException
|
||||||
|
{
|
||||||
|
copy(input,output,DEFAULT_BUFSIZE);
|
||||||
|
|
||||||
|
} // end copy
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the contents of an input reader and returns it as a <CODE>StringBuffer</CODE>.
|
||||||
|
*
|
||||||
|
* @param input The reader to copy character data from.
|
||||||
|
* @param bufsize The size of the buffer to allocate for copying.
|
||||||
|
* @return A new <CODE>StringBuffer</CODE> containing the contents of the specified reader.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading data.
|
||||||
|
* @see #copy(java.io.Reader,java.io.Writer,int)
|
||||||
|
*/
|
||||||
|
public static StringBuffer load(Reader input, int bufsize) throws IOException
|
||||||
|
{
|
||||||
|
StringWriter wr = new StringWriter();
|
||||||
|
try
|
||||||
|
{ // copy from reader to StringWriter
|
||||||
|
copy(input,wr,bufsize);
|
||||||
|
return wr.getBuffer();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
finally
|
||||||
|
{ // make sure and close the StringWriter before we go
|
||||||
|
shutdown(wr);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end load
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the contents of an input reader and returns it as a <CODE>StringBuffer</CODE>. Uses a
|
||||||
|
* default buffer size.
|
||||||
|
*
|
||||||
|
* @param input The reader to copy character data from.
|
||||||
|
* @return A new <CODE>StringBuffer</CODE> containing the contents of the specified reader.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading data.
|
||||||
|
* @see #DEFAULT_BUFSIZE
|
||||||
|
* @see #load(java.io.Reader,int)
|
||||||
|
*/
|
||||||
|
public static StringBuffer load(Reader input) throws IOException
|
||||||
|
{
|
||||||
|
return load(input,DEFAULT_BUFSIZE);
|
||||||
|
|
||||||
|
} // end load
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the contents of a text file and returns it as a <CODE>StringBuffer</CODE>.
|
||||||
|
*
|
||||||
|
* @param file The file to copy text from.
|
||||||
|
* @param bufsize The size of the buffer to allocate for copying.
|
||||||
|
* @return A new <CODE>StringBuffer</CODE> containing the contents of the specified text file.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading data.
|
||||||
|
* @see #load(java.io.Reader,int)
|
||||||
|
*/
|
||||||
|
public static StringBuffer loadText(File file, int bufsize) throws IOException
|
||||||
|
{
|
||||||
|
FileReader rdr = new FileReader(file);
|
||||||
|
try
|
||||||
|
{ // load from the string reader
|
||||||
|
return load(rdr,bufsize);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
finally
|
||||||
|
{ // make sure and close the reader before we go
|
||||||
|
shutdown(rdr);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end load
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the contents of a text file and returns it as a <CODE>StringBuffer</CODE>.
|
||||||
|
*
|
||||||
|
* @param file The file to copy text from.
|
||||||
|
* @return A new <CODE>StringBuffer</CODE> containing the contents of the specified text file.
|
||||||
|
* @exception java.io.IOException If an exception occurred while reading data.
|
||||||
|
* @see #DEFAULT_BUFSIZE
|
||||||
|
* @see #loadText(java.io.File,int)
|
||||||
|
*/
|
||||||
|
public static StringBuffer loadText(File file) throws IOException
|
||||||
|
{
|
||||||
|
return loadText(file,DEFAULT_BUFSIZE);
|
||||||
|
|
||||||
|
} // end load
|
||||||
|
|
||||||
|
} // end class IOUtils
|
267
src/baseutil/com/silverwrist/util/International.java
Normal file
267
src/baseutil/com/silverwrist/util/International.java
Normal file
|
@ -0,0 +1,267 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class which centralizes a number of "international" resources, such as locales,
|
||||||
|
* country lists, and language lists.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class International
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static International self = new International(); // me
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private List country_list = null; // list of Country objects
|
||||||
|
private Map country_map = null; // mapping from codes to Country objects
|
||||||
|
private List language_list = null; // list of Language objects
|
||||||
|
private Map language_map = null; // mapping from codes to Language objects
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new instance of the <CODE>International</CODE> object. Only one instance
|
||||||
|
* of this object is ever created.
|
||||||
|
*/
|
||||||
|
private International()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the internal list of countries from a resource file.
|
||||||
|
*
|
||||||
|
* @exception RuntimeException If an I/O error occurred while loading the country list.
|
||||||
|
*/
|
||||||
|
private synchronized void loadCountryList()
|
||||||
|
{
|
||||||
|
if ((country_list!=null) || (country_map!=null))
|
||||||
|
return; // already loaded
|
||||||
|
|
||||||
|
// Create temporary list and map to hold read data.
|
||||||
|
ArrayList tmp_list = new ArrayList();
|
||||||
|
HashMap tmp_map = new HashMap();
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // Load the country properties file.
|
||||||
|
BufferedReader data =
|
||||||
|
new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("countries.properties")));
|
||||||
|
String l; // temporary line
|
||||||
|
while ((l = data.readLine())!=null)
|
||||||
|
{ // read lines from the properties file
|
||||||
|
l = l.trim();
|
||||||
|
if ((l.length()==0) || (l.startsWith("#")))
|
||||||
|
continue; // blank line or comment line
|
||||||
|
int pos = l.indexOf('=');
|
||||||
|
if (pos<0)
|
||||||
|
continue; // no properties - just forget this line
|
||||||
|
Country c = new Country(l.substring(0,pos),l.substring(pos+1));
|
||||||
|
tmp_list.add(c);
|
||||||
|
tmp_map.put(c.getCode(),c);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // IO error loading country properties...
|
||||||
|
throw new RuntimeException("Error loading country.properties: " + e.getMessage());
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
// Set up the lists, which are considered "unmodifiable."
|
||||||
|
tmp_list.trimToSize();
|
||||||
|
country_list = Collections.unmodifiableList(tmp_list);
|
||||||
|
country_map = Collections.unmodifiableMap(tmp_map);
|
||||||
|
|
||||||
|
} // end loadCountryList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the internal list of languages from a resource file.
|
||||||
|
*
|
||||||
|
* @exception RuntimeException If an I/O error occurred while loading the language list.
|
||||||
|
*/
|
||||||
|
private synchronized void loadLanguageList()
|
||||||
|
{
|
||||||
|
if ((language_list!=null) || (language_map!=null))
|
||||||
|
return; // already loaded
|
||||||
|
|
||||||
|
// Create temporary list and map to hold read data.
|
||||||
|
ArrayList tmp_list = new ArrayList();
|
||||||
|
HashMap tmp_map = new HashMap();
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // Load the language properties file.
|
||||||
|
BufferedReader data =
|
||||||
|
new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("languages.properties")));
|
||||||
|
String l; // temporary line
|
||||||
|
while ((l = data.readLine())!=null)
|
||||||
|
{ // read lines from the properties file
|
||||||
|
l = l.trim();
|
||||||
|
if ((l.length()==0) || (l.startsWith("#")))
|
||||||
|
continue; // blank line or comment line
|
||||||
|
int pos = l.indexOf('=');
|
||||||
|
if (pos<0)
|
||||||
|
continue; // no properties - just forget this line
|
||||||
|
Language lng = new Language(l.substring(0,pos),l.substring(pos+1));
|
||||||
|
tmp_list.add(lng);
|
||||||
|
tmp_map.put(lng.getCode(),lng);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // IO error loading language properties...
|
||||||
|
throw new RuntimeException("Error loading language.properties: " + e.getMessage());
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
// Set up the lists, which are considered "unmodifiable."
|
||||||
|
tmp_list.trimToSize();
|
||||||
|
language_list = Collections.unmodifiableList(tmp_list);
|
||||||
|
language_map = Collections.unmodifiableMap(tmp_map);
|
||||||
|
|
||||||
|
} // end loadLanguageList
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of defined countries.
|
||||||
|
*
|
||||||
|
* @return The list of <CODE>Country</CODE> objects that are currently defined.
|
||||||
|
*/
|
||||||
|
public List getCountryList()
|
||||||
|
{
|
||||||
|
loadCountryList();
|
||||||
|
return country_list;
|
||||||
|
|
||||||
|
} // end getCountryList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the <CODE>Country</CODE> object with the specified code.
|
||||||
|
*
|
||||||
|
* @param code The country code to match.
|
||||||
|
* @return The matching <CODE>Country</CODE> object, or <CODE>null</CODE> if no country matched.
|
||||||
|
*/
|
||||||
|
public Country getCountryForCode(String code)
|
||||||
|
{
|
||||||
|
if (code==null)
|
||||||
|
return null;
|
||||||
|
loadCountryList();
|
||||||
|
return (Country)(country_map.get(code.trim().toUpperCase()));
|
||||||
|
|
||||||
|
} // end getCountryForCode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of defined languages.
|
||||||
|
*
|
||||||
|
* @return The list of <CODE>Language</CODE> objects that are currently defined.
|
||||||
|
*/
|
||||||
|
public List getLanguageList()
|
||||||
|
{
|
||||||
|
loadLanguageList();
|
||||||
|
return language_list;
|
||||||
|
|
||||||
|
} // end getLanguageList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the <CODE>Language</CODE> object with the specified code.
|
||||||
|
*
|
||||||
|
* @param code The language code to match.
|
||||||
|
* @return The matching <CODE>Language</CODE> object, or <CODE>null</CODE> if no language matched.
|
||||||
|
*/
|
||||||
|
public Language getLanguageForCode(String code)
|
||||||
|
{
|
||||||
|
if (code==null)
|
||||||
|
return null;
|
||||||
|
loadLanguageList();
|
||||||
|
return (Language)(language_map.get(code.trim()));
|
||||||
|
|
||||||
|
} // end getLanguageForCode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a <CODE>Locale</CODE> from a standard descriptor string.
|
||||||
|
*
|
||||||
|
* @param streq The string equivalent of the Locale to be created.
|
||||||
|
* @return The corresponding <CODE>Locale</CODE>, or the default <CODE>Locale</CODE> if the parameter is
|
||||||
|
* <CODE>null</CODE> or the empty string.
|
||||||
|
*/
|
||||||
|
public Locale createLocale(String streq)
|
||||||
|
{
|
||||||
|
if ((streq==null) || (streq.length()==0))
|
||||||
|
return Locale.getDefault(); // no locale
|
||||||
|
int p1 = streq.indexOf('_');
|
||||||
|
if (p1<0)
|
||||||
|
return new Locale(streq,""); // language but no country specified
|
||||||
|
String x_lang = streq.substring(0,p1);
|
||||||
|
int p2 = streq.indexOf('_',p1+1);
|
||||||
|
if (p2<0)
|
||||||
|
{ // there's only one underscore - figure out what part the last part is
|
||||||
|
String lastpart = streq.substring(p1+1);
|
||||||
|
if (lastpart.length()==2)
|
||||||
|
return new Locale(x_lang,lastpart); // language + country
|
||||||
|
else
|
||||||
|
return new Locale(x_lang,"",lastpart); // language + country(null) + variant
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
// do all three variants
|
||||||
|
return new Locale(x_lang,streq.substring(p1+1,p2),streq.substring(p2+1));
|
||||||
|
|
||||||
|
} // end createLocale
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the singleton instance of the <CODE>International</CODE> object.
|
||||||
|
*
|
||||||
|
* @return The singleton instance of the <CODE>International</CODE> object.
|
||||||
|
*/
|
||||||
|
public static International get()
|
||||||
|
{
|
||||||
|
return self;
|
||||||
|
|
||||||
|
} // end get()
|
||||||
|
|
||||||
|
} // end class International
|
159
src/baseutil/com/silverwrist/util/Language.java
Normal file
159
src/baseutil/com/silverwrist/util/Language.java
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A utility class used by <CODE>International</CODE> that stores a language code and name pair.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
* @see International
|
||||||
|
*/
|
||||||
|
public final class Language implements Comparable
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String m_code; // the language code
|
||||||
|
private String m_name; // the language name
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>Language</CODE> object.
|
||||||
|
*
|
||||||
|
* @param code The language code.
|
||||||
|
* @param name The language name.
|
||||||
|
*/
|
||||||
|
Language(String code, String name)
|
||||||
|
{
|
||||||
|
m_code = code.trim();
|
||||||
|
m_name = name.trim();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class Object
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether some other object is "equal to" this one.
|
||||||
|
*
|
||||||
|
* @param o The reference object with which to compare.
|
||||||
|
* @return <CODE>true</CODE> if this object is the same as the <CODE>o</CODE> argument; <CODE>false</CODE> otherwise.
|
||||||
|
*/
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if ((o==null) || !(o instanceof Language))
|
||||||
|
return false;
|
||||||
|
if (this==(Language)o)
|
||||||
|
return true;
|
||||||
|
Language other = (Language)o;
|
||||||
|
return m_code.equals(other.m_code);
|
||||||
|
|
||||||
|
} // end equals
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those
|
||||||
|
* provided by <CODE>java.util.Hashtable</CODE>.
|
||||||
|
*
|
||||||
|
* @return A hash code value for this object.
|
||||||
|
*/
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return m_code.hashCode();
|
||||||
|
|
||||||
|
} // end hashCode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of the object. In general, the <CODE>toString</CODE> method returns a string
|
||||||
|
* that "textually represents" this object.
|
||||||
|
*
|
||||||
|
* @return A string representation of the object.
|
||||||
|
*/
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return m_name + " [" + m_code + "]";
|
||||||
|
|
||||||
|
} // end toString
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface Comparable
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares this object with the specified object for order. Returns a negative integer, zero, or a positive
|
||||||
|
* integer as this object is less than, equal to, or greater than the specified object. <CODE>Language</CODE>
|
||||||
|
* objects are compared on their language name.
|
||||||
|
*
|
||||||
|
* @param o The Object to be compared.
|
||||||
|
* @return A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than
|
||||||
|
* the specified object.
|
||||||
|
* @exception java.lang.ClassCastException If the specified object's type prevents it from being compared to
|
||||||
|
* this Object.
|
||||||
|
*/
|
||||||
|
public int compareTo(Object o)
|
||||||
|
{
|
||||||
|
if (o==null)
|
||||||
|
return 1;
|
||||||
|
if (o instanceof Language)
|
||||||
|
{ // compare country names
|
||||||
|
Language c = (Language)o;
|
||||||
|
return m_name.compareTo(c.m_name);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
return m_name.compareTo(o.toString());
|
||||||
|
|
||||||
|
} // end compareTo
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External getters
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the RFC 1766 language code for this language.
|
||||||
|
*
|
||||||
|
* @return The RFC 1766 language code for this language.
|
||||||
|
*/
|
||||||
|
public final String getCode()
|
||||||
|
{
|
||||||
|
return m_code;
|
||||||
|
|
||||||
|
} // end code
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of this language.
|
||||||
|
*
|
||||||
|
* @return The name of this language.
|
||||||
|
*/
|
||||||
|
public final String getName()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
|
||||||
|
} // end name
|
||||||
|
|
||||||
|
} // end class Language
|
120
src/baseutil/com/silverwrist/util/MySQLUtils.java
Normal file
120
src/baseutil/com/silverwrist/util/MySQLUtils.java
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class containing miscellaneous public methods useful when working with MySQL databases. All
|
||||||
|
* public methods of {@link com.silverwrist.util.SQLUtils SQLUtils} are also accessible through this class.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class MySQLUtils extends SQLUtils
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static Logger logger = Logger.getLogger(MySQLUtils.class);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MySQLUtils instances should NOT be constructed in standard programming.
|
||||||
|
* Instead, the class should be used as <code>MySQLUtils.shutdown(statement);</code>.
|
||||||
|
* This constructor is public to permit tools that require a JavaBean instance
|
||||||
|
* to operate.
|
||||||
|
*/
|
||||||
|
public MySQLUtils()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlocks all database tables that were previously locked. Executes the MySQL statement "UNLOCK TABLES;".
|
||||||
|
*
|
||||||
|
* @param conn The connection on which one or more tables were previously locked.
|
||||||
|
*/
|
||||||
|
public static final void unlockTables(Connection conn)
|
||||||
|
{
|
||||||
|
Statement stmt = null;
|
||||||
|
try
|
||||||
|
{ // do the update
|
||||||
|
stmt = conn.createStatement();
|
||||||
|
stmt.executeUpdate("UNLOCK TABLES;");
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // warn if there was an error here
|
||||||
|
logger.warn("DB error in unlockTables()",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shutdown the statement before we go
|
||||||
|
shutdown(stmt);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end unlockTables
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of the most recent insert made to a table with an AUTO_INCREMENT column. This assumes that the
|
||||||
|
* column is of integer type. Executes the MySQL statement "SELECT LAST_INSERT_ID();" and returns the value
|
||||||
|
* that that statement returns.
|
||||||
|
*
|
||||||
|
* @param conn Database connection on which to perform the operation.
|
||||||
|
* @return The value of the last inserted ID on this connection.
|
||||||
|
* @exception java.sql.SQLException If an error occurred in the execution, or if the SELECT statement returned
|
||||||
|
* no rows (which it should not do).
|
||||||
|
*/
|
||||||
|
public static final int getLastInsertInt(Connection conn) throws SQLException
|
||||||
|
{
|
||||||
|
Statement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // perform the operation
|
||||||
|
stmt = conn.createStatement();
|
||||||
|
rs = stmt.executeQuery("SELECT LAST_INSERT_ID();");
|
||||||
|
if (!(rs.next()))
|
||||||
|
throw new SQLException("internal error - getLastInsertInt SELECT should have returned OK");
|
||||||
|
return rs.getInt(1);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
finally
|
||||||
|
{ // shut down the objects before we go
|
||||||
|
shutdown(rs);
|
||||||
|
shutdown(stmt);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end getLastInsertInt
|
||||||
|
|
||||||
|
} // end class MySQLUtils
|
424
src/baseutil/com/silverwrist/util/OptionSet.java
Normal file
424
src/baseutil/com/silverwrist/util/OptionSet.java
Normal file
|
@ -0,0 +1,424 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2001-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
import java.util.BitSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A variant of the <CODE>BitSet</CODE> that can express itself as a character string. Each
|
||||||
|
* character in the resulting string represents a flag that is "set." Up to 91 flags can be
|
||||||
|
* specified per <CODE>OptionSet</CODE>.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
* @see java.util.BitSet
|
||||||
|
*/
|
||||||
|
public class OptionSet extends BitSet
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// The alphabet to use to store individual flags.
|
||||||
|
private static final String ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
|
+ "!#$%&()*+,-./:;<=>?@[]^_`{|}~";
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructors
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new <CODE>OptionSet</CODE>. All bits are initially <CODE>false</CODE>.
|
||||||
|
*/
|
||||||
|
public OptionSet()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an <CODE>OptionSet</CODE> whose initial size is large enough to explicitly represent bits with
|
||||||
|
* indices in the range 0 through nbits-1. All bits are initially <CODE>false</CODE>. The maximum
|
||||||
|
* size of the <CODE>OptionSet</CODE> is 91.
|
||||||
|
*
|
||||||
|
* @param nbits The initial size of the bit set.
|
||||||
|
* @exception java.lang.NegativeArraySizeException If the specified initial size is negative.
|
||||||
|
*/
|
||||||
|
public OptionSet(int nbits)
|
||||||
|
{
|
||||||
|
super(Math.min(nbits,ALPHA.length()));
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an <CODE>OptionSet</CODE> from an array of characters representing "set" options.
|
||||||
|
*
|
||||||
|
* @param options The options to be set in the new <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public OptionSet(char[] options)
|
||||||
|
{
|
||||||
|
super(); // initialize all bits to 0
|
||||||
|
for (int i=0; i<options.length; i++)
|
||||||
|
{ // look at all the chars in the option string and set bits accordingly
|
||||||
|
int ndx = ALPHA.indexOf(options[i]);
|
||||||
|
if (ndx>=0)
|
||||||
|
super.set(ndx);
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an <CODE>OptionSet</CODE> from a string of characters representing "set" options.
|
||||||
|
*
|
||||||
|
* @param options The options to be set in the new <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public OptionSet(String options)
|
||||||
|
{
|
||||||
|
this(options.toCharArray());
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal functions
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a <CODE>StringBuffer</CODE> representing the current state of this <CODE>OptionSet</CODE>,
|
||||||
|
* with one character in it for each bit that is set.
|
||||||
|
*
|
||||||
|
* @return A <CODE>StringBuffer</CODE> containing the current state of the <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
private StringBuffer asStringBuffer()
|
||||||
|
{
|
||||||
|
StringBuffer b = new StringBuffer();
|
||||||
|
for (int i=0; i<super.length(); i++)
|
||||||
|
if (super.get(i))
|
||||||
|
b.append(ALPHA.charAt(i));
|
||||||
|
return b;
|
||||||
|
|
||||||
|
} // end asStringBuffer
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class BitSet
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bit specified by the index to <CODE>false</CODE>.
|
||||||
|
*
|
||||||
|
* @param bitIndex The index of the bit to be cleared.
|
||||||
|
* @exception java.lang.IndexOutOfBoundsException If the specified index is negative or greater than the
|
||||||
|
* maximum option for an <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public void clear(int bitIndex)
|
||||||
|
{
|
||||||
|
if (bitIndex>=ALPHA.length())
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
super.clear(bitIndex);
|
||||||
|
|
||||||
|
} // end clear
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bits from the specified <CODE>fromIndex</CODE> (inclusive) to the specified <CODE>toIndex</CODE>
|
||||||
|
* (exclusive) to <CODE>false</CODE>.
|
||||||
|
*
|
||||||
|
* @param fromIndex Index of the first bit to be cleared.
|
||||||
|
* @param toIndex Index after the last bit to be cleared.
|
||||||
|
* @exception java.lang.IndexOutOfBoundException If <CODE>fromIndex</CODE> is negative, or <CODE>fromIndex</CODE>
|
||||||
|
* is greater than the maximum option for an <CODE>OptionSet</CODE>, or <CODE>toIndex</CODE> is negative,
|
||||||
|
* or <CODE>toIndex</CODE> is greater than the maximum option for an <CODE>OptionSet</CODE>, or
|
||||||
|
* <CODE>fromIndex</CODE> is larger than <CODE>toIndex</CODE>.
|
||||||
|
*/
|
||||||
|
public void clear(int fromIndex, int toIndex)
|
||||||
|
{
|
||||||
|
if ((fromIndex>=ALPHA.length()) || (toIndex>ALPHA.length()))
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
super.clear(fromIndex,toIndex);
|
||||||
|
|
||||||
|
} // end clear
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cloning this <CODE>OptionSet</CODE> produces a new <CODE>OptionSet</CODE> that is equal to it. The clone of the
|
||||||
|
* option set is another option set that has exactly the same bits set to true as this option set and the same
|
||||||
|
* current size.
|
||||||
|
*
|
||||||
|
* @return A clone of this option set.
|
||||||
|
*/
|
||||||
|
public Object clone()
|
||||||
|
{
|
||||||
|
OptionSet rc = new OptionSet(this.size());
|
||||||
|
for (int i=this.nextSetBit(0); i>=0; i=this.nextSetBit(i+1))
|
||||||
|
rc.set(i);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end clone
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bit at the specified index to to the complement of its current value.
|
||||||
|
*
|
||||||
|
* @param bitIndex The index of the bit to flip.
|
||||||
|
* @exception java.lang.IndexOutOfBoundsException If the specified index is negative or greater than the
|
||||||
|
* maximum option for an <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public void flip(int bitIndex)
|
||||||
|
{
|
||||||
|
if (bitIndex>=ALPHA.length())
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
super.flip(bitIndex);
|
||||||
|
|
||||||
|
} // end flip
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bits from the specified <CODE>fromIndex</CODE> (inclusive) to the specified <CODE>toIndex</CODE>
|
||||||
|
* (exclusive) to the complement of their current values.
|
||||||
|
*
|
||||||
|
* @param fromIndex Index of the first bit to be flipped.
|
||||||
|
* @param toIndex Index after the last bit to be flipped.
|
||||||
|
* @exception java.lang.IndexOutOfBoundException If <CODE>fromIndex</CODE> is negative, or <CODE>fromIndex</CODE>
|
||||||
|
* is greater than the maximum option for an <CODE>OptionSet</CODE>, or <CODE>toIndex</CODE> is negative,
|
||||||
|
* or <CODE>toIndex</CODE> is greater than the maximum option for an <CODE>OptionSet</CODE>, or
|
||||||
|
* <CODE>fromIndex</CODE> is larger than <CODE>toIndex</CODE>.
|
||||||
|
*/
|
||||||
|
public void flip(int fromIndex, int toIndex)
|
||||||
|
{
|
||||||
|
if ((fromIndex>=ALPHA.length()) || (toIndex>ALPHA.length()))
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
super.flip(fromIndex,toIndex);
|
||||||
|
|
||||||
|
} // end flip
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the bit with the specified index. The value is <CODE>true</CODE> if the bit with
|
||||||
|
* the index <CODE>bitIndex</CODE> is currently set in this <CODE>OptionSet</CODE>; otherwise, the result
|
||||||
|
* is <CODE>false</CODE>.
|
||||||
|
*
|
||||||
|
* @param bitIndex The bit index.
|
||||||
|
* @return The value of the bit with the specified index.
|
||||||
|
* @exception java.lang.IndexOutOfBoundsException If the specified index is negative or greater than the
|
||||||
|
* maximum option for an <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public boolean get(int bitIndex)
|
||||||
|
{
|
||||||
|
if (bitIndex>=ALPHA.length())
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
return super.get(bitIndex);
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new <CODE>OptionSet</CODE> composed of bits from this <CODE>OptionSet</CODE> from
|
||||||
|
* <CODE>fromIndex</CODE> (inclusive) to <CODE>toIndex</CODE> (exclusive).
|
||||||
|
*
|
||||||
|
* @param fromIndex Index of the first bit to be included.
|
||||||
|
* @param toIndex Index after the last bit to be included.
|
||||||
|
* @return A new <CODE>OptionSet</CODE> from a range of this <CODE>OptionSet</CODE>.
|
||||||
|
* @exception java.lang.IndexOutOfBoundException If <CODE>fromIndex</CODE> is negative, or <CODE>fromIndex</CODE>
|
||||||
|
* is greater than the maximum option for an <CODE>OptionSet</CODE>, or <CODE>toIndex</CODE> is negative,
|
||||||
|
* or <CODE>toIndex</CODE> is greater than the maximum option for an <CODE>OptionSet</CODE>, or
|
||||||
|
* <CODE>fromIndex</CODE> is larger than <CODE>toIndex</CODE>.
|
||||||
|
*/
|
||||||
|
public BitSet get(int fromIndex, int toIndex)
|
||||||
|
{
|
||||||
|
if ((fromIndex>=ALPHA.length()) || (toIndex>ALPHA.length()))
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
BitSet tmp = super.get(fromIndex,toIndex);
|
||||||
|
OptionSet rc = new OptionSet(tmp.size());
|
||||||
|
for (int i=tmp.nextSetBit(0); i>=0; i=tmp.nextSetBit(i+1))
|
||||||
|
rc.set(i);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bit specified by the index to <CODE>true</CODE>.
|
||||||
|
*
|
||||||
|
* @param bitIndex The index of the bit to be set.
|
||||||
|
* @exception java.lang.IndexOutOfBoundsException If the specified index is negative or greater than the
|
||||||
|
* maximum option for an <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public void set(int bitIndex)
|
||||||
|
{
|
||||||
|
if (bitIndex>=ALPHA.length())
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
super.set(bitIndex);
|
||||||
|
|
||||||
|
} // end set
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bit specified by the index to the specified value.
|
||||||
|
*
|
||||||
|
* @param bitIndex The index of the bit to be set.
|
||||||
|
* @param value A boolean value to set.
|
||||||
|
* @exception java.lang.IndexOutOfBoundsException If the specified index is negative or greater than the
|
||||||
|
* maximum option for an <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public void set(int bitIndex, boolean value)
|
||||||
|
{
|
||||||
|
if (bitIndex>=ALPHA.length())
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
super.set(bitIndex,value);
|
||||||
|
|
||||||
|
} // end set
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bits from the specified <CODE>fromIndex</CODE> (inclusive) to the specified <CODE>toIndex</CODE>
|
||||||
|
* (exclusive) to <CODE>true</CODE>.
|
||||||
|
*
|
||||||
|
* @param fromIndex Index of the first bit to be set.
|
||||||
|
* @param toIndex Index after the last bit to be set.
|
||||||
|
* @exception java.lang.IndexOutOfBoundException If <CODE>fromIndex</CODE> is negative, or <CODE>fromIndex</CODE>
|
||||||
|
* is greater than the maximum option for an <CODE>OptionSet</CODE>, or <CODE>toIndex</CODE> is negative,
|
||||||
|
* or <CODE>toIndex</CODE> is greater than the maximum option for an <CODE>OptionSet</CODE>, or
|
||||||
|
* <CODE>fromIndex</CODE> is larger than <CODE>toIndex</CODE>.
|
||||||
|
*/
|
||||||
|
public void set(int fromIndex, int toIndex)
|
||||||
|
{
|
||||||
|
if ((fromIndex>=ALPHA.length()) || (toIndex>ALPHA.length()))
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
super.set(fromIndex,toIndex);
|
||||||
|
|
||||||
|
} // end set
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bits from the specified <CODE>fromIndex</CODE> (inclusive) to the specified <CODE>toIndex</CODE>
|
||||||
|
* (exclusive) to the specified value.
|
||||||
|
*
|
||||||
|
* @param fromIndex Index of the first bit to be set.
|
||||||
|
* @param toIndex Index after the last bit to be set.
|
||||||
|
* @param value A boolean value to set.
|
||||||
|
* @exception java.lang.IndexOutOfBoundException If <CODE>fromIndex</CODE> is negative, or <CODE>fromIndex</CODE>
|
||||||
|
* is greater than the maximum option for an <CODE>OptionSet</CODE>, or <CODE>toIndex</CODE> is negative,
|
||||||
|
* or <CODE>toIndex</CODE> is greater than the maximum option for an <CODE>OptionSet</CODE>, or
|
||||||
|
* <CODE>fromIndex</CODE> is larger than <CODE>toIndex</CODE>.
|
||||||
|
*/
|
||||||
|
public void set(int fromIndex, int toIndex, boolean value)
|
||||||
|
{
|
||||||
|
if ((fromIndex>=ALPHA.length()) || (toIndex>ALPHA.length()))
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
super.set(fromIndex,toIndex,value);
|
||||||
|
|
||||||
|
} // end set
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the specified bit in the <CODE>OptionSet</CODE> to a specified Boolean
|
||||||
|
* value, and returns an indication of whether that value was changed.
|
||||||
|
*
|
||||||
|
* @param ndx The index of the bit to be assigned.
|
||||||
|
* @param val <CODE>true</CODE> to set the corresponding bit, <CODE>false</CODE> to clear it.
|
||||||
|
* @return <CODE>true</CODE> if the value of the bit in the <CODE>OptionSet</CODE> was changed by this
|
||||||
|
* operation, <CODE>false</CODE> if not.
|
||||||
|
* @exception java.lang.IndexOutOfBoundsException If the specified index is negative or greater than the
|
||||||
|
* maximum option for an <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public boolean assign(int ndx, boolean val)
|
||||||
|
{
|
||||||
|
if (ndx>=ALPHA.length())
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
boolean old = super.get(ndx);
|
||||||
|
super.set(ndx,val);
|
||||||
|
return (old!=val);
|
||||||
|
|
||||||
|
} // end assign
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the state of this <CODE>OptionSet</CODE> from an array of characters representing "set" options.
|
||||||
|
*
|
||||||
|
* @param options The options to be set in the new <CODE>OptionSet</CODE>. All options not specified will
|
||||||
|
* be cleared.
|
||||||
|
*/
|
||||||
|
public void assign(char[] options)
|
||||||
|
{
|
||||||
|
super.clear();
|
||||||
|
|
||||||
|
for (int i=0; i<options.length; i++)
|
||||||
|
{ // look at all the chars in the option string and set bits accordingly
|
||||||
|
int ndx = ALPHA.indexOf(options[i]);
|
||||||
|
if (ndx>=0)
|
||||||
|
super.set(ndx);
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
} // end assign
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the state of this <CODE>OptionSet</CODE> from a string of characters representing "set" options.
|
||||||
|
*
|
||||||
|
* @param options The options to be set in the new <CODE>OptionSet</CODE>. All options not specified will
|
||||||
|
* be cleared.
|
||||||
|
*/
|
||||||
|
public void assign(String options)
|
||||||
|
{
|
||||||
|
if (options!=null)
|
||||||
|
assign(options.toCharArray());
|
||||||
|
|
||||||
|
} // end assign
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a character array representing the current state of this <CODE>OptionSet</CODE>,
|
||||||
|
* with one character in it for each bit that is set.
|
||||||
|
*
|
||||||
|
* @return A character array containing the current state of the <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public char[] asCharArray()
|
||||||
|
{
|
||||||
|
return asStringBuffer().toString().toCharArray();
|
||||||
|
|
||||||
|
} // end asCharArray
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representing the current state of this <CODE>OptionSet</CODE>,
|
||||||
|
* with one character in it for each bit that is set.
|
||||||
|
*
|
||||||
|
* @return A string containing the current state of the <CODE>OptionSet</CODE>.
|
||||||
|
*/
|
||||||
|
public String asString()
|
||||||
|
{
|
||||||
|
return asStringBuffer().toString();
|
||||||
|
|
||||||
|
} // end asString
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the character associated with a specific "option index" by all <CODE>OptionSet</CODE> instances.
|
||||||
|
*
|
||||||
|
* @param index The index of the character to retrieve.
|
||||||
|
* @return The character associated with that index.
|
||||||
|
* @exception java.lang.IndexOutOfBoundsException If the specified index is out of range.
|
||||||
|
*/
|
||||||
|
public static final char getOptionChar(int index)
|
||||||
|
{
|
||||||
|
if ((index<0) || (index>=ALPHA.length()))
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
return ALPHA.charAt(index);
|
||||||
|
|
||||||
|
} // end getOptionChar
|
||||||
|
|
||||||
|
} // end class OptionSet
|
127
src/baseutil/com/silverwrist/util/SQLUtils.java
Normal file
127
src/baseutil/com/silverwrist/util/SQLUtils.java
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class containing miscellaneous public methods useful when working with SQL databases.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class SQLUtils
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLUtils instances should NOT be constructed in standard programming.
|
||||||
|
* Instead, the class should be used as <code>SQLUtils.shutdown(statement);</code>.
|
||||||
|
* This constructor is public to permit tools that require a JavaBean instance
|
||||||
|
* to operate.
|
||||||
|
*/
|
||||||
|
public SQLUtils()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes a <CODE>ResultSet</CODE> cleanly, without throwing an exception.
|
||||||
|
*
|
||||||
|
* @param rs The <CODE>ResultSet</CODE> to be closed.
|
||||||
|
* @see java.sql.ResultSet#close()
|
||||||
|
*/
|
||||||
|
public static final void shutdown(ResultSet rs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // close the ResultSet
|
||||||
|
if (rs!=null)
|
||||||
|
rs.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // ignore any SQL errors
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes a <CODE>Statement</CODE> cleanly, without throwing an exception.
|
||||||
|
*
|
||||||
|
* @param rs The <CODE>Statement</CODE> to be closed.
|
||||||
|
* @see java.sql.Statement#close()
|
||||||
|
*/
|
||||||
|
public static final void shutdown(Statement stmt)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // close the Statement
|
||||||
|
if (stmt!=null)
|
||||||
|
stmt.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // ignore any SQL errors
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes a <CODE>Connection</CODE> cleanly, without throwing an exception.
|
||||||
|
*
|
||||||
|
* @param rs The <CODE>Connection</CODE> to be closed.
|
||||||
|
* @see java.sql.Connection#close()
|
||||||
|
*/
|
||||||
|
public static final void shutdown(Connection conn)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // close the Connection
|
||||||
|
if (conn!=null)
|
||||||
|
conn.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // ignore any SQL errors
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the return count from a query such as "SELECT COUNT(*) FROM ...". All such queries will always
|
||||||
|
* return at least one row, with the count.
|
||||||
|
*
|
||||||
|
* @param rs The <CODE>ResultSet</CODE> returned from the query execution.
|
||||||
|
* @param column The column index in which the return value may be found.
|
||||||
|
* @return The value of that column (usually, the count you were querying for).
|
||||||
|
* @exception java.sql.SQLException If there was no returned row, or there was a data type mismatch on the column.
|
||||||
|
*/
|
||||||
|
public static final int getReturnCountInt(ResultSet rs, int column) throws SQLException
|
||||||
|
{
|
||||||
|
if (!(rs.next()))
|
||||||
|
throw new SQLException("expected return count row, not present");
|
||||||
|
return rs.getInt(column);
|
||||||
|
|
||||||
|
} // end getReturnCountInt
|
||||||
|
|
||||||
|
} // end class SQLUtils
|
349
src/baseutil/com/silverwrist/util/StringUtils.java
Normal file
349
src/baseutil/com/silverwrist/util/StringUtils.java
Normal file
|
@ -0,0 +1,349 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common string utilities. Inherits from the <CODE>org.apache.commons.lang.StringUtils</CODE>
|
||||||
|
* class, so it contains everything that contains.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class StringUtils extends org.apache.commons.lang.StringUtils
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static Logger logger = Logger.getLogger(StringUtils.class);
|
||||||
|
|
||||||
|
private static final char[] HTML_ENCODE_CHARS = { '"', '&', '<', '>' };
|
||||||
|
|
||||||
|
private static final String VAR_START = "${";
|
||||||
|
private static final String VAR_END = "}";
|
||||||
|
|
||||||
|
private static final Set TRUE_STRINGS;
|
||||||
|
private static final Set FALSE_STRINGS;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StringUtils instances should NOT be constructed in standard programming.
|
||||||
|
* Instead, the class should be used as <code>StringUtils.trim(" foo ");</code>.
|
||||||
|
* This constructor is public to permit tools that require a JavaBean instance
|
||||||
|
* to operate.
|
||||||
|
*/
|
||||||
|
public StringUtils()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs HTML encoding of an arbitrary string. When a string is HTML encoded, the double-quote ("),
|
||||||
|
* ampersand (&), less-than (<), and greater-than (>) characters are transformed to their HTML
|
||||||
|
* entity equivalents; all other characters are left untouched.
|
||||||
|
*
|
||||||
|
* @param str The string to be HTML-encoded. May be <B><CODE>null</CODE></B>.
|
||||||
|
* @return The HTML-encoded equivalent of <CODE>str</CODE>. If <CODE>str</CODE> is
|
||||||
|
* <B><CODE>null</CODE></B>, returns <B><CODE>null</CODE></B>.
|
||||||
|
*/
|
||||||
|
public static final String encodeHTML(String str)
|
||||||
|
{
|
||||||
|
if (str==null)
|
||||||
|
return null; // safety feature
|
||||||
|
AnyCharMatcher nhc = new AnyCharMatcher(HTML_ENCODE_CHARS);
|
||||||
|
int ndx = nhc.get(str);
|
||||||
|
if (ndx<0)
|
||||||
|
return str; // trivial short-circuit case
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
while (ndx>=0)
|
||||||
|
{ // append the matched "head" and then the encoded character
|
||||||
|
if (ndx>0)
|
||||||
|
buf.append(str.substring(0,ndx));
|
||||||
|
switch (str.charAt(ndx++))
|
||||||
|
{
|
||||||
|
case '"':
|
||||||
|
buf.append(""");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '&':
|
||||||
|
buf.append("&");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '<':
|
||||||
|
buf.append("<");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '>':
|
||||||
|
buf.append(">");
|
||||||
|
break;
|
||||||
|
|
||||||
|
} // end switch
|
||||||
|
|
||||||
|
if (ndx==str.length())
|
||||||
|
return buf.toString(); // munched the entire string - all done!
|
||||||
|
str = str.substring(ndx);
|
||||||
|
ndx = nhc.get(str);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
buf.append(str); // append the unmatched tail
|
||||||
|
return buf.toString();
|
||||||
|
|
||||||
|
} // end encodeHTML
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates a string into <CODE>application/x-www-form-urlencoded</CODE> format, using a UTF-8 encoding.
|
||||||
|
*
|
||||||
|
* @param s The string to be encoded. May be <CODE>null</CODE>.
|
||||||
|
* @return The translated string value, or <CODE>null</CODE> if <CODE>null</CODE> was passed in.
|
||||||
|
*/
|
||||||
|
public static final String encodeURL(String s)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // the old URLEncoder.encode(str) method is deprecated as of JDK1.4, use the new one
|
||||||
|
return ((s==null) ? null : URLEncoder.encode(s,"UTF-8"));
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (UnsupportedEncodingException e)
|
||||||
|
{ // this should never happen, but we gotta catch it anyway
|
||||||
|
logger.fatal("WTF? encodeURL doesn't support UTF-8? You're crazy!");
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end encodeURL
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns <CODE>true</CODE> if the given string is a representation of a Boolean <CODE>true</CODE> value.
|
||||||
|
* Values that represent a valid Boolean <CODE>true</CODE> value include "true", "yes", "on", and "1".
|
||||||
|
*
|
||||||
|
* @param test The string to be tested.
|
||||||
|
* @return <CODE>true</CODE> if the string represents a Boolean <CODE>true</CODE> value, <CODE>false</CODE> if not.
|
||||||
|
*/
|
||||||
|
public static final boolean isBooleanTrue(String test)
|
||||||
|
{
|
||||||
|
if (test==null)
|
||||||
|
return false;
|
||||||
|
return TRUE_STRINGS.contains(test.trim().toLowerCase());
|
||||||
|
|
||||||
|
} // end isBooleanTrue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns <CODE>true</CODE> if the given string is a representation of a Boolean <CODE>false</CODE> value.
|
||||||
|
* Values that represent a valid Boolean <CODE>false</CODE> value include "false", "no", "off", and "0".
|
||||||
|
*
|
||||||
|
* @param test The string to be tested.
|
||||||
|
* @return <CODE>true</CODE> if the string represents a Boolean <CODE>false</CODE> value, <CODE>false</CODE> if not.
|
||||||
|
*/
|
||||||
|
public static final boolean isBooleanFalse(String test)
|
||||||
|
{
|
||||||
|
if (test==null)
|
||||||
|
return false;
|
||||||
|
return FALSE_STRINGS.contains(test.trim().toLowerCase());
|
||||||
|
|
||||||
|
} // end isBooleanTrue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces variable substitutions in a string. Variable substitutions are strings of the form
|
||||||
|
* <CODE>${<EM>varname</EM>}</CODE>. The <EM>varname</EM> names are looked up in the supplied
|
||||||
|
* <CODE>Map</CODE>, and the values of variables in that map are substituted.<P>
|
||||||
|
* Only variable names that exist in the <CODE>Map</CODE> are replaced; other variable strings
|
||||||
|
* in the supplied string are left untouched. Variable substitution values may themselves contain
|
||||||
|
* variables; those variables are recursively replaced. (<B><EM>Caution:</EM></B> The code cannot
|
||||||
|
* detect variable substitutions that contain themselves, or two variables that contain each other.
|
||||||
|
* Avoid these situations.)
|
||||||
|
*
|
||||||
|
* @param base The string to be operated on. If this parameter is <CODE>null</CODE>, the
|
||||||
|
* method will return <CODE>null</CODE>.
|
||||||
|
* @param vars The mapping of variable name to value substitutions. If this parameter is
|
||||||
|
* <CODE>null</CODE> or an empty map, no substitutions will be performed on
|
||||||
|
* <CODE>base</CODE>.
|
||||||
|
* @return The <CODE>base</CODE> string with all variable substitutions made as detailed above.
|
||||||
|
*/
|
||||||
|
public static final String replaceAllVariables(String base, Map vars)
|
||||||
|
{
|
||||||
|
if ((base==null) || (vars==null) || vars.isEmpty())
|
||||||
|
return base; // safety feature
|
||||||
|
|
||||||
|
String work = base;
|
||||||
|
boolean did_replace = false;
|
||||||
|
boolean retest = true;
|
||||||
|
do
|
||||||
|
{ // main loop for replacing all variables
|
||||||
|
did_replace = false;
|
||||||
|
Iterator it = vars.keySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{ // variable start is there...
|
||||||
|
if (retest)
|
||||||
|
{ // only perform this test on the first iteration and after we know we've replaced a variable
|
||||||
|
if (work.indexOf(VAR_START)<0)
|
||||||
|
return work; // no more variables in text - all done!
|
||||||
|
retest = false;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
// get variable name and see if it's present
|
||||||
|
String vname = it.next().toString();
|
||||||
|
String var_full = VAR_START + vname + VAR_END;
|
||||||
|
if (work.indexOf(var_full)>=0)
|
||||||
|
{ // OK, this variable is in place
|
||||||
|
work = replace(work,var_full,vars.get(vname).toString());
|
||||||
|
did_replace = true;
|
||||||
|
retest = true;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} while (did_replace); // end do
|
||||||
|
|
||||||
|
return work; // all done!
|
||||||
|
|
||||||
|
} // end replaceAllVariables
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the provided text into a list, based on a given separator. The separator is not included in the
|
||||||
|
* returned String list. The maximum number of splits to perfom can be controlled.
|
||||||
|
*
|
||||||
|
* @param text The string to parse.
|
||||||
|
* @param separator Character used as the delimiter.
|
||||||
|
* @param limit The maximum number of elements to include in the list. A zero or negative value implies no limit.
|
||||||
|
* @return A list of parsed Strings.
|
||||||
|
*/
|
||||||
|
public static final List split1List(String text, char separator, int limit)
|
||||||
|
{
|
||||||
|
if (text==null)
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
|
if (limit<=0)
|
||||||
|
limit = Integer.MAX_VALUE;
|
||||||
|
ArrayList rc = new ArrayList();
|
||||||
|
String work = text;
|
||||||
|
int p = work.indexOf(separator);
|
||||||
|
while ((work.length()>0) && (p>=0) && (--limit>0))
|
||||||
|
{ // add elements to the ArrayList
|
||||||
|
if (p==0)
|
||||||
|
rc.add("");
|
||||||
|
else
|
||||||
|
rc.add(work.substring(0,p));
|
||||||
|
work = work.substring(p+1);
|
||||||
|
p = work.indexOf(separator);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
rc.add(work);
|
||||||
|
rc.trimToSize();
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end split1list
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the provided text into a list, based on a given separator. The separator is not included in the
|
||||||
|
* returned String list.
|
||||||
|
*
|
||||||
|
* @param text The string to parse.
|
||||||
|
* @param separator Character used as the delimiter.
|
||||||
|
* @return A list of parsed Strings.
|
||||||
|
*/
|
||||||
|
public static final List split1List(String text, char separator)
|
||||||
|
{
|
||||||
|
return split1List(text,separator,0);
|
||||||
|
|
||||||
|
} // end split1list
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the provided text into a list, based on a given separator. The separator is not included in the
|
||||||
|
* returned String array. The maximum number of splits to perfom can be controlled.
|
||||||
|
*
|
||||||
|
* @param text The string to parse.
|
||||||
|
* @param separator Character used as the delimiter.
|
||||||
|
* @param limit The maximum number of elements to include in the list. A zero or negative value implies no limit.
|
||||||
|
* @return An array of parsed Strings.
|
||||||
|
*/
|
||||||
|
public static final String[] split1(String text, char separator, int limit)
|
||||||
|
{
|
||||||
|
List tmp = split1List(text,separator,limit);
|
||||||
|
String[] rc = new String[tmp.size()];
|
||||||
|
tmp.toArray(rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end split1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the provided text into a list, based on a given separator. The separator is not included in the
|
||||||
|
* returned String array.
|
||||||
|
*
|
||||||
|
* @param text The string to parse.
|
||||||
|
* @param separator Character used as the delimiter.
|
||||||
|
* @return An array of parsed Strings.
|
||||||
|
*/
|
||||||
|
public static final String[] split1(String text, char separator)
|
||||||
|
{
|
||||||
|
return split1(text,separator,0);
|
||||||
|
|
||||||
|
} // end split1
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static initializer
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static
|
||||||
|
{ // get the boolean values resource
|
||||||
|
ResourceBundle bv = ResourceBundle.getBundle("com.silverwrist.util.BooleanValues");
|
||||||
|
|
||||||
|
// Load the Boolean "true" values.
|
||||||
|
String[] values = split(bv.getString("values.true"),"|");
|
||||||
|
HashSet tmp = new HashSet();
|
||||||
|
for (int i=0; i<values.length; i++)
|
||||||
|
tmp.add(values[i].toLowerCase());
|
||||||
|
tmp.add("1"); // always add the default English values, too
|
||||||
|
tmp.add("true");
|
||||||
|
tmp.add("yes");
|
||||||
|
tmp.add("on");
|
||||||
|
TRUE_STRINGS = Collections.unmodifiableSet(tmp);
|
||||||
|
|
||||||
|
// Load the Boolean "false" values.
|
||||||
|
values = split(bv.getString("values.false"),"|");
|
||||||
|
tmp = new HashSet();
|
||||||
|
for (int i=0; i<values.length; i++)
|
||||||
|
tmp.add(values[i].toLowerCase());
|
||||||
|
tmp.add("0"); // always add the default English values, too
|
||||||
|
tmp.add("false");
|
||||||
|
tmp.add("no");
|
||||||
|
tmp.add("off");
|
||||||
|
FALSE_STRINGS = Collections.unmodifiableSet(tmp);
|
||||||
|
|
||||||
|
} // end static initializer
|
||||||
|
|
||||||
|
} // end class StringUtils
|
261
src/baseutil/com/silverwrist/util/countries.properties
Normal file
261
src/baseutil/com/silverwrist/util/countries.properties
Normal file
|
@ -0,0 +1,261 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
# -------------------------------------------------------------------------------------
|
||||||
|
# This list of countries is taken from the ISO 3166 standard list of country names and
|
||||||
|
# 2-letter codes <http://www.din.de/gremien/nas/nabd/iso3166ma/>. When adding new
|
||||||
|
# entries to this file, make sure and add it in sorted order by country NAME! You can
|
||||||
|
# re-sort the country entries with "sort -t = -k 2 input > output", but then make sure
|
||||||
|
# the "XX=(unknown)" entry appears first!
|
||||||
|
XX=(unknown)
|
||||||
|
AF=Afghanistan
|
||||||
|
AL=Albania
|
||||||
|
DZ=Algeria
|
||||||
|
AS=American Samoa
|
||||||
|
AD=Andorra
|
||||||
|
AO=Angola
|
||||||
|
AI=Anguilla
|
||||||
|
AQ=Antarctica
|
||||||
|
AG=Antigua and Barbuda
|
||||||
|
AR=Argentina
|
||||||
|
AM=Armenia
|
||||||
|
AW=Aruba
|
||||||
|
AU=Australia
|
||||||
|
AT=Austria
|
||||||
|
AZ=Azerbaijan
|
||||||
|
BS=Bahamas
|
||||||
|
BH=Bahrain
|
||||||
|
BD=Bangladesh
|
||||||
|
BB=Barbados
|
||||||
|
BY=Belarus
|
||||||
|
BE=Belgium
|
||||||
|
BZ=Belize
|
||||||
|
BJ=Benin
|
||||||
|
BM=Bermuda
|
||||||
|
BT=Bhutan
|
||||||
|
BO=Bolivia
|
||||||
|
BA=Bosnia and Herzegovina
|
||||||
|
BW=Botswana
|
||||||
|
BV=Bouvet Island
|
||||||
|
BR=Brazil
|
||||||
|
IO=British Indian Ocean Territory
|
||||||
|
BN=Brunei Darussalam
|
||||||
|
BG=Bulgaria
|
||||||
|
BF=Burkina Faso
|
||||||
|
BI=Burundi
|
||||||
|
KH=Cambodia
|
||||||
|
CM=Cameroon
|
||||||
|
CA=Canada
|
||||||
|
CV=Cape Verde
|
||||||
|
KY=Cayman Islands
|
||||||
|
CF=Central African Republic
|
||||||
|
TD=Chad
|
||||||
|
CL=Chile
|
||||||
|
CN=China
|
||||||
|
CX=Chrismas Island
|
||||||
|
CC=Cocos (Keeling) Islands
|
||||||
|
CO=Colombia
|
||||||
|
KM=Comoros
|
||||||
|
CG=Congo
|
||||||
|
CD=Congo (Democratic Republic of)
|
||||||
|
CK=Cook Islands
|
||||||
|
CR=Costa Rica
|
||||||
|
CI=Cote D''Ivoire
|
||||||
|
HR=Croatia
|
||||||
|
CU=Cuba
|
||||||
|
CY=Cyprus
|
||||||
|
CZ=Czech Republic
|
||||||
|
DK=Denmark
|
||||||
|
DJ=Djibouti
|
||||||
|
DM=Dominica
|
||||||
|
DO=Dominican Republic
|
||||||
|
TP=East Timor
|
||||||
|
EC=Ecuador
|
||||||
|
EG=Egypt
|
||||||
|
SV=El Salvador
|
||||||
|
GQ=Equatorial Guinea
|
||||||
|
ER=Eritrea
|
||||||
|
EE=Estonia
|
||||||
|
ET=Ethiopia
|
||||||
|
FK=Falkland Islands (Malvinas)
|
||||||
|
FO=Faroe Islands
|
||||||
|
FJ=Fiji
|
||||||
|
FI=Finland
|
||||||
|
FR=France
|
||||||
|
GF=French Guiana
|
||||||
|
PF=French Polynesia
|
||||||
|
TF=French Southern Territories
|
||||||
|
GA=Gabon
|
||||||
|
GM=Gambia
|
||||||
|
GE=Georgia
|
||||||
|
DE=Germany
|
||||||
|
GH=Ghana
|
||||||
|
GI=Gibraltar
|
||||||
|
GR=Greece
|
||||||
|
GL=Greenland
|
||||||
|
GD=Grenada
|
||||||
|
GP=Guadeloupe
|
||||||
|
GU=Guam
|
||||||
|
GT=Guatemala
|
||||||
|
GN=Guinea
|
||||||
|
GW=Guinea-Bissau
|
||||||
|
GY=Guyana
|
||||||
|
HT=Haiti
|
||||||
|
HM=Heard Island and McDonald Islands
|
||||||
|
VA=Holy See (Vatican City State)
|
||||||
|
HN=Honduras
|
||||||
|
HK=Hong Kong
|
||||||
|
HU=Hungary
|
||||||
|
IS=Iceland
|
||||||
|
IN=India
|
||||||
|
ID=Indonesia
|
||||||
|
IR=Iran (Islamic Republic of)
|
||||||
|
IQ=Iraq
|
||||||
|
IE=Ireland
|
||||||
|
IL=Israel
|
||||||
|
IT=Italy
|
||||||
|
JM=Jamaica
|
||||||
|
JP=Japan
|
||||||
|
JO=Jordan
|
||||||
|
KZ=Kazakhstan
|
||||||
|
KE=Kenya
|
||||||
|
KI=Kiribati
|
||||||
|
KP=Korea (Democratic People's Republic of)
|
||||||
|
KR=Korea (Republic of)
|
||||||
|
KW=Kuwait
|
||||||
|
KG=Kyrgyzstan
|
||||||
|
LA=Lao People's Democratic Republic
|
||||||
|
LV=Latvia
|
||||||
|
LB=Lebanon
|
||||||
|
LS=Lesotho
|
||||||
|
LR=Liberia
|
||||||
|
LY=Libyan Arab Jamahirya
|
||||||
|
LI=Liechtenstein
|
||||||
|
LT=Lithuania
|
||||||
|
LU=Luxembourg
|
||||||
|
MO=Macau
|
||||||
|
MK=Macedonia (Former Yugoslav Republic of)
|
||||||
|
MG=Madagascar
|
||||||
|
MW=Malawi
|
||||||
|
MY=Malaysia
|
||||||
|
MV=Maldives
|
||||||
|
ML=Mali
|
||||||
|
MT=Malta
|
||||||
|
MH=Marshall Islands
|
||||||
|
MQ=Martinique
|
||||||
|
MR=Mauritania
|
||||||
|
MU=Mauritius
|
||||||
|
YT=Mayotte
|
||||||
|
MX=Mexico
|
||||||
|
FM=Micronesia (Federated States of)
|
||||||
|
MD=Moldova, Republic of
|
||||||
|
MC=Monaco
|
||||||
|
MN=Mongolia
|
||||||
|
MS=Montserrat
|
||||||
|
MA=Morocco
|
||||||
|
MZ=Mozambique
|
||||||
|
MM=Myanmar
|
||||||
|
NA=Namibia
|
||||||
|
NR=Nauru
|
||||||
|
NP=Nepal
|
||||||
|
NL=Netherlands
|
||||||
|
AN=Netherlands Antillies
|
||||||
|
NC=New Caledonia
|
||||||
|
NZ=New Zealand
|
||||||
|
NI=Nicaragua
|
||||||
|
NE=Niger
|
||||||
|
NG=Nigeria
|
||||||
|
NU=Niue
|
||||||
|
NF=Norfolk Island
|
||||||
|
MP=Northern Mariana Islands'),
|
||||||
|
NO=Norway
|
||||||
|
OM=Oman
|
||||||
|
PK=Pakistan
|
||||||
|
PW=Palau
|
||||||
|
PS=Palestinian Territory, Occupied
|
||||||
|
PA=Panama
|
||||||
|
PG=Papua New Guinea
|
||||||
|
PY=Paraguay
|
||||||
|
PE=Peru
|
||||||
|
PH=Phillipines
|
||||||
|
PN=Pitcairn
|
||||||
|
PL=Poland
|
||||||
|
PT=Portugal
|
||||||
|
PR=Puerto Rico
|
||||||
|
QA=Qatar
|
||||||
|
RE=Reunion
|
||||||
|
RO=Romania
|
||||||
|
RU=Russian Federation
|
||||||
|
RW=Rwanda
|
||||||
|
SH=Saint Helena
|
||||||
|
KN=Saint Kitts and Nevis
|
||||||
|
LC=Saint Lucia
|
||||||
|
PM=Saint Pierre and Miquelon
|
||||||
|
VC=Saint Vincent and The Grenadines
|
||||||
|
WS=Samoa
|
||||||
|
SM=San Marino
|
||||||
|
ST=Sao Tome and Principe
|
||||||
|
SA=Saudi Arabia
|
||||||
|
SN=Senegal
|
||||||
|
SC=Seychelles
|
||||||
|
SL=Sierra Leone
|
||||||
|
SG=Singapore
|
||||||
|
SK=Slovakia
|
||||||
|
SI=Slovenia
|
||||||
|
SB=Solomon Islands
|
||||||
|
SO=Somalia
|
||||||
|
ZA=South Africa
|
||||||
|
GS=South Georgia and the South Sandwich Islands
|
||||||
|
ES=Spain
|
||||||
|
LK=Sri Lanka
|
||||||
|
SD=Sudan
|
||||||
|
SR=Suriname
|
||||||
|
SJ=Svalbard and Jan Mayen
|
||||||
|
SZ=Swaziland
|
||||||
|
SE=Sweden
|
||||||
|
CH=Switzerland
|
||||||
|
SY=Syrian Arab Republic
|
||||||
|
TW=Taiwan (Province of China)
|
||||||
|
TJ=Tajikistan
|
||||||
|
TZ=Tanzania, United Republic of
|
||||||
|
TH=Thailand
|
||||||
|
TG=Togo
|
||||||
|
TK=Tokelau
|
||||||
|
TO=Tonga
|
||||||
|
TT=Trinidad and Tobago
|
||||||
|
TN=Tunisia
|
||||||
|
TR=Turkey
|
||||||
|
TM=Turkmenistan
|
||||||
|
TC=Turks and Caicos Islands
|
||||||
|
TV=Tuvalu
|
||||||
|
UG=Uganda
|
||||||
|
UA=Ukraine
|
||||||
|
AE=United Arab Emirates
|
||||||
|
GB=United Kingdom
|
||||||
|
US=United States
|
||||||
|
UM=United States Minor Outlying Islands
|
||||||
|
UY=Uruguay
|
||||||
|
UZ=Uzbekistan
|
||||||
|
VU=Vanatu
|
||||||
|
VE=Venezuela
|
||||||
|
VN=Viet Nam
|
||||||
|
VG=Virgin Islands (British)
|
||||||
|
VI=Virgin Islands (U.S.)
|
||||||
|
WF=Wallis and Futuna
|
||||||
|
EH=Western Sahara
|
||||||
|
YE=Yemen
|
||||||
|
YU=Yugoslavia
|
||||||
|
ZM=Zambia
|
||||||
|
ZW=Zimbabwe
|
272
src/baseutil/com/silverwrist/util/image/ImageNormalizer.java
Normal file
272
src/baseutil/com/silverwrist/util/image/ImageNormalizer.java
Normal file
|
@ -0,0 +1,272 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util.image;
|
||||||
|
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.image.*;
|
||||||
|
import java.awt.image.renderable.ParameterBlock;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.imageio.*;
|
||||||
|
import javax.imageio.stream.*;
|
||||||
|
import javax.media.jai.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that performs "normalization" on an image to fit within a bounding box of a specified pixel
|
||||||
|
* size. "Normalized" images are scaled down proportionally to fit the bounding box, then centered over
|
||||||
|
* a black backdrop (so the image will be "letterboxed" if it has a larger H:V aspect ratio than the bounding
|
||||||
|
* box, or "pillarboxed" if it has a smaller H:V aspect ratio than the bounding box).
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class ImageNormalizer
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ImageNormalizer instances should NOT be constructed in standard programming.
|
||||||
|
* Instead, the class should be used as <code>ImageNormalizer.normalizeImage(...);</code>.
|
||||||
|
* This constructor is public to permit tools that require a JavaBean instance
|
||||||
|
* to operate.
|
||||||
|
*/
|
||||||
|
public ImageNormalizer()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Normalizes" an image to fit within a bounding box of a specified pixel size. "Normalized" images are
|
||||||
|
* scaled down proportionally to fit the bounding box, then centered over a black backdrop (so the image
|
||||||
|
* will be "letterboxed" if it has a larger H:V aspect ratio than the bounding box, or "pillarboxed" if it
|
||||||
|
* has a smaller H:V aspect ratio than the bounding box).
|
||||||
|
*
|
||||||
|
* @param image_data Raw image data from the input, in any ImageIO-recognized format.
|
||||||
|
* @param width The width of the bounding box to use to normalize the image.
|
||||||
|
* @param height The height of the bounding box to use to normalize the image.
|
||||||
|
* @param output_type The desired MIME type for output (such as "image/jpeg").
|
||||||
|
* @return The normalized image data as a byte array.
|
||||||
|
* @exception com.silverwrist.util.image.ImageNormalizerException An error occurred in the image data or
|
||||||
|
* the image transformation process.
|
||||||
|
* @see ImageNormalizerException
|
||||||
|
*/
|
||||||
|
public static byte[] normalizeImage(InputStream image_data, int width, int height, String output_type)
|
||||||
|
throws ImageNormalizerException
|
||||||
|
{
|
||||||
|
PlanarImage img1; // initial image
|
||||||
|
try
|
||||||
|
{ // get an image input stream for the image
|
||||||
|
ImageInputStream iistm = ImageIO.createImageInputStream(image_data);
|
||||||
|
|
||||||
|
// create the "ImageRead" operation to load the image; it will autodetect the
|
||||||
|
// image format and create an appropriate ImageReader
|
||||||
|
ParameterBlock pb = new ParameterBlock();
|
||||||
|
pb.add(iistm);
|
||||||
|
pb.add(new Integer(0));
|
||||||
|
pb.add(Boolean.FALSE);
|
||||||
|
pb.add(Boolean.FALSE);
|
||||||
|
RenderedOp rop = JAI.create("ImageRead",pb);
|
||||||
|
img1 = rop.getRendering();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // try to create the ImageInputStream
|
||||||
|
throw new ImageNormalizerException("Unable to load image",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (RuntimeException re)
|
||||||
|
{ // unable to get the rendering here!
|
||||||
|
throw new ImageNormalizerException("Image data not a valid image format",re);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // Compute the scaling factors required to get the image down to the appropriate size, then choose
|
||||||
|
// the smaller of the two to use as the final scaling factor. Note that we always scale DOWN,
|
||||||
|
// not UP.
|
||||||
|
Float scale_width = null, scale_height = null;
|
||||||
|
if (img1.getWidth()>width)
|
||||||
|
scale_width = new Float((float)width / (float)(img1.getWidth()));
|
||||||
|
if (img1.getHeight()>height)
|
||||||
|
scale_height = new Float((float)height / (float)(img1.getHeight()));
|
||||||
|
Float scale = null;
|
||||||
|
if (scale_width!=null)
|
||||||
|
{ // we can scale by width, how about height?
|
||||||
|
if (scale_height!=null)
|
||||||
|
{ // yes, height too...pick the smaller of the two
|
||||||
|
if (scale_width.floatValue()<scale_height.floatValue())
|
||||||
|
scale = scale_width;
|
||||||
|
else
|
||||||
|
scale = scale_height;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else // no, just width
|
||||||
|
scale = scale_width;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else if (scale_height!=null) // can only scale by height
|
||||||
|
scale = scale_height;
|
||||||
|
|
||||||
|
// If we need to scale the image now, do so.
|
||||||
|
PlanarImage img2; // image post-scaling
|
||||||
|
if (scale!=null)
|
||||||
|
{ // scale the image down!
|
||||||
|
ParameterBlock pb1 = new ParameterBlock();
|
||||||
|
pb1.addSource(img1);
|
||||||
|
pb1.add(scale.floatValue());
|
||||||
|
pb1.add(scale.floatValue());
|
||||||
|
pb1.add(0.0F);
|
||||||
|
pb1.add(0.0F);
|
||||||
|
pb1.add(Interpolation.getInstance(Interpolation.INTERP_BILINEAR));
|
||||||
|
img2 = JAI.create("scale",pb1);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else // just use this as the next image
|
||||||
|
img2 = img1;
|
||||||
|
|
||||||
|
// Figure out the offsets required to center the new image within the "frame."
|
||||||
|
int offset_x = (width - img2.getWidth()) / 2;
|
||||||
|
int offset_y = (height - img2.getHeight()) / 2;
|
||||||
|
|
||||||
|
// If we need to translate the image now, do so.
|
||||||
|
PlanarImage img3; // image after scaling and translation
|
||||||
|
if ((offset_x!=0) || (offset_y!=0))
|
||||||
|
{ // set up a translation to move the image to the right location
|
||||||
|
ParameterBlock pb2 = new ParameterBlock();
|
||||||
|
pb2.addSource(img2);
|
||||||
|
pb2.add((float)offset_x);
|
||||||
|
pb2.add((float)offset_y);
|
||||||
|
pb2.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST));
|
||||||
|
img3 = JAI.create("translate",pb2);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else // just take the image as it is
|
||||||
|
img3 = img2;
|
||||||
|
|
||||||
|
// To set up the backdrop, first we need to create an image of the right size but with the same
|
||||||
|
// sample model and color model as our transformed image.
|
||||||
|
TiledImage back1 = new TiledImage(0,0,width,height,0,0,img3.getSampleModel(),img3.getColorModel());
|
||||||
|
|
||||||
|
// Now we need to make that image black. The easiest way to do that is multiply all pixel
|
||||||
|
// values in the image by 0.
|
||||||
|
ParameterBlock pb = new ParameterBlock();
|
||||||
|
pb.addSource(back1);
|
||||||
|
double[] parms = new double[1];
|
||||||
|
parms[0] = 0.0;
|
||||||
|
pb.add(parms);
|
||||||
|
PlanarImage back2 = JAI.create("multiplyconst",pb);
|
||||||
|
|
||||||
|
// Now overlay the scaled/translated image on top of the background to get the final image.
|
||||||
|
PlanarImage final_img = JAI.create("overlay",back2,img3);
|
||||||
|
|
||||||
|
// Now we need to output this new image in the right format.
|
||||||
|
ByteArrayOutputStream stm = new ByteArrayOutputStream();
|
||||||
|
ImageOutputStream iostm = ImageIO.createImageOutputStream(stm);
|
||||||
|
|
||||||
|
// Get an ImageWriter for the MIME type.
|
||||||
|
Iterator it = ImageIO.getImageWritersByMIMEType(output_type);
|
||||||
|
ImageWriter iwr = (ImageWriter)(it.next());
|
||||||
|
|
||||||
|
// Create the ParameterBlock and the operation. Most of the parameters are null, but we
|
||||||
|
// do need to specify the ImageWriter right at the end.
|
||||||
|
pb = new ParameterBlock();
|
||||||
|
pb.addSource(final_img);
|
||||||
|
pb.add(iostm);
|
||||||
|
pb.add(null);
|
||||||
|
pb.add(Boolean.FALSE);
|
||||||
|
pb.add(Boolean.FALSE);
|
||||||
|
pb.add(Boolean.TRUE);
|
||||||
|
pb.add(Boolean.FALSE);
|
||||||
|
pb.add(null);
|
||||||
|
pb.add(null);
|
||||||
|
pb.add(null);
|
||||||
|
pb.add(null);
|
||||||
|
pb.add(null);
|
||||||
|
pb.add(null);
|
||||||
|
pb.add(null);
|
||||||
|
pb.add(iwr);
|
||||||
|
RenderedOp rop = JAI.create("ImageWrite",pb);
|
||||||
|
rop.getSourceImage(0).removeSink(rop); // disconnect the image modification mechanism
|
||||||
|
|
||||||
|
// Return the new image data.
|
||||||
|
iostm.flush();
|
||||||
|
return stm.toByteArray();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (Exception e)
|
||||||
|
{ // catchall exception
|
||||||
|
throw new ImageNormalizerException("error in scaling or translation: " + e.getMessage(),e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end normalizeImage
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Test code
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple piece of test code for the <CODE>ImageNormalizer</CODE>, which reads an image from one file,
|
||||||
|
* normalizes it, and writes it to a second file.
|
||||||
|
*
|
||||||
|
* @param args Command-line arguments. The first of these should be the name of the input file, and the
|
||||||
|
* second should be the name of the output file.
|
||||||
|
* @return (Exit code) 0 on success, 1 on error.
|
||||||
|
*/
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
if (args.length<2)
|
||||||
|
{ // make sure we have 2 arguments
|
||||||
|
System.out.println("Usage: ImageNormalizer input-file output-file");
|
||||||
|
System.exit(1);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // very simple, very easy
|
||||||
|
FileInputStream instm = new FileInputStream(args[0]);
|
||||||
|
byte[] outdata = normalizeImage(instm,100,100,"image/jpeg");
|
||||||
|
instm.close();
|
||||||
|
FileOutputStream outstm = new FileOutputStream(args[1]);
|
||||||
|
outstm.write(outdata);
|
||||||
|
outstm.close();
|
||||||
|
System.out.println(args[0] + " => " + args[1]);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (Exception e)
|
||||||
|
{ // dump exception on error
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
|
|
||||||
|
} // end main
|
||||||
|
|
||||||
|
} // end class ImageNormalizer
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util.image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates an error in the image normalization process.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
* @see com.silverwrist.util.image.ImageNormalizer#normalizeImage(java.io.InputStream,int,int,java.lang.String)
|
||||||
|
*/
|
||||||
|
public class ImageNormalizerException extends Exception
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructors
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>ImageNormalizerException</CODE>.
|
||||||
|
*/
|
||||||
|
public ImageNormalizerException()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>ImageNormalizerException</CODE>.
|
||||||
|
*
|
||||||
|
* @param message Message for the exception.
|
||||||
|
*/
|
||||||
|
public ImageNormalizerException(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>ImageNormalizerException</CODE>.
|
||||||
|
*
|
||||||
|
* @param t The exception to be wrapped by this one.
|
||||||
|
*/
|
||||||
|
public ImageNormalizerException(Throwable t)
|
||||||
|
{
|
||||||
|
super(t);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>ImageNormalizerException</CODE>.
|
||||||
|
*
|
||||||
|
* @param message Message for the exception.
|
||||||
|
* @param t The exception to be wrapped by this one.
|
||||||
|
*/
|
||||||
|
public ImageNormalizerException(String message, Throwable t)
|
||||||
|
{
|
||||||
|
super(message,t);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
} // end class ImageNormalizerException
|
254
src/baseutil/com/silverwrist/util/languages.properties
Normal file
254
src/baseutil/com/silverwrist/util/languages.properties
Normal file
|
@ -0,0 +1,254 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
# -------------------------------------------------------------------------------------
|
||||||
|
# This list of languages is styled on RFC 1766, based on ISO 639 language code listings,
|
||||||
|
# from <http://www.w3.org/WAI/ER/IG/ert/iso639.htm>, and ISO 3166 country code listings,
|
||||||
|
# from <http://www.din.de/gremien/nas/nabd/iso3166ma/>. Language variants by country taken
|
||||||
|
# from WINNT.H header file, Microsoft Windows Platform SDK. Additional language codes
|
||||||
|
# (i- names and expanded zh- names) from IANA, <ftp://ftp.isi.edu/in-notes/iana/assignments/languages/>.
|
||||||
|
# Changes to Indonesian, Hebrew, and Yiddish noted from Java 2 SDK documentation.
|
||||||
|
# When adding new entries to this file, make sure and add it in sorted order by language NAME!
|
||||||
|
# You can re-sort the language entries with "sort -t = -k 2 input > output", but then make sure
|
||||||
|
# the "i-default=(unknown)" entry appears first!
|
||||||
|
i-default=(unknown)
|
||||||
|
ab=Abkhazian
|
||||||
|
aa=Afar
|
||||||
|
af=Afrikaans
|
||||||
|
sq=Albanian
|
||||||
|
am=Amharic
|
||||||
|
i-ami=Amis
|
||||||
|
ar=Arabic
|
||||||
|
ar-DZ=Arabic (Algeria)
|
||||||
|
ar-BH=Arabic (Bahrain)
|
||||||
|
ar-EG=Arabic (Egypt)
|
||||||
|
ar-IQ=Arabic (Iraq)
|
||||||
|
ar-JO=Arabic (Jordan)
|
||||||
|
ar-KW=Arabic (Kuwait)
|
||||||
|
ar-LB=Arabic (Lebanon)
|
||||||
|
ar-LY=Arabic (Libya)
|
||||||
|
ar-MA=Arabic (Morocco)
|
||||||
|
ar-OM=Arabic (Oman)
|
||||||
|
ar-QA=Arabic (Qatar)
|
||||||
|
ar-SA=Arabic (Saudi Arabia)
|
||||||
|
ar-SY=Arabic (Syria)
|
||||||
|
ar-TN=Arabic (Tunisia)
|
||||||
|
ar-AE=Arabic (U.A.E.)
|
||||||
|
ar-YE=Arabic (Yemen)
|
||||||
|
hy=Armenian
|
||||||
|
as=Assamese
|
||||||
|
ay=Aymara
|
||||||
|
az=Azerbaijani
|
||||||
|
ba=Bashkir
|
||||||
|
eu=Basque
|
||||||
|
bn=Bengali
|
||||||
|
bh=Bihari
|
||||||
|
bi=Bislama
|
||||||
|
br=Breton
|
||||||
|
bg=Bulgarian
|
||||||
|
i-bnn=Bunun
|
||||||
|
my=Burmese
|
||||||
|
be=Byelorussian
|
||||||
|
km=Cambodian
|
||||||
|
ca=Catalan
|
||||||
|
zh=Chinese
|
||||||
|
zh-yue=Chinese (Cantonese)
|
||||||
|
zh-gan=Chinese (Gan)
|
||||||
|
zh-hakka=Chinese (Hakka)
|
||||||
|
zh-HK=Chinese (Hong Kong)
|
||||||
|
zh-xiang=Chinese (Hunan)
|
||||||
|
zh-guoyu=Chinese (Mandarin)
|
||||||
|
zh-wuu=Chinese (Shanghai)
|
||||||
|
zh-CN=Chinese (Simplified)
|
||||||
|
zh-SG=Chinese (Singapore)
|
||||||
|
zh-min=Chinese (Taiwanese)
|
||||||
|
zh-TW=Chinese (Traditional)
|
||||||
|
co=Corsican
|
||||||
|
hr=Croatian
|
||||||
|
cs=Czech
|
||||||
|
da=Danish
|
||||||
|
nl=Dutch
|
||||||
|
nl-BE=Dutch (Belgian)
|
||||||
|
dz=Dzongkha
|
||||||
|
en=English
|
||||||
|
en-AU=English (Australian)
|
||||||
|
en-BZ=English (Belize)
|
||||||
|
en-CA=English (Canadian)
|
||||||
|
en-caribbean=English (Caribbean)
|
||||||
|
en-IE=English (Irish)
|
||||||
|
en-JM=English (Jamaica)
|
||||||
|
en-NZ=English (New Zealand)
|
||||||
|
en-scouse=English (Scouse)
|
||||||
|
en-ZA=English (South Africa)
|
||||||
|
en-TT=English (Trinidad)
|
||||||
|
en-GB=English (United Kingdom)
|
||||||
|
en-US=English (United States)
|
||||||
|
eo=Esperanto
|
||||||
|
et=Estonian
|
||||||
|
fo=Faeroese
|
||||||
|
fj=Fiji
|
||||||
|
fi=Finnish
|
||||||
|
fr=French
|
||||||
|
fr-BE=French (Belgian)
|
||||||
|
fr-CA=French (Canadian)
|
||||||
|
fr-LU=French (Luxembourg)
|
||||||
|
fr-CH=French (Swiss)
|
||||||
|
fy=Frisian
|
||||||
|
gl=Gallegan
|
||||||
|
ka=Georgian
|
||||||
|
de=German
|
||||||
|
de-AT=German (Austria)
|
||||||
|
de-LI=German (Liechtenstein)
|
||||||
|
de-LU=German (Luxembourg)
|
||||||
|
de-CH=German (Swiss)
|
||||||
|
el=Greek
|
||||||
|
kl=Greenlandic
|
||||||
|
gn=Guarani
|
||||||
|
gu=Gujarati
|
||||||
|
i-hak=Hakka
|
||||||
|
ha=Hausa
|
||||||
|
he=Hebrew
|
||||||
|
hi=Hindi
|
||||||
|
hu=Hungarian
|
||||||
|
is=Icelandic
|
||||||
|
id=Indonesian
|
||||||
|
ia=Interlingua
|
||||||
|
ie=Interlingue
|
||||||
|
iu=Inuktitut
|
||||||
|
ik=Inupiak
|
||||||
|
ga=Irish
|
||||||
|
it=Italian
|
||||||
|
it-CH=Italian (Swiss)
|
||||||
|
ja=Japanese
|
||||||
|
jw=Javanese
|
||||||
|
kn=Kannada
|
||||||
|
ks=Kashmiri
|
||||||
|
km=Khmer
|
||||||
|
kk=Kazakh
|
||||||
|
rw=Kinyarwanda
|
||||||
|
ky=Kirghiz
|
||||||
|
rn=Kirundi
|
||||||
|
i-klingon=Klingon
|
||||||
|
ko=Korean
|
||||||
|
ko-johab=Korean (Johab)
|
||||||
|
ku=Kurdish
|
||||||
|
oc=Langue d'Oc
|
||||||
|
lo=Lao
|
||||||
|
la=Latin
|
||||||
|
lv=Latvian
|
||||||
|
ln=Lingala
|
||||||
|
lt=Lithuanian
|
||||||
|
i-lux=Luxembourgish
|
||||||
|
mk=Macedonian
|
||||||
|
mg=Malagasy
|
||||||
|
ms=Malay
|
||||||
|
ml=Maltese
|
||||||
|
mi=Maori
|
||||||
|
mr=Marathi
|
||||||
|
i-mingo=Mingo
|
||||||
|
mo=Moldavian
|
||||||
|
mn=Mongolian
|
||||||
|
na=Nauru
|
||||||
|
i-navajo=Navajo
|
||||||
|
ne=Nepali
|
||||||
|
no=Norwegian
|
||||||
|
no-bok=Norwegian (Bokmal)
|
||||||
|
no-nyn=Norwegian (Nynorsk)
|
||||||
|
oc=Occitan
|
||||||
|
or=Oriya
|
||||||
|
om=Oromo
|
||||||
|
i-pwn=Paiwan
|
||||||
|
pa=Panjabi
|
||||||
|
ps=Pashto
|
||||||
|
fa=Persian
|
||||||
|
pl=Polish
|
||||||
|
pt=Portuguese
|
||||||
|
pt-BR=Portuguese (Brazilian)
|
||||||
|
ps=Pushto
|
||||||
|
qu=Quechua
|
||||||
|
rm=Rhaeto-Romance
|
||||||
|
ro=Romanian
|
||||||
|
rn=Rundi
|
||||||
|
ru=Russian
|
||||||
|
sm=Samoan
|
||||||
|
sg=Sango
|
||||||
|
sa=Sanskrit
|
||||||
|
gd=Scots Gaelic
|
||||||
|
sr-cyrillic=Serbian (Cyrillic)
|
||||||
|
sr=Serbian (Latin)
|
||||||
|
sh=Serbo-Croatian
|
||||||
|
st=Sesotho
|
||||||
|
sn=Shona
|
||||||
|
sd=Sindhi
|
||||||
|
si=Singhalese
|
||||||
|
ss=Siswant
|
||||||
|
sk=Slovak
|
||||||
|
sl=Slovenian
|
||||||
|
so=Somali
|
||||||
|
st=Sotho
|
||||||
|
es-AR=Spanish (Argentina)
|
||||||
|
es-BO=Spanish (Bolivia)
|
||||||
|
es-ES=Spanish (Castilian)
|
||||||
|
es-CL=Spanish (Chile)
|
||||||
|
es-CO=Spanish (Colombia)
|
||||||
|
es-CR=Spanish (Costa Rica)
|
||||||
|
es-DO=Spanish (Dominican Republic)
|
||||||
|
es-EC=Spanish (Ecuador)
|
||||||
|
es-SV=Spanish (El Salvador)
|
||||||
|
es-GT=Spanish (Guatemala)
|
||||||
|
es-HN=Spanish (Honduras)
|
||||||
|
es-MX=Spanish (Mexican)
|
||||||
|
es=Spanish (Modern)
|
||||||
|
es-NI=Spanish (Nicaragua)
|
||||||
|
es-PA=Spanish (Panama)
|
||||||
|
es-PY=Spanish (Paraguay)
|
||||||
|
es-PE=Spanish (Peru)
|
||||||
|
es-PR=Spanish (Puerto Rico)
|
||||||
|
es-UY=Spanish (Uruguay)
|
||||||
|
es-VE=Spanish (Venezuela)
|
||||||
|
su=Sudanese
|
||||||
|
sw=Swahili
|
||||||
|
sv=Swedish
|
||||||
|
sv-FI=Swedish (Finland)
|
||||||
|
tl=Tagalog
|
||||||
|
tg=Tajik
|
||||||
|
ta=Tamil
|
||||||
|
i-tao=Tao
|
||||||
|
tt=Tatar
|
||||||
|
i-tay=Tayal
|
||||||
|
te=Tegulu
|
||||||
|
th=Thai
|
||||||
|
bo=Tibetan
|
||||||
|
ti=Tigrinya
|
||||||
|
to=Tonga
|
||||||
|
ts=Tsonga
|
||||||
|
i-tsu=Tsou
|
||||||
|
tn=Tswana
|
||||||
|
tr=Turkish
|
||||||
|
tk=Turkmen
|
||||||
|
tw=Twi
|
||||||
|
ug=Uighur
|
||||||
|
uk=Ukrainian
|
||||||
|
ur=Urdu
|
||||||
|
uz=Uzbek
|
||||||
|
vi=Vietnamese
|
||||||
|
vo=Volapuk
|
||||||
|
cy=Welsh
|
||||||
|
wo=Wolof
|
||||||
|
xh=Xhosa
|
||||||
|
yi=Yiddish
|
||||||
|
yo=Yoruba
|
||||||
|
za=Zhuang
|
||||||
|
zu=Zulu
|
489
src/baseutil/com/silverwrist/util/xml/DOMElementHelper.java
Normal file
489
src/baseutil/com/silverwrist/util/xml/DOMElementHelper.java
Normal file
|
@ -0,0 +1,489 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util.xml;
|
||||||
|
|
||||||
|
import org.w3c.dom.*;
|
||||||
|
import com.silverwrist.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class which wraps around the DOM <CODE>Element</CODE> class, providing some
|
||||||
|
* additional functionality. Written to DOM Level 2.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
* @see org.w3c.dom.Element
|
||||||
|
*/
|
||||||
|
public final class DOMElementHelper
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Element m_elt; // element housed by this helper class
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>DOMElementHelper</CODE> to wrap a specific <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to be wrapped.
|
||||||
|
*/
|
||||||
|
public DOMElementHelper(Element elt)
|
||||||
|
{
|
||||||
|
m_elt = elt;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content of all text nodes underneath a specified <CODE>Element</CODE>, concatenated
|
||||||
|
* together into a single string.
|
||||||
|
*
|
||||||
|
* @param e The <CODE>Element</CODE> to extract text from.
|
||||||
|
* @return The text content under this <CODE>Element</CODE> node. If the specified <CODE>Element</CODE>
|
||||||
|
* has no text nodes underneath it, returns <CODE>null.</CODE>
|
||||||
|
*/
|
||||||
|
private static final String getTextOfElement(Element e)
|
||||||
|
{
|
||||||
|
NodeList kids = e.getChildNodes();
|
||||||
|
if (kids==null)
|
||||||
|
return null; // no text?
|
||||||
|
|
||||||
|
StringBuffer b = null;
|
||||||
|
for (int i=0; i<kids.getLength(); i++)
|
||||||
|
{ // look for an ELEMENT_NODE node matching the desired name
|
||||||
|
Node t = kids.item(i);
|
||||||
|
if ((t.getNodeType()==Node.TEXT_NODE) || (t.getNodeType()==Node.CDATA_SECTION_NODE))
|
||||||
|
{ // append to the string under construction
|
||||||
|
if (b==null)
|
||||||
|
b = new StringBuffer();
|
||||||
|
else
|
||||||
|
b.append(' ');
|
||||||
|
b.append(t.getNodeValue());
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
if (b==null)
|
||||||
|
return null; // no TEXT nodes
|
||||||
|
else
|
||||||
|
return b.toString(); // return the concatenation
|
||||||
|
|
||||||
|
} // end getTextOfElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the text of the specified <CODE>Element</CODE>, expressed as an integer.
|
||||||
|
*
|
||||||
|
* @param e The <CODE>Element</CODE> to extract text from.
|
||||||
|
* @return An <CODE>Integer</CODE> object containing the value of the specified element. If
|
||||||
|
* the <CODE>Element</CODE> has no text, or if the text cannot be expressed as an integer,
|
||||||
|
* returns <CODE>null</CODE>.
|
||||||
|
*/
|
||||||
|
private static final Integer getIntegerFromElement(Element e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // extract the text and create an Integer around it
|
||||||
|
String s = getTextOfElement(e);
|
||||||
|
return ((s==null) ? null : new Integer(s.trim()));
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{ // value cannot be parsed as an integer
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getIntegerFromElement
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the <CODE>Element</CODE> wrapped by this object.
|
||||||
|
*
|
||||||
|
* @return See above.
|
||||||
|
*/
|
||||||
|
public final Element getElement()
|
||||||
|
{
|
||||||
|
return m_elt;
|
||||||
|
|
||||||
|
} // end getElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for the first sub-element of the wrapped <CODE>Element</CODE> with the given name.
|
||||||
|
*
|
||||||
|
* @param name Name of the sub-element to search for.
|
||||||
|
* @return The first sub-element of the wrapped <CODE>Element</CODE> with the specified name.
|
||||||
|
* If the <CODE>Element</CODE> has no child <CODE>Elements</CODE> with the given name,
|
||||||
|
* the method returns <CODE>null</CODE>.
|
||||||
|
*/
|
||||||
|
public final Element getSubElement(String name)
|
||||||
|
{
|
||||||
|
NodeList kids = m_elt.getChildNodes();
|
||||||
|
if (kids==null)
|
||||||
|
return null; // no children?
|
||||||
|
for (int i=0; i<kids.getLength(); i++)
|
||||||
|
{ // look for an ELEMENT_NODE node matching the desired name
|
||||||
|
Node t = kids.item(i);
|
||||||
|
if ((t.getNodeType()==Node.ELEMENT_NODE) && (t.getNodeName().equals(name)))
|
||||||
|
return (Element)t;
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
return null; // not found
|
||||||
|
|
||||||
|
} // end getSubElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for the first sub-element of the wrapped <CODE>Element</CODE> with the given name.
|
||||||
|
*
|
||||||
|
* @param namespaceURI Namespace URI for the sub-element to search for.
|
||||||
|
* @param name Name of the sub-element to search for.
|
||||||
|
* @return The first sub-element of the wrapped <CODE>Element</CODE> with the specified URI/name.
|
||||||
|
* If the <CODE>Element</CODE> has no child <CODE>Elements</CODE> with the given URI/name,
|
||||||
|
* the method returns <CODE>null</CODE>.
|
||||||
|
*/
|
||||||
|
public final Element getSubElementNS(String namespaceURI, String name)
|
||||||
|
{
|
||||||
|
NodeList kids = m_elt.getChildNodes();
|
||||||
|
if (kids==null)
|
||||||
|
return null; // no children?
|
||||||
|
for (int i=0; i<kids.getLength(); i++)
|
||||||
|
{ // look for an ELEMENT_NODE node matching the desired name
|
||||||
|
Node t = kids.item(i);
|
||||||
|
if ( (t.getNodeType()==Node.ELEMENT_NODE) && t.getNamespaceURI().equals(namespaceURI)
|
||||||
|
&& t.getNodeName().equals(name))
|
||||||
|
return (Element)t;
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
return null; // not found
|
||||||
|
|
||||||
|
} // end getSubElementNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content of all text nodes underneath the wrapped <CODE>Element</CODE>, concatenated
|
||||||
|
* together into a single string.
|
||||||
|
*
|
||||||
|
* @return The text content under the wrapped <CODE>Element</CODE> node. If the wrapped <CODE>Element</CODE>
|
||||||
|
* has not text nodes underneath it, returns <CODE>null.</CODE>
|
||||||
|
*/
|
||||||
|
public final String getElementText()
|
||||||
|
{
|
||||||
|
return getTextOfElement(m_elt);
|
||||||
|
|
||||||
|
} // end getElementText
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the text of the wrapped <CODE>Element</CODE>, expressed as an integer.
|
||||||
|
*
|
||||||
|
* @return An <CODE>Integer</CODE> object containing the value of the wrapped element. If
|
||||||
|
* the <CODE>Element</CODE> has no text, or if the text cannot be expressed as an integer,
|
||||||
|
* returns <CODE>null</CODE>.
|
||||||
|
*/
|
||||||
|
public final Integer getElementInt()
|
||||||
|
{
|
||||||
|
return getIntegerFromElement(m_elt);
|
||||||
|
|
||||||
|
} // end getElementInt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content of all text nodes underneath the first sub-element of the wrapped
|
||||||
|
* <CODE>Element</CODE>, with the given name, concatenated together into a single string.
|
||||||
|
*
|
||||||
|
* @param name The name of the sub-element to search for.
|
||||||
|
* @return The text content under the specified sub-element of the wrapped <CODE>Element</CODE> node.
|
||||||
|
* If the wrapped <CODE>Element</CODE> does not have a sub-element with the given name, or
|
||||||
|
* that sub-element has no text nodes underneath it, returns <CODE>null.</CODE>
|
||||||
|
*/
|
||||||
|
public final String getSubElementText(String name)
|
||||||
|
{
|
||||||
|
Element se = getSubElement(name);
|
||||||
|
return ((se==null) ? null : getTextOfElement(se));
|
||||||
|
|
||||||
|
} // end getSubElementText
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content of all text nodes underneath the first sub-element of the wrapped
|
||||||
|
* <CODE>Element</CODE>, with the given name, concatenated together into a single string.
|
||||||
|
*
|
||||||
|
* @param namespaceURI Namespace URI for the sub-element to search for.
|
||||||
|
* @param name The name of the sub-element to search for.
|
||||||
|
* @return The text content under the specified sub-element of the wrapped <CODE>Element</CODE> node.
|
||||||
|
* If the wrapped <CODE>Element</CODE> does not have a sub-element with the given URI/name, or
|
||||||
|
* that sub-element has no text nodes underneath it, returns <CODE>null.</CODE>
|
||||||
|
*/
|
||||||
|
public final String getSubElementTextNS(String namespaceURI, String name)
|
||||||
|
{
|
||||||
|
Element se = getSubElementNS(namespaceURI,name);
|
||||||
|
return ((se==null) ? null : getTextOfElement(se));
|
||||||
|
|
||||||
|
} // end getSubElementTextNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the text underneath the first sub-element of the wrapped
|
||||||
|
* <CODE>Element</CODE>, with the given name, expressed as an integer.
|
||||||
|
*
|
||||||
|
* @param name The name of the sub-element to search for.
|
||||||
|
* @return An <CODE>Integer</CODE> object containing the value of the specified element. If
|
||||||
|
* the wrapped <CODE>Element</CODE> does not have a sub-element with the given name, or that
|
||||||
|
* sub-element has no text, or if the text cannot be expressed as an integer, returns
|
||||||
|
* <CODE>null</CODE>.
|
||||||
|
*/
|
||||||
|
public final Integer getSubElementInt(String name)
|
||||||
|
{
|
||||||
|
Element se = getSubElement(name);
|
||||||
|
return ((se==null) ? null : getIntegerFromElement(se));
|
||||||
|
|
||||||
|
} // end getSubElementInt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the text underneath the first sub-element of the wrapped
|
||||||
|
* <CODE>Element</CODE>, with the given name, expressed as an integer.
|
||||||
|
*
|
||||||
|
* @param namespaceURI Namespace URI for the sub-element to search for.
|
||||||
|
* @param name The name of the sub-element to search for.
|
||||||
|
* @return An <CODE>Integer</CODE> object containing the value of the specified element. If
|
||||||
|
* the wrapped <CODE>Element</CODE> does not have a sub-element with the given URI/name, or that
|
||||||
|
* sub-element has no text, or if the text cannot be expressed as an integer, returns
|
||||||
|
* <CODE>null</CODE>.
|
||||||
|
*/
|
||||||
|
public final Integer getSubElementIntNS(String namespaceURI, String name)
|
||||||
|
{
|
||||||
|
Element se = getSubElementNS(namespaceURI,name);
|
||||||
|
return ((se==null) ? null : getIntegerFromElement(se));
|
||||||
|
|
||||||
|
} // end getSubElementIntNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the wrapped <CODE>Element</CODE> has a sub-element with the given name.
|
||||||
|
*
|
||||||
|
* @param name Name of the sub-element to search for.
|
||||||
|
* @return <CODE>true</CODE> if the wrapped <CODE>Element</CODE> has a sub-element with the
|
||||||
|
* specified name, <CODE>false</CODE> if not.
|
||||||
|
*/
|
||||||
|
public final boolean hasChildElement(String name)
|
||||||
|
{
|
||||||
|
return (getSubElement(name)!=null);
|
||||||
|
|
||||||
|
} // end hasChildElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the wrapped <CODE>Element</CODE> has a sub-element with the given name.
|
||||||
|
*
|
||||||
|
* @param namespaceURI Namespace URI for the sub-element to search for.
|
||||||
|
* @param name Name of the sub-element to search for.
|
||||||
|
* @return <CODE>true</CODE> if the wrapped <CODE>Element</CODE> has a sub-element with the
|
||||||
|
* specified name, <CODE>false</CODE> if not.
|
||||||
|
*/
|
||||||
|
public final boolean hasChildElementNS(String namespaceURI, String name)
|
||||||
|
{
|
||||||
|
return (getSubElementNS(namespaceURI,name)!=null);
|
||||||
|
|
||||||
|
} // end hasChildElementNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the wrapped <CODE>Element</CODE> has an attribute with the given name.
|
||||||
|
*
|
||||||
|
* @param name Name of the attribute to search for.
|
||||||
|
* @return <CODE>true</CODE> if the wrapped <CODE>Element</CODE> has an attribute with the
|
||||||
|
* specified name, <CODE>false</CODE> if not.
|
||||||
|
*/
|
||||||
|
public final boolean hasAttribute(String name)
|
||||||
|
{
|
||||||
|
return m_elt.hasAttribute(name);
|
||||||
|
|
||||||
|
} // end hasAttribute
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the wrapped <CODE>Element</CODE> has an attribute with the given name.
|
||||||
|
*
|
||||||
|
* @param namespaceURI Namespace URI for the attribute to search for.
|
||||||
|
* @param name Name of the attribute to search for.
|
||||||
|
* @return <CODE>true</CODE> if the wrapped <CODE>Element</CODE> has an attribute with the
|
||||||
|
* specified URI/name, <CODE>false</CODE> if not.
|
||||||
|
*/
|
||||||
|
public final boolean hasAttributeNS(String namespaceURI, String name)
|
||||||
|
{
|
||||||
|
return m_elt.hasAttributeNS(namespaceURI,name);
|
||||||
|
|
||||||
|
} // end hasAttributeNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of a specified attribute of the wrapped <CODE>Element</CODE>, expressed as
|
||||||
|
* an integer.
|
||||||
|
*
|
||||||
|
* @param name Name of the attribute to search for.
|
||||||
|
* @return An <CODE>Integer</CODE> object containing the value of the specified attribute. If
|
||||||
|
* the wrapped <CODE>Element</CODE> has no such attribute, or if the attribute's value
|
||||||
|
* cannot be expressed as an integer, returns <CODE>null</CODE>.
|
||||||
|
*/
|
||||||
|
public final Integer getAttributeInt(String name)
|
||||||
|
{
|
||||||
|
String tmp = m_elt.getAttribute(name);
|
||||||
|
if (StringUtils.isEmpty(tmp))
|
||||||
|
return null;
|
||||||
|
try
|
||||||
|
{ // convert to an Integer
|
||||||
|
return new Integer(tmp.trim());
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{ // return a null value on error
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getAttributeInt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of a specified attribute of the wrapped <CODE>Element</CODE>, expressed as
|
||||||
|
* an integer.
|
||||||
|
*
|
||||||
|
* @param namespaceURI Namespace URI for the attribute to search for.
|
||||||
|
* @param name Name of the attribute to search for.
|
||||||
|
* @return An <CODE>Integer</CODE> object containing the value of the specified attribute. If
|
||||||
|
* the wrapped <CODE>Element</CODE> has no such attribute, or if the attribute's value
|
||||||
|
* cannot be expressed as an integer, returns <CODE>null</CODE>.
|
||||||
|
*/
|
||||||
|
public final Integer getAttributeIntNS(String namespaceURI, String name)
|
||||||
|
{
|
||||||
|
String tmp = m_elt.getAttributeNS(namespaceURI,name);
|
||||||
|
if (StringUtils.isEmpty(tmp))
|
||||||
|
return null;
|
||||||
|
try
|
||||||
|
{ // convert to an Integer
|
||||||
|
return new Integer(tmp.trim());
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{ // return a null value on error
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getAttributeInt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of a specified attribute of the wrapped <CODE>Element</CODE>, expressed as
|
||||||
|
* a Boolean. Uses the Boolean string methods on {@link com.silverwrist.util.StringUtils StringUtils} to
|
||||||
|
* determine the state of the attribute value.
|
||||||
|
*
|
||||||
|
* @param name Name of the attribute to search for.
|
||||||
|
* @return <CODE>Boolean.TRUE</CODE> if the attribute value represents a "true" Boolean value;
|
||||||
|
* <CODE>Boolean.FALSE</CODE> if the attribute value represents a "false" Boolean value; <CODE>null</CODE>
|
||||||
|
* otherwise.
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanTrue(java.lang.String)
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanFalse(java.lang.String)
|
||||||
|
*/
|
||||||
|
public final Boolean getAttributeBoolean(String name)
|
||||||
|
{
|
||||||
|
String tmp = m_elt.getAttribute(name);
|
||||||
|
if (StringUtils.isBooleanTrue(tmp))
|
||||||
|
return Boolean.TRUE;
|
||||||
|
else if (StringUtils.isBooleanFalse(tmp))
|
||||||
|
return Boolean.FALSE;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end getAttributeBoolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of a specified attribute of the wrapped <CODE>Element</CODE>, expressed as
|
||||||
|
* a Boolean. Uses the Boolean string methods on {@link com.silverwrist.util.StringUtils StringUtils} to
|
||||||
|
* determine the state of the attribute value.
|
||||||
|
*
|
||||||
|
* @param namespaceURI Namespace URI for the attribute to search for.
|
||||||
|
* @param name Name of the attribute to search for.
|
||||||
|
* @return <CODE>Boolean.TRUE</CODE> if the attribute value represents a "true" Boolean value;
|
||||||
|
* <CODE>Boolean.FALSE</CODE> if the attribute value represents a "false" Boolean value; <CODE>null</CODE>
|
||||||
|
* otherwise.
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanTrue(java.lang.String)
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanFalse(java.lang.String)
|
||||||
|
*/
|
||||||
|
public final Boolean getAttributeBooleanNS(String namespaceURI, String name)
|
||||||
|
{
|
||||||
|
String tmp = m_elt.getAttributeNS(namespaceURI,name);
|
||||||
|
if (StringUtils.isBooleanTrue(tmp))
|
||||||
|
return Boolean.TRUE;
|
||||||
|
else if (StringUtils.isBooleanFalse(tmp))
|
||||||
|
return Boolean.FALSE;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end getAttributeBooleanNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of a specified attribute of the wrapped <CODE>Element</CODE>, expressed as
|
||||||
|
* a Boolean. Uses the Boolean string methods on {@link com.silverwrist.util.StringUtils StringUtils} to
|
||||||
|
* determine the state of the attribute value.
|
||||||
|
*
|
||||||
|
* @param name Name of the attribute to search for.
|
||||||
|
* @param default_val Default value for the attribute.
|
||||||
|
* @return <CODE>Boolean.TRUE</CODE> if the attribute value represents a "true" Boolean value;
|
||||||
|
* <CODE>Boolean.FALSE</CODE> if the attribute value represents a "false" Boolean value; the
|
||||||
|
* <CODE>Boolean</CODE> object corresponding to <CODE>default_val</CODE> if the attribute is missing;
|
||||||
|
* <CODE>null</CODE> otherwise.
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanTrue(java.lang.String)
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanFalse(java.lang.String)
|
||||||
|
*/
|
||||||
|
public final Boolean getAttributeBoolean(String name, boolean default_val)
|
||||||
|
{
|
||||||
|
if (this.hasAttribute(name))
|
||||||
|
return this.getAttributeBoolean(name);
|
||||||
|
else
|
||||||
|
return (default_val ? Boolean.TRUE : Boolean.FALSE);
|
||||||
|
|
||||||
|
} // end getAttributeBoolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of a specified attribute of the wrapped <CODE>Element</CODE>, expressed as
|
||||||
|
* a Boolean. Uses the Boolean string methods on {@link com.silverwrist.util.StringUtils StringUtils} to
|
||||||
|
* determine the state of the attribute value.
|
||||||
|
*
|
||||||
|
* @param namespaceURI Namespace URI for the attribute to search for.
|
||||||
|
* @param name Name of the attribute to search for.
|
||||||
|
* @param default_val Default value for the attribute.
|
||||||
|
* @return <CODE>Boolean.TRUE</CODE> if the attribute value represents a "true" Boolean value;
|
||||||
|
* <CODE>Boolean.FALSE</CODE> if the attribute value represents a "false" Boolean value; the
|
||||||
|
* <CODE>Boolean</CODE> object corresponding to <CODE>default_val</CODE> if the attribute is missing;
|
||||||
|
* <CODE>null</CODE> otherwise.
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanTrue(java.lang.String)
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanFalse(java.lang.String)
|
||||||
|
*/
|
||||||
|
public final Boolean getAttributeBooleanNS(String namespaceURI, String name, boolean default_val)
|
||||||
|
{
|
||||||
|
if (this.hasAttributeNS(namespaceURI,name))
|
||||||
|
return this.getAttributeBooleanNS(namespaceURI,name);
|
||||||
|
else
|
||||||
|
return (default_val ? Boolean.TRUE : Boolean.FALSE);
|
||||||
|
|
||||||
|
} // end getAttributeBooleanNS
|
||||||
|
|
||||||
|
} // end class DOMElementHelper
|
155
src/baseutil/com/silverwrist/util/xml/XMLLoadException.java
Normal file
155
src/baseutil/com/silverwrist/util/xml/XMLLoadException.java
Normal file
|
@ -0,0 +1,155 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util.xml;
|
||||||
|
|
||||||
|
import org.w3c.dom.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception type thrown by the {@link com.silverwrist.util.xml.XMLLoader XMLLoader} when it encounters
|
||||||
|
* a parse error, value error, or other erroneous condition. It contains a reference to the node in the DOM
|
||||||
|
* tree where the error occured, if such is possible to determine.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class XMLLoadException extends Exception
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Node m_locus = null; // locus of the error
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructors
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>XMLLoadException</CODE>.
|
||||||
|
*/
|
||||||
|
public XMLLoadException()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>XMLLoadException</CODE>.
|
||||||
|
*
|
||||||
|
* @param msg The error message to be thrown.
|
||||||
|
*/
|
||||||
|
public XMLLoadException(String msg)
|
||||||
|
{
|
||||||
|
super(msg);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>XMLLoadException</CODE>.
|
||||||
|
*
|
||||||
|
* @param inner The exception wrapped by this <CODE>XMLLoadException</CODE>.
|
||||||
|
*/
|
||||||
|
public XMLLoadException(Throwable inner)
|
||||||
|
{
|
||||||
|
super(inner);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>XMLLoadException</CODE>.
|
||||||
|
*
|
||||||
|
* @param msg The error message to be thrown.
|
||||||
|
* @param inner The exception wrapped by this <CODE>XMLLoadException</CODE>.
|
||||||
|
*/
|
||||||
|
public XMLLoadException(String msg, Throwable inner)
|
||||||
|
{
|
||||||
|
super(msg,inner);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>XMLLoadException</CODE>.
|
||||||
|
*
|
||||||
|
* @param locus The <CODE>Node</CODE> in the DOM tree where the error occurred.
|
||||||
|
*/
|
||||||
|
public XMLLoadException(Node locus)
|
||||||
|
{
|
||||||
|
super("Error in <" + locus.getNodeName() + "/> section of input");
|
||||||
|
m_locus = locus;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>XMLLoadException</CODE>.
|
||||||
|
*
|
||||||
|
* @param msg The error message to be thrown.
|
||||||
|
* @param locus The <CODE>Node</CODE> in the DOM tree where the error occurred.
|
||||||
|
*/
|
||||||
|
public XMLLoadException(String msg, Node locus)
|
||||||
|
{
|
||||||
|
super("Error in <" + locus.getNodeName() + "/> section of input - " + msg);
|
||||||
|
m_locus = locus;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>XMLLoadException</CODE>.
|
||||||
|
*
|
||||||
|
* @param inner The exception wrapped by this <CODE>XMLLoadException</CODE>.
|
||||||
|
* @param locus The <CODE>Node</CODE> in the DOM tree where the error occurred.
|
||||||
|
*/
|
||||||
|
public XMLLoadException(Throwable inner, Node locus)
|
||||||
|
{
|
||||||
|
super("Error in <" + locus.getNodeName() + "/> section of input - " + inner.getMessage(),inner);
|
||||||
|
m_locus = locus;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>XMLLoadException</CODE>.
|
||||||
|
*
|
||||||
|
* @param msg The error message to be thrown.
|
||||||
|
* @param inner The exception wrapped by this <CODE>XMLLoadException</CODE>.
|
||||||
|
* @param locus The <CODE>Node</CODE> in the DOM tree where the error occurred.
|
||||||
|
*/
|
||||||
|
public XMLLoadException(String msg, Throwable inner, Node locus)
|
||||||
|
{
|
||||||
|
super("Error in <" + locus.getNodeName() + "/> section of input - " + msg,inner);
|
||||||
|
m_locus = locus;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the locus of the error contained in this exception.
|
||||||
|
*
|
||||||
|
* @return The <CODE>Node</CODE> that indicates wherre in the DOM tree the error occurred.
|
||||||
|
*/
|
||||||
|
public Node getLocus()
|
||||||
|
{
|
||||||
|
return m_locus;
|
||||||
|
|
||||||
|
} // end getLocus
|
||||||
|
|
||||||
|
} // end class XMLLoadException
|
824
src/baseutil/com/silverwrist/util/xml/XMLLoader.java
Normal file
824
src/baseutil/com/silverwrist/util/xml/XMLLoader.java
Normal file
|
@ -0,0 +1,824 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.util.xml;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.xml.parsers.*;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.w3c.dom.*;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
import com.silverwrist.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple class which is commonly used for the loading of XML documents as configuration files. Various
|
||||||
|
* methods on this object load XML documents as DOM trees and extract portions of the information therein.
|
||||||
|
* It is implemented as a Singleton.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class XMLLoader
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static Logger logger = Logger.getLogger(XMLLoader.class);
|
||||||
|
|
||||||
|
private static XMLLoader self = null; // our singleton instance
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal constructor for <CODE>XMLLoader</CODE>. Only one instance is ever constructed.
|
||||||
|
*/
|
||||||
|
private XMLLoader()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an XML document into a DOM tree.
|
||||||
|
*
|
||||||
|
* @param stm The XML document to be parsed, expressed as an <CODE>InputStream</CODE>.
|
||||||
|
* @param namespacing <CODE>true</CODE> if we want this XML document parsed in a namespace-aware fashion,
|
||||||
|
* <CODE>false</CODE> if not.
|
||||||
|
* @return The <CODE>Document</CODE> that results from parsing the XML document.
|
||||||
|
* @exception java.io.IOException If there was an I/O error reading from the XML document.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoaderException If there was a parse error in the XML, or other error
|
||||||
|
* accessing the XML parser.
|
||||||
|
*/
|
||||||
|
public final Document load(InputStream stm, boolean namespacing) throws IOException, XMLLoadException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // create a simple DOM parser by using the Java XML parsing API
|
||||||
|
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
|
||||||
|
fac.setNamespaceAware(namespacing);
|
||||||
|
fac.setValidating(false);
|
||||||
|
DocumentBuilder parser = fac.newDocumentBuilder();
|
||||||
|
if (parser.isNamespaceAware()!=namespacing)
|
||||||
|
throw new XMLLoadException("XML parser namespacing parameter is not consistent");
|
||||||
|
|
||||||
|
// access the config file and parse it into our config data tree
|
||||||
|
return parser.parse(stm);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (FactoryConfigurationError fce)
|
||||||
|
{ // if the document builder factory could not be created
|
||||||
|
throw new XMLLoadException("XML parser factory could not be created - " + fce.getMessage());
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (ParserConfigurationException pce)
|
||||||
|
{ // if the XML parser itself could not be created
|
||||||
|
throw new XMLLoadException("XML parser could not be created - " + pce.getMessage(),pce);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (SAXException se)
|
||||||
|
{ // if the XML parser choked on our document
|
||||||
|
if (se instanceof SAXParseException)
|
||||||
|
{ // we have a detailed message - make a proper exception
|
||||||
|
SAXParseException spe = (SAXParseException)se;
|
||||||
|
throw new XMLLoadException("Error in XML data: " + spe.getMessage() + " at line "
|
||||||
|
+ spe.getLineNumber() + ", column " + spe.getColumnNumber(),spe);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // generic exception - just send up a simple error message
|
||||||
|
throw new XMLLoadException("Error in XML data - " + se.getMessage(),se);
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end load
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an XML document into a DOM tree.
|
||||||
|
*
|
||||||
|
* @param stm The XML document to be parsed, expressed as a <CODE>File</CODE> object.
|
||||||
|
* @param namespacing <CODE>true</CODE> if we want this XML document parsed in a namespace-aware fashion,
|
||||||
|
* <CODE>false</CODE> if not.
|
||||||
|
* @return The <CODE>Document</CODE> that results from parsing the XML document.
|
||||||
|
* @exception java.io.IOException If there was an I/O error reading from the XML document.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoaderException If there was a parse error in the XML, or other error
|
||||||
|
* accessing the XML parser.
|
||||||
|
*/
|
||||||
|
public final Document load(File file, boolean namespacing) throws IOException, XMLLoadException
|
||||||
|
{
|
||||||
|
return this.load(new FileInputStream(file),namespacing);
|
||||||
|
|
||||||
|
} // end load
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the root element of a parsed XML DOM tree, and verifies that it matches a specific name.
|
||||||
|
*
|
||||||
|
* @param doc The document to get the root element of.
|
||||||
|
* @param expected_name The expected name of the root element.
|
||||||
|
* @return The root <CODE>Element</CODE> of the document,
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the root element of the document does not match the
|
||||||
|
* <CODE>expected_name</CODE>.
|
||||||
|
*/
|
||||||
|
public final Element getRootElement(Document doc, String expected_name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
Element rc = doc.getDocumentElement();
|
||||||
|
if (rc.getTagName().equals(expected_name))
|
||||||
|
return rc; // we're OK
|
||||||
|
throw new XMLLoadException("expected <" + expected_name + "/> root element",rc);
|
||||||
|
|
||||||
|
} // end getRootElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the root element of a parsed XML DOM tree, and verifies that it matches a specific name.
|
||||||
|
*
|
||||||
|
* @param doc The document to get the root element of.
|
||||||
|
* @param expected_namespace The expected namespace for the root element of the document.
|
||||||
|
* @param expected_name The expected name of the root element.
|
||||||
|
* @return The root <CODE>Element</CODE> of the document,
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the root element of the document does not match the
|
||||||
|
* <CODE>expected_namespace</CODE> and <CODE>expected_name</CODE>.
|
||||||
|
*/
|
||||||
|
public final Element getRootElementNS(Document doc, String expected_namespace,
|
||||||
|
String expected_name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
Element rc = doc.getDocumentElement();
|
||||||
|
if (rc.getNamespaceURI().equals(expected_namespace) && rc.getTagName().equals(expected_name))
|
||||||
|
return rc; // we're OK
|
||||||
|
throw new XMLLoadException("expected <" + expected_namespace + ":" + expected_name + "/> root element",rc);
|
||||||
|
|
||||||
|
} // end getRootElementNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text contained in an <CODE>Element</CODE> wrapped in a
|
||||||
|
* {@link com.silverwrist.util.xml.DOMElementHelper DOMElementHelper}.
|
||||||
|
*
|
||||||
|
* @param h The <CODE>DOMElementHelper</CODE> to extract the text from.
|
||||||
|
* @return The text contained in the element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If there is no text contained in the element.
|
||||||
|
*/
|
||||||
|
public final String getText(DOMElementHelper h) throws XMLLoadException
|
||||||
|
{
|
||||||
|
String rc = h.getElementText();
|
||||||
|
if (rc!=null)
|
||||||
|
return rc; // we're OK
|
||||||
|
throw new XMLLoadException("no text found under element",h.getElement());
|
||||||
|
|
||||||
|
} // end getText
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text contained in an <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to extract the text from.
|
||||||
|
* @return The text contained in the element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If there is no text contained in the element.
|
||||||
|
*/
|
||||||
|
public final String getText(Element elt) throws XMLLoadException
|
||||||
|
{
|
||||||
|
return getText(new DOMElementHelper(elt));
|
||||||
|
|
||||||
|
} // end getText
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text contained in a named sub-element of an <CODE>Element</CODE> wrapped in a
|
||||||
|
* {@link com.silverwrist.util.xml.DOMElementHelper DOMElementHelper}.
|
||||||
|
*
|
||||||
|
* @param h The <CODE>DOMElementHelper</CODE> to extract the text from.
|
||||||
|
* @param elt_name The name of the sub-element to look for text in.
|
||||||
|
* @return The text contained in the sub-element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the sub-element is not found, or there is no text
|
||||||
|
* contained in the sub-element.
|
||||||
|
*/
|
||||||
|
public final String getSubElementText(DOMElementHelper h, String elt_name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
String rc = h.getSubElementText(elt_name);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc; // we're OK
|
||||||
|
throw new XMLLoadException("sublement <" + elt_name + "/> not found",h.getElement());
|
||||||
|
|
||||||
|
} // end getSubElementText
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text contained in a named sub-element of an <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to extract the text from.
|
||||||
|
* @param subelt_name The name of the sub-element to look for text in.
|
||||||
|
* @return The text contained in the sub-element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the sub-element is not found, or there is no text
|
||||||
|
* contained in the sub-element.
|
||||||
|
*/
|
||||||
|
public final String getSubElementText(Element elt, String subelt_name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
return getSubElementText(new DOMElementHelper(elt),subelt_name);
|
||||||
|
|
||||||
|
} // end getSubElementText
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text contained in a named sub-element of an <CODE>Element</CODE> wrapped in a
|
||||||
|
* {@link com.silverwrist.util.xml.DOMElementHelper DOMElementHelper}.
|
||||||
|
*
|
||||||
|
* @param h The <CODE>DOMElementHelper</CODE> to extract the text from.
|
||||||
|
* @param namespace The namespace URI of the sub-element to look for text in.
|
||||||
|
* @param elt_name The name of the sub-element to look for text in.
|
||||||
|
* @return The text contained in the sub-element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the sub-element is not found, or there is no text
|
||||||
|
* contained in the sub-element.
|
||||||
|
*/
|
||||||
|
public final String getSubElementTextNS(DOMElementHelper h, String namespace, String elt_name)
|
||||||
|
throws XMLLoadException
|
||||||
|
{
|
||||||
|
String rc = h.getSubElementTextNS(namespace,elt_name);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc; // we're OK
|
||||||
|
throw new XMLLoadException("sublement <" + namespace + ":" + elt_name + "/> not found",h.getElement());
|
||||||
|
|
||||||
|
} // end getSubElementTextNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text contained in a named sub-element of an <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to extract the text from.
|
||||||
|
* @param namespace The namespace URI of the sub-element to look for text in.
|
||||||
|
* @param subelt_name The name of the sub-element to look for text in.
|
||||||
|
* @return The text contained in the sub-element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the sub-element is not found, or there is no text
|
||||||
|
* contained in the sub-element.
|
||||||
|
*/
|
||||||
|
public final String getSubElementTextNS(Element elt, String namespace, String subelt_name)
|
||||||
|
throws XMLLoadException
|
||||||
|
{
|
||||||
|
return getSubElementTextNS(new DOMElementHelper(elt),namespace,subelt_name);
|
||||||
|
|
||||||
|
} // end getSubElementTextNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a named sub-element of an <CODE>Element</CODE> wrapped in a
|
||||||
|
* {@link com.silverwrist.util.xml.DOMElementHelper DOMElementHelper}.
|
||||||
|
*
|
||||||
|
* @param h The <CODE>DOMElementHelper</CODE> to extract the sub-element from.
|
||||||
|
* @param name The name of the sub-element to look for.
|
||||||
|
* @return The sub-element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the sub-element is not found.
|
||||||
|
*/
|
||||||
|
public final Element getSubElement(DOMElementHelper h, String name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
Element rc = h.getSubElement(name);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc; // we're OK
|
||||||
|
throw new XMLLoadException("sublement <" + name + "/> not found",h.getElement());
|
||||||
|
|
||||||
|
} // end getSubElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a named sub-element of an <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param sect The <CODE>Element</CODE> to extract the sub-element from.
|
||||||
|
* @param name The name of the sub-element to look for.
|
||||||
|
* @return The sub-element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the sub-element is not found.
|
||||||
|
*/
|
||||||
|
public final Element getSubElement(Element sect, String name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
return getSubElement(new DOMElementHelper(sect),name);
|
||||||
|
|
||||||
|
} // end getSubElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a named sub-element of an <CODE>Element</CODE> wrapped in a
|
||||||
|
* {@link com.silverwrist.util.xml.DOMElementHelper DOMElementHelper}.
|
||||||
|
*
|
||||||
|
* @param h The <CODE>DOMElementHelper</CODE> to extract the sub-element from.
|
||||||
|
* @param namespace The namespace URI of the sub-element to look for.
|
||||||
|
* @param name The name of the sub-element to look for.
|
||||||
|
* @return The sub-element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the sub-element is not found.
|
||||||
|
*/
|
||||||
|
public final Element getSubElementNS(DOMElementHelper h, String namespace, String name)
|
||||||
|
throws XMLLoadException
|
||||||
|
{
|
||||||
|
Element rc = h.getSubElementNS(namespace,name);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc; // we're OK
|
||||||
|
throw new XMLLoadException("sublement <" + namespace + ":" + name + "/> not found",h.getElement());
|
||||||
|
|
||||||
|
} // end getSubElementNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a named sub-element of an <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param sect The <CODE>Element</CODE> to extract the sub-element from.
|
||||||
|
* @param namespace The namespace URI of the sub-element to look for.
|
||||||
|
* @param name The name of the sub-element to look for.
|
||||||
|
* @return The sub-element.
|
||||||
|
* @exception com.silverwrist.util.XMLLoadException If the sub-element is not found.
|
||||||
|
*/
|
||||||
|
public final Element getSubElementNS(Element sect, String namespace, String name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
return getSubElementNS(new DOMElementHelper(sect),namespace,name);
|
||||||
|
|
||||||
|
} // end getSubElementNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all sub-elements of an <CODE>Element</CODE> element that have a specific name.
|
||||||
|
*
|
||||||
|
* @param sect The <CODE>Element</CODE> to extract the sub-elements from.
|
||||||
|
* @param name The name of the sub-elements to look for.
|
||||||
|
* @return A <CODE>java.util.List</CODE> containing all the sub-elements of the given <CODE>Element</CODE> with
|
||||||
|
* the specified name. If there are no matching sub-elements, an empty list is returned.
|
||||||
|
*/
|
||||||
|
public final List getMatchingSubElements(Element sect, String name)
|
||||||
|
{
|
||||||
|
ArrayList rc = new ArrayList();
|
||||||
|
NodeList nl = sect.getChildNodes();
|
||||||
|
for (int i=0; i<nl.getLength(); i++)
|
||||||
|
{ // look for an ELEMENT_NODE node matching the desired name
|
||||||
|
Node t = nl.item(i);
|
||||||
|
if ((t.getNodeType()==Node.ELEMENT_NODE) && t.getNodeName().equals(name))
|
||||||
|
rc.add((Element)t);
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
if (rc.isEmpty())
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
|
rc.trimToSize();
|
||||||
|
return Collections.unmodifiableList(rc);
|
||||||
|
|
||||||
|
} // end getMatchingSubElements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all sub-elements of an <CODE>Element</CODE> element that have a specific name.
|
||||||
|
*
|
||||||
|
* @param sect The <CODE>Element</CODE> to extract the sub-elements from.
|
||||||
|
* @param namespace The namespace URI of the sub-elements to look for.
|
||||||
|
* @param name The name of the sub-elements to look for.
|
||||||
|
* @return A <CODE>java.util.List</CODE> containing all the sub-elements of the given <CODE>Element</CODE> with
|
||||||
|
* the specified namespace and name. If there are no matching sub-elements, an empty list is returned.
|
||||||
|
*/
|
||||||
|
public final List getMatchingSubElementsNS(Element sect, String namespace, String name)
|
||||||
|
{
|
||||||
|
ArrayList rc = new ArrayList();
|
||||||
|
NodeList nl = sect.getChildNodes();
|
||||||
|
for (int i=0; i<nl.getLength(); i++)
|
||||||
|
{ // look for an ELEMENT_NODE node matching the desired name
|
||||||
|
Node t = nl.item(i);
|
||||||
|
if ( (t.getNodeType()==Node.ELEMENT_NODE) && t.getNamespaceURI().equals(namespace)
|
||||||
|
&& t.getNodeName().equals(name))
|
||||||
|
rc.add((Element)t);
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
if (rc.isEmpty())
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
|
rc.trimToSize();
|
||||||
|
return Collections.unmodifiableList(rc);
|
||||||
|
|
||||||
|
} // end getMatchingSubElementsNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure that the name of a given node is what we expect, and throws an
|
||||||
|
* {@link com.silverwrist.util.xml.XMLLoadException XMLLoadException} if it isn't.
|
||||||
|
*
|
||||||
|
* @param n The <CODE>Node</CODE> to test the name of.
|
||||||
|
* @param name The name to test the node against.
|
||||||
|
* @param enclosing_sect The <CODE>Element</CODE> that contains this node as a child, used in constructing
|
||||||
|
* the exception if the test fails.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the name of the node does not match.
|
||||||
|
*/
|
||||||
|
public final void verifyNodeName(Node n, String name, Element enclosing_sect) throws XMLLoadException
|
||||||
|
{
|
||||||
|
if (n.getNodeName().equals(name))
|
||||||
|
return;
|
||||||
|
throw new XMLLoadException("node <" + n.getNodeName() + "/> should be <" + name + "/>",enclosing_sect);
|
||||||
|
|
||||||
|
} // end verifyNodeName
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure that the name of a given node is what we expect, and throws an
|
||||||
|
* {@link com.silverwrist.util.xml.XMLLoadException XMLLoadException} if it isn't.
|
||||||
|
*
|
||||||
|
* @param n The <CODE>Node</CODE> to test the name of.
|
||||||
|
* @param name The name to test the node against.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the name of the node does not match.
|
||||||
|
*/
|
||||||
|
public final void verifyNodeName(Node n, String name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
verifyNodeName(n,name,(Element)(n.getParentNode()));
|
||||||
|
|
||||||
|
} // end verifyNodeName
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure that the name of a given node is what we expect, and throws an
|
||||||
|
* {@link com.silverwrist.util.xml.XMLLoadException XMLLoadException} if it isn't.
|
||||||
|
*
|
||||||
|
* @param n The <CODE>Node</CODE> to test the name of.
|
||||||
|
* @param namespace The namespace URI to test the node against.
|
||||||
|
* @param name The name to test the node against.
|
||||||
|
* @param enclosing_sect The <CODE>Element</CODE> that contains this node as a child, used in constructing
|
||||||
|
* the exception if the test fails.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the name of the node does not match.
|
||||||
|
*/
|
||||||
|
public final void verifyNodeNameNS(Node n, String namespace, String name, Element enclosing_sect)
|
||||||
|
throws XMLLoadException
|
||||||
|
{
|
||||||
|
if (n.getNamespaceURI().equals(namespace) && n.getNodeName().equals(name))
|
||||||
|
return;
|
||||||
|
throw new XMLLoadException("node <" + n.getNamespaceURI() + ":" + n.getNodeName() + "/> should be <"
|
||||||
|
+ namespace + ":" + name + "/>",enclosing_sect);
|
||||||
|
|
||||||
|
} // end verifyNodeNameNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure that the name of a given node is what we expect, and throws an
|
||||||
|
* {@link com.silverwrist.util.xml.XMLLoadException XMLLoadException} if it isn't.
|
||||||
|
*
|
||||||
|
* @param n The <CODE>Node</CODE> to test the name of.
|
||||||
|
* @param namespace The namespace URI to test the node against.
|
||||||
|
* @param name The name to test the node against.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the name of the node does not match.
|
||||||
|
*/
|
||||||
|
public final void verifyNodeNameNS(Node n, String namespace, String name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
verifyNodeNameNS(n,namespace,name,(Element)(n.getParentNode()));
|
||||||
|
|
||||||
|
} // end verifyNodeNameNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure that the name of a given tag element is what we expect, and throws an
|
||||||
|
* {@link com.silverwrist.util.xml.XMLLoadException XMLLoadException} if it isn't.
|
||||||
|
*
|
||||||
|
* @param tag The <CODE>Element</CODE> to test the name of.
|
||||||
|
* @param name The name to test the element against.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the name of the element does not match.
|
||||||
|
*/
|
||||||
|
public final void verifyTagName(Element tag, String name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
if (tag.getTagName().equals(name))
|
||||||
|
return;
|
||||||
|
throw new XMLLoadException("expected <" + name + "/> element",tag);
|
||||||
|
|
||||||
|
} // end verifyTagName
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure that the name of a given tag element is what we expect, and throws an
|
||||||
|
* {@link com.silverwrist.util.xml.XMLLoadException XMLLoadException} if it isn't.
|
||||||
|
*
|
||||||
|
* @param tag The <CODE>Element</CODE> to test the name of.
|
||||||
|
* @param namespace The namespace URI to test the element against.
|
||||||
|
* @param name The name to test the element against.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the name of the element does not match.
|
||||||
|
*/
|
||||||
|
public final void verifyTagNameNS(Element tag, String namespace, String name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
if (tag.getNamespaceURI().equals(namespace) && tag.getTagName().equals(name))
|
||||||
|
return;
|
||||||
|
throw new XMLLoadException("expected <" + namespace + ":" + name + "/> element",tag);
|
||||||
|
|
||||||
|
} // end verifyTagNameNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @return The attribute value.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute did not exist on the element.
|
||||||
|
*/
|
||||||
|
public final String getAttribute(Element elt, String attr_name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
String rc = elt.getAttribute(attr_name);
|
||||||
|
if (!(StringUtils.isEmpty(rc)))
|
||||||
|
return rc;
|
||||||
|
throw new XMLLoadException("no " + attr_name + "= attribute found",elt);
|
||||||
|
|
||||||
|
} // end getAttribute
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @param default_val The default value of the attribute.
|
||||||
|
* @return The attribute value, or the value of <CODE>default_val</CODE> if the attribute didn't exist.
|
||||||
|
*/
|
||||||
|
public final String getAttribute(Element elt, String attr_name, String default_val)
|
||||||
|
{
|
||||||
|
String rc = elt.getAttribute(attr_name);
|
||||||
|
return (StringUtils.isEmpty(rc) ? default_val : rc);
|
||||||
|
|
||||||
|
} // end getAttribute
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param namespace The namespace URI of the attribute to retrieve.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @return The attribute value.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute did not exist on the element.
|
||||||
|
*/
|
||||||
|
public final String getAttributeNS(Element elt, String namespace, String attr_name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
String rc = elt.getAttributeNS(namespace,attr_name);
|
||||||
|
if (!(StringUtils.isEmpty(rc)))
|
||||||
|
return rc;
|
||||||
|
throw new XMLLoadException("no " + namespace + ":" + attr_name + "= attribute found",elt);
|
||||||
|
|
||||||
|
} // end getAttributeNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param namespace The namespace URI of the attribute to retrieve.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @param default_val The default value of the attribute.
|
||||||
|
* @return The attribute value, or the value of <CODE>default_val</CODE> if the attribute didn't exist.
|
||||||
|
*/
|
||||||
|
public final String getAttributeNS(Element elt, String namespace, String attr_name, String default_val)
|
||||||
|
{
|
||||||
|
String rc = elt.getAttributeNS(namespace,attr_name);
|
||||||
|
return (StringUtils.isEmpty(rc) ? default_val : rc);
|
||||||
|
|
||||||
|
} // end getAttributeNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>, expressed as an integer.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @return The attribute value.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute did not exist on the element, or
|
||||||
|
* it could not be parsed as an integer.
|
||||||
|
*/
|
||||||
|
public final int getAttributeInt(Element elt, String attr_name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
String tmp = elt.getAttribute(attr_name);
|
||||||
|
if (StringUtils.isEmpty(tmp))
|
||||||
|
{ // the attribute is not present
|
||||||
|
throw new XMLLoadException("no " + attr_name + "= attribute found",elt);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // parse out the integer value
|
||||||
|
return Integer.parseInt(tmp.trim());
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{ // but it's not a valid integer - throw something else!
|
||||||
|
throw new XMLLoadException(attr_name + "= attribute value is not a valid integer",elt);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getAttributeInt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>, expressed as an integer.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @param default_val The default value of the attribute.
|
||||||
|
* @return The attribute value, or the value of <CODE>default_val</CODE> if the attribute didn't exist.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute could not be parsed as an integer.
|
||||||
|
*/
|
||||||
|
public final int getAttributeInt(Element elt, String attr_name, int default_val) throws XMLLoadException
|
||||||
|
{
|
||||||
|
String tmp = elt.getAttribute(attr_name);
|
||||||
|
if (StringUtils.isEmpty(tmp))
|
||||||
|
return default_val; // the attribute is not present
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // parse out the integer value
|
||||||
|
return Integer.parseInt(tmp.trim());
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{ // but it's not a valid integer - throw something else!
|
||||||
|
throw new XMLLoadException(attr_name + "= attribute value is not a valid integer",elt);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getAttributeInt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>, expressed as an integer.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param namespace The namespace URI of the attribute to retrieve.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @return The attribute value.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute did not exist on the element, or
|
||||||
|
* it could not be parsed as an integer.
|
||||||
|
*/
|
||||||
|
public final int getAttributeIntNS(Element elt, String namespace, String attr_name) throws XMLLoadException
|
||||||
|
{
|
||||||
|
String tmp = elt.getAttributeNS(namespace,attr_name);
|
||||||
|
if (StringUtils.isEmpty(tmp))
|
||||||
|
{ // the attribute is not present
|
||||||
|
throw new XMLLoadException("no " + namespace + ":" + attr_name + "= attribute found",elt);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // parse out the integer value
|
||||||
|
return Integer.parseInt(tmp.trim());
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{ // but it's not a valid integer - throw something else!
|
||||||
|
throw new XMLLoadException(namespace + ":" + attr_name + "= attribute value is not a valid integer",elt);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getAttributeIntNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>, expressed as an integer.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param namespace The namespace URI of the attribute to retrieve.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @param default_val The default value of the attribute.
|
||||||
|
* @return The attribute value, or the value of <CODE>default_val</CODE> if the attribute didn't exist.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute could not be parsed as an integer.
|
||||||
|
*/
|
||||||
|
public final int getAttributeIntNS(Element elt, String namespace, String attr_name, int default_val)
|
||||||
|
throws XMLLoadException
|
||||||
|
{
|
||||||
|
String tmp = elt.getAttributeNS(namespace,attr_name);
|
||||||
|
if (StringUtils.isEmpty(tmp))
|
||||||
|
return default_val; // the attribute is not present
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // parse out the integer value
|
||||||
|
return Integer.parseInt(tmp.trim());
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{ // but it's not a valid integer - throw something else!
|
||||||
|
throw new XMLLoadException(namespace + ":" + attr_name + "= attribute value is not a valid integer",elt);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getAttributeIntNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>, expressed as a Boolean. Uses the Boolean string
|
||||||
|
* methods on {@link com.silverwrist.util.StringUtils StringUtils} to determine the state of the attribute value.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @return The attribute value.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute did not exist on the element, or
|
||||||
|
* it could not be parsed as a Boolean.
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanTrue(java.lang.String)
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanFalse(java.lang.String)
|
||||||
|
*/
|
||||||
|
public final boolean getAttributeBoolean(Element elt, String attr_name)
|
||||||
|
throws XMLLoadException
|
||||||
|
{
|
||||||
|
String tmp = elt.getAttribute(attr_name);
|
||||||
|
if (StringUtils.isEmpty(tmp))
|
||||||
|
throw new XMLLoadException("no " + attr_name + "= attribute found",elt);
|
||||||
|
if (StringUtils.isBooleanTrue(tmp))
|
||||||
|
return true;
|
||||||
|
if (StringUtils.isBooleanFalse(tmp))
|
||||||
|
return false;
|
||||||
|
throw new XMLLoadException(attr_name + "= attribute value is not a valid Boolean",elt);
|
||||||
|
|
||||||
|
} // end getAttributeBoolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>, expressed as a Boolean. Uses the Boolean string
|
||||||
|
* methods on {@link com.silverwrist.util.StringUtils StringUtils} to determine the state of the attribute value.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @param default_val The default value of the attribute.
|
||||||
|
* @return The attribute value, or the value of <CODE>default_val</CODE> if the attribute didn't exist.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute could not be parsed as a Boolean.
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanTrue(java.lang.String)
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanFalse(java.lang.String)
|
||||||
|
*/
|
||||||
|
public final boolean getAttributeBoolean(Element elt, String attr_name, boolean default_val)
|
||||||
|
throws XMLLoadException
|
||||||
|
{
|
||||||
|
String tmp = elt.getAttribute(attr_name);
|
||||||
|
if (StringUtils.isEmpty(tmp))
|
||||||
|
return default_val;
|
||||||
|
if (StringUtils.isBooleanTrue(tmp))
|
||||||
|
return true;
|
||||||
|
if (StringUtils.isBooleanFalse(tmp))
|
||||||
|
return false;
|
||||||
|
throw new XMLLoadException(attr_name + "= attribute value is not a valid Boolean",elt);
|
||||||
|
|
||||||
|
} // end getAttributeBoolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of an attribute on an <CODE>Element</CODE>, expressed as a Boolean. Uses the Boolean string
|
||||||
|
* methods on {@link com.silverwrist.util.StringUtils StringUtils} to determine the state of the attribute value.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to retrieve the attribute from.
|
||||||
|
* @param namespace The namespace URI of the attribute to retrieve.
|
||||||
|
* @param attr_name The name of the attribute to retrieve.
|
||||||
|
* @param default_val The default value of the attribute.
|
||||||
|
* @return The attribute value, or the value of <CODE>default_val</CODE> if the attribute didn't exist.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute could not be parsed as a Boolean.
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanTrue(java.lang.String)
|
||||||
|
* @see com.silverwrist.util.StringUtils#isBooleanFalse(java.lang.String)
|
||||||
|
*/
|
||||||
|
public final boolean getAttributeBooleanNS(Element elt, String namespace, String attr_name,
|
||||||
|
boolean default_val) throws XMLLoadException
|
||||||
|
{
|
||||||
|
String tmp = elt.getAttributeNS(namespace,attr_name);
|
||||||
|
if (StringUtils.isEmpty(tmp))
|
||||||
|
return default_val;
|
||||||
|
if (StringUtils.isBooleanTrue(tmp))
|
||||||
|
return true;
|
||||||
|
if (StringUtils.isBooleanFalse(tmp))
|
||||||
|
return false;
|
||||||
|
throw new XMLLoadException(namespace + ":" + attr_name + "= attribute value is not a valid Boolean",elt);
|
||||||
|
|
||||||
|
} // end getAttributeBooleanNS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure that the value of a given attribute is what we expect, and throws an
|
||||||
|
* {@link com.silverwrist.util.xml.XMLLoadException XMLLoadException} if it isn't.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to test the attribute of.
|
||||||
|
* @param attr_name The name of the attribute to test.
|
||||||
|
* @param attr_value The value to test the attribute against.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute does not exist, or its value does not match.
|
||||||
|
*/
|
||||||
|
public final void verifyAttributeValue(Element elt, String attr_name, String attr_value)
|
||||||
|
throws XMLLoadException
|
||||||
|
{
|
||||||
|
String tmp = this.getAttribute(elt,attr_name);
|
||||||
|
if (!(tmp.equals(attr_value)))
|
||||||
|
throw new XMLLoadException("attribute " + attr_name + "= should be '" + attr_value + "', but is '"
|
||||||
|
+ tmp + "'",elt);
|
||||||
|
|
||||||
|
} // end verifyAttributeValue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure that the value of a given attribute is what we expect, and throws an
|
||||||
|
* {@link com.silverwrist.util.xml.XMLLoadException XMLLoadException} if it isn't.
|
||||||
|
*
|
||||||
|
* @param elt The <CODE>Element</CODE> to test the attribute of.
|
||||||
|
* @param namespace The namespace URI of the attribute to test.
|
||||||
|
* @param attr_name The name of the attribute to test.
|
||||||
|
* @param attr_value The value to test the attribute against.
|
||||||
|
* @exception com.silverwrist.util.xml.XMLLoadException If the attribute does not exist, or its value does not match.
|
||||||
|
*/
|
||||||
|
public final void verifyAttributeValueNS(Element elt, String namespace, String attr_name, String attr_value)
|
||||||
|
throws XMLLoadException
|
||||||
|
{
|
||||||
|
String tmp = this.getAttributeNS(elt,namespace,attr_name);
|
||||||
|
if (!(tmp.equals(attr_value)))
|
||||||
|
throw new XMLLoadException("attribute " + namespace + ":" + attr_name + "= should be '" + attr_value
|
||||||
|
+ "', but is '" + tmp + "'",elt);
|
||||||
|
|
||||||
|
} // end verifyAttributeValueNS
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Singleton instance of the <CODE>XMLLoader</CODE> object.
|
||||||
|
*
|
||||||
|
* @return The Singleton instance of the <CODE>XMLLoader</CODE> object.
|
||||||
|
*/
|
||||||
|
public static final synchronized XMLLoader get()
|
||||||
|
{
|
||||||
|
if (self==null)
|
||||||
|
self = new XMLLoader();
|
||||||
|
return self;
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
} // end class XMLLoader
|
189
src/dynamo-framework/com/silverwrist/dynamo/BrowserFlag.java
Normal file
189
src/dynamo-framework/com/silverwrist/dynamo/BrowserFlag.java
Normal file
|
@ -0,0 +1,189 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.commons.lang.enum.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type-safe enumerated type that indicates the capabilities of a browser. These objects are returned
|
||||||
|
* in a set by the {@link com.silverwrist.dynamo.iface.BrowserData#getBrowserFlags() BrowserData.getBrowserFlags()}
|
||||||
|
* method.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public final class BrowserFlag extends Enum
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* The actual enumeration values
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports frames (the <FRAMESET> and <FRAME> tags).
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag FRAMES = new BrowserFlag("FRAMES");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports in-line frames (the <IFRAME> tag).
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag IFRAMES = new BrowserFlag("IFRAMES");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports tables.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag TABLES = new BrowserFlag("TABLES");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports cookies.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag COOKIES = new BrowserFlag("COOKIES");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports background sounds (the <BGSOUND> tag).
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag BACKGROUND_SOUNDS = new BrowserFlag("BACKGROUND_SOUNDS");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports client-side scripting using Visual Basic Script.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag VBSCRIPT = new BrowserFlag("VBSCRIPT");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports client-side scripting using JavaScript (JScript).
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag JAVASCRIPT = new BrowserFlag("JAVASCRIPT");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports client-side Java applets.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag JAVA_APPLETS = new BrowserFlag("JAVA_APPLETS");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports client-side ActiveX controls.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag ACTIVEX_CONTROLS = new BrowserFlag("ACTIVEX_CONTROLS");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser supports CDF.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag CDF = new BrowserFlag("CDF");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that this browser is an America Online client.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag AOL = new BrowserFlag("AOL");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that this browser is a beta version.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag BETA = new BrowserFlag("BETA");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser is running on a 16-bit Windows operating system.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag WIN16 = new BrowserFlag("WIN16");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that this browser is not a browser at all, but a "crawler," which may be used to index the
|
||||||
|
* site's content by a search engine, or for other (nefarious) purposes.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag CRAWLER = new BrowserFlag("CRAWLER");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that this browser is not a browser at all, but a "stripper," which is copying the HTML of the
|
||||||
|
* site to another location. This may or may not be benign.
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag STRIPPER = new BrowserFlag("STRIPPER");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the browser is a cellphone or other handheld device, possibly supporting
|
||||||
|
* Wireless Access Protocol (WAP).
|
||||||
|
*/
|
||||||
|
public static final BrowserFlag WAP = new BrowserFlag("WAP");
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal constructor which creates a new element of this enumerated type.
|
||||||
|
*
|
||||||
|
* @param name The name of the <CODE>BrowserFlag</CODE> to be created.
|
||||||
|
*/
|
||||||
|
private BrowserFlag(String name)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Standard static method implementations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a <CODE>BrowserFlag</CODE> by name.
|
||||||
|
*
|
||||||
|
* @param name The name of the <CODE>BrowserFlag</CODE> to get; may be <CODE>null</CODE>.
|
||||||
|
* @return The <CODE>BrowserFlag</CODE> object, or <CODE>null</CODE> if the <CODE>BrowserFlag</CODE> does not exist.
|
||||||
|
*/
|
||||||
|
public static BrowserFlag getEnum(String name)
|
||||||
|
{
|
||||||
|
return (BrowserFlag)getEnum(BrowserFlag.class,name);
|
||||||
|
|
||||||
|
} // end getEnum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <CODE>Map</CODE> of <CODE>BrowserFlag</CODE> objects by name.
|
||||||
|
*
|
||||||
|
* @return The <CODE>BrowserFlag</CODE> object <CODE>Map</CODE>.
|
||||||
|
*/
|
||||||
|
public static Map getEnumMap()
|
||||||
|
{
|
||||||
|
return getEnumMap(BrowserFlag.class);
|
||||||
|
|
||||||
|
} // end getEnumMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <CODE>List</CODE> of <CODE>BrowserFlag</CODE> objects, in the order in which the objects are listed
|
||||||
|
* in the code above.
|
||||||
|
*
|
||||||
|
* @return The <CODE>BrowserFlag</CODE> object <CODE>List</CODE>.
|
||||||
|
*/
|
||||||
|
public static List getEnumList()
|
||||||
|
{
|
||||||
|
return getEnumList(BrowserFlag.class);
|
||||||
|
|
||||||
|
} // end getEnumList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an iterator over all <CODE>BrowserFlag</CODE> objects, in the order in which the objects are listed
|
||||||
|
* in the code above.
|
||||||
|
*
|
||||||
|
* @return The <CODE>BrowserFlag</CODE> object iterator.
|
||||||
|
*/
|
||||||
|
public static Iterator iterator()
|
||||||
|
{
|
||||||
|
return iterator(BrowserFlag.class);
|
||||||
|
|
||||||
|
} // end iterator
|
||||||
|
|
||||||
|
} // end class BrowserFlag
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that holds the Dynamo version number.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public final class DynamoVersion
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The current version number of the Dynamo framework.
|
||||||
|
*/
|
||||||
|
public static final String VERSION = "0.05";
|
||||||
|
|
||||||
|
} // end class DynamoVersion
|
482
src/dynamo-framework/com/silverwrist/dynamo/HttpStatusCode.java
Normal file
482
src/dynamo-framework/com/silverwrist/dynamo/HttpStatusCode.java
Normal file
|
@ -0,0 +1,482 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.commons.lang.enum.*;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type-safe enumerated type that encapsulates the HTTP status codes. We use an enumerated type here
|
||||||
|
* so that it can be extended to support additional status codes (the ones defined, say, by WebDAV)
|
||||||
|
* without affecting <CODE>HttpServletResponse</CODE>.
|
||||||
|
* <p>The descriptions of the status codes are taken from the HTTP 1.1 Specification,
|
||||||
|
* <a href="ftp://ftp.rfc-editor.org/in-notes/rfc2616.txt">RFC 2616</a>.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class HttpStatusCode extends ValuedEnum
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* The actual enumeration values
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// N.B.: We copy the status codes here to allow extending them independent of the codes
|
||||||
|
// listed in HttpServletResponse, but we point to the originals in HttpServletResponse
|
||||||
|
// to maintain compatibility.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>100 Continue</b>. The client SHOULD continue with its request. This interim response is used to
|
||||||
|
* inform the client that the initial part of the request has been received and has not yet been rejected
|
||||||
|
* by the server. The client SHOULD continue by sending the remainder of the request or, if the request
|
||||||
|
* has already been completed, ignore this response. The server MUST send a final response after the
|
||||||
|
* request has been completed.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode I_CONTINUE =
|
||||||
|
new HttpStatusCode("I_CONTINUE",HttpServletResponse.SC_CONTINUE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>101 Switching Protocols</b>. The server understands and is willing to comply with the client's request,
|
||||||
|
* via the Upgrade message header field, for a change in the application protocol being used on this connection.
|
||||||
|
* The server will switch protocols to those defined by the response's Upgrade header field immediately after
|
||||||
|
* the empty line which terminates the 101 response.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode I_SWITCH =
|
||||||
|
new HttpStatusCode("I_SWITCH",HttpServletResponse.SC_SWITCHING_PROTOCOLS);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>200 OK</b>. The request has succeeded. The information returned with the response is dependent on
|
||||||
|
* the method used in the request. (Default status code)
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_OK =
|
||||||
|
new HttpStatusCode("S_OK",HttpServletResponse.SC_OK);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>201 Created</b>. The request has been fulfilled and resulted in a new resource being created. The
|
||||||
|
* newly created resource can be referenced by the URI(s) returned in the entity of the response, with
|
||||||
|
* the most specific URI for the resource given by a Location header field. The response SHOULD include
|
||||||
|
* an entity containing a list of resource characteristics and location(s) from which the user or user
|
||||||
|
* agent can choose the one most appropriate. The entity format is specified by the media type given in
|
||||||
|
* the Content-Type header field. The origin server MUST create the resource before returning the 201
|
||||||
|
* status code. If the action cannot be carried out immediately, the server SHOULD respond with 202
|
||||||
|
* (Accepted) response instead.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_CREATED =
|
||||||
|
new HttpStatusCode("S_CREATED",HttpServletResponse.SC_CREATED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>202 Accepted</b>. The request has been accepted for processing, but the processing has not been
|
||||||
|
* completed. The request might or might not eventually be acted upon, as it might be disallowed when
|
||||||
|
* processing actually takes place.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_ACCEPTED =
|
||||||
|
new HttpStatusCode("S_ACCEPTED",HttpServletResponse.SC_ACCEPTED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>203 Non-Authoritative Information</b>. The returned metainformation in the entity-header is not the
|
||||||
|
* definitive set as available from the origin server, but is gathered from a local or a third-party copy.
|
||||||
|
* The set presented MAY be a subset or superset of the original version. For example, including local
|
||||||
|
* annotation information about the resource might result in a superset of the metainformation known by
|
||||||
|
* the origin server. Use of this response code is not required and is only appropriate when the response
|
||||||
|
* would otherwise be 200 (OK).
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_NONAUTHORITATIVE =
|
||||||
|
new HttpStatusCode("S_NONAUTHORITATIVE",HttpServletResponse.SC_NON_AUTHORITATIVE_INFORMATION);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>204 No Content</b>. The server has fulfilled the request but does not need to return an entity-body,
|
||||||
|
* and might want to return updated metainformation. The response MAY include new or updated metainformation
|
||||||
|
* in the form of entity-headers, which if present SHOULD be associated with the requested variant. If the
|
||||||
|
* client is a user agent, it SHOULD NOT change its document view from that which caused the request to be
|
||||||
|
* sent. This response is primarily intended to allow input for actions to take place without causing a
|
||||||
|
* change to the user agent's active document view, although any new or updated metainformation SHOULD be
|
||||||
|
* applied to the document currently in the user agent's active view.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_NODATA =
|
||||||
|
new HttpStatusCode("S_NODATA",HttpServletResponse.SC_NO_CONTENT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>205 Reset Content</b>. The server has fulfilled the request and the user agent SHOULD reset the document
|
||||||
|
* view which caused the request to be sent. This response is primarily intended to allow input for actions
|
||||||
|
* to take place via user input, followed by a clearing of the form in which the input is given so that the
|
||||||
|
* user can easily initiate another input action.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_RESET =
|
||||||
|
new HttpStatusCode("S_RESET",HttpServletResponse.SC_RESET_CONTENT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>206 Partial Content</b>. The server has fulfilled the partial GET request for the resource. The
|
||||||
|
* request MUST have included a Range header field indicating the desired range, and MAY have included
|
||||||
|
* an If-Range header field to make the request conditional.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_PARTIAL =
|
||||||
|
new HttpStatusCode("S_PARTIAL",HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>300 Multiple Choices</b>. The requested resource corresponds to any one of a set of representations,
|
||||||
|
* each with its own specific location, and agent-driven negotiation information is being provided so that
|
||||||
|
* the user (or user agent) can select a preferred representation and redirect its request to that location.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_CHOICE =
|
||||||
|
new HttpStatusCode("S_CHOICE",HttpServletResponse.SC_MULTIPLE_CHOICES);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>301 Moved Permanently</b>. The requested resource has been assigned a new permanent URI and any future
|
||||||
|
* references to this resource SHOULD use one of the returned URIs. Clients with link editing capabilities
|
||||||
|
* ought to automatically re-link references to the Request-URI to one or more of the new references returned
|
||||||
|
* by the server, where possible.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_MOVED =
|
||||||
|
new HttpStatusCode("S_MOVED",HttpServletResponse.SC_MOVED_PERMANENTLY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>302 Moved Temporarily</b> (Redirect). The requested resource resides temporarily under a different URI.
|
||||||
|
* Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for
|
||||||
|
* future requests.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_REDIRECT =
|
||||||
|
new HttpStatusCode("S_REDIRECT",HttpServletResponse.SC_MOVED_TEMPORARILY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>303 See Other</b>. The response to the request can be found under a different URI and SHOULD be
|
||||||
|
* retrieved using a GET method on that resource. This method exists primarily to allow the output of a
|
||||||
|
* POST-activated script to redirect the user agent to a selected resource. The new URI is not a
|
||||||
|
* substitute reference for the originally requested resource.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_SEE_OTHER =
|
||||||
|
new HttpStatusCode("S_SEE_OTHER",HttpServletResponse.SC_SEE_OTHER);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>304 Not Modified</b>. If the client has performed a conditional GET request and access is allowed,
|
||||||
|
* but the document has not been modified, the server SHOULD respond with this status code.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_NOTMODIFIED =
|
||||||
|
new HttpStatusCode("S_NOTMODIFIED",HttpServletResponse.SC_NOT_MODIFIED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>305 Use Proxy</b>. The requested resource MUST be accessed through the proxy given by the Location
|
||||||
|
* field. The Location field gives the URI of the proxy. The recipient is expected to repeat this single
|
||||||
|
* request via the proxy.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_USE_PROXY =
|
||||||
|
new HttpStatusCode("S_USEPROXY",HttpServletResponse.SC_USE_PROXY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>307 Temporary Redirect</b>. The requested resource resides temporarily under a different URI.
|
||||||
|
* Since the redirection MAY be altered on occasion, the client SHOULD continue to use the Request-URI
|
||||||
|
* for future requests.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode S_REDIRECT_TEMP =
|
||||||
|
new HttpStatusCode("S_REDIRECT_TEMP",HttpServletResponse.SC_TEMPORARY_REDIRECT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>400 Bad Request</b>. The request could not be understood by the server due to malformed syntax. The
|
||||||
|
* client SHOULD NOT repeat the request without modifications.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_BAD_REQUEST =
|
||||||
|
new HttpStatusCode("E_BAD_REQUEST",HttpServletResponse.SC_BAD_REQUEST);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>401 Unauthorized</b>. The request requires user authentication. The response MUST include a
|
||||||
|
* WWW-Authenticate header field containing a challenge applicable to the requested resource. The client
|
||||||
|
* MAY repeat the request with a suitable Authorization header field. If the request already included
|
||||||
|
* Authorization credentials, then the 401 response indicates that authorization has been refused for those
|
||||||
|
* credentials. If the 401 response contains the same challenge as the prior response, and the user agent
|
||||||
|
* has already attempted authentication at least once, then the user SHOULD be presented the entity that
|
||||||
|
* was given in the response, since that entity might include relevant diagnostic information.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_AUTH =
|
||||||
|
new HttpStatusCode("E_AUTH",HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>402 Payment Required</b>. This code is reserved for future use.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_PAYMENT =
|
||||||
|
new HttpStatusCode("E_PAYMENT",HttpServletResponse.SC_PAYMENT_REQUIRED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>403 Forbidden</b>. The server understood the request, but is refusing to fulfill it. Authorization
|
||||||
|
* will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server
|
||||||
|
* wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the
|
||||||
|
* refusal in the entity. If the server does not wish to make this information available to the client,
|
||||||
|
* the status code 404 (Not Found) can be used instead.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_FORBIDDEN =
|
||||||
|
new HttpStatusCode("E_FORBIDDEN",HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>404 Not Found</b>. The server has not found anything matching the Request-URI. No indication is given
|
||||||
|
* of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the
|
||||||
|
* server knows, through some internally configurable mechanism, that an old resource is permanently
|
||||||
|
* unavailable and has no forwarding address. This status code is commonly used when the server does not
|
||||||
|
* wish to reveal exactly why the request has been refused, or when no other response is applicable.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_NOTFOUND =
|
||||||
|
new HttpStatusCode("E_NOTFOUND",HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>405 Method Not Allowed</b>. The method specified in the Request-Line is not allowed for the resource
|
||||||
|
* identified by the Request-URI. The response MUST include an Allow header containing a list of valid
|
||||||
|
* methods for the requested resource.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_METHOD =
|
||||||
|
new HttpStatusCode("E_METHOD",HttpServletResponse.SC_METHOD_NOT_ALLOWED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>406 Not Acceptable</b>. The resource identified by the request is only capable of generating response
|
||||||
|
* entities which have content characteristics not acceptable according to the accept headers sent in the request.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_NOTACCEPTABLE =
|
||||||
|
new HttpStatusCode("E_NOTACCEPTABLE",HttpServletResponse.SC_NOT_ACCEPTABLE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>407 Proxy Authentication Required</b>. This code is similar to 401 (Unauthorized), but indicates that
|
||||||
|
* the client must first authenticate itself with the proxy. The proxy MUST return a Proxy-Authenticate
|
||||||
|
* header field containing a challenge applicable to the proxy for the requested resource. The client MAY
|
||||||
|
* repeat the request with a suitable Proxy-Authorization header field.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_PROXY_AUTH =
|
||||||
|
new HttpStatusCode("E_PROXY_AUTH",HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>408 Request Timeout</b>. The client did not produce a request within the time that the server was
|
||||||
|
* prepared to wait. The client MAY repeat the request without modifications at any later time.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_TIMEOUT =
|
||||||
|
new HttpStatusCode("E_TIMEOUT",HttpServletResponse.SC_REQUEST_TIMEOUT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>409 Conflict</b>. The request could not be completed due to a conflict with the current state of the
|
||||||
|
* resource. This code is only allowed in situations where it is expected that the user might be able to
|
||||||
|
* resolve the conflict and resubmit the request. The response body SHOULD include enough information for
|
||||||
|
* the user to recognize the source of the conflict. Ideally, the response entity would include enough
|
||||||
|
* information for the user or user agent to fix the problem; however, that might not be possible and is
|
||||||
|
* not required.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_CONFLICT =
|
||||||
|
new HttpStatusCode("E_CONFLICT",HttpServletResponse.SC_CONFLICT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>410 Gone</b>. The requested resource is no longer available at the server and no forwarding address
|
||||||
|
* is known. This condition is expected to be considered permanent. Clients with link editing capabilities
|
||||||
|
* SHOULD delete references to the Request-URI after user approval. If the server does not know, or has no
|
||||||
|
* facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD
|
||||||
|
* be used instead.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_GONE =
|
||||||
|
new HttpStatusCode("E_GONE",HttpServletResponse.SC_GONE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>411 Length Required</b>. The server refuses to accept the request without a defined Content-Length.
|
||||||
|
* The client MAY repeat the request if it adds a valid Content-Length header field containing the length
|
||||||
|
* of the message-body in the request message.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_NOLENGTH =
|
||||||
|
new HttpStatusCode("E_NOLENGTH",HttpServletResponse.SC_LENGTH_REQUIRED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>412 Precondition Failed</b>. The precondition given in one or more of the request-header fields
|
||||||
|
* evaluated to false when it was tested on the server. This response code allows the client to place
|
||||||
|
* preconditions on the current resource metainformation (header field data) and thus prevent the
|
||||||
|
* requested method from being applied to a resource other than the one intended.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_PRECONDITION =
|
||||||
|
new HttpStatusCode("E_PRECONDITION",HttpServletResponse.SC_PRECONDITION_FAILED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>413 Request Entity Too Large</b>. The server is refusing to process a request because the request
|
||||||
|
* entity is larger than the server is willing or able to process. The server MAY close the connection to
|
||||||
|
* prevent the client from continuing the request. If the condition is temporary, the server SHOULD include
|
||||||
|
* a Retry-After header field to indicate that it is temporary and after what time the client MAY try again.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_ENTITYTOOBIG =
|
||||||
|
new HttpStatusCode("E_ENTITYTOOBIG",HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>414 Request URI Too Long</b>. The server is refusing to service the request because the Request-URI is
|
||||||
|
* longer than the server is willing to interpret. This rare condition is only likely to occur when a client
|
||||||
|
* has improperly converted a POST request to a GET request with long query information, when the client has
|
||||||
|
* descended into a URI "black hole" of redirection (e.g., a redirected URI prefix that points to a suffix of
|
||||||
|
* itself), or when the server is under attack by a client attempting to exploit security holes present in
|
||||||
|
* some servers using fixed-length buffers for reading or manipulating the Request-URI.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_URITOOLONG =
|
||||||
|
new HttpStatusCode("E_URITOOLONG",HttpServletResponse.SC_REQUEST_URI_TOO_LONG);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>415 Media Type Not Supported</b>. The server is refusing to service the request because the entity of
|
||||||
|
* the request is in a format not supported by the requested resource for the requested method.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_BAD_TYPE =
|
||||||
|
new HttpStatusCode("E_BAD_TYPE",HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>416 Requested Range Not Satisfiable</b>. A server SHOULD return a response with this status code if
|
||||||
|
* a request included a Range request-header field, and none of the range-specifier values in this field
|
||||||
|
* overlap the current extent of the selected resource, and the request did not include an If-Range
|
||||||
|
* request-header field. (For byte-ranges, this means that the first-byte-pos of all of the byte-range-spec
|
||||||
|
* values were greater than the current length of the selected resource.) When this status code is returned
|
||||||
|
* for a byte-range request, the response SHOULD include a Content-Range entity-header field specifying the
|
||||||
|
* current length of the selected resource. This response MUST NOT use the multipart/byteranges content-type.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_BAD_RANGE =
|
||||||
|
new HttpStatusCode("E_BAD_RANGE",HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>417 Expectation Failed</b>. The expectation given in an Expect request-header field could not be met by
|
||||||
|
* this server, or, if the server is a proxy, the server has unambiguous evidence that the request could not
|
||||||
|
* be met by the next-hop server.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_EXPECTATION =
|
||||||
|
new HttpStatusCode("E_EXPECTATION",HttpServletResponse.SC_EXPECTATION_FAILED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>500 Internal Server Error</b>. The server encountered an unexpected condition which prevented it
|
||||||
|
* from fulfilling the request.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_INTERNAL =
|
||||||
|
new HttpStatusCode("E_INTERNAL",HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>501 Not Implemented</b>. The server does not support the functionality required to fulfill the request.
|
||||||
|
* This is the appropriate response when the server does not recognize the request method and is not capable
|
||||||
|
* of supporting it for any resource.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_NOTIMPL =
|
||||||
|
new HttpStatusCode("E_NOTIMPL",HttpServletResponse.SC_NOT_IMPLEMENTED);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>502 Bad Gateway</b>. The server, while acting as a gateway or proxy, received an invalid response from
|
||||||
|
* the upstream server it accessed in attempting to fulfill the request.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_BAD_GATEWAY =
|
||||||
|
new HttpStatusCode("E_BAD_GATEWAY",HttpServletResponse.SC_BAD_GATEWAY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>503 Service Unavailable</b>. The server is currently unable to handle the request due to a temporary
|
||||||
|
* overloading or maintenance of the server. The implication is that this is a temporary condition which will
|
||||||
|
* be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header.
|
||||||
|
* If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_UNAVAILABLE =
|
||||||
|
new HttpStatusCode("E_UNAVAILABLE",HttpServletResponse.SC_SERVICE_UNAVAILABLE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>504 Gateway Timeout</b>. The server, while acting as a gateway or proxy, did not receive a timely
|
||||||
|
* response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary
|
||||||
|
* server (e.g. DNS) it needed to access in attempting to complete the request.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_GATEWAY_TIMEOUT =
|
||||||
|
new HttpStatusCode("E_GATEWAY_TIMEOUT",HttpServletResponse.SC_GATEWAY_TIMEOUT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>505 HTTP Version Not Supported</b>. The server does not support, or refuses to support, the HTTP
|
||||||
|
* protocol version that was used in the request message. The server is indicating that it is unable or
|
||||||
|
* unwilling to complete the request using the same major version as the client, other than with this
|
||||||
|
* error message. The response SHOULD contain an entity describing why that version is not supported and
|
||||||
|
* what other protocols are supported by that server.
|
||||||
|
*/
|
||||||
|
public static final HttpStatusCode E_BAD_VERSION =
|
||||||
|
new HttpStatusCode("E_BAD_VERSION",HttpServletResponse.SC_HTTP_VERSION_NOT_SUPPORTED);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal constructor which creates a new element of this enumerated type.
|
||||||
|
*
|
||||||
|
* @param name The name of the <CODE>HttpStatusCode</CODE> to be created.
|
||||||
|
* @param value The numeric value to assign to the <CODE>HttpStatusCode</CODE>.
|
||||||
|
*/
|
||||||
|
private HttpStatusCode(String name, int value)
|
||||||
|
{
|
||||||
|
super(name,value);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Standard static method implementations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a <CODE>HttpStatusCode</CODE> by name.
|
||||||
|
*
|
||||||
|
* @param name The name of the <CODE>HttpStatusCode</CODE> to get; may be <CODE>null</CODE>.
|
||||||
|
* @return The <CODE>HttpStatusCode</CODE> object, or <CODE>null</CODE> if the <CODE>HttpStatusCode</CODE>
|
||||||
|
* does not exist.
|
||||||
|
*/
|
||||||
|
public static HttpStatusCode getEnum(String name)
|
||||||
|
{
|
||||||
|
return (HttpStatusCode)getEnum(HttpStatusCode.class,name);
|
||||||
|
|
||||||
|
} // end getEnum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a <CODE>HttpStatusCode</CODE> by numeric value.
|
||||||
|
*
|
||||||
|
* @param code The numeric value of the <CODE>HttpStatusCode</CODE> to get.
|
||||||
|
* @return The <CODE>HttpStatusCode</CODE> object, or <CODE>null</CODE> if the <CODE>HttpStatusCode</CODE>
|
||||||
|
* does not exist.
|
||||||
|
*/
|
||||||
|
public static HttpStatusCode getEnum(int code)
|
||||||
|
{
|
||||||
|
return (HttpStatusCode)getEnum(HttpStatusCode.class,code);
|
||||||
|
|
||||||
|
} // end getEnum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <CODE>Map</CODE> of <CODE>HttpStatusCode</CODE> objects by name.
|
||||||
|
*
|
||||||
|
* @return The <CODE>HttpStatusCode</CODE> object <CODE>Map</CODE>.
|
||||||
|
*/
|
||||||
|
public static Map getEnumMap()
|
||||||
|
{
|
||||||
|
return getEnumMap(HttpStatusCode.class);
|
||||||
|
|
||||||
|
} // end getEnumMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <CODE>List</CODE> of <CODE>HttpStatusCode</CODE> objects, in the order in which the objects are listed
|
||||||
|
* in the code above.
|
||||||
|
*
|
||||||
|
* @return The <CODE>HttpStatusCode</CODE> object <CODE>List</CODE>.
|
||||||
|
*/
|
||||||
|
public static List getEnumList()
|
||||||
|
{
|
||||||
|
return getEnumList(HttpStatusCode.class);
|
||||||
|
|
||||||
|
} // end getEnumList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an iterator over all <CODE>HttpStatusCode</CODE> objects, in the order in which the objects are listed
|
||||||
|
* in the code above.
|
||||||
|
*
|
||||||
|
* @return The <CODE>HttpStatusCode</CODE> object iterator.
|
||||||
|
*/
|
||||||
|
public static Iterator iterator()
|
||||||
|
{
|
||||||
|
return iterator(HttpStatusCode.class);
|
||||||
|
|
||||||
|
} // end iterator
|
||||||
|
|
||||||
|
} // end class HttpStatusCode
|
77
src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java
Normal file
77
src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains various namespaces which are used to designate objects in the global
|
||||||
|
* {@link com.silverwrist.dynamo.iface.ObjectProvider ObjectProvider} and other contexts.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public interface Namespaces
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Namespace used for objects provided by the application substrate object.
|
||||||
|
*/
|
||||||
|
public static final String SUBSTRATE_NAMESPACE =
|
||||||
|
"http://www.silverwrist.com/NS/dynamo/2002/11/29/substrate.objects";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace used to retrieve servlet initialization parameters.
|
||||||
|
*/
|
||||||
|
public static final String SERVLET_INIT_NAMESPACE =
|
||||||
|
"http://www.silverwrist.com/NS/dynamo/2002/12/22/servlet.init.params";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace used to retrieve servlet context initialization parameters.
|
||||||
|
*/
|
||||||
|
public static final String SERVLET_CONTEXT_NAMESPACE =
|
||||||
|
"http://www.silverwrist.com/NS/dynamo/2002/12/22/servlet.context.params";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace under which the database connections are stored.
|
||||||
|
*/
|
||||||
|
public static final String DATABASE_CONNECTIONS_NAMESPACE =
|
||||||
|
"http://www.silverwrist.com/NS/dynamo/2002/12/08/database.connections";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace under which the Dynamo objects are stored.
|
||||||
|
*/
|
||||||
|
public static final String DYNAMO_OBJECT_NAMESPACE =
|
||||||
|
"http://www.silverwrist.com/NS/dynamo/2002/12/07/dynamo.objects";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace under which the Dynamo application-level objects are stored.
|
||||||
|
*/
|
||||||
|
public static final String DYNAMO_APPLICATION_NAMESPACE =
|
||||||
|
"http://www.silverwrist.com/NS/dynamo/2002/12/08/dynamo.application";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace used to retrieve user information for mail messages.
|
||||||
|
*/
|
||||||
|
public static final String DYNAMO_USER_INFO_NAMESPACE =
|
||||||
|
"http://www.silverwrist.com/NS/dynamo/2002/12/13/user.information";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace used to designate group permissions.
|
||||||
|
*/
|
||||||
|
public static final String GROUP_PERMISSIONS_NAMESPACE =
|
||||||
|
"http://www.silverwrist.com/NS/dynamo/2002/12/27/group.permissions";
|
||||||
|
|
||||||
|
} // end interface Namespaces
|
142
src/dynamo-framework/com/silverwrist/dynamo/RequestType.java
Normal file
142
src/dynamo-framework/com/silverwrist/dynamo/RequestType.java
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.commons.lang.enum.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type-safe enumerated type that indicates the type of a {@link com.silverwrist.dynamo.iface.Request Request}
|
||||||
|
* that comes in from the framework. It is also used to indicate the type of a
|
||||||
|
* {@link com.silverwrist.dynamo.iface.SessionInfo SessionInfo} object.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public final class RequestType extends Enum
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* The actual enumeration values
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A "null" request type, only used to label certain sessions.
|
||||||
|
*
|
||||||
|
* @see com.silverwrist.dynamo.util.NullSessionInfo
|
||||||
|
*/
|
||||||
|
public static final RequestType _NULL = new RequestType("_NULL");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This <CODE>RequestType</CODE> is used to label the {@link com.silverwrist.dynamo.iface.Request Request} passed
|
||||||
|
* along with the event that is fired when the application starts up.
|
||||||
|
*
|
||||||
|
* @see com.silverwrist.dynamo.event.ApplicationEvent
|
||||||
|
*/
|
||||||
|
public static final RequestType _APPLICATION = new RequestType("_APPLICATION");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This <CODE>RequestType</CODE> is used to label the {@link com.silverwrist.dynamo.iface.Request Request} passed
|
||||||
|
* along with the event that is fired when a new session is created.
|
||||||
|
*
|
||||||
|
* @see com.silverwrist.dynamo.event.SessionInfoEvent
|
||||||
|
*/
|
||||||
|
public static final RequestType _SESSION = new RequestType("_SESSION");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Designates a {@link com.silverwrist.dynamo.iface.Request Request} or
|
||||||
|
* {@link com.silverwrist.dynamo.iface.SessionInfo SessionInfo} associated with standard HTTP requests.
|
||||||
|
*/
|
||||||
|
public static final RequestType HTTP = new RequestType("HTTP");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Designates a {@link com.silverwrist.dynamo.iface.Request Request} or
|
||||||
|
* {@link com.silverwrist.dynamo.iface.SessionInfo SessionInfo} associated with XML-RPC requests, usually
|
||||||
|
* transmitted over HTTP.
|
||||||
|
*/
|
||||||
|
public static final RequestType XMLRPC = new RequestType("XMLRPC");
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal constructor which creates a new element of this enumerated type.
|
||||||
|
*
|
||||||
|
* @param name The name of the <CODE>RequestType</CODE> to be created.
|
||||||
|
*/
|
||||||
|
private RequestType(String name)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Standard static method implementations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a <CODE>RequestType</CODE> by name.
|
||||||
|
*
|
||||||
|
* @param name The name of the <CODE>RequestType</CODE> to get; may be <CODE>null</CODE>.
|
||||||
|
* @return The <CODE>RequestType</CODE> object, or <CODE>null</CODE> if the <CODE>RequestType</CODE> does not exist.
|
||||||
|
*/
|
||||||
|
public static RequestType getEnum(String name)
|
||||||
|
{
|
||||||
|
return (RequestType)getEnum(RequestType.class,name);
|
||||||
|
|
||||||
|
} // end getEnum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <CODE>Map</CODE> of <CODE>RequestType</CODE> objects by name.
|
||||||
|
*
|
||||||
|
* @return The <CODE>RequestType</CODE> object <CODE>Map</CODE>.
|
||||||
|
*/
|
||||||
|
public static Map getEnumMap()
|
||||||
|
{
|
||||||
|
return getEnumMap(RequestType.class);
|
||||||
|
|
||||||
|
} // end getEnumMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <CODE>List</CODE> of <CODE>RequestType</CODE> objects, in the order in which the objects are listed
|
||||||
|
* in the code above.
|
||||||
|
*
|
||||||
|
* @return The <CODE>RequestType</CODE> object <CODE>List</CODE>.
|
||||||
|
*/
|
||||||
|
public static List getEnumList()
|
||||||
|
{
|
||||||
|
return getEnumList(RequestType.class);
|
||||||
|
|
||||||
|
} // end getEnumList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an iterator over all <CODE>RequestType</CODE> objects, in the order in which the objects are listed
|
||||||
|
* in the code above.
|
||||||
|
*
|
||||||
|
* @return The <CODE>RequestType</CODE> object iterator.
|
||||||
|
*/
|
||||||
|
public static Iterator iterator()
|
||||||
|
{
|
||||||
|
return iterator(RequestType.class);
|
||||||
|
|
||||||
|
} // end iterator
|
||||||
|
|
||||||
|
} // end class RequestType
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the attributes used by the Dynamo mail component to retrieve user information. Also contains
|
||||||
|
* the name for the default authenticator and default user permissons.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public interface UserInfoNamespace
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The property namespace that contains the user information.
|
||||||
|
*/
|
||||||
|
public static final String NAMESPACE = Namespaces.DYNAMO_USER_INFO_NAMESPACE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property name designating the user's full name.
|
||||||
|
*/
|
||||||
|
public static final String ATTR_FULLNAME = "full.name";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property name designating the user E-mail address.
|
||||||
|
*/
|
||||||
|
public static final String ATTR_EMAIL_ADDRESS = "email.address";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property name designating the numeric user ID.
|
||||||
|
*/
|
||||||
|
public static final String ATTR_ID = "user.id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property name designating the user name.
|
||||||
|
*/
|
||||||
|
public static final String ATTR_USERNAME = "user.name";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to designate the default hash password authenticator.
|
||||||
|
*/
|
||||||
|
public static final String AUTH_DEFAULT = "default.hash.password";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The permission that allows user information to be edited.
|
||||||
|
*/
|
||||||
|
public static final String PERM_EDIT_ALL = "edit.all";
|
||||||
|
|
||||||
|
} // end interface UserInfoNamespace
|
132
src/dynamo-framework/com/silverwrist/dynamo/Verb.java
Normal file
132
src/dynamo-framework/com/silverwrist/dynamo/Verb.java
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.commons.lang.enum.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type-safe enumerated type that indicates the action of a {@link com.silverwrist.dynamo.iface.Request Request}
|
||||||
|
* that comes in from the framework. <CODE>Verb</CODE> objects correspond roughly to HTTP methods.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public final class Verb extends Enum
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* The actual enumeration values
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates a request to delete a resource identified by a URI. Corresponds to HTTP DELETE method.
|
||||||
|
*/
|
||||||
|
public static final Verb DELETE = new Verb("DELETE"); // (standard)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates a request to retrieve a resource identified by a URI. Corresponds to HTTP GET method.
|
||||||
|
*/
|
||||||
|
public static final Verb GET = new Verb("GET"); // (standard)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates a request to interact with a resource identified by a URI. Corresponds to HTTP POST method.
|
||||||
|
* All XML-RPC requests use this verb.
|
||||||
|
*/
|
||||||
|
public static final Verb POST = new Verb("POST"); // (standard)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates a request to overwrite a resource identified by a URI. Corresponds to HTTP PUT method.
|
||||||
|
*/
|
||||||
|
public static final Verb PUT = new Verb("PUT"); // (standard)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates a request to get the last modification time of a resource identified by a URI. Often associated
|
||||||
|
* with a HTTP GET method.
|
||||||
|
*/
|
||||||
|
public static final Verb _LASTMOD = new Verb("_LASTMOD"); // extended for getLastModified
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal constructor which creates a new element of this enumerated type.
|
||||||
|
*
|
||||||
|
* @param name The name of the <CODE>Verb</CODE> to be created.
|
||||||
|
*/
|
||||||
|
private Verb(String name)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Standard static method implementations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a <CODE>Verb</CODE> by name.
|
||||||
|
*
|
||||||
|
* @param name The name of the <CODE>Verb</CODE> to get; may be <CODE>null</CODE>.
|
||||||
|
* @return The <CODE>Verb</CODE> object, or <CODE>null</CODE> if the <CODE>Verb</CODE> does not exist.
|
||||||
|
*/
|
||||||
|
public static Verb getEnum(String name)
|
||||||
|
{
|
||||||
|
return (Verb)getEnum(Verb.class,name);
|
||||||
|
|
||||||
|
} // end getEnum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <CODE>Map</CODE> of <CODE>Verb</CODE> objects by name.
|
||||||
|
*
|
||||||
|
* @return The <CODE>Verb</CODE> object <CODE>Map</CODE>.
|
||||||
|
*/
|
||||||
|
public static Map getEnumMap()
|
||||||
|
{
|
||||||
|
return getEnumMap(Verb.class);
|
||||||
|
|
||||||
|
} // end getEnumMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <CODE>List</CODE> of <CODE>Verb</CODE> objects, in the order in which the objects are listed
|
||||||
|
* in the code above.
|
||||||
|
*
|
||||||
|
* @return The <CODE>Verb</CODE> object <CODE>List</CODE>.
|
||||||
|
*/
|
||||||
|
public static List getEnumList()
|
||||||
|
{
|
||||||
|
return getEnumList(Verb.class);
|
||||||
|
|
||||||
|
} // end getEnumList
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an iterator over all <CODE>Verb</CODE> objects, in the order in which the objects are listed
|
||||||
|
* in the code above.
|
||||||
|
*
|
||||||
|
* @return The <CODE>Verb</CODE> object iterator.
|
||||||
|
*/
|
||||||
|
public static Iterator iterator()
|
||||||
|
{
|
||||||
|
return iterator(Verb.class);
|
||||||
|
|
||||||
|
} // end iterator
|
||||||
|
|
||||||
|
} // end class Verb
|
134
src/dynamo-framework/com/silverwrist/dynamo/WebConstants.java
Normal file
134
src/dynamo-framework/com/silverwrist/dynamo/WebConstants.java
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains the names of various application, session, and request attributes and initialization parameters
|
||||||
|
* used by the Dynamo servlet interface.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public interface WebConstants
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Prefix for all Dynamo-specific application (<CODE>ServletContext</CODE>) attributes.
|
||||||
|
*/
|
||||||
|
public static final String APPLICATION_PREFIX = "com.silverwrist.dynamo.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application attribute that records whether or not logging has been initiated.
|
||||||
|
*/
|
||||||
|
public static final String LOGGING_ATTRIBUTE = APPLICATION_PREFIX + "LoggingStarted";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application attribute that holds the Dynamo
|
||||||
|
* {@link com.silverwrist.dynamo.app.ApplicationContainer ApplicationContainer} object.
|
||||||
|
*/
|
||||||
|
public static final String APPLICATION_ATTRIBUTE = APPLICATION_PREFIX + "app.ApplicationContainer";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application attribute used to store the {@link com.silverwrist.dynamo.iface.MIMETypeMapper MIMETypeMapper}
|
||||||
|
* object created to tap into the servlet container's MIME type maps.
|
||||||
|
*/
|
||||||
|
public static final String SERVLET_MAPPER_ATTRIBUTE = APPLICATION_PREFIX + "servlet.MIMETypeMapper";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Servlet context initialization parameter that tells Dynamo where to find the logging configuration file.
|
||||||
|
*/
|
||||||
|
public static final String LOGGING_INIT_PARAM = "logging.config";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Servlet context initialization parameter that tells Dynamo where to find the Dynamo XML configuration file.
|
||||||
|
*/
|
||||||
|
public static final String CONFIG_INIT_PARAM = "dynamo.config";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prefix for all Dynamo-specific session (<CODE>HttpSession</CODE>) attributes.
|
||||||
|
*/
|
||||||
|
public static final String SESSION_PREFIX = "com.silverwrist.dynamo.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Session attribute used to store the HTTP-specific {@link com.silverwrist.dynamo.iface.SessionInfo SessionInfo}
|
||||||
|
* object.
|
||||||
|
*/
|
||||||
|
public static final String SESSION_PARAM = SESSION_PREFIX + "session";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Session attribute used to store the connection-specific
|
||||||
|
* {@link com.silverwrist.dynamo.iface.BrowserData BrowserData} object.
|
||||||
|
*/
|
||||||
|
public static final String SESSION_BROWSER_DATA_PARAM = SESSION_PREFIX + "browser.data";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prefix for all Dynamo-specific request (<CODE>ServletRequest</CODE>) attributes.
|
||||||
|
*/
|
||||||
|
public static final String REQUEST_PREFIX = "com.silverwrist.dynamo.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request attribute which stores the per-request
|
||||||
|
* {@link com.silverwrist.dynamo.iface.SessionInfoProvider SessionInfoProvider} object.
|
||||||
|
*/
|
||||||
|
public static final String REQUEST_SESSION_PROVIDER_ATTR = REQUEST_PREFIX + "session.provider";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request attribute which contains a reference to a new HTTP session that must be initialized.
|
||||||
|
*/
|
||||||
|
public static final String REQUEST_SESSIONINIT_ATTR = REQUEST_PREFIX + "HTTPsession.init";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request attribute which contains a reference to the connection-specific
|
||||||
|
* {@link com.silverwrist.dynamo.iface.BrowserData BrowserData} object.
|
||||||
|
*/
|
||||||
|
public static final String REQUEST_BROWSER_DATA_ATTR = REQUEST_PREFIX + "browser.data";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request attribute which contains a reference to the set of all cookies currently defined
|
||||||
|
* on the connection.
|
||||||
|
*/
|
||||||
|
public static final String REQUEST_COOKIESET_ATTR = REQUEST_PREFIX + "browser.cookieset";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request attribute containing a list of all new cookies set on the output, which cannot be set until
|
||||||
|
* the start of the output phase.
|
||||||
|
*/
|
||||||
|
public static final String REQUEST_NEWCOOKIEHOLDER_ATTR = REQUEST_PREFIX + "browser.NewCookieHolder";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request attribute containing a list of all new headers set on the output, which cannot be set until
|
||||||
|
* the start of the output phase.
|
||||||
|
*/
|
||||||
|
public static final String REQUEST_NEWHEADERHOLDER_ATTR = REQUEST_PREFIX + "servlet.NewHeaderHolder";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request attribute containing a backreference to the {@link com.silverwrist.dynamo.iface.Request Request}
|
||||||
|
* object for the current request.
|
||||||
|
*/
|
||||||
|
public static final String REQUEST_SELF_ATTR = REQUEST_PREFIX + "request.self";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The HTTP header which requests a page only if it's been modified since a specific time.
|
||||||
|
*/
|
||||||
|
public static final String HDR_IF_MODIFIED_SINCE = "If-Modified-Since";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The HTTP header which returns when a page was last modified.
|
||||||
|
*/
|
||||||
|
public static final String HDR_LAST_MODIFIED = "Last-Modified";
|
||||||
|
|
||||||
|
} // end interface WebConstants
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,27 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
# ---------------------------------------------------------------------------------
|
||||||
|
# This file has been localized for the en_US locale
|
||||||
|
creation.ioError=Unable to read from configuration file {0}.
|
||||||
|
no.classNotFound=The object class {0} was not found.
|
||||||
|
no.createError=Unable to create new object of class {0}.
|
||||||
|
no.notDynamo=The object class {0} is not a valid Dynamo NamedObject,
|
||||||
|
no.notDBPool=The object class {0} is not a valid Dynamo database connection pool.
|
||||||
|
no.notApp=The object class {0} is not a valid Dynamo application.
|
||||||
|
resource.rootErr=The resource root directory {0} does not exist.
|
||||||
|
mountRP.badName=Invalid mount path for resources: {0}
|
||||||
|
mountRP.already=Resource provider already mounted on path {0}.
|
||||||
|
registerRenderer.already=Renderer already registered for class {0}.
|
|
@ -0,0 +1,675 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
class ApplicationServiceManager implements HookServiceProviders
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class implementing initialization services
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class InitServices extends BaseDelegatingServiceProvider
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Constructors
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
InitServices()
|
||||||
|
{
|
||||||
|
super("Initialization Services");
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
InitServices(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
super("Initialization Services",sp);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class BaseDelegatingServiceProvider
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass)
|
||||||
|
{
|
||||||
|
Object rc = m_init_service_cache.get(klass);
|
||||||
|
if (rc!=null) // found in the cache!
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
for (int i=(m_init_service_hooks.size()-1); i>=0; i--)
|
||||||
|
{ // call the hooks
|
||||||
|
try
|
||||||
|
{ // get hooks in reverse order of installation and try them
|
||||||
|
ServiceProvider sp = (ServiceProvider)(m_init_service_hooks.get(i));
|
||||||
|
rc = sp.queryService(klass);
|
||||||
|
m_init_service_cache.put(klass,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // cycle around and keep trying
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
rc = m_init_services.get(klass);
|
||||||
|
if (rc!=null)
|
||||||
|
{ // cache the service
|
||||||
|
m_init_service_cache.put(klass,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
return super.queryService(klass);
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @param serviceid ID for the service to be requested, to further discriminate between requests.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass, String serviceid)
|
||||||
|
{
|
||||||
|
ServiceKey key = new ServiceKey(klass,serviceid);
|
||||||
|
Object rc = m_init_service_cache.get(key);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
for (int i=(m_init_service_hooks.size()-1); i>=0; i--)
|
||||||
|
{ // call the hooks
|
||||||
|
try
|
||||||
|
{ // get hooks in reverse order of installation and try them
|
||||||
|
ServiceProvider sp = (ServiceProvider)(m_init_service_hooks.get(i));
|
||||||
|
rc = sp.queryService(klass,serviceid);
|
||||||
|
m_init_service_cache.put(key,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // cycle around and keep trying
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // call through to superclass
|
||||||
|
return super.queryService(klass,serviceid);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // OK, try it without the service ID
|
||||||
|
rc = queryService(klass);
|
||||||
|
m_init_service_cache.put(key,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
} // end class InitServices
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class implementing runtime services
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class RuntimeServices extends BaseDelegatingServiceProvider
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Constructors
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
RuntimeServices()
|
||||||
|
{
|
||||||
|
super("Application Services");
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
RuntimeServices(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
super("Application Services",sp);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class BaseDelegatingServiceProvider
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass)
|
||||||
|
{
|
||||||
|
Object rc = m_runtime_service_cache.get(klass);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
for (int i=(m_runtime_service_hooks.size()-1); i>=0; i--)
|
||||||
|
{ // call the hooks
|
||||||
|
try
|
||||||
|
{ // get hooks in reverse order of installation and try them
|
||||||
|
ServiceProvider sp = (ServiceProvider)(m_runtime_service_hooks.get(i));
|
||||||
|
rc = sp.queryService(klass);
|
||||||
|
m_runtime_service_cache.put(klass,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // cycle around and keep trying
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
rc = m_runtime_services.get(klass);
|
||||||
|
if (rc!=null)
|
||||||
|
{ // cache the service
|
||||||
|
m_runtime_service_cache.put(klass,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
return super.queryService(klass);
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @param serviceid ID for the service to be requested, to further discriminate between requests.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass, String serviceid)
|
||||||
|
{
|
||||||
|
ServiceKey key = new ServiceKey(klass,serviceid);
|
||||||
|
Object rc = m_runtime_service_cache.get(key);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
for (int i=(m_runtime_service_hooks.size()-1); i>=0; i--)
|
||||||
|
{ // call the hooks
|
||||||
|
try
|
||||||
|
{ // get hooks in reverse order of installation and try them
|
||||||
|
ServiceProvider sp = (ServiceProvider)(m_runtime_service_hooks.get(i));
|
||||||
|
rc = sp.queryService(klass,serviceid);
|
||||||
|
m_runtime_service_cache.put(key,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // cycle around and keep trying
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // call through to superclass
|
||||||
|
return super.queryService(klass,serviceid);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // OK, try it without the service ID
|
||||||
|
rc = queryService(klass);
|
||||||
|
m_runtime_service_cache.put(key,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
} // end class RuntimeServices
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class implementing output services
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class OutputServices extends BaseDelegatingServiceProvider
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Constructors
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
OutputServices()
|
||||||
|
{
|
||||||
|
super("Application Output Services");
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
OutputServices(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
super("Application Output Services",sp);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class BaseDelegatingServiceProvider
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass)
|
||||||
|
{
|
||||||
|
Object rc = m_output_service_cache.get(klass);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
for (int i=(m_output_service_hooks.size()-1); i>=0; i--)
|
||||||
|
{ // call the hooks
|
||||||
|
try
|
||||||
|
{ // get hooks in reverse order of installation and try them
|
||||||
|
ServiceProvider sp = (ServiceProvider)(m_output_service_hooks.get(i));
|
||||||
|
rc = sp.queryService(klass);
|
||||||
|
m_output_service_cache.put(klass,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // cycle around and keep trying
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
rc = m_output_services.get(klass);
|
||||||
|
if (rc!=null)
|
||||||
|
{ // cache the service
|
||||||
|
m_output_service_cache.put(klass,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
return super.queryService(klass);
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @param serviceid ID for the service to be requested, to further discriminate between requests.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass, String serviceid)
|
||||||
|
{
|
||||||
|
ServiceKey key = new ServiceKey(klass,serviceid);
|
||||||
|
Object rc = m_output_service_cache.get(key);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
for (int i=(m_output_service_hooks.size()-1); i>=0; i--)
|
||||||
|
{ // call the hooks
|
||||||
|
try
|
||||||
|
{ // get hooks in reverse order of installation and try them
|
||||||
|
ServiceProvider sp = (ServiceProvider)(m_output_service_hooks.get(i));
|
||||||
|
rc = sp.queryService(klass,serviceid);
|
||||||
|
m_output_service_cache.put(key,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // cycle around and keep trying
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // call through to superclass
|
||||||
|
return super.queryService(klass,serviceid);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // OK, try it without the service ID
|
||||||
|
rc = queryService(klass);
|
||||||
|
m_output_service_cache.put(key,rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
} // end class OutputServices
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class implementing removal of init service hook
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class RemoveInitServiceHook implements ComponentShutdown
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Attributes
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
private ServiceProvider m_sp;
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
RemoveInitServiceHook(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
m_sp = sp;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Implementations from interface ComponentShutdown
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void shutdown()
|
||||||
|
{
|
||||||
|
m_init_service_hooks.remove(m_sp);
|
||||||
|
m_init_service_cache.clear();
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
} // end class RemoveInitServiceHook
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class implementing removal of runtime service hook
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class RemoveRuntimeServiceHook implements ComponentShutdown
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Attributes
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
private ServiceProvider m_sp;
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
RemoveRuntimeServiceHook(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
m_sp = sp;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Implementations from interface ComponentShutdown
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void shutdown()
|
||||||
|
{
|
||||||
|
m_runtime_service_hooks.remove(m_sp);
|
||||||
|
m_runtime_service_cache.clear();
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
} // end class RemoveRuntimeServiceHook
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class implementing removal of output service hook
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class RemoveOutputServiceHook implements ComponentShutdown
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Attributes
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
private ServiceProvider m_sp;
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
RemoveOutputServiceHook(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
m_sp = sp;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Implementations from interface ComponentShutdown
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void shutdown()
|
||||||
|
{
|
||||||
|
m_output_service_hooks.remove(m_sp);
|
||||||
|
m_output_service_cache.clear();
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
} // end class RemoveOutputServiceHook
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static Logger logger = Logger.getLogger(ApplicationServiceManager.class);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Hashtable m_init_services = new Hashtable(); // initializing services
|
||||||
|
private Vector m_init_service_hooks = new Vector(); // hooks for initializing services
|
||||||
|
private Hashtable m_init_service_cache = new Hashtable(); // cache of init services
|
||||||
|
private Hashtable m_runtime_services = new Hashtable(); // runtime services
|
||||||
|
private Vector m_runtime_service_hooks = new Vector(); // hooks for runtime services
|
||||||
|
private Hashtable m_runtime_service_cache = new Hashtable(); // cache of runtime services
|
||||||
|
private Hashtable m_output_services = new Hashtable(); // output services
|
||||||
|
private Vector m_output_service_hooks = new Vector(); // hooks for output services
|
||||||
|
private Hashtable m_output_service_cache = new Hashtable(); // cache of output services
|
||||||
|
private InitServices m_solo_init = null; // only one "null" init service
|
||||||
|
private RuntimeServices m_solo_runtime = null; // only one "null" runtime service
|
||||||
|
private OutputServices m_solo_output = null; // only one "null" output service
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
ApplicationServiceManager()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface HookServiceProviders
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public ServiceProvider getCurrentInitServices()
|
||||||
|
{
|
||||||
|
return createInitServices();
|
||||||
|
|
||||||
|
} // end getCurrentInitServices
|
||||||
|
|
||||||
|
public ServiceProvider getCurrentRuntimeServices()
|
||||||
|
{
|
||||||
|
return createRuntimeServices();
|
||||||
|
|
||||||
|
} // end getCurrentRuntimeServices
|
||||||
|
|
||||||
|
public ServiceProvider getCurrentOutputServices()
|
||||||
|
{
|
||||||
|
return createOutputServices();
|
||||||
|
|
||||||
|
} // end getCurrentOutputServices
|
||||||
|
|
||||||
|
public ComponentShutdown hookInitServiceProvider(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
m_init_service_hooks.add(sp);
|
||||||
|
m_init_service_cache.clear();
|
||||||
|
return new RemoveInitServiceHook(sp);
|
||||||
|
|
||||||
|
} // end hookInitServiceProvider
|
||||||
|
|
||||||
|
public ComponentShutdown hookRuntimeServiceProvider(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
m_runtime_service_hooks.add(sp);
|
||||||
|
m_runtime_service_cache.clear();
|
||||||
|
return new RemoveRuntimeServiceHook(sp);
|
||||||
|
|
||||||
|
} // end hookRuntimeServiceProvider
|
||||||
|
|
||||||
|
public ComponentShutdown hookOutputServiceProvider(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
m_output_service_hooks.add(sp);
|
||||||
|
m_output_service_cache.clear();
|
||||||
|
return new RemoveOutputServiceHook(sp);
|
||||||
|
|
||||||
|
} // end hookOutputServiceProvider
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
void addInitService(Class klass, Object svc)
|
||||||
|
{
|
||||||
|
m_init_services.put(klass,svc);
|
||||||
|
|
||||||
|
} // end addInitService
|
||||||
|
|
||||||
|
void addRuntimeService(Class klass, Object svc)
|
||||||
|
{
|
||||||
|
m_runtime_services.put(klass,svc);
|
||||||
|
|
||||||
|
} // end addRuntimeService
|
||||||
|
|
||||||
|
void addOutputService(Class klass, Object svc)
|
||||||
|
{
|
||||||
|
m_output_services.put(klass,svc);
|
||||||
|
|
||||||
|
} // end addRuntimeService
|
||||||
|
|
||||||
|
ServiceProvider createInitServices()
|
||||||
|
{
|
||||||
|
if (m_solo_init==null)
|
||||||
|
m_solo_init = new InitServices();
|
||||||
|
return m_solo_init;
|
||||||
|
|
||||||
|
} // end createInitServices
|
||||||
|
|
||||||
|
ServiceProvider createInitServices(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
if (sp==null)
|
||||||
|
return createInitServices();
|
||||||
|
return new InitServices(sp);
|
||||||
|
|
||||||
|
} // end createRuntimeServices
|
||||||
|
|
||||||
|
ServiceProvider createRuntimeServices()
|
||||||
|
{
|
||||||
|
if (m_solo_runtime==null)
|
||||||
|
m_solo_runtime = new RuntimeServices();
|
||||||
|
return m_solo_runtime;
|
||||||
|
|
||||||
|
} // end createRuntimeServices
|
||||||
|
|
||||||
|
ServiceProvider createRuntimeServices(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
if (sp==null)
|
||||||
|
return createRuntimeServices();
|
||||||
|
return new RuntimeServices(sp);
|
||||||
|
|
||||||
|
} // end createRuntimeServices
|
||||||
|
|
||||||
|
ServiceProvider createOutputServices()
|
||||||
|
{
|
||||||
|
if (m_solo_output==null)
|
||||||
|
m_solo_output = new OutputServices();
|
||||||
|
return m_solo_output;
|
||||||
|
|
||||||
|
} // end createOutputServices
|
||||||
|
|
||||||
|
ServiceProvider createOutputServices(ServiceProvider sp)
|
||||||
|
{
|
||||||
|
if (sp==null)
|
||||||
|
return createOutputServices();
|
||||||
|
return new OutputServices(sp);
|
||||||
|
|
||||||
|
} // end createOutputServices
|
||||||
|
|
||||||
|
} // end class ApplicationServiceManager
|
|
@ -0,0 +1,490 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class used internally by the {@link com.silverwrist.dynamo.app.ApplicationContainer ApplicationContainer}
|
||||||
|
* to handle background execution of tasks. It implements the
|
||||||
|
* {@link com.silverwrist.dynamo.iface.BackgroundScheduler BackgroundScheduler} service.
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
class BackgroundProcessor implements BackgroundScheduler, ComponentShutdown
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal thread class for scheduling normal-priority background tasks
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class NormalPriorityThread extends Thread
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
NormalPriorityThread(int index)
|
||||||
|
{
|
||||||
|
super("BG-Normal-" + index);
|
||||||
|
setPriority(NORM_PRIORITY);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class Thread
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
while (m_running)
|
||||||
|
{ // get tasks then execute them
|
||||||
|
BackgroundTask task = null;
|
||||||
|
synchronized (m_normal_sync)
|
||||||
|
{ // test and remove from normal queue
|
||||||
|
boolean get_task = true;
|
||||||
|
while (get_task && m_normal_queue.isEmpty())
|
||||||
|
{ // nothing to run right now...
|
||||||
|
try
|
||||||
|
{ // sleep waiting for a new background task
|
||||||
|
m_normal_sync.wait();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{ // don't bother getting a task
|
||||||
|
get_task = false;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
if (get_task)
|
||||||
|
task = (BackgroundTask)(m_normal_queue.removeFirst());
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
if (task!=null)
|
||||||
|
{ // found a task to run, now execute it
|
||||||
|
try
|
||||||
|
{ // run the task
|
||||||
|
task.run(m_services);
|
||||||
|
task = null;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (Exception e)
|
||||||
|
{ // whoops! don't let this stop us
|
||||||
|
logger.warn("BackgroundTask threw exception",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end run
|
||||||
|
|
||||||
|
} // end class NormalPriorityThread
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal thread class for scheduling low-priority background tasks
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class LowPriorityThread extends Thread
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
LowPriorityThread(int index)
|
||||||
|
{
|
||||||
|
super("BG-Low-" + index);
|
||||||
|
setPriority(MIN_PRIORITY);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class Thread
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
while (m_running)
|
||||||
|
{ // get tasks then execute them
|
||||||
|
BackgroundTask task = null;
|
||||||
|
synchronized (m_lp_sync)
|
||||||
|
{ // test and remove from normal queue
|
||||||
|
boolean get_task = true;
|
||||||
|
while (get_task && m_lp_queue.isEmpty())
|
||||||
|
{ // nothing to run right now...
|
||||||
|
try
|
||||||
|
{ // sleep waiting for a new background task
|
||||||
|
m_lp_sync.wait();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{ // don't bother getting a task
|
||||||
|
get_task = false;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
// Get the task we waited for.
|
||||||
|
if (get_task)
|
||||||
|
task = (BackgroundTask)(m_lp_queue.removeFirst());
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
if (task!=null)
|
||||||
|
{ // found a task to run, now execute it
|
||||||
|
try
|
||||||
|
{ // run the task
|
||||||
|
task.run(m_services);
|
||||||
|
task = null;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (Exception e)
|
||||||
|
{ // whoops! don't let this stop us
|
||||||
|
logger.warn("BackgroundTask threw exception",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end run
|
||||||
|
|
||||||
|
} // end class LowPriorityThread
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class for timer operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class MyTimerTask extends TimerTask implements ComponentShutdown
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Attributes
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
private BackgroundTask m_task;
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
MyTimerTask(BackgroundTask task)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
m_task = task;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class TimerTask
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // run the task
|
||||||
|
m_task.run(m_services);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (Exception e)
|
||||||
|
{ // whoops! don't let this stop us
|
||||||
|
logger.warn("BackgroundTask threw exception",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end run
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Implementations from interface ComponentShutdown
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts down the component associated with this interface, in a component-specific manner.
|
||||||
|
*/
|
||||||
|
public void shutdown()
|
||||||
|
{
|
||||||
|
cancel();
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
} // end class MyTimerTask
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static Logger logger = Logger.getLogger(BackgroundProcessor.class);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private ServiceProvider m_services;
|
||||||
|
private volatile boolean m_running = true;
|
||||||
|
private Object m_normal_sync = new Object();
|
||||||
|
private LinkedList m_normal_queue = new LinkedList();
|
||||||
|
private Thread[] m_normal_threads;
|
||||||
|
private Object m_lp_sync = new Object();
|
||||||
|
private LinkedList m_lp_queue = new LinkedList();
|
||||||
|
private Thread[] m_lp_threads;
|
||||||
|
private Timer m_timer;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs the instance of the <CODE>BackgroundProcessor</CODE> internal to the
|
||||||
|
* {@link com.silverwrist.dynamo.app.ApplicationContainer ApplicationContainer}.
|
||||||
|
*
|
||||||
|
* @param num_normal_threads Number of "normal" threads in our runtime thread pool.
|
||||||
|
* @param num_lp_threads Number of "low priority" threads in our runtime thread pool.
|
||||||
|
* @param services The {@link com.silverwrist.dynamo.iface.ServiceProvider ServiceProvider} to be supplied
|
||||||
|
* to all {@link com.silverwrist.dynamo.iface.BackgroundTask BackgroundTask}s.
|
||||||
|
*/
|
||||||
|
BackgroundProcessor(int num_norm_threads, int num_lp_threads, ServiceProvider services)
|
||||||
|
{
|
||||||
|
m_services = new SingletonServiceProvider("BackgroundProcessor",services,BackgroundScheduler.class,this);
|
||||||
|
|
||||||
|
// Create the normal priority background threads.
|
||||||
|
m_normal_threads = new Thread[num_norm_threads];
|
||||||
|
int i;
|
||||||
|
for (i=0; i<num_norm_threads; i++)
|
||||||
|
m_normal_threads[i] = new NormalPriorityThread(i);
|
||||||
|
|
||||||
|
// Create the low priority background threads.
|
||||||
|
m_lp_threads = new Thread[num_lp_threads];
|
||||||
|
for (i=0; i<num_lp_threads; i++)
|
||||||
|
m_lp_threads[i] = new LowPriorityThread(i);
|
||||||
|
|
||||||
|
// Create the timer.
|
||||||
|
m_timer = new Timer();
|
||||||
|
|
||||||
|
// Start everything up.
|
||||||
|
for (i=0; i<num_norm_threads; i++)
|
||||||
|
m_normal_threads[i].start();
|
||||||
|
for (i=0; i<num_lp_threads; i++)
|
||||||
|
m_lp_threads[i].start();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface BackgroundScheduler
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a task to be run "later," i.e., at any time after the present time, without interrupting the
|
||||||
|
* current thread's processing. Background processing of tasks submitted by this method are handled by a
|
||||||
|
* pool of threads.
|
||||||
|
*
|
||||||
|
* @param task The task to be scheduled to run later.
|
||||||
|
* @param low_priority If this is <CODE>true</CODE>, the task is handled by a pool of low-priority threads
|
||||||
|
* instead of by a pool of normal-priority threads. Low-priority threads will generally
|
||||||
|
* execute only after normal-priority threads, but are not guaranteed to.
|
||||||
|
*/
|
||||||
|
public void runTaskLater(BackgroundTask task, boolean low_priority)
|
||||||
|
{
|
||||||
|
if (low_priority)
|
||||||
|
{ // add to low priority queue
|
||||||
|
synchronized (m_lp_sync)
|
||||||
|
{ // add item and notify a thread to wake up
|
||||||
|
m_lp_queue.addLast(task);
|
||||||
|
m_lp_sync.notify();
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // add to normal queue
|
||||||
|
synchronized (m_normal_sync)
|
||||||
|
{ // add item and notify a thread to wake up
|
||||||
|
m_normal_queue.addLast(task);
|
||||||
|
m_normal_sync.notify();
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
} // end runTaskLater
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a task to be run on a one-shot basis after a delay.
|
||||||
|
*
|
||||||
|
* @param task The task to be scheduled to run.
|
||||||
|
* @param delay The delay, in milliseconds, before this task is to be run. The actual delay may be longer
|
||||||
|
* than this.
|
||||||
|
* @return An instance of a {@link com.silverwrist.dynamo.iface.ComponentShutdown ComponentShutdown} object,
|
||||||
|
* whose {@link com.silverwrist.dynamo.iface.ComponentShutdown#shutdown() shutdown()} method may be
|
||||||
|
* called to abort the execution of this task at any time before it is actually run. If this is called
|
||||||
|
* after the task is run, it has no effect.
|
||||||
|
*/
|
||||||
|
public ComponentShutdown runTaskAfter(BackgroundTask task, long delay)
|
||||||
|
{
|
||||||
|
MyTimerTask my_task = new MyTimerTask(task);
|
||||||
|
m_timer.schedule(my_task,delay);
|
||||||
|
return my_task;
|
||||||
|
|
||||||
|
} // end runTaskAfter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a task to be run on a one-shot basis at a certain time.
|
||||||
|
*
|
||||||
|
* @param task The task to be scheduled to run.
|
||||||
|
* @param when The date/time at which the task is to be run. The actual task start time may be any time
|
||||||
|
* after this.
|
||||||
|
* @return An instance of a {@link com.silverwrist.dynamo.iface.ComponentShutdown ComponentShutdown} object,
|
||||||
|
* whose {@link com.silverwrist.dynamo.iface.ComponentShutdown#shutdown() shutdown()} method may be
|
||||||
|
* called to abort the execution of this task at any time before it is actually run. If this is called
|
||||||
|
* after the task is run, it has no effect.
|
||||||
|
*/
|
||||||
|
public ComponentShutdown runTaskAt(BackgroundTask task, Date when)
|
||||||
|
{
|
||||||
|
MyTimerTask my_task = new MyTimerTask(task);
|
||||||
|
m_timer.schedule(my_task,when);
|
||||||
|
return my_task;
|
||||||
|
|
||||||
|
} // end runTaskAt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a task to be run periodically, after a delay.
|
||||||
|
*
|
||||||
|
* @param task The task to be scheduled to run.
|
||||||
|
* @param delay The delay, in milliseconds, before this task is to be run for the first time. The actual
|
||||||
|
* delay may be longer than this.
|
||||||
|
* @param period The time, in milliseconds, between successive executions of the task. The task will be
|
||||||
|
* scheduled for repeated execution, delaying at least this long between executions.
|
||||||
|
* @return An instance of a {@link com.silverwrist.dynamo.iface.ComponentShutdown ComponentShutdown} object,
|
||||||
|
* whose {@link com.silverwrist.dynamo.iface.ComponentShutdown#shutdown() shutdown()} method may be
|
||||||
|
* called to abort the periodic execution of this task at any time.
|
||||||
|
*/
|
||||||
|
public ComponentShutdown runTaskPeriodic(BackgroundTask task, long delay, long period)
|
||||||
|
{
|
||||||
|
MyTimerTask my_task = new MyTimerTask(task);
|
||||||
|
m_timer.schedule(my_task,delay,period);
|
||||||
|
return my_task;
|
||||||
|
|
||||||
|
} // end runTaskPeriodic
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a task to be run periodically, beginning at a specified time.
|
||||||
|
*
|
||||||
|
* @param task The task to be scheduled to run.
|
||||||
|
* @param when The date/time at which the task is to be run for the first time. The actual task start time
|
||||||
|
* may be any time after this.
|
||||||
|
* @param period The time, in milliseconds, between successive executions of the task. The task will be
|
||||||
|
* scheduled for repeated execution, delaying at least this long between executions.
|
||||||
|
* @return An instance of a {@link com.silverwrist.dynamo.iface.ComponentShutdown ComponentShutdown} object,
|
||||||
|
* whose {@link com.silverwrist.dynamo.iface.ComponentShutdown#shutdown() shutdown()} method may be
|
||||||
|
* called to abort the periodic execution of this task at any time.
|
||||||
|
*/
|
||||||
|
public ComponentShutdown runTaskPeriodic(BackgroundTask task, Date start, long period)
|
||||||
|
{
|
||||||
|
MyTimerTask my_task = new MyTimerTask(task);
|
||||||
|
m_timer.schedule(my_task,start,period);
|
||||||
|
return my_task;
|
||||||
|
|
||||||
|
} // end runTaskPeriodic
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a task to be run periodically, after a delay.
|
||||||
|
*
|
||||||
|
* @param task The task to be scheduled to run.
|
||||||
|
* @param delay The delay, in milliseconds, before this task is to be run for the first time. The actual
|
||||||
|
* delay may be longer than this.
|
||||||
|
* @param period The time, in milliseconds, between successive executions of the task. The task will be
|
||||||
|
* scheduled for repeated execution, with the task being started with roughly this many
|
||||||
|
* milliseconds between each start attempt. If execution is delayed, this task will try to
|
||||||
|
* "catch up" by scheduling executions more frequently.
|
||||||
|
* @return An instance of a {@link com.silverwrist.dynamo.iface.ComponentShutdown ComponentShutdown} object,
|
||||||
|
* whose {@link com.silverwrist.dynamo.iface.ComponentShutdown#shutdown() shutdown()} method may be
|
||||||
|
* called to abort the periodic execution of this task at any time.
|
||||||
|
*/
|
||||||
|
public ComponentShutdown runTaskFixedRate(BackgroundTask task, long delay, long period)
|
||||||
|
{
|
||||||
|
MyTimerTask my_task = new MyTimerTask(task);
|
||||||
|
m_timer.scheduleAtFixedRate(my_task,delay,period);
|
||||||
|
return my_task;
|
||||||
|
|
||||||
|
} // end runTaskFixedRate
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a task to be run periodically, beginning at a specified time.
|
||||||
|
*
|
||||||
|
* @param task The task to be scheduled to run.
|
||||||
|
* @param when The date/time at which the task is to be run for the first time. The actual task start time
|
||||||
|
* may be any time after this.
|
||||||
|
* @param period The time, in milliseconds, between successive executions of the task. The task will be
|
||||||
|
* scheduled for repeated execution, with the task being started with roughly this many
|
||||||
|
* milliseconds between each start attempt. If execution is delayed, this task will try to
|
||||||
|
* "catch up" by scheduling executions more frequently.
|
||||||
|
* @return An instance of a {@link com.silverwrist.dynamo.iface.ComponentShutdown ComponentShutdown} object,
|
||||||
|
* whose {@link com.silverwrist.dynamo.iface.ComponentShutdown#shutdown() shutdown()} method may be
|
||||||
|
* called to abort the periodic execution of this task at any time.
|
||||||
|
*/
|
||||||
|
public ComponentShutdown runTaskFixedRate(BackgroundTask task, Date start, long period)
|
||||||
|
{
|
||||||
|
MyTimerTask my_task = new MyTimerTask(task);
|
||||||
|
m_timer.scheduleAtFixedRate(my_task,start,period);
|
||||||
|
return my_task;
|
||||||
|
|
||||||
|
} // end runTaskFixedRate
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ComponentShutdown
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts down the <CODE>BackgroundProcessor</CODE>, stopping all its associated threads and tasks.
|
||||||
|
*/
|
||||||
|
public void shutdown()
|
||||||
|
{
|
||||||
|
m_timer.cancel();
|
||||||
|
m_running = false;
|
||||||
|
int i;
|
||||||
|
for (i=0; i<m_normal_threads.length; i++)
|
||||||
|
m_normal_threads[i].interrupt();
|
||||||
|
for (i=0; i<m_lp_threads.length; i++)
|
||||||
|
m_lp_threads[i].interrupt();
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
} // end class BackgroundProcessor
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import com.silverwrist.util.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
|
||||||
|
class ComponentResName
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String[] m_components;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
ComponentResName(String resource_path)
|
||||||
|
{
|
||||||
|
if (!(resource_path.startsWith("/")))
|
||||||
|
throw new NoSuchResourceException(resource_path);
|
||||||
|
m_components = StringUtils.split(resource_path.substring(1),"/");
|
||||||
|
if ((m_components==null) || (m_components.length==0))
|
||||||
|
throw new NoSuchResourceException(resource_path);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class Object
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if ((obj==null) || !(obj instanceof ComponentResName))
|
||||||
|
return false;
|
||||||
|
ComponentResName other = (ComponentResName)obj;
|
||||||
|
if (m_components.length!=other.m_components.length)
|
||||||
|
return false;
|
||||||
|
return (getMatchCount(other)==m_components.length);
|
||||||
|
|
||||||
|
} // end equals
|
||||||
|
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
for (int i=0; i<m_components.length; i++)
|
||||||
|
rc ^= m_components[i].hashCode();
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end hashCode
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return getStringValue(0,true);
|
||||||
|
|
||||||
|
} // end toString
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
int getComponentCount()
|
||||||
|
{
|
||||||
|
return m_components.length;
|
||||||
|
|
||||||
|
} // end getComponentCount
|
||||||
|
|
||||||
|
int getMatchCount(ComponentResName other)
|
||||||
|
{
|
||||||
|
int max_count = Math.min(other.m_components.length,m_components.length);
|
||||||
|
for (int i=0; i<max_count; i++)
|
||||||
|
{ // if a component does not match, return the count immediately
|
||||||
|
if (!(m_components[i].equals(other.m_components[i])))
|
||||||
|
return i;
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
return max_count; // all components matched
|
||||||
|
|
||||||
|
} // end getMatchCount
|
||||||
|
|
||||||
|
String getStringValue(int skip_initial, boolean prefix_slash)
|
||||||
|
{
|
||||||
|
StringBuffer rc = new StringBuffer();
|
||||||
|
if (prefix_slash)
|
||||||
|
rc.append('/');
|
||||||
|
boolean need_sep = false;
|
||||||
|
for (int i=skip_initial; i<m_components.length; i++)
|
||||||
|
{ // append together components
|
||||||
|
if (need_sep)
|
||||||
|
rc.append('/');
|
||||||
|
else
|
||||||
|
need_sep = true;
|
||||||
|
rc.append(m_components[i]);
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
return rc.toString();
|
||||||
|
|
||||||
|
} // end getStringValue
|
||||||
|
|
||||||
|
} // end class ComponentResName
|
|
@ -0,0 +1,221 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import org.w3c.dom.*;
|
||||||
|
import com.silverwrist.util.xml.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
|
||||||
|
public class ConnectionManager implements NamedObject, ComponentInitialize, ComponentShutdown
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal class implementing the initialization service hook
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class InitService implements ServiceProvider, ConnectionFrontEnd, ConnectionBackEnd
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
InitService()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Implementations from interface ServiceProvider
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass)
|
||||||
|
{
|
||||||
|
if (klass==ConnectionFrontEnd.class)
|
||||||
|
return (ConnectionFrontEnd)this;
|
||||||
|
if (klass==ConnectionBackEnd.class)
|
||||||
|
return (ConnectionBackEnd)this;
|
||||||
|
throw new NoSuchServiceException("ConnectionManager.InitService",klass);
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @param serviceid ID for the service to be requested, to further discriminate between requests.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass, String serviceid)
|
||||||
|
{
|
||||||
|
if (klass==ConnectionFrontEnd.class)
|
||||||
|
return (ConnectionFrontEnd)this;
|
||||||
|
if (klass==ConnectionBackEnd.class)
|
||||||
|
return (ConnectionBackEnd)this;
|
||||||
|
throw new NoSuchServiceException("ConnectionManager.InitService",klass,serviceid);
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Implementations from interface ConnectionFrontEnd
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Object getInterface(String connection_point, Class expected_class) throws ConfigException
|
||||||
|
{
|
||||||
|
return getConnectionPoint(connection_point).getInterface(expected_class);
|
||||||
|
|
||||||
|
} // end getInterface
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Implementations from interface ConnectionBackEnd
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void connectObject(String connection_point, Object object) throws ConfigException
|
||||||
|
{
|
||||||
|
getConnectionPoint(connection_point).connectObject(object);
|
||||||
|
|
||||||
|
} // end connectObject
|
||||||
|
|
||||||
|
} // end class InitService
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String m_name;
|
||||||
|
private Hashtable m_connection_points = new Hashtable();
|
||||||
|
private ComponentShutdown m_shutdown_hook;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public ConnectionManager()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private final ConnectionPoint getConnectionPoint(String name) throws ConfigException
|
||||||
|
{
|
||||||
|
ConnectionPoint rc = (ConnectionPoint)(m_connection_points.get(name));
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
ConfigException ce = new ConfigException(ConnectionPoint.class,"ConnectionMessages","cpoint.notFound");
|
||||||
|
ce.setParameter(0,name);
|
||||||
|
throw ce;
|
||||||
|
|
||||||
|
} // end getConnectionPoint
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface NamedObject
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
|
||||||
|
} // end getName
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ComponentInitialize
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void initialize(Element config_root, ServiceProvider services) throws ConfigException
|
||||||
|
{
|
||||||
|
XMLLoader loader = XMLLoader.get();
|
||||||
|
try
|
||||||
|
{ // verify the right node name
|
||||||
|
loader.verifyNodeName(config_root,"object");
|
||||||
|
|
||||||
|
// get the object's name
|
||||||
|
m_name = loader.getAttribute(config_root,"name");
|
||||||
|
|
||||||
|
// get the connection points list and try to load them
|
||||||
|
List l = loader.getMatchingSubElements(config_root,"connection-point");
|
||||||
|
Iterator it = l.iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{ // create the connection points
|
||||||
|
Element elt = (Element)(it.next());
|
||||||
|
ConnectionPoint cpoint = new ConnectionPoint(elt);
|
||||||
|
m_connection_points.put(cpoint.getName(),cpoint);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (XMLLoadException e)
|
||||||
|
{ // error loading XML config data
|
||||||
|
throw new ConfigException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
// Hook the init service provider to provide our services.
|
||||||
|
HookServiceProviders hooker = (HookServiceProviders)(services.queryService(HookServiceProviders.class));
|
||||||
|
m_shutdown_hook = hooker.hookInitServiceProvider(new InitService());
|
||||||
|
|
||||||
|
} // end initialize
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ComponentShutdown
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void shutdown()
|
||||||
|
{
|
||||||
|
m_shutdown_hook.shutdown();
|
||||||
|
|
||||||
|
Iterator it = m_connection_points.values().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{ // shut down those connection points
|
||||||
|
ComponentShutdown cs = (ComponentShutdown)(it.next());
|
||||||
|
cs.shutdown();
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
m_connection_points.clear();
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
} // end class ConnectionManager
|
|
@ -0,0 +1,23 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
# ---------------------------------------------------------------------------------
|
||||||
|
# This file has been localized for the en_US locale
|
||||||
|
cpoint.noInterface=Unable to find the connection point interface class "{0}".
|
||||||
|
cpoint.notValid=The connection point class "{0}" is not a valid interface.
|
||||||
|
iface.type=Connection point "{0}"'s interface type {1} cannot be assigned to the desired type {2}.
|
||||||
|
connect.already=The connection point "{0}" has already been connected.
|
||||||
|
connect.wrongType=The connection point "{0}" expects to connect to an object of type {1}.
|
||||||
|
cpoint.notFound=No connection point "{0}" defined.
|
|
@ -0,0 +1,179 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
import org.w3c.dom.*;
|
||||||
|
import com.silverwrist.util.xml.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
|
||||||
|
class ConnectionPoint implements NamedObject, InvocationHandler, ComponentShutdown
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String m_name; // name of this connection point
|
||||||
|
private Class m_interface; // interface associated with this connection point
|
||||||
|
private Object m_proxy_obj; // proxy object that provides the "head end" of the cpoint
|
||||||
|
private Object m_target_obj = null; // object on the "tail end" of the cpoint
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
ConnectionPoint(Element config) throws ConfigException
|
||||||
|
{
|
||||||
|
XMLLoader loader = XMLLoader.get();
|
||||||
|
String iface_name = null;
|
||||||
|
try
|
||||||
|
{ // verify the right node name
|
||||||
|
loader.verifyNodeName(config,"connection-point");
|
||||||
|
|
||||||
|
// get the connection point's name
|
||||||
|
m_name = loader.getAttribute(config,"name");
|
||||||
|
|
||||||
|
// get the interface represented by this proxy
|
||||||
|
iface_name = loader.getAttribute(config,"interface");
|
||||||
|
m_interface = Class.forName(iface_name);
|
||||||
|
if (!(m_interface.isInterface()))
|
||||||
|
{ // the class name does not specify an interface
|
||||||
|
ConfigException ce = new ConfigException(ConnectionPoint.class,"ConnectionMessages",
|
||||||
|
"cpoint.notValid");
|
||||||
|
ce.setParameter(0,iface_name);
|
||||||
|
throw ce;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
// Create the proxy object.
|
||||||
|
Class[] arg = new Class[1];
|
||||||
|
arg[0] = m_interface;
|
||||||
|
m_proxy_obj = Proxy.newProxyInstance(m_interface.getClassLoader(),arg,this);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (XMLLoadException e)
|
||||||
|
{ // error loading XML config data
|
||||||
|
throw new ConfigException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (ClassNotFoundException e)
|
||||||
|
{ // unable to find the interface
|
||||||
|
ConfigException ce = new ConfigException(ConnectionPoint.class,"ConnectionMessages",
|
||||||
|
"cpoint.noInterface",e);
|
||||||
|
ce.setParameter(0,iface_name);
|
||||||
|
throw ce;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface NamedObject
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
|
||||||
|
} // end getName
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface InvocationHandler
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
|
||||||
|
{
|
||||||
|
if (m_target_obj==null)
|
||||||
|
throw new ProxyException(new NullPointerException("target not yet connected for " + m_name + "/"
|
||||||
|
+ m_interface.getName()));
|
||||||
|
try
|
||||||
|
{ // invoke the method on the real target!
|
||||||
|
return method.invoke(m_target_obj,args);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IllegalAccessException e)
|
||||||
|
{ // turn into the runtime ProxyException
|
||||||
|
throw new ProxyException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (InvocationTargetException e)
|
||||||
|
{ // "unwrap" this exception type and throw it
|
||||||
|
throw e.getCause();
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end invoke
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ComponentShutdown
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void shutdown()
|
||||||
|
{
|
||||||
|
m_proxy_obj = null;
|
||||||
|
m_target_obj = null;
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
Object getInterface(Class expected_class) throws ConfigException
|
||||||
|
{
|
||||||
|
if (expected_class.isAssignableFrom(m_interface))
|
||||||
|
return m_proxy_obj;
|
||||||
|
ConfigException ce = new ConfigException(ConnectionPoint.class,"ConnectionMessages","iface.type");
|
||||||
|
ce.setParameter(0,m_name);
|
||||||
|
ce.setParameter(1,m_interface.getName());
|
||||||
|
ce.setParameter(2,expected_class.getName());
|
||||||
|
throw ce;
|
||||||
|
|
||||||
|
} // end getInterface
|
||||||
|
|
||||||
|
synchronized void connectObject(Object obj) throws ConfigException
|
||||||
|
{
|
||||||
|
if (m_target_obj!=null)
|
||||||
|
{ // this connection point has already been connected
|
||||||
|
ConfigException ce = new ConfigException(ConnectionPoint.class,"ConnectionMessages","connect.already");
|
||||||
|
ce.setParameter(0,m_name);
|
||||||
|
throw ce;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
if (!(m_interface.isInstance(obj)))
|
||||||
|
{ // the object is of the wrong type
|
||||||
|
ConfigException ce = new ConfigException(ConnectionPoint.class,"ConnectionMessages","connect.wrongType");
|
||||||
|
ce.setParameter(0,m_name);
|
||||||
|
ce.setParameter(1,m_interface.getName());
|
||||||
|
throw ce;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
m_target_obj = obj;
|
||||||
|
|
||||||
|
} // end connectObject
|
||||||
|
|
||||||
|
} // end class ConnectionPoint
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import com.silverwrist.util.*;
|
||||||
|
import com.silverwrist.dynamo.except.RenderingException;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
|
||||||
|
class DataItemRenderer implements BinaryRenderer
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
DataItemRenderer()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface BinaryRenderer
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void render(Object obj, BinaryRenderControl control) throws IOException, RenderingException
|
||||||
|
{
|
||||||
|
DataItem di = (DataItem)obj;
|
||||||
|
control.setContentType(di.getMimeType());
|
||||||
|
control.setContentLength(di.getSize());
|
||||||
|
OutputStream stm = control.getStream();
|
||||||
|
IOUtils.copy(di.getDataStream(),stm);
|
||||||
|
stm.flush();
|
||||||
|
|
||||||
|
} // end render
|
||||||
|
|
||||||
|
} // end class DataItemRenderer
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import com.silverwrist.util.xml.*;
|
||||||
|
|
||||||
|
class HeapContents implements Comparable
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
Element m_elt; // element we're sorting
|
||||||
|
int m_priority; // its priority
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
HeapContents(Element elt) throws XMLLoadException
|
||||||
|
{
|
||||||
|
m_elt = elt;
|
||||||
|
m_priority = XMLLoader.get().getAttributeInt(elt,"priority",0);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class Object
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (!(o instanceof HeapContents))
|
||||||
|
return false;
|
||||||
|
HeapContents other = (HeapContents)o;
|
||||||
|
return (m_priority==other.m_priority);
|
||||||
|
|
||||||
|
} // end equals
|
||||||
|
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return m_priority;
|
||||||
|
|
||||||
|
} // end hashCode
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface Comparable
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int compareTo(Object o)
|
||||||
|
{
|
||||||
|
HeapContents other = (HeapContents)o; // may throw ClassCastException
|
||||||
|
return m_priority - other.m_priority;
|
||||||
|
|
||||||
|
} // end compareTo
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
Element getElement()
|
||||||
|
{
|
||||||
|
return m_elt;
|
||||||
|
|
||||||
|
} // end getElement
|
||||||
|
|
||||||
|
} // end class HeapContents
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.dynamo.except.RenderingException;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
|
||||||
|
class ListRenderer implements TextRenderer
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
ListRenderer()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface TextRenderer
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void render(Object obj, TextRenderControl control) throws IOException, RenderingException
|
||||||
|
{
|
||||||
|
List list = (List)obj;
|
||||||
|
Iterator it = list.iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
control.renderSubObject(it.next());
|
||||||
|
|
||||||
|
} // end render
|
||||||
|
|
||||||
|
} // end class ListRenderer
|
|
@ -0,0 +1,270 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import java.text.*;
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.util.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
class PropertySerializationSupport implements PropertySerializer, PropertySerializerRegistration
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static final Map SIMPLE_TYPE_SERIALIZE;
|
||||||
|
|
||||||
|
private static final DateFormat s_iso8601;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static Vector m_extern_calls = new Vector();
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
PropertySerializationSupport()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private final String builtinSerialize(Object value)
|
||||||
|
{
|
||||||
|
String prefix = (String)(SIMPLE_TYPE_SERIALIZE.get(value.getClass()));
|
||||||
|
if (prefix!=null)
|
||||||
|
return prefix + value.toString();
|
||||||
|
|
||||||
|
if (value instanceof Boolean)
|
||||||
|
return (((Boolean)value).booleanValue() ? "Y" : "Z");
|
||||||
|
|
||||||
|
if (value instanceof java.util.Date)
|
||||||
|
return "T" + s_iso8601.format((java.util.Date)value);
|
||||||
|
|
||||||
|
if (value instanceof TimeZone)
|
||||||
|
return "_TZ:" + ((TimeZone)value).getID();
|
||||||
|
|
||||||
|
if (value instanceof Language)
|
||||||
|
return "_LANG:" + ((Language)value).getCode();
|
||||||
|
|
||||||
|
if (value instanceof Country)
|
||||||
|
return "_CTRY:" + ((Country)value).getCode();
|
||||||
|
|
||||||
|
if (value instanceof OptionSet)
|
||||||
|
return "_OS:" + ((OptionSet)value).asString();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end builtInSerialize
|
||||||
|
|
||||||
|
private final Object extendedDecode(String s)
|
||||||
|
{
|
||||||
|
if (s.startsWith("_LOC:"))
|
||||||
|
{ // need to break down
|
||||||
|
s = s.substring(5);
|
||||||
|
int p = s.indexOf('_');
|
||||||
|
if (p>=0)
|
||||||
|
{ // language + country, maybe + variant
|
||||||
|
String language = s.substring(0,p);
|
||||||
|
s = s.substring(p+1);
|
||||||
|
p = s.indexOf('_');
|
||||||
|
if (p>=0)
|
||||||
|
return new Locale(language,s.substring(0,p),s.substring(p+1));
|
||||||
|
else
|
||||||
|
return new Locale(language,s);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else // just language
|
||||||
|
return new Locale(s);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else if (s.startsWith("_TZ:"))
|
||||||
|
return TimeZone.getTimeZone(s.substring(4));
|
||||||
|
else if (s.startsWith("_LANG:"))
|
||||||
|
return International.get().getLanguageForCode(s.substring(6));
|
||||||
|
else if (s.startsWith("_CTRY:"))
|
||||||
|
return International.get().getCountryForCode(s.substring(6));
|
||||||
|
else if (s.startsWith("_OS:"))
|
||||||
|
return new OptionSet(s.substring(4));
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end extendedDecode
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface PropertySerializer
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String serializeProperty(Object value)
|
||||||
|
{
|
||||||
|
if (value==null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String rc = builtinSerialize(value);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
Iterator it = m_extern_calls.iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{ // try the external serializers
|
||||||
|
PropertySerializer psz = (PropertySerializer)(it.next());
|
||||||
|
rc = psz.serializeProperty(value);
|
||||||
|
if (rc!=null)
|
||||||
|
return "." + rc;
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
return null; // cannot serialize
|
||||||
|
|
||||||
|
} // end serializeProperty
|
||||||
|
|
||||||
|
public Object deserializeProperty(String value)
|
||||||
|
{
|
||||||
|
if (value==null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // the first character is the flag...
|
||||||
|
switch (value.charAt(0))
|
||||||
|
{
|
||||||
|
case 'B':
|
||||||
|
return new Byte(value.substring(1));
|
||||||
|
|
||||||
|
case 'C':
|
||||||
|
return new Character(value.charAt(1));
|
||||||
|
|
||||||
|
case 'D':
|
||||||
|
return new Double(value.substring(1));
|
||||||
|
|
||||||
|
case 'F':
|
||||||
|
return new Float(value.substring(1));
|
||||||
|
|
||||||
|
case 'I':
|
||||||
|
return new Integer(value.substring(1));
|
||||||
|
|
||||||
|
case 'J':
|
||||||
|
return new Long(value.substring(1));
|
||||||
|
|
||||||
|
case 'S':
|
||||||
|
return new Short(value.substring(1));
|
||||||
|
|
||||||
|
case 'T':
|
||||||
|
return s_iso8601.parse(value.substring(1));
|
||||||
|
|
||||||
|
case 'Y':
|
||||||
|
return Boolean.TRUE;
|
||||||
|
|
||||||
|
case 'Z':
|
||||||
|
return Boolean.FALSE;
|
||||||
|
|
||||||
|
case '!':
|
||||||
|
return value.substring(1);
|
||||||
|
|
||||||
|
case '_':
|
||||||
|
return extendedDecode(value);
|
||||||
|
|
||||||
|
case '.':
|
||||||
|
{ // run through the external decoders
|
||||||
|
String s = value.substring(1);
|
||||||
|
Iterator it = m_extern_calls.iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{ // try the external serializers
|
||||||
|
PropertySerializer psz = (PropertySerializer)(it.next());
|
||||||
|
Object rc = psz.deserializeProperty(s);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end case
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
} // end switch
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (ParseException e)
|
||||||
|
{ // if we threw this, we're h0s3d anyway
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} // end deserializeProperty
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface PropertySerializerRegistration
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public ComponentShutdown registerPropertySerializer(PropertySerializer psz)
|
||||||
|
{
|
||||||
|
m_extern_calls.add(psz);
|
||||||
|
return new ShutdownVectorRemove(m_extern_calls,psz);
|
||||||
|
|
||||||
|
} // end registerPropertySerializer
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static initializer
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
HashMap tmp = new HashMap();
|
||||||
|
tmp.put(Byte.class,"B");
|
||||||
|
tmp.put(Byte.TYPE,"B");
|
||||||
|
tmp.put(Character.class,"C");
|
||||||
|
tmp.put(Character.TYPE,"C");
|
||||||
|
tmp.put(Double.class,"D");
|
||||||
|
tmp.put(Double.TYPE,"D");
|
||||||
|
tmp.put(Float.class,"F");
|
||||||
|
tmp.put(Float.TYPE,"F");
|
||||||
|
tmp.put(Integer.class,"I");
|
||||||
|
tmp.put(Integer.TYPE,"I");
|
||||||
|
tmp.put(Long.class,"J");
|
||||||
|
tmp.put(Long.TYPE,"J");
|
||||||
|
tmp.put(Short.class,"S");
|
||||||
|
tmp.put(Short.TYPE,"S");
|
||||||
|
tmp.put(String.class,"!");
|
||||||
|
tmp.put(StringBuffer.class,"!");
|
||||||
|
tmp.put(Locale.class,"_LOC:");
|
||||||
|
SIMPLE_TYPE_SERIALIZE = Collections.unmodifiableMap(tmp);
|
||||||
|
|
||||||
|
SimpleDateFormat iso = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
|
||||||
|
iso.setCalendar(new GregorianCalendar(new SimpleTimeZone(0,"UTC")));
|
||||||
|
s_iso8601 = iso;
|
||||||
|
|
||||||
|
} // end static initializer
|
||||||
|
|
||||||
|
} // end class PropertySerializationSupport
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import org.w3c.dom.*;
|
||||||
|
import com.silverwrist.util.xml.*;
|
||||||
|
|
||||||
|
public class RewriteRule
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String m_name;
|
||||||
|
private boolean m_encode;
|
||||||
|
private String m_template;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
RewriteRule(Element elt) throws XMLLoadException
|
||||||
|
{
|
||||||
|
XMLLoader loader = XMLLoader.get();
|
||||||
|
m_name = loader.getAttribute(elt,"type").trim().toUpperCase();
|
||||||
|
m_encode = loader.getAttributeBoolean(elt,"encode");
|
||||||
|
m_template = loader.getText(elt);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Public getters
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
|
||||||
|
} // end getName
|
||||||
|
|
||||||
|
public boolean getEncode()
|
||||||
|
{
|
||||||
|
return m_encode;
|
||||||
|
|
||||||
|
} // end getEncode
|
||||||
|
|
||||||
|
public String getTemplate()
|
||||||
|
{
|
||||||
|
return m_template;
|
||||||
|
|
||||||
|
} // end getTemplate
|
||||||
|
|
||||||
|
} // end class RewriteRule
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
class ServiceKey
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Class m_class;
|
||||||
|
private String m_serviceid;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
ServiceKey(Class klass, String serviceid)
|
||||||
|
{
|
||||||
|
m_class = klass;
|
||||||
|
m_serviceid = serviceid;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class Object
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if ((obj==null) || !(obj instanceof ServiceKey))
|
||||||
|
return false;
|
||||||
|
ServiceKey other = (ServiceKey)obj;
|
||||||
|
return (m_class==other.m_class) && m_serviceid.equals(other.m_serviceid);
|
||||||
|
|
||||||
|
} // end equals
|
||||||
|
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return m_class.hashCode() ^ m_serviceid.hashCode();
|
||||||
|
|
||||||
|
} // end hashCode
|
||||||
|
|
||||||
|
} // end class ServiceKey
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.app;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import com.silverwrist.dynamo.except.NoSuchResourceException;
|
||||||
|
import com.silverwrist.dynamo.iface.ResourceProvider;
|
||||||
|
|
||||||
|
class WrappedResourceProvider
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private ComponentResName m_mount_point;
|
||||||
|
private ResourceProvider m_provider;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
WrappedResourceProvider(ComponentResName mount_point, ResourceProvider provider)
|
||||||
|
{
|
||||||
|
m_mount_point = mount_point;
|
||||||
|
m_provider = provider;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class Object
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if ((obj==null) || !(obj instanceof WrappedResourceProvider))
|
||||||
|
return false;
|
||||||
|
WrappedResourceProvider other = (WrappedResourceProvider)obj;
|
||||||
|
return m_mount_point.equals(other.m_mount_point);
|
||||||
|
|
||||||
|
} // end equals
|
||||||
|
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return m_mount_point.hashCode();
|
||||||
|
|
||||||
|
} // end hashCode
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
int getMatchCount(ComponentResName crn)
|
||||||
|
{
|
||||||
|
int rc = m_mount_point.getMatchCount(crn);
|
||||||
|
if (rc!=m_mount_point.getComponentCount())
|
||||||
|
return -1;
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end getMatchCount
|
||||||
|
|
||||||
|
InputStream getResource(ComponentResName crn) throws IOException
|
||||||
|
{
|
||||||
|
if (m_mount_point.getMatchCount(crn)!=m_mount_point.getComponentCount())
|
||||||
|
throw new NoSuchResourceException(crn.getStringValue(0,true));
|
||||||
|
return m_provider.getResource(crn.getStringValue(m_mount_point.getComponentCount(),true));
|
||||||
|
|
||||||
|
} // end getResource
|
||||||
|
|
||||||
|
long getResourceModTime(ComponentResName crn)
|
||||||
|
{
|
||||||
|
if (m_mount_point.getMatchCount(crn)!=m_mount_point.getComponentCount())
|
||||||
|
return 0;
|
||||||
|
return m_provider.getResourceModTime(crn.getStringValue(m_mount_point.getComponentCount(),true));
|
||||||
|
|
||||||
|
} // end getResourceModTime
|
||||||
|
|
||||||
|
} // end class WrappedResourceProvider
|
||||||
|
|
|
@ -0,0 +1,141 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
import java.sql.*;
|
||||||
|
import com.silverwrist.util.*;
|
||||||
|
import com.silverwrist.dynamo.iface.DBUtilities;
|
||||||
|
|
||||||
|
abstract class DBUtilitiesImpl implements DBUtilities
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static final Class[] ARGS_TYPE = new Class[0];
|
||||||
|
private static final Object[] ARGS = new Object[0];
|
||||||
|
|
||||||
|
private static final String SQL_WILDCARD_CHARS = "%_'";
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected DBUtilitiesImpl()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface DBUtilities
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String encodeString(String data)
|
||||||
|
{
|
||||||
|
if (data==null)
|
||||||
|
return null; // safety feature
|
||||||
|
int ndx = data.indexOf('\'');
|
||||||
|
if (ndx<0)
|
||||||
|
return data;
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
while (ndx>=0)
|
||||||
|
{ // convert each single quote mark to a pair of them
|
||||||
|
if (ndx>0)
|
||||||
|
buf.append(data.substring(0,ndx));
|
||||||
|
buf.append("''");
|
||||||
|
data = data.substring(ndx+1);
|
||||||
|
ndx = data.indexOf('\'');
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
buf.append(data);
|
||||||
|
return buf.toString();
|
||||||
|
|
||||||
|
} // end encodeString
|
||||||
|
|
||||||
|
public String encodeStringWildcards(String data)
|
||||||
|
{
|
||||||
|
if (data==null)
|
||||||
|
return null; // safety feature
|
||||||
|
AnyCharMatcher nhc = new AnyCharMatcher(SQL_WILDCARD_CHARS);
|
||||||
|
int ndx = nhc.get(data);
|
||||||
|
if (ndx<0)
|
||||||
|
return data; // trivial short-circuit case
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
while (ndx>=0)
|
||||||
|
{ // append the matched "head" and then the encoded character
|
||||||
|
if (ndx>0)
|
||||||
|
buf.append(data.substring(0,ndx));
|
||||||
|
switch (data.charAt(ndx++))
|
||||||
|
{
|
||||||
|
case '%':
|
||||||
|
buf.append("\\%");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '_':
|
||||||
|
buf.append("\\_");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\'':
|
||||||
|
buf.append("\'\'");
|
||||||
|
break;
|
||||||
|
|
||||||
|
} // end switch
|
||||||
|
|
||||||
|
if (ndx==data.length())
|
||||||
|
return buf.toString(); // munched the entire string - all done!
|
||||||
|
data = data.substring(ndx);
|
||||||
|
ndx = nhc.get(data);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
buf.append(data); // append the unmatched tail
|
||||||
|
return buf.toString();
|
||||||
|
|
||||||
|
} // end encodeStringWildcards
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Abstract declarations from interface DBUtilities
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public abstract java.util.Date getDateTime(ResultSet rs, String column) throws SQLException;
|
||||||
|
|
||||||
|
public abstract java.util.Date getDateTime(ResultSet rs, int column) throws SQLException;
|
||||||
|
|
||||||
|
public abstract void setDateTime(PreparedStatement stmt, int index, java.util.Date date) throws SQLException;
|
||||||
|
|
||||||
|
public abstract void testDatabase(Connection conn) throws SQLException;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static DBUtilities get(String type) throws Exception
|
||||||
|
{
|
||||||
|
String impl_class_name = DBUtilitiesImpl.class.getName() + "_" + type.toLowerCase();
|
||||||
|
Method m = Class.forName(impl_class_name).getMethod("get",ARGS_TYPE);
|
||||||
|
return (DBUtilities)(m.invoke(null,ARGS));
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
} // end class DBUtilitiesImpl
|
|
@ -0,0 +1,201 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.util.SQLUtils;
|
||||||
|
import com.silverwrist.dynamo.iface.DBUtilities;
|
||||||
|
|
||||||
|
public class DBUtilitiesImpl_mysql extends DBUtilitiesImpl
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static DBUtilitiesImpl_mysql _self = null;
|
||||||
|
|
||||||
|
// used to convert dates and times to UTC for sending to SQL
|
||||||
|
private static SimpleTimeZone utc = new SimpleTimeZone(0,"UTC");
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private DBUtilitiesImpl_mysql()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a date-and-time string (an SQL DATETIME value) to a standard Java date.
|
||||||
|
*
|
||||||
|
* @param dstr The date-and-time string to convert, presumed to be in UTC.
|
||||||
|
* @return The converted date and time.
|
||||||
|
* @exception java.sql.SQLException The date and time string was in an invalid format.
|
||||||
|
*/
|
||||||
|
private static final java.util.Date convertDateTimeString(String dstr) throws SQLException
|
||||||
|
{
|
||||||
|
if (dstr==null)
|
||||||
|
return null; // null values are the same
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // do almost the reverse process of formatting it into a string
|
||||||
|
GregorianCalendar cal = new GregorianCalendar(utc);
|
||||||
|
cal.set(Calendar.YEAR,Integer.parseInt(dstr.substring(0,4)));
|
||||||
|
cal.set(Calendar.MONTH,Integer.parseInt(dstr.substring(5,7)) - 1 + Calendar.JANUARY);
|
||||||
|
cal.set(Calendar.DAY_OF_MONTH,Integer.parseInt(dstr.substring(8,10)));
|
||||||
|
cal.set(Calendar.HOUR_OF_DAY,Integer.parseInt(dstr.substring(11,13)));
|
||||||
|
cal.set(Calendar.MINUTE,Integer.parseInt(dstr.substring(14,16)));
|
||||||
|
cal.set(Calendar.SECOND,Integer.parseInt(dstr.substring(17,19)));
|
||||||
|
return cal.getTime();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NumberFormatException e)
|
||||||
|
{ // the NumberFormatException becomes an SQLException
|
||||||
|
throw new SQLException("invalid DATETIME field format");
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end convertDateString
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a date as an SQL date/time string, expressed in UTC.
|
||||||
|
*
|
||||||
|
* @param d The date to be encoded.
|
||||||
|
* @return The string equivalent of that date.
|
||||||
|
*/
|
||||||
|
private static final String encodeDate(java.util.Date d)
|
||||||
|
{
|
||||||
|
// Break down the date as a UTC value.
|
||||||
|
GregorianCalendar cal = new GregorianCalendar(utc);
|
||||||
|
cal.setTime(d);
|
||||||
|
|
||||||
|
// Create the two string buffers converting the date.
|
||||||
|
StringBuffer rc = new StringBuffer();
|
||||||
|
StringBuffer conv = new StringBuffer();
|
||||||
|
String c;
|
||||||
|
|
||||||
|
// Encode the year first.
|
||||||
|
conv.append("0000").append(cal.get(Calendar.YEAR));
|
||||||
|
c = conv.toString();
|
||||||
|
rc.append(c.substring(c.length()-4)).append('-');
|
||||||
|
|
||||||
|
// Now the month...
|
||||||
|
conv.setLength(0);
|
||||||
|
conv.append("00").append(cal.get(Calendar.MONTH) - Calendar.JANUARY + 1);
|
||||||
|
c = conv.toString();
|
||||||
|
rc.append(c.substring(c.length()-2)).append('-');
|
||||||
|
|
||||||
|
// And the day...
|
||||||
|
conv.setLength(0);
|
||||||
|
conv.append("00").append(cal.get(Calendar.DAY_OF_MONTH));
|
||||||
|
c = conv.toString();
|
||||||
|
rc.append(c.substring(c.length()-2)).append(' ');
|
||||||
|
|
||||||
|
// And the hour...
|
||||||
|
conv.setLength(0);
|
||||||
|
conv.append("00").append(cal.get(Calendar.HOUR_OF_DAY));
|
||||||
|
c = conv.toString();
|
||||||
|
rc.append(c.substring(c.length()-2)).append(':');
|
||||||
|
|
||||||
|
// And the minute...
|
||||||
|
conv.setLength(0);
|
||||||
|
conv.append("00").append(cal.get(Calendar.MINUTE));
|
||||||
|
c = conv.toString();
|
||||||
|
rc.append(c.substring(c.length()-2)).append(':');
|
||||||
|
|
||||||
|
// And the second...
|
||||||
|
conv.setLength(0);
|
||||||
|
conv.append("00").append(cal.get(Calendar.SECOND));
|
||||||
|
c = conv.toString();
|
||||||
|
rc.append(c.substring(c.length()-2));
|
||||||
|
|
||||||
|
// This is the resulting date/time value.
|
||||||
|
return rc.toString();
|
||||||
|
|
||||||
|
} // end encodeDate
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Abstract implementations from class DBUtilitiesImpl
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public java.util.Date getDateTime(ResultSet rs, String column) throws SQLException
|
||||||
|
{
|
||||||
|
return convertDateTimeString(rs.getString(column));
|
||||||
|
|
||||||
|
} // end getDateTime
|
||||||
|
|
||||||
|
public java.util.Date getDateTime(ResultSet rs, int column) throws SQLException
|
||||||
|
{
|
||||||
|
return convertDateTimeString(rs.getString(column));
|
||||||
|
|
||||||
|
} // end getDateTime
|
||||||
|
|
||||||
|
public void setDateTime(PreparedStatement stmt, int index, java.util.Date date) throws SQLException
|
||||||
|
{
|
||||||
|
stmt.setString(index,encodeDate(date));
|
||||||
|
|
||||||
|
} // end setDateTime
|
||||||
|
|
||||||
|
public void testDatabase(Connection conn) throws SQLException
|
||||||
|
{
|
||||||
|
Statement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // execute a simple SQL statement
|
||||||
|
stmt = conn.createStatement();
|
||||||
|
rs = stmt.executeQuery("SELECT 1;");
|
||||||
|
if (!rs.next())
|
||||||
|
throw new SQLException("MySQL database test failed(1)");
|
||||||
|
if (rs.getInt(1)!=1)
|
||||||
|
throw new SQLException("MySQL database test failed(2)");
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
finally
|
||||||
|
{ // close down statement and result set
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end testDatabase
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static DBUtilities get()
|
||||||
|
{
|
||||||
|
if (_self==null)
|
||||||
|
_self = new DBUtilitiesImpl_mysql();
|
||||||
|
return _self;
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
} // end class DBUtilitiesImpl_mysql
|
|
@ -0,0 +1,652 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.w3c.dom.*;
|
||||||
|
import com.silverwrist.util.xml.*;
|
||||||
|
import com.silverwrist.dynamo.Namespaces;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple pooling system for JDBC connections, which allows connections to be kept in a pool until
|
||||||
|
* they're needed, avoiding the overhead of opening and closing connections for each transaction, or
|
||||||
|
* keeping one database connection open for each user.<P>
|
||||||
|
* Based on some code from Marty Hall's <EM>Core Servlets and Java Server Pages</EM> (Prentice Hall/
|
||||||
|
* Sun Microsystems, 2000).
|
||||||
|
*
|
||||||
|
* @author Eric J. Bowersox <erbo@silcom.com>
|
||||||
|
* @version X
|
||||||
|
*/
|
||||||
|
public class DatabaseConnectionPool implements DBConnectionPool, ComponentInitialize, ComponentShutdown
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal background thread object
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private class BackgroundThread extends Thread
|
||||||
|
{
|
||||||
|
/*====================================================================
|
||||||
|
* Constructor
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
BackgroundThread()
|
||||||
|
{
|
||||||
|
super("DatabaseConnectionPool_bkgd_" + (s_thread_counter++));
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*====================================================================
|
||||||
|
* Overrides from class Thread
|
||||||
|
*====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // attempt to create another connection in the background
|
||||||
|
Connection c = makeNewConnection();
|
||||||
|
synchronized (DatabaseConnectionPool.this)
|
||||||
|
{ // we've got a new available connection - let everyone know
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("created new connection in the background");
|
||||||
|
m_avail_connections.addElement(c);
|
||||||
|
m_pending = false;
|
||||||
|
DatabaseConnectionPool.this.notifyAll();
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (Exception e)
|
||||||
|
{ // caught an SQLException or an OutOfMemory exception
|
||||||
|
logger.warn("background connection thread caught exception",e);
|
||||||
|
// ditch this new connection and wait until an existing one frees up
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end run
|
||||||
|
|
||||||
|
} // end BackgroundThread
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static Logger logger = Logger.getLogger(DatabaseConnectionPool.class);
|
||||||
|
|
||||||
|
private static final Map INFER_TYPE_MAP; // used to infer database type from JDBC driver classname
|
||||||
|
|
||||||
|
private static int s_thread_counter = 1; // counter for data pool threads
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String m_name; // name of connection pool
|
||||||
|
private String m_dbtype; // database type
|
||||||
|
private String m_driver; // name of JDBC driver class
|
||||||
|
private String m_url; // URL for JDBC connection
|
||||||
|
private String m_username; // username for JDBC connection
|
||||||
|
private String m_password; // password for JDBC connection
|
||||||
|
private int m_max_conns; // maximum number of possible connections
|
||||||
|
private boolean m_wait_if_busy; // do we wait for a connection if none is available?
|
||||||
|
private boolean m_pending = false; // pending connection being created?
|
||||||
|
private Vector m_avail_connections = null; // connections which are available for use
|
||||||
|
private Vector m_busy_connections = null; // connections which are currently in use
|
||||||
|
private DBUtilities m_util_object; // utilities object
|
||||||
|
private PropertySerializer m_psz; // property serializer object
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new <CODE>DatabaseCOnnectionPool</CODE> object. Commonly called at initialization time,
|
||||||
|
* when the objects are created from the Dynamo XML configuration file.
|
||||||
|
*/
|
||||||
|
public DatabaseConnectionPool()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a standard database exception.
|
||||||
|
*
|
||||||
|
* @param message The message ID from the "DatabaseMessages" bundle to load.
|
||||||
|
* @return The new exception object.
|
||||||
|
*/
|
||||||
|
private static final DatabaseException newException(String message)
|
||||||
|
{
|
||||||
|
return new DatabaseException(DatabaseConnectionPool.class,"DatabaseMessages",message);
|
||||||
|
|
||||||
|
} // end newException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a standard database exception.
|
||||||
|
*
|
||||||
|
* @param message The message ID from the "DatabaseMessages" bundle to load.
|
||||||
|
* @param inner The exception to wrap in the new
|
||||||
|
* {@link com.silverwrist.dynamo.except.DatabaseException DatabaseException} object.
|
||||||
|
* @return The new exception object.
|
||||||
|
*/
|
||||||
|
private static final DatabaseException newException(String message, Throwable inner)
|
||||||
|
{
|
||||||
|
return new DatabaseException(DatabaseConnectionPool.class,"DatabaseMessages",message,inner);
|
||||||
|
|
||||||
|
} // end newException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes all database connections in the specified vector.
|
||||||
|
*
|
||||||
|
* @param vconn Vector of connections to be closed.
|
||||||
|
*/
|
||||||
|
private static final void closeConnections(Vector vconn)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("closeConnections(" + vconn.size() + " to be closed)");
|
||||||
|
|
||||||
|
for (int i=0; i<vconn.size(); i++)
|
||||||
|
{ // loop over the entire vector
|
||||||
|
try
|
||||||
|
{ // take each connection and close it
|
||||||
|
Connection c = (Connection)(vconn.get(i));
|
||||||
|
if (!(c.isClosed()))
|
||||||
|
c.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // what do we care, this connection is dying anyhow
|
||||||
|
logger.warn("got a SQLException in closeConnections (ignored): " + e.getMessage());
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
} // end closeConnections
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and returns a new database connection.
|
||||||
|
*
|
||||||
|
* @return The new database connection object.
|
||||||
|
* @exception com.silverwrist.dynamo.except.DatabaseException An error prevented the creation
|
||||||
|
* of the connection.
|
||||||
|
*/
|
||||||
|
private final Connection makeNewConnection() throws DatabaseException
|
||||||
|
{
|
||||||
|
if (m_busy_connections==null)
|
||||||
|
throw newException("dbx.notInitialized");
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // make the connection and return it
|
||||||
|
Class.forName(m_driver).newInstance(); // preload driver class
|
||||||
|
// the newInstance() call above is to work around some broken Java implementations
|
||||||
|
return DriverManager.getConnection(m_url,m_username,m_password);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (ClassNotFoundException e)
|
||||||
|
{ // convert a ClassNotFoundException to a nicer DatabaseException
|
||||||
|
logger.error("JDBC driver class \"" + m_driver + "\" not found",e);
|
||||||
|
DatabaseException d = newException("dbx.classNotFound");
|
||||||
|
d.setParameter(0,m_driver);
|
||||||
|
throw d;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (IllegalAccessException e2)
|
||||||
|
{ // convert this to a nicer DatabaseException
|
||||||
|
logger.fatal("Can't access \"" + m_driver + "\" constructor",e2);
|
||||||
|
DatabaseException d = newException("dbx.illegalAccess");
|
||||||
|
d.setParameter(0,m_driver);
|
||||||
|
throw d;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (InstantiationException e3)
|
||||||
|
{ // convert this to a nicer DatabaseException
|
||||||
|
logger.fatal("Can't create instance of \"" + m_driver + "\"",e3);
|
||||||
|
DatabaseException d = newException("dbx.instantiation");
|
||||||
|
d.setParameter(0,m_driver);
|
||||||
|
throw d;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (SQLException e4)
|
||||||
|
{ // convert this to a DatabaseException, too
|
||||||
|
logger.fatal("Can't create database connection",e4);
|
||||||
|
throw newException("dbx.sqlMakeNewConn",e4);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end makeNewConnection
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spins off a background thread to create a new database connection.
|
||||||
|
*/
|
||||||
|
private final void makeBackgroundConnection()
|
||||||
|
{
|
||||||
|
m_pending = true;
|
||||||
|
try
|
||||||
|
{ // spin off the connection attempt to the background
|
||||||
|
BackgroundThread thrd = new BackgroundThread();
|
||||||
|
thrd.start();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (OutOfMemoryError e)
|
||||||
|
{ // give up on new connection
|
||||||
|
logger.warn("memory failure spinning off background-connect thread");
|
||||||
|
m_pending = false;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end makeBackgroundConnection
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface NamedObject
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of this object.
|
||||||
|
*
|
||||||
|
* @return The name of this object.
|
||||||
|
*/
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
|
||||||
|
} // end getName
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ServiceProvider
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass)
|
||||||
|
{
|
||||||
|
if (klass==DBUtilities.class)
|
||||||
|
return m_util_object;
|
||||||
|
if (klass==PropertySerializer.class)
|
||||||
|
return m_psz;
|
||||||
|
if (klass==DBConnectionPool.class)
|
||||||
|
return (DBConnectionPool)this;
|
||||||
|
throw new NoSuchServiceException("DatabaseConnectionPool",klass);
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @param serviceid ID for the service to be requested, to further discriminate between requests.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass, String serviceid)
|
||||||
|
{
|
||||||
|
return this.queryService(klass);
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface DBConnectionPool
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a simple string identifying the database type. This is commonly used in database operations
|
||||||
|
* classes to create classnames that are dynamically loaded.
|
||||||
|
*
|
||||||
|
* @return The database identifier.
|
||||||
|
*/
|
||||||
|
public String getDatabaseType()
|
||||||
|
{
|
||||||
|
return m_dbtype;
|
||||||
|
|
||||||
|
} // end getDatabaseType
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of connections currently being managed by this connection pool.
|
||||||
|
*
|
||||||
|
* @return The number of connections currently being managed by this connection pool.
|
||||||
|
*/
|
||||||
|
public int numConnections()
|
||||||
|
{
|
||||||
|
if (m_busy_connections==null)
|
||||||
|
return 0;
|
||||||
|
int rc = m_avail_connections.size() + m_busy_connections.size();
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("numConnections() => " + rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end numConnections
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains a database connection object from the connection pool.
|
||||||
|
*
|
||||||
|
* @return The <CODE>Connection</CODE> object.
|
||||||
|
* @exception com.silverwrist.dynamo.except.DatabaseException If a connection could not be obtained.
|
||||||
|
*/
|
||||||
|
public synchronized Connection getConnection() throws DatabaseException
|
||||||
|
{
|
||||||
|
if (m_busy_connections==null)
|
||||||
|
throw newException("dbx.notInitialized");
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{ // loop until we get a connection or throw an exception
|
||||||
|
if (m_avail_connections.isEmpty())
|
||||||
|
{ // no connections available - we may need to make a new one
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("no connections available - looking to get one");
|
||||||
|
if ((numConnections() < m_max_conns) && !m_pending)
|
||||||
|
makeBackgroundConnection(); // try to create a new connection
|
||||||
|
else if (!m_wait_if_busy)
|
||||||
|
{ // don't want to wait? tough, we're h0sed!
|
||||||
|
logger.error("exhausted maximum connection limit (" + m_max_conns + ")");
|
||||||
|
throw newException("dbx.connectionLimit");
|
||||||
|
|
||||||
|
} // end else if
|
||||||
|
|
||||||
|
// Wait for the background connect attempt to finish, or for
|
||||||
|
// someone to return a connection.
|
||||||
|
try
|
||||||
|
{ // park the thread here until we know what's up
|
||||||
|
wait();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{ // do nothing
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
// now fall through the loop and try again
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // pull the last connection off the available list...
|
||||||
|
int ndx = m_avail_connections.size() - 1;
|
||||||
|
Connection rc = (Connection)(m_avail_connections.elementAt(ndx));
|
||||||
|
m_avail_connections.removeElementAt(ndx);
|
||||||
|
try
|
||||||
|
{ // see if this is a good connection or not...
|
||||||
|
if (rc.isClosed())
|
||||||
|
{ // this connection is closed - discard it, and notify any waiters that a slot
|
||||||
|
// has opened up
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("discarding closed connection");
|
||||||
|
notifyAll();
|
||||||
|
rc = null;
|
||||||
|
// fall out to the end of the loop and try again
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // this connection is OK - return it
|
||||||
|
m_busy_connections.addElement(rc);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // if isClosed() throws a SQLException, the connection is somehow broken
|
||||||
|
logger.warn("connection is borked, discarding",e);
|
||||||
|
notifyAll();
|
||||||
|
rc = null;
|
||||||
|
// fall out to the end of the loop and try again
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end else (at least one connection available)
|
||||||
|
|
||||||
|
} // end for (ever)
|
||||||
|
|
||||||
|
} // end getConnection
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a database connection object to the connection pool.
|
||||||
|
*
|
||||||
|
* @param conn The <CODE>Connection</CODE> object to be released.
|
||||||
|
* @exception com.silverwrist.dynamo.except.DatabaseException If there was an error returning the connection.
|
||||||
|
*/
|
||||||
|
public synchronized void releaseConnection(Connection conn) throws DatabaseException
|
||||||
|
{
|
||||||
|
if (m_busy_connections==null)
|
||||||
|
throw newException("dbx.notInitialized");
|
||||||
|
|
||||||
|
if (conn!=null)
|
||||||
|
{ // move from one vector to another
|
||||||
|
m_busy_connections.removeElement(conn);
|
||||||
|
m_avail_connections.addElement(conn);
|
||||||
|
notifyAll(); // wake up! Got a new connection for you!
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end releaseConnection
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ComponentInitialize
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the database connection.
|
||||||
|
*
|
||||||
|
* @param config_root Pointer to the <dbconnection/> section of the Dynamo XML configuration file that
|
||||||
|
* configures this database connection. This is to be considered "read-only" by the component.
|
||||||
|
* @param services An implementation of {@link com.silverwrist.dynamo.iface.ServiceProvider ServiceProvider}
|
||||||
|
* which provides initialization services to the component. This will include an implementation
|
||||||
|
* of {@link com.silverwrist.dynamo.iface.ObjectProvider ObjectProvider} which may be used to
|
||||||
|
* get information about other objects previously initialized by the application.
|
||||||
|
* @exception com.silverwrist.dynamo.except.ConfigException If an error is encountered in the component
|
||||||
|
* configuration.
|
||||||
|
*/
|
||||||
|
public void initialize(Element config_root, ServiceProvider services) throws ConfigException
|
||||||
|
{
|
||||||
|
XMLLoader loader = XMLLoader.get();
|
||||||
|
try
|
||||||
|
{ // verify the right node name
|
||||||
|
loader.verifyNodeName(config_root,"dbconnection");
|
||||||
|
|
||||||
|
// get the object's name
|
||||||
|
m_name = loader.getAttribute(config_root,"name");
|
||||||
|
|
||||||
|
// get the various settings
|
||||||
|
DOMElementHelper h = new DOMElementHelper(config_root);
|
||||||
|
m_dbtype = h.getSubElementText("dbtype");
|
||||||
|
if (logger.isDebugEnabled() && (m_dbtype!=null))
|
||||||
|
logger.debug("DatabaseConnectionPool specified database type: " + m_dbtype);
|
||||||
|
|
||||||
|
m_driver = loader.getSubElementText(h,"driver");
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("DatabaseConnectionPool driver: " + m_driver);
|
||||||
|
|
||||||
|
// If the database type is not known, try to infer it from the driver name.
|
||||||
|
if (m_dbtype==null)
|
||||||
|
m_dbtype = (String)(INFER_TYPE_MAP.get(m_driver));
|
||||||
|
if (m_dbtype==null)
|
||||||
|
{ // wasn't specified, can't infer it - we are HOSED!
|
||||||
|
ConfigException ce = new ConfigException(DatabaseConnectionPool.class,"DatabaseMessages",
|
||||||
|
"config.inferType");
|
||||||
|
ce.setParameter(0,m_driver);
|
||||||
|
throw ce;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else if (logger.isDebugEnabled())
|
||||||
|
logger.debug("DatabaseConnectionPool inferred database type: " + m_dbtype);
|
||||||
|
|
||||||
|
m_url = loader.getSubElementText(h,"uri");
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("DatabaseConnectionPool URI: " + m_url);
|
||||||
|
|
||||||
|
m_username = loader.getSubElementText(h,"username");
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("DatabaseConnectionPool user name: " + m_username);
|
||||||
|
|
||||||
|
m_password = loader.getSubElementText(h,"password");
|
||||||
|
|
||||||
|
Element elt = loader.getSubElement(h,"connections");
|
||||||
|
int initial_conn = loader.getAttributeInt(elt,"initial",0);
|
||||||
|
if (initial_conn<0)
|
||||||
|
throw new ConfigException(DatabaseConnectionPool.class,"DatabaseMessages","config.initialConn");
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("DatabaseConnectionPool initial connections: " + initial_conn);
|
||||||
|
|
||||||
|
m_max_conns = loader.getAttributeInt(elt,"max");
|
||||||
|
if (m_max_conns<0)
|
||||||
|
throw new ConfigException(DatabaseConnectionPool.class,"DatabaseMessages","config.maxConn");
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("DatabaseConnectionPool maximum connections: " + m_max_conns);
|
||||||
|
|
||||||
|
m_wait_if_busy = loader.getAttributeBoolean(elt,"busywait",true);
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("DatabaseConnectionPool wait if busy: " + m_wait_if_busy);
|
||||||
|
|
||||||
|
if (initial_conn>m_max_conns)
|
||||||
|
{ // fix initial value if above maximum
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
logger.debug("N.B.: reducing configured initial connections");
|
||||||
|
initial_conn = m_max_conns;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // get the appropriate utilities object
|
||||||
|
m_util_object = DBUtilitiesImpl.get(m_dbtype);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
catch (Exception e)
|
||||||
|
{ // the utilities are not implemented
|
||||||
|
ConfigException ce = new ConfigException(DatabaseConnectionPool.class,"DatabaseMessages",
|
||||||
|
"utils.impl",e);
|
||||||
|
ce.setParameter(0,m_dbtype);
|
||||||
|
throw ce;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
// Get the master property serializer so we can offer it as a service.
|
||||||
|
m_psz = (PropertySerializer)(services.queryService(PropertySerializer.class));
|
||||||
|
|
||||||
|
// Create the vectors that hold connections.
|
||||||
|
m_avail_connections = new Vector(initial_conn);
|
||||||
|
m_busy_connections = new Vector();
|
||||||
|
|
||||||
|
// Populate the "available connection" vector.
|
||||||
|
for (int i=0; i<initial_conn; i++)
|
||||||
|
m_avail_connections.addElement(makeNewConnection());
|
||||||
|
|
||||||
|
// See if we need to test the database.
|
||||||
|
boolean do_test = false;
|
||||||
|
elt = h.getSubElement("initialize");
|
||||||
|
if (elt!=null)
|
||||||
|
do_test = loader.getAttributeBoolean(elt,"test",false);
|
||||||
|
if (do_test)
|
||||||
|
{ // database must be tested
|
||||||
|
Connection conn = null;
|
||||||
|
try
|
||||||
|
{ // get connection and test it
|
||||||
|
conn = this.getConnection();
|
||||||
|
m_util_object.testDatabase(conn);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate SQL exception into ConfigException
|
||||||
|
ConfigException ce = new ConfigException(DatabaseConnectionPool.class,"DatabaseMessages","dbx.testfail",e);
|
||||||
|
ce.setParameter(0,m_name);
|
||||||
|
ce.setParameter(1,m_url);
|
||||||
|
ce.setParameter(2,e.getMessage());
|
||||||
|
throw ce;
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // release the connection we got
|
||||||
|
this.releaseConnection(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end if (testing database)
|
||||||
|
|
||||||
|
logger.info("DatabaseConnectionPool initialized");
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (XMLLoadException e)
|
||||||
|
{ // error loading XML config data
|
||||||
|
throw new ConfigException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
catch (DatabaseException e)
|
||||||
|
{ // error creating initial connections
|
||||||
|
throw new ConfigException(DatabaseConnectionPool.class,"DatabaseMessages","config.create",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end initialize
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ComponentShutdown
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts down the database connection, closing all cached <CODE>Connection</CODE> objects.
|
||||||
|
*/
|
||||||
|
public void shutdown()
|
||||||
|
{
|
||||||
|
closeConnections(m_avail_connections);
|
||||||
|
m_avail_connections = null;
|
||||||
|
closeConnections(m_busy_connections);
|
||||||
|
m_busy_connections = null;
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static initializer
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static
|
||||||
|
{ // Create the database type inference map.
|
||||||
|
HashMap map = new HashMap();
|
||||||
|
map.put("com.mysql.jdbc.Driver","mysql");
|
||||||
|
map.put("org.gjt.mm.mysql.Driver","mysql");
|
||||||
|
INFER_TYPE_MAP = Collections.unmodifiableMap(map);
|
||||||
|
|
||||||
|
} // end static initializer
|
||||||
|
|
||||||
|
} // end class DatabaseConnectionPool
|
|
@ -0,0 +1,58 @@
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
# (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.mozilla.org/MPL/>.
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
# WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
# language governing rights and limitations under the License.
|
||||||
|
#
|
||||||
|
# The Original Code is the Venice Web Communities System.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
# Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
# ---------------------------------------------------------------------------------
|
||||||
|
# This file has been localized for the en_US locale
|
||||||
|
dbx.notInitialized=The connection pool object has not been initialized
|
||||||
|
dbx.classNotFound=Can't find JDBC driver class: {0}
|
||||||
|
dbx.illegalAccess=Can't access JDBC driver class: {0}
|
||||||
|
dbx.instantiation=Can't create JDBC driver class: {0}
|
||||||
|
dbx.sqlMakeNewConn=Can't create new database connection
|
||||||
|
dbx.connectionLimit=Connection limit reached
|
||||||
|
dbx.testfail=Test failed on database {0} (url {1}): {2}
|
||||||
|
config.inferType=Database type was not specified, and unable to infer it from JDBC driver name "{0}".
|
||||||
|
config.initialConn=Invalid initial connections parameter
|
||||||
|
config.maxConn=Invalid maximum connections parameter
|
||||||
|
config.create=Unable to create initial database connections
|
||||||
|
utils.impl=Database utilities are not implemented for database type "{0}".
|
||||||
|
load.opsClass=Unable to load {2} class for database "{1}": {0}
|
||||||
|
general=Database access failure: {0}
|
||||||
|
nsCache.notFound=Unknown namespace ID seen; possible internal error.
|
||||||
|
property.serialize=The value of property "{0}" could not be serialized.
|
||||||
|
property.deserialize=The value of property "{0}" could not be deserialized.
|
||||||
|
ose.setProperty=Unable to set the value of property "{1}" in namespace "{0}".
|
||||||
|
ose.removeProperty=Unable to remove the value of property "{1}" in namespace "{0}".
|
||||||
|
ose.getNamespaces=Unable to enumerate the namespaces in this ObjectStore.
|
||||||
|
ose.getNames=Unable to enumerate the object names in namespace "{0}".
|
||||||
|
auth.register=Authenticator already registered for namespace "{0}", name "{1}".
|
||||||
|
auth.notFound=No authenticator registered for namespace "{0}", name "{1}".
|
||||||
|
auth.noUserData=User cannot authenticate with authenticator namespace "{0}", name "{1}".
|
||||||
|
ose.setBlock=Unable to set the value of block "{1}" in namespace "{0}".
|
||||||
|
ose.removeBlock=Unable to remove the value of block "{1}" in namespace "{0}".
|
||||||
|
sec.changeUser=You are not permitted to change the attributes of user "{0}".
|
||||||
|
sec.needSec=You cannot perform this operation on a group without specifying a user making the change.
|
||||||
|
sec.setGroupProperty=You are not permitted to set property values for group "{0}".
|
||||||
|
sec.removeGroupProperty=You are not permitted to remove property values from group "{0}".
|
||||||
|
sec.addGroupMember=You are not permitted to add members to group "{0}".
|
||||||
|
sec.removeGroupMember=You are not permitted to remove members from group "{0}".
|
||||||
|
sec.setGroupAcl=You are not permitted to change the access control list of group "{0}".
|
||||||
|
sec.setGlobalProperty=You are not permitted to set the global property.
|
||||||
|
sec.removeGlobalProperty=You are not permitted to remove the global property.
|
||||||
|
sec.setGlobalBlock=You are not permitted to set the global block.
|
||||||
|
sec.removeGlobalBlock=You are not permitted to remove the global block.
|
||||||
|
img.loadFail=Failed to load image {0} due to I/O error.
|
||||||
|
img.badOwner=Invalid owner for new image.
|
||||||
|
img.notOwner=You are not the owner of image {0}.
|
||||||
|
img.normalize=Image normalization of {0} failed: {1}.
|
|
@ -0,0 +1,111 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
|
||||||
|
class DefaultHashAuthenticator implements Authenticator
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
DefaultHashAuthenticator()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* IMplementations from interface Authenticator
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean authenticate(String stored_data, String input_data) throws AuthenticationException
|
||||||
|
{
|
||||||
|
return stored_data.equals(hashPassword(input_data));
|
||||||
|
|
||||||
|
} // end authenticate
|
||||||
|
|
||||||
|
public String processInputData(String input_data) throws AuthenticationException
|
||||||
|
{
|
||||||
|
return hashPassword(input_data);
|
||||||
|
|
||||||
|
} // end processInputData
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final String hashPassword(String password)
|
||||||
|
{
|
||||||
|
if ((password!=null) && (password.length()>0))
|
||||||
|
{ // hash the password and save the hash value
|
||||||
|
MessageDigest hasher;
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // get a hasher implementing the Secure Hashing Algorithm
|
||||||
|
hasher = MessageDigest.getInstance("SHA");
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (java.security.NoSuchAlgorithmException e)
|
||||||
|
{ // SHA should be a standard algorithm...if it isn't, we're h0sed
|
||||||
|
throw new RuntimeException("HOSED JRE - SHA should be a standard algorithm");
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // update the hasher with the UTF-8 bytes of the password
|
||||||
|
hasher.update(password.getBytes("UTF8"));
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (java.io.UnsupportedEncodingException e)
|
||||||
|
{ // WTF? How can the JRE NOT know about UTF-8? HOW?!?
|
||||||
|
throw new RuntimeException("HOSED JRE - UTF-8 encoding should be supported");
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
// Retrieve the raw hash value (should be 160 bits, or 20 bytes)
|
||||||
|
byte[] raw_hash = hasher.digest();
|
||||||
|
|
||||||
|
// Convert the hash value to a hexadecimal string (40 chars in length)
|
||||||
|
StringBuffer hash_buf = new StringBuffer(raw_hash.length * 2);
|
||||||
|
StringBuffer tmp_buf = new StringBuffer();
|
||||||
|
String tmp;
|
||||||
|
for (int i=0; i<raw_hash.length; i++)
|
||||||
|
{ // N.B.: Integer.toHexString does not zero-pad on the left, so that's why this is
|
||||||
|
// a little complex
|
||||||
|
tmp_buf.setLength(0);
|
||||||
|
tmp_buf.append("00").append(Integer.toHexString(raw_hash[i]).trim());
|
||||||
|
tmp = tmp_buf.toString();
|
||||||
|
hash_buf.append(tmp.substring(tmp.length()-2));
|
||||||
|
|
||||||
|
} // end for
|
||||||
|
|
||||||
|
// finally, save off the password hash value
|
||||||
|
return hash_buf.toString().toUpperCase();
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else // no password
|
||||||
|
return "";
|
||||||
|
|
||||||
|
} // end hashPassword
|
||||||
|
|
||||||
|
} // end class DefaultHashAuthenticator
|
|
@ -0,0 +1,185 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.util.*;
|
||||||
|
import com.silverwrist.dynamo.event.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.security.SecurityReferenceMonitor;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
class GlobalBlocksObject implements SecureObjectStore
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private GlobalBlocksOps m_ops; // operations object
|
||||||
|
private NamespaceCache m_ns_cache; // namespace cache
|
||||||
|
private SecurityReferenceMonitor m_srm; // security reference monitor
|
||||||
|
private PostDynamicUpdate m_post; // where we post dynamic events
|
||||||
|
private HardSoftCache m_cache; // our cache
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
GlobalBlocksObject(DBConnectionPool pool, NamespaceCache ns_cache, SecurityReferenceMonitor srm,
|
||||||
|
PostDynamicUpdate post, int hard_limit, int soft_limit) throws ConfigException
|
||||||
|
{
|
||||||
|
m_ops = GlobalBlocksOps.get(pool);
|
||||||
|
m_ns_cache = ns_cache;
|
||||||
|
m_srm = srm;
|
||||||
|
m_post = post;
|
||||||
|
m_cache = new HardSoftCache(hard_limit,soft_limit);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private final void testPermission(DynamoUser caller, String perm_namespace, String perm_name,
|
||||||
|
String fail_message) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
if (caller.equals(m_srm.getAdminUser()))
|
||||||
|
return; // Administrator can do anything
|
||||||
|
if (m_srm.getGlobalAcl().testPermission(caller,perm_namespace,perm_name))
|
||||||
|
return; // we have the right permission in the ACL
|
||||||
|
throw new DynamoSecurityException(GroupObject.class,"DatabaseMessages",fail_message);
|
||||||
|
|
||||||
|
} // end testPermission
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ObjectProvider
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an object from this <CODE>ObjectProvider</CODE>.
|
||||||
|
*
|
||||||
|
* @param namespace The namespace to interpret the name relative to.
|
||||||
|
* @param name The name of the object to be retrieved.
|
||||||
|
* @return The object reference specified.
|
||||||
|
*/
|
||||||
|
public Object getObject(String namespace, String name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // convert the namespace name to an ID here
|
||||||
|
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||||
|
Object rc = null;
|
||||||
|
synchronized (this)
|
||||||
|
{ // start by looking in the block cache
|
||||||
|
rc = m_cache.get(key);
|
||||||
|
if (rc==null)
|
||||||
|
{ // no use - need to try the database
|
||||||
|
rc = m_ops.getBlock(key);
|
||||||
|
if (rc!=null)
|
||||||
|
m_cache.put(key,rc);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
if (rc==null)
|
||||||
|
throw new NoSuchObjectException(this.toString(),namespace,name);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (DatabaseException e)
|
||||||
|
{ // translate into our NoSuchObjectException but retain the DatabaseException
|
||||||
|
throw new NoSuchObjectException(this.toString(),namespace,name,e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getObject
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface SecureObjectStore
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Object setObject(DynamoUser caller, String namespace, String name, Object value)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,namespace,"set.block","sec.setGlobalBlock");
|
||||||
|
Object rc = null;
|
||||||
|
// convert the namespace name to an ID here
|
||||||
|
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||||
|
synchronized (this)
|
||||||
|
{ // start by setting the database value
|
||||||
|
rc = m_ops.putBlock(key,value.toString());
|
||||||
|
|
||||||
|
// and cache it, too
|
||||||
|
m_cache.put(key,value.toString());
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
m_post.postUpdate(new GlobalBlockUpdateEvent(this,namespace,name));
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end setObject
|
||||||
|
|
||||||
|
public Object removeObject(DynamoUser caller, String namespace, String name)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,namespace,"remove.block","sec.removeGlobalBlock");
|
||||||
|
Object rc = null;
|
||||||
|
// convert the namespace name to an ID here
|
||||||
|
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||||
|
synchronized (this)
|
||||||
|
{ // start by killing the database value
|
||||||
|
rc = m_ops.removeBlock(key);
|
||||||
|
|
||||||
|
// and remove the cached value, too
|
||||||
|
m_cache.remove(key);
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
m_post.postUpdate(new GlobalBlockUpdateEvent(this,namespace,name));
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end removeObject
|
||||||
|
|
||||||
|
public Collection getNamespaces() throws DatabaseException
|
||||||
|
{
|
||||||
|
// call through to the database to get the list of namespace IDs
|
||||||
|
int[] ids = m_ops.getBlockNamespaceIDs();
|
||||||
|
|
||||||
|
ArrayList rc = new ArrayList(ids.length);
|
||||||
|
for (int i=0; i<ids.length; i++)
|
||||||
|
rc.add(m_ns_cache.namespaceIdToName(ids[i]));
|
||||||
|
return Collections.unmodifiableList(rc);
|
||||||
|
|
||||||
|
} // end getNamespaces
|
||||||
|
|
||||||
|
public Collection getNamesForNamespace(String namespace) throws DatabaseException
|
||||||
|
{
|
||||||
|
// call through to the database to get the data for this namespace, then get names
|
||||||
|
return m_ops.getAllBlockNames(m_ns_cache.namespaceNameToId(namespace));
|
||||||
|
// N.B.: we do not retrieve all blocks and cache them the way we do with properties because
|
||||||
|
// blocks can potentially be HUGE, and our cache size is limited at best
|
||||||
|
|
||||||
|
} // end getNamesForNamespace
|
||||||
|
|
||||||
|
} // end class GlobalBlocksObject
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
abstract class GlobalBlocksOps extends OpsBase
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected GlobalBlocksOps(DBConnectionPool pool)
|
||||||
|
{
|
||||||
|
super(pool);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class OpsBase
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void dispose()
|
||||||
|
{
|
||||||
|
super.dispose();
|
||||||
|
|
||||||
|
} // end dispose
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Abstract operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
abstract String getBlock(PropertyKey key) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract String putBlock(PropertyKey key, String data) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract String removeBlock(PropertyKey key) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract int[] getBlockNamespaceIDs() throws DatabaseException;
|
||||||
|
|
||||||
|
abstract Collection getAllBlockNames(int nsid) throws DatabaseException;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static GlobalBlocksOps get(DBConnectionPool pool) throws ConfigException
|
||||||
|
{
|
||||||
|
return (GlobalBlocksOps)get(pool,GlobalBlocksOps.class.getClassLoader(),
|
||||||
|
GlobalBlocksOps.class.getName() + "_","GlobalBlocksOps");
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
} // end class GlobalBlocksOps
|
|
@ -0,0 +1,284 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.util.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
public class GlobalBlocksOps_mysql extends GlobalBlocksOps
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private DBUtilities m_utils; // reference to utilities object
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public GlobalBlocksOps_mysql(DBConnectionPool pool)
|
||||||
|
{
|
||||||
|
super(pool);
|
||||||
|
m_utils = (DBUtilities)(pool.queryService(DBUtilities.class));
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Abstract implementations from class GlobalBlocksOps
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
String getBlock(PropertyKey key) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// look up the block
|
||||||
|
stmt = conn.prepareStatement("SELECT block FROM globalblock WHERE nsid = ? AND block_name = ?;");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (!(rs.next()))
|
||||||
|
return null; // block not found
|
||||||
|
return rs.getString(1);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end getBlock
|
||||||
|
|
||||||
|
String putBlock(PropertyKey key, String data) throws DatabaseException
|
||||||
|
{
|
||||||
|
String old_value = null;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Statement stmt2 = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// lock the table
|
||||||
|
stmt2 = conn.createStatement();
|
||||||
|
stmt2.executeUpdate("LOCK TABLES globalblock WRITE;");
|
||||||
|
|
||||||
|
// look to see if the block value is already there
|
||||||
|
stmt = conn.prepareStatement("SELECT block FROM globalblock WHERE nsid = ? AND block_name = ?;");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (rs.next())
|
||||||
|
old_value = rs.getString(1);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
rs = null;
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
|
||||||
|
if (old_value!=null)
|
||||||
|
{ // prepare the statement to update the existing record
|
||||||
|
stmt = conn.prepareStatement("UPDATE globalblock SET block = ? WHERE nsid = ? AND block_name = ?;");
|
||||||
|
stmt.setString(1,data);
|
||||||
|
stmt.setInt(2,key.getNamespaceID());
|
||||||
|
stmt.setString(3,key.getName());
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // prepare the statement to insert a new record
|
||||||
|
stmt = conn.prepareStatement("INSERT INTO globalblock (nsid, block_name, block) VALUES (?, ?, ?);");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
stmt.setString(3,data);
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
stmt.executeUpdate(); // execute it!
|
||||||
|
|
||||||
|
return old_value; // return previous value
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
MySQLUtils.unlockTables(conn);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(stmt2);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end putBlock
|
||||||
|
|
||||||
|
String removeBlock(PropertyKey key) throws DatabaseException
|
||||||
|
{
|
||||||
|
String old_value = null;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Statement stmt2 = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// lock the table
|
||||||
|
stmt2 = conn.createStatement();
|
||||||
|
stmt2.executeUpdate("LOCK TABLES globalblock WRITE;");
|
||||||
|
|
||||||
|
// look to see if the property value is already there
|
||||||
|
stmt = conn.prepareStatement("SELECT block FROM globalblock WHERE nsid = ? AND block_name = ?;");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (rs.next())
|
||||||
|
old_value = rs.getString(1);
|
||||||
|
else
|
||||||
|
return null; // no need to remove anything
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
rs = null;
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
|
||||||
|
// delete the database row
|
||||||
|
stmt = conn.prepareStatement("DELETE FROM globalblock WHERE nsid = ? AND block_name = ?;");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
return old_value;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
MySQLUtils.unlockTables(conn);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(stmt2);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end removeBlock
|
||||||
|
|
||||||
|
int[] getBlockNamespaceIDs() throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// execute the query!
|
||||||
|
stmt = conn.prepareStatement("SELECT DISTINCT nsid FROM globalblock;");
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
// read out a list of the namespace IDs
|
||||||
|
ArrayList tmp = new ArrayList();
|
||||||
|
while (rs.next())
|
||||||
|
tmp.add(new Integer(rs.getInt(1)));
|
||||||
|
|
||||||
|
// create and return the array
|
||||||
|
int[] rc = new int[tmp.size()];
|
||||||
|
for (int i=0; i<tmp.size(); i++)
|
||||||
|
rc[i] = ((Integer)(tmp.get(i))).intValue();
|
||||||
|
tmp.clear();
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end getBlockNamespaceIDs
|
||||||
|
|
||||||
|
Collection getAllBlockNames(int nsid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// execute the query!
|
||||||
|
stmt = conn.prepareStatement("SELECT block_name FROM globalblock WHERE nsid = ?;");
|
||||||
|
stmt.setInt(1,nsid);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
// prepare the return value
|
||||||
|
ArrayList rc = new ArrayList();
|
||||||
|
while (rs.next())
|
||||||
|
rc.add(rs.getString(1));
|
||||||
|
rc.trimToSize();
|
||||||
|
return Collections.unmodifiableList(rc);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end getAllBlockNames
|
||||||
|
|
||||||
|
} // end class GlobalBlocksOps_mysql
|
|
@ -0,0 +1,207 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import org.w3c.dom.*;
|
||||||
|
import com.silverwrist.util.xml.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.security.SecurityReferenceMonitor;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
public class GlobalDataManagerObject
|
||||||
|
implements NamedObject, ComponentInitialize, ComponentShutdown, ServiceProvider
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static final int DEFAULT_HARD_LIMIT = 5;
|
||||||
|
private static final int DEFAULT_SOFT_LIMIT = 20;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String m_name; // object name
|
||||||
|
private DBConnectionPool m_pool; // database connection pool
|
||||||
|
private NamespaceCache m_ns_cache; // namespace cache object
|
||||||
|
private SecurityReferenceMonitor m_srm; // security reference monitor
|
||||||
|
private PostDynamicUpdate m_post; // dynamic update poster
|
||||||
|
private GlobalPropertiesObject m_properties; // global properties object
|
||||||
|
private GlobalBlocksObject m_blocks; // global blocks object
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public GlobalDataManagerObject()
|
||||||
|
{ // do nothing
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface NamedObject
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
|
||||||
|
} // end getName
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ComponentInitialize
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void initialize(Element config_root, ServiceProvider services) throws ConfigException
|
||||||
|
{
|
||||||
|
String conn_name = null;
|
||||||
|
String nscache_name = null;
|
||||||
|
String srm_name = null;
|
||||||
|
int hard_limit = DEFAULT_HARD_LIMIT;
|
||||||
|
int soft_limit = DEFAULT_SOFT_LIMIT;
|
||||||
|
XMLLoader loader = XMLLoader.get();
|
||||||
|
try
|
||||||
|
{ // verify the right node name
|
||||||
|
loader.verifyNodeName(config_root,"object");
|
||||||
|
|
||||||
|
// get the object's name
|
||||||
|
m_name = loader.getAttribute(config_root,"name");
|
||||||
|
|
||||||
|
// get the database configuration connection
|
||||||
|
DOMElementHelper config_root_h = new DOMElementHelper(config_root);
|
||||||
|
Element elt = loader.getSubElement(config_root_h,"database");
|
||||||
|
conn_name = loader.getAttribute(elt,"connection");
|
||||||
|
nscache_name = loader.getAttribute(elt,"namespaces");
|
||||||
|
|
||||||
|
// get the security reference monitor reference
|
||||||
|
elt = loader.getSubElement(config_root_h,"security");
|
||||||
|
srm_name = loader.getAttribute(elt,"object");
|
||||||
|
|
||||||
|
// get the block cache information
|
||||||
|
elt = config_root_h.getSubElement("block-cache");
|
||||||
|
if (elt!=null)
|
||||||
|
{ // get the cache limits
|
||||||
|
hard_limit = loader.getAttributeInt(elt,"hardlimit",DEFAULT_HARD_LIMIT);
|
||||||
|
soft_limit = loader.getAttributeInt(elt,"softlimit",DEFAULT_SOFT_LIMIT);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (XMLLoadException e)
|
||||||
|
{ // error loading XML config data
|
||||||
|
throw new ConfigException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
// Get the database connection pool and the namespace cache.
|
||||||
|
m_pool = GetObjectUtils.getDatabaseConnection(services,conn_name);
|
||||||
|
m_ns_cache =
|
||||||
|
(NamespaceCache)(GetObjectUtils.getDynamoComponent(services,NamespaceCache.class,nscache_name));
|
||||||
|
m_srm =
|
||||||
|
(SecurityReferenceMonitor)(GetObjectUtils.getDynamoComponent(services,SecurityReferenceMonitor.class,
|
||||||
|
srm_name));
|
||||||
|
m_post = (PostDynamicUpdate)(services.queryService(PostDynamicUpdate.class));
|
||||||
|
|
||||||
|
// Create the subobjects.
|
||||||
|
m_properties = new GlobalPropertiesObject(m_pool,m_ns_cache,m_srm,m_post);
|
||||||
|
m_blocks = new GlobalBlocksObject(m_pool,m_ns_cache,m_srm,m_post,hard_limit,soft_limit);
|
||||||
|
|
||||||
|
} // end initialize
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ComponentShutdown
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void shutdown()
|
||||||
|
{
|
||||||
|
m_pool = null;
|
||||||
|
m_ns_cache = null;
|
||||||
|
m_srm = null;
|
||||||
|
m_post = null;
|
||||||
|
|
||||||
|
} // end shutdown
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ServiceProvider
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass)
|
||||||
|
{
|
||||||
|
if ((klass==SecureObjectStore.class) || (klass==ObjectProvider.class))
|
||||||
|
return (SecureObjectStore)m_properties;
|
||||||
|
throw new NoSuchServiceException("GlobalDataManagerObject",klass);
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries this object for a specified service.
|
||||||
|
*
|
||||||
|
* @param klass The class of the object that should be returned as a service.
|
||||||
|
* @param serviceid ID for the service to be requested, to further discriminate between requests.
|
||||||
|
* @return A service object. The service object is guaranteed to be of the class
|
||||||
|
* specified by <CODE>klass</CODE>; that is, if <CODE>queryService(klass)</CODE>
|
||||||
|
* yields some object <CODE>x</CODE>, then the expression <CODE>klass.isInstance(x)</CODE>
|
||||||
|
* is true.
|
||||||
|
* @exception com.silverwrist.dynamo.except.NoSuchServiceException If no service is available in
|
||||||
|
* the specified class.
|
||||||
|
*/
|
||||||
|
public Object queryService(Class klass, String serviceid)
|
||||||
|
{
|
||||||
|
if ((klass==SecureObjectStore.class) || (klass==ObjectProvider.class))
|
||||||
|
{ // return service
|
||||||
|
if ((serviceid==null) || serviceid.equals("properties"))
|
||||||
|
return (SecureObjectStore)m_properties;
|
||||||
|
if (serviceid.equals("blocks"))
|
||||||
|
return (SecureObjectStore)m_blocks;
|
||||||
|
throw new NoSuchServiceException("GlobalDataManagerObject",klass,serviceid);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
try
|
||||||
|
{ // look for the class without a service ID
|
||||||
|
return this.queryService(klass);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (NoSuchServiceException e)
|
||||||
|
{ // transform exception for return
|
||||||
|
throw new NoSuchServiceException(e.getContext(),klass,serviceid,e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end queryService
|
||||||
|
|
||||||
|
} // end class GlobalDataManagerObject
|
|
@ -0,0 +1,201 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.commons.collections.*;
|
||||||
|
import com.silverwrist.dynamo.event.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.security.SecurityReferenceMonitor;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
class GlobalPropertiesObject implements SecureObjectStore
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private GlobalPropertiesOps m_ops; // operations object
|
||||||
|
private NamespaceCache m_ns_cache; // namespace cache
|
||||||
|
private SecurityReferenceMonitor m_srm; // security reference monitor
|
||||||
|
private PostDynamicUpdate m_post; // where we post dynamic events
|
||||||
|
private ReferenceMap m_properties; // cached property values
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
GlobalPropertiesObject(DBConnectionPool pool, NamespaceCache ns_cache, SecurityReferenceMonitor srm,
|
||||||
|
PostDynamicUpdate post) throws ConfigException
|
||||||
|
{
|
||||||
|
m_ops = GlobalPropertiesOps.get(pool);
|
||||||
|
m_ns_cache = ns_cache;
|
||||||
|
m_srm = srm;
|
||||||
|
m_post = post;
|
||||||
|
m_properties = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private final void testPermission(DynamoUser caller, String perm_namespace, String perm_name,
|
||||||
|
String fail_message) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
if (caller.equals(m_srm.getAdminUser()))
|
||||||
|
return; // Administrator can do anything
|
||||||
|
if (m_srm.getGlobalAcl().testPermission(caller,perm_namespace,perm_name))
|
||||||
|
return; // we have the right permission in the ACL
|
||||||
|
throw new DynamoSecurityException(GroupObject.class,"DatabaseMessages",fail_message);
|
||||||
|
|
||||||
|
} // end testPermission
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ObjectProvider
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an object from this <CODE>ObjectProvider</CODE>.
|
||||||
|
*
|
||||||
|
* @param namespace The namespace to interpret the name relative to.
|
||||||
|
* @param name The name of the object to be retrieved.
|
||||||
|
* @return The object reference specified.
|
||||||
|
*/
|
||||||
|
public Object getObject(String namespace, String name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // convert the namespace name to an ID here
|
||||||
|
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||||
|
Object rc = null;
|
||||||
|
synchronized (this)
|
||||||
|
{ // start by looking in the properties map
|
||||||
|
rc = m_properties.get(key);
|
||||||
|
if (rc==null)
|
||||||
|
{ // no use - need to try the database
|
||||||
|
rc = m_ops.getProperty(key);
|
||||||
|
if (rc!=null)
|
||||||
|
m_properties.put(key,rc);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
if (rc==null)
|
||||||
|
throw new NoSuchObjectException(this.toString(),namespace,name);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (DatabaseException e)
|
||||||
|
{ // translate into our NoSuchObjectException but retain the DatabaseException
|
||||||
|
throw new NoSuchObjectException(this.toString(),namespace,name,e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getObject
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface SecureObjectStore
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Object setObject(DynamoUser caller, String namespace, String name, Object value)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,namespace,"set.property","sec.setGlobalProperty");
|
||||||
|
Object rc = null;
|
||||||
|
// convert the namespace name to an ID here
|
||||||
|
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||||
|
synchronized (this)
|
||||||
|
{ // start by setting the database value
|
||||||
|
rc = m_ops.setProperty(key,value);
|
||||||
|
|
||||||
|
// and cache it, too
|
||||||
|
m_properties.put(key,value);
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
m_post.postUpdate(new GlobalPropertyUpdateEvent(this,namespace,name));
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end setObject
|
||||||
|
|
||||||
|
public Object removeObject(DynamoUser caller, String namespace, String name)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,namespace,"remove.property","sec.removeGlobalProperty");
|
||||||
|
Object rc = null;
|
||||||
|
// convert the namespace name to an ID here
|
||||||
|
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||||
|
synchronized (this)
|
||||||
|
{ // start by killing the database value
|
||||||
|
rc = m_ops.removeProperty(key);
|
||||||
|
|
||||||
|
// and remove the cached value, too
|
||||||
|
m_properties.remove(key);
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
m_post.postUpdate(new GlobalPropertyUpdateEvent(this,namespace,name));
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end removeObject
|
||||||
|
|
||||||
|
public Collection getNamespaces() throws DatabaseException
|
||||||
|
{
|
||||||
|
// call through to the database to get the list of namespace IDs
|
||||||
|
int[] ids = m_ops.getPropertyNamespaceIDs();
|
||||||
|
|
||||||
|
ArrayList rc = new ArrayList(ids.length);
|
||||||
|
for (int i=0; i<ids.length; i++)
|
||||||
|
rc.add(m_ns_cache.namespaceIdToName(ids[i]));
|
||||||
|
return Collections.unmodifiableList(rc);
|
||||||
|
|
||||||
|
} // end getNamespaces
|
||||||
|
|
||||||
|
public Collection getNamesForNamespace(String namespace) throws DatabaseException
|
||||||
|
{
|
||||||
|
// call through to the database to get the data for this namespace
|
||||||
|
int nsid = m_ns_cache.namespaceNameToId(namespace);
|
||||||
|
Map data = m_ops.getAllProperties(nsid);
|
||||||
|
|
||||||
|
// we both create the return value and cache the data values
|
||||||
|
ArrayList rc = new ArrayList(data.size());
|
||||||
|
synchronized (this)
|
||||||
|
{ // do the transfer...
|
||||||
|
Iterator it = data.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{ // copy one entry at a time
|
||||||
|
Map.Entry ntry = (Map.Entry)(it.next());
|
||||||
|
rc.add(ntry.getKey().toString());
|
||||||
|
m_properties.put(new PropertyKey(nsid,ntry.getKey().toString()),ntry.getValue());
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
return Collections.unmodifiableList(rc);
|
||||||
|
|
||||||
|
} // end getNamesForNamespace
|
||||||
|
|
||||||
|
} // end class GlobalPropertiesObject
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
abstract class GlobalPropertiesOps extends OpsBase
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected GlobalPropertiesOps(DBConnectionPool pool)
|
||||||
|
{
|
||||||
|
super(pool);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Overrides from class OpsBase
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void dispose()
|
||||||
|
{
|
||||||
|
super.dispose();
|
||||||
|
|
||||||
|
} // end dispose
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Abstract operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
abstract Object getProperty(PropertyKey key) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract Object setProperty(PropertyKey key, Object value) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract Object removeProperty(PropertyKey key) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract int[] getPropertyNamespaceIDs() throws DatabaseException;
|
||||||
|
|
||||||
|
abstract Map getAllProperties(int namespace) throws DatabaseException;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External static operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static GlobalPropertiesOps get(DBConnectionPool pool) throws ConfigException
|
||||||
|
{
|
||||||
|
return (GlobalPropertiesOps)get(pool,GlobalPropertiesOps.class.getClassLoader(),
|
||||||
|
GlobalPropertiesOps.class.getName() + "_","GlobalPropertiesOps");
|
||||||
|
|
||||||
|
} // end get
|
||||||
|
|
||||||
|
} // end class GlobalPropertiesOps
|
|
@ -0,0 +1,344 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.util.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
public class GlobalPropertiesOps_mysql extends GlobalPropertiesOps
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private DBUtilities m_utils; // reference to utilities object
|
||||||
|
private PropertySerializer m_psz; // reference to property serializer
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public GlobalPropertiesOps_mysql(DBConnectionPool pool)
|
||||||
|
{
|
||||||
|
super(pool);
|
||||||
|
m_utils = (DBUtilities)(pool.queryService(DBUtilities.class));
|
||||||
|
m_psz = (PropertySerializer)(pool.queryService(PropertySerializer.class));
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Abstract implementations from class GlobalPropertiesOps
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
Object getProperty(PropertyKey key) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
String rc_str = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// look up the property
|
||||||
|
stmt = conn.prepareStatement("SELECT prop_value FROM globalprop WHERE nsid = ? AND prop_name = ?;");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (!(rs.next()))
|
||||||
|
return null; // property not found
|
||||||
|
|
||||||
|
rc_str = rs.getString(1);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
// Deserialize the property value.
|
||||||
|
Object rc = m_psz.deserializeProperty(rc_str);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
// deserialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GlobalPropertiesOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.deserialize");
|
||||||
|
de.setParameter(0,key.getName());
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end getProperty
|
||||||
|
|
||||||
|
Object setProperty(PropertyKey key, Object value) throws DatabaseException
|
||||||
|
{
|
||||||
|
String serialized_value = m_psz.serializeProperty(value);
|
||||||
|
if (serialized_value==null)
|
||||||
|
{ // serialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GlobalPropertiesOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.serialize");
|
||||||
|
de.setParameter(0,key.getName());
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
String old_value = null;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Statement stmt2 = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// lock the table
|
||||||
|
stmt2 = conn.createStatement();
|
||||||
|
stmt2.executeUpdate("LOCK TABLES globalprop WRITE;");
|
||||||
|
|
||||||
|
// look to see if the property value is already there
|
||||||
|
stmt = conn.prepareStatement("SELECT prop_value FROM globalprop WHERE nsid = ? AND prop_name = ?;");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (rs.next())
|
||||||
|
old_value = rs.getString(1);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
rs = null;
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
|
||||||
|
if (old_value!=null)
|
||||||
|
{ // prepare the statement to update the existing record
|
||||||
|
stmt = conn.prepareStatement("UPDATE globalprop SET prop_value = ? WHERE nsid = ? AND prop_name = ?;");
|
||||||
|
stmt.setString(1,serialized_value);
|
||||||
|
stmt.setInt(2,key.getNamespaceID());
|
||||||
|
stmt.setString(3,key.getName());
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // prepare the statement to insert a new record
|
||||||
|
stmt = conn.prepareStatement("INSERT INTO globalprop (nsid, prop_name, prop_value) VALUES (?, ?, ?);");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
stmt.setString(3,serialized_value);
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
stmt.executeUpdate(); // execute it!
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
MySQLUtils.unlockTables(conn);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(stmt2);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
if (old_value==null)
|
||||||
|
return null; // no previous value
|
||||||
|
|
||||||
|
// Deserialize the property value.
|
||||||
|
Object rc = m_psz.deserializeProperty(old_value);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
// deserialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GlobalPropertiesOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.deserialize");
|
||||||
|
de.setParameter(0,key.getName());
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end setProperty
|
||||||
|
|
||||||
|
Object removeProperty(PropertyKey key) throws DatabaseException
|
||||||
|
{
|
||||||
|
String old_value = null;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Statement stmt2 = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// lock the table
|
||||||
|
stmt2 = conn.createStatement();
|
||||||
|
stmt2.executeUpdate("LOCK TABLES globalprop WRITE;");
|
||||||
|
|
||||||
|
// look to see if the property value is already there
|
||||||
|
stmt = conn.prepareStatement("SELECT prop_value FROM globalprop WHERE nsid = ? AND prop_name = ?;");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (rs.next())
|
||||||
|
old_value = rs.getString(1);
|
||||||
|
else
|
||||||
|
return null; // no need to remove anything
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
rs = null;
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
|
||||||
|
// delete the database row
|
||||||
|
stmt = conn.prepareStatement("DELETE FROM globalprop WHERE nsid = ? AND prop_name = ?;");
|
||||||
|
stmt.setInt(1,key.getNamespaceID());
|
||||||
|
stmt.setString(2,key.getName());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
MySQLUtils.unlockTables(conn);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(stmt2);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
// Deserialize the property value.
|
||||||
|
Object rc = m_psz.deserializeProperty(old_value);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
// deserialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GlobalPropertiesOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.deserialize");
|
||||||
|
de.setParameter(0,key.getName());
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end removeProperty
|
||||||
|
|
||||||
|
int[] getPropertyNamespaceIDs() throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// execute the query!
|
||||||
|
stmt = conn.prepareStatement("SELECT DISTINCT nsid FROM globalprop;");
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
// read out a list of the namespace IDs
|
||||||
|
ArrayList tmp = new ArrayList();
|
||||||
|
while (rs.next())
|
||||||
|
tmp.add(new Integer(rs.getInt(1)));
|
||||||
|
|
||||||
|
// create and return the array
|
||||||
|
int[] rc = new int[tmp.size()];
|
||||||
|
for (int i=0; i<tmp.size(); i++)
|
||||||
|
rc[i] = ((Integer)(tmp.get(i))).intValue();
|
||||||
|
tmp.clear();
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end getPropertyNamespaceIDs
|
||||||
|
|
||||||
|
Map getAllProperties(int namespace) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// execute the query!
|
||||||
|
stmt = conn.prepareStatement("SELECT prop_name, prop_value FROM globalprop WHERE nsid = ?;");
|
||||||
|
stmt.setInt(1,namespace);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
// prepare the return value
|
||||||
|
HashMap rc = new HashMap();
|
||||||
|
while (rs.next())
|
||||||
|
{ // copy data out, deserializing properties as we go
|
||||||
|
String key = rs.getString(1);
|
||||||
|
Object value = m_psz.deserializeProperty(rs.getString(2));
|
||||||
|
if (value==null)
|
||||||
|
{ // deserialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GlobalPropertiesOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.deserialize");
|
||||||
|
de.setParameter(0,key);
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
rc.put(key,value);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end getAllProperties
|
||||||
|
|
||||||
|
} // end class GlobalPropertiesOps_mysql
|
611
src/dynamo-framework/com/silverwrist/dynamo/db/GroupObject.java
Normal file
611
src/dynamo-framework/com/silverwrist/dynamo/db/GroupObject.java
Normal file
|
@ -0,0 +1,611 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.security.Principal;
|
||||||
|
import java.security.acl.AclNotFoundException;
|
||||||
|
import java.util.*;
|
||||||
|
import org.apache.commons.collections.*;
|
||||||
|
import com.silverwrist.dynamo.Namespaces;
|
||||||
|
import com.silverwrist.dynamo.UserInfoNamespace;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.security.SecurityReferenceMonitor;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
class GroupObject implements DynamoGroup
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Static data members
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static final String PERM_NAMESPACE = Namespaces.GROUP_PERMISSIONS_NAMESPACE;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private GroupObjectOps m_ops; // operations object
|
||||||
|
private NamespaceCache m_ns_cache; // namespace cache object
|
||||||
|
private SecurityReferenceMonitor m_srm; // security reference monitor
|
||||||
|
private UserProxyManagement m_upm; // user proxy manager
|
||||||
|
private int m_gid; // group ID
|
||||||
|
private String m_groupname; // group name
|
||||||
|
private int m_gaclid; // group ACL ID
|
||||||
|
private ReferenceMap m_properties; // cached property values
|
||||||
|
private Object m_properties_sync = new Object(); // synchronization for above
|
||||||
|
private HashSet m_known_members = new HashSet(); // known members
|
||||||
|
private HashSet m_known_nonmembers = new HashSet(); // known nonmembers
|
||||||
|
private Object m_members_sync = new Object(); // synchronization for above
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
GroupObject(Map data, GroupObjectOps ops, NamespaceCache ns_cache, SecurityReferenceMonitor srm,
|
||||||
|
UserProxyManagement upm)
|
||||||
|
{
|
||||||
|
m_ops = ops;
|
||||||
|
m_ns_cache = ns_cache;
|
||||||
|
m_srm = srm;
|
||||||
|
m_upm = upm;
|
||||||
|
m_gid = ((Integer)(data.get(UserManagerOps.HMKEY_GID))).intValue();
|
||||||
|
m_groupname = (String)(data.get(UserManagerOps.HMKEY_GROUPNAME));
|
||||||
|
m_gaclid = ((Integer)(data.get(UserManagerOps.HMKEY_GACLID))).intValue();
|
||||||
|
m_properties = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Internal operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static final int getPrincipalUID(Principal p)
|
||||||
|
{
|
||||||
|
if (p instanceof DynamoUser)
|
||||||
|
return ((DynamoUser)p).getUID();
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
} // end getPrincipalUID
|
||||||
|
|
||||||
|
private final void testOperationWithoutSecurity()
|
||||||
|
{
|
||||||
|
if (m_gaclid==-1)
|
||||||
|
return;
|
||||||
|
throw new GroupRuntimeException(new DynamoSecurityException(GroupObject.class,"DatabaseMessages",
|
||||||
|
"sec.needSec"));
|
||||||
|
|
||||||
|
} // end testOperationWithoutSecurity
|
||||||
|
|
||||||
|
private final void testPermission(DynamoUser caller, String perm_namespace, String perm_name,
|
||||||
|
String fail_message) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
if (m_gaclid==-1)
|
||||||
|
return;
|
||||||
|
if (caller==null)
|
||||||
|
throw new DynamoSecurityException(GroupObject.class,"DatabaseMessages","sec.needSec");
|
||||||
|
if (caller.equals(m_srm.getAdminUser()))
|
||||||
|
return; // Administrator can do anything
|
||||||
|
if (m_srm.testPermission(m_gaclid,caller,perm_namespace,perm_name))
|
||||||
|
return; // we have the right permission in the ACL
|
||||||
|
DynamoSecurityException dse = new DynamoSecurityException(GroupObject.class,"DatabaseMessages",
|
||||||
|
fail_message);
|
||||||
|
dse.setParameter(0,m_groupname);
|
||||||
|
throw dse;
|
||||||
|
|
||||||
|
} // end testPermission
|
||||||
|
|
||||||
|
private final void testPermission(DynamoUser caller, int target_uid, String perm_namespace, String perm_name,
|
||||||
|
String perm2_name, String fail_message)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
if (m_gaclid==-1)
|
||||||
|
return;
|
||||||
|
if (caller==null)
|
||||||
|
throw new DynamoSecurityException(GroupObject.class,"DatabaseMessages","sec.needSec");
|
||||||
|
if (caller.equals(m_srm.getAdminUser()))
|
||||||
|
return; // Administrator can do anything
|
||||||
|
if ((caller.getUID()==target_uid) && m_srm.testPermission(m_gaclid,caller,perm_namespace,perm2_name))
|
||||||
|
return; // we can "join group" or "unjoin group" if we have the right permissions
|
||||||
|
if (m_srm.testPermission(m_gaclid,caller,perm_namespace,perm_name))
|
||||||
|
return; // we have the right permission in the ACL
|
||||||
|
DynamoSecurityException dse = new DynamoSecurityException(GroupObject.class,"DatabaseMessages",
|
||||||
|
fail_message);
|
||||||
|
dse.setParameter(0,m_groupname);
|
||||||
|
throw dse;
|
||||||
|
|
||||||
|
} // end testPermission
|
||||||
|
|
||||||
|
private final void testAclOwner(DynamoUser caller) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
if (m_gaclid==-1)
|
||||||
|
return;
|
||||||
|
if (caller==null)
|
||||||
|
throw new DynamoSecurityException(GroupObject.class,"DatabaseMessages","sec.needSec");
|
||||||
|
if (caller.equals(m_srm.getAdminUser()))
|
||||||
|
return; // Administrator can do anything
|
||||||
|
if (m_srm.isOwnerOfAcl(m_gaclid,caller))
|
||||||
|
return; // we own this ACL
|
||||||
|
DynamoSecurityException dse = new DynamoSecurityException(GroupObject.class,"DatabaseMessages",
|
||||||
|
"sec.setGroupAcl");
|
||||||
|
dse.setParameter(0,m_groupname);
|
||||||
|
throw dse;
|
||||||
|
|
||||||
|
} // end testAclOwner
|
||||||
|
|
||||||
|
private final boolean addUIDInternal(int uid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Integer key = new Integer(uid);
|
||||||
|
synchronized (m_members_sync)
|
||||||
|
{ // look in the cache first
|
||||||
|
if (m_known_members.contains(key))
|
||||||
|
return false; // we're already a known member
|
||||||
|
|
||||||
|
// fiddle the database
|
||||||
|
boolean rc = m_ops.addMember(m_gid,uid);
|
||||||
|
m_known_members.add(key); // update the cache to reflect reality
|
||||||
|
if (m_known_nonmembers!=null)
|
||||||
|
m_known_nonmembers.remove(key);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
} // end addUIDInternal
|
||||||
|
|
||||||
|
private final boolean removeUIDInternal(int uid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Integer key = new Integer(uid);
|
||||||
|
synchronized (m_members_sync)
|
||||||
|
{ // look in the cache first
|
||||||
|
if (m_known_nonmembers!=null)
|
||||||
|
{ // are we a known nonmember?
|
||||||
|
if (m_known_nonmembers.contains(key))
|
||||||
|
return false; // already a nonmember
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // in this circumstance, everyone not in the members set is a nonmember
|
||||||
|
if (!(m_known_members.contains(key)))
|
||||||
|
return false; // already a nonmember
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
// fiddle the database
|
||||||
|
boolean rc = m_ops.removeMember(m_gid,uid);
|
||||||
|
m_known_members.remove(key); // update the cache to reflect reality
|
||||||
|
if (m_known_nonmembers!=null)
|
||||||
|
m_known_nonmembers.add(key);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
} // end removeUIDInternal
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface Principal
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean equals(Object another)
|
||||||
|
{
|
||||||
|
if (another==null)
|
||||||
|
return false;
|
||||||
|
if (another instanceof DynamoGroup)
|
||||||
|
return (m_gid==((DynamoGroup)another).getGID());
|
||||||
|
return false;
|
||||||
|
|
||||||
|
} // end equals
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "group " + m_groupname;
|
||||||
|
|
||||||
|
} // end toString
|
||||||
|
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return m_gid;
|
||||||
|
|
||||||
|
} // end hashCode
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return m_groupname;
|
||||||
|
|
||||||
|
} // end getName
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface Group
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean addMember(Principal user)
|
||||||
|
{
|
||||||
|
testOperationWithoutSecurity();
|
||||||
|
try
|
||||||
|
{ // break down the operations...
|
||||||
|
if (user instanceof DynamoUser)
|
||||||
|
return this.addUIDInternal(((DynamoUser)user).getUID());
|
||||||
|
else if (user instanceof DynamoGroup)
|
||||||
|
{ // add all UIDs contained in this group
|
||||||
|
int[] uids = ((DynamoGroup)user).getUIDs();
|
||||||
|
boolean rc = false;
|
||||||
|
for (int i=0; i<uids.length; i++)
|
||||||
|
rc = this.addUIDInternal(uids[i]) || rc;
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end else if
|
||||||
|
else
|
||||||
|
throw new IllegalArgumentException("expected DynamoUser or DynamoGroup");
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (DatabaseException e)
|
||||||
|
{ // wrap this exception and return it
|
||||||
|
throw new GroupRuntimeException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end addMember
|
||||||
|
|
||||||
|
public boolean removeMember(Principal user)
|
||||||
|
{
|
||||||
|
testOperationWithoutSecurity();
|
||||||
|
try
|
||||||
|
{ // break down the operations...
|
||||||
|
if (user instanceof DynamoUser)
|
||||||
|
return this.removeUIDInternal(((DynamoUser)user).getUID());
|
||||||
|
else if (user instanceof DynamoGroup)
|
||||||
|
{ // remove all UIDs contained in this group
|
||||||
|
int[] uids = ((DynamoGroup)user).getUIDs();
|
||||||
|
boolean rc = false;
|
||||||
|
for (int i=0; i<uids.length; i++)
|
||||||
|
rc = this.removeUIDInternal(uids[i]) || rc;
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end else if
|
||||||
|
else
|
||||||
|
throw new IllegalArgumentException("expected DynamoUser or DynamoGroup");
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (DatabaseException e)
|
||||||
|
{ // wrap this exception and return it
|
||||||
|
throw new GroupRuntimeException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end removeMember
|
||||||
|
|
||||||
|
public boolean isMember(Principal member)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // break down the operations...
|
||||||
|
if (member instanceof DynamoUser)
|
||||||
|
return this.testUID(((DynamoUser)member).getUID());
|
||||||
|
else if (member instanceof DynamoGroup)
|
||||||
|
{ // test all UIDs contained within this group
|
||||||
|
int[] uids = ((DynamoGroup)member).getUIDs();
|
||||||
|
if (uids.length==0)
|
||||||
|
return false;
|
||||||
|
boolean rc = true;
|
||||||
|
for (int i=0; rc && (i<uids.length); i++)
|
||||||
|
rc = this.testUID(uids[i]);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end else if
|
||||||
|
else
|
||||||
|
throw new IllegalArgumentException("expected DynamoUser or DynamoGroup");
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (DatabaseException e)
|
||||||
|
{ // wrap this exception and return it
|
||||||
|
throw new GroupRuntimeException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end isMember
|
||||||
|
|
||||||
|
public Enumeration members()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // call down, get the UIDs, and use them to get proxies
|
||||||
|
int[] uids = this.getUIDs();
|
||||||
|
ArrayList tmp = new ArrayList(uids.length);
|
||||||
|
for (int i=0; i<uids.length; i++)
|
||||||
|
tmp.add(m_upm.getUserProxy(uids[i]));
|
||||||
|
return Collections.enumeration(tmp);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (DatabaseException e)
|
||||||
|
{ // wrap this exception and return it
|
||||||
|
throw new GroupRuntimeException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end members
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ObjectProvider
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an object from this <CODE>ObjectProvider</CODE>.
|
||||||
|
*
|
||||||
|
* @param namespace The namespace to interpret the name relative to.
|
||||||
|
* @param name The name of the object to be retrieved.
|
||||||
|
* @return The object reference specified.
|
||||||
|
*/
|
||||||
|
public Object getObject(String namespace, String name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ // convert the namespace name to an ID here
|
||||||
|
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||||
|
Object rc = null;
|
||||||
|
synchronized (m_properties_sync)
|
||||||
|
{ // start by looking in the properties map
|
||||||
|
rc = m_properties.get(key);
|
||||||
|
if (rc==null)
|
||||||
|
{ // no use - need to try the database
|
||||||
|
rc = m_ops.getProperty(m_gid,key);
|
||||||
|
if (rc!=null)
|
||||||
|
m_properties.put(key,rc);
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
if (rc==null)
|
||||||
|
throw new NoSuchObjectException(this.toString(),namespace,name);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (DatabaseException e)
|
||||||
|
{ // translate into our NoSuchObjectException but retain the DatabaseException
|
||||||
|
throw new NoSuchObjectException(this.toString(),namespace,name,e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end getObject
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface SecureObjectStore
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Object setObject(DynamoUser caller, String namespace, String name, Object value)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,namespace,"set.property","sec.setGroupProperty");
|
||||||
|
Object rc = null;
|
||||||
|
// convert the namespace name to an ID here
|
||||||
|
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||||
|
synchronized (m_properties_sync)
|
||||||
|
{ // start by setting the database value
|
||||||
|
rc = m_ops.setProperty(m_gid,key,value);
|
||||||
|
|
||||||
|
// and cache it, too
|
||||||
|
m_properties.put(key,value);
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end setObject
|
||||||
|
|
||||||
|
public Object removeObject(DynamoUser caller, String namespace, String name)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,namespace,"remove.property","sec.removeGroupProperty");
|
||||||
|
Object rc = null;
|
||||||
|
// convert the namespace name to an ID here
|
||||||
|
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||||
|
synchronized (m_properties_sync)
|
||||||
|
{ // start by killing the database value
|
||||||
|
rc = m_ops.removeProperty(m_gid,key);
|
||||||
|
|
||||||
|
// and remove the cached value, too
|
||||||
|
m_properties.remove(key);
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end removeObject
|
||||||
|
|
||||||
|
public Collection getNamespaces() throws DatabaseException
|
||||||
|
{
|
||||||
|
// call through to the database to get the list of namespace IDs
|
||||||
|
int[] ids = m_ops.getPropertyNamespaceIDs(m_gid);
|
||||||
|
|
||||||
|
ArrayList rc = new ArrayList(ids.length);
|
||||||
|
for (int i=0; i<ids.length; i++)
|
||||||
|
rc.add(m_ns_cache.namespaceIdToName(ids[i]));
|
||||||
|
return Collections.unmodifiableList(rc);
|
||||||
|
|
||||||
|
} // end getNamespaces
|
||||||
|
|
||||||
|
public Collection getNamesForNamespace(String namespace) throws DatabaseException
|
||||||
|
{
|
||||||
|
// call through to the database to get the data for this namespace
|
||||||
|
int nsid = m_ns_cache.namespaceNameToId(namespace);
|
||||||
|
Map data = m_ops.getAllProperties(m_gid,nsid);
|
||||||
|
|
||||||
|
// we both create the return value and cache the data values
|
||||||
|
ArrayList rc = new ArrayList(data.size());
|
||||||
|
synchronized (m_properties_sync)
|
||||||
|
{ // do the transfer...
|
||||||
|
Iterator it = data.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{ // copy one entry at a time
|
||||||
|
Map.Entry ntry = (Map.Entry)(it.next());
|
||||||
|
rc.add(ntry.getKey().toString());
|
||||||
|
m_properties.put(new PropertyKey(nsid,ntry.getKey().toString()),ntry.getValue());
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
return Collections.unmodifiableList(rc);
|
||||||
|
|
||||||
|
} // end getNamesForNamespace
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface DynamoGroup
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int getGID()
|
||||||
|
{
|
||||||
|
return m_gid;
|
||||||
|
|
||||||
|
} // end getGID
|
||||||
|
|
||||||
|
public boolean addUID(DynamoUser caller, int uid) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,uid,PERM_NAMESPACE,"add.member","join.group","sec.addGroupMember");
|
||||||
|
return addUIDInternal(uid);
|
||||||
|
|
||||||
|
} // end addUID
|
||||||
|
|
||||||
|
public boolean removeUID(DynamoUser caller, int uid) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,uid,PERM_NAMESPACE,"remove.member","unjoin.group","sec.removeGroupMember");
|
||||||
|
return removeUIDInternal(uid);
|
||||||
|
|
||||||
|
} // end removeUID
|
||||||
|
|
||||||
|
public boolean testUID(int uid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Integer key = new Integer(uid);
|
||||||
|
synchronized (m_members_sync)
|
||||||
|
{ // look in the cache first
|
||||||
|
if (m_known_members.contains(key))
|
||||||
|
return true;
|
||||||
|
if ((m_known_nonmembers==null) || m_known_nonmembers.contains(key))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// try the database
|
||||||
|
boolean rc = m_ops.testMember(m_gid,uid);
|
||||||
|
if (rc) // add cached information
|
||||||
|
m_known_members.add(key);
|
||||||
|
else if (m_known_nonmembers!=null)
|
||||||
|
m_known_nonmembers.add(key);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
} // end testUID
|
||||||
|
|
||||||
|
public int[] getUIDs() throws DatabaseException
|
||||||
|
{
|
||||||
|
int[] rc = null;
|
||||||
|
synchronized (m_members_sync)
|
||||||
|
{ // try the cache first
|
||||||
|
if (m_known_nonmembers==null)
|
||||||
|
{ // we know we already contain the complete members list, so just get that
|
||||||
|
rc = new int[m_known_members.size()];
|
||||||
|
int i = 0;
|
||||||
|
Iterator it = m_known_members.iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
rc[i++] = ((Integer)(it.next())).intValue();
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // have to call down to the database to get the list
|
||||||
|
rc = m_ops.getMembers(m_gid);
|
||||||
|
|
||||||
|
// now we can cache the entire array and dump the nonmembers cache
|
||||||
|
for (int i=0; i<rc.length; i++)
|
||||||
|
m_known_members.add(new Integer(rc[i]));
|
||||||
|
m_known_nonmembers.clear();
|
||||||
|
m_known_nonmembers = null;
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
} // end synchronized block
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end getUIDs
|
||||||
|
|
||||||
|
public boolean addMember(DynamoUser caller, Principal member)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,getPrincipalUID(member),PERM_NAMESPACE,"add.member","join.group",
|
||||||
|
"sec.addGroupMember");
|
||||||
|
if (member instanceof DynamoUser)
|
||||||
|
return this.addUIDInternal(((DynamoUser)member).getUID());
|
||||||
|
else if (member instanceof DynamoGroup)
|
||||||
|
{ // add all UIDs contained in this group
|
||||||
|
int[] uids = ((DynamoGroup)member).getUIDs();
|
||||||
|
boolean rc = false;
|
||||||
|
for (int i=0; i<uids.length; i++)
|
||||||
|
rc = this.addUIDInternal(uids[i]) || rc;
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end else if
|
||||||
|
else
|
||||||
|
throw new IllegalArgumentException("expected DynamoUser or DynamoGroup");
|
||||||
|
|
||||||
|
} // end addMember
|
||||||
|
|
||||||
|
public boolean removeMember(DynamoUser caller, Principal member)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testPermission(caller,getPrincipalUID(member),PERM_NAMESPACE,"remove.member","unjoin.group",
|
||||||
|
"sec.removeGroupMember");
|
||||||
|
if (member instanceof DynamoUser)
|
||||||
|
return this.removeUIDInternal(((DynamoUser)member).getUID());
|
||||||
|
else if (member instanceof DynamoGroup)
|
||||||
|
{ // remove all UIDs contained in this group
|
||||||
|
int[] uids = ((DynamoGroup)member).getUIDs();
|
||||||
|
boolean rc = false;
|
||||||
|
for (int i=0; i<uids.length; i++)
|
||||||
|
rc = this.removeUIDInternal(uids[i]) || rc;
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end else if
|
||||||
|
else
|
||||||
|
throw new IllegalArgumentException("expected DynamoUser or DynamoGroup");
|
||||||
|
|
||||||
|
} // end removeMember
|
||||||
|
|
||||||
|
public DynamoAcl getAcl() throws DatabaseException, AclNotFoundException
|
||||||
|
{
|
||||||
|
if (m_gaclid==-1)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return m_srm.getAcl(m_gaclid);
|
||||||
|
|
||||||
|
} // end getAcl
|
||||||
|
|
||||||
|
public void setAcl(DynamoUser caller, DynamoAcl acl) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
testAclOwner(caller);
|
||||||
|
int new_id = ((acl==null) ? -1 : acl.getAclID());
|
||||||
|
m_ops.setAclID(m_gid,new_id);
|
||||||
|
m_gaclid = new_id;
|
||||||
|
|
||||||
|
} // end setAcl
|
||||||
|
|
||||||
|
} // end class GroupObject
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
abstract class GroupObjectOps extends OpsBase
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected GroupObjectOps(DBConnectionPool pool)
|
||||||
|
{
|
||||||
|
super(pool);
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Abstract operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
abstract Object getProperty(int gid, PropertyKey key) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract Object setProperty(int gid, PropertyKey key, Object value) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract Object removeProperty(int gid, PropertyKey key) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract int[] getPropertyNamespaceIDs(int gid) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract Map getAllProperties(int gid, int namespace) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract boolean testMember(int gid, int uid) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract boolean addMember(int gid, int uid) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract boolean removeMember(int gid, int uid) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract int[] getMembers(int gid) throws DatabaseException;
|
||||||
|
|
||||||
|
abstract void setAclID(int gid, int aclid) throws DatabaseException;
|
||||||
|
|
||||||
|
} // end class GroupObjectOps
|
|
@ -0,0 +1,556 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.util.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
import com.silverwrist.dynamo.util.*;
|
||||||
|
|
||||||
|
class GroupObjectOps_mysql extends GroupObjectOps
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private DBUtilities m_utils;
|
||||||
|
private PropertySerializer m_psz;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
GroupObjectOps_mysql(DBConnectionPool pool, DBUtilities utils)
|
||||||
|
{
|
||||||
|
super(pool);
|
||||||
|
m_utils = utils;
|
||||||
|
m_psz = (PropertySerializer)(pool.queryService(PropertySerializer.class));
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Abstract implementations from class GroupObjectOps
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
Object getProperty(int gid, PropertyKey key) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
String rc_str = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// look up the property
|
||||||
|
stmt = conn.prepareStatement("SELECT prop_value FROM groupprop WHERE gid = ? AND nsid = ? "
|
||||||
|
+ "AND prop_name = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,key.getNamespaceID());
|
||||||
|
stmt.setString(3,key.getName());
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (!(rs.next()))
|
||||||
|
return null; // property not found
|
||||||
|
|
||||||
|
rc_str = rs.getString(1);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
// Deserialize the property value.
|
||||||
|
Object rc = m_psz.deserializeProperty(rc_str);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
// deserialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GroupObjectOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.deserialize");
|
||||||
|
de.setParameter(0,key.getName());
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end getProperty
|
||||||
|
|
||||||
|
Object setProperty(int gid, PropertyKey key, Object value) throws DatabaseException
|
||||||
|
{
|
||||||
|
String serialized_value = m_psz.serializeProperty(value);
|
||||||
|
if (serialized_value==null)
|
||||||
|
{ // serialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GroupObjectOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.serialize");
|
||||||
|
de.setParameter(0,key.getName());
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
String old_value = null;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Statement stmt2 = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// lock the table
|
||||||
|
stmt2 = conn.createStatement();
|
||||||
|
stmt2.executeUpdate("LOCK TABLES groupprop WRITE;");
|
||||||
|
|
||||||
|
// look to see if the property value is already there
|
||||||
|
stmt = conn.prepareStatement("SELECT prop_value FROM groupprop WHERE gid = ? AND nsid = ? "
|
||||||
|
+ "AND prop_name = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,key.getNamespaceID());
|
||||||
|
stmt.setString(3,key.getName());
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (rs.next())
|
||||||
|
old_value = rs.getString(1);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
rs = null;
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
|
||||||
|
if (old_value!=null)
|
||||||
|
{ // prepare the statement to update the existing record
|
||||||
|
stmt = conn.prepareStatement("UPDATE groupprop SET prop_value = ? WHERE gid = ? "
|
||||||
|
+ "AND nsid = ? AND prop_name = ?;");
|
||||||
|
stmt.setString(1,serialized_value);
|
||||||
|
stmt.setInt(2,gid);
|
||||||
|
stmt.setInt(3,key.getNamespaceID());
|
||||||
|
stmt.setString(4,key.getName());
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
else
|
||||||
|
{ // prepare the statement to insert a new record
|
||||||
|
stmt = conn.prepareStatement("INSERT INTO groupprop (gid, nsid, prop_name, prop_value) "
|
||||||
|
+ "VALUES (?, ?, ?, ?);");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,key.getNamespaceID());
|
||||||
|
stmt.setString(3,key.getName());
|
||||||
|
stmt.setString(4,serialized_value);
|
||||||
|
|
||||||
|
} // end else
|
||||||
|
|
||||||
|
stmt.executeUpdate(); // execute it!
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
MySQLUtils.unlockTables(conn);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(stmt2);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
if (old_value==null)
|
||||||
|
return null; // no previous value
|
||||||
|
|
||||||
|
// Deserialize the property value.
|
||||||
|
Object rc = m_psz.deserializeProperty(old_value);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
// deserialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GroupObjectOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.deserialize");
|
||||||
|
de.setParameter(0,key.getName());
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end setProperty
|
||||||
|
|
||||||
|
Object removeProperty(int gid, PropertyKey key) throws DatabaseException
|
||||||
|
{
|
||||||
|
String old_value = null;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Statement stmt2 = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// lock the table
|
||||||
|
stmt2 = conn.createStatement();
|
||||||
|
stmt2.executeUpdate("LOCK TABLES groupprop WRITE;");
|
||||||
|
|
||||||
|
// look to see if the property value is already there
|
||||||
|
stmt = conn.prepareStatement("SELECT prop_value FROM groupprop WHERE gid = ? AND nsid = ? "
|
||||||
|
+ "AND prop_name = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,key.getNamespaceID());
|
||||||
|
stmt.setString(3,key.getName());
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (rs.next())
|
||||||
|
old_value = rs.getString(1);
|
||||||
|
else
|
||||||
|
return null; // no need to remove anything
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
rs = null;
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
|
||||||
|
// delete the database row
|
||||||
|
stmt = conn.prepareStatement("DELETE FROM groupprop WHERE gid = ? AND nsid = ? AND prop_name = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,key.getNamespaceID());
|
||||||
|
stmt.setString(3,key.getName());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
MySQLUtils.unlockTables(conn);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(stmt2);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
// Deserialize the property value.
|
||||||
|
Object rc = m_psz.deserializeProperty(old_value);
|
||||||
|
if (rc!=null)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
// deserialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GroupObjectOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.deserialize");
|
||||||
|
de.setParameter(0,key.getName());
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end removeProperty
|
||||||
|
|
||||||
|
int[] getPropertyNamespaceIDs(int gid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// execute the query!
|
||||||
|
stmt = conn.prepareStatement("SELECT DISTINCT nsid FROM groupprop WHERE gid = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
// read out a list of the namespace IDs
|
||||||
|
ArrayList tmp = new ArrayList();
|
||||||
|
while (rs.next())
|
||||||
|
tmp.add(new Integer(rs.getInt(1)));
|
||||||
|
|
||||||
|
// create and return the array
|
||||||
|
int[] rc = new int[tmp.size()];
|
||||||
|
for (int i=0; i<tmp.size(); i++)
|
||||||
|
rc[i] = ((Integer)(tmp.get(i))).intValue();
|
||||||
|
tmp.clear();
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end getPropertyNamespaceIDs
|
||||||
|
|
||||||
|
Map getAllProperties(int gid, int namespace) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// execute the query!
|
||||||
|
stmt = conn.prepareStatement("SELECT prop_name, prop_value FROM groupprop WHERE gid = ? AND nsid = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,namespace);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
// prepare the return value
|
||||||
|
HashMap rc = new HashMap();
|
||||||
|
while (rs.next())
|
||||||
|
{ // copy data out, deserializing properties as we go
|
||||||
|
String key = rs.getString(1);
|
||||||
|
Object value = m_psz.deserializeProperty(rs.getString(2));
|
||||||
|
if (value==null)
|
||||||
|
{ // deserialization exception - throw it
|
||||||
|
DatabaseException de = new DatabaseException(GroupObjectOps_mysql.class,"DatabaseMessages",
|
||||||
|
"property.deserialize");
|
||||||
|
de.setParameter(0,key);
|
||||||
|
throw de;
|
||||||
|
|
||||||
|
} // end if
|
||||||
|
|
||||||
|
rc.put(key,value);
|
||||||
|
|
||||||
|
} // end while
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end getAllProperties
|
||||||
|
|
||||||
|
boolean testMember(int gid, int uid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// execute a query
|
||||||
|
stmt = conn.prepareStatement("SELECT uid FROM groupmembers WHERE gid = ? AND uid = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,uid);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
return rs.next();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end testMember
|
||||||
|
|
||||||
|
boolean addMember(int gid, int uid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Statement stmt2 = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// lock the table
|
||||||
|
stmt2 = conn.createStatement();
|
||||||
|
stmt2.executeUpdate("LOCK TABLES groupmembers WRITE;");
|
||||||
|
|
||||||
|
// see if we're already in the members list
|
||||||
|
stmt = conn.prepareStatement("SELECT uid FROM groupmembers WHERE gid = ? AND uid = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,uid);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (rs.next())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// close statement in prep for next one
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
rs = null;
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
|
||||||
|
// insert the member ID!
|
||||||
|
stmt = conn.prepareStatement("INSERT INTO groupmembers (gid, uid) VALUES (?, ?);");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,uid);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
MySQLUtils.unlockTables(conn);
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(stmt2);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end addMember
|
||||||
|
|
||||||
|
boolean removeMember(int gid, int uid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Statement stmt2 = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// lock the table
|
||||||
|
stmt2 = conn.createStatement();
|
||||||
|
stmt2.executeUpdate("LOCK TABLES groupmembers WRITE;");
|
||||||
|
|
||||||
|
// execute the deletion!
|
||||||
|
stmt = conn.prepareStatement("DELETE FROM groupmembers WHERE gid = ? AND uid = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
stmt.setInt(2,uid);
|
||||||
|
return (stmt.executeUpdate()>0);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
MySQLUtils.unlockTables(conn);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(stmt2);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end removeMember
|
||||||
|
|
||||||
|
int[] getMembers(int gid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
ArrayList tmp = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// create a query to get all the UIDs
|
||||||
|
stmt = conn.prepareStatement("SELECT uid FROM groupmembers WHERE gid = ?;");
|
||||||
|
stmt.setInt(1,gid);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
// fill the intermediate ArrayList
|
||||||
|
tmp = new ArrayList();
|
||||||
|
while (rs.next())
|
||||||
|
tmp.add(new Integer(rs.getInt(1)));
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
SQLUtils.shutdown(rs);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
// now translate into an integer array
|
||||||
|
int[] rc = new int[tmp.size()];
|
||||||
|
for (int i=0; i<tmp.size(); i++)
|
||||||
|
rc[i] = ((Integer)(tmp.get(i))).intValue();
|
||||||
|
tmp.clear();
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end getMembers
|
||||||
|
|
||||||
|
void setAclID(int gid, int aclid) throws DatabaseException
|
||||||
|
{
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
Statement stmt2 = null;
|
||||||
|
try
|
||||||
|
{ // get a connection
|
||||||
|
conn = getConnection();
|
||||||
|
|
||||||
|
// lock the table
|
||||||
|
stmt2 = conn.createStatement();
|
||||||
|
stmt2.executeUpdate("LOCK TABLES groups WRITE;");
|
||||||
|
|
||||||
|
// prepare and execute the statement
|
||||||
|
stmt = conn.prepareStatement("UPDATE groups SET gaclid = ? WHERE gid = ?;");
|
||||||
|
stmt.setInt(1,aclid);
|
||||||
|
stmt.setInt(2,gid);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (SQLException e)
|
||||||
|
{ // translate to a general DatabaseException
|
||||||
|
throw generalException(e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // shut everything down
|
||||||
|
MySQLUtils.unlockTables(conn);
|
||||||
|
SQLUtils.shutdown(stmt);
|
||||||
|
SQLUtils.shutdown(stmt2);
|
||||||
|
SQLUtils.shutdown(conn);
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
} // end setAclID
|
||||||
|
|
||||||
|
} // end class GroupObjectOps_mysql
|
249
src/dynamo-framework/com/silverwrist/dynamo/db/GroupProxy.java
Normal file
249
src/dynamo-framework/com/silverwrist/dynamo/db/GroupProxy.java
Normal file
|
@ -0,0 +1,249 @@
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||||
|
* (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.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||||
|
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||||
|
* language governing rights and limitations under the License.
|
||||||
|
*
|
||||||
|
* The Original Code is the Venice Web Communities System.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||||
|
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||||
|
* Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
package com.silverwrist.dynamo.db;
|
||||||
|
|
||||||
|
import java.security.Principal;
|
||||||
|
import java.security.acl.AclNotFoundException;
|
||||||
|
import java.util.*;
|
||||||
|
import com.silverwrist.dynamo.except.*;
|
||||||
|
import com.silverwrist.dynamo.iface.*;
|
||||||
|
|
||||||
|
abstract class GroupProxy implements DynamoGroup, DynamicWrapper
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected int m_gid;
|
||||||
|
protected String m_groupname;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructors
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected GroupProxy(int gid)
|
||||||
|
{
|
||||||
|
m_gid = gid;
|
||||||
|
m_groupname = null;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
protected GroupProxy(int gid, String groupname)
|
||||||
|
{
|
||||||
|
m_gid = gid;
|
||||||
|
m_groupname = groupname;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Abstract operations
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected abstract DynamoGroup getRealGroup();
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface Principal
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean equals(Object another)
|
||||||
|
{
|
||||||
|
if (another==null)
|
||||||
|
return false;
|
||||||
|
if (another instanceof DynamoGroup)
|
||||||
|
return (m_gid==((DynamoGroup)another).getGID());
|
||||||
|
return false;
|
||||||
|
|
||||||
|
} // end equals
|
||||||
|
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
if (m_groupname!=null)
|
||||||
|
return "group " + m_groupname;
|
||||||
|
return getRealGroup().toString();
|
||||||
|
|
||||||
|
} // end toString
|
||||||
|
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return m_gid;
|
||||||
|
|
||||||
|
} // end hashCode
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
if (m_groupname!=null)
|
||||||
|
return m_groupname;
|
||||||
|
return getRealGroup().getName();
|
||||||
|
|
||||||
|
} // end getName
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface Group
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean addMember(Principal user)
|
||||||
|
{
|
||||||
|
return getRealGroup().addMember(user);
|
||||||
|
|
||||||
|
} // end addMember
|
||||||
|
|
||||||
|
public boolean removeMember(Principal user)
|
||||||
|
{
|
||||||
|
return getRealGroup().removeMember(user);
|
||||||
|
|
||||||
|
} // end removeMember
|
||||||
|
|
||||||
|
public boolean isMember(Principal member)
|
||||||
|
{
|
||||||
|
return getRealGroup().isMember(member);
|
||||||
|
|
||||||
|
} // end isMember
|
||||||
|
|
||||||
|
public Enumeration members()
|
||||||
|
{
|
||||||
|
return getRealGroup().members();
|
||||||
|
|
||||||
|
} // end members
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface ObjectProvider
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an object from this <CODE>ObjectProvider</CODE>.
|
||||||
|
*
|
||||||
|
* @param namespace The namespace to interpret the name relative to.
|
||||||
|
* @param name The name of the object to be retrieved.
|
||||||
|
* @return The object reference specified.
|
||||||
|
*/
|
||||||
|
public Object getObject(String namespace, String name)
|
||||||
|
{
|
||||||
|
return getRealGroup().getObject(namespace,name);
|
||||||
|
|
||||||
|
} // end getObject
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface SecureObjectStore
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Object setObject(DynamoUser caller, String namespace, String name, Object value)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
return getRealGroup().setObject(caller,namespace,name,value);
|
||||||
|
|
||||||
|
} // end setObject
|
||||||
|
|
||||||
|
public Object removeObject(DynamoUser caller, String namespace, String name)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
return getRealGroup().removeObject(caller,namespace,name);
|
||||||
|
|
||||||
|
} // end removeObject
|
||||||
|
|
||||||
|
public Collection getNamespaces() throws DatabaseException
|
||||||
|
{
|
||||||
|
return getRealGroup().getNamespaces();
|
||||||
|
|
||||||
|
} // end getNamespaces
|
||||||
|
|
||||||
|
public Collection getNamesForNamespace(String namespace) throws DatabaseException
|
||||||
|
{
|
||||||
|
return getRealGroup().getNamesForNamespace(namespace);
|
||||||
|
|
||||||
|
} // end getNamesForNamespace
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface DynamoGroup
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int getGID()
|
||||||
|
{
|
||||||
|
return m_gid;
|
||||||
|
|
||||||
|
} // end getGID
|
||||||
|
|
||||||
|
public boolean addUID(DynamoUser caller, int uid) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
return getRealGroup().addUID(caller,uid);
|
||||||
|
|
||||||
|
} // end addUID
|
||||||
|
|
||||||
|
public boolean removeUID(DynamoUser caller, int uid) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
return getRealGroup().removeUID(caller,uid);
|
||||||
|
|
||||||
|
} // end removeUID
|
||||||
|
|
||||||
|
public boolean testUID(int uid) throws DatabaseException
|
||||||
|
{
|
||||||
|
return getRealGroup().testUID(uid);
|
||||||
|
|
||||||
|
} // end testUID
|
||||||
|
|
||||||
|
public int[] getUIDs() throws DatabaseException
|
||||||
|
{
|
||||||
|
return getRealGroup().getUIDs();
|
||||||
|
|
||||||
|
} // end getUIDs
|
||||||
|
|
||||||
|
public boolean addMember(DynamoUser caller, Principal member)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
return getRealGroup().addMember(caller,member);
|
||||||
|
|
||||||
|
} // end addMember
|
||||||
|
|
||||||
|
public boolean removeMember(DynamoUser caller, Principal member)
|
||||||
|
throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
return getRealGroup().removeMember(caller,member);
|
||||||
|
|
||||||
|
} // end removeMember
|
||||||
|
|
||||||
|
public DynamoAcl getAcl() throws DatabaseException, AclNotFoundException
|
||||||
|
{
|
||||||
|
return getRealGroup().getAcl();
|
||||||
|
|
||||||
|
} // end getAcl
|
||||||
|
|
||||||
|
public void setAcl(DynamoUser caller, DynamoAcl acl) throws DatabaseException, DynamoSecurityException
|
||||||
|
{
|
||||||
|
getRealGroup().setAcl(caller,acl);
|
||||||
|
|
||||||
|
} // end setAcl
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Implementations from interface DynamicWrapper
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Object unwrap()
|
||||||
|
{
|
||||||
|
return getRealGroup();
|
||||||
|
|
||||||
|
} // end unwrap
|
||||||
|
|
||||||
|
} // end class GroupProxy
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user