Compare commits
2 Commits
master
...
userinfo_g
| Author | SHA1 | Date |
|---|---|---|
|
|
b93642403d | 2 years ago |
|
|
3935ddfd5b | 2 years ago |
2507 changed files with 497841 additions and 2007504 deletions
@ -1,16 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
|
||||||
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> |
|
||||||
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="get_git_info,"/> |
|
||||||
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="get_git_info,"/> |
|
||||||
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> |
|
||||||
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> |
|
||||||
<booleanAttribute key="org.eclipse.debug.core.ATTR_REFRESH_RECURSIVE" value="false"/> |
|
||||||
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <resources/>}"/> |
|
||||||
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> |
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> |
|
||||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> |
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="superx"/> |
|
||||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="/home/superx/git/kern/superx-build/build.xml"/> |
|
||||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/> |
|
||||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> |
|
||||||
</launchConfiguration> |
|
||||||
@ -1,270 +1,46 @@ |
|||||||
# agent and copilot context - local/temporary files |
# ignore all log files |
||||||
.github/ |
*.log |
||||||
|
*.err |
||||||
|
*.log.* |
||||||
|
|
||||||
# Gradle build output and wrapper cache |
|
||||||
build/ |
|
||||||
.gradle/ |
|
||||||
|
|
||||||
# ignore /dist/* |
# ignore all CVS + sub dirs |
||||||
*dist/ |
*CVS/ |
||||||
|
|
||||||
# ignore swap files |
|
||||||
superx/WEB-INF/reports/swap_* |
|
||||||
|
|
||||||
# ignore eclipse settings |
|
||||||
.settings/org.eclipse.ltk.core.refactoring.prefs |
|
||||||
|
|
||||||
# vim .swp files |
|
||||||
*.swp |
|
||||||
|
|
||||||
# ignore gradle bin |
|
||||||
scripts/gradle/bin/ |
|
||||||
scripts/gradle/.gradle/ |
|
||||||
|
|
||||||
# cobertura |
|
||||||
superx-build/cobertura* |
|
||||||
|
|
||||||
# classes |
|
||||||
superx/WEB-INF/classes/ |
|
||||||
|
|
||||||
# tag files |
|
||||||
**/tags |
|
||||||
|
|
||||||
# .orig files |
|
||||||
**/*.orig |
|
||||||
|
|
||||||
# datum.alt files |
|
||||||
**/superx.datum.alt |
|
||||||
|
|
||||||
# script artefacts |
|
||||||
scripts/**/build/ |
|
||||||
scripts/**/log/ |
|
||||||
|
|
||||||
# build artefacts |
|
||||||
superx-build/declared-jars.txt |
|
||||||
superx-build/cobertura_build_tests/ |
|
||||||
superx-build/cobertura_build_classes/ |
|
||||||
superx-build/coveragereport/ |
|
||||||
superx-build/results/ |
|
||||||
superx-build/tmp_build/ |
|
||||||
|
|
||||||
# Eclipse launch configurations are causing conflicts on 'pull' if you've got local ones; so they should not be under SCM |
|
||||||
scripts/eclipseExternalTools/ |
|
||||||
|
|
||||||
# extracted h1-modules. These should only be links to folders in cs.bia.his_components |
|
||||||
src-modules/module/prom/ |
|
||||||
src-modules/module/res/ |
|
||||||
src-modules/module/astat/ |
|
||||||
src-modules/module/tt/ |
|
||||||
src-modules/module/star/ |
|
||||||
src-modules/module/kern_s/ |
|
||||||
src-modules/module/res_s/ |
|
||||||
# also ignore symlinks on linux |
|
||||||
src-modules/module/prom |
|
||||||
src-modules/module/res |
|
||||||
src-modules/module/astat |
|
||||||
src-modules/module/tt |
|
||||||
src-modules/module/star |
|
||||||
src-modules/module/kern_s |
|
||||||
src-modules/module/res_s |
|
||||||
src-modules/module/biad |
|
||||||
|
|
||||||
# artifact folders for reduced/cleaned modules |
|
||||||
superx/WEB-INF/conf/edustore/db/module/prom/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/res/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/zul/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/sos/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/sva/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/ivs/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/astat/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/tt/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/lm/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/etl/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/star/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/cob/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/kern_s/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/res_s/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/bau/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/fin/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/biad/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/gang/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/erfolg/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/man/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/kenn/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/kennx/ |
|
||||||
|
|
||||||
# module generation artifacts for module fin |
|
||||||
src/edustore/edustore_fin.xml |
|
||||||
superx/WEB-INF/fin_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/fin_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module bau |
|
||||||
src/edustore/edustore_bau.xml |
|
||||||
superx/WEB-INF/bau_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/bau_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module prom |
|
||||||
src/edustore/edustore_prom.xml |
|
||||||
superx/WEB-INF/prom_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/prom_dbforms-config_pg.xml |
|
||||||
superx/edit/prom/ |
|
||||||
|
|
||||||
# module generation artifacts for module res |
|
||||||
src/edustore/edustore_res.xml |
|
||||||
superx/WEB-INF/res_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/res_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module gang |
|
||||||
src/edustore/edustore_gang.xml |
|
||||||
superx/WEB-INF/gang_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/gang_dbforms-config_pg.xml |
|
||||||
superx/edit/gang/*edit.jsp |
|
||||||
superx/edit/gang/*list.jsp |
|
||||||
|
|
||||||
|
# ignore java classes |
||||||
|
*classes/ |
||||||
|
|
||||||
# module generation artifacts for module kenn |
# ignore files in directory rohdaten |
||||||
src/edustore/edustore_kenn.xml |
superx/WEB-INF/conf/edustore/db/module/*/rohdaten/unl/*.unl |
||||||
superx/WEB-INF/kenn_dbforms-config_ids.xml |
superx/WEB-INF/conf/edustore/db/install/rohdaten/unl/*.unl |
||||||
superx/WEB-INF/kenn_dbforms-config_pg.xml |
|
||||||
superx/edit/kenn/*edit.jsp |
|
||||||
superx/edit/kenn/*list.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module kennx |
# ignore temporary files |
||||||
src/edustore/edustore_kennx.xml |
*.tmp |
||||||
superx/WEB-INF/kennx_dbforms-config_ids.xml |
*.tmp.sql |
||||||
superx/WEB-INF/kennx_dbforms-config_pg.xml |
temp.xml |
||||||
superx/edit/kennx/*edit.jsp |
tmp.fo |
||||||
superx/edit/kennx/*list.jsp |
|
||||||
|
|
||||||
|
# ignore auto generated files |
||||||
|
db.properties |
||||||
|
dbforms-config.xml |
||||||
|
superx/WEB-INF/dbforms-config.old |
||||||
|
superx.datum |
||||||
|
|
||||||
# module generation artifacts for module man |
# ignore iReport Designer |
||||||
src/edustore/edustore_man.xml |
*.jasper |
||||||
superx/WEB-INF/man_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/man_dbforms-config_pg.xml |
|
||||||
superx/edit/man/catdesc.jsp |
|
||||||
superx/edit/man/cat.jsp |
|
||||||
superx/edit/man/grouping.jsp |
|
||||||
superx/edit/man/man_reports.jsp |
|
||||||
superx/edit/man/organigramm_dialog.jsp |
|
||||||
superx/edit/man/rpt.jsp |
|
||||||
superx/edit/man/*edit.jsp |
|
||||||
superx/edit/man/*list.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module erfolg |
|
||||||
src/edustore/edustore_erfolg.xml |
|
||||||
superx/WEB-INF/erfolg_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/erfolg_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module sos |
|
||||||
src/edustore/edustore_sos.xml |
|
||||||
superx/WEB-INF/sos_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/sos_dbforms-config_pg.xml |
|
||||||
superx/edit/sos/hoererstatus_edit.jsp |
|
||||||
superx/edit/sos/koepfe_oder_faelle_edit.jsp |
|
||||||
superx/edit/sos/lehr_stg_ab_edit.jsp |
|
||||||
superx/edit/sos/semester_edit.jsp |
|
||||||
superx/edit/sos/semester_list.jsp |
|
||||||
superx/edit/sos/sos_status_edit.jsp |
|
||||||
superx/edit/sos/sos_stichtag_edit.jsp |
|
||||||
superx/edit/sos/sos_stichtag_list.jsp |
|
||||||
superx/edit/sos/statistik_edit.jsp |
|
||||||
superx/edit/sos/studierendenuebertragung_edit.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module sva |
|
||||||
src/edustore/edustore_sva.xml |
|
||||||
superx/WEB-INF/sva_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/sva_dbforms-config_pg.xml |
|
||||||
superx/edit/sva/konstanten_sva_edit.jsp |
|
||||||
superx/edit/sva/sichten_sva_dienstart_edit.jsp |
|
||||||
superx/edit/sva/sichten_sva_klr_geldgeber_kurz_edit.jsp |
|
||||||
superx/edit/sva/sva_stichtag_list.jsp |
|
||||||
superx/edit/sva/sx_repository_sva_edit.jsp |
|
||||||
superx/edit/sva/user_sva.jsp |
|
||||||
superx/edit/sva/user_sva_manuell.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module ivs |
|
||||||
src/edustore/edustore_ivs.xml |
|
||||||
superx/edit/ivs/user_inventar_edit.jsp |
|
||||||
superx/WEB-INF/ivs_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/ivs_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module zul |
|
||||||
src/edustore/edustore_zul.xml |
|
||||||
superx/WEB-INF/zul_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/zul_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module astat |
|
||||||
src/edustore/edustore_astat.xml |
|
||||||
superx/WEB-INF/astat_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/astat_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module tt |
|
||||||
src/edustore/edustore_tt.xml |
|
||||||
superx/WEB-INF/tt_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/tt_dbforms-config_pg.xml |
|
||||||
superx/edit/tt/ |
|
||||||
|
|
||||||
# module generation artifacts for module lm |
|
||||||
src/edustore/edustore_lm.xml |
|
||||||
superx/WEB-INF/lm_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/lm_dbforms-config_pg.xml |
|
||||||
superx/edit/lm/ |
|
||||||
|
|
||||||
# module generation artifacts for module etl |
|
||||||
src/edustore/edustore_etl.xml |
|
||||||
superx/WEB-INF/etl_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/etl_dbforms-config_pg.xml |
|
||||||
superx/edit/etl/etl_job_edit.jsp |
|
||||||
superx/edit/etl/etl_step_edit.jsp |
|
||||||
superx/edit/etl/etl_step_type_list.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module star |
|
||||||
src/edustore/edustore_star.xml |
|
||||||
superx/WEB-INF/star_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/star_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module cob |
|
||||||
src/edustore/edustore_cob.xml |
|
||||||
superx/WEB-INF/cob_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/cob_dbforms-config_pg.xml |
|
||||||
superx/edit/cob/sx_repository_cob_edit.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module kern_s |
|
||||||
src/edustore/edustore_kern_s.xml |
|
||||||
superx/WEB-INF/kern_s_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/kern_s_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module res_s |
|
||||||
src/edustore/edustore_res_s.xml |
|
||||||
superx/WEB-INF/res_s_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/res_s_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module biad |
|
||||||
src/edustore/edustore_biad.xml |
|
||||||
superx/WEB-INF/biad_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/biad_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# dbt project generation backups |
|
||||||
superx/dbt/projects/*_backup/ |
|
||||||
|
|
||||||
# Saiku his icons |
|
||||||
superx/saiku/css/saiku/src/saiku_his.css |
|
||||||
|
|
||||||
# Dateifunktionalität im kenn und kennx Modul |
|
||||||
superx\WEB-INF\downloads |
|
||||||
|
|
||||||
# vscode personal settings |
# ignore /dist/* |
||||||
.vscode/ |
*dist/ |
||||||
.metadata/ |
|
||||||
|
|
||||||
# edustore.xml soll nicht mehr ausgeliefert werden siehe #313658 |
# ignore swap files |
||||||
src/edustore/edustore.xml |
superx/WEB-INF/reports/swap_* |
||||||
|
|
||||||
# package folder und config file für statisch generierte JSPs |
src/edustore/edustore_*.xml |
||||||
src/de/superx/jsp/ |
|
||||||
superx/WEB-INF/jsp_servlet_config.xml |
|
||||||
|
|
||||||
# jaspers werden nicht mehr commitet, sondern im build gebaut |
# ignore eclipse settings |
||||||
*.jasper |
.settings/org.eclipse.ltk.core.refactoring.prefs |
||||||
# updateUnmodifiedJars backup |
#rpta files: |
||||||
superx/WEB-INF/lib/backup/ |
superx/WEB-INF/reports/simple_table.jrtx |
||||||
|
superx/WEB-INF/reports/tabelle_jrxml_a4_quer.xsl.jrxml |
||||||
|
superx/xml/jr_templates.xsl |
||||||
|
superx/xml/rpta_assistent.xsl |
||||||
|
|||||||
@ -1,58 +1,36 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||||
<projectDescription> |
<projectDescription> |
||||||
<name>eduStore_superX</name> |
<name>eduStore_superX</name> |
||||||
<comment></comment> |
<comment></comment> |
||||||
<projects> |
<projects> |
||||||
</projects> |
</projects> |
||||||
<buildSpec> |
<buildSpec> |
||||||
<buildCommand> |
<buildCommand> |
||||||
<name>org.eclipse.jdt.core.javabuilder</name> |
<name>org.eclipse.jdt.core.javabuilder</name> |
||||||
<arguments> |
<arguments> |
||||||
</arguments> |
</arguments> |
||||||
</buildCommand> |
</buildCommand> |
||||||
<buildCommand> |
<buildCommand> |
||||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name> |
<name>org.eclipse.babel.editor.rbeBuilder</name> |
||||||
<triggers>full,incremental,</triggers> |
<arguments> |
||||||
<arguments> |
</arguments> |
||||||
<dictionary> |
</buildCommand> |
||||||
<key>LaunchConfigHandle</key> |
</buildSpec> |
||||||
<value><project>/.externalToolBuilders/Ant Superx Version.launch</value> |
<natures> |
||||||
</dictionary> |
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature> |
||||||
</arguments> |
<nature>org.eclipse.jdt.core.javanature</nature> |
||||||
</buildCommand> |
<nature>com.sysdeo.eclipse.tomcat.tomcatnature</nature> |
||||||
</buildSpec> |
<nature>com.jaspersoft.studio.babel.editor.rbeNature</nature> |
||||||
<natures> |
</natures> |
||||||
<nature>org.eclipse.jdt.core.javanature</nature> |
<filteredResources> |
||||||
<nature>com.sysdeo.eclipse.tomcat.tomcatnature</nature> |
<filter> |
||||||
<nature>com.jaspersoft.studio.babel.editor.rbeNature</nature> |
<id>1459344926910</id> |
||||||
</natures> |
<name></name> |
||||||
<filteredResources> |
<type>10</type> |
||||||
<filter> |
<matcher> |
||||||
<id>1617792163171</id> |
<id>org.eclipse.ui.ide.multiFilter</id> |
||||||
<name></name> |
<arguments>1.0-name-matches-false-false-dist</arguments> |
||||||
<type>10</type> |
</matcher> |
||||||
<matcher> |
</filter> |
||||||
<id>org.eclipse.ui.ide.multiFilter</id> |
</filteredResources> |
||||||
<arguments>1.0-name-matches-false-false-dist</arguments> |
</projectDescription> |
||||||
</matcher> |
|
||||||
</filter> |
|
||||||
<filter> |
|
||||||
<id>1617792163186</id> |
|
||||||
<name></name> |
|
||||||
<type>6</type> |
|
||||||
<matcher> |
|
||||||
<id>org.eclipse.ui.ide.multiFilter</id> |
|
||||||
<arguments>1.0-name-matches-false-true-.+\.class</arguments> |
|
||||||
</matcher> |
|
||||||
</filter> |
|
||||||
<filter> |
|
||||||
<id>1687335947806</id> |
|
||||||
<name></name> |
|
||||||
<type>30</type> |
|
||||||
<matcher> |
|
||||||
<id>org.eclipse.core.resources.regexFilterMatcher</id> |
|
||||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> |
|
||||||
</matcher> |
|
||||||
</filter> |
|
||||||
</filteredResources> |
|
||||||
</projectDescription> |
|
||||||
|
|||||||
@ -1,901 +0,0 @@ |
|||||||
/* |
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
||||||
* |
|
||||||
* Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved. |
|
||||||
* |
|
||||||
* The contents of this file are subject to the terms of either the GNU |
|
||||||
* General Public License Version 2 only ("GPL") or the Common Development |
|
||||||
* and Distribution License("CDDL") (collectively, the "License"). You |
|
||||||
* may not use this file except in compliance with the License. You can |
|
||||||
* obtain a copy of the License at |
|
||||||
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
|
|
||||||
* or packager/legal/LICENSE.txt. See the License for the specific |
|
||||||
* language governing permissions and limitations under the License. |
|
||||||
* |
|
||||||
* When distributing the software, include this License Header Notice in each |
|
||||||
* file and include the License file at packager/legal/LICENSE.txt. |
|
||||||
* |
|
||||||
* GPL Classpath Exception: |
|
||||||
* Oracle designates this particular file as subject to the "Classpath" |
|
||||||
* exception as provided by Oracle in the GPL Version 2 section of the License |
|
||||||
* file that accompanied this code. |
|
||||||
* |
|
||||||
* Modifications: |
|
||||||
* If applicable, add the following below the License Header, with the fields |
|
||||||
* enclosed by brackets [] replaced by your own identifying information: |
|
||||||
* "Portions Copyright [year] [name of copyright owner]" |
|
||||||
* |
|
||||||
* Contributor(s): |
|
||||||
* If you wish your version of this file to be governed by only the CDDL or |
|
||||||
* only the GPL Version 2, indicate your decision by adding "[Contributor] |
|
||||||
* elects to include this software in this distribution under the [CDDL or GPL |
|
||||||
* Version 2] license." If you don't indicate a single choice of license, a |
|
||||||
* recipient has the option to distribute your version of this file under |
|
||||||
* either the CDDL, the GPL Version 2 or to extend the choice of license to |
|
||||||
* its licensees as provided above. However, if you add GPL Version 2 code |
|
||||||
* and therefore, elected the GPL Version 2 license, then the option applies |
|
||||||
* only if the new code is made subject to such option by the copyright |
|
||||||
* holder. |
|
||||||
*/ |
|
||||||
|
|
||||||
/* gepatchtes class-File: |
|
||||||
* im Rahmen von #331613 muss mit dem Update auf Tomcat 10 auch die Anwendung von Serlvet API 4.0 auf 6.0 umgestellt werden. |
|
||||||
* Dies leistet ein Migrationstool, welches in erster Linie den Packagenamen von 'javax' auf 'jakarta' umstellt. |
|
||||||
* Allerdings bestand danach immer noch in der 'jersey-bunde-1.19.4.jar' ein Zugriff auf die entfernte Methode |
|
||||||
* 'HttpServletResponse.setStatus(int, String)', welcher beim Laden von Saiku zu einer Exception geführt hat, |
|
||||||
* wodurch das Frontend in der Ladeanzeige geblieben ist. |
|
||||||
* Der Patch ändert die Klasse derart, dass sie die noch vorhandene Methode 'HttpServletResponse.setStatus(int)' aufruft, |
|
||||||
* was zu funktionieren scheint. |
|
||||||
* Ursprung entspricht https://github.com/javaee/jersey-1.x/blob/864a01d7be490ab93d2424da3e446ad8eb84b1e8/jersey-servlet/src/main/java/com/sun/jersey/spi/container/servlet/WebComponent.java
|
|
||||||
*/ |
|
||||||
|
|
||||||
package com.sun.jersey.spi.container.servlet; |
|
||||||
|
|
||||||
import java.io.BufferedInputStream; |
|
||||||
import java.io.IOException; |
|
||||||
import java.io.InputStream; |
|
||||||
import java.io.OutputStream; |
|
||||||
import java.lang.reflect.Constructor; |
|
||||||
import java.lang.reflect.Proxy; |
|
||||||
import java.lang.reflect.Type; |
|
||||||
import java.net.URI; |
|
||||||
import java.security.Principal; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.Arrays; |
|
||||||
import java.util.Enumeration; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Iterator; |
|
||||||
import java.util.LinkedList; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.logging.Level; |
|
||||||
import java.util.logging.Logger; |
|
||||||
|
|
||||||
import javax.ws.rs.WebApplicationException; |
|
||||||
import javax.ws.rs.core.Application; |
|
||||||
import javax.ws.rs.core.Context; |
|
||||||
import javax.ws.rs.core.GenericEntity; |
|
||||||
import javax.ws.rs.core.MediaType; |
|
||||||
import javax.ws.rs.core.MultivaluedMap; |
|
||||||
import javax.ws.rs.core.Response; |
|
||||||
import javax.ws.rs.core.SecurityContext; |
|
||||||
|
|
||||||
import javax.naming.NamingException; |
|
||||||
import jakarta.servlet.ServletContext; |
|
||||||
import jakarta.servlet.ServletException; |
|
||||||
import jakarta.servlet.http.HttpServletRequest; |
|
||||||
import jakarta.servlet.http.HttpServletResponse; |
|
||||||
|
|
||||||
import com.sun.jersey.api.container.ContainerException; |
|
||||||
import com.sun.jersey.api.container.MappableContainerException; |
|
||||||
import com.sun.jersey.api.core.ApplicationAdapter; |
|
||||||
import com.sun.jersey.api.core.ClasspathResourceConfig; |
|
||||||
import com.sun.jersey.api.core.PackagesResourceConfig; |
|
||||||
import com.sun.jersey.api.core.ResourceConfig; |
|
||||||
import com.sun.jersey.api.core.TraceInformation; |
|
||||||
import com.sun.jersey.api.core.servlet.WebAppResourceConfig; |
|
||||||
import com.sun.jersey.api.representation.Form; |
|
||||||
import com.sun.jersey.core.header.InBoundHeaders; |
|
||||||
import com.sun.jersey.core.header.MediaTypes; |
|
||||||
import com.sun.jersey.core.reflection.ReflectionHelper; |
|
||||||
import com.sun.jersey.core.util.ReaderWriter; |
|
||||||
import com.sun.jersey.server.impl.InitialContextHelper; |
|
||||||
import com.sun.jersey.server.impl.ThreadLocalInvoker; |
|
||||||
import com.sun.jersey.server.impl.application.DeferredResourceConfig; |
|
||||||
import com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer; |
|
||||||
import com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor; |
|
||||||
import com.sun.jersey.server.impl.ejb.EJBComponentProviderFactoryInitilizer; |
|
||||||
import com.sun.jersey.server.impl.managedbeans.ManagedBeanComponentProviderFactoryInitilizer; |
|
||||||
import com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider; |
|
||||||
import com.sun.jersey.server.impl.monitoring.GlassFishMonitoringInitializer; |
|
||||||
import com.sun.jersey.server.probes.UriRuleProbeProvider; |
|
||||||
import com.sun.jersey.spi.container.ContainerListener; |
|
||||||
import com.sun.jersey.spi.container.ContainerNotifier; |
|
||||||
import com.sun.jersey.spi.container.ContainerRequest; |
|
||||||
import com.sun.jersey.spi.container.ContainerResponse; |
|
||||||
import com.sun.jersey.spi.container.ContainerResponseWriter; |
|
||||||
import com.sun.jersey.spi.container.ReloadListener; |
|
||||||
import com.sun.jersey.spi.container.WebApplication; |
|
||||||
import com.sun.jersey.spi.container.WebApplicationFactory; |
|
||||||
import com.sun.jersey.spi.inject.SingletonTypeInjectableProvider; |
|
||||||
import java.security.AccessController; |
|
||||||
import java.security.PrivilegedActionException; |
|
||||||
|
|
||||||
/** |
|
||||||
* An abstract Web component that may be extended a Servlet and/or |
|
||||||
* Filter implementation, or encapsulated by a Servlet or Filter implementation. |
|
||||||
* |
|
||||||
* @author Paul Sandoz (paul.sandoz at oracle.com) |
|
||||||
*/ |
|
||||||
public class WebComponent implements ContainerListener { |
|
||||||
/** |
|
||||||
* The servlet initialization property whose value is a fully qualified |
|
||||||
* class name of a class that implements {@link ResourceConfig} or |
|
||||||
* {@link Application}. |
|
||||||
*/ |
|
||||||
public static final String APPLICATION_CONFIG_CLASS = |
|
||||||
"javax.ws.rs.Application"; |
|
||||||
|
|
||||||
/** |
|
||||||
* The servlet initialization property whose value is a fully qualified |
|
||||||
* class name of a class that implements {@link ResourceConfig} or |
|
||||||
* {@link Application}. |
|
||||||
*/ |
|
||||||
public static final String RESOURCE_CONFIG_CLASS = |
|
||||||
"com.sun.jersey.config.property.resourceConfigClass"; |
|
||||||
|
|
||||||
/** |
|
||||||
* The base path in the Web Pages where JSP templates, associated with |
|
||||||
* viewables of resource classes, are located. |
|
||||||
* <p/> |
|
||||||
* If this property is not set then the base path will be the root path |
|
||||||
* of the Web Pages. |
|
||||||
*/ |
|
||||||
public static final String JSP_TEMPLATES_BASE_PATH = |
|
||||||
"com.sun.jersey.config.property.JSPTemplatesBasePath"; |
|
||||||
|
|
||||||
|
|
||||||
private static final Logger LOGGER = |
|
||||||
Logger.getLogger(WebComponent.class.getName()); |
|
||||||
|
|
||||||
private final ThreadLocalInvoker<HttpServletRequest> requestInvoker = |
|
||||||
new ThreadLocalInvoker<HttpServletRequest>(); |
|
||||||
|
|
||||||
private final ThreadLocalInvoker<HttpServletResponse> responseInvoker = |
|
||||||
new ThreadLocalInvoker<HttpServletResponse>(); |
|
||||||
|
|
||||||
|
|
||||||
private WebConfig config; |
|
||||||
|
|
||||||
private ResourceConfig resourceConfig; |
|
||||||
|
|
||||||
private WebApplication application; |
|
||||||
|
|
||||||
public WebComponent() { |
|
||||||
} |
|
||||||
|
|
||||||
public WebComponent(Application app) { |
|
||||||
if (app == null) |
|
||||||
throw new IllegalArgumentException(); |
|
||||||
|
|
||||||
if (app instanceof ResourceConfig) { |
|
||||||
resourceConfig = (ResourceConfig) app; |
|
||||||
} else { |
|
||||||
resourceConfig = new ApplicationAdapter(app); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Get the Web configuration. |
|
||||||
* |
|
||||||
* @return the Web configuration. |
|
||||||
*/ |
|
||||||
public WebConfig getWebConfig() { |
|
||||||
return config; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Get the resource configuration. |
|
||||||
* |
|
||||||
* @return the resource configuration. |
|
||||||
*/ |
|
||||||
public ResourceConfig getResourceConfig() { |
|
||||||
return resourceConfig; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Initiate the Web component. |
|
||||||
* |
|
||||||
* @param webConfig the Web configuration. |
|
||||||
* @throws javax.servlet.ServletException in case of any initialization error |
|
||||||
*/ |
|
||||||
public void init(WebConfig webConfig) throws ServletException { |
|
||||||
config = webConfig; |
|
||||||
|
|
||||||
if (resourceConfig == null) |
|
||||||
resourceConfig = createResourceConfig(config); |
|
||||||
|
|
||||||
load(); |
|
||||||
|
|
||||||
Object o = resourceConfig.getProperties().get( |
|
||||||
ResourceConfig.PROPERTY_CONTAINER_NOTIFIER); |
|
||||||
if (o instanceof List) { |
|
||||||
List list = (List) o; |
|
||||||
for (Object elem : list) { |
|
||||||
if (elem instanceof ContainerNotifier) { |
|
||||||
ContainerNotifier crf = (ContainerNotifier) elem; |
|
||||||
crf.addListener(this); |
|
||||||
} |
|
||||||
} |
|
||||||
} else if (o instanceof ContainerNotifier) { |
|
||||||
ContainerNotifier crf = (ContainerNotifier) o; |
|
||||||
crf.addListener(this); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Destroy this Web component. |
|
||||||
* <p/> |
|
||||||
* This will destroy the Web application created by this this Web component. |
|
||||||
*/ |
|
||||||
public void destroy() { |
|
||||||
if (application != null) |
|
||||||
application.destroy(); |
|
||||||
} |
|
||||||
|
|
||||||
private final static class Writer extends OutputStream implements ContainerResponseWriter { |
|
||||||
final HttpServletResponse response; |
|
||||||
|
|
||||||
ContainerResponse cResponse; |
|
||||||
|
|
||||||
long contentLength; |
|
||||||
|
|
||||||
OutputStream out; |
|
||||||
|
|
||||||
boolean statusAndHeadersWritten = false; |
|
||||||
|
|
||||||
Writer(HttpServletResponse response) { |
|
||||||
this.response = response; |
|
||||||
} |
|
||||||
|
|
||||||
public OutputStream writeStatusAndHeaders(long contentLength, |
|
||||||
ContainerResponse cResponse) throws IOException { |
|
||||||
this.contentLength = contentLength; |
|
||||||
this.cResponse = cResponse; |
|
||||||
this.statusAndHeadersWritten = false; |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public void finish() throws IOException { |
|
||||||
if (statusAndHeadersWritten) |
|
||||||
return; |
|
||||||
|
|
||||||
// Note that the writing of headers MUST be performed before
|
|
||||||
// the invocation of sendError as on some Servlet implementations
|
|
||||||
// modification of the response headers will have no effect
|
|
||||||
// after the invocation of sendError.
|
|
||||||
writeHeaders(); |
|
||||||
|
|
||||||
|
|
||||||
writeStatus(); |
|
||||||
} |
|
||||||
|
|
||||||
private void writeStatus() { |
|
||||||
Response.StatusType statusType = cResponse.getStatusType(); |
|
||||||
final String reasonPhrase = statusType.getReasonPhrase(); |
|
||||||
|
|
||||||
// if (reasonPhrase != null) {
|
|
||||||
// response.setStatus(statusType.getStatusCode(), reasonPhrase);
|
|
||||||
// } else {
|
|
||||||
response.setStatus(statusType.getStatusCode()); |
|
||||||
// }
|
|
||||||
} |
|
||||||
|
|
||||||
public void write(int b) throws IOException { |
|
||||||
initiate(); |
|
||||||
out.write(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(byte b[]) throws IOException { |
|
||||||
if (b.length > 0) { |
|
||||||
initiate(); |
|
||||||
out.write(b); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(byte b[], int off, int len) throws IOException { |
|
||||||
if (len > 0) { |
|
||||||
initiate(); |
|
||||||
out.write(b, off, len); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void flush() throws IOException { |
|
||||||
writeStatusAndHeaders(); |
|
||||||
if (out != null) |
|
||||||
out.flush(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void close() throws IOException { |
|
||||||
initiate(); |
|
||||||
out.close(); |
|
||||||
} |
|
||||||
|
|
||||||
void initiate() throws IOException { |
|
||||||
if (out == null) { |
|
||||||
writeStatusAndHeaders(); |
|
||||||
out = response.getOutputStream(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void writeStatusAndHeaders() { |
|
||||||
if (statusAndHeadersWritten) |
|
||||||
return; |
|
||||||
|
|
||||||
writeHeaders(); |
|
||||||
writeStatus(); |
|
||||||
statusAndHeadersWritten = true; |
|
||||||
} |
|
||||||
|
|
||||||
void writeHeaders() { |
|
||||||
if (contentLength != -1 && contentLength < Integer.MAX_VALUE) |
|
||||||
response.setContentLength((int) contentLength); |
|
||||||
|
|
||||||
MultivaluedMap<String, Object> headers = cResponse.getHttpHeaders(); |
|
||||||
for (Map.Entry<String, List<Object>> e : headers.entrySet()) { |
|
||||||
for (Object v : e.getValue()) { |
|
||||||
response.addHeader(e.getKey(), ContainerResponse.getHeaderValue(v)); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Dispatch client requests to a resource class. |
|
||||||
* |
|
||||||
* @param baseUri the base URI of the request. |
|
||||||
* @param requestUri the URI of the request. |
|
||||||
* @param request the {@link HttpServletRequest} object that |
|
||||||
* contains the request the client made to |
|
||||||
* the Web component. |
|
||||||
* @param response the {@link HttpServletResponse} object that |
|
||||||
* contains the response the Web component returns |
|
||||||
* to the client. |
|
||||||
* @return the status code of the response. |
|
||||||
* @throws IOException if an input or output error occurs |
|
||||||
* while the Web component is handling the |
|
||||||
* HTTP request. |
|
||||||
* @throws ServletException if the HTTP request cannot |
|
||||||
* be handled. |
|
||||||
*/ |
|
||||||
public int service(URI baseUri, URI requestUri, |
|
||||||
final HttpServletRequest request, |
|
||||||
final HttpServletResponse response) |
|
||||||
throws ServletException, IOException { |
|
||||||
// Copy the application field to local instance to ensure that the
|
|
||||||
// currently loaded web application is used to process
|
|
||||||
// request
|
|
||||||
final WebApplication _application = application; |
|
||||||
|
|
||||||
final ContainerRequest cRequest = createRequest( |
|
||||||
_application, |
|
||||||
request, |
|
||||||
baseUri, |
|
||||||
requestUri); |
|
||||||
|
|
||||||
cRequest.setSecurityContext(new SecurityContext() { |
|
||||||
public Principal getUserPrincipal() { |
|
||||||
return request.getUserPrincipal(); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean isUserInRole(String role) { |
|
||||||
return request.isUserInRole(role); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean isSecure() { |
|
||||||
return request.isSecure(); |
|
||||||
} |
|
||||||
|
|
||||||
public String getAuthenticationScheme() { |
|
||||||
return request.getAuthType(); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
try { |
|
||||||
// Check if any servlet filters have consumed a request entity
|
|
||||||
// of the media type application/x-www-form-urlencoded
|
|
||||||
// This can happen if a filter calls request.getParameter(...)
|
|
||||||
filterFormParameters(request, cRequest); |
|
||||||
|
|
||||||
UriRuleProbeProvider.requestStart(requestUri); |
|
||||||
|
|
||||||
requestInvoker.set(request); |
|
||||||
responseInvoker.set(response); |
|
||||||
|
|
||||||
final Writer w = new Writer(response); |
|
||||||
_application.handleRequest(cRequest, w); |
|
||||||
return w.cResponse.getStatus(); |
|
||||||
} catch (WebApplicationException ex) { |
|
||||||
final Response exResponse = ex.getResponse(); |
|
||||||
final String entity = exResponse.getEntity() != null ? exResponse.getEntity().toString() : null; |
|
||||||
|
|
||||||
response.sendError(exResponse.getStatus(), entity); |
|
||||||
|
|
||||||
return exResponse.getStatus(); |
|
||||||
} catch (MappableContainerException ex) { |
|
||||||
traceOnException(cRequest, response); |
|
||||||
throw new ServletException(ex.getCause()); |
|
||||||
} catch (ContainerException ex) { |
|
||||||
traceOnException(cRequest, response); |
|
||||||
throw new ServletException(ex); |
|
||||||
} catch (RuntimeException ex) { |
|
||||||
traceOnException(cRequest, response); |
|
||||||
throw ex; |
|
||||||
} finally { |
|
||||||
UriRuleProbeProvider.requestEnd(); |
|
||||||
requestInvoker.set(null); |
|
||||||
responseInvoker.set(null); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Extension point for creating your custom container request. |
|
||||||
* |
|
||||||
* @param app the web app |
|
||||||
* @param request the current servlet api request |
|
||||||
* @param baseUri the base uri |
|
||||||
* @param requestUri the request uri |
|
||||||
* @return the request container |
|
||||||
* @throws IOException if any error occurs when getting the input stream |
|
||||||
*/ |
|
||||||
protected ContainerRequest createRequest(WebApplication app, |
|
||||||
HttpServletRequest request, URI baseUri, URI requestUri) throws IOException { |
|
||||||
return new ContainerRequest( |
|
||||||
app, |
|
||||||
request.getMethod(), |
|
||||||
baseUri, |
|
||||||
requestUri, |
|
||||||
getHeaders(request), |
|
||||||
request.getInputStream()); |
|
||||||
} |
|
||||||
|
|
||||||
private void traceOnException(final ContainerRequest cRequest, final HttpServletResponse response) { |
|
||||||
if (cRequest.isTracingEnabled()) { |
|
||||||
final TraceInformation ti = (TraceInformation) cRequest.getProperties(). |
|
||||||
get(TraceInformation.class.getName()); |
|
||||||
|
|
||||||
ti.addTraceHeaders(new TraceInformation.TraceHeaderListener() { |
|
||||||
public void onHeader(String name, String value) { |
|
||||||
response.addHeader(name, value); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Create a new instance of a {@link WebApplication}. |
|
||||||
* |
|
||||||
* @return the {@link WebApplication} instance. |
|
||||||
*/ |
|
||||||
protected WebApplication create() { |
|
||||||
return WebApplicationFactory.createWebApplication(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* A helper class for creating an injectable provider that supports |
|
||||||
* {@link Context} with a type and constant value. |
|
||||||
* |
|
||||||
* @param <T> the type of the constant value. |
|
||||||
*/ |
|
||||||
protected static class ContextInjectableProvider<T> extends |
|
||||||
SingletonTypeInjectableProvider<Context, T> { |
|
||||||
|
|
||||||
/** |
|
||||||
* Create a new instance. |
|
||||||
* |
|
||||||
* @param type the type of the constant value. |
|
||||||
* @param instance the constant value. |
|
||||||
*/ |
|
||||||
protected ContextInjectableProvider(Type type, T instance) { |
|
||||||
super(type, instance); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Configure the {@link ResourceConfig}. |
|
||||||
* <p/> |
|
||||||
* The {@link ResourceConfig} is configured such that the following classes |
|
||||||
* may be injected onto the field of a root resource class or a parameter |
|
||||||
* of a method of root resource class that is annotated with |
|
||||||
* {@link javax.ws.rs.core.Context}: {@link HttpServletRequest}, {@link HttpServletResponse} |
|
||||||
* , {@link ServletContext} and {@link WebConfig}. |
|
||||||
* <p/> |
|
||||||
* Any root resource class in registered in the resource configuration |
|
||||||
* that is an interface is processed as follows. |
|
||||||
* If the class is an interface and there exists a JNDI named object |
|
||||||
* with the fully qualified class name as the JNDI name then that named |
|
||||||
* object is added as a singleton root resource and the class is removed |
|
||||||
* from the set of root resource classes. |
|
||||||
* <p/> |
|
||||||
* An inheriting class may override this method to configure the |
|
||||||
* {@link ResourceConfig} to provide alternative or additional instances |
|
||||||
* that are resource or provider classes or instances, and may modify the |
|
||||||
* features and properties of the {@link ResourceConfig}. For an inheriting |
|
||||||
* class to extend configuration behaviour the overriding method MUST call |
|
||||||
* <code>super.configure(servletConfig, rc, wa)</code> as the first statement |
|
||||||
* of that method. |
|
||||||
* <p/> |
|
||||||
* This method will be called only once at initiation. Subsequent |
|
||||||
* reloads of the Web application will not result in subsequence calls to |
|
||||||
* this method. |
|
||||||
* |
|
||||||
* @param wc the Web configuration |
|
||||||
* @param rc the Resource configuration |
|
||||||
* @param wa the Web application |
|
||||||
*/ |
|
||||||
protected void configure(WebConfig wc, ResourceConfig rc, WebApplication wa) { |
|
||||||
configureJndiResources(rc); |
|
||||||
|
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<HttpServletRequest>( |
|
||||||
HttpServletRequest.class, |
|
||||||
(HttpServletRequest) Proxy.newProxyInstance( |
|
||||||
this.getClass().getClassLoader(), |
|
||||||
new Class[]{HttpServletRequest.class}, |
|
||||||
requestInvoker))); |
|
||||||
|
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<HttpServletResponse>( |
|
||||||
HttpServletResponse.class, |
|
||||||
(HttpServletResponse) Proxy.newProxyInstance( |
|
||||||
this.getClass().getClassLoader(), |
|
||||||
new Class[]{HttpServletResponse.class}, |
|
||||||
responseInvoker))); |
|
||||||
|
|
||||||
GenericEntity<ThreadLocal<HttpServletRequest>> requestThreadLocal = |
|
||||||
new GenericEntity<ThreadLocal<HttpServletRequest>>(requestInvoker.getImmutableThreadLocal()) { |
|
||||||
}; |
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<ThreadLocal<HttpServletRequest>>( |
|
||||||
requestThreadLocal.getType(), requestThreadLocal.getEntity())); |
|
||||||
|
|
||||||
GenericEntity<ThreadLocal<HttpServletResponse>> responseThreadLocal = |
|
||||||
new GenericEntity<ThreadLocal<HttpServletResponse>>(responseInvoker.getImmutableThreadLocal()) { |
|
||||||
}; |
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<ThreadLocal<HttpServletResponse>>( |
|
||||||
responseThreadLocal.getType(), responseThreadLocal.getEntity())); |
|
||||||
|
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<ServletContext>( |
|
||||||
ServletContext.class, |
|
||||||
wc.getServletContext())); |
|
||||||
|
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<WebConfig>( |
|
||||||
WebConfig.class, |
|
||||||
wc)); |
|
||||||
|
|
||||||
rc.getClasses().add(JSPTemplateProcessor.class); |
|
||||||
|
|
||||||
// TODO
|
|
||||||
// If CDI is enabled should EJB injection be disabled?
|
|
||||||
EJBComponentProviderFactoryInitilizer.initialize(rc); |
|
||||||
|
|
||||||
CDIComponentProviderFactoryInitializer.initialize(wc, rc, wa); |
|
||||||
|
|
||||||
// TODO
|
|
||||||
// If CDI is enabled then no need to initialize managed beans
|
|
||||||
ManagedBeanComponentProviderFactoryInitilizer.initialize(rc); |
|
||||||
|
|
||||||
GlassFishMonitoringInitializer.initialize(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Initiate the {@link WebApplication}. |
|
||||||
* <p/> |
|
||||||
* This method will be called once at initiation and for |
|
||||||
* each reload of the Web application. |
|
||||||
* <p/> |
|
||||||
* An inheriting class may override this method to initiate the |
|
||||||
* Web application with different parameters. |
|
||||||
* |
|
||||||
* @param rc the Resource configuration |
|
||||||
* @param wa the Web application |
|
||||||
*/ |
|
||||||
protected void initiate(ResourceConfig rc, WebApplication wa) { |
|
||||||
wa.initiate(rc); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Load the Web application. This will create, configure and initiate |
|
||||||
* the web application. |
|
||||||
*/ |
|
||||||
public void load() { |
|
||||||
WebApplication _application = create(); |
|
||||||
configure(config, resourceConfig, _application); |
|
||||||
initiate(resourceConfig, _application); |
|
||||||
application = _application; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Get the default resource configuration if one is not declared in the |
|
||||||
* web.xml. |
|
||||||
* <p/> |
|
||||||
* This implementation returns an instance of {@link WebAppResourceConfig} |
|
||||||
* that scans in files and directories as declared by the |
|
||||||
* {@link ClasspathResourceConfig#PROPERTY_CLASSPATH} if present, otherwise |
|
||||||
* in the "WEB-INF/lib" and "WEB-INF/classes" directories. |
|
||||||
* <p/> |
|
||||||
* An inheriting class may override this method to supply a different |
|
||||||
* default resource configuration implementation. |
|
||||||
* |
|
||||||
* @param props the properties to pass to the resource configuration. |
|
||||||
* @param wc the web configuration. |
|
||||||
* @return the default resource configuration. |
|
||||||
* @throws javax.servlet.ServletException in case of any issues with providing \ |
|
||||||
* the default resource configuration |
|
||||||
*/ |
|
||||||
protected ResourceConfig getDefaultResourceConfig(Map<String, Object> props, |
|
||||||
WebConfig wc) throws ServletException { |
|
||||||
return getWebAppResourceConfig(props, wc); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
// ContainerListener
|
|
||||||
|
|
||||||
/** |
|
||||||
* Reload the Web application. This will create and initiate the web |
|
||||||
* application using the same {@link ResourceConfig} implementation |
|
||||||
* that was used to load the Web application. |
|
||||||
* <p/> |
|
||||||
* This method may be called at runtime, more than once, to reload the |
|
||||||
* Web application. For example, if a {@link ResourceConfig} implementation |
|
||||||
* is capable of detecting changes to resource classes (addition or removal) |
|
||||||
* or providers then this method may be invoked to reload the web |
|
||||||
* application for such changes to take effect. |
|
||||||
* <p/> |
|
||||||
* If this method is called when there are pending requests then such |
|
||||||
* requests will be processed using the previously loaded web application. |
|
||||||
*/ |
|
||||||
public void onReload() { |
|
||||||
WebApplication oldApplication = application; |
|
||||||
WebApplication newApplication = create(); |
|
||||||
initiate(resourceConfig, newApplication); |
|
||||||
application = newApplication; |
|
||||||
|
|
||||||
if (resourceConfig instanceof ReloadListener) |
|
||||||
((ReloadListener) resourceConfig).onReload(); |
|
||||||
|
|
||||||
oldApplication.destroy(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
/* package */ ResourceConfig getWebAppResourceConfig(Map<String, Object> props, |
|
||||||
WebConfig webConfig) throws ServletException { |
|
||||||
// Default to using Web app resource config
|
|
||||||
return new WebAppResourceConfig(props, webConfig.getServletContext()); |
|
||||||
} |
|
||||||
|
|
||||||
private ResourceConfig createResourceConfig(WebConfig webConfig) |
|
||||||
throws ServletException { |
|
||||||
final Map<String, Object> props = getInitParams(webConfig); |
|
||||||
final ResourceConfig rc = createResourceConfig(webConfig, props); |
|
||||||
rc.setPropertiesAndFeatures(props); |
|
||||||
return rc; |
|
||||||
} |
|
||||||
|
|
||||||
private ResourceConfig createResourceConfig(WebConfig webConfig, Map<String, Object> props) |
|
||||||
throws ServletException { |
|
||||||
// Check if the resource config class property is present
|
|
||||||
String resourceConfigClassName = webConfig.getInitParameter(RESOURCE_CONFIG_CLASS); |
|
||||||
// Otherwise check if the JAX-RS application config class property is
|
|
||||||
// present
|
|
||||||
if (resourceConfigClassName == null) |
|
||||||
resourceConfigClassName = webConfig.getInitParameter(APPLICATION_CONFIG_CLASS); |
|
||||||
|
|
||||||
// If no resource config class property is present
|
|
||||||
if (resourceConfigClassName == null) { |
|
||||||
// If the packages property is present then
|
|
||||||
// use the packages resource config
|
|
||||||
String packages = webConfig.getInitParameter( |
|
||||||
PackagesResourceConfig.PROPERTY_PACKAGES); |
|
||||||
if (packages != null) { |
|
||||||
props.put(PackagesResourceConfig.PROPERTY_PACKAGES, packages); |
|
||||||
return new PackagesResourceConfig(props); |
|
||||||
} |
|
||||||
|
|
||||||
ResourceConfig defaultConfig = webConfig.getDefaultResourceConfig(props); |
|
||||||
if (defaultConfig != null) |
|
||||||
return defaultConfig; |
|
||||||
|
|
||||||
return getDefaultResourceConfig(props, webConfig); |
|
||||||
} |
|
||||||
|
|
||||||
try { |
|
||||||
Class<?> resourceConfigClass = AccessController.doPrivileged(ReflectionHelper. |
|
||||||
classForNameWithExceptionPEA(resourceConfigClassName)); |
|
||||||
|
|
||||||
// TODO add support for WebAppResourceConfig
|
|
||||||
if (resourceConfigClass == ClasspathResourceConfig.class) { |
|
||||||
String[] paths = getPaths(webConfig.getInitParameter( |
|
||||||
ClasspathResourceConfig.PROPERTY_CLASSPATH)); |
|
||||||
props.put(ClasspathResourceConfig.PROPERTY_CLASSPATH, paths); |
|
||||||
return new ClasspathResourceConfig(props); |
|
||||||
} else if (ResourceConfig.class.isAssignableFrom(resourceConfigClass)) { |
|
||||||
try { |
|
||||||
Constructor constructor = resourceConfigClass.getConstructor(Map.class); |
|
||||||
if (ClasspathResourceConfig.class.isAssignableFrom(resourceConfigClass)) { |
|
||||||
String[] paths = getPaths(webConfig.getInitParameter( |
|
||||||
ClasspathResourceConfig.PROPERTY_CLASSPATH)); |
|
||||||
props.put(ClasspathResourceConfig.PROPERTY_CLASSPATH, paths); |
|
||||||
} |
|
||||||
return (ResourceConfig) constructor.newInstance(props); |
|
||||||
} catch (NoSuchMethodException ex) { |
|
||||||
// Pass through and try the default constructor
|
|
||||||
} catch (Exception e) { |
|
||||||
throw new ServletException(e); |
|
||||||
} |
|
||||||
|
|
||||||
return new DeferredResourceConfig(resourceConfigClass.asSubclass(ResourceConfig.class)); |
|
||||||
} else if (Application.class.isAssignableFrom(resourceConfigClass)) { |
|
||||||
return new DeferredResourceConfig(resourceConfigClass.asSubclass(Application.class)); |
|
||||||
} else { |
|
||||||
String message = "Resource configuration class, " + resourceConfigClassName + |
|
||||||
", is not a super class of " + Application.class; |
|
||||||
throw new ServletException(message); |
|
||||||
} |
|
||||||
} catch (ClassNotFoundException e) { |
|
||||||
String message = "Resource configuration class, " + resourceConfigClassName + |
|
||||||
", could not be loaded"; |
|
||||||
throw new ServletException(message, e); |
|
||||||
} catch (PrivilegedActionException e) { |
|
||||||
String message = "Resource configuration class, " + resourceConfigClassName + |
|
||||||
", could not be loaded"; |
|
||||||
throw new ServletException(message, e.getCause()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private Map<String, Object> getInitParams(WebConfig webConfig) { |
|
||||||
Map<String, Object> props = new HashMap<String, Object>(); |
|
||||||
Enumeration names = webConfig.getInitParameterNames(); |
|
||||||
while (names.hasMoreElements()) { |
|
||||||
String name = (String) names.nextElement(); |
|
||||||
props.put(name, webConfig.getInitParameter(name)); |
|
||||||
} |
|
||||||
return props; |
|
||||||
} |
|
||||||
|
|
||||||
private String[] getPaths(String classpath) throws ServletException { |
|
||||||
final ServletContext context = config.getServletContext(); |
|
||||||
if (classpath == null) { |
|
||||||
String[] paths = { |
|
||||||
context.getRealPath("/WEB-INF/lib"), |
|
||||||
context.getRealPath("/WEB-INF/classes") |
|
||||||
}; |
|
||||||
if (paths[0] == null && paths[1] == null) { |
|
||||||
String message = "The default deployment configuration that scans for " + |
|
||||||
"classes in /WEB-INF/lib and /WEB-INF/classes is not supported " + |
|
||||||
"for the application server." + |
|
||||||
"Try using the package scanning configuration, see the JavaDoc for " + |
|
||||||
PackagesResourceConfig.class.getName() + " and the property " + |
|
||||||
PackagesResourceConfig.PROPERTY_PACKAGES + "."; |
|
||||||
throw new ServletException(message); |
|
||||||
} |
|
||||||
return paths; |
|
||||||
} else { |
|
||||||
String[] virtualPaths = classpath.split(";"); |
|
||||||
List<String> resourcePaths = new ArrayList<String>(); |
|
||||||
for (String virtualPath : virtualPaths) { |
|
||||||
virtualPath = virtualPath.trim(); |
|
||||||
if (virtualPath.length() == 0) continue; |
|
||||||
String path = context.getRealPath(virtualPath); |
|
||||||
if (path != null) resourcePaths.add(path); |
|
||||||
} |
|
||||||
if (resourcePaths.isEmpty()) { |
|
||||||
String message = "None of the declared classpath locations, " + |
|
||||||
classpath + |
|
||||||
", could be resolved. " + |
|
||||||
"This could be because the default deployment configuration that scans for " + |
|
||||||
"classes in classpath locations is not supported. " + |
|
||||||
"Try using the package scanning configuration, see the JavaDoc for " + |
|
||||||
PackagesResourceConfig.class.getName() + " and the property " + |
|
||||||
PackagesResourceConfig.PROPERTY_PACKAGES + "."; |
|
||||||
throw new ServletException(message); |
|
||||||
} |
|
||||||
return resourcePaths.toArray(new String[resourcePaths.size()]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void configureJndiResources(ResourceConfig rc) { |
|
||||||
// Obtain any instances that are registered in JNDI
|
|
||||||
// Assumes such instances are singletons
|
|
||||||
// Registered classes have to be interfaces
|
|
||||||
javax.naming.Context x = InitialContextHelper.getInitialContext(); |
|
||||||
if (x != null) { |
|
||||||
Iterator<Class<?>> i = rc.getClasses().iterator(); |
|
||||||
while (i.hasNext()) { |
|
||||||
Class<?> c = i.next(); |
|
||||||
if (!c.isInterface()) continue; |
|
||||||
|
|
||||||
try { |
|
||||||
Object o = x.lookup(c.getName()); |
|
||||||
if (o != null) { |
|
||||||
i.remove(); |
|
||||||
rc.getSingletons().add(o); |
|
||||||
LOGGER.log(Level.INFO, |
|
||||||
"An instance of the class " + c.getName() + |
|
||||||
" is found by JNDI look up using the class name as the JNDI name. " + |
|
||||||
"The instance will be registered as a singleton."); |
|
||||||
} |
|
||||||
} catch (NamingException ex) { |
|
||||||
LOGGER.log(Level.CONFIG, |
|
||||||
"JNDI lookup failed for Jersey application resource " + c.getName(), |
|
||||||
ex); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void filterFormParameters(HttpServletRequest servletRequest, ContainerRequest containerRequet) throws IOException { |
|
||||||
if (MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, containerRequet.getMediaType()) |
|
||||||
&& !isEntityPresent(containerRequet)) { |
|
||||||
Form f = new Form(); |
|
||||||
|
|
||||||
Enumeration e = servletRequest.getParameterNames(); |
|
||||||
while (e.hasMoreElements()) { |
|
||||||
String name = (String) e.nextElement(); |
|
||||||
String[] values = servletRequest.getParameterValues(name); |
|
||||||
|
|
||||||
f.put(name, Arrays.asList(values)); |
|
||||||
} |
|
||||||
|
|
||||||
if (!f.isEmpty()) { |
|
||||||
containerRequet.getProperties().put(FormDispatchProvider.FORM_PROPERTY, f); |
|
||||||
if (LOGGER.isLoggable(Level.WARNING)) { |
|
||||||
LOGGER.log(Level.WARNING, |
|
||||||
"A servlet request, to the URI " + containerRequet.getRequestUri() + ", " + |
|
||||||
"contains form parameters in " + |
|
||||||
"the request body but the request body has been consumed " + |
|
||||||
"by the servlet or a servlet filter accessing the request " + |
|
||||||
"parameters. Only resource methods using @FormParam " + |
|
||||||
"will work as expected. Resource methods consuming the " + |
|
||||||
"request body by other means will not work as expected."); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private boolean isEntityPresent(ContainerRequest cr) throws IOException { |
|
||||||
InputStream in = cr.getEntityInputStream(); |
|
||||||
if (!in.markSupported()) { |
|
||||||
in = new BufferedInputStream(in, ReaderWriter.BUFFER_SIZE); |
|
||||||
cr.setEntityInputStream(in); |
|
||||||
} |
|
||||||
|
|
||||||
in.mark(1); |
|
||||||
if (in.read() == -1) |
|
||||||
return false; |
|
||||||
else { |
|
||||||
in.reset(); |
|
||||||
return true; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private InBoundHeaders getHeaders(HttpServletRequest request) { |
|
||||||
InBoundHeaders rh = new InBoundHeaders(); |
|
||||||
|
|
||||||
for (Enumeration<String> names = request.getHeaderNames(); names.hasMoreElements();) { |
|
||||||
String name = names.nextElement(); |
|
||||||
List<String> valueList = new LinkedList<String>(); |
|
||||||
for (Enumeration<String> values = request.getHeaders(name); values.hasMoreElements();) { |
|
||||||
valueList.add(values.nextElement()); |
|
||||||
} |
|
||||||
rh.put(name, valueList); |
|
||||||
} |
|
||||||
|
|
||||||
return rh; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,366 +0,0 @@ |
|||||||
/* |
|
||||||
* $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/util/MultipartRequest.java,v 1.19 2005/02/19 21:26:32 hkollmann Exp $ |
|
||||||
* $Revision: 1.19 $ |
|
||||||
* $Date: 2005/02/19 21:26:32 $ |
|
||||||
* |
|
||||||
* DbForms - a Rapid Application Development Framework |
|
||||||
* Copyright (C) 2001 Joachim Peer <joepeer@excite.com> |
|
||||||
* |
|
||||||
* This library is free software; you can redistribute it and/or |
|
||||||
* modify it under the terms of the GNU Lesser General Public |
|
||||||
* License as published by the Free Software Foundation; either |
|
||||||
* version 2.1 of the License, or (at your option) any later version. |
|
||||||
* |
|
||||||
* This library is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||||
* Lesser General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU Lesser General Public |
|
||||||
* License along with this library; if not, write to the Free Software |
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.dbforms.util; |
|
||||||
|
|
||||||
import org.apache.commons.fileupload.DiskFileUpload; |
|
||||||
import org.apache.commons.fileupload.FileItem; |
|
||||||
import org.apache.commons.logging.Log; |
|
||||||
import org.apache.commons.logging.LogFactory; |
|
||||||
|
|
||||||
import java.io.File; |
|
||||||
import java.io.IOException; |
|
||||||
import java.io.InputStream; |
|
||||||
|
|
||||||
import java.util.Enumeration; |
|
||||||
import java.util.Hashtable; |
|
||||||
import java.util.Iterator; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Vector; |
|
||||||
|
|
||||||
import jakarta.servlet.ServletRequest; |
|
||||||
import jakarta.servlet.ServletRequestWrapper; |
|
||||||
import jakarta.servlet.http.HttpServletRequest; |
|
||||||
import org.dbforms.util.external.FileUtil; |
|
||||||
|
|
||||||
import de.superx.util.multipart.support.DefaultMultipartHttpServletRequest; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* A utility class to handle <code>multipart/form-data</code> requests, the |
|
||||||
* kind of requests that support file uploads. This class emulates the interface
|
|
||||||
* of <code>HttpServletRequest</code>, making it familiar to use. It uses a |
|
||||||
* "push" model where any incoming files are read and saved directly to disk in |
|
||||||
* the constructor. If you wish to have more flexibility, e.g. write the files |
|
||||||
* to a database, use the "pull" model <code>MultipartParser</code> instead. |
|
||||||
* <p> |
|
||||||
* This class can receive arbitrarily large files (up to an artificial limit you |
|
||||||
* can set), and fairly efficiently too. It cannot handle nested data (multipart |
|
||||||
* content within multipart content) or internationalized content (such as non |
|
||||||
* Latin-1 filenames). |
|
||||||
* </p> |
|
||||||
* <p> |
|
||||||
* See the included <a href="upload.war">upload.war </a> for an example of how |
|
||||||
* to use this class. |
|
||||||
* <p> |
|
||||||
* The full file upload specification is contained in experimental RFC 1867, |
|
||||||
* available at <a href="http://www.ietf.org/rfc/rfc1867.txt" |
|
||||||
* http://www.ietf.org/rfc/rfc1867.txt </a>.
|
|
||||||
* </p> |
|
||||||
* <p> |
|
||||||
* PLEASE NOTE: this class uses Multipart Support Classes by Jason Hunter. |
|
||||||
* Copyright (C) 1998 by Jason Hunter. All rights reserved. |
|
||||||
* Use of this class is limited. Please see the LICENSE for more information. |
|
||||||
* Make sure that you project meets the requierements defined by Jason Hunter |
|
||||||
* respective O'reilly! |
|
||||||
* </p> |
|
||||||
* |
|
||||||
* @see MultipartParser |
|
||||||
* |
|
||||||
* @author Jason Hunter |
|
||||||
* @author Geoff Soutter |
|
||||||
* @author Joe Peer - _changed_ it for use in DbForms (i apologize) |
|
||||||
*/ |
|
||||||
/* Witt: am 28.05.2026 als Basis für gepatchte Datei nach 'src-patches' übernommen, Basis waren meine |
|
||||||
* lokalen 'dbforms_2.5_20050226' Sourcen */ |
|
||||||
public class MultipartRequest { |
|
||||||
private static Log logCat = LogFactory.getLog(MultipartRequest.class); // logging category
|
|
||||||
private Hashtable files = new Hashtable(); // name - UploadedFile
|
|
||||||
|
|
||||||
// for this class
|
|
||||||
//private File dir;
|
|
||||||
private Hashtable parameters = new Hashtable(); // name - Vector of values
|
|
||||||
|
|
||||||
/** |
|
||||||
* Constructs a new MultipartRequest to handle the specified request, |
|
||||||
* {saving any uploaded files to the given directory}, and limiting the |
|
||||||
* upload size to the specified length. If the content is too large, an |
|
||||||
* IOException is thrown. This constructor actually parses the |
|
||||||
* <tt>multipart/form-data</tt> and throws an IOException if there's any |
|
||||||
* problem reading or parsing the request. |
|
||||||
* |
|
||||||
* @param request |
|
||||||
* the servlet request. |
|
||||||
* @param maxPostSize |
|
||||||
* the maximum size of the POST content. |
|
||||||
* @exception IOException |
|
||||||
* if the uploaded content is larger than |
|
||||||
* <tt>maxPostSize</tt> or there's a problem reading or |
|
||||||
* parsing the request. |
|
||||||
*/ |
|
||||||
public MultipartRequest(HttpServletRequest request, |
|
||||||
int maxPostSize) |
|
||||||
throws IOException { |
|
||||||
// Sanity check values
|
|
||||||
if (request == null) { |
|
||||||
throw new IllegalArgumentException("request cannot be null"); |
|
||||||
} |
|
||||||
|
|
||||||
// Create a new file upload handler
|
|
||||||
DiskFileUpload upload = new DiskFileUpload(); |
|
||||||
|
|
||||||
// Set upload parameters
|
|
||||||
upload.setSizeMax(maxPostSize); |
|
||||||
|
|
||||||
String tmpDir = System.getProperty("java.io.tmpdir"); |
|
||||||
upload.setRepositoryPath(tmpDir); |
|
||||||
|
|
||||||
// Parse the request
|
|
||||||
try { |
|
||||||
// we initilize this list with 'null', as the following unwrapping code should do the work - contrary to the 'org.dbforms.util.MultipartRequest code, from which this is copied
|
|
||||||
List<FileItem> items = null; //upload.parseRequest(request);
|
|
||||||
|
|
||||||
if (items == null || items.size() == 0) { |
|
||||||
ServletRequest originalRequest = request; |
|
||||||
DefaultMultipartHttpServletRequest dmhsr = null; |
|
||||||
while (originalRequest instanceof ServletRequestWrapper) { |
|
||||||
if (originalRequest instanceof DefaultMultipartHttpServletRequest) { |
|
||||||
dmhsr = (DefaultMultipartHttpServletRequest) originalRequest; |
|
||||||
items = dmhsr.getFileItems(); |
|
||||||
break; |
|
||||||
} |
|
||||||
originalRequest = ((ServletRequestWrapper) originalRequest).getRequest(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
Iterator iter = items.iterator(); |
|
||||||
|
|
||||||
while (iter.hasNext()) { |
|
||||||
FileItem item = (FileItem) iter.next(); |
|
||||||
String name = item.getFieldName(); |
|
||||||
|
|
||||||
if (item.isFormField()) { |
|
||||||
String value = item.getString(); |
|
||||||
|
|
||||||
// plain parameters get allways into parameters structure
|
|
||||||
Vector existingValues = (Vector) parameters.get(name); |
|
||||||
|
|
||||||
if (existingValues == null) { |
|
||||||
existingValues = new Vector(); |
|
||||||
parameters.put(name, existingValues); |
|
||||||
} |
|
||||||
|
|
||||||
existingValues.addElement(value); |
|
||||||
} else { |
|
||||||
String fileName = item.getName(); |
|
||||||
|
|
||||||
if (!Util.isNull(fileName)) { |
|
||||||
File f = new File(fileName); |
|
||||||
// 2004-08-05-HKK/Dziugas Baltrunas:
|
|
||||||
// FileItem always returns the full pathname!
|
|
||||||
fileName = FileUtil.filename(f.getName()); |
|
||||||
|
|
||||||
// The part actually contained a file
|
|
||||||
// #changes by joe peer:
|
|
||||||
// we must delay storing the file-inputstream (into
|
|
||||||
// database, filesystem or whatever)
|
|
||||||
// until we know exactly what should happen with it
|
|
||||||
FileHolder fileHolder = new FileHolder(fileName, item); |
|
||||||
files.put(name, fileHolder); |
|
||||||
logCat.info("buffered and now added as " + name |
|
||||||
+ " the following fileHolder:" |
|
||||||
+ fileHolder.getFileName()); |
|
||||||
|
|
||||||
// #changes by joe peer:
|
|
||||||
// if a file parameter is not null it gets into the
|
|
||||||
// parameters structures as well
|
|
||||||
// this is important to provide a simple access to
|
|
||||||
// request (no distinction between files and plain
|
|
||||||
// params)
|
|
||||||
Vector existingValues = (Vector) parameters.get(name); |
|
||||||
|
|
||||||
if (existingValues == null) { |
|
||||||
existingValues = new Vector(); |
|
||||||
parameters.put(name, existingValues); |
|
||||||
} |
|
||||||
|
|
||||||
existingValues.addElement(fileName); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} catch (Exception e) { |
|
||||||
logCat.error("MultipartRequest", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the content type of the specified file (as supplied by the client |
|
||||||
* browser), or null if the file was not included in the upload. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the file name. |
|
||||||
* @return the content type of the file. |
|
||||||
*/ |
|
||||||
public String getContentType(String name) { |
|
||||||
try { |
|
||||||
//#changed by joe peer
|
|
||||||
//UploadedFile file = (UploadedFile)files.get(name);
|
|
||||||
FileHolder filePart = (FileHolder) files.get(name); |
|
||||||
|
|
||||||
return filePart.getContentType(); // may be null
|
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns a FilePart object for the specified file this method was added by |
|
||||||
* joe peer |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the file name. |
|
||||||
* @return a FilePart object for the named file. |
|
||||||
*/ |
|
||||||
public FileHolder getFileHolder(String name) { |
|
||||||
try { |
|
||||||
return (FileHolder) files.get(name); |
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns a InputStream object for the specified file saved on the server's |
|
||||||
* filesystem, or null if the file was not included in the upload. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the file name. |
|
||||||
* @return a InputStream object for the named file. |
|
||||||
*/ |
|
||||||
public InputStream getFileInputStream(String name) { |
|
||||||
try { |
|
||||||
//#changed by joe peer
|
|
||||||
//UploadedFile file = (UploadedFile)files.get(name);
|
|
||||||
FileHolder filePart = (FileHolder) files.get(name); |
|
||||||
|
|
||||||
return filePart.getInputStreamFromBuffer(); // may be null
|
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the names of all the uploaded files as an Enumeration of Strings. |
|
||||||
* It returns an empty Enumeration if there are no uploaded files. Each file |
|
||||||
* name is the name specified by the form, not by the user. |
|
||||||
* |
|
||||||
* @return the names of all the uploaded files as an Enumeration of Strings. |
|
||||||
*/ |
|
||||||
public Enumeration getFileNames() { |
|
||||||
return files.keys(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the filesystem name of the specified file, or null if the file |
|
||||||
* was not included in the upload. A filesystem name is the name specified |
|
||||||
* by the user. It is also the name under which the file is actually saved. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the file name. |
|
||||||
* @return the filesystem name of the file. |
|
||||||
*/ |
|
||||||
public String getFilesystemName(String name) { |
|
||||||
try { |
|
||||||
//#changed by joe peer
|
|
||||||
//UploadedFile file = (UploadedFile)files.get(name);
|
|
||||||
FileHolder filePart = (FileHolder) files.get(name); |
|
||||||
|
|
||||||
return filePart.getFileName(); // may be null
|
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the value of the named parameter as a String, or null if the |
|
||||||
* parameter was not sent or was sent without a value. The value is |
|
||||||
* guaranteed to be in its normal, decoded form. If the parameter has |
|
||||||
* multiple values, only the last one is returned (for backward |
|
||||||
* compatibility). For parameters with multiple values, it's possible the |
|
||||||
* last "value" may be null. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the parameter name. |
|
||||||
* @return the parameter value. |
|
||||||
*/ |
|
||||||
public String getParameter(String name) { |
|
||||||
try { |
|
||||||
Vector values = (Vector) parameters.get(name); |
|
||||||
|
|
||||||
if ((values == null) || (values.size() == 0)) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
String value = (String) values.elementAt(0); |
|
||||||
|
|
||||||
return value; |
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the names of all the parameters as an Enumeration of Strings. It |
|
||||||
* returns an empty Enumeration if there are no parameters. |
|
||||||
* |
|
||||||
* @return the names of all the parameters as an Enumeration of Strings. |
|
||||||
*/ |
|
||||||
public Enumeration getParameterNames() { |
|
||||||
return parameters.keys(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the values of the named parameter as a String array, or null if |
|
||||||
* the parameter was not sent. The array has one entry for each parameter |
|
||||||
* field sent. If any field was sent without a value that entry is stored in |
|
||||||
* the array as a null. The values are guaranteed to be in their normal, |
|
||||||
* decoded form. A single value is returned as a one-element array. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the parameter name. |
|
||||||
* @return the parameter values. |
|
||||||
*/ |
|
||||||
public String[] getParameterValues(String name) { |
|
||||||
try { |
|
||||||
Vector values = (Vector) parameters.get(name); |
|
||||||
|
|
||||||
if ((values == null) || (values.size() == 0)) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
String[] valuesArray = new String[values.size()]; |
|
||||||
values.copyInto(valuesArray); |
|
||||||
|
|
||||||
return valuesArray; |
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,699 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2002-2016 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
/* taken/copied from 'spring-security-web-6.2.8.jar' as a base for patching */ |
|
||||||
|
|
||||||
package org.springframework.security.web.util; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
import java.io.PrintWriter; |
|
||||||
import java.util.Locale; |
|
||||||
|
|
||||||
import jakarta.servlet.ServletOutputStream; |
|
||||||
import jakarta.servlet.WriteListener; |
|
||||||
import jakarta.servlet.http.HttpServletResponse; |
|
||||||
import jakarta.servlet.http.HttpServletResponseWrapper; |
|
||||||
|
|
||||||
/** |
|
||||||
* Base class for response wrappers which encapsulate the logic for handling an event when |
|
||||||
* the {@link jakarta.servlet.http.HttpServletResponse} is committed. |
|
||||||
* |
|
||||||
* @author Rob Winch |
|
||||||
* @since 4.0.2 |
|
||||||
*/ |
|
||||||
public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper { |
|
||||||
|
|
||||||
private boolean disableOnCommitted; |
|
||||||
|
|
||||||
/** |
|
||||||
* The Content-Length response header. If this is greater than 0, then once |
|
||||||
* {@link #contentWritten} is larger than or equal the response is considered |
|
||||||
* committed. |
|
||||||
*/ |
|
||||||
private long contentLength; |
|
||||||
|
|
||||||
/** |
|
||||||
* The size of data written to the response body. The field will only be updated when |
|
||||||
* {@link #disableOnCommitted} is false. |
|
||||||
*/ |
|
||||||
private long contentWritten; |
|
||||||
|
|
||||||
/** |
|
||||||
* @param response the response to be wrapped |
|
||||||
*/ |
|
||||||
public OnCommittedResponseWrapper(HttpServletResponse response) { |
|
||||||
super(response); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void addHeader(String name, String value) { |
|
||||||
checkContentLengthHeader(name, value); |
|
||||||
super.addHeader(name, value); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void addIntHeader(String name, int value) { |
|
||||||
checkContentLengthHeader(name, value); |
|
||||||
super.addIntHeader(name, value); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setHeader(String name, String value) { |
|
||||||
checkContentLengthHeader(name, value); |
|
||||||
super.setHeader(name, value); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setIntHeader(String name, int value) { |
|
||||||
checkContentLengthHeader(name, value); |
|
||||||
super.setIntHeader(name, value); |
|
||||||
} |
|
||||||
|
|
||||||
private void checkContentLengthHeader(String name, int value) { |
|
||||||
if ("Content-Length".equalsIgnoreCase(name)) { |
|
||||||
setContentLength(value); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void checkContentLengthHeader(String name, String value) { |
|
||||||
if ("Content-Length".equalsIgnoreCase(name)) { |
|
||||||
setContentLength(Long.parseLong(value)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setContentLength(int len) { |
|
||||||
setContentLength((long) len); |
|
||||||
super.setContentLength(len); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setContentLengthLong(long len) { |
|
||||||
setContentLength(len); |
|
||||||
super.setContentLengthLong(len); |
|
||||||
} |
|
||||||
|
|
||||||
private void setContentLength(long len) { |
|
||||||
this.contentLength = len; |
|
||||||
checkContentLength(0); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Invoke this method to disable invoking |
|
||||||
* {@link OnCommittedResponseWrapper#onResponseCommitted()} when the |
|
||||||
* {@link jakarta.servlet.http.HttpServletResponse} is committed. This can be useful |
|
||||||
* in the event that Async Web Requests are made. |
|
||||||
*/ |
|
||||||
protected void disableOnResponseCommitted() { |
|
||||||
this.disableOnCommitted = true; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Returns true if {@link #onResponseCommitted()} will be invoked when the response is |
|
||||||
* committed, else false. |
|
||||||
* @return if {@link #onResponseCommitted()} is enabled |
|
||||||
*/ |
|
||||||
protected boolean isDisableOnResponseCommitted() { |
|
||||||
return this.disableOnCommitted; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Implement the logic for handling the |
|
||||||
* {@link jakarta.servlet.http.HttpServletResponse} being committed |
|
||||||
*/ |
|
||||||
protected abstract void onResponseCommitted(); |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the superclass <code>sendError()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public final void sendError(int sc) throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
super.sendError(sc); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the superclass <code>sendError()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public final void sendError(int sc, String msg) throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
super.sendError(sc, msg); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the superclass <code>sendRedirect()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public final void sendRedirect(String location) throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
super.sendRedirect(location); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the calling <code>getOutputStream().close()</code> or |
|
||||||
* <code>getOutputStream().flush()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public ServletOutputStream getOutputStream() throws IOException { |
|
||||||
return new SaveContextServletOutputStream(super.getOutputStream()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the <code>getWriter().close()</code> or |
|
||||||
* <code>getWriter().flush()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public PrintWriter getWriter() throws IOException { |
|
||||||
return new SaveContextPrintWriter(super.getWriter()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the superclass <code>flushBuffer()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public void flushBuffer() throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
super.flushBuffer(); |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(boolean content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
checkContentLength(content ? 4 : 5); // TODO Localization
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(char content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
checkContentLength(1); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(Object content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength(String.valueOf(content)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(byte[] content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
checkContentLength((content != null) ? content.length : 0); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(char[] content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
checkContentLength((content != null) ? content.length : 0); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(int content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength(String.valueOf(content)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(float content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength(String.valueOf(content)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(double content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength(String.valueOf(content)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLengthLn() { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength("\r\n"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(String content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
int contentLength = (content != null) ? content.length() : 4; |
|
||||||
checkContentLength(contentLength); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Adds the contentLengthToWrite to the total contentWritten size and checks to see if |
|
||||||
* the response should be written. |
|
||||||
* @param contentLengthToWrite the size of the content that is about to be written. |
|
||||||
*/ |
|
||||||
private void checkContentLength(long contentLengthToWrite) { |
|
||||||
this.contentWritten += contentLengthToWrite; |
|
||||||
boolean isBodyFullyWritten = this.contentLength > 0 && this.contentWritten >= this.contentLength; |
|
||||||
int bufferSize = getBufferSize(); |
|
||||||
boolean requiresFlush = bufferSize > 0 && this.contentWritten >= bufferSize; |
|
||||||
if (isBodyFullyWritten || requiresFlush) { |
|
||||||
doOnResponseCommitted(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Calls <code>onResponseCommmitted()</code> with the current contents as long as |
|
||||||
* {@link #disableOnResponseCommitted()} was not invoked. |
|
||||||
*/ |
|
||||||
private void doOnResponseCommitted() { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
onResponseCommitted(); |
|
||||||
disableOnResponseCommitted(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Ensures {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before |
|
||||||
* calling the prior to methods that commit the response. We delegate all methods to |
|
||||||
* the original {@link java.io.PrintWriter} to ensure that the behavior is as close to |
|
||||||
* the original {@link java.io.PrintWriter} as possible. See SEC-2039 |
|
||||||
* |
|
||||||
* @author Rob Winch |
|
||||||
*/ |
|
||||||
private class SaveContextPrintWriter extends PrintWriter { |
|
||||||
|
|
||||||
private final PrintWriter delegate; |
|
||||||
|
|
||||||
SaveContextPrintWriter(PrintWriter delegate) { |
|
||||||
super(delegate); |
|
||||||
this.delegate = delegate; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void flush() { |
|
||||||
doOnResponseCommitted(); |
|
||||||
this.delegate.flush(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void close() { |
|
||||||
doOnResponseCommitted(); |
|
||||||
this.delegate.close(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean equals(Object obj) { |
|
||||||
return this.delegate.equals(obj); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public int hashCode() { |
|
||||||
return this.delegate.hashCode(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return getClass().getName() + "[delegate=" + this.delegate.toString() + "]"; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean checkError() { |
|
||||||
return this.delegate.checkError(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(int c) { |
|
||||||
trackContentLength(c); |
|
||||||
this.delegate.write(c); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(char[] buf, int off, int len) { |
|
||||||
checkContentLength(len); |
|
||||||
this.delegate.write(buf, off, len); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(char[] buf) { |
|
||||||
trackContentLength(buf); |
|
||||||
this.delegate.write(buf); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(String s, int off, int len) { |
|
||||||
checkContentLength(len); |
|
||||||
this.delegate.write(s, off, len); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(String s) { |
|
||||||
trackContentLength(s); |
|
||||||
this.delegate.write(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(boolean b) { |
|
||||||
trackContentLength(b); |
|
||||||
this.delegate.print(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(char c) { |
|
||||||
trackContentLength(c); |
|
||||||
this.delegate.print(c); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(int i) { |
|
||||||
trackContentLength(i); |
|
||||||
this.delegate.print(i); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(long l) { |
|
||||||
trackContentLength(l); |
|
||||||
this.delegate.print(l); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(float f) { |
|
||||||
trackContentLength(f); |
|
||||||
this.delegate.print(f); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(double d) { |
|
||||||
trackContentLength(d); |
|
||||||
this.delegate.print(d); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(char[] s) { |
|
||||||
trackContentLength(s); |
|
||||||
this.delegate.print(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(String s) { |
|
||||||
trackContentLength(s); |
|
||||||
this.delegate.print(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(Object obj) { |
|
||||||
trackContentLength(obj); |
|
||||||
this.delegate.print(obj); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println() { |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(boolean x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(char x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(int x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(long x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(float x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(double x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(char[] x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(String x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(Object x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter printf(String format, Object... args) { |
|
||||||
return this.delegate.printf(format, args); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter printf(Locale l, String format, Object... args) { |
|
||||||
return this.delegate.printf(l, format, args); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter format(String format, Object... args) { |
|
||||||
return this.delegate.format(format, args); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter format(Locale l, String format, Object... args) { |
|
||||||
return this.delegate.format(l, format, args); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter append(CharSequence csq) { |
|
||||||
checkContentLength(csq.length()); |
|
||||||
return this.delegate.append(csq); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter append(CharSequence csq, int start, int end) { |
|
||||||
checkContentLength(end - start); |
|
||||||
return this.delegate.append(csq, start, end); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter append(char c) { |
|
||||||
trackContentLength(c); |
|
||||||
return this.delegate.append(c); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Ensures{@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before |
|
||||||
* calling methods that commit the response. We delegate all methods to the original |
|
||||||
* {@link jakarta.servlet.ServletOutputStream} to ensure that the behavior is as close |
|
||||||
* to the original {@link jakarta.servlet.ServletOutputStream} as possible. See |
|
||||||
* SEC-2039 |
|
||||||
* |
|
||||||
* @author Rob Winch |
|
||||||
*/ |
|
||||||
private class SaveContextServletOutputStream extends ServletOutputStream { |
|
||||||
|
|
||||||
private final ServletOutputStream delegate; |
|
||||||
|
|
||||||
SaveContextServletOutputStream(ServletOutputStream delegate) { |
|
||||||
this.delegate = delegate; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(int b) throws IOException { |
|
||||||
trackContentLength(b); |
|
||||||
this.delegate.write(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void flush() throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
this.delegate.flush(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void close() throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
this.delegate.close(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(boolean b) throws IOException { |
|
||||||
trackContentLength(b); |
|
||||||
this.delegate.print(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(char c) throws IOException { |
|
||||||
trackContentLength(c); |
|
||||||
this.delegate.print(c); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(double d) throws IOException { |
|
||||||
trackContentLength(d); |
|
||||||
this.delegate.print(d); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(float f) throws IOException { |
|
||||||
trackContentLength(f); |
|
||||||
this.delegate.print(f); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(int i) throws IOException { |
|
||||||
trackContentLength(i); |
|
||||||
this.delegate.print(i); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(long l) throws IOException { |
|
||||||
trackContentLength(l); |
|
||||||
this.delegate.print(l); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(String s) throws IOException { |
|
||||||
trackContentLength(s); |
|
||||||
this.delegate.print(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println() throws IOException { |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(boolean b) throws IOException { |
|
||||||
trackContentLength(b); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(char c) throws IOException { |
|
||||||
trackContentLength(c); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(c); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(double d) throws IOException { |
|
||||||
trackContentLength(d); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(d); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(float f) throws IOException { |
|
||||||
trackContentLength(f); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(f); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(int i) throws IOException { |
|
||||||
trackContentLength(i); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(i); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(long l) throws IOException { |
|
||||||
trackContentLength(l); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(l); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(String s) throws IOException { |
|
||||||
trackContentLength(s); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(byte[] b) throws IOException { |
|
||||||
trackContentLength(b); |
|
||||||
this.delegate.write(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(byte[] b, int off, int len) throws IOException { |
|
||||||
checkContentLength(len); |
|
||||||
this.delegate.write(b, off, len); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean isReady() { |
|
||||||
return this.delegate.isReady(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setWriteListener(WriteListener writeListener) { |
|
||||||
this.delegate.setWriteListener(writeListener); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean equals(Object obj) { |
|
||||||
return this.delegate.equals(obj); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public int hashCode() { |
|
||||||
return this.delegate.hashCode(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return getClass().getName() + "[delegate=" + this.delegate.toString() + "]"; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,35 +1,31 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class ActivatableItem implements ActivatableItemI { |
public class ActivatableItem implements ActivatableItemI { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
private boolean isActive; |
||||||
private boolean isActive; |
/** |
||||||
|
* |
||||||
/** |
*/ |
||||||
* |
public ActivatableItem() { |
||||||
*/ |
super(); |
||||||
public ActivatableItem() { |
} |
||||||
super(); |
|
||||||
} |
/* (non-Javadoc) |
||||||
|
* @see de.memtext.baseobjects.ActivatableItemI#isActive() |
||||||
/* (non-Javadoc) |
*/ |
||||||
* @see de.memtext.baseobjects.ActivatableItemI#isActive() |
public boolean isActive() { |
||||||
*/ |
return isActive; |
||||||
@Override |
} |
||||||
public boolean isActive() { |
|
||||||
return isActive; |
/* (non-Javadoc) |
||||||
} |
* @see de.memtext.baseobjects.ActivatableItemI#setActive(boolean) |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
public void setActive(boolean isActive) { |
||||||
* @see de.memtext.baseobjects.ActivatableItemI#setActive(boolean) |
this.isActive=isActive; |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public void setActive(boolean isActive) { |
} |
||||||
this.isActive = isActive; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,11 +1,10 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public interface ActivatableItemI { |
public interface ActivatableItemI { |
||||||
boolean isActive(); |
boolean isActive(); |
||||||
|
void setActive(boolean isActive); |
||||||
void setActive(boolean isActive); |
} |
||||||
} |
|
||||||
|
|||||||
@ -1,39 +1,40 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
public class ComparableObject extends NamedObject implements Comparable { |
public class ComparableObject extends NamedObject implements Comparable { |
||||||
private int sortNr; |
private int sortNr; |
||||||
|
private static final long serialVersionUID = 1; |
||||||
private static final long serialVersionUID = 1; |
|
||||||
|
public ComparableObject(String name, int sortNr) { |
||||||
public ComparableObject(String name, int sortNr) { |
super(name); |
||||||
super(name); |
this.sortNr = sortNr; |
||||||
this.sortNr = sortNr; |
} |
||||||
} |
|
||||||
|
public int compareTo(Object o) { |
||||||
@Override |
int result = 0; |
||||||
public int compareTo(Object o) { |
if (getSortNr() < ((ComparableObject) o).getSortNr()) |
||||||
int result = 0; |
result = -1; |
||||||
if (getSortNr() < ((ComparableObject) o).getSortNr()) result = -1; |
if (getSortNr() > ((ComparableObject) o).getSortNr()) |
||||||
if (getSortNr() > ((ComparableObject) o).getSortNr()) result = 1; |
result = 1; |
||||||
return result; |
return result; |
||||||
} |
} |
||||||
|
|
||||||
public int getSortNr() { |
public int getSortNr() { |
||||||
return sortNr; |
return sortNr; |
||||||
} |
} |
||||||
|
|
||||||
@Override |
public boolean equals(Object o) { |
||||||
public boolean equals(Object o) { |
boolean result = false; |
||||||
boolean result = false; |
ComparableObject comp = (ComparableObject) o; |
||||||
ComparableObject comp = (ComparableObject) o; |
if (this.getName().equals(comp.getName()) |
||||||
if (this.getName().equals(comp.getName()) && this.getSortNr() == comp.getSortNr()) result = true; |
&& this.getSortNr() == comp.getSortNr()) |
||||||
|
result = true; |
||||||
return result; |
|
||||||
} |
return result; |
||||||
|
} |
||||||
public void setSortNr(int sortNr) { |
|
||||||
this.sortNr = sortNr; |
public void setSortNr(int sortNr) { |
||||||
} |
this.sortNr = sortNr; |
||||||
} |
} |
||||||
|
} |
||||||
//Created on 22.10.2004 at 16:20:48
|
|
||||||
|
//Created on 22.10.2004 at 16:20:48
|
||||||
|
|||||||
@ -1,52 +1,50 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* List with different behaviour when setting items, |
* List with different behaviour when setting items, |
||||||
* when index higher than count of elements doesn't throw |
* when index higher than count of elements doesn't throw |
||||||
* Exception, but adds as many nulls as necessary up to the |
* Exception, but adds as many nulls as necessary up to the |
||||||
* right count of elements and then sets the indicated position to |
* right count of elements and then sets the indicated position to |
||||||
* the new value |
* the new value |
||||||
* |
* |
||||||
* * If for example a value for column 5 is to be stored, but the data List only |
* * If for example a value for column 5 is to be stored, but the data List only |
||||||
* contains values for column 1 and 2, for column 3 and 4 null values are stored. |
* contains values for column 1 and 2, for column 3 and 4 null values are stored. |
||||||
|
|
||||||
* */ |
* */ |
||||||
public class DataList extends LinkedList { |
public class DataList extends LinkedList { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
*/ |
*/ |
||||||
public DataList() { |
public DataList() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* @param c |
* @param c |
||||||
*/ |
*/ |
||||||
public DataList(Collection c) { |
public DataList(Collection c) { |
||||||
super(c); |
super(c); |
||||||
|
|
||||||
} |
} |
||||||
|
/** |
||||||
/** |
* If for example a value for column 5 is to be stored, but the data List only |
||||||
* If for example a value for column 5 is to be stored, but the data List only |
* contains values for column 1 and 2, for column 3 and 4 null values are stored. |
||||||
* contains values for column 1 and 2, for column 3 and 4 null values are stored. |
|
||||||
|
*/ |
||||||
*/ |
public Object set(int index, Object o) { |
||||||
@Override |
while (index > this.size() - 1) { |
||||||
public Object set(int index, Object o) { |
this.add(null); |
||||||
while (index > this.size() - 1) { |
} |
||||||
this.add(null); |
Object previous = this.get(index); |
||||||
} |
super.set(index, o); |
||||||
Object previous = this.get(index); |
return previous; |
||||||
super.set(index, o); |
} |
||||||
return previous; |
|
||||||
} |
} |
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,21 +1,18 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseAdapter; |
||||||
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
||||||
|
|
||||||
public abstract class DoubleClickMouseListener extends MouseAdapter { |
public abstract class DoubleClickMouseListener extends MouseAdapter { |
||||||
|
|
||||||
public DoubleClickMouseListener() { |
public DoubleClickMouseListener() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
|
public final void mousePressed(MouseEvent e) { |
||||||
@Override |
if (e.getClickCount() == 2) doubleClickOccured(); |
||||||
public final void mousePressed(MouseEvent e) { |
} |
||||||
if (e.getClickCount() == 2) doubleClickOccured(); |
protected abstract void doubleClickOccured() ; |
||||||
} |
|
||||||
|
|
||||||
protected abstract void doubleClickOccured(); |
} |
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
//Created on 16.03.2004 at 15:51:43
|
//Created on 16.03.2004 at 15:51:43
|
||||||
@ -1,57 +1,50 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class IdObject implements IdObjectI, Serializable { |
public class IdObject implements IdObjectI,Serializable { |
||||||
private Object id; |
private Object id; |
||||||
|
private static final long serialVersionUID = 1; |
||||||
private static final long serialVersionUID = 1; |
public IdObject() { |
||||||
|
|
||||||
public IdObject() { |
} |
||||||
|
public IdObject(Object id) { |
||||||
} |
setId(id); |
||||||
|
|
||||||
public IdObject(Object id) { |
} |
||||||
setId(id); |
|
||||||
|
/** |
||||||
} |
* @return |
||||||
|
*/ |
||||||
/** |
public Object getId() { |
||||||
* @return |
return id; |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public Object getId() { |
|
||||||
return id; |
|
||||||
} |
/** |
||||||
|
* @param object |
||||||
|
*/ |
||||||
|
public void setId(Object object) { |
||||||
/** |
id = object; |
||||||
* @param object |
} |
||||||
*/ |
|
||||||
@Override |
public String toString() |
||||||
public void setId(Object object) { |
{ |
||||||
id = object; |
return "id:"+getId(); |
||||||
} |
} |
||||||
|
/** |
||||||
@Override |
* Provides a deep copy |
||||||
public String toString() { |
*/ |
||||||
return "id:" + getId(); |
public Object clone() throws CloneNotSupportedException { |
||||||
} |
if (id!=null&&!(id instanceof String)&&!(id instanceof Integer)) |
||||||
|
throw new CloneNotSupportedException(" You have to check in IdObject.clone if deep copying is necessary for class "+id.getClass()); |
||||||
/** |
|
||||||
* Provides a deep copy |
IdObject cl=new IdObject(this.getId()); |
||||||
*/ |
return cl; |
||||||
@Override |
} |
||||||
public Object clone() throws CloneNotSupportedException { |
} |
||||||
if (id != null && !(id instanceof String) && !(id instanceof Integer)) |
|
||||||
throw new CloneNotSupportedException(" You have to check in IdObject.clone if deep copying is necessary for class " + id.getClass()); |
|
||||||
|
|
||||||
IdObject cl = new IdObject(this.getId()); |
|
||||||
return cl; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,13 +1,11 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
/** |
||||||
/** |
* @see de.memtext.util.TreeUtils for a method creating key list (1,2,4) from nodes |
||||||
* @see de.memtext.util.TreeUtils for a method creating key list (1,2,4) from nodes |
*/ |
||||||
*/ |
public interface IdObjectI { |
||||||
public interface IdObjectI { |
public Object getId(); |
||||||
public Object getId(); |
public void setId(Object id); |
||||||
|
|
||||||
public void setId(Object id); |
} |
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
//Created on 30.01.2004 at 13:03:06
|
//Created on 30.01.2004 at 13:03:06
|
||||||
@ -1,33 +1,28 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* For classes up in the hierarchy which need a name in some context |
* For classes up in the hierarchy which need a name in some context |
||||||
* but shouldn't pass it on to inheriting classes |
* but shouldn't pass it on to inheriting classes |
||||||
*/ |
*/ |
||||||
public final class NameDecorator implements NamedObjectI { |
public final class NameDecorator implements NamedObjectI{ |
||||||
private Object object; |
private Object object; |
||||||
|
private String name; |
||||||
private String name; |
public NameDecorator(String name,Object object) { |
||||||
|
this.name=name; |
||||||
public NameDecorator(String name, Object object) { |
this.object=object; |
||||||
this.name = name; |
} |
||||||
this.object = object; |
public String getName() { |
||||||
} |
return name; |
||||||
|
} |
||||||
@Override |
public void setName(String name) { |
||||||
public String getName() { |
this.name=name; |
||||||
return name; |
} |
||||||
} |
|
||||||
|
public Object getObject() |
||||||
@Override |
{ |
||||||
public void setName(String name) { |
return object; |
||||||
this.name = name; |
} |
||||||
} |
} |
||||||
|
|
||||||
public Object getObject() { |
|
||||||
return object; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 25.11.2003 at 14:49:50
|
//Created on 25.11.2003 at 14:49:50
|
||||||
@ -1,88 +1,83 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
|
|
||||||
import de.memtext.util.EqualsUtil; |
import de.memtext.util.EqualsUtil; |
||||||
import de.memtext.util.HashCodeUtil; |
import de.memtext.util.HashCodeUtil; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
*/ |
*/ |
||||||
public class NamedIdObject extends NamedObject implements NamedIdObjectI, Serializable { |
public class NamedIdObject extends NamedObject implements NamedIdObjectI, |
||||||
private Object id; |
Serializable { |
||||||
|
private Object id; |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
public NamedIdObject() { |
||||||
public NamedIdObject() { |
} |
||||||
} |
|
||||||
|
public NamedIdObject(NamedObjectI namedObject) { |
||||||
public NamedIdObject(NamedObjectI namedObject) { |
setName(namedObject.getName()); |
||||||
setName(namedObject.getName()); |
} |
||||||
} |
|
||||||
|
public NamedIdObject(Object id, String name) { |
||||||
public NamedIdObject(Object id, String name) { |
setId(id); |
||||||
setId(id); |
setName(name); |
||||||
setName(name); |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* @return |
||||||
* @return |
*/ |
||||||
*/ |
public Object getId() { |
||||||
@Override |
return id; |
||||||
public Object getId() { |
} |
||||||
return id; |
|
||||||
} |
/** |
||||||
|
* @param object |
||||||
/** |
*/ |
||||||
* @param object |
public void setId(Object id) { |
||||||
*/ |
this.id = id; |
||||||
@Override |
} |
||||||
public void setId(Object id) { |
|
||||||
this.id = id; |
public String toString() { |
||||||
} |
return getId() + " - " + getName(); |
||||||
|
} |
||||||
@Override |
public boolean equals(Object o) |
||||||
public String toString() { |
{ |
||||||
return getId() + " - " + getName(); |
boolean result=false; |
||||||
} |
if (o instanceof NamedIdObject) |
||||||
|
{ |
||||||
@Override |
NamedIdObject o2=(NamedIdObject)o; |
||||||
public boolean equals(Object o) { |
result=EqualsUtil.areEqual(this.getId(),o2.getId())&&EqualsUtil.areEqual(this.getName(),o2.getName()); |
||||||
boolean result = false; |
|
||||||
if (o instanceof NamedIdObject) { |
|
||||||
NamedIdObject o2 = (NamedIdObject) o; |
} |
||||||
result = EqualsUtil.areEqual(this.getId(), o2.getId()) && EqualsUtil.areEqual(this.getName(), o2.getName()); |
return result; |
||||||
|
} |
||||||
|
public int hashCode(){ |
||||||
} |
int result = HashCodeUtil.SEED; |
||||||
return result; |
//collect the contributions of various fields
|
||||||
} |
result = HashCodeUtil.hash(result, getId()); |
||||||
|
result = HashCodeUtil.hash(result, getName()); |
||||||
@Override |
|
||||||
public int hashCode() { |
return result; |
||||||
int result = HashCodeUtil.SEED; |
} |
||||||
//collect the contributions of various fields
|
/** |
||||||
result = HashCodeUtil.hash(result, getId()); |
* Provides a deep copy |
||||||
result = HashCodeUtil.hash(result, getName()); |
*/ |
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
return result; |
|
||||||
} |
NamedIdObject cl = new NamedIdObject((NamedObject) super.clone()); |
||||||
|
|
||||||
/** |
if (id != null && !(id instanceof String) && !(id instanceof Integer)) |
||||||
* Provides a deep copy |
throw new CloneNotSupportedException( |
||||||
*/ |
" You have to check in NamedIdObject.clone if deep copying is necessary for class " |
||||||
@Override |
+ id.getClass()); |
||||||
public Object clone() throws CloneNotSupportedException { |
|
||||||
|
if (this.id != null) |
||||||
NamedIdObject cl = new NamedIdObject((NamedObject) super.clone()); |
cl.setId(id); |
||||||
|
return cl; |
||||||
if (id != null && !(id instanceof String) && !(id instanceof Integer)) |
} |
||||||
throw new CloneNotSupportedException(" You have to check in NamedIdObject.clone if deep copying is necessary for class " + id.getClass()); |
|
||||||
|
|
||||||
if (this.id != null) cl.setId(id); |
|
||||||
return cl; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
@ -1,10 +1,10 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public interface NamedIdObjectI extends NamedObjectI, IdObjectI { |
public interface NamedIdObjectI extends NamedObjectI, IdObjectI{ |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
@ -1,88 +1,91 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
|
|
||||||
import de.memtext.tree.KeyParentEqualException; |
import de.memtext.tree.KeyParentEqualException; |
||||||
import de.memtext.util.EqualsUtil; |
import de.memtext.util.EqualsUtil; |
||||||
import de.memtext.util.HashCodeUtil; |
import de.memtext.util.HashCodeUtil; |
||||||
|
|
||||||
public class NamedIdObjectWithParent extends NamedIdObject implements NamedIdObjectWithParentI, Serializable { |
public class NamedIdObjectWithParent extends NamedIdObject implements |
||||||
private Object parentKey; |
NamedIdObjectWithParentI, Serializable { |
||||||
|
private Object parentKey; |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
public NamedIdObjectWithParent() { |
||||||
public NamedIdObjectWithParent() { |
super(); |
||||||
super(); |
} |
||||||
} |
|
||||||
|
public NamedIdObjectWithParent(NamedIdObjectI namedIdObject) { |
||||||
public NamedIdObjectWithParent(NamedIdObjectI namedIdObject) { |
setId(namedIdObject.getId()); |
||||||
setId(namedIdObject.getId()); |
setName(namedIdObject.getName()); |
||||||
setName(namedIdObject.getName()); |
} |
||||||
} |
|
||||||
|
public NamedIdObjectWithParent(Object id, String name) { |
||||||
public NamedIdObjectWithParent(Object id, String name) { |
super(id, name); |
||||||
super(id, name); |
} |
||||||
} |
|
||||||
|
public NamedIdObjectWithParent(Object id, String name, Object parentKey) |
||||||
public NamedIdObjectWithParent(Object id, String name, Object parentKey) throws KeyParentEqualException { |
throws KeyParentEqualException { |
||||||
super(id, name); |
super(id, name); |
||||||
setParentKey(parentKey); |
setParentKey(parentKey); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
public Object getParentKey() { |
||||||
public Object getParentKey() { |
return parentKey; |
||||||
return parentKey; |
} |
||||||
} |
|
||||||
|
public void setParentKey(Object parentKey) throws KeyParentEqualException { |
||||||
@Override |
this.parentKey = parentKey; |
||||||
public void setParentKey(Object parentKey) throws KeyParentEqualException { |
if ((getId() == null && getParentKey() == null) |
||||||
this.parentKey = parentKey; |
|| (getId() != null && getId().equals(getParentKey()))) |
||||||
if ((getId() == null && getParentKey() == null) || (getId() != null && getId().equals(getParentKey()))) throw new KeyParentEqualException((NamedIdObjectWithParentI) this); |
throw new KeyParentEqualException((NamedIdObjectWithParentI) this); |
||||||
} |
} |
||||||
|
//TODO aufteilen auf übergeordnete Objekte
|
||||||
//TODO aufteilen auf übergeordnete Objekte
|
public boolean equals(Object obj) { |
||||||
@Override |
|
||||||
public boolean equals(Object obj) { |
if ( this == obj ) return true; |
||||||
|
if ( obj == null || obj.getClass() != this.getClass() ) return false; |
||||||
if (this == obj) return true; |
|
||||||
if (obj == null || obj.getClass() != this.getClass()) return false; |
NamedIdObjectWithParent i2=(NamedIdObjectWithParent)obj; |
||||||
|
return |
||||||
NamedIdObjectWithParent i2 = (NamedIdObjectWithParent) obj; |
EqualsUtil.areEqual(this.getId(), i2.getId()) && |
||||||
return EqualsUtil.areEqual(this.getId(), i2.getId()) && EqualsUtil.areEqual(this.getName(), i2.getName()) && EqualsUtil.areEqual(this.getParentKey(), i2.getParentKey()); |
EqualsUtil.areEqual(this.getName(), i2.getName()) && |
||||||
|
EqualsUtil.areEqual(this.getParentKey(), i2.getParentKey()); |
||||||
|
|
||||||
} |
|
||||||
|
} |
||||||
/* |
|
||||||
* @see java.lang.Object#hashCode() |
/* |
||||||
*/ |
* @see java.lang.Object#hashCode() |
||||||
@Override |
*/ |
||||||
public int hashCode() { |
public int hashCode() { |
||||||
int result = HashCodeUtil.SEED; |
int result = HashCodeUtil.SEED; |
||||||
result = HashCodeUtil.hash(result, getId()); |
result = HashCodeUtil.hash(result, getId()); |
||||||
result = HashCodeUtil.hash(result, getName()); |
result = HashCodeUtil.hash(result, getName()); |
||||||
result = HashCodeUtil.hash(result, getParentKey()); |
result = HashCodeUtil.hash(result, getParentKey()); |
||||||
return result; |
return result ; |
||||||
} |
} |
||||||
|
/** |
||||||
/** |
* Provides a deep copy |
||||||
* Provides a deep copy |
*/ |
||||||
*/ |
public Object clone() throws CloneNotSupportedException { |
||||||
@Override |
|
||||||
public Object clone() throws CloneNotSupportedException { |
NamedIdObjectWithParent cl = new NamedIdObjectWithParent( |
||||||
|
(NamedIdObject) super.clone()); |
||||||
NamedIdObjectWithParent cl = new NamedIdObjectWithParent((NamedIdObject) super.clone()); |
|
||||||
|
if (parentKey != null && !(parentKey instanceof String) |
||||||
if (parentKey != null && !(parentKey instanceof String) && !(parentKey instanceof Integer)) |
&& !(parentKey instanceof Integer)) |
||||||
throw new CloneNotSupportedException(" You have to check in NamedIdObjectWithParent.clone if deep copying is necessary for class " + parentKey.getClass()); |
throw new CloneNotSupportedException( |
||||||
|
" You have to check in NamedIdObjectWithParent.clone if deep copying is necessary for class " |
||||||
if (this.parentKey != null) try { |
+ parentKey.getClass()); |
||||||
cl.setParentKey(this.parentKey); |
|
||||||
} catch (KeyParentEqualException e) { |
if (this.parentKey != null) |
||||||
throw new CloneNotSupportedException("Cloning didn't work" + e); |
try { |
||||||
} |
cl.setParentKey(this.parentKey); |
||||||
return cl; |
} catch (KeyParentEqualException e) { |
||||||
} |
throw new CloneNotSupportedException("Cloning didn't work" + e); |
||||||
} |
} |
||||||
|
return cl; |
||||||
//Created on 18.11.2003
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 18.11.2003
|
||||||
|
|||||||
@ -1,10 +1,9 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import de.memtext.tree.KeyParentEqualException; |
import de.memtext.tree.KeyParentEqualException; |
||||||
|
|
||||||
public interface NamedIdObjectWithParentI extends NamedIdObjectI { |
public interface NamedIdObjectWithParentI extends NamedIdObjectI { |
||||||
public Object getParentKey(); |
public Object getParentKey(); |
||||||
|
public void setParentKey(Object parentKey) throws KeyParentEqualException; |
||||||
public void setParentKey(Object parentKey) throws KeyParentEqualException; |
} |
||||||
} |
|
||||||
//Created on 18.11.2003
|
//Created on 18.11.2003
|
||||||
@ -1,57 +1,49 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class NamedObject implements NamedObjectI, Serializable { |
public class NamedObject implements NamedObjectI,Serializable { |
||||||
private String name; |
private String name; |
||||||
|
private static final long serialVersionUID = 1; |
||||||
private static final long serialVersionUID = 1; |
/** |
||||||
|
* |
||||||
/** |
*/ |
||||||
* |
|
||||||
*/ |
public NamedObject() { |
||||||
|
|
||||||
public NamedObject() { |
} |
||||||
|
public NamedObject(String name) { |
||||||
} |
setName(name); |
||||||
|
} |
||||||
public NamedObject(String name) { |
|
||||||
setName(name); |
|
||||||
} |
/** |
||||||
|
* @return |
||||||
|
*/ |
||||||
/** |
public String getName() { |
||||||
* @return |
return name; |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public String getName() { |
|
||||||
return name; |
|
||||||
} |
/** |
||||||
|
* @param string |
||||||
|
*/ |
||||||
|
public void setName(String string) { |
||||||
/** |
name = string; |
||||||
* @param string |
} |
||||||
*/ |
public String toString() { |
||||||
@Override |
return name; |
||||||
public void setName(String string) { |
} |
||||||
name = string; |
|
||||||
} |
/** |
||||||
|
* Provides a deep copy |
||||||
@Override |
*/ |
||||||
public String toString() { |
protected Object clone() throws CloneNotSupportedException { |
||||||
return name; |
return new NamedObject(this.getName()); |
||||||
} |
} |
||||||
|
} |
||||||
/** |
|
||||||
* Provides a deep copy |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
|
||||||
return new NamedObject(this.getName()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,15 +1,13 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public interface NamedObjectI { |
public interface NamedObjectI { |
||||||
|
|
||||||
public String getName(); |
public String getName(); |
||||||
|
|
||||||
public void setName(String name); |
public void setName(String name); |
||||||
|
public String toString(); |
||||||
@Override |
|
||||||
public String toString(); |
|
||||||
} |
} |
||||||
@ -1,34 +1,32 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
/** |
||||||
/** |
* This class holds information about a string that is to be |
||||||
* This class holds information about a string that is to be |
* searched for and another string that the former is to be |
||||||
* searched for and another string that the former is to be |
* replaced with. |
||||||
* replaced with. |
* By default both are empty strings. |
||||||
* By default both are empty strings. |
*/ |
||||||
*/ |
public class SearchReplaceTextHolder { |
||||||
public class SearchReplaceTextHolder { |
private String searchText="", replaceText=""; |
||||||
private String searchText = "", replaceText = ""; |
public SearchReplaceTextHolder() { |
||||||
|
super(); |
||||||
public SearchReplaceTextHolder() { |
} |
||||||
super(); |
|
||||||
} |
public String getReplaceText() { |
||||||
|
return replaceText; |
||||||
public String getReplaceText() { |
} |
||||||
return replaceText; |
|
||||||
} |
public String getSearchText() { |
||||||
|
return searchText; |
||||||
public String getSearchText() { |
} |
||||||
return searchText; |
|
||||||
} |
public void setReplaceText(String string) { |
||||||
|
replaceText = string; |
||||||
public void setReplaceText(String string) { |
} |
||||||
replaceText = string; |
|
||||||
} |
public void setSearchText(String string) { |
||||||
|
searchText = string; |
||||||
public void setSearchText(String string) { |
} |
||||||
searchText = string; |
|
||||||
} |
} |
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
//Created on 04.02.2004 at 11:40:47
|
//Created on 04.02.2004 at 11:40:47
|
||||||
@ -1,98 +1,86 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
import de.memtext.rights.Rights; |
import de.memtext.rights.Rights; |
||||||
|
|
||||||
/** |
/** |
||||||
* stellt einen User dar, könnte sicherer gemacht werden mit |
* stellt einen User dar, könnte sicherer gemacht werden mit |
||||||
* defensive Copying |
* defensive Copying |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class User extends NamedIdObject implements Serializable { |
public class User extends NamedIdObject implements Serializable { |
||||||
private List groupMembershipIds = new ArrayList(5); |
private List groupMembershipIds = new ArrayList(5); |
||||||
|
private String passwd; |
||||||
private String passwd; |
|
||||||
|
private Rights rights; |
||||||
private Rights rights; |
private boolean isAdmin=false; |
||||||
|
private static final long serialVersionUID = 1; |
||||||
private boolean isAdmin = false; |
public User() { |
||||||
|
setName(""); |
||||||
private static final long serialVersionUID = 1; |
setPasswd(""); |
||||||
|
} |
||||||
public User() { |
public User(String username, String passwd) { |
||||||
setName(""); |
setName(username); |
||||||
setPasswd(""); |
setPasswd(passwd); |
||||||
} |
|
||||||
|
} |
||||||
public User(String username, String passwd) { |
|
||||||
setName(username); |
public User(String username, Integer userid) { |
||||||
setPasswd(passwd); |
super(userid,username); |
||||||
|
if (userid == null) |
||||||
} |
throw new IllegalArgumentException("No user without userid allowed"); |
||||||
|
} |
||||||
public User(String username, Integer userid) { |
public User(String username) { |
||||||
super(userid, username); |
setName(username); |
||||||
if (userid == null) throw new IllegalArgumentException("No user without userid allowed"); |
} |
||||||
} |
/** |
||||||
|
* @param groupmemberships |
||||||
public User(String username) { |
*/ |
||||||
setName(username); |
public void addAllGroupmembershipsById(List groupmemberships) { |
||||||
} |
groupMembershipIds.addAll(groupmemberships); |
||||||
|
} |
||||||
/** |
public void addGroupMembershipById(Integer groupid) { |
||||||
* @param groupmemberships |
groupMembershipIds.add(groupid); |
||||||
*/ |
} |
||||||
public void addAllGroupmembershipsById(List groupmemberships) { |
|
||||||
groupMembershipIds.addAll(groupmemberships); |
public String getPasswd() { |
||||||
} |
return passwd; |
||||||
|
} |
||||||
public void addGroupMembershipById(Integer groupid) { |
|
||||||
groupMembershipIds.add(groupid); |
|
||||||
} |
|
||||||
|
public Iterator groupmembershipIdIterator() { |
||||||
public String getPasswd() { |
return groupMembershipIds.iterator(); |
||||||
return passwd; |
} |
||||||
} |
public void removeGroupMembershipById(Integer groupid) { |
||||||
|
groupMembershipIds.remove(groupid); |
||||||
|
} |
||||||
|
|
||||||
public Iterator groupmembershipIdIterator() { |
public void setPasswd(String pwd) { |
||||||
return groupMembershipIds.iterator(); |
passwd = pwd; |
||||||
} |
} |
||||||
|
|
||||||
public void removeGroupMembershipById(Integer groupid) { |
|
||||||
groupMembershipIds.remove(groupid); |
public String toString() |
||||||
} |
{ |
||||||
|
|
||||||
public void setPasswd(String pwd) { |
return getName(); |
||||||
passwd = pwd; |
} |
||||||
} |
public Rights getRights() { |
||||||
|
return rights; |
||||||
|
} |
||||||
@Override |
public void setRights(Rights rights) { |
||||||
public String toString() { |
this.rights = rights; |
||||||
|
} |
||||||
return getName(); |
public boolean isAdmin() { |
||||||
} |
return isAdmin; |
||||||
|
} |
||||||
public Rights getRights() { |
public void setAdmin(boolean isAdmin) { |
||||||
return rights; |
this.isAdmin = isAdmin; |
||||||
} |
} |
||||||
|
|
||||||
public void setRights(Rights rights) { |
} |
||||||
this.rights = rights; |
|
||||||
} |
|
||||||
|
|
||||||
public boolean isAdmin() { |
|
||||||
return isAdmin; |
|
||||||
} |
|
||||||
|
|
||||||
public void setAdmin(boolean isAdmin) { |
|
||||||
this.isAdmin = isAdmin; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,347 +1,321 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.ActivatableItemI; |
import de.memtext.baseobjects.ActivatableItemI; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class ActivatableItemList implements List, Serializable { |
public class ActivatableItemList implements List,Serializable { |
||||||
private List collect = new LinkedList(); |
private List collect = new LinkedList(); |
||||||
|
private static final long serialVersionUID = 1; |
||||||
private static final long serialVersionUID = 1; |
/** |
||||||
|
* |
||||||
/** |
*/ |
||||||
* |
public ActivatableItemList() { |
||||||
*/ |
super(); |
||||||
public ActivatableItemList() { |
} |
||||||
super(); |
|
||||||
} |
public Iterator activeItemIterator() { |
||||||
|
return getActiveItems().iterator(); |
||||||
public Iterator activeItemIterator() { |
} |
||||||
return getActiveItems().iterator(); |
|
||||||
} |
public Collection getActiveItems() { |
||||||
|
Collection result = new LinkedList(); |
||||||
public Collection getActiveItems() { |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
Collection result = new LinkedList(); |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
if (element.isActive()) |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
result.add(element); |
||||||
if (element.isActive()) result.add(element); |
} |
||||||
} |
return result; |
||||||
return result; |
} |
||||||
} |
public void setAllActive(boolean active) { |
||||||
|
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
public void setAllActive(boolean active) { |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
element.setActive(active); |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
} |
||||||
element.setActive(active); |
} |
||||||
} |
public boolean isAllActive() { |
||||||
} |
boolean result = true; |
||||||
|
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
public boolean isAllActive() { |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
boolean result = true; |
if (!element.isActive()) { |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
result = false; |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
break; |
||||||
if (!element.isActive()) { |
} |
||||||
result = false; |
} |
||||||
break; |
return result; |
||||||
} |
} |
||||||
} |
public boolean isAllDeactivated() { |
||||||
return result; |
boolean result = true; |
||||||
} |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
|
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
public boolean isAllDeactivated() { |
if (element.isActive()) { |
||||||
boolean result = true; |
result = false; |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
break; |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
} |
||||||
if (element.isActive()) { |
} |
||||||
result = false; |
return result; |
||||||
break; |
} |
||||||
} |
public int activeCount() { |
||||||
} |
int count = 0; |
||||||
return result; |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
} |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
|
if (element.isActive()) |
||||||
public int activeCount() { |
count++; |
||||||
int count = 0; |
} |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
return count; |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
} |
||||||
if (element.isActive()) count++; |
public int deactivatedCount() { |
||||||
} |
|
||||||
return count; |
int count = 0; |
||||||
} |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
|
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
public int deactivatedCount() { |
if (!element.isActive()) |
||||||
|
count++; |
||||||
int count = 0; |
} |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
return count; |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
|
||||||
if (!element.isActive()) count++; |
} |
||||||
} |
public ActivatableItemI getActiveItem(int pos) { |
||||||
return count; |
ActivatableItemI result = null; |
||||||
|
int i = 0; |
||||||
} |
|
||||||
|
for (Iterator it = activeItemIterator(); it.hasNext();) { |
||||||
public ActivatableItemI getActiveItem(int pos) { |
ActivatableItemI element = (ActivatableItemI) it.next(); |
||||||
ActivatableItemI result = null; |
if (i == pos) { |
||||||
int i = 0; |
result = element; |
||||||
|
break; |
||||||
for (Iterator it = activeItemIterator(); it.hasNext();) { |
} |
||||||
ActivatableItemI element = (ActivatableItemI) it.next(); |
i++; |
||||||
if (i == pos) { |
} |
||||||
result = element; |
if (result == null) |
||||||
break; |
throw new RuntimeException("not found"); |
||||||
} |
|
||||||
i++; |
return result; |
||||||
} |
} |
||||||
if (result == null) throw new RuntimeException("not found"); |
/** |
||||||
|
* |
||||||
return result; |
* @return null if all deactivated |
||||||
} |
*/ |
||||||
|
public ActivatableItemI getFirstActive() { |
||||||
/** |
ActivatableItemI result = null; |
||||||
* |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
* @return null if all deactivated |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
*/ |
if (element.isActive()) { |
||||||
public ActivatableItemI getFirstActive() { |
result = element; |
||||||
ActivatableItemI result = null; |
break; |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
} |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
} |
||||||
if (element.isActive()) { |
return result; |
||||||
result = element; |
} |
||||||
break; |
/** |
||||||
} |
* |
||||||
} |
* @return null if all active |
||||||
return result; |
*/ |
||||||
} |
public ActivatableItemI getFirstDeactivated() { |
||||||
|
ActivatableItemI result = null; |
||||||
/** |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
* |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
* @return null if all active |
if (!element.isActive()) { |
||||||
*/ |
result = element; |
||||||
public ActivatableItemI getFirstDeactivated() { |
break; |
||||||
ActivatableItemI result = null; |
} |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
} |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
return result; |
||||||
if (!element.isActive()) { |
} |
||||||
result = element; |
/* (non-Javadoc) |
||||||
break; |
* @see java.util.Collection#size() |
||||||
} |
*/ |
||||||
} |
public int size() { |
||||||
return result; |
return collect.size(); |
||||||
} |
} |
||||||
|
|
||||||
/* (non-Javadoc) |
/* (non-Javadoc) |
||||||
* @see java.util.Collection#size() |
* @see java.util.Collection#isEmpty() |
||||||
*/ |
*/ |
||||||
@Override |
public boolean isEmpty() { |
||||||
public int size() { |
return collect.isEmpty(); |
||||||
return collect.size(); |
} |
||||||
} |
|
||||||
|
/* (non-Javadoc) |
||||||
/* (non-Javadoc) |
* @see java.util.Collection#contains(java.lang.Object) |
||||||
* @see java.util.Collection#isEmpty() |
*/ |
||||||
*/ |
public boolean contains(Object o) { |
||||||
@Override |
return collect.contains(o); |
||||||
public boolean isEmpty() { |
} |
||||||
return collect.isEmpty(); |
|
||||||
} |
/* (non-Javadoc) |
||||||
|
* @see java.util.Collection#iterator() |
||||||
/* (non-Javadoc) |
*/ |
||||||
* @see java.util.Collection#contains(java.lang.Object) |
public Iterator iterator() { |
||||||
*/ |
return collect.iterator(); |
||||||
@Override |
} |
||||||
public boolean contains(Object o) { |
|
||||||
return collect.contains(o); |
/* (non-Javadoc) |
||||||
} |
* @see java.util.Collection#toArray() |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
public Object[] toArray() { |
||||||
* @see java.util.Collection#iterator() |
return collect.toArray(); |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public Iterator iterator() { |
/* (non-Javadoc) |
||||||
return collect.iterator(); |
* @see java.util.Collection#toArray(java.lang.Object[]) |
||||||
} |
*/ |
||||||
|
public Object[] toArray(Object[] a) { |
||||||
/* (non-Javadoc) |
return collect.toArray(a); |
||||||
* @see java.util.Collection#toArray() |
} |
||||||
*/ |
|
||||||
@Override |
/* (non-Javadoc) |
||||||
public Object[] toArray() { |
* @see java.util.Collection#containsAll(java.util.Collection) |
||||||
return collect.toArray(); |
*/ |
||||||
} |
public boolean containsAll(Collection c) { |
||||||
|
return collect.containsAll(c); |
||||||
/* (non-Javadoc) |
} |
||||||
* @see java.util.Collection#toArray(java.lang.Object[]) |
|
||||||
*/ |
/* (non-Javadoc) |
||||||
@Override |
* @see java.util.Collection#addAll(java.util.Collection) |
||||||
public Object[] toArray(Object[] a) { |
*/ |
||||||
return collect.toArray(a); |
public boolean addAll(Collection c) { |
||||||
} |
for (Iterator iter = c.iterator(); iter.hasNext();) { |
||||||
|
Object element = iter.next(); |
||||||
/* (non-Javadoc) |
if (!(element instanceof ActivatableItemI)) |
||||||
* @see java.util.Collection#containsAll(java.util.Collection) |
throw new IllegalArgumentException("only Activatable items"); |
||||||
*/ |
|
||||||
@Override |
} |
||||||
public boolean containsAll(Collection c) { |
return collect.addAll(c); |
||||||
return collect.containsAll(c); |
} |
||||||
} |
|
||||||
|
/* (non-Javadoc) |
||||||
/* (non-Javadoc) |
* @see java.util.Collection#removeAll(java.util.Collection) |
||||||
* @see java.util.Collection#addAll(java.util.Collection) |
*/ |
||||||
*/ |
public boolean removeAll(Collection c) { |
||||||
@Override |
return collect.removeAll(c); |
||||||
public boolean addAll(Collection c) { |
} |
||||||
for (Iterator iter = c.iterator(); iter.hasNext();) { |
|
||||||
Object element = iter.next(); |
/* (non-Javadoc) |
||||||
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
* @see java.util.Collection#retainAll(java.util.Collection) |
||||||
|
*/ |
||||||
} |
public boolean retainAll(Collection c) { |
||||||
return collect.addAll(c); |
for (Iterator iter = c.iterator(); iter.hasNext();) { |
||||||
} |
Object element = iter.next(); |
||||||
|
if (!(element instanceof ActivatableItemI)) |
||||||
/* (non-Javadoc) |
throw new IllegalArgumentException("only Activatable items"); |
||||||
* @see java.util.Collection#removeAll(java.util.Collection) |
|
||||||
*/ |
} |
||||||
@Override |
return collect.retainAll(c); |
||||||
public boolean removeAll(Collection c) { |
} |
||||||
return collect.removeAll(c); |
|
||||||
} |
/* (non-Javadoc) |
||||||
|
* @see java.util.Collection#clear() |
||||||
/* (non-Javadoc) |
*/ |
||||||
* @see java.util.Collection#retainAll(java.util.Collection) |
public void clear() { |
||||||
*/ |
collect.clear(); |
||||||
@Override |
} |
||||||
public boolean retainAll(Collection c) { |
|
||||||
for (Iterator iter = c.iterator(); iter.hasNext();) { |
/* (non-Javadoc) |
||||||
Object element = iter.next(); |
* @see java.util.Collection#add(java.lang.Object) |
||||||
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
*/ |
||||||
|
public boolean add(Object o) { |
||||||
} |
if (!(o instanceof ActivatableItemI)) |
||||||
return collect.retainAll(c); |
throw new IllegalArgumentException("only Activatable items"); |
||||||
} |
return collect.add(o); |
||||||
|
} |
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.Collection#clear() |
/* (non-Javadoc) |
||||||
*/ |
* @see java.util.Collection#remove(java.lang.Object) |
||||||
@Override |
*/ |
||||||
public void clear() { |
public boolean remove(Object o) { |
||||||
collect.clear(); |
return collect.remove(o); |
||||||
} |
} |
||||||
|
|
||||||
/* (non-Javadoc) |
/* (non-Javadoc) |
||||||
* @see java.util.Collection#add(java.lang.Object) |
* @see java.util.List#addAll(int, java.util.Collection) |
||||||
*/ |
*/ |
||||||
@Override |
public boolean addAll(int index, Collection c) { |
||||||
public boolean add(Object o) { |
for (Iterator iter = c.iterator(); iter.hasNext();) { |
||||||
if (!(o instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
Object element = iter.next(); |
||||||
return collect.add(o); |
if (!(element instanceof ActivatableItemI)) |
||||||
} |
throw new IllegalArgumentException("only Activatable items"); |
||||||
|
|
||||||
/* (non-Javadoc) |
} |
||||||
* @see java.util.Collection#remove(java.lang.Object) |
return collect.addAll(c); |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public boolean remove(Object o) { |
/* (non-Javadoc) |
||||||
return collect.remove(o); |
* @see java.util.List#get(int) |
||||||
} |
*/ |
||||||
|
public Object get(int index) { |
||||||
/* (non-Javadoc) |
return collect.get(index); |
||||||
* @see java.util.List#addAll(int, java.util.Collection) |
} |
||||||
*/ |
|
||||||
@Override |
/* (non-Javadoc) |
||||||
public boolean addAll(int index, Collection c) { |
* @see java.util.List#set(int, java.lang.Object) |
||||||
for (Iterator iter = c.iterator(); iter.hasNext();) { |
*/ |
||||||
Object element = iter.next(); |
public Object set(int index, Object element) { |
||||||
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
if (!(element instanceof ActivatableItemI)) |
||||||
|
throw new IllegalArgumentException("only Activatable items"); |
||||||
} |
return collect.set(index, element); |
||||||
return collect.addAll(c); |
} |
||||||
} |
|
||||||
|
/* (non-Javadoc) |
||||||
/* (non-Javadoc) |
* @see java.util.List#add(int, java.lang.Object) |
||||||
* @see java.util.List#get(int) |
*/ |
||||||
*/ |
public void add(int index, Object element) { |
||||||
@Override |
if (!(element instanceof ActivatableItemI)) |
||||||
public Object get(int index) { |
throw new IllegalArgumentException("only Activatable items"); |
||||||
return collect.get(index); |
collect.add(index, element); |
||||||
} |
} |
||||||
|
|
||||||
/* (non-Javadoc) |
/* (non-Javadoc) |
||||||
* @see java.util.List#set(int, java.lang.Object) |
* @see java.util.List#remove(int) |
||||||
*/ |
*/ |
||||||
@Override |
public Object remove(int index) { |
||||||
public Object set(int index, Object element) { |
return collect.remove(index); |
||||||
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
} |
||||||
return collect.set(index, element); |
|
||||||
} |
/* (non-Javadoc) |
||||||
|
* @see java.util.List#indexOf(java.lang.Object) |
||||||
/* (non-Javadoc) |
*/ |
||||||
* @see java.util.List#add(int, java.lang.Object) |
public int indexOf(Object o) { |
||||||
*/ |
return collect.indexOf(o); |
||||||
@Override |
} |
||||||
public void add(int index, Object element) { |
|
||||||
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
/* (non-Javadoc) |
||||||
collect.add(index, element); |
* @see java.util.List#lastIndexOf(java.lang.Object) |
||||||
} |
*/ |
||||||
|
public int lastIndexOf(Object o) { |
||||||
/* (non-Javadoc) |
return collect.lastIndexOf(o); |
||||||
* @see java.util.List#remove(int) |
} |
||||||
*/ |
|
||||||
@Override |
/* (non-Javadoc) |
||||||
public Object remove(int index) { |
* @see java.util.List#listIterator() |
||||||
return collect.remove(index); |
*/ |
||||||
} |
public ListIterator listIterator() { |
||||||
|
return collect.listIterator(); |
||||||
/* (non-Javadoc) |
} |
||||||
* @see java.util.List#indexOf(java.lang.Object) |
|
||||||
*/ |
/* (non-Javadoc) |
||||||
@Override |
* @see java.util.List#listIterator(int) |
||||||
public int indexOf(Object o) { |
*/ |
||||||
return collect.indexOf(o); |
public ListIterator listIterator(int index) { |
||||||
} |
return collect.listIterator(index); |
||||||
|
} |
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.List#lastIndexOf(java.lang.Object) |
/* (non-Javadoc) |
||||||
*/ |
* @see java.util.List#subList(int, int) |
||||||
@Override |
*/ |
||||||
public int lastIndexOf(Object o) { |
public List subList(int fromIndex, int toIndex) { |
||||||
return collect.lastIndexOf(o); |
return collect.subList(fromIndex, toIndex); |
||||||
} |
} |
||||||
|
public String toString() { |
||||||
/* (non-Javadoc) |
return "ActivatableItemsList " + size() + " items"; |
||||||
* @see java.util.List#listIterator() |
} |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public ListIterator listIterator() { |
|
||||||
return collect.listIterator(); |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.List#listIterator(int) |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public ListIterator listIterator(int index) { |
|
||||||
return collect.listIterator(index); |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.List#subList(int, int) |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public List subList(int fromIndex, int toIndex) { |
|
||||||
return collect.subList(fromIndex, toIndex); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return "ActivatableItemsList " + size() + " items"; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,141 +1,125 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
|
|
||||||
/** |
/** |
||||||
* Basis for the collections, but default the used collection is a |
* Basis for the collections, but default the used collection is a |
||||||
* linkedList, subclasses may change to use a list or set |
* linkedList, subclasses may change to use a list or set |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class BaseObjectCollection implements Collection, Serializable { |
public class BaseObjectCollection implements Collection,Serializable { |
||||||
protected Collection collect; |
protected Collection collect; |
||||||
|
private static final long serialVersionUID = 1; |
||||||
private static final long serialVersionUID = 1; |
public BaseObjectCollection() { |
||||||
|
super(); |
||||||
public BaseObjectCollection() { |
collect = new LinkedList(); |
||||||
super(); |
} |
||||||
collect = new LinkedList(); |
|
||||||
} |
|
||||||
|
|
||||||
|
public int size() { |
||||||
|
return collect.size(); |
||||||
@Override |
} |
||||||
public int size() { |
|
||||||
return collect.size(); |
/* (non-Javadoc) |
||||||
} |
* @see java.util.Collection#isEmpty() |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
public boolean isEmpty() { |
||||||
* @see java.util.Collection#isEmpty() |
return collect.isEmpty(); |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public boolean isEmpty() { |
/* (non-Javadoc) |
||||||
return collect.isEmpty(); |
* @see java.util.Collection#contains(java.lang.Object) |
||||||
} |
*/ |
||||||
|
public boolean contains(Object o) { |
||||||
/* (non-Javadoc) |
return collect.contains(o); |
||||||
* @see java.util.Collection#contains(java.lang.Object) |
} |
||||||
*/ |
|
||||||
@Override |
/* (non-Javadoc) |
||||||
public boolean contains(Object o) { |
* @see java.util.Collection#iterator() |
||||||
return collect.contains(o); |
*/ |
||||||
} |
public Iterator iterator() { |
||||||
|
return collect.iterator(); |
||||||
/* (non-Javadoc) |
} |
||||||
* @see java.util.Collection#iterator() |
|
||||||
*/ |
/* (non-Javadoc) |
||||||
@Override |
* @see java.util.Collection#toArray() |
||||||
public Iterator iterator() { |
*/ |
||||||
return collect.iterator(); |
public Object[] toArray() { |
||||||
} |
return collect.toArray(); |
||||||
|
} |
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.Collection#toArray() |
/* (non-Javadoc) |
||||||
*/ |
* @see java.util.Collection#toArray(java.lang.Object[]) |
||||||
@Override |
*/ |
||||||
public Object[] toArray() { |
public Object[] toArray(Object[] a) { |
||||||
return collect.toArray(); |
return collect.toArray(a); |
||||||
} |
} |
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.Collection#toArray(java.lang.Object[]) |
|
||||||
*/ |
|
||||||
@Override |
/* (non-Javadoc) |
||||||
public Object[] toArray(Object[] a) { |
* @see java.util.Collection#containsAll(java.util.Collection) |
||||||
return collect.toArray(a); |
*/ |
||||||
} |
public boolean containsAll(Collection c) { |
||||||
|
return collect.containsAll(c); |
||||||
|
} |
||||||
|
|
||||||
|
/* (non-Javadoc) |
||||||
/* (non-Javadoc) |
* @see java.util.Collection#addAll(java.util.Collection) |
||||||
* @see java.util.Collection#containsAll(java.util.Collection) |
*/ |
||||||
*/ |
public boolean addAll(Collection c) { |
||||||
@Override |
return collect.addAll(c); |
||||||
public boolean containsAll(Collection c) { |
} |
||||||
return collect.containsAll(c); |
|
||||||
} |
/* (non-Javadoc) |
||||||
|
* @see java.util.Collection#removeAll(java.util.Collection) |
||||||
/* (non-Javadoc) |
*/ |
||||||
* @see java.util.Collection#addAll(java.util.Collection) |
public boolean removeAll(Collection c) { |
||||||
*/ |
return collect.removeAll(c); |
||||||
@Override |
} |
||||||
public boolean addAll(Collection c) { |
|
||||||
return collect.addAll(c); |
/* (non-Javadoc) |
||||||
} |
* @see java.util.Collection#retainAll(java.util.Collection) |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
public boolean retainAll(Collection c) { |
||||||
* @see java.util.Collection#removeAll(java.util.Collection) |
return collect.retainAll(c); |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public boolean removeAll(Collection c) { |
/* (non-Javadoc) |
||||||
return collect.removeAll(c); |
* @see java.util.Collection#clear() |
||||||
} |
*/ |
||||||
|
public void clear() { |
||||||
/* (non-Javadoc) |
collect.clear(); |
||||||
* @see java.util.Collection#retainAll(java.util.Collection) |
} |
||||||
*/ |
|
||||||
@Override |
/* (non-Javadoc) |
||||||
public boolean retainAll(Collection c) { |
* @see java.util.Collection#add(java.lang.Object) |
||||||
return collect.retainAll(c); |
*/ |
||||||
} |
public boolean add(Object o) { |
||||||
|
if (o==null) throw new IllegalArgumentException("can't add null value"); |
||||||
/* (non-Javadoc) |
return collect.add(o); |
||||||
* @see java.util.Collection#clear() |
} |
||||||
*/ |
|
||||||
@Override |
/* (non-Javadoc) |
||||||
public void clear() { |
* @see java.util.Collection#remove(java.lang.Object) |
||||||
collect.clear(); |
*/ |
||||||
} |
public boolean remove(Object o) { |
||||||
|
return collect.remove(o); |
||||||
/* (non-Javadoc) |
} |
||||||
* @see java.util.Collection#add(java.lang.Object) |
|
||||||
*/ |
|
||||||
@Override |
/** |
||||||
public boolean add(Object o) { |
* Only shallow copy |
||||||
if (o == null) throw new IllegalArgumentException("can't add null value"); |
*/ |
||||||
return collect.add(o); |
protected Object clone() throws CloneNotSupportedException { |
||||||
} |
BaseObjectCollection c=new BaseObjectCollection(); |
||||||
|
c.addAll(this); |
||||||
/* (non-Javadoc) |
return c; |
||||||
* @see java.util.Collection#remove(java.lang.Object) |
} |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public boolean remove(Object o) { |
|
||||||
return collect.remove(o); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Only shallow copy |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
|
||||||
BaseObjectCollection c = new BaseObjectCollection(); |
|
||||||
c.addAll(this); |
|
||||||
return c; |
|
||||||
} |
|
||||||
} |
|
||||||
//Created on 30.1.2004
|
//Created on 30.1.2004
|
||||||
@ -1,107 +1,108 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.IdObjectI; |
import de.memtext.baseobjects.IdObjectI; |
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class IdObjectCollection extends BaseObjectCollection implements Collection, Serializable { |
public class IdObjectCollection |
||||||
private static final long serialVersionUID = 1; |
extends BaseObjectCollection |
||||||
|
implements Collection ,Serializable{ |
||||||
public IdObjectCollection() { |
private static final long serialVersionUID = 1; |
||||||
super(); |
public IdObjectCollection() { |
||||||
} |
super(); |
||||||
|
} |
||||||
/** |
/** |
||||||
* |
* |
||||||
* @param id |
* @param id |
||||||
* @return object |
* @return object |
||||||
* @throws IllegalArgumentException if nothing found |
* @throws IllegalArgumentException if nothing found |
||||||
*/ |
*/ |
||||||
public IdObjectI getById(Object id) { |
public IdObjectI getById(Object id) { |
||||||
IdObjectI test, result = null; |
IdObjectI test, result = null; |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
test = (IdObjectI) it.next(); |
test = (IdObjectI) it.next(); |
||||||
if ((id == null && test.getId() == null) || (test.getId() != null && test.getId().equals(id))) { |
if ((id == null && test.getId() == null) |
||||||
result = test; |
|| (test.getId() != null && test.getId().equals(id))) { |
||||||
break; |
result = test; |
||||||
} |
break; |
||||||
} |
} |
||||||
if (result == null) throw new IllegalArgumentException("No element with id " + id + " found!"); |
} |
||||||
return result; |
if (result == null) |
||||||
} |
throw new IllegalArgumentException( |
||||||
|
"No element with id " + id + " found!"); |
||||||
/** |
return result; |
||||||
* like '12','34','343' |
} |
||||||
* useful for creating sqls like where x in (...) |
/** |
||||||
* @return |
* like '12','34','343' |
||||||
*/ |
* useful for creating sqls like where x in (...) |
||||||
public String getIdsApostropheString() { |
* @return |
||||||
StringBuffer result = new StringBuffer(); |
*/ |
||||||
IdObjectI test; |
public String getIdsApostropheString() { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
StringBuffer result = new StringBuffer(); |
||||||
test = (IdObjectI) it.next(); |
IdObjectI test; |
||||||
result.append("'" + test.getId() + "',"); |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
} |
test = (IdObjectI) it.next(); |
||||||
StringUtils.deleteLastChar(result); |
result.append("'" + test.getId() + "',"); |
||||||
return result.toString(); |
} |
||||||
} |
StringUtils.deleteLastChar(result); |
||||||
|
return result.toString(); |
||||||
public boolean containsItemWithId(Object id) { |
} |
||||||
boolean result = false; |
public boolean containsItemWithId(Object id) { |
||||||
IdObjectI test; |
boolean result = false; |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
IdObjectI test; |
||||||
test = (IdObjectI) it.next(); |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
if (test.getId().equals(id)) { |
test = (IdObjectI) it.next(); |
||||||
result = true; |
if (test.getId().equals(id)) { |
||||||
break; |
result = true; |
||||||
} |
break; |
||||||
} |
} |
||||||
return result; |
} |
||||||
} |
return result; |
||||||
|
} |
||||||
/** |
/** |
||||||
* Checks if the collection contains only the ids given in the param collection ids |
* Checks if the collection contains only the ids given in the param collection ids |
||||||
* @param Collection ids |
* @param Collection ids |
||||||
* @return |
* @return |
||||||
*/ |
*/ |
||||||
public boolean consistsOfIds(Collection ids) { |
public boolean consistsOfIds(Collection ids) { |
||||||
|
|
||||||
if (this.size() != ids.size()) return false; |
if (this.size() != ids.size()) |
||||||
boolean result = true; |
return false; |
||||||
for (Iterator it = ids.iterator(); it.hasNext();) { |
boolean result = true; |
||||||
Object id = it.next(); |
for (Iterator it = ids.iterator(); it.hasNext();) { |
||||||
try { |
Object id = it.next(); |
||||||
Object dummy = getById(id); |
try { |
||||||
} catch (IllegalArgumentException e) { |
Object dummy = getById(id); |
||||||
result = false; |
} catch (IllegalArgumentException e) { |
||||||
break; |
result = false; |
||||||
} |
break; |
||||||
} |
} |
||||||
return result; |
} |
||||||
} |
return result; |
||||||
|
} |
||||||
@Override |
|
||||||
public boolean add(Object o) { |
public boolean add(Object o) { |
||||||
if (o == null) throw new IllegalArgumentException("can't add null value"); |
if (o == null) |
||||||
if (!(o instanceof IdObjectI)) throw new IllegalArgumentException("only named IdObjects allowed"); |
throw new IllegalArgumentException("can't add null value"); |
||||||
return collect.add(o); |
if (!(o instanceof IdObjectI)) |
||||||
} |
throw new IllegalArgumentException("only named IdObjects allowed"); |
||||||
|
return collect.add(o); |
||||||
/** |
} |
||||||
* Only shallow copy |
|
||||||
*/ |
/** |
||||||
@Override |
* Only shallow copy |
||||||
protected Object clone() throws CloneNotSupportedException { |
*/ |
||||||
IdObjectCollection c = new IdObjectCollection(); |
protected Object clone() throws CloneNotSupportedException { |
||||||
c.addAll(this); |
IdObjectCollection c=new IdObjectCollection(); |
||||||
return c; |
c.addAll(this); |
||||||
} |
return c; |
||||||
} |
} |
||||||
|
} |
||||||
//Created on 30.1.2004
|
//Created on 30.1.2004
|
||||||
@ -1,97 +1,84 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.IdObjectI; |
import de.memtext.baseobjects.IdObjectI; |
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class IdObjectList extends IdObjectCollection implements List { |
public class IdObjectList extends IdObjectCollection implements List { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
public IdObjectList() { |
||||||
public IdObjectList() { |
super(); |
||||||
super(); |
collect=new LinkedList(); |
||||||
collect = new LinkedList(); |
} |
||||||
} |
|
||||||
|
|
||||||
|
public Object get(int pos) |
||||||
@Override |
{ |
||||||
public Object get(int pos) { |
return ((List)collect).get(pos); |
||||||
return ((List) collect).get(pos); |
} |
||||||
} |
|
||||||
|
public boolean addAll(int arg0, Collection arg1) { |
||||||
@Override |
return ((List)collect).addAll(arg0,arg1); |
||||||
public boolean addAll(int arg0, Collection arg1) { |
} |
||||||
return ((List) collect).addAll(arg0, arg1); |
|
||||||
} |
public Object set(int arg0, Object arg1) { |
||||||
|
return ((List)collect).set(arg0,arg1); |
||||||
@Override |
} |
||||||
public Object set(int arg0, Object arg1) { |
|
||||||
return ((List) collect).set(arg0, arg1); |
public void add(int pos, Object arg1) { |
||||||
} |
((List)collect).add(pos,arg1); |
||||||
|
} |
||||||
@Override |
|
||||||
public void add(int pos, Object arg1) { |
public Object remove(int arg0) { |
||||||
((List) collect).add(pos, arg1); |
return ((List)collect).remove(arg0); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
|
||||||
public Object remove(int arg0) { |
public ListIterator listIterator(int arg0) { |
||||||
return ((List) collect).remove(arg0); |
return ((List)collect).listIterator(arg0); |
||||||
} |
} |
||||||
|
|
||||||
|
public List subList(int arg0, int arg1) { |
||||||
@Override |
return ((List)collect).subList(arg0,arg1); |
||||||
public ListIterator listIterator(int arg0) { |
} |
||||||
return ((List) collect).listIterator(arg0); |
|
||||||
} |
public int indexOf(Object arg0) { |
||||||
|
return ((List)collect).indexOf(arg0); |
||||||
@Override |
} |
||||||
public List subList(int arg0, int arg1) { |
|
||||||
return ((List) collect).subList(arg0, arg1); |
public int lastIndexOf(Object arg0) { |
||||||
} |
return ((List)collect).lastIndexOf(arg0); |
||||||
|
} |
||||||
@Override |
|
||||||
public int indexOf(Object arg0) { |
public ListIterator listIterator() { |
||||||
return ((List) collect).indexOf(arg0); |
return ((List)collect).listIterator(); |
||||||
} |
} |
||||||
|
public String toString() |
||||||
@Override |
{ |
||||||
public int lastIndexOf(Object arg0) { |
StringBuffer result=new StringBuffer("idobject list:"); |
||||||
return ((List) collect).lastIndexOf(arg0); |
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
} |
IdObjectI element = (IdObjectI) it.next(); |
||||||
|
result.append(element.toString()+","); |
||||||
@Override |
} |
||||||
public ListIterator listIterator() { |
StringUtils.getLastChar(result); |
||||||
return ((List) collect).listIterator(); |
return result.toString(); |
||||||
} |
} |
||||||
|
/** |
||||||
@Override |
* Only shallow copy |
||||||
public String toString() { |
*/ |
||||||
StringBuffer result = new StringBuffer("idobject list:"); |
protected Object clone() throws CloneNotSupportedException { |
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
IdObjectList c=new IdObjectList(); |
||||||
IdObjectI element = (IdObjectI) it.next(); |
c.addAll(this); |
||||||
result.append(element.toString() + ","); |
return c; |
||||||
} |
} |
||||||
StringUtils.getLastChar(result); |
} |
||||||
return result.toString(); |
//Created on 30.1.2004
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Only shallow copy |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
|
||||||
IdObjectList c = new IdObjectList(); |
|
||||||
c.addAll(this); |
|
||||||
return c; |
|
||||||
} |
|
||||||
} |
|
||||||
//Created on 30.1.2004
|
|
||||||
|
|||||||
@ -1,26 +1,24 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.HashSet; |
import java.util.HashSet; |
||||||
import java.util.Set; |
import java.util.Set; |
||||||
|
|
||||||
public class IdObjectSet extends IdObjectCollection implements Set { |
public class IdObjectSet extends IdObjectCollection implements Set { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
public IdObjectSet() { |
||||||
public IdObjectSet() { |
super(); |
||||||
super(); |
collect=new HashSet(); |
||||||
collect = new HashSet(); |
} |
||||||
} |
|
||||||
|
|
||||||
|
/** |
||||||
/** |
* Only shallow copy |
||||||
* Only shallow copy |
*/ |
||||||
*/ |
protected Object clone() throws CloneNotSupportedException { |
||||||
@Override |
IdObjectSet c=new IdObjectSet(); |
||||||
protected Object clone() throws CloneNotSupportedException { |
c.addAll(this); |
||||||
IdObjectSet c = new IdObjectSet(); |
return c; |
||||||
c.addAll(this); |
} |
||||||
return c; |
} |
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 30.1.2004
|
//Created on 30.1.2004
|
||||||
@ -1,135 +1,138 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedIdObjectI; |
import de.memtext.baseobjects.NamedIdObject; |
||||||
import de.memtext.util.EqualsUtil; |
import de.memtext.baseobjects.NamedIdObjectI; |
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.EqualsUtil; |
||||||
|
import de.memtext.util.StringUtils; |
||||||
/** |
|
||||||
* |
/** |
||||||
* @author MB |
* |
||||||
*/ |
* @author MB |
||||||
public class NamedIdObjectCollection extends NamedObjectCollection implements Collection, Serializable { |
*/ |
||||||
private static final long serialVersionUID = 1; |
public class NamedIdObjectCollection extends NamedObjectCollection implements |
||||||
|
Collection, Serializable { |
||||||
public NamedIdObjectCollection() { |
private static final long serialVersionUID = 1; |
||||||
super(); |
public NamedIdObjectCollection() { |
||||||
} |
super(); |
||||||
|
} |
||||||
/** |
|
||||||
* |
/** |
||||||
* @param id |
* |
||||||
* @return object |
* @param id |
||||||
* @throws IllegalArgumentException |
* @return object |
||||||
* if nothing found |
* @throws IllegalArgumentException |
||||||
*/ |
* if nothing found |
||||||
public NamedIdObjectI getById(Object id) { |
*/ |
||||||
NamedIdObjectI test, result = null; |
public NamedIdObjectI getById(Object id) { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
NamedIdObjectI test, result = null; |
||||||
test = (NamedIdObjectI) it.next(); |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
if ((id == null && test.getId() == null) || (test.getId() != null && test.getId().equals(id))) { |
test = (NamedIdObjectI) it.next(); |
||||||
result = test; |
if ((id == null && test.getId() == null) |
||||||
break; |
|| (test.getId() != null && test.getId().equals(id))) { |
||||||
} |
result = test; |
||||||
} |
break; |
||||||
if (result == null) throw new IllegalArgumentException("No element with id " + id + " found!"); |
} |
||||||
return result; |
} |
||||||
} |
if (result == null) |
||||||
|
throw new IllegalArgumentException("No element with id " + id |
||||||
/** |
+ " found!"); |
||||||
* like '12','34','343' useful for creating sqls like where x in (...) |
return result; |
||||||
* |
} |
||||||
* @return |
|
||||||
*/ |
/** |
||||||
public String getIdsApostropheString() { |
* like '12','34','343' useful for creating sqls like where x in (...) |
||||||
StringBuffer result = new StringBuffer(); |
* |
||||||
NamedIdObjectI test; |
* @return |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
*/ |
||||||
test = (NamedIdObjectI) it.next(); |
public String getIdsApostropheString() { |
||||||
result.append("'" + test.getId() + "',"); |
StringBuffer result = new StringBuffer(); |
||||||
} |
NamedIdObjectI test; |
||||||
StringUtils.deleteLastChar(result); |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
return result.toString(); |
test = (NamedIdObjectI) it.next(); |
||||||
} |
result.append("'" + test.getId() + "',"); |
||||||
|
} |
||||||
@Override |
StringUtils.deleteLastChar(result); |
||||||
public boolean containsItemWithName(String name) { |
return result.toString(); |
||||||
boolean result = false; |
} |
||||||
NamedIdObjectI test; |
|
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
public boolean containsItemWithName(String name) { |
||||||
test = (NamedIdObjectI) it.next(); |
boolean result = false; |
||||||
if (test.getName().equals(name)) { |
NamedIdObjectI test; |
||||||
result = true; |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
break; |
test = (NamedIdObjectI) it.next(); |
||||||
} |
if (test.getName().equals(name)) { |
||||||
} |
result = true; |
||||||
return result; |
break; |
||||||
} |
} |
||||||
|
} |
||||||
public boolean containsItemWithId(Object id) { |
return result; |
||||||
boolean result = false; |
} |
||||||
NamedIdObjectI test; |
|
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
public boolean containsItemWithId(Object id) { |
||||||
test = (NamedIdObjectI) it.next(); |
boolean result = false; |
||||||
if (EqualsUtil.areEqual(test.getId(), id)) { |
NamedIdObjectI test; |
||||||
result = true; |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
break; |
test = (NamedIdObjectI) it.next(); |
||||||
} |
if (EqualsUtil.areEqual(test.getId(),id)) { |
||||||
} |
result = true; |
||||||
return result; |
break; |
||||||
} |
} |
||||||
|
} |
||||||
/** |
return result; |
||||||
* Checks if the collection contains only the ids given in the param |
} |
||||||
* collection ids |
|
||||||
* |
/** |
||||||
* @param Collection |
* Checks if the collection contains only the ids given in the param |
||||||
* ids |
* collection ids |
||||||
* @return |
* |
||||||
*/ |
* @param Collection |
||||||
public boolean consistsOfIds(Collection ids) { |
* ids |
||||||
|
* @return |
||||||
if (this.size() != ids.size()) return false; |
*/ |
||||||
boolean result = true; |
public boolean consistsOfIds(Collection ids) { |
||||||
for (Iterator it = ids.iterator(); it.hasNext();) { |
|
||||||
Object id = it.next(); |
if (this.size() != ids.size()) |
||||||
try { |
return false; |
||||||
Object dummy = getById(id); |
boolean result = true; |
||||||
} catch (IllegalArgumentException e) { |
for (Iterator it = ids.iterator(); it.hasNext();) { |
||||||
result = false; |
Object id = it.next(); |
||||||
break; |
try { |
||||||
} |
Object dummy = getById(id); |
||||||
} |
} catch (IllegalArgumentException e) { |
||||||
return result; |
result = false; |
||||||
} |
break; |
||||||
|
} |
||||||
@Override |
} |
||||||
public boolean add(Object o) { |
return result; |
||||||
if (o == null) throw new IllegalArgumentException("can't add null value"); |
} |
||||||
if (!(o instanceof NamedIdObjectI)) throw new IllegalArgumentException("only named IdObjects allowed"); |
|
||||||
return collect.add(o); |
public boolean add(Object o) { |
||||||
} |
if (o == null) |
||||||
|
throw new IllegalArgumentException("can't add null value"); |
||||||
@Override |
if (!(o instanceof NamedIdObjectI)) |
||||||
public String toString() { |
throw new IllegalArgumentException("only named IdObjects allowed"); |
||||||
StringBuffer result = new StringBuffer(size() + " NamedIdObjects: "); |
return collect.add(o); |
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
} |
||||||
NamedIdObjectI element = (NamedIdObjectI) it.next(); |
|
||||||
result.append(element + " - "); |
public String toString() { |
||||||
} |
StringBuffer result = new StringBuffer(size() + " NamedIdObjects: "); |
||||||
return result.toString(); |
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
} |
NamedIdObjectI element = (NamedIdObjectI) it.next(); |
||||||
|
result.append(element + " - "); |
||||||
/** |
} |
||||||
* Only shallow copy |
return result.toString(); |
||||||
*/ |
} |
||||||
@Override |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
/** |
||||||
NamedIdObjectCollection c = new NamedIdObjectCollection(); |
* Only shallow copy |
||||||
c.addAll(this); |
*/ |
||||||
return c; |
protected Object clone() throws CloneNotSupportedException { |
||||||
} |
NamedIdObjectCollection c=new NamedIdObjectCollection(); |
||||||
|
c.addAll(this); |
||||||
|
return c; |
||||||
|
} |
||||||
} |
} |
||||||
@ -1,82 +1,71 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class NamedIdObjectList extends NamedIdObjectCollection implements List { |
public class NamedIdObjectList extends NamedIdObjectCollection implements List { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
public NamedIdObjectList() { |
||||||
public NamedIdObjectList() { |
super(); |
||||||
super(); |
collect=new LinkedList(); |
||||||
collect = new LinkedList(); |
} |
||||||
} |
|
||||||
|
|
||||||
|
public Object get(int pos) |
||||||
@Override |
{ |
||||||
public Object get(int pos) { |
return ((List)collect).get(pos); |
||||||
return ((List) collect).get(pos); |
} |
||||||
} |
|
||||||
|
public boolean addAll(int arg0, Collection arg1) { |
||||||
@Override |
return ((List)collect).addAll(arg0,arg1); |
||||||
public boolean addAll(int arg0, Collection arg1) { |
} |
||||||
return ((List) collect).addAll(arg0, arg1); |
|
||||||
} |
public Object set(int arg0, Object arg1) { |
||||||
|
return ((List)collect).set(arg0,arg1); |
||||||
@Override |
} |
||||||
public Object set(int arg0, Object arg1) { |
|
||||||
return ((List) collect).set(arg0, arg1); |
public void add(int pos, Object arg1) { |
||||||
} |
((List)collect).add(pos,arg1); |
||||||
|
} |
||||||
@Override |
|
||||||
public void add(int pos, Object arg1) { |
public Object remove(int arg0) { |
||||||
((List) collect).add(pos, arg1); |
return ((List)collect).remove(arg0); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
|
||||||
public Object remove(int arg0) { |
public ListIterator listIterator(int arg0) { |
||||||
return ((List) collect).remove(arg0); |
return ((List)collect).listIterator(arg0); |
||||||
} |
} |
||||||
|
|
||||||
|
public List subList(int arg0, int arg1) { |
||||||
@Override |
return ((List)collect).subList(arg0,arg1); |
||||||
public ListIterator listIterator(int arg0) { |
} |
||||||
return ((List) collect).listIterator(arg0); |
|
||||||
} |
public int indexOf(Object arg0) { |
||||||
|
return ((List)collect).indexOf(arg0); |
||||||
@Override |
} |
||||||
public List subList(int arg0, int arg1) { |
|
||||||
return ((List) collect).subList(arg0, arg1); |
public int lastIndexOf(Object arg0) { |
||||||
} |
return ((List)collect).lastIndexOf(arg0); |
||||||
|
} |
||||||
@Override |
|
||||||
public int indexOf(Object arg0) { |
public ListIterator listIterator() { |
||||||
return ((List) collect).indexOf(arg0); |
return ((List)collect).listIterator(); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
/** |
||||||
public int lastIndexOf(Object arg0) { |
* Only shallow copy |
||||||
return ((List) collect).lastIndexOf(arg0); |
*/ |
||||||
} |
protected Object clone() throws CloneNotSupportedException { |
||||||
|
NamedIdObjectList c=new NamedIdObjectList(); |
||||||
@Override |
c.addAll(this); |
||||||
public ListIterator listIterator() { |
return c; |
||||||
return ((List) collect).listIterator(); |
} |
||||||
} |
|
||||||
|
} |
||||||
/** |
|
||||||
* Only shallow copy |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
|
||||||
NamedIdObjectList c = new NamedIdObjectList(); |
|
||||||
c.addAll(this); |
|
||||||
return c; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,38 +1,35 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.HashSet; |
import java.util.HashSet; |
||||||
import java.util.Set; |
import java.util.Set; |
||||||
|
|
||||||
public class NamedIdObjectSet extends NamedIdObjectCollection implements Set { |
public class NamedIdObjectSet extends NamedIdObjectCollection implements Set { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
/** |
||||||
/** |
* Default uses a HashSet internally; |
||||||
* Default uses a HashSet internally; |
* |
||||||
* |
*/ |
||||||
*/ |
public NamedIdObjectSet() { |
||||||
public NamedIdObjectSet() { |
super(); |
||||||
super(); |
collect=new HashSet(); |
||||||
collect = new HashSet(); |
} |
||||||
} |
/** |
||||||
|
* |
||||||
/** |
* @param set the implementation of Set interface to use internally |
||||||
* |
*/ |
||||||
* @param set the implementation of Set interface to use internally |
public NamedIdObjectSet(Set set) { |
||||||
*/ |
super(); |
||||||
public NamedIdObjectSet(Set set) { |
collect=set; |
||||||
super(); |
} |
||||||
collect = set; |
|
||||||
} |
/** |
||||||
|
* Only shallow copy |
||||||
/** |
*/ |
||||||
* Only shallow copy |
protected Object clone() throws CloneNotSupportedException { |
||||||
*/ |
NamedIdObjectSet c=new NamedIdObjectSet(); |
||||||
@Override |
c.addAll(this); |
||||||
protected Object clone() throws CloneNotSupportedException { |
return c; |
||||||
NamedIdObjectSet c = new NamedIdObjectSet(); |
} |
||||||
c.addAll(this); |
} |
||||||
return c; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 03.12.2003
|
//Created on 03.12.2003
|
||||||
@ -1,75 +1,82 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedIdObjectWithParentI; |
import de.memtext.baseobjects.NamedIdObject; |
||||||
import de.memtext.util.EqualsUtil; |
import de.memtext.baseobjects.NamedIdObjectI; |
||||||
|
import de.memtext.baseobjects.NamedIdObjectWithParent; |
||||||
public class NamedIdObjectWithParentCollection extends NamedIdObjectCollection implements Collection { |
import de.memtext.baseobjects.NamedIdObjectWithParentI; |
||||||
private static final long serialVersionUID = 1; |
import de.memtext.util.EqualsUtil; |
||||||
|
|
||||||
public NamedIdObjectWithParentCollection() { |
public class NamedIdObjectWithParentCollection |
||||||
super(); |
extends NamedIdObjectCollection |
||||||
} |
implements Collection { |
||||||
|
private static final long serialVersionUID = 1; |
||||||
public boolean containsItemWithParent(Object parent) { |
public NamedIdObjectWithParentCollection() { |
||||||
boolean result = false; |
super(); |
||||||
NamedIdObjectWithParentI test; |
} |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
|
||||||
test = (NamedIdObjectWithParentI) it.next(); |
public boolean containsItemWithParent(Object parent) { |
||||||
if (EqualsUtil.areEqual(test.getParentKey(), parent)) { |
boolean result = false; |
||||||
result = true; |
NamedIdObjectWithParentI test; |
||||||
break; |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
} |
test = (NamedIdObjectWithParentI) it.next(); |
||||||
} |
if (EqualsUtil.areEqual(test.getParentKey(),parent)) { |
||||||
return result; |
result = true; |
||||||
} |
break; |
||||||
|
} |
||||||
/** |
} |
||||||
* get a collection with all objects in the collection that have a |
return result; |
||||||
* given parentKey |
} |
||||||
* @param parentKey |
/** |
||||||
* @return collection if concrete object is a NamedIdObjectWithParentList also |
* get a collection with all objects in the collection that have a |
||||||
* returns a NamedIdObjectWithParentList, same for NamedIdObjectWithParentSet |
* given parentKey |
||||||
* makes casting possible |
* @param parentKey |
||||||
*/ |
* @return collection if concrete object is a NamedIdObjectWithParentList also |
||||||
public NamedIdObjectWithParentCollection getByParent(Object parentKey) { |
* returns a NamedIdObjectWithParentList, same for NamedIdObjectWithParentSet |
||||||
NamedIdObjectWithParentCollection result = new NamedIdObjectWithParentCollection(); |
* makes casting possible |
||||||
if (this instanceof NamedIdObjectWithParentList) result = new NamedIdObjectWithParentList(); |
*/ |
||||||
if (this instanceof NamedIdObjectWithParentSet) result = new NamedIdObjectWithParentSet(); |
public NamedIdObjectWithParentCollection getByParent(Object parentKey) { |
||||||
|
NamedIdObjectWithParentCollection result = |
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
new NamedIdObjectWithParentCollection(); |
||||||
NamedIdObjectWithParentI element = (NamedIdObjectWithParentI) it.next(); |
if (this instanceof NamedIdObjectWithParentList) |
||||||
if (EqualsUtil.areEqual(element.getParentKey(), parentKey)) result.add(element); |
result = new NamedIdObjectWithParentList(); |
||||||
} |
if (this instanceof NamedIdObjectWithParentSet) |
||||||
return result; |
result = new NamedIdObjectWithParentSet(); |
||||||
} |
|
||||||
|
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
public int countItemsWithParent(Object parent) { |
NamedIdObjectWithParentI element = |
||||||
return getByParent(parent).size(); |
(NamedIdObjectWithParentI) it.next(); |
||||||
|
if (EqualsUtil.areEqual(element.getParentKey(),parentKey)) |
||||||
} |
result.add(element); |
||||||
|
} |
||||||
@Override |
return result; |
||||||
public String toString() { |
} |
||||||
StringBuffer result = new StringBuffer(size() + " NamedIdObjectsWithParent: "); |
|
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
public int countItemsWithParent(Object parent) |
||||||
NamedIdObjectWithParentI element = (NamedIdObjectWithParentI) it.next(); |
{ |
||||||
result.append(element + " - "); |
return getByParent(parent).size(); |
||||||
} |
|
||||||
return result.toString(); |
} |
||||||
} |
public String toString() |
||||||
|
{ |
||||||
/** |
StringBuffer result=new StringBuffer(size()+" NamedIdObjectsWithParent: "); |
||||||
* Only shallow copy |
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
*/ |
NamedIdObjectWithParentI element = (NamedIdObjectWithParentI) it.next(); |
||||||
@Override |
result.append(element+" - "); |
||||||
protected Object clone() throws CloneNotSupportedException { |
} |
||||||
NamedIdObjectWithParentCollection c = new NamedIdObjectWithParentCollection(); |
return result.toString(); |
||||||
c.addAll(this); |
} |
||||||
return c; |
|
||||||
} |
/** |
||||||
} |
* Only shallow copy |
||||||
|
*/ |
||||||
|
protected Object clone() throws CloneNotSupportedException { |
||||||
|
NamedIdObjectWithParentCollection c=new NamedIdObjectWithParentCollection(); |
||||||
|
c.addAll(this); |
||||||
|
return c; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 18.11.2003
|
//Created on 18.11.2003
|
||||||
@ -1,77 +1,66 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
public class NamedIdObjectWithParentList extends NamedIdObjectWithParentCollection implements List { |
public class NamedIdObjectWithParentList extends NamedIdObjectWithParentCollection implements List { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
public NamedIdObjectWithParentList() { |
||||||
public NamedIdObjectWithParentList() { |
super(); |
||||||
super(); |
collect=new LinkedList(); |
||||||
collect = new LinkedList(); |
} |
||||||
} |
public Object get(int pos) |
||||||
|
{ |
||||||
@Override |
return ((List)collect).get(pos); |
||||||
public Object get(int pos) { |
} |
||||||
return ((List) collect).get(pos); |
|
||||||
} |
public boolean addAll(int arg0, Collection arg1) { |
||||||
@Override |
return ((List)collect).addAll(arg0,arg1); |
||||||
public boolean addAll(int arg0, Collection arg1) { |
} |
||||||
return ((List) collect).addAll(arg0, arg1); |
|
||||||
} |
public Object set(int arg0, Object arg1) { |
||||||
|
return ((List)collect).set(arg0,arg1); |
||||||
@Override |
} |
||||||
public Object set(int arg0, Object arg1) { |
|
||||||
return ((List) collect).set(arg0, arg1); |
public void add(int pos, Object arg1) { |
||||||
} |
((List)collect).add(pos,arg1); |
||||||
|
} |
||||||
@Override |
|
||||||
public void add(int pos, Object arg1) { |
public Object remove(int arg0) { |
||||||
((List) collect).add(pos, arg1); |
return ((List)collect).remove(arg0); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
|
||||||
public Object remove(int arg0) { |
public ListIterator listIterator(int arg0) { |
||||||
return ((List) collect).remove(arg0); |
return ((List)collect).listIterator(arg0); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
public List subList(int arg0, int arg1) { |
||||||
public ListIterator listIterator(int arg0) { |
return ((List)collect).subList(arg0,arg1); |
||||||
return ((List) collect).listIterator(arg0); |
} |
||||||
} |
|
||||||
|
public int indexOf(Object arg0) { |
||||||
@Override |
return ((List)collect).indexOf(arg0); |
||||||
public List subList(int arg0, int arg1) { |
} |
||||||
return ((List) collect).subList(arg0, arg1); |
|
||||||
} |
public int lastIndexOf(Object arg0) { |
||||||
|
return ((List)collect).lastIndexOf(arg0); |
||||||
@Override |
} |
||||||
public int indexOf(Object arg0) { |
|
||||||
return ((List) collect).indexOf(arg0); |
public ListIterator listIterator() { |
||||||
} |
return ((List)collect).listIterator(); |
||||||
|
} |
||||||
@Override |
/** |
||||||
public int lastIndexOf(Object arg0) { |
* Only shallow copy |
||||||
return ((List) collect).lastIndexOf(arg0); |
*/ |
||||||
} |
protected Object clone() throws CloneNotSupportedException { |
||||||
|
NamedIdObjectWithParentList c=new NamedIdObjectWithParentList(); |
||||||
@Override |
c.addAll(this); |
||||||
public ListIterator listIterator() { |
return c; |
||||||
return ((List) collect).listIterator(); |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
|
||||||
* Only shallow copy |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
|
||||||
NamedIdObjectWithParentList c = new NamedIdObjectWithParentList(); |
|
||||||
c.addAll(this); |
|
||||||
return c; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
//Created on 18.11.2003
|
//Created on 18.11.2003
|
||||||
@ -1,27 +1,25 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.HashSet; |
import java.util.HashSet; |
||||||
import java.util.Set; |
import java.util.Set; |
||||||
|
|
||||||
public class NamedIdObjectWithParentSet extends NamedIdObjectWithParentCollection implements Set { |
public class NamedIdObjectWithParentSet extends NamedIdObjectWithParentCollection implements Set { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
public NamedIdObjectWithParentSet() { |
||||||
public NamedIdObjectWithParentSet() { |
super(); |
||||||
super(); |
collect=new HashSet(); |
||||||
collect = new HashSet(); |
} |
||||||
} |
|
||||||
|
|
||||||
|
/** |
||||||
/** |
* Only shallow copy |
||||||
* Only shallow copy |
*/ |
||||||
*/ |
protected Object clone() throws CloneNotSupportedException { |
||||||
@Override |
NamedIdObjectWithParentCollection c=new NamedIdObjectWithParentSet(); |
||||||
protected Object clone() throws CloneNotSupportedException { |
c.addAll(this); |
||||||
NamedIdObjectWithParentCollection c = new NamedIdObjectWithParentSet(); |
return c; |
||||||
c.addAll(this); |
} |
||||||
return c; |
} |
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
//Created on 03.12.2003
|
//Created on 03.12.2003
|
||||||
@ -1,99 +1,102 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedObjectI; |
import de.memtext.baseobjects.NamedObjectI; |
||||||
import de.memtext.util.EqualsUtil; |
import de.memtext.util.EqualsUtil; |
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class NamedObjectCollection extends BaseObjectCollection implements Collection, Serializable { |
public class NamedObjectCollection |
||||||
private static final long serialVersionUID = 1; |
extends BaseObjectCollection |
||||||
|
implements Collection,Serializable { |
||||||
public NamedObjectCollection() { |
private static final long serialVersionUID = 1; |
||||||
super(); |
|
||||||
} |
public NamedObjectCollection() { |
||||||
|
super(); |
||||||
|
} |
||||||
/** |
|
||||||
* Tries to find an element with the given name |
|
||||||
* @param name |
/** |
||||||
* @return first element with given name |
* Tries to find an element with the given name |
||||||
* @throws IllegalArgumentException if nothing found |
* @param name |
||||||
*/ |
* @return first element with given name |
||||||
public NamedObjectI getByName(String name) { |
* @throws IllegalArgumentException if nothing found |
||||||
NamedObjectI test, result = null; |
*/public NamedObjectI getByName(String name) { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
NamedObjectI test, result = null; |
||||||
test = (NamedObjectI) it.next(); |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
if (test.getName().equals(name)) { |
test = (NamedObjectI) it.next(); |
||||||
result = test; |
if (test.getName().equals(name)) { |
||||||
break; |
result = test; |
||||||
} |
break; |
||||||
} |
} |
||||||
if (result == null) throw new IllegalArgumentException("No element with name " + name + " found."); |
} |
||||||
return result; |
if (result == null) |
||||||
} |
throw new IllegalArgumentException( |
||||||
|
"No element with name " + name + " found."); |
||||||
/** |
return result; |
||||||
* like '12','34','343' |
} |
||||||
* useful for creating sqls like where x in (...) |
/** |
||||||
* @return '' if collection is empty |
* like '12','34','343' |
||||||
*/ |
* useful for creating sqls like where x in (...) |
||||||
|
* @return '' if collection is empty |
||||||
public String getNamesApostropheString() { |
*/ |
||||||
StringBuffer result = new StringBuffer(); |
|
||||||
NamedObjectI test; |
public String getNamesApostropheString() { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
StringBuffer result = new StringBuffer(); |
||||||
test = (NamedObjectI) it.next(); |
NamedObjectI test; |
||||||
result.append("'" + test.getName() + "',"); |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
} |
test = (NamedObjectI) it.next(); |
||||||
StringUtils.deleteLastChar(result); |
result.append("'" + test.getName() + "',"); |
||||||
if (result.length() == 0) result.append("''"); |
} |
||||||
return result.toString(); |
StringUtils.deleteLastChar(result); |
||||||
} |
if (result.length() == 0) |
||||||
|
result.append("''"); |
||||||
public boolean containsItemWithName(String name) { |
return result.toString(); |
||||||
boolean result = false; |
} |
||||||
NamedObjectI test; |
|
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
public boolean containsItemWithName(String name) { |
||||||
test = (NamedObjectI) it.next(); |
boolean result = false; |
||||||
if (EqualsUtil.areEqual(test.getName(), name)) { |
NamedObjectI test; |
||||||
result = true; |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
break; |
test = (NamedObjectI) it.next(); |
||||||
} |
if (EqualsUtil.areEqual(test.getName(),name)) |
||||||
} |
{ |
||||||
return result; |
result = true; |
||||||
} |
break; |
||||||
|
} |
||||||
@Override |
} |
||||||
public boolean add(Object o) { |
return result; |
||||||
if (o == null) throw new IllegalArgumentException("can't add null value"); |
} |
||||||
if (!(o instanceof NamedObjectI)) throw new IllegalArgumentException("only named Objects allowed"); |
|
||||||
return collect.add(o); |
public boolean add(Object o) { |
||||||
} |
if (o == null) |
||||||
|
throw new IllegalArgumentException("can't add null value"); |
||||||
@Override |
if (!(o instanceof NamedObjectI)) |
||||||
public String toString() { |
throw new IllegalArgumentException("only named Objects allowed"); |
||||||
StringBuffer result = new StringBuffer(size() + " NamedObjects: "); |
return collect.add(o); |
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
} |
||||||
NamedObjectI element = (NamedObjectI) it.next(); |
public String toString() |
||||||
result.append(element + " - "); |
{ |
||||||
} |
StringBuffer result=new StringBuffer(size()+" NamedObjects: "); |
||||||
return result.toString(); |
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
} |
NamedObjectI element = (NamedObjectI) it.next(); |
||||||
|
result.append(element+" - "); |
||||||
/** |
} |
||||||
* Only shallow copy |
return result.toString(); |
||||||
*/ |
} |
||||||
@Override |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
/** |
||||||
NamedObjectCollection c = new NamedObjectCollection(); |
* Only shallow copy |
||||||
c.addAll(this); |
*/ |
||||||
return c; |
protected Object clone() throws CloneNotSupportedException { |
||||||
} |
NamedObjectCollection c=new NamedObjectCollection(); |
||||||
} |
c.addAll(this); |
||||||
|
return c; |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,79 +1,70 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class NamedObjectList extends NamedObjectCollection implements List { |
public class NamedObjectList extends NamedObjectCollection implements List { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
public NamedObjectList() { |
||||||
public NamedObjectList() { |
super(); |
||||||
super(); |
collect = new LinkedList(); |
||||||
collect = new LinkedList(); |
} |
||||||
} |
|
||||||
|
public Object get(int pos) |
||||||
@Override |
{ |
||||||
public Object get(int pos) { |
return ((List)collect).get(pos); |
||||||
return ((List) collect).get(pos); |
} |
||||||
} |
|
||||||
@Override |
public boolean addAll(int arg0, Collection arg1) { |
||||||
public boolean addAll(int arg0, Collection arg1) { |
return ((List)collect).addAll(arg0,arg1); |
||||||
return ((List) collect).addAll(arg0, arg1); |
} |
||||||
} |
|
||||||
|
public Object set(int arg0, Object arg1) { |
||||||
@Override |
return ((List)collect).set(arg0,arg1); |
||||||
public Object set(int arg0, Object arg1) { |
} |
||||||
return ((List) collect).set(arg0, arg1); |
|
||||||
} |
public void add(int pos, Object arg1) { |
||||||
|
((List)collect).add(pos,arg1); |
||||||
@Override |
} |
||||||
public void add(int pos, Object arg1) { |
|
||||||
((List) collect).add(pos, arg1); |
public Object remove(int arg0) { |
||||||
} |
return ((List)collect).remove(arg0); |
||||||
|
} |
||||||
@Override |
|
||||||
public Object remove(int arg0) { |
|
||||||
return ((List) collect).remove(arg0); |
public ListIterator listIterator(int arg0) { |
||||||
} |
return ((List)collect).listIterator(arg0); |
||||||
|
} |
||||||
@Override |
|
||||||
public ListIterator listIterator(int arg0) { |
public List subList(int arg0, int arg1) { |
||||||
return ((List) collect).listIterator(arg0); |
return ((List)collect).subList(arg0,arg1); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
public int indexOf(Object arg0) { |
||||||
public List subList(int arg0, int arg1) { |
return ((List)collect).indexOf(arg0); |
||||||
return ((List) collect).subList(arg0, arg1); |
} |
||||||
} |
|
||||||
|
public int lastIndexOf(Object arg0) { |
||||||
@Override |
return ((List)collect).lastIndexOf(arg0); |
||||||
public int indexOf(Object arg0) { |
} |
||||||
return ((List) collect).indexOf(arg0); |
|
||||||
} |
public ListIterator listIterator() { |
||||||
|
return ((List)collect).listIterator(); |
||||||
@Override |
} |
||||||
public int lastIndexOf(Object arg0) { |
|
||||||
return ((List) collect).lastIndexOf(arg0); |
/** |
||||||
} |
* Only shallow copy |
||||||
|
*/ |
||||||
@Override |
protected Object clone() throws CloneNotSupportedException { |
||||||
public ListIterator listIterator() { |
NamedObjectCollection c=new NamedObjectList(); |
||||||
return ((List) collect).listIterator(); |
c.addAll(this); |
||||||
} |
return c; |
||||||
|
} |
||||||
/** |
} |
||||||
* Only shallow copy |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
|
||||||
NamedObjectCollection c = new NamedObjectList(); |
|
||||||
c.addAll(this); |
|
||||||
return c; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,31 +1,29 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.HashSet; |
import java.util.HashSet; |
||||||
import java.util.Set; |
import java.util.Set; |
||||||
|
|
||||||
public class NamedObjectSet extends NamedObjectCollection implements Set { |
public class NamedObjectSet extends NamedObjectCollection implements Set { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
public NamedObjectSet() { |
||||||
public NamedObjectSet() { |
super(); |
||||||
super(); |
collect=new HashSet(); |
||||||
collect = new HashSet(); |
} |
||||||
} |
|
||||||
|
public NamedObjectSet(Set set) { |
||||||
public NamedObjectSet(Set set) { |
super(); |
||||||
super(); |
if (set==null)throw new IllegalArgumentException("set must not be null"); |
||||||
if (set == null) throw new IllegalArgumentException("set must not be null"); |
collect=set; |
||||||
collect = set; |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* Only shallow copy |
||||||
* Only shallow copy |
*/ |
||||||
*/ |
protected Object clone() throws CloneNotSupportedException { |
||||||
@Override |
NamedObjectCollection c=new NamedObjectSet(); |
||||||
protected Object clone() throws CloneNotSupportedException { |
c.addAll(this); |
||||||
NamedObjectCollection c = new NamedObjectSet(); |
return c; |
||||||
c.addAll(this); |
} |
||||||
return c; |
} |
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 02.12.2003 at 19:08:30
|
//Created on 02.12.2003 at 19:08:30
|
||||||
@ -1,92 +1,89 @@ |
|||||||
package de.memtext.buttons; |
package de.memtext.buttons; |
||||||
|
|
||||||
import java.util.Enumeration; |
import java.util.Enumeration; |
||||||
|
|
||||||
import javax.swing.ButtonGroup; |
import javax.swing.ButtonGroup; |
||||||
import javax.swing.JLabel; |
import javax.swing.ButtonModel; |
||||||
import javax.swing.JPanel; |
import javax.swing.JLabel; |
||||||
import javax.swing.JRadioButton; |
import javax.swing.JPanel; |
||||||
|
import javax.swing.JRadioButton; |
||||||
public class ButtonGroupPanel extends JPanel { |
|
||||||
ButtonGroup group = new ButtonGroup(); |
public class ButtonGroupPanel extends JPanel { |
||||||
|
ButtonGroup group = new ButtonGroup(); |
||||||
ButtonWithValue hiddenNoSelectionButton = new ButtonWithValue("", null); |
ButtonWithValue hiddenNoSelectionButton = new ButtonWithValue("", null); |
||||||
|
|
||||||
public ButtonGroupPanel() { |
public ButtonGroupPanel() { |
||||||
this(null); |
this(null); |
||||||
} |
} |
||||||
|
public ButtonGroupPanel(String header) { |
||||||
public ButtonGroupPanel(String header) { |
super(); |
||||||
super(); |
if (header != null) |
||||||
if (header != null) this.add(new JLabel(header)); |
this.add(new JLabel(header)); |
||||||
|
|
||||||
hiddenNoSelectionButton.setVisible(false); |
hiddenNoSelectionButton.setVisible(false); |
||||||
hiddenNoSelectionButton.setSelected(true); |
hiddenNoSelectionButton.setSelected(true); |
||||||
group.add(hiddenNoSelectionButton); |
group.add(hiddenNoSelectionButton); |
||||||
} |
} |
||||||
|
public void addCategory(String label, Object value,boolean isSelected) { |
||||||
public void addCategory(String label, Object value, boolean isSelected) { |
ButtonWithValue b = new ButtonWithValue(label, value); |
||||||
ButtonWithValue b = new ButtonWithValue(label, value); |
this.add(b); |
||||||
this.add(b); |
group.add(b); |
||||||
group.add(b); |
b.setSelected(isSelected); |
||||||
b.setSelected(isSelected); |
} |
||||||
} |
public void addCategory(String label, Object value) { |
||||||
|
addCategory(label, value,false); |
||||||
public void addCategory(String label, Object value) { |
} |
||||||
addCategory(label, value, false); |
|
||||||
} |
public void addCategory(String label, int i) { |
||||||
|
addCategory(label, new Integer(i)); |
||||||
public void addCategory(String label, int i) { |
} |
||||||
addCategory(label, Integer.valueOf(i)); |
public void addCategory(String label, int i,boolean isSelected) { |
||||||
} |
addCategory(label, new Integer(i),isSelected); |
||||||
|
} |
||||||
public void addCategory(String label, int i, boolean isSelected) { |
/** |
||||||
addCategory(label, Integer.valueOf(i), isSelected); |
* If you pass null as an argument no element will be selected |
||||||
} |
* @param label |
||||||
|
*/ |
||||||
/** |
public void setSelected(String label) { |
||||||
* If you pass null as an argument no element will be selected |
if (label == null) |
||||||
* @param label |
hiddenNoSelectionButton.setSelected(true); |
||||||
*/ |
else |
||||||
public void setSelected(String label) { |
for (Enumeration en = group.getElements(); |
||||||
if (label == null) |
en.hasMoreElements(); |
||||||
hiddenNoSelectionButton.setSelected(true); |
) { |
||||||
else |
ButtonWithValue b = (ButtonWithValue) en.nextElement(); |
||||||
for (Enumeration en = group.getElements(); en.hasMoreElements();) { |
if (b.getText().equals(label)) { |
||||||
ButtonWithValue b = (ButtonWithValue) en.nextElement(); |
b.doClick(); |
||||||
if (b.getText().equals(label)) { |
break; |
||||||
b.doClick(); |
} |
||||||
break; |
} |
||||||
} |
} |
||||||
} |
|
||||||
} |
public Object getSelectedValue() { |
||||||
|
ButtonWithValue selectedButton=null; |
||||||
public Object getSelectedValue() { |
for (Enumeration en = group.getElements(); |
||||||
ButtonWithValue selectedButton = null; |
en.hasMoreElements(); |
||||||
for (Enumeration en = group.getElements(); en.hasMoreElements();) { |
) { |
||||||
ButtonWithValue b = (ButtonWithValue) en.nextElement(); |
ButtonWithValue b = (ButtonWithValue) en.nextElement(); |
||||||
if (b.isSelected()) { |
if (b.isSelected()) { |
||||||
selectedButton = b; |
selectedButton=b; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
} |
||||||
return selectedButton.getValue(); |
return selectedButton.getValue(); |
||||||
} |
} |
||||||
|
class ButtonWithValue extends JRadioButton { |
||||||
class ButtonWithValue extends JRadioButton { |
private Object value; |
||||||
private Object value; |
ButtonWithValue(String label, Object value) { |
||||||
|
super(label); |
||||||
ButtonWithValue(String label, Object value) { |
this.value = value; |
||||||
super(label); |
} |
||||||
this.value = value; |
Object getValue() { |
||||||
} |
return value; |
||||||
|
} |
||||||
Object getValue() { |
|
||||||
return value; |
} |
||||||
} |
|
||||||
|
} |
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
//Created on 17.02.2004 at 13:40:06
|
//Created on 17.02.2004 at 13:40:06
|
||||||
@ -1,38 +1,39 @@ |
|||||||
package de.memtext.buttons; |
package de.memtext.buttons; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* JButtons not as static variables, because can be used in different |
* JButtons not as static variables, because can be used in different |
||||||
* places in one application, setting one be invisible would make all invisible |
* places in one application, setting one be invisible would make all invisible |
||||||
*/ |
*/ |
||||||
public class Standard { |
public class Standard { |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for Standard. |
* Constructor for Standard. |
||||||
*/ |
*/ |
||||||
private Standard() { |
private Standard() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
|
|
||||||
public static JButton getCopy() { |
public static JButton getCopy() |
||||||
|
{ |
||||||
JButton copy = new JButton(de.memtext.icons.MBStandardIcons.getCopy()); |
|
||||||
copy.setToolTipText("Kopieren"); |
JButton copy=new JButton(de.memtext.icons.MBStandardIcons.getCopy()); |
||||||
copy.setActionCommand("copy"); |
copy.setToolTipText("Kopieren"); |
||||||
return copy; |
copy.setActionCommand("copy"); |
||||||
|
return copy; |
||||||
} |
|
||||||
|
} |
||||||
public static JButton getCopyWithText() { |
public static JButton getCopyWithText() |
||||||
|
{ |
||||||
JButton copy = new JButton("Kopieren", de.memtext.icons.MBStandardIcons.getCopy()); |
|
||||||
copy.setToolTipText("Kopieren"); |
JButton copy=new JButton("Kopieren",de.memtext.icons.MBStandardIcons.getCopy()); |
||||||
copy.setActionCommand("copy"); |
copy.setToolTipText("Kopieren"); |
||||||
return copy; |
copy.setActionCommand("copy"); |
||||||
|
return copy; |
||||||
} |
|
||||||
|
} |
||||||
} |
|
||||||
|
} |
||||||
|
|||||||
@ -1,44 +1,43 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.util.ListResourceBundle; |
import java.util.ListResourceBundle; |
||||||
|
/** |
||||||
/** |
* Resources for HsqlStandaloneMgr. |
||||||
* Resources for HsqlStandaloneMgr. |
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
||||||
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
* by copying HsqlStandaloneMgrResources_de to your locale |
||||||
* by copying HsqlStandaloneMgrResources_de to your locale |
*/ |
||||||
*/ |
public abstract class AbstractHsqlStandaloneMgrResources extends ListResourceBundle { |
||||||
public abstract class AbstractHsqlStandaloneMgrResources extends ListResourceBundle { |
|
||||||
|
public abstract String getDbInUseBy(String dbname,String user); |
||||||
public abstract String getDbInUseBy(String dbname, String user); |
} |
||||||
} |
|
||||||
|
|
||||||
|
|||||||
@ -1,158 +1,174 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.io.File; |
import java.io.File; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.DriverManager; |
import java.sql.DriverManager; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
import java.text.DateFormat; |
import java.text.DateFormat; |
||||||
import java.text.ParseException; |
import java.text.ParseException; |
||||||
import java.text.SimpleDateFormat; |
import java.text.SimpleDateFormat; |
||||||
import java.util.Date; |
import java.util.Date; |
||||||
|
/** |
||||||
/** |
* Additional procedures for HSQLDB |
||||||
* Additional procedures for HSQLDB |
* make sure that this class in the classpath. |
||||||
* make sure that this class in the classpath. |
* To constantly add it to hsql. |
||||||
* To constantly add it to hsql. |
* Go to the directory where your hsqldb.jar is located |
||||||
* Go to the directory where your hsqldb.jar is located |
* Call jar -xf hsqlAddOn.jar |
||||||
* Call jar -xf hsqlAddOn.jar |
* jar -uf hsqldb.jar org/hsqldb/Library2.class |
||||||
* jar -uf hsqldb.jar org/hsqldb/Library2.class |
* Delete the directory org. |
||||||
* Delete the directory org. |
* |
||||||
* |
* Open your Database in Database Manager and execute |
||||||
* Open your Database in Database Manager and execute |
* the following commands once: |
||||||
* the following commands once: |
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
||||||
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
||||||
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
|
||||||
|
|
||||||
|
*/ |
||||||
*/ |
public class AddProc { |
||||||
public class AddProc { |
private static DateFormat dfUS = new SimpleDateFormat("yyyy-MM-dd"); |
||||||
private static DateFormat dfUS = new SimpleDateFormat("yyyy-MM-dd"); |
|
||||||
|
private AddProc() { |
||||||
private AddProc() { |
super(); |
||||||
super(); |
} |
||||||
} |
/** |
||||||
|
* Fills regular tables with values from a CSV-file. |
||||||
/** |
* Similar to Postgres COPY FROM command. |
||||||
* Fills regular tables with values from a CSV-file. |
* |
||||||
* Similar to Postgres COPY FROM command. |
* If you want to fill your table TEST with data from test.csv |
||||||
* |
* make sure that this class in the classpath and that<br> |
||||||
* If you want to fill your table TEST with data from test.csv |
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC;<br> |
||||||
* make sure that this class in the classpath and that<br> |
CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom"<br> |
||||||
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC;<br> |
* has been called in your database at some point. |
||||||
CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom"<br> |
<br> |
||||||
* has been called in your database at some point. |
* Then execute <br> |
||||||
<br> |
* CALL COPYFROM('TEST','test.csv',null)<br> |
||||||
* Then execute <br> |
* <br> |
||||||
* CALL COPYFROM('TEST','test.csv',null)<br> |
* if your not using , but | as a field separator<br> |
||||||
* <br> |
CALL COPYFROM('TEST','test.csv','fs=|')<br> |
||||||
* if your not using , but | as a field separator<br> |
<br> |
||||||
CALL COPYFROM('TEST','test.csv','fs=|')<br> |
* |
||||||
<br> |
* @param con - Connection is automatically handed over by HSQL |
||||||
* |
* @param table - the name of the table that is to be filled |
||||||
* @param con - Connection is automatically handed over by HSQL |
* if you created your table with "", e.g. create table "myData" <br> |
||||||
* @param table - the name of the table that is to be filled |
* also pass the inverted commans like this CALL COPYFROM('\"myData\"','test.csv',null); |
||||||
* if you created your table with "", e.g. create table "myData" <br> |
* |
||||||
* also pass the inverted commans like this CALL COPYFROM('\"myData\"','test.csv',null); |
* @param file - the filename of the CSV-file |
||||||
* |
* @param options - you can specify options separated by ; |
||||||
* @param file - the filename of the CSV-file |
* which are described in the text table documentation e.g.<br> |
||||||
* @param options - you can specify options separated by ; |
* fs=| to use pipe instead of default comma as field separator or<br> |
||||||
* which are described in the text table documentation e.g.<br> |
* |
||||||
* fs=| to use pipe instead of default comma as field separator or<br> |
* fs=|;vs=.;lvs=~" varchar separator, longvarchar separator<br> |
||||||
* |
* ignore_first=true; ignore first line<br> |
||||||
* fs=|;vs=.;lvs=~" varchar separator, longvarchar separator<br> |
* all_quoted=true or<br> |
||||||
* ignore_first=true; ignore first line<br> |
* encoding=UTF-8 if you don't have ASCII<br> |
||||||
* all_quoted=true or<br> |
* @throws SQLException |
||||||
* encoding=UTF-8 if you don't have ASCII<br> |
*/ |
||||||
* @throws SQLException |
public static String copyFrom( |
||||||
*/ |
Connection con, |
||||||
public static String copyFrom(Connection con, String table, String file, String options) throws SQLException { |
String table, |
||||||
if (table == null || table.equals("")) throw new IllegalArgumentException("Table must not be null or empty"); |
String file, |
||||||
if (file == null || file.equals("")) throw new IllegalArgumentException("File must not be null or empty"); |
String options) |
||||||
File f = new File(file); |
throws SQLException { |
||||||
if (!f.exists()) throw new IllegalArgumentException("source file " + file + " doesn't exist"); |
if (table == null || table.equals("")) |
||||||
|
throw new IllegalArgumentException("Table must not be null or empty"); |
||||||
//normally created tables are in UPPERCASE in the metadata,
|
if (file == null || file.equals("")) |
||||||
//but tables in inverted commas (create table "myData")
|
throw new IllegalArgumentException("File must not be null or empty"); |
||||||
//are stored case sensitive
|
File f = new File(file); |
||||||
String tableNameInMetaData; |
if (!f.exists()) |
||||||
if (table.startsWith("\"")) |
throw new IllegalArgumentException( |
||||||
tableNameInMetaData = table.substring(1, table.length() - 1); |
"source file " + file + " doesn't exist"); |
||||||
else |
|
||||||
tableNameInMetaData = table.toUpperCase(); |
//normally created tables are in UPPERCASE in the metadata,
|
||||||
StringBuffer buf = new StringBuffer("create temp text table TMP_COPYFROM("); |
//but tables in inverted commas (create table "myData")
|
||||||
|
//are stored case sensitive
|
||||||
ResultSet rs = con.getMetaData().getColumns(null, null, tableNameInMetaData, null); |
String tableNameInMetaData; |
||||||
String colname, coltype; |
if (table.startsWith("\"")) |
||||||
boolean tableFound = false; |
tableNameInMetaData = table.substring(1, table.length() - 1); |
||||||
while (rs.next()) { |
else |
||||||
tableFound = true; |
tableNameInMetaData = table.toUpperCase(); |
||||||
colname = rs.getObject(4).toString(); |
StringBuffer buf = |
||||||
coltype = rs.getObject(6).toString(); |
new StringBuffer("create temp text table TMP_COPYFROM("); |
||||||
buf.append(colname + " " + coltype + ","); |
|
||||||
} |
ResultSet rs = |
||||||
rs.close(); |
con.getMetaData().getColumns(null, null, tableNameInMetaData, null); |
||||||
if (!tableFound) throw new SQLException("Copy from failed - table " + table + " not found"); |
String colname, coltype; |
||||||
buf.deleteCharAt(buf.lastIndexOf(",")); |
boolean tableFound = false; |
||||||
buf.append("); SET TABLE TMP_COPYFROM SOURCE \"" + file); |
while (rs.next()) { |
||||||
if (options != null) buf.append(";" + options); |
tableFound = true; |
||||||
buf.append("\";"); |
colname = rs.getObject(4).toString(); |
||||||
buf.append("insert into " + table + " select * from TMP_COPYFROM"); |
coltype = rs.getObject(6).toString(); |
||||||
System.out.println(buf); |
buf.append(colname + " " + coltype + ","); |
||||||
Statement stmt = con.createStatement(); |
} |
||||||
try { |
rs.close(); |
||||||
stmt.execute(buf.toString()); |
if (!tableFound) |
||||||
return "success"; |
throw new SQLException( |
||||||
} |
"Copy from failed - table " |
||||||
//finally is executed before returning whether an exception occurs or not
|
+ table |
||||||
finally { |
+ " not found"); |
||||||
stmt.execute("drop table TMP_COPYFROM IF EXISTS"); |
buf.deleteCharAt(buf.lastIndexOf(",")); |
||||||
} |
buf.append("); SET TABLE TMP_COPYFROM SOURCE \"" + file); |
||||||
|
if (options != null) |
||||||
} |
buf.append(";" + options); |
||||||
|
buf.append("\";"); |
||||||
|
buf.append("insert into " + table + " select * from TMP_COPYFROM"); |
||||||
public static String toDate(String year, String month, String day) throws ParseException { |
System.out.println(buf); |
||||||
String result; |
Statement stmt = con.createStatement(); |
||||||
Date d = dfUS.parse(year.trim() + "-" + month.trim() + "-" + day.trim()); |
try { |
||||||
result = dfUS.format(d); |
stmt.execute(buf.toString()); |
||||||
return result; |
return "success"; |
||||||
} |
} |
||||||
|
//finally is executed before returning whether an exception occurs or not
|
||||||
public static String toDate(String year, int month, int day) throws ParseException { |
finally { |
||||||
return toDate(year + "", month + "", day + ""); |
stmt.execute("drop table TMP_COPYFROM IF EXISTS"); |
||||||
} |
} |
||||||
|
|
||||||
public static String toDate(int year, int month, int day) throws ParseException { |
} |
||||||
return toDate(year + "", month + "", day + ""); |
|
||||||
|
|
||||||
} |
public static String toDate(String year, String month, String day) |
||||||
|
throws ParseException { |
||||||
public static void main(String a[]) { |
String result; |
||||||
Connection conn = null; |
Date d = |
||||||
try { |
dfUS.parse(year.trim() + "-" + month.trim() + "-" + day.trim()); |
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
result = dfUS.format(d); |
||||||
conn = DriverManager.getConnection("jdbc:hsqldb:test", "sa", ""); |
return result; |
||||||
java.sql.Statement stmt = conn.createStatement(); |
} |
||||||
stmt.execute("drop table \"test\" if exists;create table \"test\" (col1 integer,col2 varchar, col3 double,col4 date)"); |
public static String toDate(String year, int month, int day) |
||||||
copyFrom(conn, "\"test\"", "test.csv", "fs=;"); |
throws ParseException { |
||||||
System.out.println("2"); |
return toDate(year + "", month + "", day + ""); |
||||||
copyFrom(conn, "\"test\"", "test.csv", "fs=;"); |
} |
||||||
stmt.close(); |
public static String toDate(int year, int month, int day) |
||||||
|
throws ParseException { |
||||||
} catch (ClassNotFoundException e) { |
return toDate(year + "", month + "", day + ""); |
||||||
e.printStackTrace(); |
|
||||||
} catch (SQLException e) { |
} |
||||||
e.printStackTrace(); |
public static void main(String a[]) { |
||||||
} finally { |
Connection conn = null; |
||||||
try { |
try { |
||||||
conn.close(); |
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
} catch (SQLException e1) { |
conn = DriverManager.getConnection("jdbc:hsqldb:test", "sa", ""); |
||||||
e1.printStackTrace(); |
java.sql.Statement stmt = conn.createStatement(); |
||||||
} |
stmt.execute( |
||||||
} |
"drop table \"test\" if exists;create table \"test\" (col1 integer,col2 varchar, col3 double,col4 date)"); |
||||||
} |
copyFrom(conn, "\"test\"", "test.csv", "fs=;"); |
||||||
} |
System.out.println("2"); |
||||||
|
copyFrom(conn, "\"test\"", "test.csv", "fs=;"); |
||||||
|
stmt.close(); |
||||||
|
|
||||||
|
} catch (ClassNotFoundException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} catch (SQLException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
conn.close(); |
||||||
|
} catch (SQLException e1) { |
||||||
|
e1.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 08.03.2004 at 13:48:03
|
//Created on 08.03.2004 at 13:48:03
|
||||||
@ -1,49 +1,43 @@ |
|||||||
/* |
/* |
||||||
* Created on 23.07.2003 |
* Created on 23.07.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author Gast |
* @author Gast |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class Comparison { |
public class Comparison { |
||||||
private String name; |
private String name; |
||||||
|
private Collection units = new LinkedList(); |
||||||
private Collection units = new LinkedList(); |
public Comparison(String name) { |
||||||
|
this.name = name; |
||||||
public Comparison(String name) { |
} |
||||||
this.name = name; |
public void addUnit(ComparisonUnit unit) { |
||||||
} |
units.add(unit); |
||||||
|
|
||||||
public void addUnit(ComparisonUnit unit) { |
} |
||||||
units.add(unit); |
public Iterator iterator() |
||||||
|
{ |
||||||
} |
return units.iterator(); |
||||||
|
} |
||||||
public Iterator iterator() { |
public int getUnitCount() |
||||||
return units.iterator(); |
{ |
||||||
} |
return units.size(); |
||||||
|
} |
||||||
public int getUnitCount() { |
public void removeUnit(ComparisonUnit unit) { |
||||||
return units.size(); |
units.remove(unit); |
||||||
} |
} |
||||||
|
public String toString() { |
||||||
public void removeUnit(ComparisonUnit unit) { |
return name; |
||||||
units.remove(unit); |
} |
||||||
} |
} |
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return name; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,51 +1,50 @@ |
|||||||
/* |
/* |
||||||
* Created on 23.07.2003 |
* Created on 23.07.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author Gast |
* @author Gast |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class ComparisonUnit { |
public class ComparisonUnit { |
||||||
private String name, sql; |
private String name,sql; |
||||||
|
public ComparisonUnit(String name,String sql) |
||||||
public ComparisonUnit(String name, String sql) { |
{ |
||||||
this.name = name; |
this.name=name; |
||||||
this.sql = sql; |
this.sql=sql; |
||||||
} |
} |
||||||
|
/** |
||||||
/** |
* @return |
||||||
* @return |
*/ |
||||||
*/ |
public String getName() { |
||||||
public String getName() { |
return name; |
||||||
return name; |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* @return |
||||||
* @return |
*/ |
||||||
*/ |
public String getSql() { |
||||||
public String getSql() { |
return sql; |
||||||
return sql; |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* @param string |
||||||
* @param string |
*/ |
||||||
*/ |
public void setName(String string) { |
||||||
public void setName(String string) { |
name = string; |
||||||
name = string; |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* @param string |
||||||
* @param string |
*/ |
||||||
*/ |
public void setSql(String string) { |
||||||
public void setSql(String string) { |
sql = string; |
||||||
sql = string; |
} |
||||||
} |
|
||||||
|
} |
||||||
} |
|
||||||
|
|||||||
@ -1,100 +1,127 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
import java.io.IOException; |
||||||
import java.io.IOException; |
import java.sql.Connection; |
||||||
import java.sql.Connection; |
import java.sql.DriverManager; |
||||||
import java.sql.DriverManager; |
import java.sql.SQLException; |
||||||
import java.sql.SQLException; |
import java.util.Properties; |
||||||
import java.util.Properties; |
|
||||||
|
import de.memtext.util.CryptUtils; |
||||||
import de.memtext.util.CryptUtils; |
import de.memtext.util.PropUtils; |
||||||
import de.memtext.util.PropUtils; |
/** |
||||||
|
* This class is a utility that makes the creation of database connections |
||||||
/** |
* easier. If necessary, one can use loadClass("jdbdcDriver-class") and then |
||||||
* This class is a utility that makes the creation of database connections |
* use one of the static getConnection(..) methods |
||||||
* easier. If necessary, one can use loadClass("jdbdcDriver-class") and then |
* @author MB |
||||||
* use one of the static getConnection(..) methods |
* |
||||||
* @author MB |
|
||||||
* |
*/ |
||||||
|
public class ConnectionCreator { |
||||||
*/ |
public static void loadClass(String className) { |
||||||
public class ConnectionCreator { |
try { |
||||||
public static void loadClass(String className) { |
Class.forName(className); |
||||||
try { |
|
||||||
Class.forName(className); |
} catch (Exception e) { |
||||||
|
System.out.println(e.toString()); |
||||||
} catch (Exception e) { |
System.exit(0); |
||||||
System.out.println(e.toString()); |
} |
||||||
System.exit(0); |
} |
||||||
} |
public static Connection getConnection( |
||||||
} |
String url, |
||||||
|
String username, |
||||||
public static Connection getConnection(String url, String username, String passwd) throws SQLException { |
String passwd) throws SQLException |
||||||
|
{ |
||||||
return DriverManager.getConnection(url, username, passwd); |
|
||||||
} |
return DriverManager.getConnection(url, username, passwd); |
||||||
|
} |
||||||
public static Connection getConnection(String driver, String url, String username, String passwd) throws SQLException, ClassNotFoundException { |
public static Connection getConnection( |
||||||
Class.forName(driver); |
String driver, |
||||||
return getConnection(url, username, passwd); |
String url, |
||||||
} |
String username, |
||||||
|
String passwd) |
||||||
public static Connection getConnectionQuitOnException(String driver, String url, String username, String passwd) { |
throws SQLException, ClassNotFoundException { |
||||||
Connection con = null; |
Class.forName(driver); |
||||||
try { |
return getConnection(url, username, passwd); |
||||||
con = getConnection(driver, url, username, passwd); |
} |
||||||
} catch (Exception e) { |
|
||||||
System.out.println("Couldn't create connection to database " + url + "\n" + e.toString()); |
public static Connection getConnectionQuitOnException( |
||||||
System.exit(-1); |
String driver, |
||||||
} |
String url, |
||||||
return con; |
String username, |
||||||
} |
String passwd) { |
||||||
|
Connection con = null; |
||||||
public static Connection getConnection(String propfilename, String driverkey, String urlkey, String usernamekey, String passwordkey) |
try { |
||||||
throws IOException, SQLException, ClassNotFoundException { |
con = getConnection(driver, url, username, passwd); |
||||||
Properties props = PropUtils.getProps(propfilename); |
} catch (Exception e) { |
||||||
String driver = PropUtils.getProperty(props, driverkey); |
System.out.println( |
||||||
String url = PropUtils.getProperty(props, urlkey); |
"Couldn't create connection to database " |
||||||
String username = PropUtils.getProperty(props, usernamekey); |
+ url |
||||||
String passwd = PropUtils.getProperty(props, passwordkey); |
+ "\n" |
||||||
return getConnection(driver, url, username, passwd); |
+ e.toString()); |
||||||
|
System.exit(-1); |
||||||
} |
} |
||||||
|
return con; |
||||||
public static Connection getConnection(String propfilename) throws IOException, SQLException, ClassNotFoundException { |
} |
||||||
return getConnection(propfilename, "driver", "url", "username", "password"); |
public static Connection getConnection( |
||||||
} |
String propfilename, |
||||||
|
String driverkey, |
||||||
/** |
String urlkey, |
||||||
* Method getConnectionCryptPassword. |
String usernamekey, |
||||||
* 28.10.08 EInfache Verschlüsselungsmethode wird nicht mehr unterstützt |
String passwordkey) throws IOException, SQLException, ClassNotFoundException |
||||||
* @param propfilename |
{ |
||||||
* @param string |
Properties props = PropUtils.getProps(propfilename); |
||||||
* @param string1 |
String driver = PropUtils.getProperty(props, driverkey); |
||||||
* @param string11 |
String url = PropUtils.getProperty(props, urlkey); |
||||||
* @param string111 |
String username = PropUtils.getProperty(props, usernamekey); |
||||||
* @return Connection |
String passwd = PropUtils.getProperty(props, passwordkey); |
||||||
* @throws IOException |
return getConnection(driver, url, username, passwd); |
||||||
* @throws ClassNotFoundException |
|
||||||
* @throws SQLException |
} |
||||||
*/ |
public static Connection getConnection(String propfilename) throws IOException, SQLException, ClassNotFoundException |
||||||
public static Connection getConnectionCryptPassword(String propfilename, String driverkey, String urlkey, String usernamekey, String passwordkey) |
{ |
||||||
throws IOException, SQLException, ClassNotFoundException { |
return getConnection( |
||||||
Properties props = PropUtils.getProps(propfilename); |
propfilename, |
||||||
String driver = PropUtils.getProperty(props, driverkey); |
"driver", |
||||||
String url = PropUtils.getProperty(props, urlkey); |
"url", |
||||||
String username = PropUtils.getProperty(props, usernamekey); |
"username", |
||||||
String passwd = PropUtils.getProperty(props, passwordkey); |
"password"); |
||||||
if (passwd.startsWith("sx_des")) { |
} |
||||||
try { |
|
||||||
passwd = CryptUtils.decryptStringDES(passwd.substring(6)); |
/** |
||||||
} catch (Exception e) { |
* Method getConnectionCryptPassword. |
||||||
e.printStackTrace(); |
* 28.10.08 EInfache Verschlüsselungsmethode wird nicht mehr unterstützt |
||||||
throw new SQLException("DES-Passwort konnte nicht entschlüsselt werden"); |
* @param propfilename |
||||||
} |
* @param string |
||||||
} |
* @param string1 |
||||||
// else
|
* @param string11 |
||||||
// passwd=de.memtext.util.CryptUtils.decryptSimple(passwd );
|
* @param string111 |
||||||
return getConnection(driver, url, username, passwd); |
* @return Connection |
||||||
} |
* @throws IOException |
||||||
|
* @throws ClassNotFoundException |
||||||
} |
* @throws SQLException |
||||||
|
*/ |
||||||
|
public static Connection getConnectionCryptPassword( |
||||||
|
String propfilename, |
||||||
|
String driverkey, |
||||||
|
String urlkey, |
||||||
|
String usernamekey, |
||||||
|
String passwordkey) throws IOException, SQLException, ClassNotFoundException |
||||||
|
{ |
||||||
|
Properties props = PropUtils.getProps(propfilename); |
||||||
|
String driver = PropUtils.getProperty(props, driverkey); |
||||||
|
String url = PropUtils.getProperty(props, urlkey); |
||||||
|
String username = PropUtils.getProperty(props, usernamekey); |
||||||
|
String passwd =PropUtils.getProperty(props, passwordkey); |
||||||
|
if (passwd.startsWith("sx_des")) { |
||||||
|
try { |
||||||
|
passwd = CryptUtils.decryptStringDES(passwd.substring(6)); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new SQLException("DES-Passwort konnte nicht entschlüsselt werden"); |
||||||
|
} |
||||||
|
} |
||||||
|
// else
|
||||||
|
// passwd=de.memtext.util.CryptUtils.decryptSimple(passwd );
|
||||||
|
return getConnection(driver, url, username, passwd); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,43 +1,37 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedObject; |
import de.memtext.baseobjects.NamedObject; |
||||||
|
/** |
||||||
/** |
* This class represents a Database system like Informix or Postgres |
||||||
* This class represents a Database system like Informix or Postgres |
*/ |
||||||
*/ |
public class DB extends NamedObject { |
||||||
public class DB extends NamedObject { |
private String version; |
||||||
private String version; |
static public final DB INFORMIX = new DB("Informix", "7.3"); |
||||||
|
static public final DB POSTGRES = new DB("Postgres", "7.3"); |
||||||
static public final DB INFORMIX = new DB("Informix", "7.3"); |
static public final DB ACCESS = new DB("Access", "2000"); |
||||||
|
/** |
||||||
static public final DB POSTGRES = new DB("Postgres", "7.3"); |
* The public constructors are needed because the DB class is |
||||||
|
* a java bean which is cool for XMLEncoding |
||||||
static public final DB ACCESS = new DB("Access", "2000"); |
* |
||||||
|
*/ |
||||||
/** |
public DB() { |
||||||
* The public constructors are needed because the DB class is |
this("Unbekannte Datenbank",""); |
||||||
* a java bean which is cool for XMLEncoding |
} |
||||||
* |
public DB(String name) { |
||||||
*/ |
this(name, ""); |
||||||
public DB() { |
} |
||||||
this("Unbekannte Datenbank", ""); |
|
||||||
} |
public DB(String name, String version) { |
||||||
|
super(name); |
||||||
public DB(String name) { |
this.version = version; |
||||||
this(name, ""); |
} |
||||||
} |
|
||||||
|
public boolean equals(Object o) { |
||||||
public DB(String name, String version) { |
if (!(o instanceof DB)) |
||||||
super(name); |
return false; |
||||||
this.version = version; |
DB db = (DB) o; |
||||||
} |
return this.getName().equals(db.getName()); |
||||||
|
} |
||||||
@Override |
} |
||||||
public boolean equals(Object o) { |
|
||||||
if (!(o instanceof DB)) return false; |
|
||||||
DB db = (DB) o; |
|
||||||
return this.getName().equals(db.getName()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 03.12.2003 at 15:54:27
|
//Created on 03.12.2003 at 15:54:27
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,78 +1,104 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.DriverManager; |
import java.sql.DriverManager; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
|
|
||||||
public class DBComparison { |
public class DBComparison { |
||||||
|
|
||||||
private DBComparison() { |
private DBComparison() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
|
public static void main(String a[]) { |
||||||
public static void main(String a[]) { |
try { |
||||||
try { |
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
|
||||||
|
java.sql.Connection con = |
||||||
java.sql.Connection con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:9000", "sa", ""); |
DriverManager.getConnection( |
||||||
DBAccess.addConnection("ssc", con); |
"jdbc:hsqldb:hsql://localhost:9000", |
||||||
java.sql.Connection con2 = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:9500", "sa", ""); |
"sa", |
||||||
DBAccess.addConnection("ssc-test", con2); |
""); |
||||||
compare("ssc", "ssc-test"); |
DBAccess.addConnection("ssc", con); |
||||||
|
java.sql.Connection con2 = |
||||||
} catch (ClassNotFoundException e) { |
DriverManager.getConnection( |
||||||
e.printStackTrace(); |
"jdbc:hsqldb:hsql://localhost:9500", |
||||||
} catch (SQLException e) { |
"sa", |
||||||
e.printStackTrace(); |
""); |
||||||
} catch (Exception e) { |
DBAccess.addConnection("ssc-test", con2); |
||||||
e.printStackTrace(); |
compare("ssc", "ssc-test"); |
||||||
} |
|
||||||
|
} catch (ClassNotFoundException e) { |
||||||
} |
e.printStackTrace(); |
||||||
|
} catch (SQLException e) { |
||||||
private static void compare(String db1, String db2) throws SQLException { |
e.printStackTrace(); |
||||||
System.out.println("Start comparing..."); |
} catch (Exception e) { |
||||||
StringBuffer fineTables = new StringBuffer("The following tables are fine: "); |
e.printStackTrace(); |
||||||
List tableList = DBAccess.get(db1).getTableList(); |
} |
||||||
boolean isOk = false; |
|
||||||
for (Iterator it = tableList.iterator(); it.hasNext();) { |
} |
||||||
String table = (String) it.next(); |
private static void compare(String db1, String db2) { |
||||||
|
System.out.println("Start comparing..."); |
||||||
if (DBAccess.get(db2).hasTable(table)) { |
StringBuffer fineTables = |
||||||
isOk = true; |
new StringBuffer("The following tables are fine: "); |
||||||
if (DBAccess.get(db1).getColumnCount(table) != DBAccess.get(db2).getColumnCount(table)) { |
List tableList = DBAccess.get(db1).getTableList(); |
||||||
System.out.println("Table " + table + " has a different number of columns"); |
boolean isOk = false; |
||||||
isOk = false; |
for (Iterator it = tableList.iterator(); it.hasNext();) { |
||||||
} else { |
String table = (String) it.next(); |
||||||
List colList = DBAccess.get(db1).getColumnNames(table); |
|
||||||
for (Iterator it2 = colList.iterator(); it2.hasNext();) { |
if (DBAccess.get(db2).hasTable(table)) { |
||||||
String colname = (String) it2.next(); |
isOk = true; |
||||||
if (!DBAccess.get(db2).hasColumn(table, colname)) { |
if (DBAccess.get(db1).getColumnCount(table) |
||||||
System.out.println("Table " + table + " in " + db2 + " doesn't have column:" + colname); |
!= DBAccess.get(db2).getColumnCount(table)) { |
||||||
isOk = false; |
System.out.println( |
||||||
} else { |
"Table " |
||||||
|
+ table |
||||||
if (DBAccess.get(db1).getColumnType(table, colname) != DBAccess.get(db2).getColumnType(table, colname)) { |
+ " has a different number of columns"); |
||||||
System.out.println("Table " + table + " column:" + colname + " are of different types"); |
isOk = false; |
||||||
isOk = false; |
} else { |
||||||
} |
List colList = DBAccess.get(db1).getColumnNames(table); |
||||||
|
for (Iterator it2 = colList.iterator(); it2.hasNext();) { |
||||||
} |
String colname = (String) it2.next(); |
||||||
} |
if (!DBAccess.get(db2).hasColumn(table, colname)) { |
||||||
if (isOk) fineTables.append(table + ","); |
System.out.println( |
||||||
} |
"Table " |
||||||
|
+ table |
||||||
} else { |
+ " in " |
||||||
System.out.println(db2 + " doesn't contain table:" + table); |
+ db2 |
||||||
} |
+ " doesn't have column:" |
||||||
} |
+ colname); |
||||||
StringUtils.deleteLastChar(fineTables); |
isOk = false; |
||||||
System.out.println(fineTables); |
} else { |
||||||
System.out.println("..done"); |
|
||||||
} |
if (DBAccess.get(db1).getColumnType(table, colname) |
||||||
} |
!= DBAccess.get(db2).getColumnType( |
||||||
|
table, |
||||||
|
colname)) { |
||||||
|
System.out.println( |
||||||
|
"Table " |
||||||
|
+ table |
||||||
|
+ " column:" |
||||||
|
+ colname |
||||||
|
+ " are of different types"); |
||||||
|
isOk = false; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
if (isOk) |
||||||
|
fineTables.append(table + ","); |
||||||
|
} |
||||||
|
|
||||||
|
} else { |
||||||
|
System.out.println(db2 + " doesn't contain table:" + table); |
||||||
|
} |
||||||
|
} |
||||||
|
StringUtils.deleteLastChar(fineTables); |
||||||
|
System.out.println(fineTables); |
||||||
|
System.out.println("..done"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 11.02.2004 at 13:19:36
|
//Created on 11.02.2004 at 13:19:36
|
||||||
@ -1,19 +1,20 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
/** |
/** |
||||||
* Eine spezielle Exception im Servlet. |
* Eine spezielle Exception im Servlet. |
||||||
* Wird zwar im Applet eigentlich nicht gebraucht, aber trotzdem |
* Wird zwar im Applet eigentlich nicht gebraucht, aber trotzdem |
||||||
* in diesem Package, damit Klassen wie Sicht einheitliche throws-Deklarationen haben. |
* in diesem Package, damit Klassen wie Sicht einheitliche throws-Deklarationen haben. |
||||||
* |
* |
||||||
* @author Marlies Winterstein |
* @author Marlies Winterstein |
||||||
* @version 2.0, 18.2.2002 |
* @version 2.0, 18.2.2002 |
||||||
*/ |
*/ |
||||||
public class DBServletException extends Exception { |
public class DBServletException extends Exception |
||||||
public DBServletException() { |
{ |
||||||
super(); |
public DBServletException() |
||||||
} |
{ |
||||||
|
super(); |
||||||
public DBServletException(String msg) { |
} |
||||||
super(msg); |
public DBServletException(String msg) |
||||||
} |
{ |
||||||
} |
super(msg); |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,63 +1,96 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
|
|
||||||
import de.memtext.util.TimeUtils; |
import de.memtext.util.TimeUtils; |
||||||
|
|
||||||
public class DBTimer { |
public class DBTimer { |
||||||
private static int runCount = 200; |
private static int runCount=200; |
||||||
|
private static boolean logEachRun=false; |
||||||
private static boolean logEachRun = false; |
//private static String driver="org.hsqldb.jdbcDriver";
|
||||||
|
private static String driver="com.informix.jdbc.IfxDriver"; |
||||||
//private static String driver="org.hsqldb.jdbcDriver";
|
//private static String url="jdbc:hsqldb:hsql://localhost:9001";
|
||||||
private static String driver = "com.informix.jdbc.IfxDriver"; |
private static String url="jdbc:informix-sqli://jupiter:50000:informixserver=superx_host;database=superx"; |
||||||
|
private static String user="superx"; |
||||||
//private static String url="jdbc:hsqldb:hsql://localhost:9001";
|
private static String passwd="anfang12"; |
||||||
private static String url = "jdbc:informix-sqli://jupiter:50000:informixserver=superx_host;database=superx"; |
private static String sql="execute procedure sp_cob_keychild('1',0);"; |
||||||
|
|
||||||
private static String user = "superx"; |
//wenn ein zweiter Sql folgen soll - drop table tmp_xx muss z.B. in eigenem Aufruf sein.
|
||||||
|
private static String sql2=null;//"select sum(betrag) from cob_busa,tmp_children T where fikrkey=T.key";
|
||||||
private static String passwd = "anfang12"; |
//"select sum(betrag) from cob_busa where fikrkey in (select key from tmp_children)";
|
||||||
|
private static String sql3=null;//"drop table tmp_children;";
|
||||||
private static String sql = "execute procedure sp_cob_keychild('1',0);"; |
public static void main(String[] args) { |
||||||
|
//sql="select sum(betrag) from cob_busa C, tmp_children T where fikrkey=T.key and T.parent='1'";
|
||||||
//wenn ein zweiter Sql folgen soll - drop table tmp_xx muss z.B. in eigenem Aufruf sein.
|
sql = "select sum(betrag) from cob_busa where fikrkey in ('1', \n" + |
||||||
private static String sql2 = null;//"select sum(betrag) from cob_busa,tmp_children T where fikrkey=T.key";
|
" '11 ', \n" + |
||||||
//"select sum(betrag) from cob_busa where fikrkey in (select key from tmp_children)";
|
" '111 ', \n" + |
||||||
|
" '1111 ', \n" + |
||||||
private static String sql3 = null;//"drop table tmp_children;";
|
" '1112 ', \n" + |
||||||
|
" '112 ', \n" + |
||||||
public static void main(String[] args) { |
" '1121 ', \n" + |
||||||
//sql="select sum(betrag) from cob_busa C, tmp_children T where fikrkey=T.key and T.parent='1'";
|
" '1122 ', \n" + |
||||||
sql = "select sum(betrag) from cob_busa where fikrkey in ('1', \n" + " '11 ', \n" + " '111 ', \n" + " '1111 ', \n" + " '1112 ', \n" + " '112 ', \n" |
" '113 ', \n" + |
||||||
+ " '1121 ', \n" + " '1122 ', \n" + " '113 ', \n" + " '1131 ', \n" + " '1132 ', \n" + " '12 ', \n" + " '121 ', \n" + " '1211 ', \n" |
" '1131 ', \n" + |
||||||
+ " '1212 ', \n" + " '1213 ', \n" + " '122 ', \n" + " '123 ', \n" + " '124 ', \n" + " '125 ', \n" + " '126 ', \n" + " '13 ', \n" |
" '1132 ', \n" + |
||||||
+ " '131 ', \n" + " '1311 ', \n" + " '1312 ', \n" + " '1313 ', \n" + " '132 ', \n" + " '1321 ', \n" + " '1322 ', \n" + " '1323 ', \n" |
" '12 ', \n" + |
||||||
+ " '133 ', \n" + " '1331 ', \n" + " '1332 ', \n" + " '1333 ', \n" + " '1334 ', \n" + " '134 ', \n" + " '135 ', \n" + " '136 ', \n" |
" '121 ', \n" + |
||||||
+ " '137 ', \n" + " '138 ')"; |
" '1211 ', \n" + |
||||||
try { |
" '1212 ', \n" + |
||||||
Class.forName(driver); |
" '1213 ', \n" + |
||||||
Connection conn = java.sql.DriverManager.getConnection(url, user, passwd); |
" '122 ', \n" + |
||||||
Statement stmt = conn.createStatement(); |
" '123 ', \n" + |
||||||
TimeUtils t = new TimeUtils(); |
" '124 ', \n" + |
||||||
System.out.println("start " + sql); |
" '125 ', \n" + |
||||||
for (int i = 1; i <= runCount; i++) { |
" '126 ', \n" + |
||||||
if (logEachRun) System.out.println(i); |
" '13 ', \n" + |
||||||
stmt.execute(sql); |
" '131 ', \n" + |
||||||
if (sql2 != null) stmt.execute(sql2); |
" '1311 ', \n" + |
||||||
if (sql3 != null) stmt.execute(sql3); |
" '1312 ', \n" + |
||||||
} |
" '1313 ', \n" + |
||||||
t.print(runCount + " times"); |
" '132 ', \n" + |
||||||
stmt.close(); |
" '1321 ', \n" + |
||||||
conn.close(); |
" '1322 ', \n" + |
||||||
System.out.println("done"); |
" '1323 ', \n" + |
||||||
|
" '133 ', \n" + |
||||||
} catch (Exception e) { |
" '1331 ', \n" + |
||||||
e.printStackTrace(); |
" '1332 ', \n" + |
||||||
System.exit(-1); |
" '1333 ', \n" + |
||||||
} |
" '1334 ', \n" + |
||||||
} |
" '134 ', \n" + |
||||||
} |
" '135 ', \n" + |
||||||
|
" '136 ', \n" + |
||||||
|
" '137 ', \n" + |
||||||
|
" '138 ')"; |
||||||
|
try { |
||||||
|
Class.forName(driver); |
||||||
|
Connection conn = |
||||||
|
java.sql.DriverManager.getConnection( |
||||||
|
url, |
||||||
|
user, |
||||||
|
passwd); |
||||||
|
Statement stmt = conn.createStatement(); |
||||||
|
TimeUtils t=new TimeUtils(); |
||||||
|
System.out.println("start "+sql); |
||||||
|
for (int i=1;i<=runCount;i++) |
||||||
|
{ |
||||||
|
if (logEachRun) System.out.println(i); |
||||||
|
stmt.execute(sql); |
||||||
|
if (sql2!=null) |
||||||
|
stmt.execute(sql2); |
||||||
|
if (sql3!=null) |
||||||
|
stmt.execute(sql3); |
||||||
|
} |
||||||
|
t.print(runCount+" times"); |
||||||
|
stmt.close(); |
||||||
|
conn.close(); |
||||||
|
System.out.println("done"); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
System.exit(-1); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 09.03.2005 at 10:05:37
|
//Created on 09.03.2005 at 10:05:37
|
||||||
@ -1,109 +1,106 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.DriverManager; |
import java.sql.DriverManager; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedObject; |
import de.memtext.baseobjects.NamedObject; |
||||||
|
import de.memtext.util.CryptUtils; |
||||||
/** |
/** |
||||||
* wonder what this is |
* wonder what this is |
||||||
*/ |
*/ |
||||||
public class DataSource extends NamedObject { |
public class DataSource extends NamedObject { |
||||||
|
|
||||||
private static final String CRYPT_PREFIX = "^^@@@"; |
private static final String CRYPT_PREFIX = "^^@@@"; |
||||||
|
private String url, username, cryptPassword, driver; |
||||||
private String url, username, cryptPassword, driver; |
private transient String password; |
||||||
|
private DB db; |
||||||
private transient String password; |
public DataSource() { |
||||||
|
} |
||||||
private DB db; |
|
||||||
|
public DataSource(String url, String username, String password) { |
||||||
public DataSource() { |
setUrl(url); |
||||||
} |
setUsername(username); |
||||||
|
setPassword(password); |
||||||
public DataSource(String url, String username, String password) { |
} |
||||||
setUrl(url); |
|
||||||
setUsername(username); |
public void setInformixSampleValues() { |
||||||
setPassword(password); |
setUrl("jupiter:50000:informixserver=superx_host;database=superx"); |
||||||
} |
setUsername("informix"); |
||||||
|
setPassword(""); |
||||||
public void setInformixSampleValues() { |
this.db=DB.INFORMIX; |
||||||
setUrl("jupiter:50000:informixserver=superx_host;database=superx"); |
} |
||||||
setUsername("informix"); |
public void setAccessSampleValues() { |
||||||
setPassword(""); |
setUrl("jdbc:odbc:jdbcodbc:"); |
||||||
this.db = DB.INFORMIX; |
setUsername("informix"); |
||||||
} |
setPassword(""); |
||||||
|
this.db=DB.ACCESS; |
||||||
public void setAccessSampleValues() { |
} |
||||||
setUrl("jdbc:odbc:jdbcodbc:"); |
|
||||||
setUsername("informix"); |
public String getDriver() { |
||||||
setPassword(""); |
return driver; |
||||||
this.db = DB.ACCESS; |
} |
||||||
} |
|
||||||
|
public String getPassword() { |
||||||
public String getDriver() { |
return password; |
||||||
return driver; |
} |
||||||
} |
|
||||||
|
public String getUrl() { |
||||||
public String getPassword() { |
return url; |
||||||
return password; |
} |
||||||
} |
|
||||||
|
public String getUsername() { |
||||||
public String getUrl() { |
return username; |
||||||
return url; |
} |
||||||
} |
|
||||||
|
public void setDriver(String string) { |
||||||
public String getUsername() { |
driver = string; |
||||||
return username; |
} |
||||||
} |
|
||||||
|
public void setPassword(String string) { |
||||||
public void setDriver(String string) { |
password = string; |
||||||
driver = string; |
this.setCryptPassword(string); |
||||||
} |
} |
||||||
|
|
||||||
public void setPassword(String string) { |
public void setUrl(String string) { |
||||||
password = string; |
url = string; |
||||||
this.setCryptPassword(string); |
} |
||||||
} |
|
||||||
|
public void setUsername(String string) { |
||||||
public void setUrl(String string) { |
username = string; |
||||||
url = string; |
} |
||||||
} |
|
||||||
|
public DB getDb() { |
||||||
public void setUsername(String string) { |
return db; |
||||||
username = string; |
} |
||||||
} |
|
||||||
|
public void setDb(DB db) { |
||||||
public DB getDb() { |
this.db = db; |
||||||
return db; |
} |
||||||
} |
|
||||||
|
public void testConnection() throws SQLException, ClassNotFoundException { |
||||||
public void setDb(DB db) { |
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); |
||||||
this.db = db; |
Connection con=DriverManager.getConnection(url,username,password); |
||||||
} |
con.close(); |
||||||
|
|
||||||
public void testConnection() throws SQLException, ClassNotFoundException { |
|
||||||
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); |
} |
||||||
Connection con = DriverManager.getConnection(url, username, password); |
|
||||||
con.close(); |
public String getCryptPassword() { |
||||||
|
return cryptPassword; |
||||||
|
} |
||||||
} |
|
||||||
|
public void setCryptPassword(String aPwd) { |
||||||
public String getCryptPassword() { |
if (!isEncrypted(aPwd)) |
||||||
return cryptPassword; |
{ |
||||||
} |
//cryptPassword =CRYPT_PREFIX + CryptUtils.encryptStringDES(aPwd);
|
||||||
|
} |
||||||
public void setCryptPassword(String aPwd) { |
} |
||||||
if (!isEncrypted(aPwd)) { |
|
||||||
//cryptPassword =CRYPT_PREFIX + CryptUtils.encryptStringDES(aPwd);
|
public boolean isEncrypted(String aPwd) |
||||||
} |
{ |
||||||
} |
return aPwd.startsWith(CRYPT_PREFIX); |
||||||
|
} |
||||||
public boolean isEncrypted(String aPwd) { |
} |
||||||
return aPwd.startsWith(CRYPT_PREFIX); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 17.04.2004 at 16:28:15
|
//Created on 17.04.2004 at 16:28:15
|
||||||
@ -1,121 +1,116 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
|
|
||||||
import de.memtext.observ.DocumentListenerObserver; |
import de.memtext.observ.DocumentListenerObserver; |
||||||
import de.memtext.widgets.InfoMessage; |
import de.memtext.widgets.InfoMessage; |
||||||
import de.memtext.widgets.LabeledPasswordField; |
import de.memtext.widgets.LabeledPasswordField; |
||||||
import de.memtext.widgets.LabeledTextField; |
import de.memtext.widgets.LabeledTextField; |
||||||
import de.memtext.widgets.MultilineEditPanel; |
import de.memtext.widgets.MultilineEditPanel; |
||||||
import de.memtext.widgets.WarningMessage; |
import de.memtext.widgets.WarningMessage; |
||||||
|
|
||||||
public class DataSourceEditPanel extends MultilineEditPanel { |
public class DataSourceEditPanel extends MultilineEditPanel { |
||||||
private DataSource ds; |
private DataSource ds; |
||||||
|
private LabeledTextField hostField = new LabeledTextField("Host", 10); |
||||||
private LabeledTextField hostField = new LabeledTextField("Host", 10); |
private LabeledTextField serverField = new LabeledTextField("Server", 10); |
||||||
|
private LabeledTextField serviceField = new LabeledTextField("Service", 10); |
||||||
private LabeledTextField serverField = new LabeledTextField("Server", 10); |
private LabeledTextField odbcSourceField = |
||||||
|
new LabeledTextField("Odbc-DSN", 10); |
||||||
private LabeledTextField serviceField = new LabeledTextField("Service", 10); |
private LabeledTextField usernameField = |
||||||
|
new LabeledTextField("Kennung", 10); |
||||||
private LabeledTextField odbcSourceField = new LabeledTextField("Odbc-DSN", 10); |
private LabeledTextField passwordField = |
||||||
|
new LabeledPasswordField("Password", 10); |
||||||
private LabeledTextField usernameField = new LabeledTextField("Kennung", 10); |
private JPanel pButtons = new JPanel(); |
||||||
|
|
||||||
private LabeledTextField passwordField = new LabeledPasswordField("Password", 10); |
public DataSourceEditPanel() { |
||||||
|
this.setBackground(null); |
||||||
private JPanel pButtons = new JPanel(); |
odbcSourceField.setValue("sospos"); |
||||||
|
odbcSourceField.setBackground(null); |
||||||
public DataSourceEditPanel() { |
usernameField.setValue("admin"); |
||||||
this.setBackground(null); |
this.add(hostField); |
||||||
odbcSourceField.setValue("sospos"); |
this.add(serverField); |
||||||
odbcSourceField.setBackground(null); |
this.add(serviceField); |
||||||
usernameField.setValue("admin"); |
this.add(odbcSourceField); |
||||||
this.add(hostField); |
|
||||||
this.add(serverField); |
this.add(usernameField); |
||||||
this.add(serviceField); |
|
||||||
this.add(odbcSourceField); |
this.add(passwordField); |
||||||
|
//this.addGlue();
|
||||||
this.add(usernameField); |
JButton btnTesten = new JButton("testen"); |
||||||
|
btnTesten.setBackground(null); |
||||||
this.add(passwordField); |
pButtons.setBackground(null); |
||||||
//this.addGlue();
|
btnTesten.addActionListener(new ActionListener() { |
||||||
JButton btnTesten = new JButton("testen"); |
public void actionPerformed(ActionEvent ae) { |
||||||
btnTesten.setBackground(null); |
test(); |
||||||
pButtons.setBackground(null); |
} |
||||||
btnTesten.addActionListener(new ActionListener() { |
}); |
||||||
|
pButtons.add(btnTesten); |
||||||
@Override |
//this.addGlue();
|
||||||
public void actionPerformed(ActionEvent ae) { |
this.add(pButtons); |
||||||
test(); |
} |
||||||
} |
public void setDataSource(DataSource ds) { |
||||||
}); |
this.ds = ds; |
||||||
pButtons.add(btnTesten); |
setMode(ds.getDb()); |
||||||
//this.addGlue();
|
} |
||||||
this.add(pButtons); |
public void addButton(JButton btn) { |
||||||
} |
pButtons.add(btn); |
||||||
|
} |
||||||
public void setDataSource(DataSource ds) { |
private void setMode(DB db) { |
||||||
this.ds = ds; |
if (db.equals(DB.ACCESS)) { |
||||||
setMode(ds.getDb()); |
odbcSourceField.setVisible(true); |
||||||
} |
hostField.setVisible(false); |
||||||
|
serverField.setVisible(false); |
||||||
public void addButton(JButton btn) { |
serviceField.setVisible(false); |
||||||
pButtons.add(btn); |
} |
||||||
} |
if (db.equals(DB.INFORMIX)) { |
||||||
|
odbcSourceField.setVisible(false); |
||||||
private void setMode(DB db) { |
hostField.setVisible(true); |
||||||
if (db.equals(DB.ACCESS)) { |
serverField.setVisible(true); |
||||||
odbcSourceField.setVisible(true); |
serviceField.setVisible(true); |
||||||
hostField.setVisible(false); |
} |
||||||
serverField.setVisible(false); |
} |
||||||
serviceField.setVisible(false); |
protected void test() { |
||||||
} |
updateDataSource(); |
||||||
if (db.equals(DB.INFORMIX)) { |
try { |
||||||
odbcSourceField.setVisible(false); |
ds.testConnection(); |
||||||
hostField.setVisible(true); |
InfoMessage.show(this, "Verbindung erfolgreich aufgebaut", "Erfolg"); |
||||||
serverField.setVisible(true); |
} catch (SQLException e) { |
||||||
serviceField.setVisible(true); |
if (ds.getDb().equals( DB.ACCESS)) { |
||||||
} |
WarningMessage.show(this, |
||||||
} |
"Verbindung zur ODBC-Quelle " |
||||||
|
+ odbcSourceField.getValue() |
||||||
protected void test() { |
+ " konnte nicht aufgebaut werden.\n" |
||||||
updateDataSource(); |
+ e, |
||||||
try { |
"Achtung"); |
||||||
ds.testConnection(); |
} |
||||||
InfoMessage.show(this, "Verbindung erfolgreich aufgebaut", "Erfolg"); |
} catch (ClassNotFoundException e) { |
||||||
} catch (SQLException e) { |
WarningMessage.show(this, |
||||||
if (ds.getDb().equals(DB.ACCESS)) { |
"Benötigte Treiber-Klase nicht gefunden ", |
||||||
WarningMessage.show(this, "Verbindung zur ODBC-Quelle " + odbcSourceField.getValue() + " konnte nicht aufgebaut werden.\n" + e, "Achtung"); |
"Achtung"); |
||||||
} |
} |
||||||
} catch (ClassNotFoundException e) { |
} |
||||||
WarningMessage.show(this, "Benötigte Treiber-Klase nicht gefunden ", "Achtung"); |
public void updateDataSource() { |
||||||
} |
if (ds.getDb() == DB.ACCESS) { |
||||||
} |
ds.setUrl("jdbc:odbc:" + odbcSourceField.getValue()); |
||||||
|
} |
||||||
public void updateDataSource() { |
ds.setUsername(usernameField.getValue().toString()); |
||||||
if (ds.getDb() == DB.ACCESS) { |
ds.setPassword(""); |
||||||
ds.setUrl("jdbc:odbc:" + odbcSourceField.getValue()); |
} |
||||||
} |
public void addDocumentListener(DocumentListenerObserver listener) { |
||||||
ds.setUsername(usernameField.getValue().toString()); |
hostField.addDocumentListener(listener); |
||||||
ds.setPassword(""); |
serverField.addDocumentListener(listener); |
||||||
} |
serviceField.addDocumentListener(listener); |
||||||
|
odbcSourceField.addDocumentListener(listener); |
||||||
public void addDocumentListener(DocumentListenerObserver listener) { |
|
||||||
hostField.addDocumentListener(listener); |
usernameField.addDocumentListener(listener); |
||||||
serverField.addDocumentListener(listener); |
|
||||||
serviceField.addDocumentListener(listener); |
passwordField.addDocumentListener(listener); |
||||||
odbcSourceField.addDocumentListener(listener); |
} |
||||||
|
} |
||||||
usernameField.addDocumentListener(listener); |
|
||||||
|
|
||||||
passwordField.addDocumentListener(listener); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 17.04.2004 at 16:37:44
|
//Created on 17.04.2004 at 16:37:44
|
||||||
@ -1,92 +1,94 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbRequest |
public class DbRequest |
||||||
|
|
||||||
implements java.io.Serializable { |
implements java.io.Serializable { |
||||||
static final long serialVersionUID = -2L; |
static final long serialVersionUID = -2L; |
||||||
|
|
||||||
|
|
||||||
private String sql; |
private String sql; |
||||||
|
private String name; |
||||||
private String name; |
private Object[] params; |
||||||
|
private int type; |
||||||
private Object[] params; |
private DbRequestType dbRequestType; |
||||||
|
public DbRequest(String sql) |
||||||
private int type; |
{ |
||||||
|
this(null,sql,null,null); |
||||||
private DbRequestType dbRequestType; |
} |
||||||
|
public DbRequest(String name,String sql,Object[] params) |
||||||
public DbRequest(String sql) { |
{ |
||||||
this(null, sql, null, null); |
this(name,sql,params,null); |
||||||
} |
} |
||||||
|
/** |
||||||
public DbRequest(String name, String sql, Object[] params) { |
* Request type used by servlet |
||||||
this(name, sql, params, null); |
* @param name |
||||||
} |
* @param sql |
||||||
|
* @param params |
||||||
/** |
* @param dbRequestType |
||||||
* Request type used by servlet |
*/ |
||||||
* @param name |
public DbRequest(String name,String sql,Object[] params,DbRequestType dbRequestType) |
||||||
* @param sql |
{ |
||||||
* @param params |
setName(name); |
||||||
* @param dbRequestType |
setSql(sql); |
||||||
*/ |
setParams(params); |
||||||
public DbRequest(String name, String sql, Object[] params, DbRequestType dbRequestType) { |
this.dbRequestType=dbRequestType; |
||||||
setName(name); |
} |
||||||
setSql(sql); |
|
||||||
setParams(params); |
public String getName() |
||||||
this.dbRequestType = dbRequestType; |
{ |
||||||
} |
return name; |
||||||
|
} |
||||||
public String getName() { |
|
||||||
return name; |
public void setName(String name) |
||||||
} |
{ |
||||||
|
this.name=name; |
||||||
public void setName(String name) { |
} |
||||||
this.name = name; |
|
||||||
} |
public Object[] getParams() |
||||||
|
{ |
||||||
public Object[] getParams() { |
return params; |
||||||
return params; |
} |
||||||
} |
|
||||||
|
public void setParams(Object[] params) |
||||||
public void setParams(Object[] params) { |
{ |
||||||
this.params = params; |
this.params=params; |
||||||
} |
} |
||||||
|
|
||||||
public String getSql() { |
public String getSql() |
||||||
return sql; |
{ |
||||||
} |
return sql; |
||||||
|
} |
||||||
public void setSql(String sql) { |
|
||||||
this.sql = sql; |
public void setSql(String sql) |
||||||
} |
{ |
||||||
|
this.sql=sql; |
||||||
/** |
} |
||||||
* @return |
|
||||||
*/ |
/** |
||||||
public DbRequestType getDbRequestType() { |
* @return |
||||||
return dbRequestType; |
*/ |
||||||
} |
public DbRequestType getDbRequestType() { |
||||||
|
return dbRequestType; |
||||||
/** |
} |
||||||
* @param type |
|
||||||
*/ |
/** |
||||||
public void setDbRequestType(DbRequestType type) { |
* @param type |
||||||
dbRequestType = type; |
*/ |
||||||
} |
public void setDbRequestType(DbRequestType type) { |
||||||
|
dbRequestType = type; |
||||||
} |
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|||||||
@ -1,31 +1,27 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbRequestType { |
public class DbRequestType { |
||||||
|
|
||||||
private final String name; |
private final String name; |
||||||
|
|
||||||
public static final DbRequestType QUERY = new DbRequestType("QUERY"); |
public static final DbRequestType QUERY=new DbRequestType("QUERY"); |
||||||
|
public static final DbRequestType UPDATE=new DbRequestType("UPDATE"); |
||||||
public static final DbRequestType UPDATE = new DbRequestType("UPDATE"); |
private DbRequestType(String name) |
||||||
|
{ |
||||||
private DbRequestType(String name) { |
this.name=name; |
||||||
this.name = name; |
} |
||||||
} |
public String toString() {return name; |
||||||
|
} |
||||||
@Override |
} |
||||||
public String toString() { |
|
||||||
return name; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,69 +1,58 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbResponse implements java.io.Serializable { |
public class DbResponse implements java.io.Serializable { |
||||||
static final long serialVersionUID = -3L; |
static final long serialVersionUID = -3L; |
||||||
|
private Collection result; |
||||||
private Collection result; |
private boolean OK; |
||||||
|
private Exception exception; |
||||||
private boolean OK; |
private int updatedRowsCount; |
||||||
|
|
||||||
private Exception exception; |
/** |
||||||
|
* MyServletResponse constructor comment. |
||||||
private int updatedRowsCount; |
*/ |
||||||
|
public DbResponse(Collection result, boolean OK, Exception exception) { |
||||||
/** |
this.result = result; |
||||||
* MyServletResponse constructor comment. |
this.OK = OK; |
||||||
*/ |
this.exception = exception; |
||||||
public DbResponse(Collection result, boolean OK, Exception exception) { |
} |
||||||
this.result = result; |
public Exception getException() { |
||||||
this.OK = OK; |
return exception; |
||||||
this.exception = exception; |
} |
||||||
} |
public Collection getResult() { |
||||||
|
return result; |
||||||
public Exception getException() { |
} |
||||||
return exception; |
public boolean isOK() { |
||||||
} |
return OK; |
||||||
|
} |
||||||
public Collection getResult() { |
public void setException(Exception exception) { |
||||||
return result; |
this.exception = exception; |
||||||
} |
} |
||||||
|
public void setOK(boolean OK) { |
||||||
public boolean isOK() { |
this.OK = OK; |
||||||
return OK; |
} |
||||||
} |
public void setResult(Collection result) { |
||||||
|
this.result = result; |
||||||
public void setException(Exception exception) { |
} |
||||||
this.exception = exception; |
public int getUpdatedRowsCount() { |
||||||
} |
return updatedRowsCount; |
||||||
|
} |
||||||
public void setOK(boolean OK) { |
|
||||||
this.OK = OK; |
public void setUpdatedRowsCount(int updatedRowsCount) { |
||||||
} |
this.updatedRowsCount = updatedRowsCount; |
||||||
|
} |
||||||
public void setResult(Collection result) { |
|
||||||
this.result = result; |
} |
||||||
} |
|
||||||
|
|
||||||
public int getUpdatedRowsCount() { |
|
||||||
return updatedRowsCount; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUpdatedRowsCount(int updatedRowsCount) { |
|
||||||
this.updatedRowsCount = updatedRowsCount; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,105 +1,110 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.net.MalformedURLException; |
import java.net.MalformedURLException; |
||||||
import java.rmi.Naming; |
import java.rmi.Naming; |
||||||
import java.rmi.NotBoundException; |
import java.rmi.NotBoundException; |
||||||
import java.rmi.RMISecurityManager; |
import java.rmi.RMISecurityManager; |
||||||
import java.rmi.RemoteException; |
import java.rmi.RemoteException; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbRmiClient { |
public class DbRmiClient { |
||||||
private DbServerI dbServerI = null; |
private DbServerI dbServerI= null; |
||||||
|
String name="DbServer"; //"//localhost/DbServer"
|
||||||
String name = "DbServer"; //"//localhost/DbServer"
|
public DbRmiClient() |
||||||
|
{ |
||||||
public DbRmiClient() { |
if (System.getSecurityManager() == null) { |
||||||
if (System.getSecurityManager() == null) { |
System.setSecurityManager(new RMISecurityManager()); |
||||||
System.setSecurityManager(new RMISecurityManager()); |
} |
||||||
} |
try { |
||||||
try { |
dbServerI = (DbServerI)Naming.lookup(name); |
||||||
dbServerI = (DbServerI) Naming.lookup(name); |
} catch (MalformedURLException e) { |
||||||
} catch (MalformedURLException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (RemoteException e) { |
||||||
} catch (RemoteException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (NotBoundException e) { |
||||||
} catch (NotBoundException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} |
||||||
} |
} |
||||||
} |
public void test() |
||||||
|
{ |
||||||
public void test() { |
testUpdate(); |
||||||
testUpdate(); |
testQuery(); |
||||||
testQuery(); |
} |
||||||
} |
private void testUpdate() { |
||||||
|
try { |
||||||
private void testUpdate() { |
|
||||||
try { |
DbRequest dbRequest=new DbRequest("update dummy set col2=99"); |
||||||
|
DbResponse dbResponse=dbServerI.execute(dbRequest); |
||||||
DbRequest dbRequest = new DbRequest("update dummy set col2=99"); |
if (dbResponse.isOK()) |
||||||
DbResponse dbResponse = dbServerI.execute(dbRequest); |
{ |
||||||
if (dbResponse.isOK()) { |
System.out.println("OK - updated rows :" + dbResponse.getUpdatedRowsCount()); |
||||||
System.out.println("OK - updated rows :" + dbResponse.getUpdatedRowsCount()); |
} |
||||||
} else { |
else |
||||||
System.out.println("failed :" + dbResponse.getException()); |
{ |
||||||
} |
System.out.println("failed :"+dbResponse.getException()); |
||||||
|
} |
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
System.out.println(" exception: " + e.getMessage()); |
} catch (Exception e) { |
||||||
e.printStackTrace(); |
System.out.println(" exception: " + e.getMessage()); |
||||||
} |
e.printStackTrace(); |
||||||
} |
} |
||||||
|
} |
||||||
private void testQuery() { |
|
||||||
try { |
private void testQuery() { |
||||||
|
try { |
||||||
DbRequest dbRequest = new DbRequest("select * from dummy"); |
|
||||||
DbResponse dbResponse = dbServerI.executeQuery("select * from dummy"); |
DbRequest dbRequest=new DbRequest("select * from dummy"); |
||||||
if (dbResponse.isOK()) { |
DbResponse dbResponse=dbServerI.executeQuery("select * from dummy"); |
||||||
System.out.println("OK"); |
if (dbResponse.isOK()) |
||||||
List result = (List) dbResponse.getResult(); |
{ |
||||||
System.out.println("rows:" + result.size()); |
System.out.println("OK"); |
||||||
int i = 0; |
List result=(List)dbResponse.getResult(); |
||||||
for (Iterator it = result.iterator(); it.hasNext();) { |
System.out.println("rows:"+result.size()); |
||||||
List row = (List) it.next(); |
int i=0; |
||||||
i++; |
for (Iterator it=result.iterator();it.hasNext();) |
||||||
System.out.print("row " + i + " "); |
{ |
||||||
for (Iterator it2 = row.iterator(); it2.hasNext();) { |
List row=(List)it.next(); |
||||||
Object o = it2.next(); |
i++; |
||||||
System.out.print(" - " + o); |
System.out.print("row "+i+" "); |
||||||
} |
for (Iterator it2=row.iterator();it2.hasNext();) |
||||||
System.out.println(""); |
{ |
||||||
} |
Object o=it2.next(); |
||||||
|
System.out.print(" - "+o); |
||||||
} else { |
} |
||||||
System.out.println("failed :" + dbResponse.getException()); |
System.out.println(""); |
||||||
} |
} |
||||||
|
|
||||||
|
} |
||||||
} catch (Exception e) { |
else |
||||||
System.out.println(" exception: " + e.getMessage()); |
{ |
||||||
e.printStackTrace(); |
System.out.println("failed :"+dbResponse.getException()); |
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
public static void main(String a[]) { |
} catch (Exception e) { |
||||||
DbRmiClient c = new DbRmiClient(); |
System.out.println(" exception: " + e.getMessage()); |
||||||
c.test(); |
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
} |
public static void main(String a[]) { |
||||||
|
DbRmiClient c=new DbRmiClient(); |
||||||
} |
c.test(); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,26 +1,23 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.rmi.Remote; |
import java.rmi.Remote; |
||||||
import java.rmi.RemoteException; |
import java.rmi.RemoteException; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public interface DbServerI extends Remote { |
public interface DbServerI extends Remote { |
||||||
public DbResponse execute(String sql) throws RemoteException; |
public DbResponse execute(String sql) throws RemoteException; |
||||||
|
public DbResponse executeQuery(String sql) throws RemoteException; |
||||||
public DbResponse executeQuery(String sql) throws RemoteException; |
public DbResponse execute(DbRequest dbRequest) throws RemoteException; |
||||||
|
public DbResponse executeQuery(DbRequest dbRequest) throws RemoteException; |
||||||
public DbResponse execute(DbRequest dbRequest) throws RemoteException; |
} |
||||||
|
|
||||||
public DbResponse executeQuery(DbRequest dbRequest) throws RemoteException; |
|
||||||
} |
|
||||||
|
|||||||
@ -1,126 +1,117 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.rmi.Naming; |
import java.rmi.Naming; |
||||||
import java.rmi.RMISecurityManager; |
import java.rmi.RMISecurityManager; |
||||||
import java.rmi.RemoteException; |
import java.rmi.RemoteException; |
||||||
import java.rmi.server.UnicastRemoteObject; |
import java.rmi.server.UnicastRemoteObject; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbServerImpl extends UnicastRemoteObject implements de.memtext.db.DbServerI { |
public class DbServerImpl |
||||||
private String dbDriver = "org.hsqldb.jdbcDriver"; |
extends UnicastRemoteObject |
||||||
|
implements de.memtext.db.DbServerI { |
||||||
private String dbURL = "jdbc:hsqldb:hsql://localhost:9000"; |
private String dbDriver = "org.hsqldb.jdbcDriver"; |
||||||
|
private String dbURL = "jdbc:hsqldb:hsql://localhost:9000"; |
||||||
private String userid = "SA"; |
private String userid = "SA"; |
||||||
|
private String passwd = ""; |
||||||
private String passwd = ""; |
private int updateRowCount; |
||||||
|
private Connection con; |
||||||
private int updateRowCount; |
private Statement stmt; |
||||||
|
public DbServerImpl() throws RemoteException { |
||||||
private Connection con; |
super(); |
||||||
|
ConnectionCreator.loadClass(dbDriver); |
||||||
private Statement stmt; |
try { |
||||||
|
con = ConnectionCreator.getConnection(dbURL, userid, passwd); |
||||||
public DbServerImpl() throws RemoteException { |
stmt = con.createStatement(); |
||||||
super(); |
} catch (Exception e) { |
||||||
ConnectionCreator.loadClass(dbDriver); |
e.printStackTrace(); |
||||||
try { |
throw new RemoteException("Couldn't connect to DB" + e.toString()); |
||||||
con = ConnectionCreator.getConnection(dbURL, userid, passwd); |
} |
||||||
stmt = con.createStatement(); |
} |
||||||
} catch (Exception e) { |
public DbResponse execute(String sql) throws RemoteException { |
||||||
e.printStackTrace(); |
DbResponse result = new DbResponse(null, true, null); |
||||||
throw new RemoteException("Couldn't connect to DB" + e.toString()); |
try { |
||||||
} |
updateRowCount = stmt.executeUpdate(sql); |
||||||
} |
result.setUpdatedRowsCount(updateRowCount); |
||||||
|
result.setOK(true); |
||||||
@Override |
} catch (SQLException e) { |
||||||
public DbResponse execute(String sql) throws RemoteException { |
e.printStackTrace(); |
||||||
DbResponse result = new DbResponse(null, true, null); |
result.setOK(false); |
||||||
try { |
result.setException(e); |
||||||
updateRowCount = stmt.executeUpdate(sql); |
} |
||||||
result.setUpdatedRowsCount(updateRowCount); |
return result; |
||||||
result.setOK(true); |
} |
||||||
} catch (SQLException e) { |
|
||||||
e.printStackTrace(); |
/* (non-Javadoc) |
||||||
result.setOK(false); |
* @see de.mbisping.db.DbServerI#execute(de.mbisping.db.DbRequest) |
||||||
result.setException(e); |
*/ |
||||||
} |
public DbResponse execute(DbRequest dbRequest) throws RemoteException { |
||||||
return result; |
DbResponse result = new DbResponse(null, true, null); |
||||||
} |
if (dbRequest.getSql() != null) |
||||||
|
result = execute(dbRequest.getSql()); |
||||||
/* (non-Javadoc) |
|
||||||
* @see de.mbisping.db.DbServerI#execute(de.mbisping.db.DbRequest) |
return result; |
||||||
*/ |
} |
||||||
@Override |
|
||||||
public DbResponse execute(DbRequest dbRequest) throws RemoteException { |
public DbResponse executeQuery(String sql) throws RemoteException { |
||||||
DbResponse result = new DbResponse(null, true, null); |
DbResponse result = new DbResponse(null, true, null); |
||||||
if (dbRequest.getSql() != null) result = execute(dbRequest.getSql()); |
try { |
||||||
|
ResultSet rs=stmt.executeQuery(sql); |
||||||
return result; |
List list=DbUtils.toResultList(rs); |
||||||
} |
result.setResult(list); |
||||||
|
result.setOK(true); |
||||||
@Override |
} catch (SQLException e) { |
||||||
public DbResponse executeQuery(String sql) throws RemoteException { |
e.printStackTrace(); |
||||||
DbResponse result = new DbResponse(null, true, null); |
result.setOK(false); |
||||||
try { |
result.setException(e); |
||||||
ResultSet rs = stmt.executeQuery(sql); |
} |
||||||
List list = DbUtils.toResultList(rs); |
return result; |
||||||
result.setResult(list); |
} |
||||||
result.setOK(true); |
/* (non-Javadoc) |
||||||
} catch (SQLException e) { |
* @see de.mbisping.db.DbServerI#executeQuery(de.mbisping.db.DbRequest) |
||||||
e.printStackTrace(); |
*/ |
||||||
result.setOK(false); |
public DbResponse executeQuery(DbRequest dbRequest) |
||||||
result.setException(e); |
throws RemoteException { |
||||||
} |
DbResponse result = new DbResponse(null, true, null); |
||||||
return result; |
result.setUpdatedRowsCount(20); |
||||||
} |
return result; |
||||||
|
} |
||||||
/* (non-Javadoc) |
|
||||||
* @see de.mbisping.db.DbServerI#executeQuery(de.mbisping.db.DbRequest) |
public static void main(String args[]) { |
||||||
*/ |
|
||||||
@Override |
// Create and install a security manager
|
||||||
public DbResponse executeQuery(DbRequest dbRequest) throws RemoteException { |
if (System.getSecurityManager() == null) { |
||||||
DbResponse result = new DbResponse(null, true, null); |
System.setSecurityManager(new RMISecurityManager()); |
||||||
result.setUpdatedRowsCount(20); |
} |
||||||
return result; |
|
||||||
} |
try { |
||||||
|
|
||||||
public static void main(String args[]) { |
DbServerImpl obj = new DbServerImpl(); |
||||||
|
//String name="//localhost/DbServer";
|
||||||
// Create and install a security manager
|
String name = "DbServer"; |
||||||
if (System.getSecurityManager() == null) { |
// Bind this object instance to the name "HelloServer"
|
||||||
System.setSecurityManager(new RMISecurityManager()); |
Naming.rebind(name, obj); |
||||||
} |
|
||||||
|
System.out.println(name + " bound in registry"); |
||||||
try { |
} catch (Exception e) { |
||||||
|
System.out.println("DbServerImpl err: " + e.getMessage()); |
||||||
DbServerImpl obj = new DbServerImpl(); |
e.printStackTrace(); |
||||||
//String name="//localhost/DbServer";
|
} |
||||||
String name = "DbServer"; |
} |
||||||
// Bind this object instance to the name "HelloServer"
|
|
||||||
Naming.rebind(name, obj); |
} |
||||||
|
|
||||||
System.out.println(name + " bound in registry"); |
|
||||||
} catch (Exception e) { |
|
||||||
System.out.println("DbServerImpl err: " + e.getMessage()); |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,99 +1,177 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.DriverManager; |
import java.sql.Connection; |
||||||
import java.sql.ResultSet; |
import java.sql.DriverManager; |
||||||
import java.sql.ResultSetMetaData; |
import java.sql.PreparedStatement; |
||||||
import java.sql.SQLException; |
import java.sql.ResultSet; |
||||||
import java.util.Iterator; |
import java.sql.ResultSetMetaData; |
||||||
import java.util.LinkedList; |
import java.sql.SQLException; |
||||||
import java.util.List; |
import java.sql.Statement; |
||||||
|
import java.util.Iterator; |
||||||
/** |
import java.util.LinkedList; |
||||||
* @author MB |
import java.util.List; |
||||||
*/ |
|
||||||
public class DbUtils { |
/** |
||||||
|
* @author MB |
||||||
/** |
*/ |
||||||
* |
public class DbUtils { |
||||||
*/ |
|
||||||
private DbUtils() { |
/** |
||||||
} |
* |
||||||
|
*/ |
||||||
/* private Vector toResultVector(ResultSet rs) throws SQLException |
private DbUtils() { |
||||||
{ |
} |
||||||
Vector help = new Vector(); |
|
||||||
ResultSetMetaData rsmd = rs.getMetaData(); |
/* |
||||||
int numberOfColumns = rsmd.getColumnCount(); |
* private Vector toResultVector(ResultSet rs) throws SQLException { Vector help |
||||||
|
* = new Vector(); ResultSetMetaData rsmd = rs.getMetaData(); int |
||||||
Vector row = null; |
* numberOfColumns = rsmd.getColumnCount(); |
||||||
while (rs.next()) { |
* |
||||||
row = new Vector(); |
* Vector row = null; while (rs.next()) { row = new Vector(); for (int i = 1; i |
||||||
for (int i = 1; i <= numberOfColumns; i++) { |
* <= numberOfColumns; i++) { row.add(rs.getObject(i)); } help.add(row); } |
||||||
row.add(rs.getObject(i)); |
* rs.close(); return help; |
||||||
} |
* |
||||||
help.add(row); |
* } |
||||||
} |
*/ |
||||||
rs.close(); |
public static List toResultList(ResultSet rs) throws SQLException { |
||||||
return help; |
List help = new LinkedList(); |
||||||
|
ResultSetMetaData rsmd = rs.getMetaData(); |
||||||
}*/ |
int numberOfColumns = rsmd.getColumnCount(); |
||||||
public static List toResultList(ResultSet rs) throws SQLException { |
|
||||||
List help = new LinkedList(); |
List row = null; |
||||||
ResultSetMetaData rsmd = rs.getMetaData(); |
while (rs.next()) { |
||||||
int numberOfColumns = rsmd.getColumnCount(); |
row = new LinkedList(); |
||||||
|
for (int i = 1; i <= numberOfColumns; i++) { |
||||||
List row = null; |
row.add(rs.getObject(i)); |
||||||
while (rs.next()) { |
} |
||||||
row = new LinkedList(); |
help.add(row); |
||||||
for (int i = 1; i <= numberOfColumns; i++) { |
} |
||||||
row.add(rs.getObject(i)); |
rs.close(); |
||||||
} |
return help; |
||||||
help.add(row); |
} |
||||||
} |
|
||||||
rs.close(); |
public static void grantRightToAllTables() { |
||||||
return help; |
String url = "jdbc:hsqldb:hsql://localhost:9999"; |
||||||
} |
String user = ""; |
||||||
|
String right = "select"; |
||||||
public static void grantRightToAllTables() throws SQLException { |
try { |
||||||
String url = "jdbc:hsqldb:hsql://localhost:9999"; |
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
String user = ""; |
} catch (ClassNotFoundException e) { |
||||||
String right = "select"; |
e.printStackTrace(); |
||||||
try { |
} |
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
|
||||||
} catch (ClassNotFoundException e) { |
try { |
||||||
e.printStackTrace(); |
DBAccess.addConnection("dbConn", DriverManager.getConnection(url, "admin", "hatschi3000")); |
||||||
} |
} catch (SQLException e1) { |
||||||
|
e1.printStackTrace(); |
||||||
try { |
} catch (Exception e1) { |
||||||
DBAccess.addConnection("dbConn", DriverManager.getConnection(url, "admin", "hatschi3000")); |
e1.printStackTrace(); |
||||||
} catch (SQLException e1) { |
} |
||||||
e1.printStackTrace(); |
List tablist = DBAccess.get("dbConn").getTableList(); |
||||||
} catch (Exception e1) { |
StringBuffer buf = new StringBuffer(); |
||||||
e1.printStackTrace(); |
for (Iterator it = tablist.iterator(); it.hasNext();) { |
||||||
} |
String tabname = (String) it.next(); |
||||||
List tablist = DBAccess.get("dbConn").getTableList(); |
buf.append("grant " + right + " on " + tabname + " to " + user + ";"); |
||||||
StringBuffer buf = new StringBuffer(); |
|
||||||
for (Iterator it = tablist.iterator(); it.hasNext();) { |
} |
||||||
String tabname = (String) it.next(); |
DBAccess.get("dbConn").execute(buf.toString()); |
||||||
buf.append("grant " + right + " on " + tabname + " to " + user + ";"); |
|
||||||
|
DBAccess.closeConnection("dbConn"); |
||||||
} |
|
||||||
DBAccess.get("dbConn").execute(buf.toString()); |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Places Object in inverted single commas if it isn't null |
||||||
DBAccess.closeConnection("dbConn"); |
* |
||||||
|
* @param val |
||||||
} |
* @return either "null" if val is null or "'val'" |
||||||
|
*/ |
||||||
/** |
public static String placeInInvertedCommas(Object val) { |
||||||
* Places Object in inverted single commas if it isn't null |
if (val == null) |
||||||
* @param val |
return "null"; |
||||||
* @return either "null" if val is null or "'val'" |
return "'" + val + "'"; |
||||||
*/ |
} |
||||||
public static String placeInInvertedCommas(Object val) { |
|
||||||
if (val == null) return "null"; |
|
||||||
return "'" + val + "'"; |
public static int getInt(Statement stm, String query) throws SQLException { |
||||||
} |
int result = -1; |
||||||
} |
ResultSet rs = stm.executeQuery(query); |
||||||
|
while (rs.next()) { |
||||||
|
result = rs.getInt(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
public static String getString(Statement stm, String query) throws SQLException { |
||||||
|
String result = null; |
||||||
|
ResultSet rs = stm.executeQuery(query); |
||||||
|
while (rs.next()) { |
||||||
|
result = rs.getString(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
/** |
||||||
|
* |
||||||
|
* @param query |
||||||
|
* @return -1 wenn nichts gefunden |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
public static int getInt(Connection con, String query,int param) throws SQLException { |
||||||
|
int result = -1; |
||||||
|
PreparedStatement pst=con.prepareStatement(query); |
||||||
|
pst.setInt(1, param); |
||||||
|
ResultSet rs = pst.executeQuery(); |
||||||
|
while (rs.next()) { |
||||||
|
result = rs.getInt(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
pst.close(); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param query |
||||||
|
* @return -1 wenn nichts gefunden |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
public static int getInt(Connection con, String query,String param) throws SQLException { |
||||||
|
int result = -1; |
||||||
|
PreparedStatement pst=con.prepareStatement(query); |
||||||
|
pst.setString(1, param); |
||||||
|
ResultSet rs = pst.executeQuery(); |
||||||
|
while (rs.next()) { |
||||||
|
result = rs.getInt(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
pst.close(); |
||||||
|
return result; |
||||||
|
} |
||||||
|
/** |
||||||
|
* |
||||||
|
* @param con |
||||||
|
* @param query |
||||||
|
* @param param |
||||||
|
* @return null if nothing found |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
public static String getString(Connection con,String query,String param) throws SQLException |
||||||
|
{ |
||||||
|
String result=null; |
||||||
|
PreparedStatement pst=con.prepareStatement(query); |
||||||
|
pst.setString(1, param); |
||||||
|
ResultSet rs = pst.executeQuery(); |
||||||
|
while (rs.next()) { |
||||||
|
result = rs.getString(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
pst.close(); |
||||||
|
return result; |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
//Created on 21.06.2003
|
//Created on 21.06.2003
|
||||||
@ -1,69 +1,123 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change this generated comment edit the template variable "typecomment": |
* To change this generated comment edit the template variable "typecomment": |
||||||
* Window>Preferences>Java>Templates. |
* Window>Preferences>Java>Templates. |
||||||
* To enable and disable the creation of type comments go to |
* To enable and disable the creation of type comments go to |
||||||
* Window>Preferences>Java>Code Generation. |
* Window>Preferences>Java>Code Generation. |
||||||
*/ |
*/ |
||||||
public class HsqlProcedures { |
public class HsqlProcedures { |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for HsqlProcedures. |
* Constructor for HsqlProcedures. |
||||||
*/ |
*/ |
||||||
private HsqlProcedures() { |
private HsqlProcedures() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
|
|
||||||
public static Integer get1() { |
public static Integer get1() |
||||||
return Integer.valueOf(1); |
{ |
||||||
|
return new Integer(1); |
||||||
} |
|
||||||
|
} |
||||||
public static void alterTableColumnIntegerToVarchar(java.sql.Connection con, String tablename, String columnname) { |
public static void alterTableColumnIntegerToVarchar( |
||||||
try { |
java.sql.Connection con, |
||||||
Statement stmt = con.createStatement(); |
String tablename, |
||||||
// add new tmp varchar col
|
String columnname) { |
||||||
stmt.execute("alter table " + tablename + " add column tmp" + columnname + " varchar"); |
try { |
||||||
//update value of tmp
|
Statement stmt = con.createStatement(); |
||||||
stmt.execute("update " + tablename + " set tmp" + columnname + "= " + columnname); |
// add new tmp varchar col
|
||||||
//drop original
|
stmt.execute( |
||||||
stmt.execute("alter table " + tablename + " drop column " + columnname); |
"alter table " |
||||||
//add col with original name and of varchar type
|
+ tablename |
||||||
stmt.execute("alter table " + tablename + " add column " + columnname + " varchar"); |
+ " add column tmp" |
||||||
//update values
|
+ columnname |
||||||
stmt.execute("update " + tablename + " set " + columnname + "= tmp" + columnname); |
+ " varchar"); |
||||||
//drop tmp
|
//update value of tmp
|
||||||
stmt.execute("alter table " + tablename + " drop column tmp" + columnname); |
stmt.execute( |
||||||
} catch (Exception e) { |
"update " |
||||||
e.printStackTrace(); |
+ tablename |
||||||
} |
+ " set tmp" |
||||||
|
+ columnname |
||||||
} |
+ "= " |
||||||
|
+ columnname); |
||||||
public static void alterTableColumnVarcharToInteger(java.sql.Connection con, String tablename, String columnname) { |
//drop original
|
||||||
try { |
stmt.execute( |
||||||
Statement stmt = con.createStatement(); |
"alter table " + tablename + " drop column " + columnname); |
||||||
// add new tmp varchar col
|
//add col with original name and of varchar type
|
||||||
stmt.execute("alter table " + tablename + " add column tmp" + columnname + " integer"); |
stmt.execute( |
||||||
//update value of tmp
|
"alter table " |
||||||
stmt.execute("update " + tablename + " set tmp" + columnname + "= " + columnname); |
+ tablename |
||||||
//drop original
|
+ " add column " |
||||||
stmt.execute("alter table " + tablename + " drop column " + columnname); |
+ columnname |
||||||
//add col with original name and of varchar type
|
+ " varchar"); |
||||||
stmt.execute("alter table " + tablename + " add column " + columnname + " integer"); |
//update values
|
||||||
//update values
|
stmt.execute( |
||||||
stmt.execute("update " + tablename + " set " + columnname + "= tmp" + columnname); |
"update " |
||||||
//drop tmp
|
+ tablename |
||||||
stmt.execute("alter table " + tablename + " drop column tmp" + columnname); |
+ " set " |
||||||
} catch (Exception e) { |
+ columnname |
||||||
e.printStackTrace(); |
+ "= tmp" |
||||||
} |
+ columnname); |
||||||
|
//drop tmp
|
||||||
} |
stmt.execute( |
||||||
|
"alter table " + tablename + " drop column tmp" + columnname); |
||||||
} |
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public static void alterTableColumnVarcharToInteger( |
||||||
|
java.sql.Connection con, |
||||||
|
String tablename, |
||||||
|
String columnname) { |
||||||
|
try { |
||||||
|
Statement stmt = con.createStatement(); |
||||||
|
// add new tmp varchar col
|
||||||
|
stmt.execute( |
||||||
|
"alter table " |
||||||
|
+ tablename |
||||||
|
+ " add column tmp" |
||||||
|
+ columnname |
||||||
|
+ " integer"); |
||||||
|
//update value of tmp
|
||||||
|
stmt.execute( |
||||||
|
"update " |
||||||
|
+ tablename |
||||||
|
+ " set tmp" |
||||||
|
+ columnname |
||||||
|
+ "= " |
||||||
|
+ columnname); |
||||||
|
//drop original
|
||||||
|
stmt.execute( |
||||||
|
"alter table " + tablename + " drop column " + columnname); |
||||||
|
//add col with original name and of varchar type
|
||||||
|
stmt.execute( |
||||||
|
"alter table " |
||||||
|
+ tablename |
||||||
|
+ " add column " |
||||||
|
+ columnname |
||||||
|
+ " integer"); |
||||||
|
//update values
|
||||||
|
stmt.execute( |
||||||
|
"update " |
||||||
|
+ tablename |
||||||
|
+ " set " |
||||||
|
+ columnname |
||||||
|
+ "= tmp" |
||||||
|
+ columnname); |
||||||
|
//drop tmp
|
||||||
|
stmt.execute( |
||||||
|
"alter table " + tablename + " drop column tmp" + columnname); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,381 +1,422 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.awt.Component; |
import java.awt.Component; |
||||||
import java.io.BufferedInputStream; |
import java.io.BufferedInputStream; |
||||||
import java.io.BufferedOutputStream; |
import java.io.BufferedOutputStream; |
||||||
import java.io.File; |
import java.io.File; |
||||||
import java.io.FileInputStream; |
import java.io.FileInputStream; |
||||||
import java.io.FileOutputStream; |
import java.io.FileOutputStream; |
||||||
import java.io.FilenameFilter; |
import java.io.FilenameFilter; |
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
import java.util.Properties; |
import java.util.Properties; |
||||||
import java.util.ResourceBundle; |
import java.util.ResourceBundle; |
||||||
|
|
||||||
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
||||||
|
|
||||||
/** |
/** |
||||||
* A class which helps managing multiple connections to a stand-alone database |
* A class which helps managing multiple connections to a stand-alone database |
||||||
* (e.g. on a network path). After one user has opened the database other users |
* (e.g. on a network path). After one user has opened the database other users |
||||||
* can get the option to open a temporary copy of the database. The temporary |
* can get the option to open a temporary copy of the database. The temporary |
||||||
* copy may be read-only, but doesn't has to be. If it's not read-only all, all |
* copy may be read-only, but doesn't has to be. If it's not read-only all, all |
||||||
* changes will be discarded when the connection is closed. (May be useful if |
* changes will be discarded when the connection is closed. (May be useful if |
||||||
* the application only does some dispensible logging or so). see |
* the application only does some dispensible logging or so). see |
||||||
* SampleApplication |
* SampleApplication |
||||||
*/ |
*/ |
||||||
public class HsqlStandaloneMgr { |
public class HsqlStandaloneMgr { |
||||||
private static AbstractHsqlStandaloneMgrResources resources; |
private static AbstractHsqlStandaloneMgrResources resources; |
||||||
|
|
||||||
private HsqlStandaloneMgr() { |
private HsqlStandaloneMgr() { |
||||||
} |
} |
||||||
|
|
||||||
private static void initResources() { |
private static void initResources() { |
||||||
String mypackage = ""; |
String mypackage = ""; |
||||||
//if you place the Resources classes in some package, define it like this
|
//if you place the Resources classes in some package, define it like this
|
||||||
mypackage = "de.memtext.db."; |
mypackage="de.memtext.db."; |
||||||
resources = (AbstractHsqlStandaloneMgrResources) ResourceBundle.getBundle(mypackage + "HsqlStandaloneMgrResources"); |
resources = (AbstractHsqlStandaloneMgrResources) ResourceBundle |
||||||
} |
.getBundle(mypackage + "HsqlStandaloneMgrResources"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Checks if a database is already opened (by checking if a .lck file |
/** |
||||||
* exists) Use from HSQLDB 1.7.2 or higher |
* Checks if a database is already opened (by checking if a .lck file |
||||||
* |
* exists) Use from HSQLDB 1.7.2 or higher |
||||||
* @param String |
* |
||||||
* path - null,"" or "." for current directory |
* @param String |
||||||
* @param String |
* path - null,"" or "." for current directory |
||||||
* databasename |
* @param String |
||||||
* @return true if database is already opened |
* databasename |
||||||
*/ |
* @return true if database is already opened |
||||||
public static boolean isDatabaseOpen(String path, String databasename) { |
*/ |
||||||
File lckFile = new File(getAdaptedPath(path) + databasename + ".lck"); |
public static boolean isDatabaseOpen(String path, String databasename) { |
||||||
return lckFile.exists(); |
File lckFile = new File(getAdaptedPath(path)+databasename+".lck"); |
||||||
} |
return lckFile.exists(); |
||||||
|
} |
||||||
/** |
|
||||||
* Deletes any temporary files which the HsqlStandaloneMgr may have created |
/** |
||||||
* for the given url |
* Deletes any temporary files which the HsqlStandaloneMgr may have created |
||||||
* |
* for the given url |
||||||
* @param String |
* |
||||||
* url |
* @param String |
||||||
* @param String |
* url |
||||||
* path - null,"" or "." for current dir |
* @param String |
||||||
* @param String |
* path - null,"" or "." for current dir |
||||||
* databasename - of the original database, no _TMP_COPY appendix |
* @param String |
||||||
*/ |
* databasename - of the original database, no _TMP_COPY appendix |
||||||
public static void deleteTmpFiles(String url, String path, String databasename) { |
*/ |
||||||
if (databasename.indexOf("_TMP_COPY") > -1) throw new IllegalArgumentException("Please specifiy the name of the original database without _TMP_COPY"); |
public static void deleteTmpFiles(String url, String path, |
||||||
path = getAdaptedPath(path); |
String databasename) { |
||||||
|
if (databasename.indexOf("_TMP_COPY") > -1) |
||||||
int tmpPos = url.indexOf("_TMP_COPY"); |
throw new IllegalArgumentException( |
||||||
if (tmpPos == -1) { |
"Please specifiy the name of the original database without _TMP_COPY"); |
||||||
//if the main connection is closed delete info about the user
|
path=getAdaptedPath(path); |
||||||
File f = new File(path + databasename + "_user.properties"); |
|
||||||
if (f.exists()) f.delete(); |
int tmpPos = url.indexOf("_TMP_COPY"); |
||||||
} else { |
if (tmpPos == -1) { |
||||||
//delete files for temp. connection
|
//if the main connection is closed delete info about the user
|
||||||
String tmp = url.substring(tmpPos); |
File f = new File(path + databasename + "_user.properties"); |
||||||
if (path == null || path.equals("")) path = "."; |
if (f.exists()) |
||||||
File fpath = new File(path); |
f.delete(); |
||||||
File tmpFiles[] = fpath.listFiles(new TmpFileFilter(databasename + tmp)); |
} else { |
||||||
for (int i = 0; i < tmpFiles.length; i++) { |
//delete files for temp. connection
|
||||||
tmpFiles[i].delete(); |
String tmp = url.substring(tmpPos); |
||||||
} |
if (path==null||path.equals("")) path="."; |
||||||
} |
File fpath = new File(path); |
||||||
|
File tmpFiles[] = fpath.listFiles(new TmpFileFilter(databasename |
||||||
} |
+ tmp)); |
||||||
|
for (int i = 0; i < tmpFiles.length; i++) { |
||||||
/** |
tmpFiles[i].delete(); |
||||||
* Asks the user if he/she wants to open a temporary copy of the database or |
} |
||||||
* not. A boolean indicates if the questions concerns read-only mode or not. |
} |
||||||
* |
|
||||||
* @param Component |
} |
||||||
* parentComponent - usually the application Frame, but may be |
|
||||||
* null |
/** |
||||||
* @param String |
* Asks the user if he/she wants to open a temporary copy of the database or |
||||||
* databasename - name of original database |
* not. A boolean indicates if the questions concerns read-only mode or not. |
||||||
* @param boolean |
* |
||||||
* isReadOnlyCopyWanted - should the temp. copy be read-only |
* @param Component |
||||||
* @return int from JOptionPane.showConfirmDialog |
* parentComponent - usually the application Frame, but may be |
||||||
*/ |
* null |
||||||
public static int askUser(Component parentComponent, String path, |
* @param String |
||||||
|
* databasename - name of original database |
||||||
String databasename, boolean isReadOnlyCopyWanted) { |
* @param boolean |
||||||
if (resources == null) initResources(); |
* isReadOnlyCopyWanted - should the temp. copy be read-only |
||||||
|
* @return int from JOptionPane.showConfirmDialog |
||||||
String username = null; |
*/ |
||||||
File f = new File(getAdaptedPath(path) + databasename + "_user.properties"); |
public static int askUser(Component parentComponent, String path, |
||||||
if (f.exists()) { |
|
||||||
Properties p = new Properties(); |
String databasename, boolean isReadOnlyCopyWanted) { |
||||||
FileInputStream fis; |
if (resources == null) |
||||||
try { |
initResources(); |
||||||
fis = new FileInputStream(f); |
|
||||||
p.load(fis); |
String username = null; |
||||||
username = p.getProperty("user"); |
File f = new File(getAdaptedPath(path) + databasename + "_user.properties"); |
||||||
fis.close(); |
if (f.exists()) { |
||||||
} catch (Exception e) { |
Properties p = new Properties(); |
||||||
System.err.println(resources.getString("Couldn't read user name")); |
FileInputStream fis; |
||||||
e.printStackTrace(); |
try { |
||||||
} |
fis = new FileInputStream(f); |
||||||
|
p.load(fis); |
||||||
} |
username = p.getProperty("user"); |
||||||
StringBuffer msg = new StringBuffer(resources.getDbInUseBy(databasename, username)); |
fis.close(); |
||||||
|
} catch (Exception e) { |
||||||
if (isReadOnlyCopyWanted) |
System.err.println(resources |
||||||
msg.append(resources.getString("Would you like to open a temporary copy in read-only mode?")); |
.getString("Couldn't read user name")); |
||||||
else |
e.printStackTrace(); |
||||||
msg.append(resources.getString("Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!")); |
} |
||||||
return JOptionPane.showConfirmDialog(parentComponent, msg, "HSQLDB", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
|
||||||
|
} |
||||||
} |
StringBuffer msg = new StringBuffer(resources.getDbInUseBy( |
||||||
|
databasename, username)); |
||||||
/** |
|
||||||
* Returns a connection to a temporary copy of a database either in |
if (isReadOnlyCopyWanted) |
||||||
* read-only mode or not. |
msg |
||||||
* |
.append(resources |
||||||
* @param Component |
.getString("Would you like to open a temporary copy in read-only mode?")); |
||||||
* parentComponent - usually the application Frame, but may be |
else |
||||||
* null |
msg |
||||||
* @param String |
.append(resources |
||||||
* path - null,"" or "." for current dir |
.getString("Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!")); |
||||||
* @param String |
return JOptionPane.showConfirmDialog(parentComponent, msg, "HSQLDB", |
||||||
* databasename |
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
||||||
* @param String |
|
||||||
* username |
} |
||||||
* @param String |
|
||||||
* password |
/** |
||||||
* @param boolean |
* Returns a connection to a temporary copy of a database either in |
||||||
* isReadOnlyCopyWanted - should the temporary copy of the |
* read-only mode or not. |
||||||
* database be in read-only mode |
* |
||||||
* @return Connection to the temporary copy of the database |
* @param Component |
||||||
* @throws ClassNotFoundException |
* parentComponent - usually the application Frame, but may be |
||||||
* @throws SQLException |
* null |
||||||
* @throws IOException |
* @param String |
||||||
*/ |
* path - null,"" or "." for current dir |
||||||
public static Connection getTmpConnection(Component parentComponent, String path, String databasename, String username, String password, boolean isReadOnlyCopyWanted) |
* @param String |
||||||
throws ClassNotFoundException, SQLException, IOException { |
* databasename |
||||||
if (resources == null) initResources(); |
* @param String |
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
* username |
||||||
path = getAdaptedPath(path); |
* @param String |
||||||
|
* password |
||||||
int tmpInstanceNumber = checkNumber(path, databasename); |
* @param boolean |
||||||
|
* isReadOnlyCopyWanted - should the temporary copy of the |
||||||
try { |
* database be in read-only mode |
||||||
copyDatabaseFiles(path, databasename, tmpInstanceNumber); |
* @return Connection to the temporary copy of the database |
||||||
} catch (IOException e) { |
* @throws ClassNotFoundException |
||||||
JOptionPane.showMessageDialog(parentComponent, resources.getString("Could not create temporary copy of database.)") + "\n" + e, "HSQLDB", JOptionPane.WARNING_MESSAGE); |
* @throws SQLException |
||||||
throw e; |
* @throws IOException |
||||||
} |
*/ |
||||||
|
public static Connection getTmpConnection(Component parentComponent, |
||||||
if (isReadOnlyCopyWanted) { |
String path, String databasename, String username, String password, |
||||||
try { |
boolean isReadOnlyCopyWanted) throws ClassNotFoundException, |
||||||
setReadonly(path + databasename + "_TMP_COPY" + tmpInstanceNumber + ".properties"); |
SQLException, IOException { |
||||||
} catch (IOException e) { |
if (resources == null) |
||||||
JOptionPane.showMessageDialog(parentComponent, resources.getString("Could not set temporary copy of database to readonly mode.") + "\n" + e, "HSQLDB", |
initResources(); |
||||||
JOptionPane.WARNING_MESSAGE); |
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
throw e; |
path = getAdaptedPath(path); |
||||||
} |
|
||||||
} |
int tmpInstanceNumber = checkNumber(path, databasename); |
||||||
String url = "jdbc:hsqldb:file:" + path + databasename + "_TMP_COPY" + tmpInstanceNumber; |
|
||||||
|
try { |
||||||
Connection con = java.sql.DriverManager.getConnection(url, username, password); |
copyDatabaseFiles(path, databasename, tmpInstanceNumber); |
||||||
|
} catch (IOException e) { |
||||||
if (!isReadOnlyCopyWanted) { |
JOptionPane.showMessageDialog(parentComponent, resources |
||||||
Statement stmt = con.createStatement(); |
.getString("Could not create temporary copy of database.)") |
||||||
ResultSet rs = stmt.executeQuery("select count(*) from system_tables where hsqldb_type='TEXT'"); |
+ "\n" + e, "HSQLDB", JOptionPane.WARNING_MESSAGE); |
||||||
rs.next(); |
throw e; |
||||||
if (rs.getInt(1) > 0) { |
} |
||||||
stmt.execute("shutdown"); |
|
||||||
stmt.close(); |
if (isReadOnlyCopyWanted) { |
||||||
con.close(); |
try { |
||||||
deleteTmpFiles(url, path, databasename); |
setReadonly(path + databasename + "_TMP_COPY" |
||||||
throw new SQLException(resources.getString("Handling non read-only temporary database with text tables is not supported")); |
+ tmpInstanceNumber + ".properties"); |
||||||
} |
} catch (IOException e) { |
||||||
rs.close(); |
JOptionPane |
||||||
stmt.close(); |
.showMessageDialog( |
||||||
} |
parentComponent, |
||||||
return con; |
resources |
||||||
} |
.getString("Could not set temporary copy of database to readonly mode.") |
||||||
|
+ "\n" + e, "HSQLDB", |
||||||
private static int checkNumber(String path, String databasename) { |
JOptionPane.WARNING_MESSAGE); |
||||||
int result = 1; |
throw e; |
||||||
while (new File(path + databasename + "_TMP_COPY" + result + ".script").exists()) |
} |
||||||
result++; |
} |
||||||
return result; |
String url = "jdbc:hsqldb:file:" + path + databasename |
||||||
} |
+ "_TMP_COPY" + tmpInstanceNumber; |
||||||
|
|
||||||
/** |
Connection con = java.sql.DriverManager.getConnection(url, username, |
||||||
* Returns a regular connection to a database and creates a file |
password); |
||||||
* database_user.properties with the name of the user that opens the |
|
||||||
* database |
if (!isReadOnlyCopyWanted) { |
||||||
* |
Statement stmt = con.createStatement(); |
||||||
* @param String |
ResultSet rs = stmt |
||||||
* path - null,"" or "." for current dir |
.executeQuery("select count(*) from system_tables where hsqldb_type='TEXT'"); |
||||||
* @param String |
rs.next(); |
||||||
* databasename |
if (rs.getInt(1) > 0) { |
||||||
* @param String |
stmt.execute("shutdown"); |
||||||
* username |
stmt.close(); |
||||||
* @param String |
con.close(); |
||||||
* password |
deleteTmpFiles(url, path, databasename); |
||||||
* @return Connection to the database |
throw new SQLException( |
||||||
* @throws ClassNotFoundException |
resources |
||||||
* @throws SQLException |
.getString("Handling non read-only temporary database with text tables is not supported")); |
||||||
* @throws IOException |
} |
||||||
*/ |
rs.close(); |
||||||
public static Connection getConnection(String path, String databasename, String username, String password) throws ClassNotFoundException, SQLException, IOException { |
stmt.close(); |
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
} |
||||||
String url = null; |
return con; |
||||||
if (path == null) |
} |
||||||
url = "jdbc:hsqldb:" + databasename; |
|
||||||
else |
private static int checkNumber(String path, String databasename) { |
||||||
url = "jdbc:hsqldb:file:" + getAdaptedPath(path) + databasename; |
int result = 1; |
||||||
|
while (new File(path + databasename + "_TMP_COPY" + result |
||||||
Connection con = java.sql.DriverManager.getConnection(url, username, password); |
+ ".script").exists()) |
||||||
|
result++; |
||||||
Properties p = new Properties(); |
return result; |
||||||
p.put("user", System.getProperty("user.name")); |
} |
||||||
String filename = (path != null ? path + "/" + databasename + "_user.properties" : databasename + "_user.properties"); |
|
||||||
FileOutputStream fos = new FileOutputStream(filename); |
/** |
||||||
p.store(fos, "User which uses the HSQL database"); |
* Returns a regular connection to a database and creates a file |
||||||
fos.close(); |
* database_user.properties with the name of the user that opens the |
||||||
|
* database |
||||||
return con; |
* |
||||||
} |
* @param String |
||||||
|
* path - null,"" or "." for current dir |
||||||
/** |
* @param String |
||||||
* String and makes sure separator char is at the end |
* databasename |
||||||
* |
* @param String |
||||||
* @param String |
* username |
||||||
* path |
* @param String |
||||||
* @return adapted path String |
* password |
||||||
*/ |
* @return Connection to the database |
||||||
private static String getAdaptedPath(String path) { |
* @throws ClassNotFoundException |
||||||
if (path == null) path = ""; |
* @throws SQLException |
||||||
if ((path.equals(".") || path.length() > 1) && !(path.endsWith("/") || path.endsWith("\\"))) path += File.separator; |
* @throws IOException |
||||||
|
*/ |
||||||
return path; |
public static Connection getConnection(String path, String databasename, |
||||||
} |
String username, String password) throws ClassNotFoundException, |
||||||
|
SQLException, IOException { |
||||||
/** |
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
* Changes the property readonly to true in a database properties file |
String url=null; |
||||||
* |
if (path==null) |
||||||
* @param String |
url="jdbc:hsqldb:"+databasename; |
||||||
* propertiesFile including path if necessary |
else |
||||||
* @throws IOException |
url = "jdbc:hsqldb:file:" + getAdaptedPath(path) + databasename; |
||||||
*/ |
|
||||||
private static void setReadonly(String propertiesFile) throws IOException { |
Connection con = java.sql.DriverManager.getConnection(url, username, |
||||||
Properties p = new Properties(); |
password); |
||||||
p.load(new FileInputStream(propertiesFile)); |
|
||||||
p.put("readonly", "true"); |
Properties p = new Properties(); |
||||||
p.store(new FileOutputStream(propertiesFile), "HSQL database"); |
p.put("user", System.getProperty("user.name")); |
||||||
|
String filename=(path!=null?path+"/"+databasename+"_user.properties":databasename+"_user.properties"); |
||||||
} |
FileOutputStream fos = new FileOutputStream(filename); |
||||||
|
p.store(fos, "User which uses the HSQL database"); |
||||||
/** |
fos.close(); |
||||||
* Makes a temporary copy of all existing database files with the appendix |
|
||||||
* _TMP_COPY |
return con; |
||||||
* |
} |
||||||
* @param String |
|
||||||
* path - may be null for current dir, no / or \ at the end |
/** |
||||||
* @param String |
* String and makes sure separator char is at the end |
||||||
* databasename |
* |
||||||
* @throws IOException |
* @param String |
||||||
*/ |
* path |
||||||
private static void copyDatabaseFiles(String path, String databasename, int number) throws IOException { |
* @return adapted path String |
||||||
|
*/ |
||||||
String s = path + databasename; |
private static String getAdaptedPath(String path) { |
||||||
copyFile(s + ".script", s + "_TMP_COPY" + number + ".script"); |
if (path == null) path = ""; |
||||||
copyFile(s + ".properties", s + "_TMP_COPY" + number + ".properties"); |
if ((path.equals(".")||path.length()>1)&&!(path.endsWith("/")||path.endsWith("\\"))) |
||||||
if (new File(s + ".log").exists()) copyFile(s + ".log", s + "_TMP_COPY" + number + ".log"); |
path+=File.separator; |
||||||
if (new File(s + ".data").exists()) copyFile(s + ".data", s + "_TMP_COPY" + number + ".data"); |
|
||||||
if (new File(s + ".backup").exists()) copyFile(s + ".backup", s + "_TMP_COPY" + number + ".backup"); |
return path; |
||||||
if (new File(s + ".nio").exists()) copyFile(s + ".nio", s + "_TMP_COPY" + number + ".nio"); |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* Changes the property readonly to true in a database properties file |
||||||
* Creates a copy of a file |
* |
||||||
* |
* @param String |
||||||
* @param String |
* propertiesFile including path if necessary |
||||||
* source - source file name (incl. path if necessary) |
* @throws IOException |
||||||
* @param String |
*/ |
||||||
* target - target file name (incl. path if necessary) |
private static void setReadonly(String propertiesFile) throws IOException { |
||||||
* @throws IOException |
Properties p = new Properties(); |
||||||
*/ |
p.load(new FileInputStream(propertiesFile)); |
||||||
static public void copyFile(String source, String target) throws IOException { |
p.put("readonly", "true"); |
||||||
|
p.store(new FileOutputStream(propertiesFile), "HSQL database"); |
||||||
try { |
|
||||||
FileInputStream is = new FileInputStream(source); |
} |
||||||
FileOutputStream os = new FileOutputStream(target); |
|
||||||
|
/** |
||||||
BufferedInputStream in = new BufferedInputStream(is); |
* Makes a temporary copy of all existing database files with the appendix |
||||||
BufferedOutputStream out = new BufferedOutputStream(os); |
* _TMP_COPY |
||||||
|
* |
||||||
int buffer_size = 32768; |
* @param String |
||||||
byte[] buffer = new byte[buffer_size]; |
* path - may be null for current dir, no / or \ at the end |
||||||
|
* @param String |
||||||
int len = in.read(buffer, 0, buffer_size); |
* databasename |
||||||
while (len != -1) { |
* @throws IOException |
||||||
out.write(buffer, 0, len); |
*/ |
||||||
len = in.read(buffer, 0, buffer_size); |
private static void copyDatabaseFiles(String path, String databasename, |
||||||
} |
int number) throws IOException { |
||||||
in.close(); |
|
||||||
is.close(); |
String s = path + databasename; |
||||||
out.close(); |
copyFile(s + ".script", s + "_TMP_COPY" + number + ".script"); |
||||||
os.close(); |
copyFile(s + ".properties", s + "_TMP_COPY" + number + ".properties"); |
||||||
|
if (new File(s + ".log").exists()) |
||||||
} catch (IOException e) { |
copyFile(s + ".log", s + "_TMP_COPY" + number + ".log"); |
||||||
throw new IOException("Couldn't copy file " + source + ": " + e.toString()); |
if (new File(s + ".data").exists()) |
||||||
} |
copyFile(s + ".data", s + "_TMP_COPY" + number + ".data"); |
||||||
} |
if (new File(s + ".backup").exists()) |
||||||
|
copyFile(s + ".backup", s + "_TMP_COPY" + number + ".backup"); |
||||||
private static class TmpFileFilter implements FilenameFilter { |
if (new File(s + ".nio").exists()) |
||||||
private String tmpName; |
copyFile(s + ".nio", s + "_TMP_COPY" + number + ".nio"); |
||||||
|
} |
||||||
TmpFileFilter(String tmpName) { |
|
||||||
this.tmpName = tmpName; |
/** |
||||||
} |
* Creates a copy of a file |
||||||
|
* |
||||||
@Override |
* @param String |
||||||
public boolean accept(File dir, String name) { |
* source - source file name (incl. path if necessary) |
||||||
return name.indexOf(tmpName) > -1; |
* @param String |
||||||
} |
* target - target file name (incl. path if necessary) |
||||||
|
* @throws IOException |
||||||
} |
*/ |
||||||
|
static public void copyFile(String source, String target) |
||||||
} |
throws IOException { |
||||||
|
|
||||||
//Created on 21.10.2004 at 20:35:55
|
try { |
||||||
|
FileInputStream is = new FileInputStream(source); |
||||||
|
FileOutputStream os = new FileOutputStream(target); |
||||||
|
|
||||||
|
BufferedInputStream in = new BufferedInputStream(is); |
||||||
|
BufferedOutputStream out = new BufferedOutputStream(os); |
||||||
|
|
||||||
|
int buffer_size = 32768; |
||||||
|
byte[] buffer = new byte[buffer_size]; |
||||||
|
|
||||||
|
int len = in.read(buffer, 0, buffer_size); |
||||||
|
while (len != -1) { |
||||||
|
out.write(buffer, 0, len); |
||||||
|
len = in.read(buffer, 0, buffer_size); |
||||||
|
} |
||||||
|
in.close(); |
||||||
|
is.close(); |
||||||
|
out.close(); |
||||||
|
os.close(); |
||||||
|
|
||||||
|
} catch (IOException e) { |
||||||
|
throw new IOException("Couldn't copy file " + source + ": " |
||||||
|
+ e.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static class TmpFileFilter implements FilenameFilter { |
||||||
|
private String tmpName; |
||||||
|
|
||||||
|
TmpFileFilter(String tmpName) { |
||||||
|
this.tmpName = tmpName; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean accept(File dir, String name) { |
||||||
|
return name.indexOf(tmpName) > -1; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
//Created on 21.10.2004 at 20:35:55
|
||||||
|
|||||||
@ -1,66 +1,70 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
/** |
||||||
/** |
* Resources for HsqlStandaloneMgr. |
||||||
* Resources for HsqlStandaloneMgr. |
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
||||||
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
* by copying HsqlStandaloneMgrResources_de to your locale |
||||||
* by copying HsqlStandaloneMgrResources_de to your locale |
*/ |
||||||
*/ |
|
||||||
|
public class HsqlStandaloneMgrResources extends |
||||||
public class HsqlStandaloneMgrResources extends AbstractHsqlStandaloneMgrResources { |
AbstractHsqlStandaloneMgrResources { |
||||||
@Override |
public Object[][] getContents() { |
||||||
public Object[][] getContents() { |
return contents; |
||||||
return contents; |
} |
||||||
} |
|
||||||
|
static final Object[][] contents = { |
||||||
static final Object[][] contents = { |
|
||||||
|
{ "Couldn't read user name", "Couldn't read user name" }, |
||||||
{ "Couldn't read user name", "Couldn't read user name" }, |
{ "Would you like to open a temporary copy in read-only mode?", |
||||||
{ "Would you like to open a temporary copy in read-only mode?", "Would you like to open a temporary copy in read-only mode?" }, |
"Would you like to open a temporary copy in read-only mode?" }, |
||||||
{ "Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!", |
{ |
||||||
"Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!" }, |
"Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!", |
||||||
{ "Could not create temporary copy of database.", "Could not create temporary copy of database." }, |
"Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!" }, |
||||||
{ "Could not set temporary copy of database to readonly mode.", "Could not set temporary copy of database to readonly mode." }, |
{ "Could not create temporary copy of database.", |
||||||
{ "Handling non read-only temporary database with text tables is not supported", |
"Could not create temporary copy of database." }, |
||||||
"Handling non read-only temporary database with text tables is not supported" } |
{ "Could not set temporary copy of database to readonly mode.", |
||||||
|
"Could not set temporary copy of database to readonly mode." }, |
||||||
}; |
{ |
||||||
|
"Handling non read-only temporary database with text tables is not supported", |
||||||
@Override |
"Handling non read-only temporary database with text tables is not supported" } |
||||||
public String getDbInUseBy(String dbname, String user) { |
|
||||||
String result = "The database " + dbname + " is already in use"; |
}; |
||||||
if (user != null) result += " by user " + user; |
|
||||||
result += ".\n"; |
public String getDbInUseBy(String dbname, String user) { |
||||||
return result; |
String result = "The database " + dbname + " is already in use"; |
||||||
} |
if (user != null) |
||||||
} |
result += " by user " + user; |
||||||
|
result += ".\n"; |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|||||||
@ -1,63 +1,68 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
/** |
||||||
/** |
* Resources for HsqlStandaloneMgr. |
||||||
* Resources for HsqlStandaloneMgr. |
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
||||||
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
* by copying this class to your locale |
||||||
* by copying this class to your locale |
*/ |
||||||
*/ |
public class HsqlStandaloneMgrResources_de extends |
||||||
public class HsqlStandaloneMgrResources_de extends AbstractHsqlStandaloneMgrResources { |
AbstractHsqlStandaloneMgrResources { |
||||||
@Override |
public Object[][] getContents() { |
||||||
public Object[][] getContents() { |
return contents; |
||||||
return contents; |
} |
||||||
} |
|
||||||
|
static final Object[][] contents = { |
||||||
static final Object[][] contents = { { "Couldn't read user name", "Konnte Usernamen nicht lesen" }, |
{ "Couldn't read user name", "Konnte Usernamen nicht lesen" }, |
||||||
{ "Would you like to open a temporary copy in read-only mode?", "Möchten Sie eine schreibgeschützte Kopie öffnen?" }, |
{ "Would you like to open a temporary copy in read-only mode?", |
||||||
{ "Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!", |
"Möchten Sie eine schreibgeschützte Kopie öffnen?" }, |
||||||
"Möchten Sie eine temporäre Kopie öffnen?\nAchtung, wenn Sie das Programm beenden, gehen alle Änderungen, die Sie vorgenommen haben, verloren!" }, |
{ |
||||||
{ "Could not create temporary copy of database.", "Konnte keine temporäre Kopie der Datenbank anlegen." }, |
"Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!", |
||||||
{ "Could not set temporary copy of database to readonly mode.", "Konnte die temp. Kopie nicht auf schreibgeschützt setzen" }, |
"Möchten Sie eine temporäre Kopie öffnen?\nAchtung, wenn Sie das Programm beenden, gehen alle Änderungen, die Sie vorgenommen haben, verloren!" }, |
||||||
{ "Handling non read-only temporary database with text tables is not supported", |
{ "Could not create temporary copy of database.", |
||||||
"Nicht schreibgeschützte Datenbanken mit Text-Tables werden nicht unterstützt" } |
"Konnte keine temporäre Kopie der Datenbank anlegen." }, |
||||||
|
{ "Could not set temporary copy of database to readonly mode.", |
||||||
}; |
"Konnte die temp. Kopie nicht auf schreibgeschützt setzen" }, |
||||||
|
{ |
||||||
@Override |
"Handling non read-only temporary database with text tables is not supported", |
||||||
public String getDbInUseBy(String dbname, String user) { |
"Nicht schreibgeschützte Datenbanken mit Text-Tables werden nicht unterstützt" } |
||||||
String result = "Die Datenbank " + dbname + " wird schon benutzt "; |
|
||||||
if (user != null) result += " vom User " + user; |
}; |
||||||
result += ".\n"; |
|
||||||
return result; |
public String getDbInUseBy(String dbname, String user) { |
||||||
} |
String result = "Die Datenbank " + dbname + " wird schon benutzt "; |
||||||
} |
if (user != null) |
||||||
|
result += " vom User " + user; |
||||||
|
result += ".\n"; |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|||||||
@ -1,83 +1,91 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
|
/** |
||||||
/** |
* Additional procedures for HSQLDB |
||||||
* Additional procedures for HSQLDB |
* make sure that this class in the classpath. |
||||||
* make sure that this class in the classpath. |
* To constantly add it to hsql, go to the directory where your hsqldb.jar is located |
||||||
* To constantly add it to hsql, go to the directory where your hsqldb.jar is located |
* Call jar -xf hsqlAddOn.jar |
||||||
* Call jar -xf hsqlAddOn.jar |
* jar -uf hsqldb.jar org/hsqldb/Library2.class |
||||||
* jar -uf hsqldb.jar org/hsqldb/Library2.class |
* Delete the directory org. |
||||||
* Delete the directory org. |
* |
||||||
* |
* Open your Database in Database Manager and execute |
||||||
* Open your Database in Database Manager and execute |
* the following commands once: |
||||||
* the following commands once: |
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
||||||
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
||||||
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
*/ |
||||||
*/ |
public class Library2 { |
||||||
public class Library2 { |
private Library2() { |
||||||
private Library2() { |
super(); |
||||||
super(); |
} |
||||||
} |
/** |
||||||
|
* Fills regular tables with values from a CSV-file. |
||||||
/** |
* Similar to Postgres COPY FROM command. |
||||||
* Fills regular tables with values from a CSV-file. |
* |
||||||
* Similar to Postgres COPY FROM command. |
* If you want to fill your table TEST with data from test.csv |
||||||
* |
* make sure that this class in the classpath and that |
||||||
* If you want to fill your table TEST with data from test.csv |
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
||||||
* make sure that this class in the classpath and that |
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
||||||
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
* has been called in your database at some point. |
||||||
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
|
||||||
* has been called in your database at some point. |
* * Then execute |
||||||
|
* COPYFROM("TEST","test.csv",null) |
||||||
* * Then execute |
* |
||||||
* COPYFROM("TEST","test.csv",null) |
* if your not using , but | as a field separator |
||||||
* |
COPYFROM("TEST","test.csv","fs=|") |
||||||
* if your not using , but | as a field separator |
|
||||||
COPYFROM("TEST","test.csv","fs=|") |
* |
||||||
|
* @param con - Connection is automatically handed over by HSQL |
||||||
* |
* @param table - the name of the table that is to be filled |
||||||
* @param con - Connection is automatically handed over by HSQL |
* if your table isn't found capital letters may be required |
||||||
* @param table - the name of the table that is to be filled |
* @param file - the filename of the CSV-file |
||||||
* if your table isn't found capital letters may be required |
* @param options - you can specify options separated by ; |
||||||
* @param file - the filename of the CSV-file |
* which are described in the text table documentation e.g. |
||||||
* @param options - you can specify options separated by ; |
* fs=| to use pipe instead of default comma as field separator or |
||||||
* which are described in the text table documentation e.g. |
* or |
||||||
* fs=| to use pipe instead of default comma as field separator or |
* fs=|;vs=.;lvs=~" varchar separator, longvarchar separator |
||||||
* or |
* ignore_first=true; ignore first line |
||||||
* fs=|;vs=.;lvs=~" varchar separator, longvarchar separator |
* all_quoted=true or |
||||||
* ignore_first=true; ignore first line |
* encoding=UTF-8 if you don't have ASCII |
||||||
* all_quoted=true or |
* @throws SQLException |
||||||
* encoding=UTF-8 if you don't have ASCII |
*/ |
||||||
* @throws SQLException |
public static void copyFrom( |
||||||
*/ |
Connection con, |
||||||
public static void copyFrom(Connection con, String table, String file, String options) throws SQLException { |
String table, |
||||||
StringBuffer buf = new StringBuffer("create text table TMP_SOURCE_" + table + " ("); |
String file, |
||||||
|
String options) |
||||||
ResultSet rs = con.getMetaData().getColumns(null, null, table, null); |
throws SQLException { |
||||||
String colname, coltype; |
StringBuffer buf = |
||||||
boolean tableFound = false; |
new StringBuffer("create text table TMP_SOURCE_" + table + " ("); |
||||||
while (rs.next()) { |
|
||||||
tableFound = true; |
ResultSet rs = con.getMetaData().getColumns(null, null, table, null); |
||||||
colname = rs.getObject(4).toString(); |
String colname, coltype; |
||||||
coltype = rs.getObject(6).toString(); |
boolean tableFound = false; |
||||||
buf.append(colname + " " + coltype + ","); |
while (rs.next()) { |
||||||
} |
tableFound = true; |
||||||
rs.close(); |
colname = rs.getObject(4).toString(); |
||||||
if (!tableFound) throw new IllegalArgumentException("Copy from failed - table " + table + " not found"); |
coltype = rs.getObject(6).toString(); |
||||||
buf.deleteCharAt(buf.lastIndexOf(",")); |
buf.append(colname + " " + coltype + ","); |
||||||
buf.append("); SET TABLE TMP_SOURCE_" + table + " SOURCE \"" + file); |
} |
||||||
if (options != null) buf.append(";" + options); |
rs.close(); |
||||||
buf.append("\";"); |
if (!tableFound) |
||||||
buf.append("insert into " + table + " select * from TMP_SOURCE_" + table); |
throw new IllegalArgumentException( |
||||||
Statement stmt = con.createStatement(); |
"Copy from failed - table " + table + " not found"); |
||||||
try { |
buf.deleteCharAt(buf.lastIndexOf(",")); |
||||||
stmt.execute(buf.toString()); |
buf.append("); SET TABLE TMP_SOURCE_" + table + " SOURCE \"" + file); |
||||||
} finally { |
if (options != null) |
||||||
stmt.execute("drop table TMP_SOURCE_" + table + " IF EXISTS"); |
buf.append(";" + options); |
||||||
} |
buf.append("\";"); |
||||||
} |
buf.append( |
||||||
} |
"insert into " + table + " select * from TMP_SOURCE_" + table); |
||||||
|
Statement stmt = con.createStatement(); |
||||||
|
try { |
||||||
|
stmt.execute(buf.toString()); |
||||||
|
} finally { |
||||||
|
stmt.execute("drop table TMP_SOURCE_" + table + " IF EXISTS"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -0,0 +1,262 @@ |
|||||||
|
package de.memtext.db; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.IOException; |
||||||
|
import java.security.InvalidKeyException; |
||||||
|
import java.security.NoSuchAlgorithmException; |
||||||
|
import java.security.SignatureException; |
||||||
|
import java.security.spec.InvalidKeySpecException; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
import javax.xml.transform.TransformerConfigurationException; |
||||||
|
|
||||||
|
import org.apache.commons.dbcp.ConnectionFactory; |
||||||
|
import org.apache.commons.dbcp.DriverManagerConnectionFactory; |
||||||
|
import org.apache.commons.dbcp.PoolableConnectionFactory; |
||||||
|
import org.apache.commons.dbcp.PoolingDriver; |
||||||
|
import org.apache.commons.pool.impl.GenericObjectPool; |
||||||
|
|
||||||
|
import de.memtext.baseobjects.NamedObjectI; |
||||||
|
import de.memtext.tree.KeyParentEqualException; |
||||||
|
import de.memtext.util.DSAHandler; |
||||||
|
|
||||||
|
/** |
||||||
|
* A new Connection pool making use of Jakarta Commons dbcp. |
||||||
|
*/ |
||||||
|
public class MemtextPool extends GenericObjectPool implements NamedObjectI { |
||||||
|
|
||||||
|
private String name, subpath; |
||||||
|
private String nameNoAppendix; |
||||||
|
|
||||||
|
private Properties props = new Properties(); |
||||||
|
private String privateKeyEncoded = null; |
||||||
|
private String publicKeyEncoded = null; |
||||||
|
private DSAHandler dsaHandler; |
||||||
|
|
||||||
|
public MemtextPool(String name, String nameAppendix, String subpath) |
||||||
|
throws SQLException, IOException, DBServletException { |
||||||
|
this.subpath = subpath; |
||||||
|
nameNoAppendix = name; |
||||||
|
this.setName(name + nameAppendix); |
||||||
|
try { |
||||||
|
readPropertiesAndUrl(); |
||||||
|
System.out |
||||||
|
.print(" (" + props.getProperty("connectionURL") + ") .."); |
||||||
|
} catch (Exception e) { |
||||||
|
System.out |
||||||
|
.println("Konnte properties / Passwort nicht lesen. " + e); |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException( |
||||||
|
"Konnte properties / Passwort nicht lesen. " + e); |
||||||
|
} |
||||||
|
try { |
||||||
|
|
||||||
|
Class.forName(props.getProperty("driverName")); |
||||||
|
} catch (ClassNotFoundException e1) { |
||||||
|
throw new DBServletException("Treiber " |
||||||
|
+ props.getProperty("driverName") |
||||||
|
+ " nicht gefunden. Ggfs. nach tomcat/common/lib kopieren."); |
||||||
|
} |
||||||
|
|
||||||
|
initLogging(); |
||||||
|
this.setTestOnBorrow(true); |
||||||
|
|
||||||
|
int minIdle = 5; |
||||||
|
if (props.getProperty("minIdle") != null |
||||||
|
&& !props.getProperty("minIdle").trim().equals("")) { |
||||||
|
minIdle = Integer.parseInt(props.getProperty("minIdle")); |
||||||
|
} |
||||||
|
this.setMinIdle(minIdle); |
||||||
|
int maxIdle = -1; |
||||||
|
if (props.getProperty("maxIdle") != null |
||||||
|
&& !props.getProperty("maxIdle").trim().equals("")) { |
||||||
|
maxIdle = Integer.parseInt(props.getProperty("maxIdle")); |
||||||
|
} |
||||||
|
if (maxIdle != -1) |
||||||
|
setMaxIdle(maxIdle); |
||||||
|
|
||||||
|
int maxActive = -1; |
||||||
|
if (props.getProperty("maxActive") != null |
||||||
|
&& !props.getProperty("maxActive").trim().equals("")) { |
||||||
|
maxActive = Integer.parseInt(props.getProperty("maxActive")); |
||||||
|
} |
||||||
|
if (maxActive != -1) |
||||||
|
setMaxActive(maxActive); |
||||||
|
|
||||||
|
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( |
||||||
|
props.getProperty("connectionURL"), props); |
||||||
|
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( |
||||||
|
connectionFactory, this, null, "select count(*) from xdummy;" //validationQuery
|
||||||
|
, false, true); |
||||||
|
int i = 1; |
||||||
|
try { |
||||||
|
// PoolingDriver driver = new PoolingDriver();
|
||||||
|
Class.forName("org.apache.commons.dbcp.PoolingDriver"); |
||||||
|
} catch (ClassNotFoundException e2) { |
||||||
|
throw new DBServletException( |
||||||
|
"ConnectionPool Klasse org.apache.commons.dbcp.PoolingDriver nicht gefunden.\ncommons-dbcp nach tomcat/common/lib stellen."); |
||||||
|
} |
||||||
|
PoolingDriver driver = (PoolingDriver) DriverManager |
||||||
|
.getDriver("jdbc:apache:commons:dbcp:"); |
||||||
|
|
||||||
|
driver.registerPool(this.getName(), this); |
||||||
|
|
||||||
|
Object x = driver.getConnectionPool(this.getName()); |
||||||
|
try { |
||||||
|
Connection con = this.getConnection(); |
||||||
|
Statement st = con.createStatement(); |
||||||
|
ResultSet rs = st |
||||||
|
.executeQuery("select value from properties where name='privatekey'"); |
||||||
|
while (rs.next()) { |
||||||
|
privateKeyEncoded = rs.getString(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
rs = st |
||||||
|
.executeQuery("select value from properties where name='publickey'"); |
||||||
|
while (rs.next()) { |
||||||
|
publicKeyEncoded = rs.getString(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
con.close(); |
||||||
|
|
||||||
|
} catch (SQLException e) { |
||||||
|
String msg = "Fehler beim Aufbau des ConnectionPools "; |
||||||
|
if (!getName().startsWith("default")) |
||||||
|
msg += " für Mandant: " + getName(); |
||||||
|
msg += "\nKonnte keine Connection aus dem Pool holen.\n" + e; |
||||||
|
|
||||||
|
throw new SQLException(msg); |
||||||
|
} |
||||||
|
if (privateKeyEncoded != null) |
||||||
|
initDSAHandler(); |
||||||
|
} |
||||||
|
|
||||||
|
protected void initLogging() throws IOException { |
||||||
|
/* |
||||||
|
* LogUtils.initRawFile("superx_" + getName(), getLogDir() + "/superx_" + |
||||||
|
* name + ".log", 2000, 1, false, true); LogUtils.initRawFile("superx_" + |
||||||
|
* getName() + "_xml", getLogDir() + "/superx_" + name + "_xml.log", |
||||||
|
* 2000, 1, false, true); |
||||||
|
* |
||||||
|
* Level lev = Level.SEVERE; |
||||||
|
* |
||||||
|
* try { if (props.getProperty("logLevelSQL") != null) lev = |
||||||
|
* Level.parse(props.getProperty("logLevelSQL")); } catch |
||||||
|
* (IllegalArgumentException e) { String msg = "Ungültiger Level für |
||||||
|
* sqlLogger "; if (!this.getName().equals("default")) msg += "(Mandant :" + |
||||||
|
* getName() + ") "; msg += " :" + props.getProperty("logLevelSQL"); |
||||||
|
* System.out.println(msg); } Logger.getLogger("superx_" + |
||||||
|
* getName()).setLevel(lev); lev = Level.SEVERE; |
||||||
|
* |
||||||
|
* try { if (props.getProperty("logLevelXML") != null) lev = |
||||||
|
* Level.parse(props.getProperty("logLevelXML")); } catch |
||||||
|
* (IllegalArgumentException e) { String msg = "Ungültiger Level für |
||||||
|
* XMLLogger "; if (!this.getName().equals("default")) msg += "(Mandant :" + |
||||||
|
* getName() + ") "; msg += " :" + props.getProperty("logLevelXML"); |
||||||
|
* System.out.println(msg); } Logger.getLogger("superx_" + getName() + |
||||||
|
* "_xml").setLevel(lev); |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
public static String getLogDir() { |
||||||
|
String tomcat_home = System.getProperty("catalina.home"); //tomcat 4
|
||||||
|
// and 5
|
||||||
|
if (tomcat_home == null) |
||||||
|
tomcat_home = System.getProperty("tomcat.home"); //tomcat 3.x
|
||||||
|
if (tomcat_home == null) |
||||||
|
tomcat_home = "/home/superx/webserver/tomcat"; |
||||||
|
|
||||||
|
return tomcat_home + "/logs"; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public Properties getProperties() { |
||||||
|
return props; |
||||||
|
} |
||||||
|
|
||||||
|
private void readPropertiesAndUrl() throws Exception { |
||||||
|
String propname = "db_" + nameNoAppendix + ".properties"; |
||||||
|
if (nameNoAppendix.equals("default")) |
||||||
|
propname = "db.properties"; |
||||||
|
|
||||||
|
java.net.URL url = MemtextPool.class.getProtectionDomain() |
||||||
|
.getCodeSource().getLocation(); |
||||||
|
File myJar = new File(url.getFile()); |
||||||
|
File myPath = new File(myJar.getParent()); |
||||||
|
String pfad = myPath.getParent() + System.getProperty("file.separator"); |
||||||
|
if (subpath != null) |
||||||
|
pfad += subpath + System.getProperty("file.separator"); |
||||||
|
props = PropsReader.prepareProps(new File(pfad + propname)); |
||||||
|
int i = 1; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public void close() throws SQLException { |
||||||
|
PoolingDriver driver = (PoolingDriver) DriverManager |
||||||
|
.getDriver("jdbc:apache:commons:dbcp:"); |
||||||
|
driver.closePool(this.getName()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public Connection getConnection() throws SQLException { |
||||||
|
return DriverManager.getConnection("jdbc:apache:commons:dbcp:" |
||||||
|
+ this.getName()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void init() throws TransformerConfigurationException, |
||||||
|
KeyParentEqualException, SQLException, DBServletException { |
||||||
|
} |
||||||
|
|
||||||
|
public void clearLogFiles() throws IOException { |
||||||
|
} |
||||||
|
|
||||||
|
private void initDSAHandler() throws DBServletException { |
||||||
|
//privateKey wird ggfs. im Konstruktur bei Connection-Test, public key
|
||||||
|
// aus properties eingelesen
|
||||||
|
if (privateKeyEncoded == null) |
||||||
|
throw new IllegalStateException( |
||||||
|
"privatekey war null - properties-table auf Eintrag überprüfen"); |
||||||
|
if (publicKeyEncoded == null) |
||||||
|
throw new IllegalStateException( |
||||||
|
"publickey war null - properties-table prüfen"); |
||||||
|
try { |
||||||
|
dsaHandler = new DSAHandler(privateKeyEncoded, publicKeyEncoded); |
||||||
|
} catch (Exception e) { |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasDSAHandler() { |
||||||
|
return dsaHandler != null; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean verifiy(String data, String signature) |
||||||
|
throws InvalidKeyException, NoSuchAlgorithmException, |
||||||
|
InvalidKeySpecException, SignatureException { |
||||||
|
if (dsaHandler == null) |
||||||
|
throw new IllegalStateException( |
||||||
|
"DSAHandler ist null, public und private key definition prüfen"); |
||||||
|
return dsaHandler.verify(data, signature); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public String getPrivateKey() { |
||||||
|
return privateKeyEncoded; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 04.11.2004 at 20:18:11 as SxPool
|
||||||
@ -0,0 +1,197 @@ |
|||||||
|
package de.memtext.db; |
||||||
|
|
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.File; |
||||||
|
import java.io.FileReader; |
||||||
|
import java.io.IOException; |
||||||
|
import java.lang.reflect.Constructor; |
||||||
|
import java.lang.reflect.InvocationTargetException; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.Iterator; |
||||||
|
|
||||||
|
import javax.xml.transform.TransformerConfigurationException; |
||||||
|
|
||||||
|
import org.apache.commons.dbcp.PoolingDriver; |
||||||
|
|
||||||
|
import de.memtext.baseobjects.coll.NamedObjectSet; |
||||||
|
import de.memtext.tree.KeyParentEqualException; |
||||||
|
|
||||||
|
|
||||||
|
public class MemtextPools extends NamedObjectSet { |
||||||
|
|
||||||
|
private NamedObjectSet pools = new NamedObjectSet(); |
||||||
|
|
||||||
|
public MemtextPools() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized Connection getConnection(String poolname) |
||||||
|
throws SQLException { |
||||||
|
if (pools.size() == 0) |
||||||
|
throw new IllegalStateException("Kein ConnectionPool gefunden."); |
||||||
|
if (!pools.containsItemWithName(poolname)) |
||||||
|
throw new SQLException("Kein ConnectionPool für Mandant:" |
||||||
|
+ poolname + " gefunden"); |
||||||
|
String pooldrv = "jdbc:apache:commons:dbcp:" + poolname; |
||||||
|
if (DriverManager.getDriver(pooldrv) == null) { |
||||||
|
String msg = "Kein ConnectionPool gefunden "; |
||||||
|
if (!poolname.equals("default")) |
||||||
|
msg += " für Mandant " + poolname; |
||||||
|
throw new SQLException(msg); |
||||||
|
} |
||||||
|
return DriverManager.getConnection(pooldrv); |
||||||
|
} |
||||||
|
|
||||||
|
public MemtextPool get(String poolname) { |
||||||
|
if (!pools.containsItemWithName(poolname)) |
||||||
|
throw new IllegalStateException("Kein ConnectionPool (" + poolname |
||||||
|
+ ") vorhanden"); |
||||||
|
return (MemtextPool) pools.getByName(poolname); |
||||||
|
} |
||||||
|
|
||||||
|
/* void initDefaultOnly() throws SQLException, IOException, |
||||||
|
DBServletException { |
||||||
|
pools.add(new MemtextPool("default")); |
||||||
|
} |
||||||
|
*/ |
||||||
|
/** |
||||||
|
* wenn mehrfach benutzt wird (ConnectionPools für SuperX und Joolap) |
||||||
|
* mind ein sollte namensappendix haben, damit unterscheidbar - |
||||||
|
* sonst wird z.B. Pool für joolap "default" von später erzeugten Pool für superx "default" |
||||||
|
* überschrieben! |
||||||
|
*/ |
||||||
|
public void init(String subpath,Class poolclass, String nameAppendix) throws SQLException, IOException, |
||||||
|
DBServletException { |
||||||
|
if (nameAppendix==null) nameAppendix=""; |
||||||
|
Class[] params = new Class[2]; |
||||||
|
params[0] = String.class; |
||||||
|
params[1] = String.class; |
||||||
|
Constructor constructor; |
||||||
|
try { |
||||||
|
constructor = poolclass.getConstructor(params); |
||||||
|
|
||||||
|
String db_extfile = "mandanten.cfg"; |
||||||
|
if (db_extfile.indexOf(File.separator) == -1) { |
||||||
|
java.net.URL url = MemtextPools.class.getProtectionDomain() |
||||||
|
.getCodeSource().getLocation(); |
||||||
|
File myJar = new File(url.getFile()); |
||||||
|
File myPath = new File(myJar.getParent()); |
||||||
|
String pfad = myPath.getParent(); |
||||||
|
if (subpath!=null) pfad+=File.separator+subpath; |
||||||
|
db_extfile = pfad + File.separator+db_extfile; ; |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
File f = new File(db_extfile); |
||||||
|
if (!f.exists()) { |
||||||
|
//einfach nur normale db.properties (default)
|
||||||
|
System.out.print("Aufbau Datenbank-ConnectionPool"); |
||||||
|
Object[] args = new Object[2]; |
||||||
|
args[0] = "default";//Appendix hängt JoolapPool an
|
||||||
|
args[1] = subpath; |
||||||
|
MemtextPool connectionPool = (MemtextPool) constructor.newInstance(args); |
||||||
|
System.out.println(" OK"); |
||||||
|
System.out.println(" public/private key "+(connectionPool.hasDSAHandler()?" aktiv ":" nicht aktiv")); |
||||||
|
|
||||||
|
pools.add(connectionPool); |
||||||
|
} else { //mehrereMandanten
|
||||||
|
FileReader fr = new FileReader(f); |
||||||
|
BufferedReader bfr = new BufferedReader(fr); |
||||||
|
String line; |
||||||
|
while ((line = bfr.readLine()) != null) { |
||||||
|
System.out.print("Aufbau Datenbank-ConnectionPool für " |
||||||
|
+ line); |
||||||
|
Object[] args = new Object[2]; |
||||||
|
args[0] = line;//Appendix hängt JoolapPool an
|
||||||
|
args[1] = subpath; |
||||||
|
MemtextPool connectionPool = (MemtextPool) constructor.newInstance(args); |
||||||
|
System.out.println("OK"); |
||||||
|
System.out.println(" public/private key"+(connectionPool.hasDSAHandler()?" aktiv ":" nicht aktiv")); |
||||||
|
|
||||||
|
pools.add(connectionPool); |
||||||
|
} |
||||||
|
bfr.close(); |
||||||
|
fr.close(); |
||||||
|
} |
||||||
|
} catch (SecurityException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (NoSuchMethodException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (IllegalArgumentException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (InstantiationException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (IllegalAccessException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (InvocationTargetException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Destroys all ConnectionPools |
||||||
|
* |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void closeAll() throws Exception { |
||||||
|
for (Iterator it = pools.iterator(); it.hasNext();) { |
||||||
|
MemtextPool pool = (MemtextPool) it.next(); |
||||||
|
pool.close(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void main(String args[]) { |
||||||
|
try { |
||||||
|
init("xx",MemtextPool.class, null); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
int i = 1; |
||||||
|
} |
||||||
|
|
||||||
|
public void invalidate(String poolname, Connection con) |
||||||
|
throws DBServletException { |
||||||
|
if (!pools.containsItemWithName(poolname)) |
||||||
|
throw new DBServletException( |
||||||
|
"Kann Connection nicht invalidieren - kein ConnectionPool " |
||||||
|
+ poolname + " gefunden."); |
||||||
|
try { |
||||||
|
PoolingDriver driver = (PoolingDriver) DriverManager |
||||||
|
.getDriver("jdbc:apache:commons:dbcp:"); |
||||||
|
|
||||||
|
//driver.invalidateConnection(con);
|
||||||
|
driver.getConnectionPool(poolname).invalidateObject(con); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException("Invalidating connection failed -" + e); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void resetAllPools() |
||||||
|
throws TransformerConfigurationException, KeyParentEqualException, |
||||||
|
SQLException, DBServletException { |
||||||
|
for (Iterator it = pools.iterator(); it.hasNext();) { |
||||||
|
MemtextPool aPool = (MemtextPool) it.next(); |
||||||
|
aPool.init(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void clearLogFiles() throws IOException { |
||||||
|
for (Iterator it = pools.iterator(); it.hasNext();) { |
||||||
|
MemtextPool aPool = (MemtextPool) it.next(); |
||||||
|
aPool.clearLogFiles(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 04.11.2004 at 20:18:11 als SxPools
|
||||||
@ -1,23 +1,22 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
public class NichtAngemeldetException extends Exception { |
||||||
public class NichtAngemeldetException extends Exception { |
|
||||||
|
public NichtAngemeldetException() { |
||||||
public NichtAngemeldetException() { |
super(); |
||||||
super(); |
} |
||||||
} |
|
||||||
|
public NichtAngemeldetException(String message) { |
||||||
public NichtAngemeldetException(String message) { |
super(message); |
||||||
super(message); |
} |
||||||
} |
|
||||||
|
public NichtAngemeldetException(String message, Throwable cause) { |
||||||
public NichtAngemeldetException(String message, Throwable cause) { |
super(message, cause); |
||||||
super(message, cause); |
} |
||||||
} |
|
||||||
|
public NichtAngemeldetException(Throwable cause) { |
||||||
public NichtAngemeldetException(Throwable cause) { |
super(cause); |
||||||
super(cause); |
} |
||||||
} |
|
||||||
|
} |
||||||
} |
|
||||||
|
|
||||||
//Created on 05.10.2004 at 13:12:23
|
//Created on 05.10.2004 at 13:12:23
|
||||||
@ -1,100 +1,101 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
|
/** |
||||||
/** |
* Hilfsklasse zum Erstellen von Prozeduraufrüfen für verschd. |
||||||
* Hilfsklasse zum Erstellen von Prozeduraufrüfen für verschd. |
* Datenbanken. |
||||||
* Datenbanken. |
* Wird mit DB Object erstellt, z.B. ProcedureSql(DB.INFORMIX) |
||||||
* Wird mit DB Object erstellt, z.B. ProcedureSql(DB.INFORMIX) |
* dann setName() |
||||||
* dann setName() |
* dann beliebig oft addParam(),oder addDateParam() |
||||||
* dann beliebig oft addParam(),oder addDateParam() |
* Falls nach Aufruf der Prozedur ein select notwendig ist, |
||||||
* Falls nach Aufruf der Prozedur ein select notwendig ist, |
* reinsetzen mit setFinalSelect() |
||||||
* reinsetzen mit setFinalSelect() |
* zum Schluss. getFinishedCall für fertigen Datenbankspezifischen |
||||||
* zum Schluss. getFinishedCall für fertigen Datenbankspezifischen |
* Prozeduraufruf |
||||||
* Prozeduraufruf |
*/ |
||||||
*/ |
public class ProcedureSql { |
||||||
public class ProcedureSql { |
|
||||||
|
private DB dbsystem; |
||||||
private DB dbsystem; |
private boolean isAddPossible = true,isNameSet, isFinished; |
||||||
|
private String finalSelect = ""; |
||||||
private boolean isAddPossible = true, isNameSet, isFinished; |
|
||||||
|
private StringBuffer result = new StringBuffer(); |
||||||
private String finalSelect = ""; |
|
||||||
|
public ProcedureSql(DB db) { |
||||||
private StringBuffer result = new StringBuffer(); |
this.dbsystem = db; |
||||||
|
if (dbsystem.equals(DB.INFORMIX)) |
||||||
public ProcedureSql(DB db) { |
result.append("execute procedure "); |
||||||
this.dbsystem = db; |
if (dbsystem.equals(DB.POSTGRES)) |
||||||
if (dbsystem.equals(DB.INFORMIX)) result.append("execute procedure "); |
result.append("select "); |
||||||
if (dbsystem.equals(DB.POSTGRES)) result.append("select "); |
|
||||||
|
} |
||||||
} |
|
||||||
|
public ProcedureSql(DB dbsystem, String procname) { |
||||||
public ProcedureSql(DB dbsystem, String procname) { |
this(dbsystem); |
||||||
this(dbsystem); |
result.append(procname + ("(")); |
||||||
result.append(procname + ("(")); |
isNameSet=true; |
||||||
isNameSet = true; |
} |
||||||
} |
public void setName(String procName) { |
||||||
|
if (isNameSet)throw new IllegalStateException("Name wurde schon gesetzt"); |
||||||
public void setName(String procName) { |
result.append(procName+("(")); |
||||||
if (isNameSet) throw new IllegalStateException("Name wurde schon gesetzt"); |
isNameSet=true; |
||||||
result.append(procName + ("(")); |
} |
||||||
isNameSet = true; |
public void addParam(String param) { |
||||||
} |
if (!isAddPossible) |
||||||
|
throw new IllegalStateException("kann keine Parameter hinzufügen, vielleicht wurde getFinishedCall schon aufgerufen"); |
||||||
public void addParam(String param) { |
result.append(param + ","); |
||||||
if (!isAddPossible) throw new IllegalStateException("kann keine Parameter hinzufügen, vielleicht wurde getFinishedCall schon aufgerufen"); |
} |
||||||
result.append(param + ","); |
public void addDateParam(String param) { |
||||||
} |
if (!isAddPossible) |
||||||
|
throw new IllegalStateException("kann keine Parameter hinzufügen, vielleicht wurde getFinishedCall schon aufgerufen"); |
||||||
public void addDateParam(String param) { |
|
||||||
if (!isAddPossible) throw new IllegalStateException("kann keine Parameter hinzufügen, vielleicht wurde getFinishedCall schon aufgerufen"); |
if (dbsystem.equals(DB.INFORMIX)) |
||||||
|
result.append("date"); |
||||||
if (dbsystem.equals(DB.INFORMIX)) result.append("date"); |
if (dbsystem.equals(DB.POSTGRES)) |
||||||
if (dbsystem.equals(DB.POSTGRES)) result.append("date_val"); |
result.append("date_val"); |
||||||
result.append("('" + param + "'),"); |
result.append("('" + param + "'),"); |
||||||
} |
} |
||||||
|
public void setFinalSelect(String sel) { |
||||||
public void setFinalSelect(String sel) { |
finalSelect = sel; |
||||||
finalSelect = sel; |
} |
||||||
} |
|
||||||
|
public String getFinishedCall() { |
||||||
public String getFinishedCall() { |
if (!isFinished) |
||||||
if (!isFinished) finish(); |
finish(); |
||||||
return result.toString(); |
return result.toString(); |
||||||
} |
} |
||||||
|
|
||||||
private void finish() { |
private void finish() { |
||||||
addClosingBracket(); |
addClosingBracket(); |
||||||
result.append(finalSelect); |
result.append(finalSelect); |
||||||
isAddPossible = false; |
isAddPossible = false; |
||||||
isFinished = true; |
isFinished = true; |
||||||
} |
} |
||||||
|
|
||||||
private void addClosingBracket() { |
private void addClosingBracket() { |
||||||
char lc = result.charAt(result.length() - 1);// StringUtils.getLastChar(result);
|
char lc=result.charAt(result.length()-1);// StringUtils.getLastChar(result);
|
||||||
if (lc == ',') StringUtils.deleteLastChar(result); |
if (lc==',') |
||||||
result.append(");"); |
StringUtils.deleteLastChar(result); |
||||||
} |
result.append(");"); |
||||||
|
} |
||||||
public void addParam(Integer integer) { |
|
||||||
addParam(integer.toString()); |
public void addParam(Integer integer) { |
||||||
} |
addParam(integer.toString()); |
||||||
|
} |
||||||
public void addParam(int in) { |
|
||||||
addParam(Integer.valueOf(in).toString()); |
public void addParam(int in) { |
||||||
} |
addParam(new Integer(in).toString()); |
||||||
|
} |
||||||
public void addParam(Object param) { |
|
||||||
addParam(param.toString()); |
public void addParam(Object param) { |
||||||
} |
addParam(param.toString()); |
||||||
|
} |
||||||
public static void main(String args[]) { |
|
||||||
ProcedureSql p = new ProcedureSql(DB.POSTGRES, "test"); |
public static void main(String args[]) { |
||||||
p.addParam(23); |
ProcedureSql p=new ProcedureSql(DB.POSTGRES,"test"); |
||||||
System.out.println(p.getFinishedCall()); |
p.addParam(23); |
||||||
} |
System.out.println(p.getFinishedCall()); |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
//Created on 03.12.2003 at 15:56:43
|
//Created on 03.12.2003 at 15:56:43
|
||||||
@ -1,78 +1,72 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedIdObject; |
import de.memtext.baseobjects.NamedIdObject; |
||||||
|
/** |
||||||
/** |
* Beschreibt eine (zusätzliche) in der Datenbank hinterlegt Eigenschaft. |
||||||
* Beschreibt eine (zusätzliche) in der Datenbank hinterlegt Eigenschaft. |
* (z.B. Accident meister) |
||||||
* (z.B. Accident meister) |
*/ |
||||||
*/ |
public class PropDescriptor extends NamedIdObject { |
||||||
public class PropDescriptor extends NamedIdObject { |
//wie heißt die Spalte in der DB
|
||||||
//wie heißt die Spalte in der DB
|
private String colname; |
||||||
private String colname; |
//bei Combobox sql für quelle select key,name from xx
|
||||||
|
private String quelle; |
||||||
//bei Combobox sql für quelle select key,name from xx
|
//soll auf dem Bildschirm sichtbar sein
|
||||||
private String quelle; |
private boolean isVisible; |
||||||
|
|
||||||
//soll auf dem Bildschirm sichtbar sein
|
private String defaultkey; |
||||||
private boolean isVisible; |
private int sortnr; |
||||||
|
|
||||||
private String defaultkey; |
|
||||||
|
public PropDescriptor() { |
||||||
private int sortnr; |
|
||||||
|
} |
||||||
|
|
||||||
public PropDescriptor() { |
public PropDescriptor(Object id, String name) { |
||||||
|
super(id,name); |
||||||
} |
} |
||||||
|
|
||||||
public PropDescriptor(Object id, String name) { |
public String getColname() { |
||||||
super(id, name); |
return colname; |
||||||
} |
} |
||||||
|
|
||||||
public String getColname() { |
public void setColname(String colname) { |
||||||
return colname; |
this.colname = colname; |
||||||
} |
} |
||||||
|
|
||||||
public void setColname(String colname) { |
public String getDefaultkey() { |
||||||
this.colname = colname; |
return defaultkey; |
||||||
} |
} |
||||||
|
|
||||||
public String getDefaultkey() { |
public void setDefaultkey(String defaultkey) { |
||||||
return defaultkey; |
this.defaultkey = defaultkey; |
||||||
} |
} |
||||||
|
|
||||||
public void setDefaultkey(String defaultkey) { |
public boolean isVisible() { |
||||||
this.defaultkey = defaultkey; |
return isVisible; |
||||||
} |
} |
||||||
|
|
||||||
public boolean isVisible() { |
public void setVisible(boolean isVisible) { |
||||||
return isVisible; |
this.isVisible = isVisible; |
||||||
} |
} |
||||||
|
|
||||||
public void setVisible(boolean isVisible) { |
public String getQuelle() { |
||||||
this.isVisible = isVisible; |
return quelle; |
||||||
} |
} |
||||||
|
|
||||||
public String getQuelle() { |
public void setQuelle(String quelle) { |
||||||
return quelle; |
this.quelle = quelle; |
||||||
} |
} |
||||||
|
|
||||||
public void setQuelle(String quelle) { |
public int getSortnr() { |
||||||
this.quelle = quelle; |
return sortnr; |
||||||
} |
} |
||||||
|
public void setSortnr(int sortnr) { |
||||||
public int getSortnr() { |
this.sortnr = sortnr; |
||||||
return sortnr; |
} |
||||||
} |
public String toString() |
||||||
|
{ |
||||||
public void setSortnr(int sortnr) { |
return getName(); |
||||||
this.sortnr = sortnr; |
} |
||||||
} |
} |
||||||
|
|
||||||
@Override |
//Created on 17.05.2005 at 10:17:03
|
||||||
public String toString() { |
|
||||||
return getName(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 17.05.2005 at 10:17:03
|
|
||||||
|
|||||||
@ -1,58 +1,88 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import static de.superx.servlet.SxSQL_Server.DEFAULT_MANDANTEN_ID; |
import java.io.File; |
||||||
|
import java.io.FileInputStream; |
||||||
import java.io.File; |
import java.io.FileNotFoundException; |
||||||
import java.io.FileInputStream; |
import java.io.IOException; |
||||||
import java.io.FileNotFoundException; |
import java.io.InputStream; |
||||||
import java.io.IOException; |
import java.util.Properties; |
||||||
import java.io.InputStream; |
import java.util.logging.Level; |
||||||
import java.util.Properties; |
import java.util.logging.Logger; |
||||||
|
|
||||||
import de.memtext.util.CryptUtils; |
import de.memtext.util.CryptUtils; |
||||||
|
|
||||||
public class PropsReader { |
public class PropsReader { |
||||||
private static byte key[] = { (byte) 255, (byte) 221, (byte) 127, (byte) 109, (byte) 129 }; |
private static byte key[] = { (byte) 255, (byte) 221, (byte) 127, |
||||||
|
(byte) 109, (byte) 129 }; |
||||||
/* |
private static int keyLength = key.length; |
||||||
* |
/* |
||||||
* 28.10.08 EInfache Verschlüsselungsmethode wird nicht mehr unterstützt |
* |
||||||
*/ |
* 28.10.08 EInfache Verschlüsselungsmethode wird nicht mehr unterstützt |
||||||
public static String check(String mandantenID, String d) throws Exception { |
*/ |
||||||
String result = ""; |
public static String check(String mandantenID, String d) throws Exception { |
||||||
if (d.startsWith("sx_des")) { |
String result = ""; |
||||||
result = CryptUtils.decryptStringDES(d.substring(6)); |
// Logger.getLogger("superx_" + mandantenID).log(Level.FINEST,
|
||||||
} else { |
// "Verschlüsseltes Passwort " + d);
|
||||||
result = d; |
if (d.startsWith("sx_des")) { |
||||||
} |
result = CryptUtils.decryptStringDES(d.substring(6)); |
||||||
return result; |
} |
||||||
} |
else { |
||||||
|
result=d; |
||||||
public static Properties prepareProps(File propfile) throws IOException, FileNotFoundException, Exception { |
/* try { |
||||||
Properties props = new Properties(); |
byte[] tmp; |
||||||
if (!propfile.exists()) { |
tmp = d.getBytes(); |
||||||
throw new IOException("Datei nicht gefunden: " + propfile); |
|
||||||
} |
int size = (byte) (tmp[0] ^ key[0 % keyLength]); |
||||||
InputStream is = new FileInputStream(propfile); |
int index = (byte) (tmp[1] ^ key[1 % keyLength]); |
||||||
props.load(is); |
byte de[] = new byte[size]; |
||||||
is.close(); |
|
||||||
String mandantenID = props.getProperty("MandantenID"); |
for (int i = index; i < (size + index); i++) { |
||||||
if (mandantenID == null) mandantenID = DEFAULT_MANDANTEN_ID; |
de[i - index] = (byte) (tmp[i] ^ key[i % keyLength]); |
||||||
props.put("user", props.getProperty("connectionName")); |
} |
||||||
props.put("password", check(mandantenID, props.getProperty("connectionPassword"))); |
result = new String(de); |
||||||
|
} catch (Exception e) { |
||||||
if (props.getProperty("driverName").indexOf("postgres") > -1) { |
throw new DBServletException( |
||||||
props.put("charSet", "Latin-1"); |
"Konnte Passwort nicht entschlüsseln (altes Verfahren). Bitte mit propadmin.x prüfen.\n" |
||||||
props.put("DateStyle", "German, DMY"); |
+ e); |
||||||
} |
}*/ |
||||||
if (props.getProperty("driverName").indexOf("informix") > -1) |
} |
||||||
|
return result; |
||||||
{ |
} |
||||||
props.put("GL_DATETIME", "%d.%m.%Y %T"); |
|
||||||
props.put("CLIENT_LOCALE", "de_de.8859-1"); |
public static Properties prepareProps(File propfile) throws IOException, |
||||||
} |
FileNotFoundException, Exception { |
||||||
return props; |
Properties props = new Properties(); |
||||||
} |
if (!propfile.exists()) { |
||||||
} |
throw new IOException("Datei nicht gefunden: " + propfile); |
||||||
|
} |
||||||
//Created on 27.04.2005 at 09:07:18
|
InputStream is = new FileInputStream(propfile); |
||||||
|
|
||||||
|
if (is != null) { |
||||||
|
props.load(is); |
||||||
|
is.close(); |
||||||
|
} else { |
||||||
|
throw new IOException("cannot open " + propfile); |
||||||
|
} |
||||||
|
String mandantenID = props.getProperty("MandantenID"); |
||||||
|
if (mandantenID == null) |
||||||
|
mandantenID = "default"; |
||||||
|
props.put("user", props.getProperty("connectionName")); |
||||||
|
props.put("password", check(mandantenID, props |
||||||
|
.getProperty("connectionPassword"))); |
||||||
|
|
||||||
|
if (props.getProperty("driverName").indexOf("postgres") > -1) { |
||||||
|
props.put("charSet", "Latin-1"); |
||||||
|
props.put("DateStyle", "German, DMY"); |
||||||
|
// props.put("DateStyle", "ISO, DMY");
|
||||||
|
} |
||||||
|
if (props.getProperty("driverName").indexOf("informix") > -1) |
||||||
|
|
||||||
|
{ |
||||||
|
props.put("GL_DATETIME", "%d.%m.%Y %T"); |
||||||
|
props.put("CLIENT_LOCALE", "de_de.8859-1"); |
||||||
|
} |
||||||
|
return props; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 27.04.2005 at 09:07:18
|
||||||
|
|||||||
@ -1,97 +1,90 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
/** |
||||||
/** |
* collects restrictions for sql-clauses, manages where and |
||||||
* collects restrictions for sql-clauses, manages where and |
* and what to delete |
||||||
* and what to delete |
* take care of inital where yourself |
||||||
* take care of inital where yourself |
*/ |
||||||
*/ |
public class RestrictionCollector { |
||||||
public class RestrictionCollector { |
private StringBuffer restrict = new StringBuffer(); |
||||||
private StringBuffer restrict = new StringBuffer(); |
|
||||||
|
private int count=0; |
||||||
private int count = 0; |
public RestrictionCollector() { |
||||||
|
} |
||||||
public RestrictionCollector() { |
public RestrictionCollector(String restriction) { |
||||||
} |
restrict.append(restriction); |
||||||
|
count = 1; |
||||||
public RestrictionCollector(String restriction) { |
|
||||||
restrict.append(restriction); |
} |
||||||
count = 1; |
public boolean isSomethingAdded() |
||||||
|
{ |
||||||
} |
return count>0; |
||||||
|
} |
||||||
public boolean isSomethingAdded() { |
public void addAndRestriction(StringBuffer restriction) { |
||||||
return count > 0; |
addAndRestriction(restriction.toString()); |
||||||
} |
} |
||||||
|
public void addAndRestriction(String restriction) { |
||||||
public void addAndRestriction(StringBuffer restriction) { |
if (restriction==null||restriction.length()<3) |
||||||
addAndRestriction(restriction.toString()); |
throw new IllegalArgumentException("Not OK:"+restriction); |
||||||
} |
boolean isNewlineAtStart=restriction.startsWith("\n"); |
||||||
|
restriction = restriction.trim(); |
||||||
public void addAndRestriction(String restriction) { |
if (isNewlineAtStart) restriction="\n"+restriction; |
||||||
if (restriction == null || restriction.length() < 3) throw new IllegalArgumentException("Not OK:" + restriction); |
if (restriction.substring(0, 3).equalsIgnoreCase("and")) |
||||||
boolean isNewlineAtStart = restriction.startsWith("\n"); |
restriction = restriction.substring(3); |
||||||
restriction = restriction.trim(); |
if (count>0) |
||||||
if (isNewlineAtStart) restriction = "\n" + restriction; |
restrict.append(" and " + restriction + " "); |
||||||
if (restriction.substring(0, 3).equalsIgnoreCase("and")) restriction = restriction.substring(3); |
else |
||||||
if (count > 0) |
restrict.append(restriction + " "); |
||||||
restrict.append(" and " + restriction + " "); |
count++; |
||||||
else |
} |
||||||
restrict.append(restriction + " "); |
|
||||||
count++; |
public void addOrRestriction(StringBuffer restriction) { |
||||||
} |
addOrRestriction(restriction.toString()); |
||||||
|
} |
||||||
public void addOrRestriction(StringBuffer restriction) { |
public void addOrRestriction(String restriction) { |
||||||
addOrRestriction(restriction.toString()); |
if (restriction==null||restriction.length()<3) |
||||||
} |
throw new IllegalArgumentException("Not OK:"+restriction); |
||||||
|
|
||||||
public void addOrRestriction(String restriction) { |
restriction = restriction.trim(); |
||||||
if (restriction == null || restriction.length() < 3) throw new IllegalArgumentException("Not OK:" + restriction); |
if (restriction.substring(0, 3).equalsIgnoreCase("or ")) |
||||||
|
restriction = restriction.substring(3); |
||||||
restriction = restriction.trim(); |
|
||||||
if (restriction.substring(0, 3).equalsIgnoreCase("or ")) restriction = restriction.substring(3); |
if (count>0) |
||||||
|
restrict.append(" or " + restriction + " "); |
||||||
if (count > 0) |
else |
||||||
restrict.append(" or " + restriction + " "); |
restrict.append(restriction + " "); |
||||||
else |
count++; |
||||||
restrict.append(restriction + " "); |
} |
||||||
count++; |
public void addOrRestriction(RestrictionCollector collector) { |
||||||
} |
addOrRestriction(collector.toString()); |
||||||
|
} |
||||||
public void addOrRestriction(RestrictionCollector collector) { |
public String toString() { |
||||||
addOrRestriction(collector.toString()); |
if (count>0) |
||||||
} |
return restrict.toString(); |
||||||
|
else |
||||||
@Override |
return ""; |
||||||
public String toString() { |
} |
||||||
if (count > 0) |
public String toStringInclusiveWhere() |
||||||
return restrict.toString(); |
{ |
||||||
else |
if (count>0) |
||||||
return ""; |
return " where "+restrict; |
||||||
} |
else |
||||||
|
return ""; |
||||||
public String toStringInclusiveWhere() { |
} |
||||||
if (count > 0) |
public int getArgumentCount() |
||||||
return " where " + restrict; |
{ |
||||||
else |
return count; |
||||||
return ""; |
} |
||||||
} |
public void addAndRestriction(RestrictionCollector collector) { |
||||||
|
if (collector.getArgumentCount()>1) |
||||||
public int getArgumentCount() { |
addAndRestriction( collector.toString()); |
||||||
return count; |
else |
||||||
} |
addAndRestriction( collector.toString() ); |
||||||
|
} |
||||||
public void addAndRestriction(RestrictionCollector collector) { |
public static void main(String[] args) { |
||||||
if (collector.getArgumentCount() > 1) |
RestrictionCollector r = new RestrictionCollector(); |
||||||
addAndRestriction(collector.toString()); |
r.addAndRestriction(" AND 1=1"); |
||||||
else |
r.addAndRestriction("2=2"); |
||||||
addAndRestriction(collector.toString()); |
System.out.println(r); |
||||||
} |
} |
||||||
|
} |
||||||
public static void main(String[] args) { |
|
||||||
RestrictionCollector r = new RestrictionCollector(); |
|
||||||
r.addAndRestriction(" AND 1=1"); |
|
||||||
r.addAndRestriction("2=2"); |
|
||||||
System.out.println(r); |
|
||||||
} |
|
||||||
} |
|
||||||
// Created on 23.07.2003
|
// Created on 23.07.2003
|
||||||
@ -1,121 +1,124 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowAdapter; |
||||||
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
|
|
||||||
import javax.swing.JFrame; |
import javax.swing.JFrame; |
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
||||||
|
|
||||||
public class SampleApp extends JFrame { |
public class SampleApp extends JFrame { |
||||||
private Connection con = null; |
private Connection con = null; |
||||||
|
private String path = ""; // null , "" or "." for current directory
|
||||||
private String path = ""; // null , "" or "." for current directory
|
private String dbname = "testing"; |
||||||
|
|
||||||
private String dbname = "testing"; |
public SampleApp() throws ClassNotFoundException, SQLException, IOException { |
||||||
|
super("SampleApp"); |
||||||
public SampleApp() throws ClassNotFoundException, SQLException, IOException { |
initDb(); |
||||||
super("SampleApp"); |
|
||||||
initDb(); |
JLabel lbl = new JLabel("got a connection to " |
||||||
|
+ con.getMetaData().getURL()); |
||||||
JLabel lbl = new JLabel("got a connection to " + con.getMetaData().getURL()); |
this.getContentPane().add(lbl); |
||||||
this.getContentPane().add(lbl); |
this.setSize(600, 400); |
||||||
this.setSize(600, 400); |
|
||||||
|
addWindowListener(new WindowAdapter() { |
||||||
addWindowListener(new WindowAdapter() { |
public void windowClosing(WindowEvent we) { |
||||||
@Override |
try { |
||||||
public void windowClosing(WindowEvent we) { |
String url=con.getMetaData().getURL(); |
||||||
try { |
Statement stmt= con.createStatement(); |
||||||
String url = con.getMetaData().getURL(); |
stmt.execute("shutdown"); |
||||||
Statement stmt = con.createStatement(); |
stmt.close(); |
||||||
stmt.execute("shutdown"); |
con.close(); |
||||||
stmt.close(); |
//delete all temporary files that may exists
|
||||||
con.close(); |
HsqlStandaloneMgr.deleteTmpFiles( url,path, dbname); |
||||||
//delete all temporary files that may exists
|
} catch (SQLException e) { |
||||||
HsqlStandaloneMgr.deleteTmpFiles(url, path, dbname); |
e.printStackTrace(); |
||||||
} catch (SQLException e) { |
} |
||||||
e.printStackTrace(); |
System.exit(0); |
||||||
} |
} |
||||||
System.exit(0); |
}); |
||||||
} |
|
||||||
}); |
} |
||||||
|
|
||||||
} |
private void initDb() throws ClassNotFoundException, SQLException, |
||||||
|
IOException { |
||||||
private void initDb() throws ClassNotFoundException, SQLException, IOException { |
|
||||||
|
if (!HsqlStandaloneMgr.isDatabaseOpen(path, dbname)) { |
||||||
if (!HsqlStandaloneMgr.isDatabaseOpen(path, dbname)) { |
//if the database isn't open yet, we just open a regular connection
|
||||||
//if the database isn't open yet, we just open a regular connection
|
//the system username is written to a special properties file
|
||||||
//the system username is written to a special properties file
|
con = HsqlStandaloneMgr.getConnection(path, dbname, "sa", ""); |
||||||
con = HsqlStandaloneMgr.getConnection(path, dbname, "sa", ""); |
Statement stmt = con.createStatement(); |
||||||
Statement stmt = con.createStatement(); |
stmt |
||||||
stmt.execute("drop table test if exists;create table test( col1 integer);insert into test values(1);checkpoint;"); |
.execute("drop table test if exists;create table test( col1 integer);insert into test values(1);checkpoint;"); |
||||||
stmt.close(); |
stmt.close(); |
||||||
} else |
} else |
||||||
// the database is already open
|
// the database is already open
|
||||||
{ |
{ |
||||||
//you can decide if the temporary copy should be read-only mode
|
//you can decide if the temporary copy should be read-only mode
|
||||||
//if not, all changes to the database will be lost after closing
|
//if not, all changes to the database will be lost after closing
|
||||||
// the connection
|
// the connection
|
||||||
boolean isReadOnlyModeWanted = true; |
boolean isReadOnlyModeWanted = true; |
||||||
int result = HsqlStandaloneMgr.askUser(this, path, dbname, isReadOnlyModeWanted); |
int result = HsqlStandaloneMgr.askUser(this, path, dbname, |
||||||
if (result == JOptionPane.YES_OPTION) { |
isReadOnlyModeWanted); |
||||||
con = HsqlStandaloneMgr.getTmpConnection(this, path, dbname, "sa", "", isReadOnlyModeWanted); |
if (result == JOptionPane.YES_OPTION) { |
||||||
} else { |
con = HsqlStandaloneMgr.getTmpConnection(this, path, dbname, |
||||||
// opening of temp. copy not wanted
|
"sa", "", isReadOnlyModeWanted); |
||||||
System.exit(0); |
} else |
||||||
} |
{ |
||||||
} |
// opening of temp. copy not wanted
|
||||||
} |
System.exit(0); |
||||||
|
} |
||||||
public static void main(String args[]) { |
} |
||||||
|
} |
||||||
try { |
|
||||||
SampleApp app = new SampleApp(); |
public static void main(String args[]) { |
||||||
app.show(); |
|
||||||
} catch (ClassNotFoundException e) { |
try { |
||||||
e.printStackTrace(); |
SampleApp app = new SampleApp(); |
||||||
} catch (SQLException e) { |
app.show(); |
||||||
e.printStackTrace(); |
} catch (ClassNotFoundException e) { |
||||||
} catch (IOException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (SQLException e) { |
||||||
} |
e.printStackTrace(); |
||||||
|
} catch (IOException e) { |
||||||
} |
e.printStackTrace(); |
||||||
} |
} |
||||||
|
|
||||||
//Created on 23.10.2004 at 12:10:38
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 23.10.2004 at 12:10:38
|
||||||
|
|||||||
@ -1,47 +1,48 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.io.File; |
import java.io.File; |
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.DatabaseMetaData; |
import java.sql.DatabaseMetaData; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
|
|
||||||
import org.apache.commons.io.FileUtils; |
import de.memtext.util.StringUtils; |
||||||
|
|
||||||
public class SchemaReader { |
public class SchemaReader { |
||||||
|
|
||||||
public static void main(String[] args) { |
public static void main(String[] args) { |
||||||
if (args.length != 1) { |
if (args.length != 1) { |
||||||
System.out.println("SchemaReader db.properties"); |
System.out.println("SchemaReader db.properties"); |
||||||
System.exit(1); |
System.exit(1); |
||||||
} |
} |
||||||
try { |
try { |
||||||
Connection con = ConnectionCreator.getConnectionCryptPassword(args[0], "driverName", "connectionURL", "connectionName", "connectionPassword"); |
Connection con = ConnectionCreator.getConnectionCryptPassword(args[0],"driverName","connectionURL","connectionName","connectionPassword"); |
||||||
DatabaseMetaData md = con.getMetaData(); |
DatabaseMetaData md = con.getMetaData(); |
||||||
ResultSet myTables = md.getTables(null, null, null, null); |
ResultSet myTables = md.getTables(null, null, null, null); |
||||||
StringBuffer result = new StringBuffer(); |
StringBuffer result = new StringBuffer(); |
||||||
if (myTables != null) { |
if (myTables != null) { |
||||||
while (myTables.next()) { |
while (myTables.next()) { |
||||||
String tabname = myTables.getString(3); |
String tabname = myTables.getString(3); |
||||||
result.append("TABLE " + tabname + "\n"); |
result.append("TABLE " + tabname + "\n"); |
||||||
ResultSet cols = md.getColumns(null, null, tabname, null); |
ResultSet cols = md.getColumns(null, null, tabname, null); |
||||||
while (cols.next()) { |
while (cols.next()) { |
||||||
result.append(cols.getString(4) + ":" + cols.getObject(5) + "\n"); |
result.append(cols.getString(4) + ":" |
||||||
} |
+ cols.getObject(5) + "\n"); |
||||||
result.append("----\n"); |
} |
||||||
} |
result.append("----\n"); |
||||||
} |
} |
||||||
FileUtils.writeStringToFile(new File("schema.txt"), result.toString()); |
} |
||||||
|
StringUtils.write(new File("schema.txt"),result.toString()); |
||||||
} catch (IOException e) { |
|
||||||
e.printStackTrace(); |
} catch (IOException e) { |
||||||
} catch (SQLException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (SQLException e) { |
||||||
} catch (ClassNotFoundException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (ClassNotFoundException e) { |
||||||
} |
e.printStackTrace(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
} |
||||||
//Created on 21.02.2006 at 10:38:08
|
|
||||||
|
//Created on 21.02.2006 at 10:38:08
|
||||||
|
|||||||
@ -1,217 +1,266 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
import java.io.BufferedWriter; |
||||||
import java.io.BufferedWriter; |
import java.io.FileWriter; |
||||||
import java.io.FileWriter; |
import java.sql.Connection; |
||||||
import java.sql.Connection; |
import java.sql.DriverManager; |
||||||
import java.sql.DriverManager; |
import java.sql.ResultSet; |
||||||
import java.sql.ResultSet; |
import java.sql.SQLException; |
||||||
import java.sql.SQLException; |
import java.sql.Statement; |
||||||
import java.sql.Statement; |
import java.util.Enumeration; |
||||||
import java.util.Enumeration; |
import java.util.Random; |
||||||
import java.util.Random; |
import java.util.Vector; |
||||||
import java.util.Vector; |
/** |
||||||
|
* Randomizes values in a database. |
||||||
/** |
* Reads all values of a given table column (select distinct x from..) and |
||||||
* Randomizes values in a database. |
* multiplies all occurences of a single value (e.g. 150) with a factor between |
||||||
* Reads all values of a given table column (select distinct x from..) and |
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
||||||
* multiplies all occurences of a single value (e.g. 150) with a factor between |
* |
||||||
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
* if boolean printOutOnly is true the update sql statements are only logged |
||||||
* |
* to console, not performed |
||||||
* if boolean printOutOnly is true the update sql statements are only logged |
* */ |
||||||
* to console, not performed |
public class ValueRandomizer { |
||||||
* */ |
//private static String driver = "org.hsqldb.jdbcDriver";
|
||||||
public class ValueRandomizer { |
private static String driver = "org.postgresql.Driver"; |
||||||
//private static String driver = "org.hsqldb.jdbcDriver";
|
//private static String dbUrl = "jdbc:hsqldb:hsql://localhost:9999";
|
||||||
private static String driver = "org.postgresql.Driver"; |
private static String dbUrl = "jdbc:postgresql://localhost:5432/superx"; |
||||||
|
private static String username = "superx"; //"joolap";
|
||||||
//private static String dbUrl = "jdbc:hsqldb:hsql://localhost:9999";
|
private static String password = ""; //"loopja3000";
|
||||||
private static String dbUrl = "jdbc:postgresql://localhost:5432/superx"; |
private static String tablename = "cob_busa"; |
||||||
|
private static String colname = "betrag"; //"value";
|
||||||
private static String username = "superx"; //"joolap";
|
private static String datenart = "DOUBLE"; //or "INTEGER";
|
||||||
|
|
||||||
private static String password = ""; //"loopja3000";
|
private static double minFactor = 0.6; |
||||||
|
private static double maxFactor = 1.8; |
||||||
private static String tablename = "cob_busa"; |
|
||||||
|
private static boolean printOutOnly = false; |
||||||
private static String colname = "betrag"; //"value";
|
private static Statement stat; |
||||||
|
private static Random r = new Random(); |
||||||
private static String datenart = "DOUBLE"; //or "INTEGER";
|
public static void main(String args[]) { |
||||||
|
|
||||||
private static double minFactor = 0.6; |
try { |
||||||
|
Class.forName(driver); |
||||||
private static double maxFactor = 1.8; |
Connection conn; |
||||||
|
System.out.println("establishing connection to " + dbUrl); |
||||||
private static boolean printOutOnly = false; |
conn = DriverManager.getConnection(dbUrl, username, password); |
||||||
|
stat = conn.createStatement(); |
||||||
private static Statement stat; |
System.out.println("done."); |
||||||
|
out(); |
||||||
private static Random r = new Random(); |
stat.close(); |
||||||
|
conn.close(); |
||||||
public static void main(String args[]) { |
System.exit(-1); |
||||||
|
|
||||||
try { |
|
||||||
Class.forName(driver); |
//alle werte einlesen
|
||||||
Connection conn; |
Vector werte = readDistinctValues(); |
||||||
System.out.println("establishing connection to " + dbUrl); |
if (datenart.toUpperCase().equalsIgnoreCase("DOUBLE")) { |
||||||
conn = DriverManager.getConnection(dbUrl, username, password); |
//massiveRandomizeDouble(werte);
|
||||||
stat = conn.createStatement(); |
randomize(werte); |
||||||
System.out.println("done."); |
} else //integer
|
||||||
out(); |
{ |
||||||
stat.close(); |
massiveRandomizeInteger(werte); |
||||||
conn.close(); |
} |
||||||
System.exit(-1); |
|
||||||
|
System.out.println("Randomizierung erfolgreich beendet"); |
||||||
|
} catch (Exception e) { |
||||||
//alle werte einlesen
|
System.out.println(e.toString()); |
||||||
Vector werte = readDistinctValues(); |
System.exit(0); |
||||||
if (datenart.toUpperCase().equalsIgnoreCase("DOUBLE")) { |
} |
||||||
//massiveRandomizeDouble(werte);
|
|
||||||
randomize(werte); |
} |
||||||
} else //integer
|
/** |
||||||
{ |
* randomizes in categories of values |
||||||
massiveRandomizeInteger(werte); |
* only for double |
||||||
} |
* @param werte |
||||||
|
*/ |
||||||
System.out.println("Randomizierung erfolgreich beendet"); |
private static void randomize(Vector werte) { |
||||||
} catch (Exception e) { |
int categories = 15; |
||||||
System.out.println(e.toString()); |
int valuesPerCategory = (int) werte.size() / categories; |
||||||
System.exit(0); |
StringBuffer updates = new StringBuffer(); |
||||||
} |
float limit = 0, limit2; |
||||||
|
for (int i = 1; i < categories; i++) { |
||||||
} |
limit = |
||||||
|
(float) ((Double) werte.get(i * valuesPerCategory)) |
||||||
/** |
.doubleValue(); |
||||||
* randomizes in categories of values |
updates.append( |
||||||
* only for double |
"update " |
||||||
* @param werte |
+ tablename |
||||||
*/ |
+ " set " |
||||||
private static void randomize(Vector werte) { |
+ colname |
||||||
int categories = 15; |
+ "=" |
||||||
int valuesPerCategory = (int) werte.size() / categories; |
+ colname |
||||||
StringBuffer updates = new StringBuffer(); |
+ "*" |
||||||
float limit = 0, limit2; |
+ getRndFactor() |
||||||
for (int i = 1; i < categories; i++) { |
+ " where " |
||||||
limit = (float) ((Double) werte.get(i * valuesPerCategory)).doubleValue(); |
+ colname |
||||||
updates.append("update " + tablename + " set " + colname + "=" + colname + "*" + getRndFactor() + " where " + colname + ">" + limit); |
+ ">" |
||||||
if (i > 1) { |
+ limit); |
||||||
limit2 = (float) ((Double) werte.get((i - 1) * valuesPerCategory)).doubleValue(); |
if (i > 1) { |
||||||
updates.append(" and " + colname + "<" + limit2); |
limit2 = |
||||||
} |
(float) ((Double) werte.get((i - 1) * valuesPerCategory)) |
||||||
updates.append(";\n"); |
.doubleValue(); |
||||||
} |
updates.append(" and " + colname + "<" + limit2); |
||||||
limit = (float) ((Double) werte.get((categories - 1) * valuesPerCategory)).doubleValue(); |
} |
||||||
updates.append("update " + tablename + " set " + colname + "=" + colname + "*" + getRndFactor() + " where " + colname + "<" + limit + ";"); |
updates.append(";\n"); |
||||||
|
} |
||||||
System.out.println(updates); |
limit = |
||||||
} |
(float) ((Double) werte.get((categories - 1) * valuesPerCategory)) |
||||||
|
.doubleValue(); |
||||||
/** |
updates.append( |
||||||
* * multiplies all occurences of a single value (e.g. 150) with a factor between |
"update " |
||||||
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
+ tablename |
||||||
|
+ " set " |
||||||
* @param werte |
+ colname |
||||||
* @throws SQLException |
+ "=" |
||||||
*/ |
+ colname |
||||||
private static void massiveRandomizeInteger(Vector werte) throws SQLException { |
+ "*" |
||||||
Integer einWert; |
+ getRndFactor() |
||||||
String upd = null; |
+ " where " |
||||||
for (Enumeration en = werte.elements(); en.hasMoreElements();) { |
+ colname |
||||||
einWert = (Integer) en.nextElement(); |
+ "<" |
||||||
int neuerwert = (int) (einWert.intValue() * getRndFactor()); |
+ limit |
||||||
upd = "update " + tablename + " set " + colname + "=" + neuerwert + " where " + colname + "=" + einWert.toString() + ";"; |
+ ";"); |
||||||
|
|
||||||
if (printOutOnly) |
System.out.println(updates); |
||||||
System.out.println(upd); |
} |
||||||
else |
/** |
||||||
stat.executeUpdate(upd); |
* * multiplies all occurences of a single value (e.g. 150) with a factor between |
||||||
} |
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
||||||
|
|
||||||
} |
* @param werte |
||||||
|
* @throws SQLException |
||||||
/** |
*/ |
||||||
* * multiplies all occurences of a single value (e.g. 150) with a factor between |
private static void massiveRandomizeInteger(Vector werte) |
||||||
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
throws SQLException { |
||||||
|
Integer einWert; |
||||||
* @param werte |
String upd = null; |
||||||
* @throws SQLException |
for (Enumeration en = werte.elements(); en.hasMoreElements();) { |
||||||
*/ |
einWert = (Integer) en.nextElement(); |
||||||
private static void massiveRandomizeDouble(Vector werte) throws SQLException { |
int neuerwert = (int) (einWert.intValue() * getRndFactor()); |
||||||
Double einWert; |
upd = |
||||||
double zufallswert; |
"update " |
||||||
String upd; |
+ tablename |
||||||
int i = 0; |
+ " set " |
||||||
int count = werte.size(); |
+ colname |
||||||
for (Enumeration en = werte.elements(); en.hasMoreElements();) { |
+ "=" |
||||||
einWert = (Double) en.nextElement(); |
+ neuerwert |
||||||
i++; |
+ " where " |
||||||
zufallswert = einWert.doubleValue() * getRndFactor(); |
+ colname |
||||||
upd = "update " + tablename + " set " + colname + "=" + zufallswert + " where " + colname + "=" + einWert + ";"; |
+ "=" |
||||||
if (printOutOnly) |
+ einWert.toString() |
||||||
System.out.println(upd); |
+ ";"; |
||||||
else { |
|
||||||
stat.executeUpdate(upd); |
if (printOutOnly) |
||||||
if (i % 20 == 0) System.out.println("Done " + i + " updates of " + count); |
System.out.println(upd); |
||||||
} |
else |
||||||
|
stat.executeUpdate(upd); |
||||||
} |
} |
||||||
} |
|
||||||
|
} |
||||||
private static float getRndFactor() { |
/** |
||||||
double rnd = Math.abs(r.nextDouble()); |
* * multiplies all occurences of a single value (e.g. 150) with a factor between |
||||||
while (rnd < minFactor) |
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
||||||
rnd += minFactor; |
|
||||||
while (rnd > maxFactor) |
* @param werte |
||||||
rnd -= 0.05; |
* @throws SQLException |
||||||
return (float) rnd; |
*/ |
||||||
} |
private static void massiveRandomizeDouble(Vector werte) |
||||||
|
throws SQLException { |
||||||
private static Vector readDistinctValues() throws SQLException { |
Double einWert; |
||||||
Vector werte = new Vector(); |
double zufallswert; |
||||||
ResultSet rs = null; |
String upd; |
||||||
Object item; |
int i = 0; |
||||||
System.out.println("Alle werte einlesen:" + "select distinct " + colname + " from " + tablename + " order by 1 DESC"); |
int count = werte.size(); |
||||||
|
for (Enumeration en = werte.elements(); en.hasMoreElements();) { |
||||||
rs = stat.executeQuery("select distinct " + colname + " from " + tablename + " order by " + colname + " DESC"); |
einWert = (Double) en.nextElement(); |
||||||
while (rs.next()) { |
i++; |
||||||
item = rs.getObject(1); |
zufallswert = einWert.doubleValue() * getRndFactor(); |
||||||
werte.add(item); |
upd = |
||||||
} |
"update " |
||||||
rs.close(); |
+ tablename |
||||||
return werte; |
+ " set " |
||||||
} |
+ colname |
||||||
|
+ "=" |
||||||
private static void out() { |
+ zufallswert |
||||||
try { |
+ " where " |
||||||
FileWriter fw = new FileWriter("c:\\cygwin\\home\\superx\\cob_busa.unl"); |
+ colname |
||||||
BufferedWriter bw = new BufferedWriter(fw); |
+ "=" |
||||||
StringBuffer buf = new StringBuffer(); |
+ einWert |
||||||
|
+ ";"; |
||||||
ResultSet rs = stat.executeQuery("select * from cob_busa"); |
if (printOutOnly) |
||||||
|
System.out.println(upd); |
||||||
int cols = 20; |
else { |
||||||
String s; |
stat.executeUpdate(upd); |
||||||
Object o; |
if (i % 20 == 0) |
||||||
while (rs.next()) { |
System.out.println("Done " + i + " updates of " + count); |
||||||
for (int i = 1; i <= cols; i++) { |
} |
||||||
o = rs.getObject(i); |
|
||||||
if (o == null) |
} |
||||||
s = ""; |
} |
||||||
else |
private static float getRndFactor() { |
||||||
s = o.toString(); |
double rnd = Math.abs(r.nextDouble()); |
||||||
|
while (rnd < minFactor) |
||||||
buf.append(s.trim() + "^"); |
rnd += minFactor; |
||||||
} |
while (rnd > maxFactor) |
||||||
buf.append("^\n"); |
rnd -= 0.05; |
||||||
|
return (float) rnd; |
||||||
} |
} |
||||||
rs.close(); |
private static Vector readDistinctValues() throws SQLException { |
||||||
|
Vector werte = new Vector(); |
||||||
bw.write(buf.toString()); |
ResultSet rs = null; |
||||||
bw.close(); |
Object item; |
||||||
fw.close(); |
System.out.println( |
||||||
} catch (Exception e) { |
"Alle werte einlesen:" |
||||||
e.printStackTrace(); |
+ "select distinct " |
||||||
} |
+ colname |
||||||
System.out.println("done"); |
+ " from " |
||||||
} |
+ tablename |
||||||
} |
+ " order by 1 DESC"); |
||||||
|
|
||||||
|
rs = |
||||||
|
stat.executeQuery( |
||||||
|
"select distinct " |
||||||
|
+ colname |
||||||
|
+ " from " |
||||||
|
+ tablename |
||||||
|
+ " order by " |
||||||
|
+ colname |
||||||
|
+ " DESC"); |
||||||
|
while (rs.next()) { |
||||||
|
item = rs.getObject(1); |
||||||
|
werte.add(item); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
return werte; |
||||||
|
} |
||||||
|
|
||||||
|
private static void out() { |
||||||
|
try { |
||||||
|
FileWriter fw = |
||||||
|
new FileWriter("c:\\cygwin\\home\\superx\\cob_busa.unl"); |
||||||
|
BufferedWriter bw = new BufferedWriter(fw); |
||||||
|
StringBuffer buf = new StringBuffer(); |
||||||
|
|
||||||
|
ResultSet rs = stat.executeQuery("select * from cob_busa"); |
||||||
|
|
||||||
|
int cols = 20;String s;Object o; |
||||||
|
while (rs.next()) { |
||||||
|
for (int i = 1; i <= cols; i++) |
||||||
|
{o=rs.getObject(i); |
||||||
|
if (o==null) s=""; |
||||||
|
else s=o.toString(); |
||||||
|
|
||||||
|
buf.append(s.trim() + "^");} |
||||||
|
buf.append("^\n"); |
||||||
|
|
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
|
||||||
|
bw.write(buf.toString()); |
||||||
|
bw.close(); |
||||||
|
fw.close(); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
System.out.println("done"); |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,67 +1,69 @@ |
|||||||
package de.memtext.db.dataexchange; |
package de.memtext.db.dataexchange; |
||||||
|
|
||||||
/** |
/** |
||||||
* Insert the type's description here. |
* Insert the type's description here. |
||||||
* Creation date: (29.11.2002 16:53:06) |
* Creation date: (29.11.2002 16:53:06) |
||||||
* @author: |
* @author: |
||||||
*/ |
*/ |
||||||
public class MyRequest implements java.io.Serializable { |
public class MyRequest implements java.io.Serializable { |
||||||
static final long serialVersionUID = -2L; |
static final long serialVersionUID = -2L; |
||||||
|
static final int NORMAL=1; |
||||||
static final int NORMAL = 1; |
static final int EXPECT_ONE_UPDATE=2; |
||||||
|
|
||||||
static final int EXPECT_ONE_UPDATE = 2; |
private String sql; |
||||||
|
private String name; |
||||||
private String sql; |
private Object[] params; |
||||||
|
private int type; |
||||||
private String name; |
public MyRequest(String name,String sql,Object[] params) |
||||||
|
{ |
||||||
private Object[] params; |
this(name,sql,params,NORMAL); |
||||||
|
} |
||||||
private int type; |
public MyRequest(String name,String sql,Object[] params,int type) |
||||||
|
{ |
||||||
public MyRequest(String name, String sql, Object[] params) { |
setName(name); |
||||||
this(name, sql, params, NORMAL); |
setSql(sql); |
||||||
} |
setParams(params); |
||||||
|
setType(type); |
||||||
public MyRequest(String name, String sql, Object[] params, int type) { |
} |
||||||
setName(name); |
|
||||||
setSql(sql); |
public int getType() |
||||||
setParams(params); |
{ |
||||||
setType(type); |
return type; |
||||||
} |
} |
||||||
|
|
||||||
public int getType() { |
public void setType(int type) |
||||||
return type; |
{ |
||||||
} |
this.type=type; |
||||||
|
} |
||||||
public void setType(int type) { |
public String getName() |
||||||
this.type = type; |
{ |
||||||
} |
return name; |
||||||
|
} |
||||||
public String getName() { |
|
||||||
return name; |
public void setName(String name) |
||||||
} |
{ |
||||||
|
this.name=name; |
||||||
public void setName(String name) { |
} |
||||||
this.name = name; |
|
||||||
} |
public Object[] getParams() |
||||||
|
{ |
||||||
public Object[] getParams() { |
return params; |
||||||
return params; |
} |
||||||
} |
|
||||||
|
public void setParams(Object[] params) |
||||||
public void setParams(Object[] params) { |
{ |
||||||
this.params = params; |
this.params=params; |
||||||
} |
} |
||||||
|
|
||||||
public String getSql() { |
public String getSql() |
||||||
return sql; |
{ |
||||||
} |
return sql; |
||||||
|
} |
||||||
public void setSql(String sql) { |
|
||||||
this.sql = sql; |
public void setSql(String sql) |
||||||
} |
{ |
||||||
|
this.sql=sql; |
||||||
} |
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|||||||
@ -1,61 +1,49 @@ |
|||||||
package de.memtext.db.dataexchange; |
package de.memtext.db.dataexchange; |
||||||
|
|
||||||
import java.util.Vector; |
import java.util.Vector; |
||||||
|
/** |
||||||
/** |
* Insert the type's description here. |
||||||
* Insert the type's description here. |
* Creation date: (28.11.2002 19:25:34) |
||||||
* Creation date: (28.11.2002 19:25:34) |
* @author: |
||||||
* @author: |
*/ |
||||||
*/ |
public class MyServletResponse implements java.io.Serializable { |
||||||
public class MyServletResponse implements java.io.Serializable { |
static final long serialVersionUID = -3L; |
||||||
static final long serialVersionUID = -3L; |
private Vector result; |
||||||
|
private boolean OK; |
||||||
private Vector result; |
private Exception exception; |
||||||
|
private int updatedRowsCount; |
||||||
private boolean OK; |
|
||||||
|
/** |
||||||
private Exception exception; |
* MyServletResponse constructor comment. |
||||||
|
*/ |
||||||
private int updatedRowsCount; |
public MyServletResponse(Vector result, boolean OK, Exception exception) { |
||||||
|
this.result = result; |
||||||
/** |
this.OK = OK; |
||||||
* MyServletResponse constructor comment. |
this.exception = exception; |
||||||
*/ |
} |
||||||
public MyServletResponse(Vector result, boolean OK, Exception exception) { |
public Exception getException() { |
||||||
this.result = result; |
return exception; |
||||||
this.OK = OK; |
} |
||||||
this.exception = exception; |
public Vector getResult() { |
||||||
} |
return result; |
||||||
|
} |
||||||
public Exception getException() { |
public boolean isOK() { |
||||||
return exception; |
return OK; |
||||||
} |
} |
||||||
|
public void setException(Exception exception) { |
||||||
public Vector getResult() { |
this.exception = exception; |
||||||
return result; |
} |
||||||
} |
public void setOK(boolean OK) { |
||||||
|
this.OK = OK; |
||||||
public boolean isOK() { |
} |
||||||
return OK; |
public void setResult(Vector result) { |
||||||
} |
this.result = result; |
||||||
|
} |
||||||
public void setException(Exception exception) { |
public int getUpdatedRowsCount() { |
||||||
this.exception = exception; |
return updatedRowsCount; |
||||||
} |
} |
||||||
|
|
||||||
public void setOK(boolean OK) { |
public void setUpdatedRowsCount(int updatedRowsCount) { |
||||||
this.OK = OK; |
this.updatedRowsCount = updatedRowsCount; |
||||||
} |
} |
||||||
|
|
||||||
public void setResult(Vector result) { |
|
||||||
this.result = result; |
|
||||||
} |
|
||||||
|
|
||||||
public int getUpdatedRowsCount() { |
|
||||||
return updatedRowsCount; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUpdatedRowsCount(int updatedRowsCount) { |
|
||||||
this.updatedRowsCount = updatedRowsCount; |
|
||||||
} |
|
||||||
} |
} |
||||||
@ -1,46 +1,49 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Dimension; |
import java.awt.Dimension; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
|
|
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
|
|
||||||
import de.memtext.util.BrowserLauncher; |
import de.memtext.util.BrowserLauncher; |
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.util.WindowUtils; |
||||||
import de.memtext.widgets.VerticalBox; |
import de.memtext.widgets.VerticalBox; |
||||||
|
|
||||||
public class AboutDialog extends OkDlg { |
public class AboutDialog extends OkDlg { |
||||||
private JLabel infoLbl, homepageLabel; |
private JLabel infoLbl, homepageLabel; |
||||||
|
public AboutDialog( |
||||||
public AboutDialog(Frame parent, String title, String infoText, String homePageLink, final String homepageUrl) throws HeadlessException { |
Frame parent, |
||||||
super(parent, title); |
String title, |
||||||
infoLbl = new JLabel(infoText); |
String infoText, |
||||||
homepageLabel = new JLabel("<html><u>" + homePageLink); |
String homePageLink, |
||||||
homepageLabel.addMouseListener(new java.awt.event.MouseAdapter() { |
final String homepageUrl) |
||||||
|
throws HeadlessException { |
||||||
@Override |
super(parent, title); |
||||||
public void mouseClicked(java.awt.event.MouseEvent evt) { |
infoLbl = new JLabel(infoText); |
||||||
|
homepageLabel = new JLabel("<html><u>" + homePageLink); |
||||||
try { |
homepageLabel.addMouseListener(new java.awt.event.MouseAdapter() { |
||||||
BrowserLauncher.openURL(homepageUrl); |
public void mouseClicked(java.awt.event.MouseEvent evt) { |
||||||
} catch (IOException e) { |
|
||||||
e.printStackTrace(); |
try { |
||||||
} |
BrowserLauncher.openURL(homepageUrl); |
||||||
} |
} catch (IOException e) { |
||||||
}); |
e.printStackTrace(); |
||||||
|
} |
||||||
VerticalBox vbox = new VerticalBox(); |
} |
||||||
vbox.addWithCenterAlignment(infoLbl); |
}); |
||||||
vbox.addWithCenterAlignment(homepageLabel); |
|
||||||
setCenter(vbox); |
VerticalBox vbox = new VerticalBox(); |
||||||
pack(); |
vbox.addWithCenterAlignment(infoLbl); |
||||||
Dimension size = this.getSize(); |
vbox.addWithCenterAlignment(homepageLabel); |
||||||
setSize(size.width + 30, size.height + 30); |
setCenter(vbox); |
||||||
WindowUtils.center(this); |
pack(); |
||||||
} |
Dimension size = this.getSize(); |
||||||
|
setSize(size.width + 30, size.height + 30); |
||||||
} |
WindowUtils.center(this); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
//Created on 18.06.2004 at 12:20:35
|
//Created on 18.06.2004 at 12:20:35
|
||||||
@ -1,106 +1,113 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
||||||
import java.awt.Dialog; |
import java.awt.Dialog; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.GraphicsConfiguration; |
import java.awt.GraphicsConfiguration; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowAdapter; |
||||||
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
||||||
|
|
||||||
import javax.swing.JComponent; |
import javax.swing.JComponent; |
||||||
import javax.swing.JDialog; |
import javax.swing.JDialog; |
||||||
|
|
||||||
public class DialogWithExit extends JDialog { |
public class DialogWithExit extends JDialog { |
||||||
|
|
||||||
public DialogWithExit() throws HeadlessException { |
public DialogWithExit() throws HeadlessException { |
||||||
super(); |
super(); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Frame owner) throws HeadlessException { |
public DialogWithExit(Frame owner) throws HeadlessException { |
||||||
super(owner); |
super(owner); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Frame owner, boolean arg1) throws HeadlessException { |
public DialogWithExit(Frame owner, boolean arg1) throws HeadlessException { |
||||||
super(owner, arg1); |
super(owner, arg1); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Frame owner, String arg1) throws HeadlessException { |
public DialogWithExit(Frame owner, String arg1) throws HeadlessException { |
||||||
super(owner, arg1); |
super(owner, arg1); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Frame owner, String arg1, boolean arg2) throws HeadlessException { |
public DialogWithExit(Frame owner, String arg1, boolean arg2) |
||||||
super(owner, arg1, arg2); |
throws HeadlessException { |
||||||
initMe(); |
super(owner, arg1, arg2); |
||||||
} |
initMe(); |
||||||
|
} |
||||||
public DialogWithExit(Frame owner, String arg1, boolean arg2, GraphicsConfiguration arg3) { |
|
||||||
super(owner, arg1, arg2, arg3); |
public DialogWithExit( |
||||||
initMe(); |
Frame owner, |
||||||
} |
String arg1, |
||||||
|
boolean arg2, |
||||||
public DialogWithExit(Dialog owner) throws HeadlessException { |
GraphicsConfiguration arg3) { |
||||||
super(owner); |
super(owner, arg1, arg2, arg3); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Dialog owner, boolean arg1) throws HeadlessException { |
public DialogWithExit(Dialog owner) throws HeadlessException { |
||||||
super(owner, arg1); |
super(owner); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Dialog owner, String arg1) throws HeadlessException { |
public DialogWithExit(Dialog owner, boolean arg1) throws HeadlessException { |
||||||
super(owner, arg1); |
super(owner, arg1); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Dialog owner, String arg1, boolean arg2) throws HeadlessException { |
public DialogWithExit(Dialog owner, String arg1) throws HeadlessException { |
||||||
super(owner, arg1, arg2); |
super(owner, arg1); |
||||||
} |
initMe(); |
||||||
|
} |
||||||
public DialogWithExit(Dialog owner, String arg1, boolean arg2, GraphicsConfiguration arg3) throws HeadlessException { |
|
||||||
super(owner, arg1, arg2, arg3); |
public DialogWithExit(Dialog owner, String arg1, boolean arg2) |
||||||
initMe(); |
throws HeadlessException { |
||||||
} |
super(owner, arg1, arg2); |
||||||
|
} |
||||||
private void initMe() { |
|
||||||
addWindowListener(new WindowAdapter() { |
public DialogWithExit( |
||||||
@Override |
Dialog owner, |
||||||
public void windowClosing(WindowEvent we) { |
String arg1, |
||||||
exit(); |
boolean arg2, |
||||||
} |
GraphicsConfiguration arg3) |
||||||
}); |
throws HeadlessException { |
||||||
} |
super(owner, arg1, arg2, arg3); |
||||||
|
initMe(); |
||||||
/** |
} |
||||||
* called if window is closed, does nothing by default, |
private void initMe(){ |
||||||
* subclasses can override |
addWindowListener(new WindowAdapter() { |
||||||
* |
public void windowClosing(WindowEvent we) { |
||||||
*/ |
exit(); |
||||||
protected void exit() { |
} |
||||||
} |
}); |
||||||
|
} |
||||||
//man könnte noch abfragen ob auch wirklich Borderlayout benutzt
|
/** |
||||||
//wird
|
* called if window is closed, does nothing by default, |
||||||
/** |
* subclasses can override |
||||||
* installs a component in the center of the dialog |
* |
||||||
* @param comp |
*/ |
||||||
*/ |
protected void exit() { |
||||||
public void setCenter(JComponent comp) { |
} |
||||||
this.getContentPane().add(comp, BorderLayout.CENTER); |
|
||||||
} |
//man könnte noch abfragen ob auch wirklich Borderlayout benutzt
|
||||||
|
//wird
|
||||||
/** |
/** |
||||||
* installs a component in the notrh of the dialog |
* installs a component in the center of the dialog |
||||||
* @param comp |
* @param comp |
||||||
*/ |
*/ |
||||||
public void setNorth(JComponent comp) { |
public void setCenter(JComponent comp) { |
||||||
this.getContentPane().add(comp, BorderLayout.NORTH); |
this.getContentPane().add(comp, BorderLayout.CENTER); |
||||||
} |
} |
||||||
} |
/** |
||||||
|
* installs a component in the notrh of the dialog |
||||||
|
* @param comp |
||||||
|
*/ |
||||||
|
public void setNorth(JComponent comp) { |
||||||
|
this.getContentPane().add(comp, BorderLayout.NORTH); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 21.11.2003
|
//Created on 21.11.2003
|
||||||
@ -1,57 +1,57 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Component; |
import java.awt.Component; |
||||||
import java.text.ParseException; |
import java.text.ParseException; |
||||||
|
|
||||||
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
||||||
|
|
||||||
import de.memtext.util.DateUtils; |
import de.memtext.util.DateUtils; |
||||||
import de.memtext.widgets.WarningMessage; |
import de.memtext.widgets.WarningMessage; |
||||||
|
|
||||||
public class EnterDateDlg { |
public class EnterDateDlg { |
||||||
private java.util.Date date; |
private java.util.Date date; |
||||||
|
private Component parentComp; |
||||||
private Component parentComp; |
private String title, text; |
||||||
|
|
||||||
private String title, text; |
public EnterDateDlg(Component parentComp, String text, String title) { |
||||||
|
this.parentComp = parentComp; |
||||||
public EnterDateDlg(Component parentComp, String text, String title) { |
this.title = title; |
||||||
this.parentComp = parentComp; |
this.text = text; |
||||||
this.title = title; |
} |
||||||
this.text = text; |
|
||||||
} |
public boolean wasOkSelected() |
||||||
|
{ |
||||||
public boolean wasOkSelected() { |
return date!=null; |
||||||
return date != null; |
} |
||||||
} |
public void show() { |
||||||
|
date = null; |
||||||
public void show() { |
String in; |
||||||
date = null; |
boolean ok = false; |
||||||
String in; |
while (!ok) { |
||||||
boolean ok = false; |
in = JOptionPane.showInputDialog(parentComp, text, title, |
||||||
while (!ok) { |
JOptionPane.QUESTION_MESSAGE); |
||||||
in = JOptionPane.showInputDialog(parentComp, text, title, JOptionPane.QUESTION_MESSAGE); |
if (in == null) { |
||||||
if (in == null) { |
date = null; |
||||||
date = null; |
ok = true; |
||||||
ok = true; |
} else { |
||||||
} else { |
try { |
||||||
try { |
date = DateUtils.parse(in); |
||||||
date = DateUtils.parse(in); |
ok = true; |
||||||
ok = true; |
} catch (ParseException e) { |
||||||
} catch (ParseException e) { |
WarningMessage.show(parentComp, "Ungültige Datumseingabe", |
||||||
WarningMessage.show(parentComp, "Ungültige Datumseingabe", title); |
title); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public static void main(String args[]) { |
public static void main(String args[]) { |
||||||
new EnterDateDlg(null, "test", "title").show(); |
new EnterDateDlg(null, "test", "title").show(); |
||||||
} |
} |
||||||
|
|
||||||
public java.util.Date getDate() { |
public java.util.Date getDate() { |
||||||
return date; |
return date; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
//Created on 18.08.2004 at 12:36:12
|
//Created on 18.08.2004 at 12:36:12
|
||||||
|
|||||||
@ -1,62 +1,63 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.io.File; |
import java.io.File; |
||||||
|
|
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
|
|
||||||
import de.memtext.util.FilenamesFilter; |
import de.memtext.util.FilenamesFilter; |
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.util.WindowUtils; |
||||||
import de.memtext.widgets.FileSelectionPanel; |
import de.memtext.widgets.FileSelectionPanel; |
||||||
import de.memtext.widgets.VerticalBox; |
import de.memtext.widgets.VerticalBox; |
||||||
|
|
||||||
public class ImportDlg extends OkCancelDlg { |
public class ImportDlg extends OkCancelDlg { |
||||||
private JLabel lblTop = new JLabel(); |
private JLabel lblTop = new JLabel(); |
||||||
|
private FileSelectionPanel fsp = new FileSelectionPanel("Datei"); |
||||||
private FileSelectionPanel fsp = new FileSelectionPanel("Datei"); |
|
||||||
|
public ImportDlg(Frame owner, String title, String infoTxt) { |
||||||
public ImportDlg(Frame owner, String title, String infoTxt) { |
super(owner, title, true); |
||||||
super(owner, title, true); |
VerticalBox vbox = new VerticalBox(); |
||||||
VerticalBox vbox = new VerticalBox(); |
lblTop.setText(infoTxt); |
||||||
lblTop.setText(infoTxt); |
vbox.add(lblTop); |
||||||
vbox.add(lblTop); |
vbox.add(fsp); |
||||||
vbox.add(fsp); |
setCenter(vbox); |
||||||
setCenter(vbox); |
this.pack(); |
||||||
this.pack(); |
WindowUtils.center(this); |
||||||
WindowUtils.center(this); |
|
||||||
|
} |
||||||
} |
|
||||||
|
public void setCurrentDir(File defaultdir) |
||||||
public void setCurrentDir(File defaultdir) { |
{ |
||||||
fsp.setCurrentDir(defaultdir); |
fsp.setCurrentDir(defaultdir); |
||||||
} |
} |
||||||
|
/** |
||||||
/** |
|
||||||
|
* @param endings |
||||||
* @param endings |
*/ |
||||||
*/ |
public void setFileFilter(String endings) { |
||||||
public void setFileFilter(String endings) { |
fsp.setFileFilter(new FilenamesFilter("CSV oder XML Dateien", endings)); |
||||||
fsp.setFileFilter(new FilenamesFilter("CSV oder XML Dateien", endings)); |
} |
||||||
} |
|
||||||
|
protected void performOk() { |
||||||
@Override |
this.dispose(); |
||||||
protected void performOk() { |
} |
||||||
this.dispose(); |
|
||||||
} |
protected void performCancel() { |
||||||
|
this.dispose(); |
||||||
@Override |
} |
||||||
protected void performCancel() { |
|
||||||
this.dispose(); |
public File getSelectedFile() { |
||||||
} |
return fsp.getSelectedFile(); |
||||||
|
} |
||||||
public File getSelectedFile() { |
|
||||||
return fsp.getSelectedFile(); |
public static void main(String[] args) { |
||||||
} |
ImportDlg d = |
||||||
|
new ImportDlg( |
||||||
public static void main(String[] args) { |
null, |
||||||
ImportDlg d = new ImportDlg(null, "titl", "Unfälle importieren aus CSV- oder XML-Datei (z.B. Universum Unfallanzeige 3.0)"); |
"titl", |
||||||
d.setFileFilter(".xml|.csv"); |
"Unfälle importieren aus CSV- oder XML-Datei (z.B. Universum Unfallanzeige 3.0)"); |
||||||
d.show(); |
d.setFileFilter(".xml|.csv"); |
||||||
} |
d.show(); |
||||||
} |
} |
||||||
|
} |
||||||
//Created on 19.02.2004 at 11:56:06
|
//Created on 19.02.2004 at 11:56:06
|
||||||
@ -1,34 +1,40 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
||||||
|
|
||||||
/** |
/** |
||||||
Convienience class to create and Input Dialog with JOptionPane. |
Convienience class to create and Input Dialog with JOptionPane. |
||||||
I.e. selection item from drop down (combobox) |
I.e. selection item from drop down (combobox) |
||||||
*/ |
*/ |
||||||
public class InputDialog { |
public class InputDialog { |
||||||
private String title, txt; |
private String title, txt; |
||||||
|
private ArrayList list; |
||||||
private ArrayList list; |
|
||||||
|
public InputDialog(Collection col, String title, String txt) { |
||||||
public InputDialog(Collection col, String title, String txt) { |
super(); |
||||||
super(); |
this.title = title; |
||||||
this.title = title; |
this.txt = txt; |
||||||
this.txt = txt; |
list = new ArrayList(); |
||||||
list = new ArrayList(); |
if (col==null||col.size()==0) throw new IllegalArgumentException("Collection mustn't be null or empty"); |
||||||
if (col == null || col.size() == 0) throw new IllegalArgumentException("Collection mustn't be null or empty"); |
for (Iterator it = col.iterator(); it.hasNext();) { |
||||||
for (Iterator it = col.iterator(); it.hasNext();) { |
list.add(it.next()); |
||||||
list.add(it.next()); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
public Object show() { |
||||||
public Object show() { |
return JOptionPane.showInputDialog( |
||||||
return JOptionPane.showInputDialog(null, txt, title, JOptionPane.QUESTION_MESSAGE, null, list.toArray(), null); |
null, |
||||||
} |
txt, |
||||||
} |
title, |
||||||
|
JOptionPane.QUESTION_MESSAGE, |
||||||
|
null, |
||||||
|
list.toArray(), |
||||||
|
null); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,74 +1,67 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import javax.swing.JFrame; |
import javax.swing.JFrame; |
||||||
|
|
||||||
import de.memtext.widgets.LabeledPasswordField; |
import de.memtext.widgets.LabeledPasswordField; |
||||||
import de.memtext.widgets.LabeledTextField; |
import de.memtext.widgets.LabeledTextField; |
||||||
import de.memtext.widgets.MultilineEditPanel; |
import de.memtext.widgets.MultilineEditPanel; |
||||||
|
|
||||||
/** |
/** |
||||||
A Login Dialog |
A Login Dialog |
||||||
*/ |
*/ |
||||||
public class LoginDlg extends OkCancelDlg { |
public class LoginDlg extends OkCancelDlg { |
||||||
private LabeledTextField lUser = new LabeledTextField("Kennung", 15); |
private LabeledTextField lUser = new LabeledTextField("Kennung", 15); |
||||||
|
private LabeledPasswordField lPass = |
||||||
private LabeledPasswordField lPass = new LabeledPasswordField("Passwort", 15); |
new LabeledPasswordField("Passwort", 15); |
||||||
|
public LoginDlg(JFrame frame, String title) { |
||||||
public LoginDlg(JFrame frame, String title) { |
super(frame, title,true); |
||||||
super(frame, title, true); |
initdlg(); |
||||||
initdlg(); |
} |
||||||
} |
|
||||||
|
private void initdlg() { |
||||||
private void initdlg() { |
MultilineEditPanel vbox = new MultilineEditPanel(); |
||||||
MultilineEditPanel vbox = new MultilineEditPanel(); |
vbox.add(lUser); |
||||||
vbox.add(lUser); |
vbox.add(lPass); |
||||||
vbox.add(lPass); |
this.setCenter(vbox); |
||||||
this.setCenter(vbox); |
this.pack(); |
||||||
this.pack(); |
} |
||||||
} |
|
||||||
|
protected void performOk() { |
||||||
@Override |
this.hide(); |
||||||
protected void performOk() { |
} |
||||||
this.hide(); |
public void setUsername(String username) |
||||||
} |
{ |
||||||
|
lUser.setValue(username); |
||||||
public void setUsername(String username) { |
} |
||||||
lUser.setValue(username); |
public void setPassword(String password) |
||||||
} |
{ |
||||||
|
lPass.setValue(password); |
||||||
public void setPassword(String password) { |
} |
||||||
lPass.setValue(password); |
protected void performCancel() { |
||||||
} |
this.hide(); |
||||||
|
} |
||||||
@Override |
public String getUsername() { |
||||||
protected void performCancel() { |
return lUser.getValue().toString(); |
||||||
this.hide(); |
} |
||||||
} |
/** |
||||||
|
* can be returned only once, cleared for security reasons |
||||||
public String getUsername() { |
* afterwards |
||||||
return lUser.getValue().toString(); |
* @return |
||||||
} |
*/ |
||||||
|
public String getPassword() { |
||||||
/** |
/* char[] pw = passw.getPassword(); |
||||||
* can be returned only once, cleared for security reasons |
String result = new String(pw); |
||||||
* afterwards |
for (int i = 0; i < pw.length; i++) { |
||||||
* @return |
pw[i] = 0; |
||||||
*/ |
} |
||||||
public String getPassword() { |
return result; |
||||||
/* char[] pw = passw.getPassword(); |
*/ |
||||||
String result = new String(pw); |
return lPass.getValue().toString(); |
||||||
for (int i = 0; i < pw.length; i++) { |
} |
||||||
pw[i] = 0; |
public static void main(String args[]) { |
||||||
} |
LoginDlg d=new LoginDlg(null,"asdf"); |
||||||
return result; |
d.show(); |
||||||
*/ |
System.out.println(d.getPassword()); |
||||||
return lPass.getValue().toString(); |
|
||||||
} |
} |
||||||
|
} |
||||||
public static void main(String args[]) { |
|
||||||
LoginDlg d = new LoginDlg(null, "asdf"); |
|
||||||
d.show(); |
|
||||||
System.out.println(d.getPassword()); |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,132 +1,113 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Dimension; |
import java.awt.Dimension; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowAdapter; |
||||||
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
||||||
|
|
||||||
import javax.swing.JScrollPane; |
import javax.swing.JScrollPane; |
||||||
import javax.swing.JTree; |
import javax.swing.JTree; |
||||||
import javax.swing.tree.DefaultTreeModel; |
import javax.swing.tree.DefaultTreeModel; |
||||||
import javax.swing.tree.TreeCellRenderer; |
import javax.swing.tree.TreeCellRenderer; |
||||||
import javax.swing.tree.TreeNode; |
import javax.swing.tree.TreeNode; |
||||||
|
|
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.util.WindowUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* A dialog that presents a tree and allows the selection of |
* A dialog that presents a tree and allows the selection of |
||||||
* one node or to clear the selection |
* one node or to clear the selection |
||||||
*/ |
*/ |
||||||
public class NodeSelectionDlg extends OkCancelClearDlg { |
public class NodeSelectionDlg extends OkCancelClearDlg { |
||||||
private JTree tree; |
private JTree tree; |
||||||
|
private Object selectedNode = null; |
||||||
private Object selectedNode = null; |
private String title; |
||||||
|
public NodeSelectionDlg(Frame owner, String title, JTree tree) { |
||||||
private String title; |
super(owner, title); |
||||||
|
this.tree = tree; |
||||||
public NodeSelectionDlg(Frame owner, String title, JTree tree) { |
this.title=title; |
||||||
super(owner, title); |
this.setCenter(new JScrollPane(tree)); |
||||||
this.tree = tree; |
selectedNode = null; |
||||||
this.title = title; |
if (tree.getLastSelectedPathComponent() != null) |
||||||
this.setCenter(new JScrollPane(tree)); |
selectedNode = (TreeNode) tree.getLastSelectedPathComponent(); |
||||||
selectedNode = null; |
this.pack(); |
||||||
if (tree.getLastSelectedPathComponent() != null) selectedNode = (TreeNode) tree.getLastSelectedPathComponent(); |
WindowUtils.center(this); |
||||||
this.pack(); |
addWindowListener(new WindowAdapter() { |
||||||
WindowUtils.center(this); |
public void windowClosing(WindowEvent we) { |
||||||
addWindowListener(new WindowAdapter() { |
exit(); |
||||||
@Override |
} |
||||||
public void windowClosing(WindowEvent we) { |
}); |
||||||
exit(); |
} |
||||||
} |
/** |
||||||
}); |
* called if window is closed, does nothing by default, |
||||||
} |
* subclasses can override |
||||||
|
* |
||||||
/** |
*/ |
||||||
* called if window is closed, does nothing by default, |
protected void exit() { |
||||||
* subclasses can override |
} |
||||||
* |
|
||||||
*/ |
public NodeSelectionDlg( |
||||||
@Override |
Frame owner, |
||||||
protected void exit() { |
String title, |
||||||
} |
DefaultTreeModel treeModel) { |
||||||
|
this(owner, title, new JTree(treeModel)); |
||||||
public NodeSelectionDlg(Frame owner, String title, DefaultTreeModel treeModel) { |
} |
||||||
this(owner, title, new JTree(treeModel)); |
public NodeSelectionDlg(Frame owner, String title, TreeNode node) { |
||||||
} |
this(owner, title, new JTree(node)); |
||||||
|
} |
||||||
public NodeSelectionDlg(Frame owner, String title, TreeNode node) { |
/** |
||||||
this(owner, title, new JTree(node)); |
* can be overriden by subclasses to perform a check if |
||||||
} |
* the selected node is OK |
||||||
|
* @return |
||||||
/** |
*/ |
||||||
* can be overriden by subclasses to perform a check if |
protected boolean isSelectedNodeOk(TreeNode testme) |
||||||
* the selected node is OK |
{ |
||||||
* @return |
return true; |
||||||
*/ |
} |
||||||
protected boolean isSelectedNodeOk(TreeNode testme) { |
protected void performOk() { |
||||||
return true; |
if (!isSelectedNodeOk((TreeNode)tree.getLastSelectedPathComponent())) return; |
||||||
} |
selectedNode = tree.getLastSelectedPathComponent(); |
||||||
|
this.setVisible(false); |
||||||
@Override |
} |
||||||
protected void performOk() { |
|
||||||
if (!isSelectedNodeOk((TreeNode) tree.getLastSelectedPathComponent())) return; |
protected void performCancel() { |
||||||
selectedNode = tree.getLastSelectedPathComponent(); |
this.setVisible(false); |
||||||
this.setVisible(false); |
} |
||||||
} |
public TreeNode getSelectedNode() { |
||||||
|
return selectedNode == null ? null : (TreeNode) selectedNode; |
||||||
@Override |
} |
||||||
protected void performCancel() { |
protected void performClear() { |
||||||
this.setVisible(false); |
selectedNode = null; |
||||||
} |
tree.clearSelection(); |
||||||
|
this.setVisible(false); |
||||||
public TreeNode getSelectedNode() { |
} |
||||||
return selectedNode == null ? null : (TreeNode) selectedNode; |
public void setSize(Dimension dim) { |
||||||
} |
super.setSize(dim); |
||||||
|
WindowUtils.center(this); |
||||||
@Override |
} |
||||||
protected void performClear() { |
public void setSize(int x, int y) { |
||||||
selectedNode = null; |
super.setSize(x, y); |
||||||
tree.clearSelection(); |
WindowUtils.center(this); |
||||||
this.setVisible(false); |
} |
||||||
} |
public static void main(String a[]) { |
||||||
|
NodeSelectionDlg t = new NodeSelectionDlg(null, "adsf", new JTree()); |
||||||
@Override |
t.pack(); |
||||||
public void setSize(Dimension dim) { |
t.show(); |
||||||
super.setSize(dim); |
System.out.println(t.getSelectedNode()); |
||||||
WindowUtils.center(this); |
t.show(); |
||||||
} |
System.out.println(t.getSelectedNode()); |
||||||
|
} |
||||||
@Override |
public void setNode(TreeNode node) { |
||||||
public void setSize(int x, int y) { |
tree.setModel(new DefaultTreeModel(node)); |
||||||
super.setSize(x, y); |
selectedNode=null; |
||||||
WindowUtils.center(this); |
} |
||||||
} |
public void setCellRenderer(TreeCellRenderer renderer) { |
||||||
|
tree.setCellRenderer(renderer); |
||||||
public static void main(String a[]) { |
} |
||||||
NodeSelectionDlg t = new NodeSelectionDlg(null, "adsf", new JTree()); |
public String getTitle() { |
||||||
t.pack(); |
return title; |
||||||
t.show(); |
} |
||||||
System.out.println(t.getSelectedNode()); |
public String getInfoText() { |
||||||
t.show(); |
return title; |
||||||
System.out.println(t.getSelectedNode()); |
} |
||||||
} |
} |
||||||
|
|
||||||
public void setNode(TreeNode node) { |
|
||||||
tree.setModel(new DefaultTreeModel(node)); |
|
||||||
selectedNode = null; |
|
||||||
} |
|
||||||
|
|
||||||
public void setCellRenderer(TreeCellRenderer renderer) { |
|
||||||
tree.setCellRenderer(renderer); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String getTitle() { |
|
||||||
return title; |
|
||||||
} |
|
||||||
|
|
||||||
public String getInfoText() { |
|
||||||
return title; |
|
||||||
} |
|
||||||
} |
|
||||||
//Created on 17.11.2003
|
//Created on 17.11.2003
|
||||||
@ -1,56 +1,54 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
import javax.swing.JScrollPane; |
import javax.swing.JScrollPane; |
||||||
|
|
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.widgets.ObjectCheckBox; |
||||||
import de.memtext.widgets.ObjectCheckBox; |
import de.memtext.widgets.VerticalBox; |
||||||
import de.memtext.widgets.VerticalBox; |
import de.memtext.util.WindowUtils; |
||||||
|
|
||||||
public class ObjectCheckBoxDlg extends OkCancelDlg { |
public class ObjectCheckBoxDlg extends OkCancelDlg { |
||||||
private List boxList = new LinkedList(); |
private List boxList = new LinkedList(); |
||||||
|
private List selectedObjectsList; |
||||||
private List selectedObjectsList; |
public ObjectCheckBoxDlg(Frame frame, String title, List itemList,boolean selected) |
||||||
|
throws HeadlessException { |
||||||
public ObjectCheckBoxDlg(Frame frame, String title, List itemList, boolean selected) throws HeadlessException { |
super(frame, title); |
||||||
super(frame, title); |
VerticalBox vbox = new VerticalBox(); |
||||||
VerticalBox vbox = new VerticalBox(); |
for (Iterator it = itemList.iterator(); it.hasNext();) { |
||||||
for (Iterator it = itemList.iterator(); it.hasNext();) { |
Object element = (Object) it.next(); |
||||||
Object element = (Object) it.next(); |
ObjectCheckBox cb = new ObjectCheckBox(element,selected); |
||||||
ObjectCheckBox cb = new ObjectCheckBox(element, selected); |
boxList.add(cb); |
||||||
boxList.add(cb); |
vbox.add(cb); |
||||||
vbox.add(cb); |
} |
||||||
} |
this.setCenter(new JScrollPane(vbox)); |
||||||
this.setCenter(new JScrollPane(vbox)); |
this.pack(); |
||||||
this.pack(); |
WindowUtils.center(this); |
||||||
WindowUtils.center(this); |
} |
||||||
} |
|
||||||
|
protected void performOk() { |
||||||
@Override |
selectedObjectsList=new LinkedList(); |
||||||
protected void performOk() { |
for (Iterator it = boxList.iterator(); it.hasNext();) { |
||||||
selectedObjectsList = new LinkedList(); |
ObjectCheckBox element = (ObjectCheckBox) it.next(); |
||||||
for (Iterator it = boxList.iterator(); it.hasNext();) { |
if (element.isSelected()) |
||||||
ObjectCheckBox element = (ObjectCheckBox) it.next(); |
selectedObjectsList.add(element.getObject()); |
||||||
if (element.isSelected()) selectedObjectsList.add(element.getObject()); |
} |
||||||
} |
this.hide(); |
||||||
this.hide(); |
} |
||||||
} |
|
||||||
|
protected void performCancel() { |
||||||
@Override |
selectedObjectsList=new LinkedList(); |
||||||
protected void performCancel() { |
this.hide(); |
||||||
selectedObjectsList = new LinkedList(); |
} |
||||||
this.hide(); |
|
||||||
} |
public List getSelectedObjectsList() { |
||||||
|
return selectedObjectsList; |
||||||
public List getSelectedObjectsList() { |
} |
||||||
return selectedObjectsList; |
|
||||||
} |
} |
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
//Created on 26.11.2003 at 12:47:31
|
//Created on 26.11.2003 at 12:47:31
|
||||||
@ -1,80 +1,72 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JFrame; |
import javax.swing.JFrame; |
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
|
|
||||||
/** |
/** |
||||||
* Abstract Dialog in which OK or Cancel can be clicked. |
* Abstract Dialog in which OK or Cancel can be clicked. |
||||||
* Subclasses must implement performCancel and performOk. |
* Subclasses must implement performCancel and performOk. |
||||||
* setCenter for convenience. |
* setCenter for convenience. |
||||||
* |
* |
||||||
It's important that clients don't call |
It's important that clients don't call |
||||||
getContentPane().setLayout(new BorderLayout()) or something like that, |
getContentPane().setLayout(new BorderLayout()) or something like that, |
||||||
because that will cause southPanel to disappear |
because that will cause southPanel to disappear |
||||||
*/ |
*/ |
||||||
public abstract class OkCancelClearDlg extends OkCancelDlg { |
public abstract class OkCancelClearDlg |
||||||
private boolean wasClearSelected; |
extends OkCancelDlg |
||||||
|
{ |
||||||
protected JButton btnClear = new JButton("Leeren"); |
private boolean wasClearSelected; |
||||||
|
protected JButton btnClear = new JButton("Leeren"); |
||||||
/** |
/** |
||||||
* Constructor for OkCancelClearDlg. |
* Constructor for OkCancelClearDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @param arg1 |
* @param arg1 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkCancelClearDlg(Frame arg0, String title) throws HeadlessException { |
public OkCancelClearDlg(Frame arg0, String title) |
||||||
super(arg0, title, true); |
throws HeadlessException { |
||||||
initOkCancelClearDlg(); |
super(arg0, title, true); |
||||||
} |
initOkCancelClearDlg(); |
||||||
|
} |
||||||
private void initOkCancelClearDlg() { |
|
||||||
|
private void initOkCancelClearDlg() { |
||||||
btnClear.setActionCommand("Clear"); |
|
||||||
btnClear.addActionListener(new ActionListener() { |
btnClear.setActionCommand("Clear"); |
||||||
|
btnClear.addActionListener(new ActionListener() { |
||||||
@Override |
public void actionPerformed(ActionEvent ae) { |
||||||
public void actionPerformed(ActionEvent ae) { |
wasOkSelected = false; |
||||||
wasOkSelected = false; |
wasClearSelected = true; |
||||||
wasClearSelected = true; |
performClear(); |
||||||
performClear(); |
} |
||||||
} |
}); |
||||||
}); |
addAfterCancel(btnClear); |
||||||
addAfterCancel(btnClear); |
} |
||||||
} |
public boolean wasClearSelected() { |
||||||
|
return wasClearSelected; |
||||||
public boolean wasClearSelected() { |
} |
||||||
return wasClearSelected; |
protected abstract void performClear(); |
||||||
} |
public static void main(String[] args) { |
||||||
|
|
||||||
protected abstract void performClear(); |
OkCancelClearDlg dlg = new OkCancelClearDlg(new JFrame(), "test") { |
||||||
|
protected void performOk() { |
||||||
public static void main(String[] args) { |
} |
||||||
|
|
||||||
OkCancelClearDlg dlg = new OkCancelClearDlg(new JFrame(), "test") { |
protected void performCancel() { |
||||||
|
} |
||||||
@Override |
|
||||||
protected void performOk() { |
protected void performClear() { |
||||||
} |
} |
||||||
|
}; |
||||||
@Override |
|
||||||
protected void performCancel() { |
// dlg.addAboveOK(new JLabel("bla"));
|
||||||
} |
dlg.setCenter(new JLabel("cnter")); |
||||||
|
dlg.pack(); |
||||||
@Override |
dlg.show(); |
||||||
protected void performClear() { |
} |
||||||
} |
} |
||||||
}; |
|
||||||
|
|
||||||
// dlg.addAboveOK(new JLabel("bla"));
|
|
||||||
dlg.setCenter(new JLabel("cnter")); |
|
||||||
dlg.pack(); |
|
||||||
dlg.show(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,205 +1,200 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
||||||
import java.awt.Dialog; |
import java.awt.Dialog; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JComponent; |
import javax.swing.JComponent; |
||||||
import javax.swing.JFrame; |
import javax.swing.JFrame; |
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
|
|
||||||
import de.memtext.widgets.HorizontalBox; |
import de.memtext.widgets.HorizontalBox; |
||||||
import de.memtext.widgets.VerticalBox; |
import de.memtext.widgets.VerticalBox; |
||||||
|
|
||||||
/** |
/** |
||||||
* Abstract Dialog in which OK or Cancel can be clicked. |
* Abstract Dialog in which OK or Cancel can be clicked. |
||||||
* Subclasses must implement performCancel and performOk. |
* Subclasses must implement performCancel and performOk. |
||||||
* setCenter for convenience. |
* setCenter for convenience. |
||||||
* |
* |
||||||
It's important that clients don't call |
It's important that clients don't call |
||||||
getContentPane().setLayout(new BorderLayout()) or something like that, |
getContentPane().setLayout(new BorderLayout()) or something like that, |
||||||
because that will cause southPanel to disappear |
because that will cause southPanel to disappear |
||||||
*/ |
*/ |
||||||
public abstract class OkCancelDlg extends DialogWithExit { |
public abstract class OkCancelDlg |
||||||
private OkCancelPanel pOkCancel; |
extends DialogWithExit |
||||||
|
{ |
||||||
private HorizontalBox boxAboverOkCancel = new HorizontalBox(); |
private OkCancelPanel pOkCancel; |
||||||
|
private HorizontalBox boxAboverOkCancel = new HorizontalBox(); |
||||||
protected boolean wasOkSelected, wasCancelSelected; |
protected boolean wasOkSelected,wasCancelSelected; |
||||||
|
public OkCancelDlg(Frame owner, String title, boolean isModal) { |
||||||
public OkCancelDlg(Frame owner, String title, boolean isModal) { |
super(owner, title, isModal); |
||||||
super(owner, title, isModal); |
initOkCancelDlg(); |
||||||
initOkCancelDlg(); |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* Constructor for OkCancelDlg. |
||||||
* Constructor for OkCancelDlg. |
* @param arg0 |
||||||
* @param arg0 |
* @param arg1 |
||||||
* @param arg1 |
* @param arg2 |
||||||
* @param arg2 |
* @throws HeadlessException |
||||||
* @throws HeadlessException |
*/ |
||||||
*/ |
public OkCancelDlg(Frame frame, String title) throws HeadlessException { |
||||||
public OkCancelDlg(Frame frame, String title) throws HeadlessException { |
super(frame, title, true); |
||||||
super(frame, title, true); |
initOkCancelDlg(); |
||||||
initOkCancelDlg(); |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* Constructor for OkCancelDlg. |
||||||
* Constructor for OkCancelDlg. |
* @param arg0 |
||||||
* @param arg0 |
* @throws HeadlessException |
||||||
* @throws HeadlessException |
*/ |
||||||
*/ |
public OkCancelDlg(Dialog arg0) throws HeadlessException { |
||||||
public OkCancelDlg(Dialog arg0) throws HeadlessException { |
super(arg0, true); |
||||||
super(arg0, true); |
initOkCancelDlg(); |
||||||
initOkCancelDlg(); |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* Constructor for OkCancelDlg. |
||||||
* Constructor for OkCancelDlg. |
* @param arg0 |
||||||
* @param arg0 |
* @param arg1 |
||||||
* @param arg1 |
* @throws HeadlessException |
||||||
* @throws HeadlessException |
*/ |
||||||
*/ |
public OkCancelDlg(Dialog arg0, String arg1) throws HeadlessException { |
||||||
public OkCancelDlg(Dialog arg0, String arg1) throws HeadlessException { |
super(arg0, arg1, true); |
||||||
super(arg0, arg1, true); |
initOkCancelDlg(); |
||||||
initOkCancelDlg(); |
} |
||||||
} |
|
||||||
|
private void initOkCancelDlg() { |
||||||
private void initOkCancelDlg() { |
//this.setContentPane(new OneTimeInitContentPane());
|
||||||
//this.setContentPane(new OneTimeInitContentPane());
|
VerticalBox pSouth = new VerticalBox(); |
||||||
VerticalBox pSouth = new VerticalBox(); |
pOkCancel = new OkCancelPanel(); |
||||||
pOkCancel = new OkCancelPanel(); |
pSouth.add(boxAboverOkCancel); |
||||||
pSouth.add(boxAboverOkCancel); |
pSouth.add(pOkCancel); |
||||||
pSouth.add(pOkCancel); |
|
||||||
|
this.getContentPane().add(pSouth, BorderLayout.SOUTH); |
||||||
this.getContentPane().add(pSouth, BorderLayout.SOUTH); |
pOkCancel.addActionListener(new ActionListener(){ |
||||||
pOkCancel.addActionListener(new ActionListener() { |
public void actionPerformed(ActionEvent ae) |
||||||
|
{ |
||||||
@Override |
String cmd = ae.getActionCommand(); |
||||||
public void actionPerformed(ActionEvent ae) { |
if (cmd.equals("OK")) { |
||||||
String cmd = ae.getActionCommand(); |
wasOkSelected = true; |
||||||
if (cmd.equals("OK")) { |
wasCancelSelected=false; |
||||||
wasOkSelected = true; |
performOk(); |
||||||
wasCancelSelected = false; |
} |
||||||
performOk(); |
|
||||||
} |
if (cmd.equals("Cancel")) { |
||||||
|
wasOkSelected = false; |
||||||
if (cmd.equals("Cancel")) { |
wasCancelSelected=true; |
||||||
wasOkSelected = false; |
performCancel(); |
||||||
wasCancelSelected = true; |
} |
||||||
performCancel(); |
} |
||||||
} |
}); |
||||||
} |
this.getRootPane().setDefaultButton(pOkCancel.getBtnOk()); |
||||||
}); |
} |
||||||
this.getRootPane().setDefaultButton(pOkCancel.getBtnOk()); |
public void addAboveOK(JComponent comp) { |
||||||
} |
boxAboverOkCancel.add(comp); |
||||||
|
} |
||||||
public void addAboveOK(JComponent comp) { |
|
||||||
boxAboverOkCancel.add(comp); |
public boolean wasOkSelected() { |
||||||
} |
return wasOkSelected; |
||||||
|
} |
||||||
public boolean wasOkSelected() { |
public boolean wasCancelSelected() { |
||||||
return wasOkSelected; |
return wasCancelSelected; |
||||||
} |
} |
||||||
|
/** |
||||||
public boolean wasCancelSelected() { |
* subclasses must implement this method and specify commands |
||||||
return wasCancelSelected; |
* to be executed when OK was clicked |
||||||
} |
*/ |
||||||
|
protected abstract void performOk(); |
||||||
/** |
/** |
||||||
* subclasses must implement this method and specify commands |
* subclasses must implement this method and specify commands |
||||||
* to be executed when OK was clicked |
* to be executed when Cancel was clicked |
||||||
*/ |
* |
||||||
protected abstract void performOk(); |
*/ |
||||||
|
protected abstract void performCancel(); |
||||||
/** |
/** |
||||||
* subclasses must implement this method and specify commands |
* Adds a Component before the OK button |
||||||
* to be executed when Cancel was clicked |
* @param comp |
||||||
* |
*/ |
||||||
*/ |
public void addBeforeOK(JComponent comp) { |
||||||
protected abstract void performCancel(); |
int pos = |
||||||
|
de.memtext.util.ComponentUtils.getPositionOnComponent( |
||||||
/** |
pOkCancel.getBtnOk(), |
||||||
* Adds a Component before the OK button |
pOkCancel); |
||||||
* @param comp |
pOkCancel.add(comp, pos); |
||||||
*/ |
} |
||||||
public void addBeforeOK(JComponent comp) { |
/** |
||||||
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(pOkCancel.getBtnOk(), pOkCancel); |
* Adds a component right of the OK Button |
||||||
pOkCancel.add(comp, pos); |
* @param comp |
||||||
} |
*/ |
||||||
|
public void addAfterOK(JComponent comp) { |
||||||
/** |
int pos = |
||||||
* Adds a component right of the OK Button |
de.memtext.util.ComponentUtils.getPositionOnComponent( |
||||||
* @param comp |
pOkCancel.getBtnOk(), |
||||||
*/ |
pOkCancel); |
||||||
public void addAfterOK(JComponent comp) { |
pOkCancel.add(comp, pos + 1); |
||||||
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(pOkCancel.getBtnOk(), pOkCancel); |
} |
||||||
pOkCancel.add(comp, pos + 1); |
/** |
||||||
} |
* Adds a component right of the Cancel Button |
||||||
|
* @param comp |
||||||
/** |
*/ |
||||||
* Adds a component right of the Cancel Button |
public void addAfterCancel(JComponent comp) { |
||||||
* @param comp |
int pos = |
||||||
*/ |
de.memtext.util.ComponentUtils.getPositionOnComponent( |
||||||
public void addAfterCancel(JComponent comp) { |
pOkCancel.getBtnCancel(), |
||||||
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(pOkCancel.getBtnCancel(), pOkCancel); |
pOkCancel); |
||||||
pOkCancel.add(comp, pos + 1); |
pOkCancel.add(comp, pos + 1); |
||||||
} |
} |
||||||
/* class OneTimeInitContentPane extends Container { |
/* class OneTimeInitContentPane extends Container { |
||||||
private int setLayoutCount=0; |
private int setLayoutCount=0; |
||||||
public void setLayout(LayoutManager manager) { |
public void setLayout(LayoutManager manager) { |
||||||
if (!(manager instanceof BorderLayout)) { |
if (!(manager instanceof BorderLayout)) { |
||||||
throw new IllegalArgumentException("OKCancel Dlg must have BorderLayout"); |
throw new IllegalArgumentException("OKCancel Dlg must have BorderLayout"); |
||||||
} |
} |
||||||
super.setLayout(manager); |
super.setLayout(manager); |
||||||
setLayoutCount++; |
setLayoutCount++; |
||||||
if (setLayoutCount > 0) { |
if (setLayoutCount > 0) { |
||||||
System.out.println( |
System.out.println( |
||||||
"changing layout may cause problems in OKCancelDlg"); |
"changing layout may cause problems in OKCancelDlg"); |
||||||
|
|
||||||
} |
} |
||||||
} |
} |
||||||
}*/ |
}*/ |
||||||
|
|
||||||
public void setOkVisible(boolean b) { |
public void setOkVisible(boolean b) { |
||||||
pOkCancel.setOkVisible(b); |
pOkCancel.setOkVisible(b); |
||||||
} |
} |
||||||
|
public void setCancelVisible(boolean b) { |
||||||
public void setCancelVisible(boolean b) { |
pOkCancel.setCancelVisible(b); |
||||||
pOkCancel.setCancelVisible(b); |
} |
||||||
} |
public boolean requestFocusForOK() { |
||||||
|
return pOkCancel.getBtnOk().requestFocusInWindow(); |
||||||
public boolean requestFocusForOK() { |
} |
||||||
return pOkCancel.getBtnOk().requestFocusInWindow(); |
public void setOkBold(boolean b) { |
||||||
} |
pOkCancel.setOkBold(b); |
||||||
|
} |
||||||
public void setOkBold(boolean b) { |
|
||||||
pOkCancel.setOkBold(b); |
public void setOkDefaultButton() { |
||||||
} |
this.getRootPane().setDefaultButton(pOkCancel.getBtnOk()); |
||||||
|
} |
||||||
public void setOkDefaultButton() { |
|
||||||
this.getRootPane().setDefaultButton(pOkCancel.getBtnOk()); |
public static void main(String[] args) { |
||||||
} |
|
||||||
|
OkCancelDlg dlg = new OkCancelDlg(new JFrame(), "test") { |
||||||
public static void main(String[] args) { |
protected void performOk() { |
||||||
|
} |
||||||
OkCancelDlg dlg = new OkCancelDlg(new JFrame(), "test") { |
|
||||||
@Override |
protected void performCancel() { |
||||||
protected void performOk() { |
} |
||||||
} |
}; |
||||||
|
|
||||||
@Override |
// dlg.addAboveOK(new JLabel("bla"));
|
||||||
protected void performCancel() { |
dlg.setCenter(new JLabel("cnter")); |
||||||
} |
dlg.pack(); |
||||||
}; |
dlg.show(); |
||||||
|
} |
||||||
// dlg.addAboveOK(new JLabel("bla"));
|
|
||||||
dlg.setCenter(new JLabel("cnter")); |
} |
||||||
dlg.pack(); |
|
||||||
dlg.show(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,61 +1,56 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Font; |
import java.awt.Font; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
|
|
||||||
/** |
/** |
||||||
A Panel with an OK and a Cancel button. |
A Panel with an OK and a Cancel button. |
||||||
*/ |
*/ |
||||||
public class OkCancelPanel extends JPanel { |
public class OkCancelPanel extends JPanel { |
||||||
protected JButton btnOk, btnCancel; |
protected JButton btnOk, btnCancel; |
||||||
|
public OkCancelPanel() { |
||||||
public OkCancelPanel() { |
btnOk = new JButton("OK"); |
||||||
btnOk = new JButton("OK"); |
btnCancel = new JButton("Abbrechen"); |
||||||
btnCancel = new JButton("Abbrechen"); |
btnCancel.setActionCommand("Cancel"); |
||||||
btnCancel.setActionCommand("Cancel"); |
add(btnOk); |
||||||
add(btnOk); |
add(btnCancel); |
||||||
add(btnCancel); |
|
||||||
|
} |
||||||
} |
public void addActionListener(ActionListener al) { |
||||||
|
btnOk.addActionListener(al); |
||||||
public void addActionListener(ActionListener al) { |
btnCancel.addActionListener(al); |
||||||
btnOk.addActionListener(al); |
} |
||||||
btnCancel.addActionListener(al); |
|
||||||
} |
/** |
||||||
|
* Returns the btnCancel. |
||||||
/** |
* @return JButton |
||||||
* Returns the btnCancel. |
*/ |
||||||
* @return JButton |
public JButton getBtnCancel() { |
||||||
*/ |
return btnCancel; |
||||||
public JButton getBtnCancel() { |
} |
||||||
return btnCancel; |
|
||||||
} |
/** |
||||||
|
* Returns the btnOk. |
||||||
/** |
* @return JButton |
||||||
* Returns the btnOk. |
*/ |
||||||
* @return JButton |
public JButton getBtnOk() { |
||||||
*/ |
return btnOk; |
||||||
public JButton getBtnOk() { |
} |
||||||
return btnOk; |
public void setOkVisible(boolean b) { |
||||||
} |
btnOk.setVisible(b); |
||||||
|
} |
||||||
public void setOkVisible(boolean b) { |
public void setCancelVisible(boolean b) { |
||||||
btnOk.setVisible(b); |
btnCancel.setVisible(b); |
||||||
} |
} |
||||||
|
public void setOkBold(boolean b) { |
||||||
public void setCancelVisible(boolean b) { |
Font f=btnOk.getFont(); |
||||||
btnCancel.setVisible(b); |
if (b) |
||||||
} |
btnOk.setFont(f.deriveFont(Font.BOLD)); |
||||||
|
else |
||||||
public void setOkBold(boolean b) { |
btnOk.setFont(f.deriveFont(Font.PLAIN)); |
||||||
Font f = btnOk.getFont(); |
} |
||||||
if (b) |
|
||||||
btnOk.setFont(f.deriveFont(Font.BOLD)); |
} |
||||||
else |
|
||||||
btnOk.setFont(f.deriveFont(Font.PLAIN)); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,109 +1,106 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
||||||
import java.awt.Container; |
import java.awt.Container; |
||||||
import java.awt.Dialog; |
import java.awt.Dialog; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JComponent; |
import javax.swing.JComponent; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
|
/** |
||||||
/** |
* Dialog which can only be closed by clicking OK. |
||||||
* Dialog which can only be closed by clicking OK. |
* |
||||||
* |
* setCenter for convenienance. |
||||||
* setCenter for convenienance. |
* |
||||||
* |
* @author MB |
||||||
* @author MB |
* |
||||||
* |
*/ |
||||||
*/ |
|
||||||
|
public class OkDlg extends DialogWithExit { |
||||||
public class OkDlg extends DialogWithExit { |
private JPanel psouth = new JPanel(); |
||||||
private JPanel psouth = new JPanel(); |
protected JButton ok = new JButton("OK"); |
||||||
|
|
||||||
protected JButton ok = new JButton("OK"); |
/** |
||||||
|
* Constructor for OkDlg. |
||||||
/** |
* @param arg0 |
||||||
* Constructor for OkDlg. |
* @throws HeadlessException |
||||||
* @param arg0 |
*/ |
||||||
* @throws HeadlessException |
public OkDlg(Frame owner) throws HeadlessException { |
||||||
*/ |
super(owner,true); |
||||||
public OkDlg(Frame owner) throws HeadlessException { |
initSouth(); |
||||||
super(owner, true); |
} |
||||||
initSouth(); |
public OkDlg(Frame owner, String title, boolean isModal) { |
||||||
} |
super(owner,title,isModal); |
||||||
|
initSouth(); |
||||||
public OkDlg(Frame owner, String title, boolean isModal) { |
} |
||||||
super(owner, title, isModal); |
|
||||||
initSouth(); |
|
||||||
} |
public OkDlg(Frame owner, String title) throws HeadlessException { |
||||||
|
super(owner, title,true); |
||||||
|
initSouth(); |
||||||
public OkDlg(Frame owner, String title) throws HeadlessException { |
} |
||||||
super(owner, title, true); |
|
||||||
initSouth(); |
|
||||||
} |
public JButton getOkBtn() |
||||||
|
{ |
||||||
|
return ok; |
||||||
public JButton getOkBtn() { |
} |
||||||
return ok; |
|
||||||
} |
|
||||||
|
/** |
||||||
|
* Constructor for OkDlg. |
||||||
/** |
* @param arg0 |
||||||
* Constructor for OkDlg. |
* @throws HeadlessException |
||||||
* @param arg0 |
*/ |
||||||
* @throws HeadlessException |
public OkDlg(Dialog arg0) throws HeadlessException { |
||||||
*/ |
super(arg0,true); |
||||||
public OkDlg(Dialog arg0) throws HeadlessException { |
initSouth(); |
||||||
super(arg0, true); |
} |
||||||
initSouth(); |
|
||||||
} |
|
||||||
|
private void initSouth() { |
||||||
|
|
||||||
private void initSouth() { |
ok.addActionListener(new ActionListener(){ |
||||||
|
public void actionPerformed(ActionEvent ae) |
||||||
ok.addActionListener(new ActionListener() { |
{ |
||||||
|
performOk(); |
||||||
@Override |
} |
||||||
public void actionPerformed(ActionEvent ae) { |
}); |
||||||
performOk(); |
psouth.add(ok); |
||||||
} |
|
||||||
}); |
Container cp = this.getContentPane(); |
||||||
psouth.add(ok); |
cp.add(psouth, BorderLayout.SOUTH); |
||||||
|
this.getRootPane().setDefaultButton(ok); |
||||||
Container cp = this.getContentPane(); |
|
||||||
cp.add(psouth, BorderLayout.SOUTH); |
} |
||||||
this.getRootPane().setDefaultButton(ok); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
public void addBeforeOK(JComponent comp) { |
||||||
|
int pos = |
||||||
|
de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
||||||
public void addBeforeOK(JComponent comp) { |
psouth.add(comp, pos); |
||||||
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
} |
||||||
psouth.add(comp, pos); |
public void addAfterOK(JComponent comp) { |
||||||
} |
int pos = |
||||||
|
de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
||||||
public void addAfterOK(JComponent comp) { |
psouth.add(comp, pos+1); |
||||||
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
} |
||||||
psouth.add(comp, pos + 1); |
/** |
||||||
} |
* subclasses can override this method and specify commands |
||||||
|
* to be executed when OK was clicked |
||||||
/** |
*/ |
||||||
* subclasses can override this method and specify commands |
protected void performOk() |
||||||
* to be executed when OK was clicked |
{ |
||||||
*/ |
this.hide(); |
||||||
protected void performOk() { |
} |
||||||
this.hide(); |
public static void main(String args[]) { |
||||||
} |
OkDlg d=new OkDlg(new javax.swing.JFrame()); |
||||||
|
d.show(); |
||||||
public static void main(String args[]) { |
} |
||||||
OkDlg d = new OkDlg(new javax.swing.JFrame()); |
} |
||||||
d.show(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,177 +1,185 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
||||||
import java.awt.Container; |
import java.awt.Container; |
||||||
import java.awt.Dialog; |
import java.awt.Dialog; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.GraphicsConfiguration; |
import java.awt.GraphicsConfiguration; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
A abstract dialog with OK and DONE buttons. Subclasses must implement |
A abstract dialog with OK and DONE buttons. Subclasses must implement |
||||||
performDone() and performOK(); |
performDone() and performOK(); |
||||||
*/ |
*/ |
||||||
public abstract class OkDoneDlg extends DialogWithExit { |
public abstract class OkDoneDlg extends DialogWithExit { |
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg() throws HeadlessException { |
public OkDoneDlg() throws HeadlessException { |
||||||
super(); |
super(); |
||||||
initSouth(); |
initSouth(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg(Frame arg0) throws HeadlessException { |
public OkDoneDlg(Frame arg0) throws HeadlessException { |
||||||
super(arg0); |
super(arg0); |
||||||
initSouth(); |
initSouth(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @param arg1 |
* @param arg1 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg(Frame arg0, boolean arg1) throws HeadlessException { |
public OkDoneDlg(Frame arg0, boolean arg1) throws HeadlessException { |
||||||
super(arg0, arg1); |
super(arg0, arg1); |
||||||
initSouth(); |
initSouth(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @param arg1 |
* @param arg1 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg(Frame arg0, String arg1) throws HeadlessException { |
public OkDoneDlg(Frame arg0, String arg1) throws HeadlessException { |
||||||
super(arg0, arg1); |
super(arg0, arg1); |
||||||
initSouth(); |
initSouth(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @param arg1 |
* @param arg1 |
||||||
* @param arg2 |
* @param arg2 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg(Frame arg0, String arg1, boolean arg2) throws HeadlessException { |
public OkDoneDlg(Frame arg0, String arg1, boolean arg2) |
||||||
super(arg0, arg1, arg2); |
throws HeadlessException { |
||||||
initSouth(); |
super(arg0, arg1, arg2); |
||||||
} |
initSouth(); |
||||||
|
} |
||||||
/** |
|
||||||
* Constructor for OkDoneDlg. |
/** |
||||||
* @param arg0 |
* Constructor for OkDoneDlg. |
||||||
* @param arg1 |
* @param arg0 |
||||||
* @param arg2 |
* @param arg1 |
||||||
* @param arg3 |
* @param arg2 |
||||||
*/ |
* @param arg3 |
||||||
public OkDoneDlg(Frame arg0, String arg1, boolean arg2, GraphicsConfiguration arg3) { |
*/ |
||||||
super(arg0, arg1, arg2, arg3); |
public OkDoneDlg( |
||||||
initSouth(); |
Frame arg0, |
||||||
} |
String arg1, |
||||||
|
boolean arg2, |
||||||
/** |
GraphicsConfiguration arg3) { |
||||||
* Constructor for OkDoneDlg. |
super(arg0, arg1, arg2, arg3); |
||||||
* @param arg0 |
initSouth(); |
||||||
* @throws HeadlessException |
} |
||||||
*/ |
|
||||||
public OkDoneDlg(Dialog arg0) throws HeadlessException { |
/** |
||||||
super(arg0); |
* Constructor for OkDoneDlg. |
||||||
initSouth(); |
* @param arg0 |
||||||
} |
* @throws HeadlessException |
||||||
|
*/ |
||||||
/** |
public OkDoneDlg(Dialog arg0) throws HeadlessException { |
||||||
* Constructor for OkDoneDlg. |
super(arg0); |
||||||
* @param arg0 |
initSouth(); |
||||||
* @param arg1 |
} |
||||||
* @throws HeadlessException |
|
||||||
*/ |
/** |
||||||
public OkDoneDlg(Dialog arg0, boolean arg1) throws HeadlessException { |
* Constructor for OkDoneDlg. |
||||||
super(arg0, arg1); |
* @param arg0 |
||||||
initSouth(); |
* @param arg1 |
||||||
} |
* @throws HeadlessException |
||||||
|
*/ |
||||||
/** |
public OkDoneDlg(Dialog arg0, boolean arg1) throws HeadlessException { |
||||||
* Constructor for OkDoneDlg. |
super(arg0, arg1); |
||||||
* @param arg0 |
initSouth(); |
||||||
* @param arg1 |
} |
||||||
* @throws HeadlessException |
|
||||||
*/ |
/** |
||||||
public OkDoneDlg(Dialog arg0, String arg1) throws HeadlessException { |
* Constructor for OkDoneDlg. |
||||||
super(arg0, arg1); |
* @param arg0 |
||||||
initSouth(); |
* @param arg1 |
||||||
} |
* @throws HeadlessException |
||||||
|
*/ |
||||||
/** |
public OkDoneDlg(Dialog arg0, String arg1) throws HeadlessException { |
||||||
* Constructor for OkDoneDlg. |
super(arg0, arg1); |
||||||
* @param arg0 |
initSouth(); |
||||||
* @param arg1 |
} |
||||||
* @param arg2 |
|
||||||
* @throws HeadlessException |
/** |
||||||
*/ |
* Constructor for OkDoneDlg. |
||||||
public OkDoneDlg(Dialog arg0, String arg1, boolean arg2) throws HeadlessException { |
* @param arg0 |
||||||
super(arg0, arg1, arg2); |
* @param arg1 |
||||||
initSouth(); |
* @param arg2 |
||||||
} |
* @throws HeadlessException |
||||||
|
*/ |
||||||
/** |
public OkDoneDlg(Dialog arg0, String arg1, boolean arg2) |
||||||
* Constructor for OkDoneDlg. |
throws HeadlessException { |
||||||
* @param arg0 |
super(arg0, arg1, arg2); |
||||||
* @param arg1 |
initSouth(); |
||||||
* @param arg2 |
} |
||||||
* @param arg3 |
|
||||||
* @throws HeadlessException |
/** |
||||||
*/ |
* Constructor for OkDoneDlg. |
||||||
public OkDoneDlg(Dialog arg0, String arg1, boolean arg2, GraphicsConfiguration arg3) throws HeadlessException { |
* @param arg0 |
||||||
super(arg0, arg1, arg2, arg3); |
* @param arg1 |
||||||
initSouth(); |
* @param arg2 |
||||||
} |
* @param arg3 |
||||||
|
* @throws HeadlessException |
||||||
private void initSouth() { |
*/ |
||||||
OkCancelPanel ocp = new OkCancelPanel(); |
public OkDoneDlg( |
||||||
Container cp = this.getContentPane(); |
Dialog arg0, |
||||||
cp.add(ocp, BorderLayout.SOUTH); |
String arg1, |
||||||
ocp.addActionListener(new ActionListener() { |
boolean arg2, |
||||||
|
GraphicsConfiguration arg3) |
||||||
@Override |
throws HeadlessException { |
||||||
public void actionPerformed(ActionEvent ae) { |
super(arg0, arg1, arg2, arg3); |
||||||
String cmd = ae.getActionCommand(); |
initSouth(); |
||||||
if (cmd.equals("OK")) { |
} |
||||||
performOk(); |
|
||||||
} |
private void initSouth() { |
||||||
|
OkCancelPanel ocp = new OkCancelPanel(); |
||||||
if (cmd.equals("Done")) { |
Container cp = this.getContentPane(); |
||||||
performDone(); |
cp.add(ocp, BorderLayout.SOUTH); |
||||||
} |
ocp.addActionListener(new ActionListener(){ |
||||||
} |
public void actionPerformed(ActionEvent ae) |
||||||
}); |
{ |
||||||
; |
String cmd = ae.getActionCommand(); |
||||||
} |
if (cmd.equals("OK")) { |
||||||
|
performOk(); |
||||||
|
} |
||||||
/** |
|
||||||
* subclasses must implement this method and specify commands |
if (cmd.equals("Done")) { |
||||||
* to be executed when OK was clicked |
performDone(); |
||||||
*/ |
} |
||||||
protected abstract void performOk(); |
} |
||||||
|
});; |
||||||
/** |
} |
||||||
* subclasses must implement this method and specify commands |
|
||||||
* to be executed when DONE was clicked |
|
||||||
*/ |
/** |
||||||
|
* subclasses must implement this method and specify commands |
||||||
protected abstract void performDone(); |
* to be executed when OK was clicked |
||||||
} |
*/ |
||||||
|
protected abstract void performOk(); |
||||||
|
/** |
||||||
|
* subclasses must implement this method and specify commands |
||||||
|
* to be executed when DONE was clicked |
||||||
|
*/ |
||||||
|
|
||||||
|
protected abstract void performDone(); |
||||||
|
} |
||||||
|
|||||||
@ -1,32 +1,32 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change this generated comment edit the template variable "typecomment": |
* To change this generated comment edit the template variable "typecomment": |
||||||
* Window>Preferences>Java>Templates. |
* Window>Preferences>Java>Templates. |
||||||
* To enable and disable the creation of type comments go to |
* To enable and disable the creation of type comments go to |
||||||
* Window>Preferences>Java>Code Generation. |
* Window>Preferences>Java>Code Generation. |
||||||
*/ |
*/ |
||||||
public class OkDonePanel extends JPanel { |
public class OkDonePanel extends JPanel { |
||||||
JButton btnOk, btnDone; |
JButton btnOk,btnDone; |
||||||
|
public OkDonePanel() |
||||||
public OkDonePanel() { |
{ |
||||||
btnOk = new JButton("OK"); |
btnOk=new JButton("OK"); |
||||||
btnDone = new JButton("Fertig"); |
btnDone=new JButton("Fertig"); |
||||||
add(btnOk); |
add(btnOk); |
||||||
add(btnDone); |
add(btnDone); |
||||||
} |
} |
||||||
|
public void addActionListener(ActionListener al) |
||||||
public void addActionListener(ActionListener al) { |
{ |
||||||
btnOk.addActionListener(al); |
btnOk.addActionListener(al); |
||||||
btnDone.addActionListener(al); |
btnDone.addActionListener(al); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|||||||
@ -1,199 +1,185 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Dimension; |
import java.awt.Dimension; |
||||||
import java.awt.Font; |
import java.awt.Font; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.GridLayout; |
import java.awt.GridLayout; |
||||||
import java.awt.event.KeyEvent; |
import java.awt.event.KeyEvent; |
||||||
|
|
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
import javax.swing.JPasswordField; |
import javax.swing.JPasswordField; |
||||||
import javax.swing.JTextField; |
import javax.swing.JTextField; |
||||||
import javax.swing.KeyStroke; |
import javax.swing.KeyStroke; |
||||||
|
|
||||||
import de.memtext.rights.NewPasswordChecker; |
import de.memtext.rights.NewPasswordChecker; |
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.util.WindowUtils; |
||||||
import de.memtext.widgets.HorizontalBox; |
import de.memtext.widgets.HorizontalBox; |
||||||
import de.memtext.widgets.WarningMessage; |
import de.memtext.widgets.WarningMessage; |
||||||
|
|
||||||
public abstract class PasswdChangeDlg extends OkCancelDlg { |
public abstract class PasswdChangeDlg extends OkCancelDlg { |
||||||
private JLabel lblInfoDummy = new JLabel(); |
private JLabel lblInfoDummy=new JLabel(); |
||||||
|
private NewPasswordChecker newPasswordChecker; |
||||||
private NewPasswordChecker newPasswordChecker; |
private boolean isCheckOldPasswdWanted = true,isNewPasswordRequired=true; |
||||||
|
private JTextField usernameField = new JTextField(20); |
||||||
private boolean isCheckOldPasswdWanted = true, isNewPasswordRequired = true; |
private KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); |
||||||
|
private JLabel lblInfo=new JLabel(); |
||||||
private JTextField usernameField = new JTextField(20); |
private JLabel lbl0 = new JLabel("Username:", JLabel.RIGHT); |
||||||
|
private JLabel lbl1 = new JLabel("altes Passwort:", JLabel.RIGHT); |
||||||
private KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); |
private JPasswordField oldpasswField = new JPasswordField(30); |
||||||
|
private JLabel lbl2 = new JLabel("neues Passwort:", JLabel.RIGHT); |
||||||
private JLabel lblInfo = new JLabel(); |
private JPasswordField newpasswField = new JPasswordField(30); |
||||||
|
private JLabel lbl3 = new JLabel("wiederholen:", JLabel.RIGHT); |
||||||
private JLabel lbl0 = new JLabel("Username:", JLabel.RIGHT); |
private JPasswordField newpasswField2 = new JPasswordField(30); |
||||||
|
|
||||||
private JLabel lbl1 = new JLabel("altes Passwort:", JLabel.RIGHT); |
public PasswdChangeDlg(Frame frame, String title) { |
||||||
|
super(frame, title, true); |
||||||
private JPasswordField oldpasswField = new JPasswordField(30); |
JPanel p=new JPanel(); |
||||||
|
p.add(lblInfo); |
||||||
private JLabel lbl2 = new JLabel("neues Passwort:", JLabel.RIGHT); |
HorizontalBox hbox = new HorizontalBox(); |
||||||
|
JPanel lblPanel = new JPanel(new GridLayout(0, 1)); |
||||||
private JPasswordField newpasswField = new JPasswordField(30); |
lblPanel.setMaximumSize(new Dimension(150, 100)); |
||||||
|
|
||||||
private JLabel lbl3 = new JLabel("wiederholen:", JLabel.RIGHT); |
|
||||||
|
lblPanel.add(lbl0); |
||||||
private JPasswordField newpasswField2 = new JPasswordField(30); |
lblPanel.add(lbl1); |
||||||
|
lblPanel.add(lbl2); |
||||||
public PasswdChangeDlg(Frame frame, String title) { |
lblPanel.add(lbl3); |
||||||
super(frame, title, true); |
|
||||||
JPanel p = new JPanel(); |
lblInfo.setVisible(false); |
||||||
p.add(lblInfo); |
hbox.add(lblPanel); |
||||||
HorizontalBox hbox = new HorizontalBox(); |
JPanel fieldPanel = new JPanel(new GridLayout(0, 1)); |
||||||
JPanel lblPanel = new JPanel(new GridLayout(0, 1)); |
|
||||||
lblPanel.setMaximumSize(new Dimension(150, 100)); |
fieldPanel.add(usernameField); |
||||||
|
usernameField.getKeymap().removeKeyStrokeBinding(enter); |
||||||
|
|
||||||
lblPanel.add(lbl0); |
fieldPanel.add(oldpasswField); |
||||||
lblPanel.add(lbl1); |
oldpasswField.getKeymap().removeKeyStrokeBinding(enter); |
||||||
lblPanel.add(lbl2); |
fieldPanel.add(newpasswField); |
||||||
lblPanel.add(lbl3); |
newpasswField.getKeymap().removeKeyStrokeBinding(enter); |
||||||
|
fieldPanel.add(newpasswField2); |
||||||
lblInfo.setVisible(false); |
newpasswField2.getKeymap().removeKeyStrokeBinding(enter); |
||||||
hbox.add(lblPanel); |
hbox.add(fieldPanel); |
||||||
JPanel fieldPanel = new JPanel(new GridLayout(0, 1)); |
this.setCenter(hbox); |
||||||
|
this.setNorth(p); |
||||||
fieldPanel.add(usernameField); |
this.pack(); |
||||||
usernameField.getKeymap().removeKeyStrokeBinding(enter); |
WindowUtils.center(this); |
||||||
|
} |
||||||
fieldPanel.add(oldpasswField); |
public void setNewPasswordChecker(NewPasswordChecker newPasswordChecker) |
||||||
oldpasswField.getKeymap().removeKeyStrokeBinding(enter); |
{ |
||||||
fieldPanel.add(newpasswField); |
this.newPasswordChecker=newPasswordChecker; |
||||||
newpasswField.getKeymap().removeKeyStrokeBinding(enter); |
} |
||||||
fieldPanel.add(newpasswField2); |
public void setUsername(String username) { |
||||||
newpasswField2.getKeymap().removeKeyStrokeBinding(enter); |
usernameField.setText(username); |
||||||
hbox.add(fieldPanel); |
} |
||||||
this.setCenter(hbox); |
public void clear() { |
||||||
this.setNorth(p); |
usernameField.setText(""); |
||||||
this.pack(); |
oldpasswField.setText(""); |
||||||
WindowUtils.center(this); |
newpasswField.setText(""); |
||||||
} |
newpasswField2.setText(""); |
||||||
|
} |
||||||
public void setNewPasswordChecker(NewPasswordChecker newPasswordChecker) { |
protected abstract boolean isOldPasswordOK(String username, String passwd); |
||||||
this.newPasswordChecker = newPasswordChecker; |
|
||||||
} |
/** |
||||||
|
* wenn OK geklickt wird wird automatisch geprüft ob die Länge des neuen |
||||||
public void setUsername(String username) { |
* Passwort passt und beide gleich sind |
||||||
usernameField.setText(username); |
*/ |
||||||
} |
protected final void performOk() { |
||||||
|
String new1 = new String(newpasswField.getPassword()); |
||||||
public void clear() { |
if (new1==null||new1.length()<4 ) |
||||||
usernameField.setText(""); |
{ |
||||||
oldpasswField.setText(""); |
WarningMessage.show(this, |
||||||
newpasswField.setText(""); |
"Das neue Passwort ist zu kurz.", |
||||||
newpasswField2.setText(""); |
"Achtung"); |
||||||
} |
return; |
||||||
|
} |
||||||
protected abstract boolean isOldPasswordOK(String username, String passwd); |
|
||||||
|
String new2 = new String(newpasswField2.getPassword()); |
||||||
/** |
String oldPassword = new String(oldpasswField.getPassword()); |
||||||
* wenn OK geklickt wird wird automatisch geprüft ob die Länge des neuen |
if (!new1.equals(new2)) { |
||||||
* Passwort passt und beide gleich sind |
WarningMessage.show(this, |
||||||
*/ |
"Die beiden neuen Passwörter stimmen nicht überein", |
||||||
@Override |
"Achtung"); |
||||||
protected final void performOk() { |
return; |
||||||
String new1 = new String(newpasswField.getPassword()); |
} |
||||||
if (new1 == null || new1.length() < 4) { |
String faults=null; |
||||||
WarningMessage.show(this, "Das neue Passwort ist zu kurz.", "Achtung"); |
if (newPasswordChecker!=null) faults=newPasswordChecker.checkForFaults(getUsername(),new String(newpasswField.getPassword())); |
||||||
return; |
|
||||||
} |
if (faults!=null) { |
||||||
|
WarningMessage.show(this, |
||||||
String new2 = new String(newpasswField2.getPassword()); |
faults, |
||||||
String oldPassword = new String(oldpasswField.getPassword()); |
"Achtung"); |
||||||
if (!new1.equals(new2)) { |
return; |
||||||
WarningMessage.show(this, "Die beiden neuen Passwörter stimmen nicht überein", "Achtung"); |
} |
||||||
return; |
|
||||||
} |
if (isNewPasswordRequired&&new1.equals(oldPassword)) |
||||||
String faults = null; |
{ |
||||||
if (newPasswordChecker != null) faults = newPasswordChecker.checkForFaults(getUsername(), new String(newpasswField.getPassword())); |
WarningMessage.show(this,"Sie müssen ein neues Passwort eingeben","Achtung"); |
||||||
|
return; |
||||||
if (faults != null) { |
} |
||||||
WarningMessage.show(this, faults, "Achtung"); |
|
||||||
return; |
if (isCheckOldPasswdWanted |
||||||
} |
&& !isOldPasswordOK(usernameField.getText(), |
||||||
|
oldPassword)) { |
||||||
if (isNewPasswordRequired && new1.equals(oldPassword)) { |
WarningMessage.show(this,"Das alte Passwort stimmt nicht", "Achtung"); |
||||||
WarningMessage.show(this, "Sie müssen ein neues Passwort eingeben", "Achtung"); |
return; |
||||||
return; |
} |
||||||
} |
this.hide(); |
||||||
|
} |
||||||
if (isCheckOldPasswdWanted && !isOldPasswordOK(usernameField.getText(), oldPassword)) { |
|
||||||
WarningMessage.show(this, "Das alte Passwort stimmt nicht", "Achtung"); |
protected void performCancel() { |
||||||
return; |
this.hide(); |
||||||
} |
} |
||||||
this.hide(); |
|
||||||
} |
|
||||||
|
public void setUsernameFieldEnabled(boolean b) { |
||||||
@Override |
usernameField.setEnabled(b); |
||||||
protected void performCancel() { |
} |
||||||
this.hide(); |
public void setOldPassword(String passw) { |
||||||
} |
oldpasswField.setText(passw); |
||||||
|
} |
||||||
|
public String getUsername() { |
||||||
public void setUsernameFieldEnabled(boolean b) { |
return usernameField.getText(); |
||||||
usernameField.setEnabled(b); |
} |
||||||
} |
public String getOldPasswd() { |
||||||
|
return new String(oldpasswField.getPassword()); |
||||||
public void setOldPassword(String passw) { |
} |
||||||
oldpasswField.setText(passw); |
public String getNewPasswd() { |
||||||
} |
return new String(newpasswField.getPassword()); |
||||||
|
} |
||||||
public String getUsername() { |
public boolean isCheckOldPasswdWanted() { |
||||||
return usernameField.getText(); |
return isCheckOldPasswdWanted; |
||||||
} |
} |
||||||
|
|
||||||
public String getOldPasswd() { |
public void setCheckOldPasswdWanted(boolean b) { |
||||||
return new String(oldpasswField.getPassword()); |
isCheckOldPasswdWanted = b; |
||||||
} |
lbl1.setVisible(b); |
||||||
|
oldpasswField.setVisible(b); |
||||||
public String getNewPasswd() { |
} |
||||||
return new String(newpasswField.getPassword()); |
public void setInfoLabel(String txt) { |
||||||
} |
lblInfo.setVisible(true); |
||||||
|
lblInfo.setText(txt); |
||||||
public boolean isCheckOldPasswdWanted() { |
lblInfo.setFont(new Font("SansSerif",Font.BOLD,12)); |
||||||
return isCheckOldPasswdWanted; |
} |
||||||
} |
|
||||||
|
public boolean isNewPasswordRequired() { |
||||||
public void setCheckOldPasswdWanted(boolean b) { |
return isNewPasswordRequired; |
||||||
isCheckOldPasswdWanted = b; |
} |
||||||
lbl1.setVisible(b); |
|
||||||
oldpasswField.setVisible(b); |
public void setNewPasswordRequired(boolean b) { |
||||||
} |
isNewPasswordRequired = b; |
||||||
|
} |
||||||
public void setInfoLabel(String txt) { |
public static void main(String a[]) |
||||||
lblInfo.setVisible(true); |
{ |
||||||
lblInfo.setText(txt); |
PasswdChangeDlg dlg=new PasswdChangeDlg(null,"dummy"){ |
||||||
lblInfo.setFont(new Font("SansSerif", Font.BOLD, 12)); |
|
||||||
} |
protected boolean isOldPasswordOK(String username, String passwd) { |
||||||
|
return false; |
||||||
public boolean isNewPasswordRequired() { |
}} |
||||||
return isNewPasswordRequired; |
; |
||||||
} |
dlg.setInfoLabel("bitte ändern"); |
||||||
|
dlg.show(); |
||||||
public void setNewPasswordRequired(boolean b) { |
} |
||||||
isNewPasswordRequired = b; |
} |
||||||
} |
|
||||||
|
|
||||||
public static void main(String a[]) { |
|
||||||
PasswdChangeDlg dlg = new PasswdChangeDlg(null, "dummy") { |
|
||||||
|
|
||||||
@Override |
|
||||||
protected boolean isOldPasswordOK(String username, String passwd) { |
|
||||||
return false; |
|
||||||
} |
|
||||||
}; |
|
||||||
dlg.setInfoLabel("bitte ändern"); |
|
||||||
dlg.show(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 09.01.2004 at 17:16:16
|
//Created on 09.01.2004 at 17:16:16
|
||||||
@ -0,0 +1,122 @@ |
|||||||
|
package de.memtext.hbt; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.logging.Logger; |
||||||
|
|
||||||
|
import javax.mail.Flags; |
||||||
|
import javax.mail.Folder; |
||||||
|
import javax.mail.Message; |
||||||
|
import javax.mail.MessagingException; |
||||||
|
import javax.mail.search.FlagTerm; |
||||||
|
|
||||||
|
import de.memtext.util.LogUtils; |
||||||
|
import de.superx.servlet.SxMail; |
||||||
|
import de.superx.servlet.SxPool; |
||||||
|
|
||||||
|
public abstract class AbstractAriel extends Thread { |
||||||
|
// this is defined as private static method to use as little memory as possible,
|
||||||
|
// it would be neglectable in moder computers to create it every time the method
|
||||||
|
// runs, GarbargeCollection would easily do the job
|
||||||
|
// yet I define it that way out of respect for the programmers of beginning in
|
||||||
|
// the 50ies/60ies or whenever
|
||||||
|
// private static FlagTerm flagUnseen = new FlagTerm(new Flags(Flags.Flag.SEEN), true); // ja ich weiß, flagUnseen
|
||||||
|
Flags seen = new Flags(Flags.Flag.RECENT); |
||||||
|
private static FlagTerm flagUnseen = new FlagTerm(new Flags(Flags.Flag.SEEN), false); |
||||||
|
static Flags flagsContainingOnlySeen=new Flags(Flags.Flag.SEEN); |
||||||
|
protected Logger logger=null; |
||||||
|
// wird bisher nicht
|
||||||
|
// benötigt, aber ist doch
|
||||||
|
// klar, dass ich das gleich
|
||||||
|
// nutzen will, dass nervt,
|
||||||
|
// dass die Meldung jetzt
|
||||||
|
// kommt
|
||||||
|
private boolean isActive = true; |
||||||
|
private int interval = 10; |
||||||
|
protected SxMail sxmail; |
||||||
|
|
||||||
|
public AbstractAriel() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(Runnable target) { |
||||||
|
super(target); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(String name) { |
||||||
|
super(name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, Runnable target) { |
||||||
|
super(group, target); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, String name) { |
||||||
|
super(group, name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(Runnable target, String name) { |
||||||
|
super(target, name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, Runnable target, String name) { |
||||||
|
super(group, target, name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, Runnable target, String name, long stackSize) { |
||||||
|
super(group, target, name, stackSize); |
||||||
|
} |
||||||
|
|
||||||
|
public void initLogging()throws IOException |
||||||
|
{ |
||||||
|
String filename=SxPool.getLogDir() + "/superx_" |
||||||
|
+ getArielName() + ".log"; |
||||||
|
LogUtils.initRawFile("superx_" + getArielName(), filename, 20000, 1, true, true); |
||||||
|
System.out.println("Superx Mail logging in "+filename); |
||||||
|
logger=Logger.getLogger("superx_" + getArielName()); |
||||||
|
Level lev = Level.SEVERE; |
||||||
|
logger.setLevel(lev); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
public String getArielName() |
||||||
|
{ |
||||||
|
return "mail"; |
||||||
|
} |
||||||
|
public void run() { |
||||||
|
while (isActive) { |
||||||
|
try { |
||||||
|
Thread.sleep(interval * 1000); |
||||||
|
|
||||||
|
} catch (InterruptedException e) { |
||||||
|
// e.printStackTrace();
|
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
|
||||||
|
logger.log(Level.INFO,"SuperX is checking mails for new heartbeats..."); |
||||||
|
|
||||||
|
|
||||||
|
Folder inbox=sxmail.getInbox(); |
||||||
|
//if (inbox.hasNewMessages())
|
||||||
|
processNewMessages(inbox.getMessages()); // processed messages will be deleted -> don#t need inbox.search(flagUnseen)); // former first attempt was : processNewMessages(inbox.getMessages()); // should be in differnt colour (<- British English)
|
||||||
|
|
||||||
|
sxmail.closeInbox(); //deletes marked mails
|
||||||
|
} catch (Exception e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
abstract void processNewMessages(Message[] messages) throws MessagingException, IOException, SQLException; |
||||||
|
|
||||||
|
public void setActive(boolean isActive) { |
||||||
|
this.isActive=isActive; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,96 @@ |
|||||||
|
package de.memtext.hbt; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
import javax.mail.Folder; |
||||||
|
import javax.mail.Message; |
||||||
|
import javax.mail.MessagingException; |
||||||
|
import javax.mail.Session; |
||||||
|
import javax.mail.Store; |
||||||
|
import javax.mail.Transport; |
||||||
|
import javax.mail.internet.AddressException; |
||||||
|
import javax.mail.internet.InternetAddress; |
||||||
|
import javax.mail.internet.MimeMessage; |
||||||
|
|
||||||
|
public class Checker { |
||||||
|
|
||||||
|
public static void check(Session emailSession, String user, String password) |
||||||
|
throws MessagingException, IOException { |
||||||
|
|
||||||
|
// create the POP3 store object and connect with the pop server
|
||||||
|
// pop3s wichtig -> vermutlich secure
|
||||||
|
Store store = emailSession.getStore("pop3s"); |
||||||
|
store.connect(emailSession.getProperty("mail.pop3.host"), user, password); |
||||||
|
|
||||||
|
Folder emailFolder = store.getFolder("INBOX"); |
||||||
|
emailFolder.open(Folder.READ_ONLY); |
||||||
|
|
||||||
|
// messages werden geholt, können nur ausgelesen werden, wenn Folder noch open
|
||||||
|
// ist!
|
||||||
|
Message[] messages = emailFolder.getMessages(); |
||||||
|
|
||||||
|
System.out.println("messages.length---" + messages.length); |
||||||
|
|
||||||
|
for (int i = 0, n = messages.length; i < n; i++) { |
||||||
|
Message message = messages[i]; |
||||||
|
System.out.println("---------------------------------"); |
||||||
|
System.out.println("Email Number " + (i + 1)); |
||||||
|
System.out.println("Subject: " + message.getSubject()); |
||||||
|
System.out.println("From: " + message.getFrom()[0]); |
||||||
|
System.out.println("Text: " + message.getContent().toString()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
// close the store and folder objects
|
||||||
|
emailFolder.close(false); |
||||||
|
store.close(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static void send(Session emailSession, String user, String recipient, String subject, String text, |
||||||
|
String password) throws AddressException, MessagingException { |
||||||
|
MimeMessage replyMessage = new MimeMessage(emailSession); |
||||||
|
// replyMessage = (MimeMessage) message.reply(false);
|
||||||
|
replyMessage.setFrom(new InternetAddress(user)); |
||||||
|
replyMessage.setRecipients(Message.RecipientType.TO, recipient); |
||||||
|
replyMessage.setSubject(subject); |
||||||
|
replyMessage.setText(text); |
||||||
|
Transport t = emailSession.getTransport("smtp"); |
||||||
|
t.connect(user, password); |
||||||
|
t.sendMessage(replyMessage, replyMessage.getAllRecipients()); |
||||||
|
System.out.println("Message sent..."); |
||||||
|
} |
||||||
|
|
||||||
|
private static Session initSession(String pophost, String smtphost) { |
||||||
|
Properties properties = new Properties(); |
||||||
|
properties.put("mail.pop3.host", pophost); |
||||||
|
properties.put("mail.pop3.port", "995"); |
||||||
|
properties.put("mail.pop3.starttls.enable", "true"); |
||||||
|
properties.put("mail.smtp.auth", "true"); |
||||||
|
properties.put("mail.smtp.starttls.enable", "true"); |
||||||
|
properties.put("mail.smtp.host", smtphost); |
||||||
|
properties.put("mail.smtp.port", "25"); |
||||||
|
return Session.getDefaultInstance(properties); |
||||||
|
} |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
Session session = initSession("pop3.strato.de", "smtp.strato.de"); |
||||||
|
String username = "heartbeat@mbisping.de"; |
||||||
|
String password = "$Anfang1200"; |
||||||
|
|
||||||
|
try { |
||||||
|
check(session, username, password); |
||||||
|
send(session, username, "danielq@memtext.de", "From Düsseldorf with fun...", "This is the memtext's first digitial 'heartbeat' :-)\n send via java mail - \nThanks and see you around :-)", |
||||||
|
password); |
||||||
|
} catch (MessagingException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} catch (IOException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,293 @@ |
|||||||
|
package de.memtext.hbt; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.FileOutputStream; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
import javax.mail.BodyPart; |
||||||
|
import javax.mail.Flags; |
||||||
|
import javax.mail.Message; |
||||||
|
import javax.mail.MessagingException; |
||||||
|
import javax.mail.Multipart; |
||||||
|
import javax.mail.Part; |
||||||
|
import javax.mail.internet.AddressException; |
||||||
|
import javax.mail.internet.MimeMessage; |
||||||
|
|
||||||
|
import clover.com.atlassian.extras.common.org.springframework.util.StringUtils; |
||||||
|
import de.memtext.db.DbUtils; |
||||||
|
import de.memtext.util.FileUtils; |
||||||
|
import de.memtext.util.MailUtils; |
||||||
|
import de.superx.servlet.SuperXManager; |
||||||
|
import de.superx.servlet.SxMail; |
||||||
|
import de.superx.servlet.SxPools; |
||||||
|
|
||||||
|
public class NewHeartBeatAriel extends AbstractAriel { |
||||||
|
private static final Pattern pHbtId = Pattern.compile("@hbt:\\d*@"); |
||||||
|
|
||||||
|
public NewHeartBeatAriel(SxMail sxmail) throws IOException { |
||||||
|
this.sxmail = sxmail; |
||||||
|
initLogging(); |
||||||
|
} |
||||||
|
|
||||||
|
void processNewMessages(Message newMessages[]) throws MessagingException, IOException, SQLException { |
||||||
|
|
||||||
|
|
||||||
|
logger.log(Level.INFO," found " + newMessages.length + " new messages"); |
||||||
|
for (int i = 0, n = newMessages.length; i < n; i++) { |
||||||
|
Message aNewMessage = newMessages[i]; |
||||||
|
|
||||||
|
String content = MailUtils.getContent(aNewMessage); |
||||||
|
if (content.indexOf("@hbt:") == -1) |
||||||
|
createNewHeartBeat(aNewMessage, content); |
||||||
|
else |
||||||
|
appendToHeartBeat(aNewMessage, content); |
||||||
|
// had thought setting via inbox nessary, but that's only the preferred way to
|
||||||
|
// set flags for group of messages since some mail implementations by have
|
||||||
|
// optimized support for groups of messages
|
||||||
|
// inbox.setFlags(new Message[] {message}, , true);
|
||||||
|
// message.setFlags(flagsContainingOnlySeen, true);
|
||||||
|
// unseen wäre schöner, mailapi.jar aktualisieren bei HIS Antrag
|
||||||
|
// nötig,vielleicht klappt mit delete
|
||||||
|
aNewMessage.setFlag(Flags.Flag.DELETED, true); // AbstractAriel.run ruft sxmail.closeInbox() auf mit
|
||||||
|
// Anweisung zu löschen
|
||||||
|
|
||||||
|
// sorry to bother you, Garbage collector , need message only to times, hey or
|
||||||
|
// doesn't that matter anyway since only a simple reference (like in good old
|
||||||
|
// C), but clearer/easier to read if line Message message=.. was superfolous
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void appendToHeartBeat(Message message, String content) |
||||||
|
throws SQLException, IOException, MessagingException { |
||||||
|
StringBuffer result = new StringBuffer(); |
||||||
|
int hbtTid = -1; |
||||||
|
Connection con = SxPools.getConnection(sxmail.getMandantenID()); |
||||||
|
Statement stm = con.createStatement(); |
||||||
|
boolean isHbtFoundInDb = false; |
||||||
|
String feedbackSubject = ""; |
||||||
|
Matcher m = pHbtId.matcher(content); |
||||||
|
boolean foundHbtTag=m.find(); |
||||||
|
if (foundHbtTag) { |
||||||
|
String hbtIdString = content.substring(m.start() + 5, m.end() - 1); |
||||||
|
content=content.replaceAll("@hbt:\\d*@", ""); |
||||||
|
try { |
||||||
|
hbtTid = Integer.parseInt(hbtIdString); |
||||||
|
if (DbUtils.getInt(con, "select count(*) from hbt_heartbeat where tid=?", hbtTid) > 0) |
||||||
|
isHbtFoundInDb = true; |
||||||
|
} catch (NumberFormatException e) { |
||||||
|
result.append(" hbt:" + hbtIdString |
||||||
|
+ " konnte nicht in integer transformiert werden, Nachricht wird zwischengespeichert"); |
||||||
|
isHbtFoundInDb = false; |
||||||
|
} |
||||||
|
if (isHbtFoundInDb) { |
||||||
|
// TODO ggfs. mehrer Topics
|
||||||
|
int maxTopic = DbUtils.getInt(con, "select max(tid) from hbt_topic where hbt_id=?", hbtTid); |
||||||
|
// int maxNote = DbUtils.getInt(stm, "select max(tid) from hbt_note where
|
||||||
|
// hbt_id=" + hbtTid + " hbt_topic_id=" + maxTopic);
|
||||||
|
int newNoteId = createNote(con, stm, hbtTid, maxTopic, message, content); |
||||||
|
feedbackSubject = "Your new note was added to Heartbeat " + hbtTid; |
||||||
|
result.append("Feel free to view this HeartBeat by visiting " + sxmail.getWTFAI() |
||||||
|
+ "/edit/hbt/hbt_viewer.jsp?tid=" + hbtTid + " \n\n" + "Always at your service: \n" |
||||||
|
+ " your HeartBeatAriel @ SuperX"); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!foundHbtTag || !isHbtFoundInDb) { |
||||||
|
feedbackSubject = "Sorry, target hbt found found ..."; |
||||||
|
PreparedStatement pst=con.prepareStatement("insert into hbt_tmp_note (note) values (?)"); |
||||||
|
pst.setString(1,content); |
||||||
|
pst.execute(); |
||||||
|
pst.close(); |
||||||
|
int newNoteId=DbUtils.getInt(stm, "select max(tid) from hbt_tmp_note"); |
||||||
|
result.append("you can select the right hbt_id by visiting " + sxmail.getWTFAI()+"/servlet/SuperXmlMaske?tid=60040?note_id="+newNoteId); |
||||||
|
} |
||||||
|
stm.close(); |
||||||
|
con.close(); |
||||||
|
sendFeedbackEmail(feedbackSubject, result.toString(), message); |
||||||
|
} |
||||||
|
|
||||||
|
private void createNewHeartBeat(Message inMessage, String content) |
||||||
|
throws SQLException, MessagingException, IOException { |
||||||
|
int newHbtTid = performHbtInsert(inMessage, content); |
||||||
|
String text = "Feel free to complete this heartbeat's details by visiting " + sxmail.getWTFAI() |
||||||
|
+ "/edit/hbt/hbt_edit.jsp?tid=" + newHbtTid + " \n\n" + "Always at your service: \n" |
||||||
|
+ " your HeartBeatAriel @ SuperX"; |
||||||
|
sendFeedbackEmail("Your new digital heartbeat has been created ...", text, inMessage); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Performs the creation of a new HeartBeat in the database |
||||||
|
* |
||||||
|
* @param message |
||||||
|
* @return newHbtTid |
||||||
|
* @throws SQLException |
||||||
|
* @throws MessagingException |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
private int performHbtInsert(Message m, String content) throws SQLException, IOException, MessagingException { |
||||||
|
Connection con = SxPools.getConnection(sxmail.getMandantenID()); |
||||||
|
Statement stm = con.createStatement(); |
||||||
|
|
||||||
|
int newHbtTid = createHbt(con, stm, content, m.getSubject()); |
||||||
|
int newTopicId = createTopic(stm, newHbtTid); |
||||||
|
createNote(con, stm, newHbtTid, newTopicId, m, content); |
||||||
|
con.close(); |
||||||
|
return newHbtTid; |
||||||
|
} |
||||||
|
|
||||||
|
private int createHbt(Connection dbConnection, Statement stm, String content, String subject) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
String primary_customer_id = identifyPrimaryCustomerId(dbConnection, stm, content); |
||||||
|
String name = StringUtils.replace(subject, "'", "''");// for SQL insert
|
||||||
|
// Sql insert - fuck prepared statements, nobody hacks this, I don't give a
|
||||||
|
// shit, not worth my extra time or effort, I want to get things done now while
|
||||||
|
// having fun :-)
|
||||||
|
stm.execute("select sp_update_sequence('hbt_heartbeat')"); |
||||||
|
String insertSql = "INSERT INTO hbt_heartbeat \n" + "( primary_customer_id,name," + " created_at, \n" |
||||||
|
+ " status \n" + ") \n" + "VALUES \n" + "( " + primary_customer_id + ",'" + name + "', " |
||||||
|
+ " today(), \n" + " 1 \n" + ") " + ""; |
||||||
|
stm.execute(insertSql); |
||||||
|
int newHbtTid = DbUtils.getInt(stm, "select max(tid) from hbt_heartbeat"); |
||||||
|
return newHbtTid; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* Wenn im Text der weitergeleiteten Email der Absender mit @@ markiert ist, |
||||||
|
* z.B. @@hiber@his.de@@, diesen auslesen zugehörige Organisation auslesen |
||||||
|
* |
||||||
|
* @param m |
||||||
|
* @return String null oder key_apnr z.B. '1001' |
||||||
|
* @throws IOException |
||||||
|
* @throws MessagingException |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
private String identifyPrimaryCustomerId(Connection con, Statement stm, String content) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
String result = "null"; |
||||||
|
int pos1 = content.indexOf("@@"); |
||||||
|
int pos2 = content.substring(pos1 + 2).indexOf("@@"); |
||||||
|
if (pos1 > -1 && pos2 > -1) { |
||||||
|
String absender = content.substring(pos1 + 2); |
||||||
|
absender = absender.substring(0, absender.lastIndexOf("@@")); |
||||||
|
logger.log(Level.INFO," checking customer " + absender); |
||||||
|
int userinfo_id = DbUtils.getInt(con, "select tid from userinfo where email=?", absender); |
||||||
|
result = DbUtils.getString(stm, |
||||||
|
"select min(ch110_institut) from user_institution where userid=" + userinfo_id); |
||||||
|
|
||||||
|
if (result == null) |
||||||
|
result = "null"; |
||||||
|
else |
||||||
|
result = "'" + result + "'"; |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
private int createTopic(Statement stm, int newHbtTid) throws SQLException { |
||||||
|
stm.execute("select sp_update_sequence('hbt_topic')"); |
||||||
|
String insertSql = "INSERT INTO hbt_topic \n" + "( hbt_id,name, created_at)" + "VALUES (" + newHbtTid |
||||||
|
+ ",'Start',now() )"; |
||||||
|
stm.execute(insertSql); |
||||||
|
int newTopicId = DbUtils.getInt(stm, "select max(tid) from hbt_topic"); |
||||||
|
return newTopicId; |
||||||
|
} |
||||||
|
|
||||||
|
private int createNote(Connection con, Statement stm, int hbtId, int topicId, Message m, String content) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
stm.execute("select sp_update_sequence('hbt_note')"); |
||||||
|
PreparedStatement pst = con |
||||||
|
.prepareStatement(" INSERT INTO hbt_note (hbt_id,hbt_topic_id,note, created_at) VALUES (?,?,?,now());"); |
||||||
|
pst.setInt(1, hbtId); |
||||||
|
pst.setInt(2, topicId); |
||||||
|
|
||||||
|
pst.setString(3, content); |
||||||
|
pst.execute(); |
||||||
|
pst.close(); |
||||||
|
int newNoteId = DbUtils.getInt(stm, "select max(tid) from hbt_note"); |
||||||
|
saveAttachments(stm, hbtId, topicId, newNoteId, m); |
||||||
|
return newNoteId; |
||||||
|
} |
||||||
|
|
||||||
|
private void saveAttachments(Statement stm, int newHbtTid, int newTopicId, int newNoteId, Message m) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
// List<String> attachments = new ArrayList<String>();
|
||||||
|
Object content = m.getContent(); |
||||||
|
// if (content instanceof String) return null;
|
||||||
|
|
||||||
|
if (content instanceof Multipart) { |
||||||
|
Multipart multipart = (Multipart) content; |
||||||
|
for (int i = 0; i < multipart.getCount(); i++) { |
||||||
|
BodyPart part = multipart.getBodyPart(i); |
||||||
|
logger.log(Level.INFO,part.getFileName() + " " + part.getContentType() + " " + part.getDisposition()); |
||||||
|
if (part.getDisposition() != null && part.getDisposition().equalsIgnoreCase(Part.ATTACHMENT)) { |
||||||
|
// result.addAll(getAttachments(multipart.getBodyPart(i)));
|
||||||
|
String filename = SuperXManager.getWEB_INFPfad()+"/downloads/hbt_"+newHbtTid+"_" +newNoteId+"_"+FileUtils.removeProblemChars(part.getFileName()); |
||||||
|
sxDownloadsInsert(stm, newHbtTid, newTopicId, newNoteId, filename, part.getContentType()); |
||||||
|
// javaxmail >1.4 bodyPart.saveFile(filename);
|
||||||
|
// old version
|
||||||
|
InputStream is = part.getInputStream(); |
||||||
|
File f = new File(filename); |
||||||
|
FileOutputStream fos = new FileOutputStream(f); |
||||||
|
byte[] buf = new byte[4096]; |
||||||
|
int bytesRead; |
||||||
|
while ((bytesRead = is.read(buf)) != -1) { |
||||||
|
fos.write(buf, 0, bytesRead); |
||||||
|
} |
||||||
|
fos.close(); |
||||||
|
logger.log(Level.INFO," saving attachment " + (i++) + " as " + filename); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void sxDownloadsInsert(Statement stm, int newHbtTid, int newTopicId, int newNoteId, String filename, |
||||||
|
String contenttype) throws SQLException { |
||||||
|
stm.execute("select sp_update_sequence('sx_downloads')"); |
||||||
|
String filenameShort = filename.substring(filename.indexOf(File.separator + "hbt") + 1); |
||||||
|
String insertSQLSxDownloads = "INSERT INTO sx_downloads \n" + "( \n" + " name, \n" + " importdatum, \n" |
||||||
|
+ " kommentar, \n" + " kommentar_url, \n" + " contenttype, \n" + " datei, \n" + " gueltig_seit, \n" |
||||||
|
+ " gueltig_bis \n" + ") \n" + "VALUES \n" + "( \n" + " '" + filenameShort + "', \n" + " today(), \n" |
||||||
|
+ " 'kommentar_value', \n" + " 'kommentar_url_value', \n" + " '" + contenttype + "', \n" + " '" |
||||||
|
+ filenameShort + "', \n" + " today(), \n" + " date_val('1.1.3000') \n" + ") \n" + ""; |
||||||
|
stm.execute(insertSQLSxDownloads); |
||||||
|
int newDownloadTid = DbUtils.getInt(stm, "select max(tid) from sx_downloads"); |
||||||
|
stm.executeUpdate("insert into hbt_attachment (hbt_id,topic_id,note_id,download_id) values (" + newHbtTid + "," |
||||||
|
+ newTopicId + "," + newNoteId + "," + newDownloadTid + ")"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* sendFeedBackEmail -- hier hätte ich gern automatisch newline in Zeile 60 |
||||||
|
* direkt unter createNewHeartBeat automatisch erzeugt, dann nach weiter unten |
||||||
|
* im Quelltext verlagert, damit von der Reihenfolge in |
||||||
|
* createNewHeartBeat(Message message) her passt |
||||||
|
* |
||||||
|
* @param newHbtTid : tid von neuem HeartBeat in der Datenbank |
||||||
|
* @param inMessage |
||||||
|
* @throws MessagingException |
||||||
|
* @throws AddressException |
||||||
|
*/ |
||||||
|
private void sendFeedbackEmail(String subject, String text, Message inMessage) |
||||||
|
throws AddressException, MessagingException { |
||||||
|
MimeMessage reply = sxmail.createMessage(); |
||||||
|
reply.setRecipients(Message.RecipientType.TO, inMessage.getFrom()); |
||||||
|
reply.setSubject(subject); |
||||||
|
reply.setText(text); |
||||||
|
sxmail.setMessage(reply); |
||||||
|
|
||||||
|
logger.log(Level.INFO,"Reply message happily sent..."); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -1,11 +1,10 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
public class ArrowDownIcon extends BasicIcon { |
public class ArrowDownIcon extends BasicIcon { |
||||||
@Override |
public void myPaint(Graphics g) { |
||||||
public void myPaint(Graphics g) { |
drawArrowDown(g, 6); |
||||||
drawArrowDown(g, 6); |
} |
||||||
} |
|
||||||
|
} |
||||||
} |
|
||||||
|
|||||||
@ -1,14 +1,13 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
public class ArrowRight extends BasicIcon { |
public class ArrowRight extends BasicIcon { |
||||||
|
|
||||||
@Override |
void myPaint(Graphics g) { |
||||||
void myPaint(Graphics g) { |
drawArrowRight(g); |
||||||
drawArrowRight(g); |
} |
||||||
} |
|
||||||
|
} |
||||||
} |
|
||||||
|
|
||||||
//Created on 17.04.2004 at 21:42:08
|
//Created on 17.04.2004 at 21:42:08
|
||||||
@ -1,15 +1,14 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
import javax.swing.Icon; |
import javax.swing.Icon; |
||||||
|
|
||||||
public class ArrowUpIcon extends BasicIcon implements Icon { |
public class ArrowUpIcon extends BasicIcon implements Icon { |
||||||
|
|
||||||
@Override |
public void myPaint(Graphics g) { |
||||||
public void myPaint(Graphics g) { |
drawArrowUp(g, 4); |
||||||
drawArrowUp(g, 4); |
|
||||||
|
} |
||||||
} |
|
||||||
|
} |
||||||
} |
|
||||||
|
|||||||
@ -1,109 +1,99 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Color; |
import java.awt.Color; |
||||||
import java.awt.Component; |
import java.awt.Component; |
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
import javax.swing.Icon; |
import javax.swing.Icon; |
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
|
|
||||||
public abstract class BasicIcon implements Icon { |
public abstract class BasicIcon implements Icon { |
||||||
private int iconWidth = 16, iconHeight = 16; |
private int iconWidth = 16, iconHeight = 16; |
||||||
|
private Color color = Color.black; |
||||||
private Color color = Color.black; |
/** |
||||||
|
* @see javax.swing.Icon#getIconWidth() |
||||||
/** |
*/ |
||||||
* @see javax.swing.Icon#getIconWidth() |
public int getIconWidth() { |
||||||
*/ |
return iconWidth; |
||||||
@Override |
} |
||||||
public int getIconWidth() { |
|
||||||
return iconWidth; |
/** |
||||||
} |
* @see javax.swing.Icon#getIconHeight() |
||||||
|
*/ |
||||||
/** |
public int getIconHeight() { |
||||||
* @see javax.swing.Icon#getIconHeight() |
return iconHeight; |
||||||
*/ |
} |
||||||
@Override |
public void paintIcon(Component c, Graphics g, int x, int y) { |
||||||
public int getIconHeight() { |
g.translate(x, y); |
||||||
return iconHeight; |
if (c.isEnabled()) |
||||||
} |
g.setColor(color); |
||||||
|
else |
||||||
@Override |
g.setColor(Color.GRAY); |
||||||
public void paintIcon(Component c, Graphics g, int x, int y) { |
myPaint(g); |
||||||
g.translate(x, y); |
g.translate(-x, -y); |
||||||
if (c.isEnabled()) |
} |
||||||
g.setColor(color); |
abstract void myPaint(Graphics g); |
||||||
else |
void drawDoubleLine(Graphics g, int y) { |
||||||
g.setColor(Color.GRAY); |
if (y > getIconHeight() - 2) |
||||||
myPaint(g); |
throw new IllegalArgumentException("can't draw that low"); |
||||||
g.translate(-x, -y); |
g.drawLine(0, y, getIconWidth(), y); |
||||||
} |
g.drawLine(0, y + 1, getIconWidth(), y + 1); |
||||||
|
} |
||||||
abstract void myPaint(Graphics g); |
|
||||||
|
void drawArrowRight(Graphics g) { |
||||||
void drawDoubleLine(Graphics g, int y) { |
int midx = (int) Math.floor(getIconWidth() / 2); |
||||||
if (y > getIconHeight() - 2) throw new IllegalArgumentException("can't draw that low"); |
int midy = (int) Math.floor(getIconHeight() / 2); |
||||||
g.drawLine(0, y, getIconWidth(), y); |
// mittellinie
|
||||||
g.drawLine(0, y + 1, getIconWidth(), y + 1); |
g.drawLine(0, midy - 1, getIconWidth(), midy - 1); |
||||||
} |
g.drawLine(0, midy, getIconWidth(), midy); |
||||||
|
g.drawLine(0, midy + 1, getIconWidth(), midy + 1); |
||||||
void drawArrowRight(Graphics g) { |
|
||||||
int midx = (int) Math.floor(getIconWidth() / 2); |
g.drawLine(midx + 1, 1, getIconWidth(), midy - 1); |
||||||
int midy = (int) Math.floor(getIconHeight() / 2); |
g.drawLine(midx + 1, 2, getIconWidth(), midy); |
||||||
// mittellinie
|
|
||||||
g.drawLine(0, midy - 1, getIconWidth(), midy - 1); |
g.drawLine(midx + 1, getIconHeight() - 1, getIconWidth(), midy + 1); |
||||||
g.drawLine(0, midy, getIconWidth(), midy); |
g.drawLine(midx + 1, getIconHeight() - 2, getIconWidth(), midy); |
||||||
g.drawLine(0, midy + 1, getIconWidth(), midy + 1); |
|
||||||
|
} |
||||||
g.drawLine(midx + 1, 1, getIconWidth(), midy - 1); |
|
||||||
g.drawLine(midx + 1, 2, getIconWidth(), midy); |
void drawArrowUp(Graphics g, int y) { |
||||||
|
int midx = (int) Math.floor(getIconWidth() / 2); |
||||||
g.drawLine(midx + 1, getIconHeight() - 1, getIconWidth(), midy + 1); |
int midy = (int) Math.floor(getIconHeight() / 2); |
||||||
g.drawLine(midx + 1, getIconHeight() - 2, getIconWidth(), midy); |
g.drawLine(0, y + midy, midx, y); |
||||||
|
g.drawLine(midx, y, getIconWidth(), y + midy); |
||||||
} |
g.drawLine(0, y + midy + 1, midx, y + 1); |
||||||
|
g.drawLine(midx, y + 1, getIconWidth(), y + midy + 1); |
||||||
void drawArrowUp(Graphics g, int y) { |
|
||||||
int midx = (int) Math.floor(getIconWidth() / 2); |
} |
||||||
int midy = (int) Math.floor(getIconHeight() / 2); |
void drawArrowDown(Graphics g, int y) { |
||||||
g.drawLine(0, y + midy, midx, y); |
int midx = (int) Math.floor(getIconWidth() / 2); |
||||||
g.drawLine(midx, y, getIconWidth(), y + midy); |
int midy = (int) Math.floor(getIconHeight() / 2); |
||||||
g.drawLine(0, y + midy + 1, midx, y + 1); |
g.drawLine(0, y, midx, midy + y); |
||||||
g.drawLine(midx, y + 1, getIconWidth(), y + midy + 1); |
g.drawLine(midx, y + midy, getIconWidth(), y); |
||||||
|
g.drawLine(0, y + 1, midx, midy + y + 1); |
||||||
} |
g.drawLine(midx, y + midy + 1, getIconWidth(), y + 1); |
||||||
|
|
||||||
void drawArrowDown(Graphics g, int y) { |
} |
||||||
int midx = (int) Math.floor(getIconWidth() / 2); |
public static void main(String[] args) { |
||||||
int midy = (int) Math.floor(getIconHeight() / 2); |
de.memtext.widgets.MBFrame f = new de.memtext.widgets.MBFrame("test"); |
||||||
g.drawLine(0, y, midx, midy + y); |
f.setCenter(new JButton("test", new ArrowRight())); |
||||||
g.drawLine(midx, y + midy, getIconWidth(), y); |
f.pack(); |
||||||
g.drawLine(0, y + 1, midx, midy + y + 1); |
f.show(); |
||||||
g.drawLine(midx, y + midy + 1, getIconWidth(), y + 1); |
} |
||||||
|
public void setIconHeight(int i) { |
||||||
} |
iconHeight = i; |
||||||
|
} |
||||||
public static void main(String[] args) { |
|
||||||
de.memtext.widgets.MBFrame f = new de.memtext.widgets.MBFrame("test"); |
public void setIconWidth(int i) { |
||||||
f.setCenter(new JButton("test", new ArrowRight())); |
iconWidth = i; |
||||||
f.pack(); |
} |
||||||
f.show(); |
|
||||||
} |
public Color getColor() { |
||||||
|
return color; |
||||||
public void setIconHeight(int i) { |
} |
||||||
iconHeight = i; |
|
||||||
} |
public void setColor(Color color) { |
||||||
|
this.color = color; |
||||||
public void setIconWidth(int i) { |
} |
||||||
iconWidth = i; |
|
||||||
} |
} |
||||||
|
|
||||||
public Color getColor() { |
|
||||||
return color; |
|
||||||
} |
|
||||||
|
|
||||||
public void setColor(Color color) { |
|
||||||
this.color = color; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,16 +1,16 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
|
|
||||||
public class DoubleArrowDownIcon extends BasicIcon { |
public class DoubleArrowDownIcon extends BasicIcon { |
||||||
@Override |
public void myPaint(Graphics g) |
||||||
public void myPaint(Graphics g) { |
{ |
||||||
drawArrowDown(g, 2); |
drawArrowDown(g,2); |
||||||
drawArrowDown(g, 6); |
drawArrowDown(g,6); |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
|||||||
@ -1,23 +1,23 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change this generated comment edit the template variable "typecomment": |
* To change this generated comment edit the template variable "typecomment": |
||||||
* Window>Preferences>Java>Templates. |
* Window>Preferences>Java>Templates. |
||||||
* To enable and disable the creation of type comments go to |
* To enable and disable the creation of type comments go to |
||||||
* Window>Preferences>Java>Code Generation. |
* Window>Preferences>Java>Code Generation. |
||||||
*/ |
*/ |
||||||
public class DoubleArrowDownLineIcon extends BasicIcon { |
public class DoubleArrowDownLineIcon extends BasicIcon { |
||||||
@Override |
public void myPaint(Graphics g) |
||||||
public void myPaint(Graphics g) { |
{ |
||||||
drawArrowDown(g, 0); |
drawArrowDown(g,0); |
||||||
drawArrowDown(g, 4); |
drawArrowDown(g,4); |
||||||
drawDoubleLine(g, getIconHeight() - 2); |
drawDoubleLine(g,getIconHeight()-2); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
|||||||
@ -1,22 +1,22 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change this generated comment edit the template variable "typecomment": |
* To change this generated comment edit the template variable "typecomment": |
||||||
* Window>Preferences>Java>Templates. |
* Window>Preferences>Java>Templates. |
||||||
* To enable and disable the creation of type comments go to |
* To enable and disable the creation of type comments go to |
||||||
* Window>Preferences>Java>Code Generation. |
* Window>Preferences>Java>Code Generation. |
||||||
*/ |
*/ |
||||||
public class DoubleArrowUpIcon extends BasicIcon { |
public class DoubleArrowUpIcon extends BasicIcon { |
||||||
@Override |
public void myPaint(Graphics g) |
||||||
public void myPaint(Graphics g) { |
{ |
||||||
drawArrowUp(g, 0); |
drawArrowUp(g,0); |
||||||
drawArrowUp(g, 4); |
drawArrowUp(g,4); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue