diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 3d51f7d0..00000000 --- a/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -# EditorConfig is awesome: https://EditorConfig.org - -root = true - -[*] -end_of_line = lf -indent_size = 2 -indent_style = spaces -insert_final_newline = true -trim_trailing_whitespace = true - -[*.java] -indent_size = 4 - -[*.md] -trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 4e5f4943..00000000 --- a/.eslintrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "extends": "eslint:recommended", - "env": { - "es6": true, - "commonjs": true - }, - "globals": { - "app": "readonly", - "HopObject": "readonly", - "java": "readonly", - "Packages": "readonly", - "req": "readonly", - "res": "readonly" - } -} diff --git a/.github/actions/ssh/action.yml b/.github/actions/ssh/action.yml deleted file mode 100644 index 5c4886ab..00000000 --- a/.github/actions/ssh/action.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: SSH setup -description: Set up the SSH agent - -inputs: - config: - description: The SSH configuration - required: true - key: - description: The private SSH key - required: true - known-hosts: - description: The list of known hosts - required: true - -runs: - using: composite - - steps: - - name: Configure SSH - shell: sh - env: - CONFIG: ${{ inputs.config }} - KNOWN_HOSTS: ${{ inputs.known-hosts }} - run: | - mkdir -p ~/.ssh - echo "${CONFIG}" > ~/.ssh/config - echo "${KNOWN_HOSTS}" > ~/.ssh/known_hosts - - - name: Start SSH agent - shell: bash - env: - SOCKET: /tmp/ssh-agent.sock - run: | - echo "SSH_AUTH_SOCK=${SOCKET}" >> $GITHUB_ENV - ssh-agent -a ${SOCKET} > /dev/null - - - name: Add SSH key - shell: bash - env: - KEY: ${{ inputs.key }} - run: | - ssh-add - <<< "${KEY}" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 69bcdeab..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Build - -on: - push: - paths: - - .github/workflows/build.yml - - build.gradle - - settings.gradle - - src/** - - launcher/build.gradle - - launcher/src/** - workflow_dispatch: - -jobs: - build: - runs-on: antville - - steps: - - uses: actions/checkout@v4 - - - name: Compile with Gradle - run: ./gradlew :compileJava diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 9eeb14b0..00000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Deploy - -on: - workflow_dispatch: - inputs: - hostname: - description: Hostname - type: string - required: true - default: antville.org - -jobs: - stage: - runs-on: antville - - environment: - name: production - url: ${{ inputs.hostname }} - - steps: - - uses: actions/checkout@v4 - - - name: Build with Gradle - run: ./gradlew installDist - - - name: Copy build files to server - run: | - rsync ./build/install/helma/ ${{ inputs.hostname }}:./ \ - --verbose --archive --delete --compress \ - --filter '+ /bin' \ - --filter '+ /extras' \ - --filter '+ /launcher.jar' \ - --filter '- /lib/ext' \ - --filter '+ /lib' \ - --filter '+ /modules' \ - --filter '- /*' - - - name: Restart Helma - run: ssh ${{ inputs.hostname }} restart diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index ac8a3d1a..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Release - -on: - workflow_dispatch: - push: - tags: '2*' - -permissions: - contents: write - -jobs: - release: - runs-on: antville - - env: - GH_TOKEN: ${{ secrets.GH_TOKEN }} - LC_TIME: en_US.UTF-8 - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Create release notes - id: create_release_notes - run: | - release_notes=$(npx git-cliff@latest --latest) - # Write the release notes as a heredoc to the workflow output - # ⚠️ No white space around `<<` is crucial! - echo "release_notes<<.eot0x03" >> $GITHUB_OUTPUT - echo "$release_notes" >> $GITHUB_OUTPUT - echo ".eot0x03" >> $GITHUB_OUTPUT - - - name: Build with Gradle - run: ./gradlew assembleDist - - - name: Create release - uses: actions/forgejo-release@v2 - with: - direction: upload - url: https://code.host.antville.org - token: ${{ github.token }} - title: Helma ${{ github.ref_name }} - release-dir: build/distributions - release-notes: ${{ steps.create_release_notes.outputs.release_notes }} - verbose: true - - - name: Create release at GitHub - run: | - gh release create "$GITHUB_REF_NAME" \ - --repo "$GITHUB_REPOSITORY" \ - --title "Helma ${{ github.ref_name }}" \ - --notes "${{ steps.create_release_notes.outputs.release_notes }}" - - - name: Upload release assets to GitHub - run: | - gh release upload "$GITHUB_REF_NAME" build/distributions/helma-*.* \ - --repo "$GITHUB_REPOSITORY" \ - --clobber diff --git a/.github/workflows/renovate.yml b/.github/workflows/renovate.yml deleted file mode 100644 index e470128c..00000000 --- a/.github/workflows/renovate.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Run Renovate - -on: - schedule: - - cron: "13 * * * *" - workflow_dispatch: - -jobs: - renovate: - runs-on: antville - - steps: - - uses: actions/checkout@v4 - - - name: Run Renovate - # See - # debug | info | warn | error | fatal - run: LOG_LEVEL=info npx renovate - env: - # Renovate is using this token to retrieve release notes - GITHUB_COM_TOKEN: ${{ secrets.renovate_github_com_token }} - # Autodiscover is better suited for an extra repo running Renovate on all desired repos - #RENOVATE_AUTODISCOVER: 'true' - RENOVATE_CONFIG_FILE: renovate.json - RENOVATE_ENDPOINT: ${{ github.api_url }} - RENOVATE_GIT_AUTHOR: Renovate Bot - #RENOVATE_GIT_IGNORED_AUTHORS: - # - 29139614+renovate[bot]@users.noreply.github.com - RENOVATE_IGNORE_PR_AUTHOR: 'true' - RENOVATE_LOG_FILE: renovate-log.ndjson - RENOVATE_LOG_FILE_LEVEL: debug - RENOVATE_PLATFORM: gitea - RENOVATE_REPOSITORIES: ${{ github.repository }} - RENOVATE_REPOSITORY_CACHE: 'enabled' - # github.token is not working here, it lacks some permissions required by Renovate - RENOVATE_TOKEN: ${{ secrets.renovate_token }} - - - name: Save log file - # FIXME: v4 of this action causes an error on Forgejo (“You must configure a GitHub token”) - uses: actions/upload-artifact@v3 - if: always() - with: - name: renovate-log.ndjson - path: renovate-log.ndjson diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 7bf7bcbc..00000000 --- a/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -# Generally ignore hidden files -.* - -# Manage some Codium configuration -.vscode/* -!.vscode -!.vscode/extensions.json -!.vscode/launch.json -!.vscode/settings.json -!.vscode/tasks.json - -# Ignore files created during build or run -/bin -/backups -build -/docs -/lib -/licenses -/log - -# Ignore files managed in src/dist -/*.properties -/apps -/db -/extras -/launcher.jar -/static - -# Manage Gradle configuration -!/gradle.properties diff --git a/.java-version b/.java-version deleted file mode 100644 index 98d9bcb7..00000000 --- a/.java-version +++ /dev/null @@ -1 +0,0 @@ -17 diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index c52f6863..00000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "recommendations": [ - "vscjava.vscode-java-pack", - "vscjava.vscode-gradle" - ] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index b9116072..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "java", - "name": "Current File", - "request": "launch", - "mainClass": "${file}" - }, - { - "type": "java", - "name": "Debug", - "request": "launch", - "mainClass": "helma.main.Server", - "projectName": "helma_" - } - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 83708e5d..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "files.watcherExclude": { - "apps/": true - }, - "java.configuration.updateBuildConfiguration": "automatic" -} diff --git a/CHANGES.md b/CHANGES.md deleted file mode 100644 index 5527d072..00000000 --- a/CHANGES.md +++ /dev/null @@ -1,31 +0,0 @@ -# Change Log - -## May 17, 2020 - -* Added support for colored log output -* Added xgettext and po2js tasks (only running with Antville right now) - -## April 13, 2020 - -* Added support for gzip compressed response in helma.Http -* Fixed helma.Http.getURL() not following redirects if protocol changes (e.g. http → https) -* Fixed references to obsolete Base64 encoder in modules -* Updated JavaMail library to implementation package - -## March 21, 2020 - -* Completely rewrote build system with Gradle -* Separated launcher from main source as Gradle subproject -* Launcher now includes all JARs found in `lib` -* Upgraded Rhino to version 1.7.12 -* Upgraded Jetty to version 9.x -* Fixed compatibility issues with Java 11 -* Removed support for Apache JServ Protocol (AJP) -* Added support for CommonJS require() method -* Allow variable arguments in res.write() and res.writeln() -* Replaced Helma’s MD5 and Base64 methods with equivalent methods from Apache Commons -* Refactored String methods from Java to JavaScript: encode(), encodeForm(), encodeXml(), stripTags() -* Replaced custom String methods with Rhino’s built-in ones: endsWith(), repeat(), startsWith(), trim() -* Refactored custom String.pad() method with built-in methods -* Redefined custom Array.contains() method with built-in Array.includes() -* Refactored custom Array methods with built-in methods: intersection(), union() diff --git a/CNAME b/CNAME new file mode 100644 index 00000000..baf59dc2 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +helma.js.org diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 65dfb884..00000000 --- a/LICENSE.md +++ /dev/null @@ -1,37 +0,0 @@ -# License - -Copyright (c) 1999-2025 Helma Project. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - -3. Products derived from this software may not be called "Helma" - or "Hop", nor may "Helma" or "Hop" appear in their name, without - prior written permission of the Helma Project Group. For written - permission, please contact helma@helma.org. - -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE HELMA PROJECT OR ITS -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED -OF THE POSSIBILITY OF SUCH DAMAGE. - -Helma includes third party software released under different specific -license terms. See the licenses directory in the Helma distribution -for a list of these licenses. diff --git a/README.md b/README.md deleted file mode 100644 index f6438677..00000000 --- a/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# How to Helma - -## TL;DR - -- Make sure you have Java 17 or higher installed -- Download and unpack the [latest release](https://code.host.antville.org/antville/helma/releases) -- Invoke `./bin/helma`, resp. `./bin/helma.bat`, depending on your platform -- Direct your web browser to - -## Introduction - -Helma is an open source web application framework for fast and efficient scripting and serving of your websites and Internet applications. - -Helma is written in Java and employs JavaScript for its server-side scripting environment, removing the need for compilation cycles and reducing development costs while giving you instant access to leverage the whole wealth of Java libraries out there. - -Helma pioneered the simple and codeless mapping of application objects to database tables, which has only recently come into vogue with other web frameworks. In addition, an embedded object-oriented database performs automatic data persistence of unmapped objects. - -Helma has proven itself to be stable and fast, capable of serving high traffic sites with hundreds of thousands of dynamic pages per day. The Austrian Broadcasting Corporation, popular weblog hosting sites such as antville.org, twoday.net, and blogger.de, among many others, have successfully been deploying Helma for several years now. - -Although Helma became a Grande Dame of server-side JavaScript already decades ago when she performed in cozy Finnish clubs, she appears somehow retired nowadays. Nevertheless, she is here to stay for those last ones out there still tinkering with this nostalgic and wonderful piece of software. - -## System Requirements - -You need a Java virtual machine version 11 or higher to run Helma. - -Please consult the documentation of your platform how to obtain and install Java. - -You also can directly download a [Java runtime or development kit](https://www.oracle.com/java/technologies/javase-downloads.html#javasejdk) from Oracle. - -Helma is built with [Gradle](https://gradle.org), the build task depends on the binaries [rsync](https://rsync.samba.org) and [npx](https://www.npmjs.com/package/npx) being installed on your system. - -## Development - -### Additional Prerequisites - -* [Node.js](https://nodejs.org) LTS version -* [Rsync](https://rsync.samba.org) version ≥ 3.1.0 - -Clone this repository to your machine and run Helma with `./gradlew run`. - -To update the installation from a build, run `./gradlew update` and enter `yes` at the prompt. - -> ⚠️ -> Please be aware that this step is going to overwrite files in the installation directory – escpecially at a later time when there might be substantial changes. Should this happen by accident you find the previous installation in the `backups` directory. -> -> Alternatively, you could move or copy the desired files manually from the installation directory `build/install/helma`. - -After all files are put into place start Helma by invoking `./bin/helma.bat` or `./bin/helma`, depending on whether you are on Windows or Linux / Unix / OS X, respectively. If the `java` command is not found, try setting the `JAVA_HOME` environment variable to the location of your Java installation. - -You can adjust server-wide settings in the `server.properties` file. For example, you could set the `smtp` property to the name of the SMTP server that Helma should use to send e-mail. Applications can be started or stopped by editing the `apps.properties` file, or through the web interface using the management application that is part of Helma. - -If all goes well you should be able to connect your browser to – port 8080 on the local machine, that is. - -Helma comes with a version of [Jetty](http://eclipse.org/jetty/), a lightweight yet industrial strength web server. - -While Jetty works well for development and in fact deploying real web sites, you might want to run Helma with the web server you are already using. This is most easily done by proxying Helma. Please consult the documentation of your web server how to achieve this. - -Finally, Helma can be plugged into Servlet containers using Servlet classes that communicate with Helma either directly or via Java RMI. Be warned that these options may be harder to set up and maintain though, since most of the recent development efforts have been geared towards a proxied setup. - -## Documentation and Further Information - -After installing and running Helma, you will be able to access introductions to the features of Helma and the various included development tools. Further information you will find on the helma.org website: - -> 😿 -> Unfortunately, the Helma website disappeard in the meantime. However, with some archaeological web digging and thanks to the great search engines and archive services out there it is still possible to find useful resources. - -- [helma.org at Internet Archive](http://web.archive.org/web/20180122132315/http://helma.org) -- [Documentation](http://web.archive.org/web/20100530234322/http://helma.org/documentation/) -- [API Reference](https://helma.serverjs.org/reference/) -- [Tutorial](http://web.archive.org/web/20100526182848/http://helma.org/Documentation/Object-Relational+Mapping+Tutorial/) -- [DocBook](http://dev.orf.at/download/helma/documentation/documentation.pdf) diff --git a/_config.yml b/_config.yml new file mode 100644 index 00000000..c7418817 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-slate \ No newline at end of file diff --git a/build.gradle b/build.gradle deleted file mode 100644 index cd60e214..00000000 --- a/build.gradle +++ /dev/null @@ -1,294 +0,0 @@ -plugins { - id 'application' - id 'com.github.jk1.dependency-license-report' version '2.9' -} - -import org.apache.tools.ant.filters.FixCrLfFilter - -def jettyLogLevel = '-Dorg.eclipse.jetty.LEVEL=WARN' - -// Suppress menu bar and default icon being shown in macos dock (Radar #5754483) -// See https://developer.apple.com/library/content/releasenotes/Java/JavaLeopardUpdate1RN/ResolvedIssues/ResolvedIssues.html -def suppressMacosDockIcon = '-Dapple.awt.UIElement=true' - -// This list is used to determine which files need processing of line endings -def textFiles = ['**/*.hac', '**/.html', '**/*.js', '**/*.md', '**/*.properties', '**/*.skin', '**/*.txt', '**/*.xml'] - -allprojects { - apply plugin: 'java' - - java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - } - - repositories { - mavenCentral() - } -} - -version = new Date().format("yy.M.d") - -tasks.build.dependsOn javadoc, 'jsdoc', 'generateLicenseReport' -tasks.compileJava.dependsOn 'processSource' - -// Disable DocLint for now -// See -if (JavaVersion.current().isJava8Compatible()) { - allprojects { - tasks.withType(Javadoc) { - options.addStringOption('Xdoclint:none', '-quiet') - } - } -} - -configurations { - // Wrapping implementation because it does not allow access to its files - // (i.e. cannot be resolved) - library.extendsFrom implementation -} - -dependencies { - implementation 'com.google.code.gson:gson:2.12.1' - implementation 'commons-codec:commons-codec:1.18.0' - implementation 'org.apache.commons:commons-fileupload2-core:2.0.0-M2' - implementation 'org.apache.commons:commons-fileupload2-jakarta:2.0.0-M1' - implementation 'commons-logging:commons-logging:1.3.5' - implementation 'commons-net:commons-net:3.11.1' - implementation 'com.sun.mail:javax.mail:1.6.2' - implementation 'jakarta.servlet:jakarta.servlet-api:5.0.0' - implementation 'org.ccil.cowan.tagsoup:tagsoup:1.2.1' - implementation 'org.eclipse.jetty.ee9:jetty-ee9-servlet:12.0.19' - implementation 'org.eclipse.jetty:jetty-xml:12.0.19' - implementation 'org.mozilla:rhino-all:1.8.0' - implementation 'org.sejda.imageio:webp-imageio:0.1.6' - implementation 'xerces:xercesImpl:2.12.2' - implementation 'xmlrpc:xmlrpc:2.0.1' -} - -def rhinoJar = configurations.library.files.find { jar -> - jar.name.startsWith('rhino') -} - -run { - jvmArgs jettyLogLevel, suppressMacosDockIcon - classpath += fileTree(dir: 'lib/ext', include: '*.jar') -} - -application { - mainClass = 'helma.main.Server' - - applicationDistribution.from(projectDir) { - include 'modules/**' - include 'LICENSE.md' - include 'README.md' - include 'start.*' - } - - applicationDistribution.from(javadoc.destinationDir) { - include '**' - into 'docs/javadoc' - } - - applicationDistribution.from("${project.buildDir}/docs/jsdoc") { - include '**' - into 'docs/jsdoc' - } - - applicationDistribution.from("${project.buildDir}/reports/dependency-license") { - include '**' - into 'licenses' - } -} - -startScripts { - applicationName = 'helma' - classpath = files('../launcher.jar') - mainClass = 'helma.main.launcher.Main' - - defaultJvmOpts = [jettyLogLevel, suppressMacosDockIcon] - - doLast { - // Work-around to make the classpath above work (launcher.jar is located outside of `lib` dir) - // See https://discuss.gradle.org/t/classpath-in-application-plugin-is-building-always-relative-to-app-home-lib-directory/2012 - def unixScriptFile = file getUnixScript() - def windowsScriptFile = file getWindowsScript() - unixScriptFile.text = unixScriptFile.text.replace('$APP_HOME/lib', '$APP_HOME') - windowsScriptFile.text = windowsScriptFile.text.replace('%APP_HOME%\\lib', '%APP_HOME%') - } -} - -distributions { - main { - contents { - from project(':launcher').jar - } - } -} - -distTar { - dependsOn ':generateLicenseReport', ':javadoc', ':jsdoc' - - compression = Compression.GZIP - - filesMatching(textFiles) { - filter(FixCrLfFilter.class, eol: FixCrLfFilter.CrLf.newInstance("lf")) - } -} - -distZip { - dependsOn ':generateLicenseReport', ':javadoc', ':jsdoc' - - filesMatching(textFiles) { - filter(FixCrLfFilter.class, eol: FixCrLfFilter.CrLf.newInstance("crlf")) - } -} - -installDist { - dependsOn build -} - -def processSource = tasks.register('processSource', Sync) { - def gitOutput = new ByteArrayOutputStream() - - outputs.dir "${project.buildDir}/src" - - exec { - commandLine 'git', 'rev-parse', '--short', 'HEAD' - standardOutput = gitOutput - errorOutput = new ByteArrayOutputStream() - ignoreExitValue = true - } - - from 'src' - - filter { - line -> line - .replaceAll('__builddate__', new Date().format("d MMM yyyy")) - .replaceAll('__commithash__', gitOutput.toString().trim()) - .replaceAll('__version__', version) - } into outputs.files.singleFile -} - -tasks.compileJava.source = processSource.map { it.outputs.files } - -tasks.register('update') { - dependsOn installDist - - def rsyncArgs = ['--archive', '--filter', '- backups'] - - def confirm = { - ant.input(message: 'Update this installation?', validargs: 'yes,no', addproperty: 'continue') - return ant.continue == 'yes' - } - - onlyIf { confirm() } - - doFirst { - def backupDir = 'backups/' + new Date().format('yyyyMMdd-HHmmss') - - mkdir backupDir - - exec { - // Create a backup with rsync instead of a CopyTask because the latter chokes on multi-byte characters - // See https://github.com/gradle/gradle/issues/789 - executable 'rsync' - args rsyncArgs - args "$projectDir/", backupDir - } - - print "Created backup of ${projectDir} in ${backupDir}" - } - - doLast { - exec { - // Using rsync to selectively update the repo directory - executable 'rsync' - args '--delete' - args rsyncArgs - args '--filter', '+ bin/***' - args '--filter', '+ docs/***' - args '--filter', '+ extras/***' - args '--filter', '+ launcher.jar' - args '--filter', '+ lib' - args '--filter', '+ *.jar' - args '--filter', '- *' - args "${installDist.destinationDir}/", projectDir - } - } -} - -tasks.register('jsdoc', Exec) { - description 'Generates JSDoc API documentation for the included JavaScript modules.' - group 'Documentation' - - def sources = ['modules/core', 'modules/helma', 'modules/jala/code'] - def destination = "${project.buildDir}/docs/jsdoc" - - sources.each { dir -> inputs.dir dir } - outputs.dir destination - - executable 'npx' - args = ['jsdoc', '-d', "$destination"].plus(sources) -} - -tasks.register('xgettext', JavaExec) { - description 'Extracts translatable message strings from source code.' - group 'i18n' - - classpath = files('launcher.jar') - mainClass = 'helma.main.launcher.Commandline' - - // TODO: Decouple from Antville app - args = [ - // Root.extractMessages is currently located in antville/code/Global/i18n.js - 'antville.extractMessages', - 'modules/jala/util/HopKit/scripts/MessageParser.js', - 'code compat', - 'apps/antville/i18n/antville.pot' - ] -} - -tasks.register('po2js', JavaExec) { - description 'Converts translated message strings from PO format to JavaScript.' - group 'i18n' - - classpath = files(rhinoJar) - mainClass = 'org.mozilla.javascript.tools.shell.Main' - - // TODO: Decouple from Antville app - args = [ - 'modules/jala/util/HopKit/scripts/PoParser.js', - 'apps/antville/i18n', - 'apps/antville/i18n' - ] -} - -tasks.register('rhinoShell', JavaExec) { - description 'Runs the interactive Rhino JavaScript shell.' - group 'Application' - - classpath = files(rhinoJar) - mainClass = 'org.mozilla.javascript.tools.shell.Main' - - standardInput = System.in -} - -// Call this task with a function definition using the `-P` parameter, e.g. -// `./gradlew commandLine -Pfunction=manage.getAllApplications` -tasks.register('commandLine', JavaExec) { - description 'Runs a function in a Helma application with `-Pfunction=app.functionName`.' - group 'Application' - - classpath = files('launcher.jar') - mainClass = 'helma.main.launcher.Commandline' - args '-h', projectDir, function -} - -tasks.register('debug', JavaExec) { - group = 'application' - main = 'helma.main.Server' - classpath = sourceSets.main.runtimeClasspath - jvmArgs = ['-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005'] - classpath += fileTree(dir: 'lib/ext', include: '*.jar') -} diff --git a/cliff.toml b/cliff.toml deleted file mode 100644 index 755c4ca2..00000000 --- a/cliff.toml +++ /dev/null @@ -1,52 +0,0 @@ -# git-cliff ~ default configuration file -# https://git-cliff.org/docs/configuration -# -# Lines starting with "#" are comments. -# Configuration options are organized into tables and keys. -# See documentation for more information on available options. - -[changelog] -trim = true - -header = "## Changes" - -body = """ -{% for group, commits in commits | filter(attribute="merge_commit") | group_by(attribute="group") %} - ### {{ group | striptags | trim | upper_first }} - {% for commit in commits %} - * [{{ commit.id | split(pat="") | slice(end=11) | join() }}]\ - (https://code.host.antville.org/antville/helma/commit/{{ commit.id }}) \ - {% if commit.breaking %}**Breaking:** {% endif %}\ - {{ commit.message | split(pat="\\n") | first | upper_first | escape }}\ - {% endfor %} -{% endfor %} - -**Full Changelog:** [{{ previous.version }} → {{ version }}]\ -(https://code.host.antville.org/antville/helma/compare/\ -{{ previous.version | urlencode }}..{{ version | urlencode }})\n\n -""" - -footer = """ -Generated by [git-cliff](https://git-cliff.org/). -""" - -[git] -conventional_commits = false -filter_commits = false -filter_unconventional = false -protect_breaking_commits = false -sort_commits = "newest" -split_commits = false -topo_order = false - -commit_parsers = [ - { message = "^Apply \\d+ suggestion", skip = true }, - { message = "^Merge .*(branch|dependabot|dependency|renovate)", skip = true }, - { message = "^Lock file maintenance", skip = true }, - { message = "yarn\\.lock", skip = true }, - - { message = "^[Ff]ix", group = " 🐛 Bug Fixes" }, - { field = "author.name", pattern = "[Rr]enovate|[Dd]ependabot", group = " 📦 Dependency Updates" }, - { message = "^Merge pull request", group = " 🔀 Merges" }, - { message = ".*", group = " Uncategorized" }, -] diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index 71690dc7..00000000 --- a/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -org.gradle.console = plain - -function = diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 1b33c55b..00000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 002b867c..00000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,7 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip -networkTimeout=10000 -validateDistributionUrl=true -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index 23d15a93..00000000 --- a/gradlew +++ /dev/null @@ -1,251 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original 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. -# -# SPDX-License-Identifier: Apache-2.0 -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH="\\\"\\\"" - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ - "$@" - -# Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" -fi - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index 5eed7ee8..00000000 --- a/gradlew.bat +++ /dev/null @@ -1,94 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH= - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/index.md b/index.md new file mode 100644 index 00000000..81533a2e --- /dev/null +++ b/index.md @@ -0,0 +1,36 @@ +## Server-side JavaScript is so 1999 + +It was the year when one of the earlier collaborative weblogs (yes, that’s what we called blogs at the time) called [Helma turned into a _corporate website_](http://web.archive.org/web/20010502043303/http://classic.helma.at/comment.asp?helmatic=hannes&item=7696)… + +Thus, the life of Helma, the _web application framework_ begun. And with it, a serious effort of applying server-side JavaScript. + +**JavaScript on the server. +Long before NodeJS. +Way long.** + +Helma would not have been possible without the creative minds at the Austrian public broadcaster ORF, once called ORF Online, ORF.at nowadays. + +They commissioned the precursor of Helma, a publishing system based on Marimba, and they used and further developed it for their in-house content management. + +This early code blossomed into Helma and the content management organically grew into it, together with a bunch of sidelined applications, comprehending forum apps, podcast services and even SSL certificate management. + +And all by writing JavaScript on the server. +Long before NodeJS. +Way long. + +From ORF.at’s solid trunk a lot of colorful branches started to sprout, some of which still are around: + +* [Antville](https://antville.org), the non-profit weblog hosting system, and its (at the time) corporate sibling [Twoday](https://twoday.net) +* [Parq](http://www.parq.at) and [Coplaner](http://coplaner.net), two groupware platforms for “joint building ventures” (_Baugruppen_ in German) + +All written in JavaScript on the server. +Long before NodeJS. +Way long. + +The people using Helma thought it was very convenient to write code in the same programming language for both, the client _and_ the server. And they were not wrong: along came NodeJS and somehow suddenly JavaScript was everywhere. + +Unfortunately, Helma was not. And so she became part of the JavaScript mythology. A blink of an eye in the history of the web. Almost forgotten. Blessed forever. + +A little server-side JavaScript framework called Helma. +Long before NodeJS. +Way long ago. diff --git a/launcher/build.gradle b/launcher/build.gradle deleted file mode 100644 index 7e1983a9..00000000 --- a/launcher/build.gradle +++ /dev/null @@ -1,5 +0,0 @@ -jar { - manifest { - from 'src/main/java/helma/main/launcher/manifest.txt' - } -} diff --git a/launcher/src/main/java/helma/main/launcher/Commandline.java b/launcher/src/main/java/helma/main/launcher/Commandline.java deleted file mode 100644 index 5dc211bd..00000000 --- a/launcher/src/main/java/helma/main/launcher/Commandline.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.main.launcher; - -import java.lang.reflect.*; - -/** - * Helma bootstrap class. Figures out Helma home directory, sets up class path and - * lauchnes main class. This class must be invoked from a jar file in order to work. - * - * @author Stefan Pollach - */ -public class Commandline { - - /** - * boot method for running a request from the command line. - * This retrieves the Helma home directory, creates the - * classpath, get the request properties, creates the app and - * runs it - *- - * @param args command line arguments - */ - public static void main(String[] args) { - try { - String installDir = Main.getInstallDir(args); - - ClassLoader loader = Main.createClassLoader(installDir); - - // get the main server class - Class clazz = loader.loadClass("helma.main.CommandlineRunner"); - Class[] cargs = new Class[]{args.getClass()}; - Method main = clazz.getMethod("main", cargs); - Object[] nargs = new Object[]{args}; - - // and invoke the static main(String, String[]) method - main.invoke(null, nargs); - } catch (Exception x) { - // unable to get Helma installation dir from launcher jar - x.printStackTrace(); - System.err.println("Unable to get Helma installation directory: "); - System.err.println(x.getMessage()); - System.exit(2); - } - } -} diff --git a/launcher/src/main/java/helma/main/launcher/Main.java b/launcher/src/main/java/helma/main/launcher/Main.java deleted file mode 100644 index d7060eda..00000000 --- a/launcher/src/main/java/helma/main/launcher/Main.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.main.launcher; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.net.URLDecoder; -import java.net.MalformedURLException; -import java.util.ArrayList; - -/** - * Helma bootstrap class. Basically this is a convenience wrapper that takes over - * the job of setting the class path and helma install directory before launching - * the static main(String[]) method in helma.main.Server. This class - * should be invoked from a jar file in the Helma install directory in order to - * be able to set up class and install paths. - */ -public class Main { - private Class serverClass; - private Object server; - - private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; - private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - - /** - * Helma boot method. This retrieves the Helma home directory, creates the - * classpath and invokes main() in helma.main.Server. - * - * @param args command line arguments - * - */ - public static void main(String[] args) { - Main main = new Main(); - main.init(args); - main.start(); - } - - public void init(String[] args) { - try { - String installDir = getInstallDir(args); - ClassLoader loader = createClassLoader(installDir); - // get the main server class - serverClass = loader.loadClass("helma.main.Server"); - Class[] cargs = new Class[]{args.getClass()}; - Method loadServer = serverClass.getMethod("loadServer", cargs); - Object[] nargs = new Object[]{args}; - // and invoke the static loadServer(String[]) method - server = loadServer.invoke(null, nargs); - Method init = serverClass.getMethod("init", EMPTY_CLASS_ARRAY); - init.invoke(server, EMPTY_OBJECT_ARRAY); - } catch (Exception x) { - // unable to get Helma installation dir from launcher jar - System.err.println("Unable to load Helma: "); - x.printStackTrace(); - System.exit(2); - } - } - - public void start() { - try { - Method start = serverClass.getMethod("start", EMPTY_CLASS_ARRAY); - start.invoke(server, EMPTY_OBJECT_ARRAY); - } catch (Exception x) { - // unable to get Helma installation dir from launcher jar - System.err.println("Unable to start Helma: "); - x.printStackTrace(); - System.exit(2); - } - } - - public void stop() { - try { - Method start = serverClass.getMethod("stop", EMPTY_CLASS_ARRAY); - start.invoke(server, EMPTY_OBJECT_ARRAY); - } catch (Exception x) { - // unable to get Helma installation dir from launcher jar - System.err.println("Unable to stop Helma: "); - x.printStackTrace(); - System.exit(2); - } - } - - public void destroy() { - try { - Method start = serverClass.getMethod("shutdown", EMPTY_CLASS_ARRAY); - start.invoke(server, EMPTY_OBJECT_ARRAY); - } catch (Exception x) { - // unable to get Helma installation dir from launcher jar - System.err.println("Unable to shutdown Helma: "); - x.printStackTrace(); - System.exit(2); - } - } - - static void addJars(ArrayList jarlist, File dir) throws MalformedURLException { - File[] files = dir.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - String n = name.toLowerCase(); - return n.endsWith(".jar") || n.endsWith(".zip"); //$NON-NLS-1$//$NON-NLS-2$ - } - }); - - if (files != null) { - for (int i = 0; i < files.length; i++) { - jarlist.add(new URL("file:" + files[i].getAbsolutePath())); //$NON-NLS-1$ - } - } - } - - /** - * Create a server-wide ClassLoader from our install directory. - * This will be used as parent ClassLoader for all application - * ClassLoaders. - * - * @param installDir - * @return the main classloader we'll be using - * @throws MalformedURLException - */ - public static ClassLoader createClassLoader(String installDir) - throws MalformedURLException, UnsupportedEncodingException { - - // decode installDir in case it is URL-encoded - installDir = URLDecoder.decode(installDir, System.getProperty("helma.urlEncoding", "UTF-8")); - - // set up the class path - File libdir = new File(installDir, "lib"); - ArrayList jarlist = new ArrayList(); - - // add all jar files from the lib directory - addJars(jarlist, libdir); - - // add all jar files from the lib/ext directory - addJars(jarlist, new File(libdir, "ext")); //$NON-NLS-1$ - - URL[] urls = new URL[jarlist.size()]; - - jarlist.toArray(urls); - - // find out if system classes should be excluded from class path - String excludeSystemClasses = System.getProperty("helma.excludeSystemClasses"); - - ClassLoader loader; - - if ("true".equalsIgnoreCase(excludeSystemClasses)) { - loader = new URLClassLoader(urls, null); - } else { - loader = new URLClassLoader(urls); - } - - // set the new class loader as context class loader - Thread.currentThread().setContextClassLoader(loader); - return loader; - } - - - /** - * Get the Helma install directory from the command line -i argument or - * from the Jar URL from which this class was loaded. Additionally, the - * System property "helma.home" is set to the install directory path. - * - * @param args - * @return the base install directory we're running in - * @throws IOException - * @throws MalformedURLException - */ - public static String getInstallDir(String[] args) - throws IOException, MalformedURLException { - // check if home directory is set via command line arg. If not, - // we'll get it from the location of the jar file this class - // has been loaded from. - String installDir = null; - - // first, try to get helma home dir from command line options - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-i") && ((i + 1) < args.length)) { - installDir = args[i + 1]; - } - } - - // try to get Helma installation directory - if (installDir == null) { - URL launcherUrl = ClassLoader.getSystemClassLoader() - .getResource("helma/main/launcher/Main.class"); //$NON-NLS-1$ - - // this is a JAR URL of the form - // jar:!/{entry} - // we strip away the jar: prefix and the !/{entry} suffix - // to get the original jar file URL - - String jarUrl = launcherUrl.toString(); - - if (!jarUrl.startsWith("jar:") || jarUrl.indexOf("!") < 0) { - installDir = System.getProperty("user.dir"); - System.err.println("Warning: Helma install dir not set by -i parameter "); - System.err.println(" and not started from launcher.jar. Using "); - System.err.println(" current working directory as install dir."); - } else { - jarUrl = jarUrl.substring(4); - - int excl = jarUrl.indexOf("!"); - jarUrl = jarUrl.substring(0, excl); - launcherUrl = new URL(jarUrl); - - File f = new File(launcherUrl.getPath()).getAbsoluteFile(); - - installDir = f.getParentFile().getCanonicalPath(); - } - } - // set System property - System.setProperty("helma.home", installDir); - // and return install dir - return installDir; - } - -} diff --git a/launcher/src/main/java/helma/main/launcher/manifest.txt b/launcher/src/main/java/helma/main/launcher/manifest.txt deleted file mode 100644 index 37df267c..00000000 --- a/launcher/src/main/java/helma/main/launcher/manifest.txt +++ /dev/null @@ -1,3 +0,0 @@ -Main-Class: helma.main.launcher.Main - - diff --git a/lib/ext/.keep b/lib/ext/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/modules/README.md b/modules/README.md deleted file mode 100644 index a067850e..00000000 --- a/modules/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Helma Modules - -The Helma modules directory is organized in several groups: - -* **modules/core** which contains extensions to core JavaScript types such as -Object, Array, or Date. -* **modules/helma** which provide new functionality to JavaScript, usually by -wrapping a Java library. -* **modules/jala**, a Git submodule providing the very useful ORF.at libraries for Helma - -To use a HelmaLib module in your Helma application, you need to add it to the -app's repositories. The simplest way to do so is by using the `app.addRepository()` -function: - - app.addRepository('modules/helma/Search.js'); diff --git a/modules/core/Array.js b/modules/core/Array.js deleted file mode 100644 index 450380e7..00000000 --- a/modules/core/Array.js +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Array.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Adds useful methods to the JavaScript Array type. - *

- * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/core/Array.js') - */ - -/** - * Check if this array contains a specific value. - * @external - * @memberof {Array} - * @param {Object} val the value to check - * @return {boolean} true if the value is contained - */ -Array.prototype.contains = Array.prototype.includes - -/** - * Retrieve the union set of a bunch of arrays - * @external - * @memberof {Array} - * @param {Array} array1,... the arrays to unify - * @return {Array} the union set - */ -Array.union = function() { - return Array.from(arguments).reduce((result, array) => { - return result.concat(array.filter(element => !result.includes(element))); - }, []); -}; - -/** - * Retrieve the intersection set of a bunch of arrays - * @external - * @memberof {Array} - * @param {Array} array1,... the arrays to intersect - * @return {Array} the intersection set - */ -Array.intersection = function() { - return Array.from(arguments).reduce((result, array) => { - return result.filter(element => array.includes(element)); - }); -}; - -// prevent any newly added properties from being enumerated -for (var i in Array) - Array.dontEnum(i); -for (var i in Array.prototype) - Array.prototype.dontEnum(i); diff --git a/modules/core/Date.js b/modules/core/Date.js deleted file mode 100644 index 76bc5f36..00000000 --- a/modules/core/Date.js +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2005 Helma Software. All Rights Reserved. - * - * $RCSfile: Date.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Adds useful methods to the JavaScript Date type. - *

- * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/core/Date.js') - */ - -Date.ONESECOND = 1000; -Date.ONEMINUTE = 60 * Date.ONESECOND; -Date.ONEHOUR = 60 * Date.ONEMINUTE; -Date.ONEDAY = 24 * Date.ONEHOUR; -Date.ONEWEEK = 7 * Date.ONEDAY; -Date.ONEMONTH = 30 * Date.ONEDAY; -Date.ONEYEAR = 12 * Date.ONEMONTH; -Date.ISOFORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - - -/** - * Format a Date to a string. - * For details on the format pattern, see - * http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html * - * @external - * @memberof {Date} - * - * @param String Format pattern - * @param Object Java Locale Object (optional) - * @param Object Java TimeZone Object (optional) - * @return String formatted Date - * @see http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html - */ -Date.prototype.format = function (format, locale, timezone) { - if (!format) - return this.toString(); - var sdf = locale ? new java.text.SimpleDateFormat(format, locale) - : new java.text.SimpleDateFormat(format); - if (timezone && timezone != sdf.getTimeZone()) - sdf.setTimeZone(timezone); - return sdf.format(this); -}; - - -/** - * set the date/time to UTC by subtracting - * the timezone offset - * @external - * @memberof {Date} - */ -Date.prototype.toUtc = function() { - this.setMinutes(this.getMinutes() + this.getTimezoneOffset()); -}; - - -/** - * set the date/time to local time by adding - * the timezone offset - * @external - * @memberof {Date} - */ -Date.prototype.toLocalTime = function() { - this.setMinutes(this.getMinutes() - this.getTimezoneOffset()); -}; - - -/** - * returns the difference between this and another - * date object in milliseconds - * @external - * @memberof {Date} - */ -Date.prototype.diff = function(dateObj) { - return this.getTime() - dateObj.getTime(); -}; - - -/** - * return the timespan to current date/time or a different Date object - * @external - * @memberof {Date} - * @param Object parameter object containing optional properties: - * .now = String to use if difference is < 1 minute - * .day|days = String to use for single|multiple day(s) - * .hour|hours = String to use for single|multiple hour(s) - * .minute|minutes = String to use for single|multiple minute(s) - * .date = Date object to use for calculating the timespan - * @return Object containing properties: - * .isFuture = (Boolean) - * .span = (String) timespan - * @see Date.prototype.getAge - * @see Date.prototype.getExpiry - */ -Date.prototype.getTimespan = function(param) { - if (!param) - param = {date: new Date()}; - else if (!param.date) - param.date = new Date(); - - var result = {isFuture: this > param.date}; - var diff = Math.abs(param.date.diff(this)); - var age = {days: Math.floor(diff / Date.ONEDAY), - hours: Math.floor((diff % Date.ONEDAY) / Date.ONEHOUR), - minutes: Math.floor((diff % Date.ONEHOUR) / Date.ONEMINUTE)}; - - res.push(); - if (diff < Date.ONEMINUTE) - res.write(param.now || "now"); - else { - var arr = [{one: "day", many: "days"}, - {one: "hour", many: "hours"}, - {one: "minute", many: "minutes"}]; - for (var i in arr) { - var value = age[arr[i].many]; - if (value != 0) { - var prop = (value == 1 ? arr[i].one : arr[i].many); - res.write(value); - res.write(" "); - res.write(param[prop] || prop); - if (i < arr.length -1) - res.write(param.delimiter || ", "); - } - } - } - result.span = res.pop(); - return result; -}; - - -/** - * return the past timespan between this Date object and - * the current Date or a different Date object - * @see Date.prototype.getTimespan - * @external - * @memberof {Date} - */ -Date.prototype.getAge = function(param) { - var age = this.getTimespan(param); - if (!age.isFuture) - return age.span; - return null; -}; - - -/** - * return the future timespan between this Date object and - * the current Date or a different Date object - * @see Date.prototype.getTimespan - * @external - * @memberof {Date} - */ -Date.prototype.getExpiry = function(param) { - var age = this.getTimespan(param); - if (age.isFuture) - return age.span; - return null; -}; - - -/** - * checks if a date object equals another date object - * @external - * @memberof {Date} - * @param Object Date object to compare - * @param Int indicating how far the comparison should go - * @return Boolean - */ -Date.prototype.equals = function(date, extend) { - if (!extend) - extend = Date.ONEDAY; - switch (extend) { - case Date.ONESECOND: - if (this.getSeconds() != date.getSeconds()) - return false; - case Date.ONEMINUTE: - if (this.getMinutes() != date.getMinutes()) - return false; - case Date.ONEHOUR: - if (this.getHours() != date.getHours()) - return false; - case Date.ONEDAY: - if (this.getDate() != date.getDate()) - return false; - case Date.ONEMONTH: - if (this.getMonth() != date.getMonth()) - return false; - case Date.ONEYEAR: - if (this.getFullYear() != date.getFullYear()) - return false; - } - return true; -}; - - -// prevent any newly added properties from being enumerated -for (var i in Date) - Date.dontEnum(i); -for (var i in Date.prototype) - Date.prototype.dontEnum(i); diff --git a/modules/core/Filters.js b/modules/core/Filters.js deleted file mode 100644 index f1b94acf..00000000 --- a/modules/core/Filters.js +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2007 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Implements some useful macro filters. - *

- * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/core/Filters.js') - */ - -app.addRepository('modules/core/String.js'); - -/** - * Transforms a string to lowercase. - * - * @see String.prototype.toLowerCase - */ -function lowercase_filter(input) { - return (input || "").toString().toLowerCase(); -} - - -/** - * Transforms a string to uppercase. - * - * @see String.prototype.toUpperCase - */ -function uppercase_filter(input) { - return (input || "").toString().toUpperCase(); -} - - -/** - * Transforms the first Character of a string to uppercase. - * - * @see String.prototype.capitalize - */ -function capitalize_filter(input) { - return (input || "").toString().capitalize(); -} - - -/** - * Transforms the first Character of each word in a string - * to uppercase. - * - * @see String.prototype.titleize - */ -function titleize_filter(input) { - return (input || "").toString().titleize(); -} - - -/** - * Cuts a String at a certain position, and - * optionally appends a suffix, if truncation - * has occurred. - * - * @see String.prototype.head - * @param limit Maximum length - * @param clipping Appended String, default is the empty String - */ -function truncate_filter(input, param, limit, clipping) { - var limit = param.limit != null ? param.limit : limit; - var clipping = param.clipping || clipping || ""; - return (input || "").toString().head(limit, clipping); -} - - -/** - * Removes leading and trailing whitespaces. - * - * @see String.prototype.trim - */ -function trim_filter(input) { - return (input || "").toString().trim(); -} - - -/** - * Removes all tags from a String. - * Currently simply wraps Helma's stripTags-method. - * - * @see global.stripTags - */ -function stripTags_filter(input) { - return stripTags((input || "").toString()); -}; - - -/** - * Escapes the characters in a String using XML entities. - * Currently simply wraps Helma's encodeXml-method. - * - * @see global.encodeXml - */ -function escapeXml_filter(input) { - return encodeXml((input || "").toString()); -} - - -/** - * Escapes the characters in a String using HTML entities. - * - * @see http://www.google.com/codesearch?q=escapeHtml - */ -function escapeHtml_filter(input) { - var replace = Packages.org.eclipse.jetty.util.StringUtil.replace; - var str = (input || "").toString(); - return replace(replace(replace(replace(str, '&', '&'), '"', '"'), '>', '>'), '<', '<'); -} - -var h_filter = escapeHtml_filter; - - -/** - * Escapes the characters in a String to be suitable - * to use as an HTTP parameter value. - * - * @see http://www.google.com/codesearch?q=escapeUrl - * @param charset Optional String. The name of a supported - * character encoding. - */ -function escapeUrl_filter(input, param, charset) { - var charset = param.charset || charset || app.getCharset(); - return java.net.URLEncoder.encode(input || "", charset); -} - - -/** - * Escapes a string so it may be used in JavaScript String - * definitions. - */ -function escapeJavaScript_filter(input) { - var replace = Packages.org.eclipse.jetty.util.StringUtil.replace; - var str = (input || "").toString(); - return replace(replace(replace(replace(replace(str, '"', '\\"'), "'", "\\'"), '\n', '\\n'), '\r', '\\r'), '\t', '\\t'); -} - - -/** - * Replaces linebreaks with HTML linebreaks. - */ -function linebreakToHtml_filter(input) { - var replace = Packages.org.eclipse.jetty.util.StringUtil.replace; - var str = (input || "").toString(); - return replace(str, '\n', '
'); -} - - -/** - * Performs a string replacement. - * - * @param old - * @param new - */ -function replace_filter(input, param, oldString, newString) { - var str = String(input || ''); - var oldString = param.old || oldString; - var newString = param['new'] || newString; - return str.replace(new RegExp(oldString, 'g'), newString); -} - - -/** - * Returns a substring. Simply wraps the javascript - * method 'substring'. - * - * @see String.prototype.substring - * @param from - * @param to - */ -function substring_filter(input, param, from, to) { - var from = param.from != null ? param.from : from; - var to = param.to != null ? param.to : to; - var str = (input || "").toString(); - return str.substring(from, to); -} - - -/** - * Returns a formatted string representation of a Date. - * Simply wraps javascripts Date.format-method. - * - * @see Date.prototype.format - * @param format - */ -function dateFormat_filter(input, param, format) { - var format = param.format || format; - if (!input) { - return; - } else { - return input.format(format); - } -} diff --git a/modules/core/Global.js b/modules/core/Global.js deleted file mode 100644 index 41e32357..00000000 --- a/modules/core/Global.js +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2005 Helma Software. All Rights Reserved. - * - * $RCSfile: Global.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Adds useful global macros. - *

- * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/core/Global.js') - */ - -app.addRepository("modules/core/String.js"); - - -/** - * write out a property contained in app.properties - * @param Object containing the name of the property - */ -function property_macro(param, name) { - res.write(getProperty(name || param.name) || String.NULL); - return; -} - - -/** - * wrapper to output a string from within a skin - * just to be able to use different encodings - * @param Object containing the string as text property - */ -function write_macro(param, text) { - res.write(param.text || text || String.NULL); - return; -} - - -/** - * renders the current datetime - * @param Object containing a formatting string as format property - */ -function now_macro(param) { - var d = new Date(); - if (param.format) { - try { - res.write(d.format(param.format)); - } catch (e) { - res.write('[Invalid date format]'); - } - } else if (param.as == "timestamp") { - res.write(d.getTime()); - } else { - res.write(d); - } - return; -} - - -/** - * renders a global skin - */ -var skin_macro = function(param, name) { - var skinName = name || param.name; - if (skinName) { - renderSkin(skinName, param); - } - return; -} - -/** - * Encodes a string for HTML output and inserts linebreak tags. - * - * Performs the following string manipulations: - * All line breaks (i.e. line feeds) are replaced with
tags. - * All special characters are being replaced with their equivalent HTML entity. - * Existing markup tags are being encoded. - * - * @param {string} text - * The string to encode for HTML output. - * @param {boolean} [encodeNewLine = true] - * If or if not to encode line breaks (i.e. line feeds). - * @return {string} - * The encoded string. - */ -function encode(text, encodeNewLine) { - text = String(text); - - if (text === null || !text.length) return text; - var buffer = []; - if (typeof encodeNewLine === 'undefined') encodeNewLine = true; - - for (var i = 0, len = text.length; i < len; i += 1) { - var char = text.charAt(i); - - switch (char) { - case '<': - buffer.push('<'); - break; - - case '>': - buffer.push('>'); - break; - - case '&': - buffer.push('&'); - break; - - case '"': - buffer.push('"'); - break; - - case '\n': - if (encodeNewLine) { - buffer.push("
"); - } - buffer.push('\n'); - break; - - default: - buffer.push(char); - } - } - - return buffer.join(''); -} - -/** - * Encodes a string for XML output. - * - * Performs the following string manipulations: - * All special characters are being replaced with their equivalent HTML entity. - * Existing tags, single and double quotes, as well as ampersands are being encoded. - * Some invalid XML characters below '0x20' are removed - * - * @param {string} text - * The string to encode for XML output. - * @return {string} - * The string encoded for XML output. - */ -function encodeXml(text) { - text = String(text); - - if (text === null || !text.length) return text; - var buffer = []; - - for (var i = 0, len = text.length; i < len; i += 1) { - var char = text.charAt(i); - - switch (char) { - case '<': - buffer.push('<'); - break; - - case '>': - buffer.push('>'); - break; - - case '&': - buffer.push('&'); - break; - - case '"': - buffer.push('"'); - break; - - case '\'': - buffer.push('''); - break; - - default: - var charCode = text.charCodeAt(i); - if (charCode < 0x20) { - // sort out invalid XML characters below 0x20 - all but 0x9, 0xA and 0xD. - // The trick is an adaption of java.lang.Character.isSpace(). - if (((((1 << 0x9) | (1 << 0xA) | (1 << 0xD)) >> charCode) & 1) !== 0) { - buffer.push(char); - } - } else { - buffer.push(char); - } - } - } - - return buffer.join(''); -} - -/** - * Encodes a string for HTML output, leaving linebreaks untouched. - * - * Performs the following string manipulations: - * Unlike encode, leaves linebreaks untouched. This is what you usually want to do for encoding form content (esp. - * with text input values). - * All special characters (i.e. non ASCII) are being replaced with their equivalent HTML entity. - * Existing markup tags are being encoded. - * - * @param {string} text - * The string to format for HTML output. - * @return {string} - * The string formatted for HTML output. - */ -var encodeForm = function(text) { - text = String(text); - - if (text === null || !text.length) return text; - - return encode(text, false); -}; - -/** - * Removes any markup tags contained in the passed string, and returns the modified string. - * - * @param {string} markup - * The text that is to be stripped of tags. - * @return {string} - * The text with the tags stripped out. - */ -var stripTags = function (markup) { - if (!markup) return ''; - - var chars = String(markup).split(''); - var charCounter = 0; - var inTag = false; - - for (var i = 0, len = markup.length; i < len; i += 1) { - if (chars[i] === '<') inTag = true; - - if (!inTag) { - if (i > charCounter) { - chars[charCounter] = chars[i]; - } - - charCounter += 1; - } - - if (chars[i] === '>') { - inTag = false; - } - } - - if (i > charCounter) { - chars.length = charCounter; - return chars.join(''); - } - - return markup; -}; diff --git a/modules/core/HopObject.js b/modules/core/HopObject.js deleted file mode 100644 index 507177cb..00000000 --- a/modules/core/HopObject.js +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2005 Helma Software. All Rights Reserved. - * - * $RCSfile: HopObject.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Adds useful methods to Helma's built-in HopObject prototype. - *

- * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/core/HopObject.js') - */ - -app.addRepository("modules/core/Number.js"); -app.addRepository("modules/core/String.js"); - - -/** - * Iterates over each child node of the HopObject. - * @external - * @memberof {HopObject} - * @param {Function} callback The callback function to be - * called for each child node. On every call the first - * argument of this function is set to the current value - * of the counter variable i. - */ -HopObject.prototype.forEach = function(callback) { - if (!callback || callback instanceof Function == false) { - return; - } - for (var i=0; iparam - * argument: - *
    - *
  1. param.none - not a single child node
  2. - *
  3. param.one - exactly one child node
  4. - *
  5. param.many - more than one child node
  6. - *
- * @external - * @memberof {HopObject} - * @param {Object} param The default macro parameter - * @param {String} name The default name for a child node - */ -HopObject.prototype.size_macro = function(param, name) { - var EMPTYSTR = ""; - var n = this.size(); - if (name) { - var text; - var plural = name.endsWith("s") ? "es" : "s"; - if (n > 0) { - if (n > 1) { - text = n + " " + name + plural; - } else { - text = (param.one !== null) ? param.one : "one " + name; - } - } else { - text = (param.none !== null) ? param.none : "no " + name + plural; - } - res.write(text); - } else { - res.write(n); - } - return; -}; diff --git a/modules/core/JSON.js b/modules/core/JSON.js deleted file mode 100644 index 56dfb991..00000000 --- a/modules/core/JSON.js +++ /dev/null @@ -1,2 +0,0 @@ -// This file intentionally left blank to prevent legacy code from -// breaking when trying to include the obsolete JSON module. diff --git a/modules/core/Number.js b/modules/core/Number.js deleted file mode 100644 index 1f460109..00000000 --- a/modules/core/Number.js +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Number.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Adds useful methods to the JavaScript Number type. - *

- * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/core/Number.js') - */ - -/** - * format a Number to a String - * @external - * @memberof {Number} - * @param String Format pattern - * @param java.util.Locale An optional Locale instance - * @return String Number formatted to a String - */ -Number.prototype.format = function(fmt, locale) { - var symbols; - if (locale != null) { - symbols = new java.text.DecimalFormatSymbols(locale); - } else { - symbols = new java.text.DecimalFormatSymbols(); - } - var df = new java.text.DecimalFormat(fmt || "###,##0.##", symbols); - return df.format(0 + this); // addition with 0 prevents exception -}; - - -/** - * return the percentage of a Number - * according to a given total Number - * @external - * @memberof {Number} - * @param Int Total - * @param String Format Pattern - * @param java.util.Locale An optional Locale instance - * @return Int Percentage - */ -Number.prototype.toPercent = function(total, fmt, locale) { - if (!total) - return (0).format(fmt, locale); - var p = this / (total / 100); - return p.format(fmt, locale); -}; - - -/** - * factory to create functions for sorting objects in an array - * @external - * @memberof {Number} - * @param String name of the field each object is compared with - * @param Number order (ascending or descending) - * @return Function ready for use in Array.prototype.sort - */ -Number.Sorter = function(field, order) { - if (!order) - order = 1; - return function(a, b) { - return (a[field] - b[field]) * order; - }; -}; - -Number.Sorter.ASC = 1; -Number.Sorter.DESC = -1; - - -// prevent any newly added properties from being enumerated -for (var i in Number) - Number.dontEnum(i); -for (var i in Number.prototype) - Number.prototype.dontEnum(i); diff --git a/modules/core/Object.js b/modules/core/Object.js deleted file mode 100644 index 0bf53006..00000000 --- a/modules/core/Object.js +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Object.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Adds useful methods to the JavaScript Object type. - *

- * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/core/Object.js') - */ - -app.addRepository('modules/core/Global.js'); - -/** - * Copies the properties of this object into a clone. - * @external - * @memberof {Object} - * @param {Object} clone The optional target object - * @param {Boolean} recursive If true child objects are cloned as well, otherwise - * the clone contains references to the child objects - * @returns The resulting object - */ -Object.prototype.clone = function(clone, recursive) { - - var getValue = function(value, recursive) { - if (recursive !== true || value == null - || (typeof (value) !== "object" && typeof (value) !== "function")) { - return value; - } - return value.clone(null, recursive); - }; - - if (typeof (this) === "object") { - if (this === null) { - return null; - } - switch (this.constructor) { - case String: - case Number: - case Boolean: - case Date: - return new this.constructor(this.valueOf()); - - case Array: - return this.map(function(value) { - return getValue(value, recursive); - }); - - default: - if (clone == null) { - clone = new this.constructor(); - } - for ( var propName in this) { - clone[propName] = getValue(this[propName], recursive); - } - return clone; - } - } else if (typeof (this) === "function" && this.constructor === RegExp) { - return new RegExp(this.valueOf()); - } - return this; -}; - - -/** - * reduce an extended object (ie. a HopObject) - * to a generic javascript object - * @external - * @memberof {Object} - * @param HopObject the HopObject to be reduced - * @return Object the resulting generic object - */ -Object.prototype.reduce = function(recursive) { - var result = {}; - for (var i in this) { - if (this[i] instanceof HopObject == false) - result[i] = this[i]; - else if (recursive) - result[i] = this.reduce(true); - } - return result; -}; - - -/** - * print the contents of an object for debugging - * @external - * @memberof {Object} - * @param Object the object to dump - * @param Boolean recursive flag (if true, dump child objects, too) - */ -Object.prototype.dump = function(recursive) { - var beginList = "
    "; - var endList = "
"; - var beginItem = "
  • "; - var endItem = "
  • "; - var beginKey = ""; - var endKey = ": "; - res.write(beginList); - for (var p in this) { - res.write(beginItem); - res.write(beginKey); - res.write(p); - res.write(endKey); - if (recursive && typeof this[p] == "object") { - var recurse = true; - var types = [Function, Date, String, Number]; - for (var i in types) { - if (this[p] instanceof types[i]) { - recurse = false - break; - } - } - if (recurse == true) - this[p].dump(true); - else { - res.write(this[p].toSource()); - } - } else if (this[p]) { - res.write(encode(this[p].toSource())); - } - res.write(endItem); - } - res.write(endList); - return; -}; - - -// prevent any newly added properties from being enumerated -for (var i in Object) - Object.dontEnum(i); -for (var i in Object.prototype) - Object.prototype.dontEnum(i); diff --git a/modules/core/String.js b/modules/core/String.js deleted file mode 100644 index 9348d7b2..00000000 --- a/modules/core/String.js +++ /dev/null @@ -1,684 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: String.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - - -String.ANUMPATTERN = /[^a-zA-Z0-9]/; -String.APATTERN = /[^a-zA-Z]/; -String.NUMPATTERN = /[^0-9]/; -String.FILEPATTERN = /[^a-zA-Z0-9-_\. ]/; -String.HEXPATTERN = /[^a-fA-F0-9]/; -String.LEFT = -1 -String.BALANCE = 0 -String.RIGHT = 1 -String.ISOFORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; -String.SPACE = " "; -String.EMPTY = ""; -String.NULL = String.EMPTY; // to be deprecated? - -// Email and URL RegExps contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ -// licensed unter MIT license - http://www.opensource.org/licenses/mit-license.php - -String.EMAILPATTERN = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i; - -String.URLPATTERN = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i; - -/** - * @fileoverview Adds useful methods to the JavaScript String type. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/core/String.js') - */ - -app.addRepository('modules/core/Global.js'); - -/** - * checks if a date format pattern is correct - * @external - * @memberof {String} - * @return Boolean true if the pattern is correct - */ -String.prototype.isDateFormat = function() { - try { - new java.text.SimpleDateFormat(this); - return true; - } catch (err) { - return false; - } -}; - - -/** - * parse a timestamp into a date object. This is used when users - * want to set createtime explicitly when creating/editing stories. - * @external - * @memberof {String} - * @param String date format to be applied - * @param Object Java TimeZone Object (optional) - * @return Object contains the resulting date - */ -String.prototype.toDate = function(format, timezone) { - var sdf = res.data._dateformat; - if (!sdf) { - sdf = new java.text.SimpleDateFormat(format); - res.data._dateformat = sdf; - } else if (format != sdf.toPattern()) - sdf.applyPattern(format); - if (timezone && timezone != sdf.getTimeZone()) - sdf.setTimeZone(timezone); - try { - return new Date(sdf.parse(this).getTime()); - } catch (err) { - return null; - } -}; - - -/** - * function checks if the string passed contains any characters that - * are forbidden in URLs and tries to create a java.net.URL from it - * FIXME: probably deprecated -> helma.Url - * @external - * @memberof {String} - * @return Boolean - * @see helma.Url.PATTERN - */ -String.prototype.isUrl = function() { - return String.URLPATTERN.test(this); -}; - - -/** - * function checks if the string passed contains any characters - * that are forbidden in image- or filenames - * @external - * @memberof {String} - * @return Boolean - */ -String.prototype.isFileName = function() { - return !String.FILEPATTERN.test(this); -}; - - -/** - * function cleans the string passed as argument from any characters - * that are forbidden or shouldn't be used in filenames - * @external - * @memberof {String} - * @return Boolean - */ -String.prototype.toFileName = function() { - return this.replace(new RegExp(String.FILEPATTERN.source, "g"), String.NULL); -}; - - -/** - * function checks a string for a valid color value in hexadecimal format. - * it may also contain # as first character - * @external - * @memberof {String} - * @returns Boolean false, if string length (without #) > 6 or < 6 or - * contains any character which is not a valid hex value - */ -String.prototype.isHexColor = function() { - var str = this; - if (this.indexOf("#") == 0) - str = this.substring(1); - if (str.length != 6) - return false; - return !String.HEXPATTERN.test(str); -}; - - -/** - * converts a string into a hexadecimal color - * representation (e.g. "ffcc33"). also knows how to - * convert a color string like "rgb (255, 204, 51)". - * @external - * @memberof {String} - * @return String the resulting hex color (w/o "#") - */ -String.prototype.toHexColor = function() { - if (this.startsWith("rgb")) { - res.push(); - var col = this.replace(/[^0-9,]/g, String.NULL); - var parts = col.split(","); - for (var i in parts) { - var num = parseInt(parts[i], 10); - var hex = num.toString(16); - res.write(hex.pad("0", 2, String.LEFT)); - } - return res.pop(); - } - var col = this.replace(new RegExp(String.HEXPATTERN.source), String.NULL); - return col.toLowerCase().pad("0", 6, String.LEFT); -}; - - -/** - * function returns true if the string contains - * only a-z and 0-9 (case insensitive!) - * @external - * @memberof {String} - * @return Boolean true in case string is alpha, false otherwise - */ -String.prototype.isAlphanumeric = function() { - if (!this.length) - return false; - return !String.ANUMPATTERN.test(this); -}; - - -/** - * function cleans a string by throwing away all - * non-alphanumeric characters - * @external - * @memberof {String} - * @return cleaned string - */ -String.prototype.toAlphanumeric = function() { - return this.replace(new RegExp(String.ANUMPATTERN.source, "g"), String.NULL); -}; - - -/** - * function returns true if the string contains - * only characters a-z - * @external - * @memberof {String} - * @return Boolean true in case string is alpha, false otherwise - */ -String.prototype.isAlpha = function() { - if (!this.length) - return false; - return !String.APATTERN.test(this); -}; - - -/** - * function returns true if the string contains - * only 0-9 - * @external - * @memberof {String} - * @return Boolean true in case string is numeric, false otherwise - */ -String.prototype.isNumeric = function() { - if (!this.length) - return false; - return !String.NUMPATTERN.test(this); -}; - - -/** - * transforms the first n characters of a string to uppercase - * @external - * @memberof {String} - * @param Number amount of characters to transform - * @return String the resulting string - */ -String.prototype.capitalize = function(limit) { - if (limit == null) - limit = 1; - var head = this.substring(0, limit); - var tail = this.substring(limit, this.length); - return head.toUpperCase() + tail.toLowerCase(); -}; - - -/** - * transforms the first n characters of each - * word in a string to uppercase - * @external - * @memberof {String} - * @return String the resulting string - */ -String.prototype.titleize = function() { - var parts = this.split(" "); - res.push(); - for (var i in parts) { - res.write(parts[i].capitalize()); - if (i < parts.length-1) - res.write(" "); - } - return res.pop(); -}; - - -/** - * translates all characters of a string into HTML entities - * @external - * @memberof {String} - * @return String translated result - */ -String.prototype.entitize = function() { - res.push(); - for (var i=0; i/g, replacement); - return str; -}; - - -/** - * function calculates the md5 hash of a string - * @external - * @memberof {String} - * @return String md5 hash of the string - */ -String.prototype.md5 = function() { - return Packages.org.apache.commons.codec.digest.DigestUtils.md5Hex(this); -}; - - -/** - * fills a string with another string up to a desired length - * @external - * @memberof {String} - * @param String the filling string - * @param Number the desired length of the resulting string - * @param Number the direction which the string will be padded in: - * -1: left 0: both (balance) 1: right - * (you can use the constants String.LEFT, - * String.BALANCE and String.RIGHT here as well.) - * @return String the resulting string - */ -String.prototype.pad = function(str, length, mode) { - if (mode === null || mode === String.RIGHT) return this.padEnd(length, str); - if (mode === String.LEFT) return this.padStart(length, str); - - if (mode === String.BALANCE && str && length) { - const pos = Math.ceil(this.length / 2); - const head = this.substr(0, pos); - const tail = this.substr(pos); - const additionalLength = (length - this.length) / 2; - const startLength = head.length + Math.floor(additionalLength); - const endLength = tail.length + Math.ceil(additionalLength); - return head.padStart(startLength, str) + tail.padEnd(endLength, str); - } - - return this; -}; - - -/** - * function returns true if a string contains the string - * passed as argument - * @external - * @memberof {String} - * @param String string to search for - * @param Int Position to start search - * @param Boolean - */ -String.prototype.contains = function(str, fromIndex) { - return this.indexOf(str, fromIndex || 0) > -1; -}; - - -/** - * function compares a string with the one passed as argument - * using diff - * @external - * @memberof {String} - * @param String String to compare against String object value - * @param String Optional regular expression string to use for - * splitting. If not defined, newlines will be used. - * @return Object Array containing one JS object for each line - * with the following properties: - * .num Line number - * .value String line if unchanged - * .deleted Obj Array containing deleted lines - * .inserted Obj Array containing added lines - */ -String.prototype.diff = function(mod, separator) { - // if no separator use line separator - var regexp = (typeof(separator) == "undefined") ? - new RegExp("\r\n|\r|\n") : - new RegExp(separator); - // split both strings into arrays - var orig = this.split(regexp); - var mod = mod.split(regexp); - // create the Diff object - var diff = new Packages.helma.util.Diff(orig, mod); - // get the diff. - var d = diff.diff(); - if (!d) - return null; - - var max = Math.max(orig.length, mod.length); - var result = new Array(); - for (var i=0;i -1) { - count += 1; - offset += 1; - } - return count; -}; - - -/** - * returns the string encoded using the base64 algorithm - * @external - * @memberof {String} - */ -String.prototype.enbase64 = function() { - var bytes = java.lang.String(this).getBytes('utf-8'); - return String(java.lang.String(Packages.org.apache.commons.codec.binary.Base64.encodeBase64(bytes), 'utf-8')); -}; - - -/** - * returns the decoded string using the base64 algorithm - * @external - * @memberof {String} - */ -String.prototype.debase64 = function() { - var bytes = Packages.org.apache.commons.codec.binary.Base64.decodeBase64(this); - return String(java.lang.String(bytes, 'utf-8')); -}; - - -// wrapper methods for string-related -// global helma functions - -String.prototype.encode = function() { - return encode(this); -}; - -String.prototype.encodeXml = function() { - return encodeXml(this); -}; - -String.prototype.encodeForm = function() { - return encodeForm(this); -}; - -String.prototype.format = function() { - return format(this); -}; - -String.prototype.stripTags = function() { - return stripTags(this); -}; - -/** - * factory to create functions for sorting objects in an array - * @external - * @memberof {String} - * @param String name of the field each object is compared with - * @param Number order (ascending or descending) - * @return Function ready for use in Array.prototype.sort - */ -String.Sorter = function(field, order) { - if (!order) - order = 1; - var key = field + ":" + order; - if (!String.Sorter.cache[key]) { - String.Sorter.cache[key] = function(a, b) { - var str1 = String(a[field] || String.NULL).toLowerCase(); - var str2 = String(b[field] || String.NULL).toLowerCase(); - if (str1 > str2) - return order * 1; - if (str1 < str2) - return order * -1; - return 0; - }; - } - return String.Sorter.cache[key]; -}; - -String.Sorter.ASC = 1; -String.Sorter.DESC = -1; -String.Sorter.cache = {}; - - -/** - * create a string from a bunch of substrings - * @external - * @memberof {String} - * @param String one or more strings as arguments - * @return String the resulting string - */ -String.compose = function() { - res.push(); - for (var i=0; i
    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Aspects.js') - */ - -/** - * Define the global namespace if not existing - */ -if (!global.helma) { - global.helma = {}; -} - -/** - * Library for adding Aspects - *

    - * Provides static methods to wrap existing functions - * inside a javascript closure in order to add additional - * behavior without overriding the existing one. - *

    - * Based on code by roman porotnikov, - * http://www.jroller.com/page/deep/20030701 - *

    - * Note: Each prototype that uses aspects must implement a method - * onCodeUpdate() to prevent aspects being lost when the prototype - * is re-compiled - * - * @constructor - */ -helma.Aspects = function() { - return this; -}; - - -/** @ignore */ -helma.Aspects.toString = function() { - return "[helma.Aspects]"; -}; - - -/** @ignore */ -helma.Aspects.prototype.toString = function() { - return "[helma.Aspects Object]"; -}; - - -/** - * Adds a function to be called before the orginal function. - *

    - * The return value of the added function needs to provide the - * array of arguments that is passed to the original function. - * The added function receives an array of the original arguments, - * the original function and the scope object of the original - * function as its parameters. - * - * @param {Object} obj The object of which the original function is a property - * @param {String} fname The property name of the original function - * @param {Function} before The function to be called before the original function - * @returns Function A new function, wrapping the original function - * @type Function - */ -helma.Aspects.prototype.addBefore = function(obj, fname, before) { - var oldFunc = obj[fname]; - obj[fname] = function() { - return oldFunc.apply(this, before(arguments, oldFunc, this)); - } - return; -}; - - -/** - * Adds a function to be called after an existing function. - *

    - * The return value of the original function is passed to the - * added function as its first argument. In addition, the added - * function also receives an array of the original arguments, - * the original function and the scope object of the original - * function as additional parameters. - * - * @param {Object} obj as Object, the object of which the original function is a property - * @param {String} fname as String, the property name of the original function - * @param {Function} after as Function, the function to be called after the original function - * @returns Function A new function, wrapping the original function - * @type Function - */ -helma.Aspects.prototype.addAfter = function(obj, fname, after) { - var oldFunc = obj[fname]; - obj[fname] = function() { - return after(oldFunc.apply(this, arguments), arguments, oldFunc, this); - } - return; -}; - - -/** - * Wraps an additional function around the original function. - *

    - * The added function receives as its arguments an array of the original - * arguments, the original function and the scope object of the original - * function. The original function is not called directly and needs - * to be invoked by the added function. - * - * @param {Object} obj as Object, the object of which the original function is a property - * @param {String} fname as String, the property name of the original function - * @param {Function} around as Function, the function to be called inside the original function - * @returns Function A new function, wrapping the original function - * @type Function - */ -helma.Aspects.prototype.addAround = function(obj, fname, around) { - var oldFunc = obj[fname]; - obj[fname] = function() { - return around(arguments, oldFunc, this); - } - return; -}; - - -helma.lib = "Aspects"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; - - -helma.aspects = new helma.Aspects(); -helma.dontEnum("aspects"); diff --git a/modules/helma/Chart.js b/modules/helma/Chart.js deleted file mode 100644 index 6f699ebc..00000000 --- a/modules/helma/Chart.js +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Chart.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - - -/** - * @fileoverview Fields and methods of the helma.Chart prototype - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Chart.js') - */ - -// take care of any dependencies -app.addRepository('modules/helma/jxl-2.5.7.jar'); - -/** - * Define the global namespace if not existing - */ -if (!global.helma) { - global.helma = {}; -} - -/** - * Creates a new instance of helma.Chart - * @class Instances of this class are capable of reading - * Excel spreadsheets and rendering them as XHTML table. Internally - * helma.Chart uses the Java Excel API - * by Andy Khan. - * @param {String} fpath The path to the spreadsheet file - * @param {String} prefix An optional prefix to use for all - * stylesheet classes within the rendered table - * @param {String} sheetName The name of the sheet within the - * spreadsheet file to render. If this argument is omitted, the - * first sheet is rendered. - * @returns A newly created helma.Chart instance. - * @constructor - * @author Tobi Schaefer - */ -helma.Chart = function(fpath, prefix, sheetName) { - var JXLPKG = Packages.jxl.Workbook; - var JXLPKGNAME = "jxl.jar"; - var JXLPKGURL = "http://www.andykhan.com/jexcelapi/"; - - var workbook, file; - try { - file = new java.io.File(fpath); - workbook = JXLPKG.getWorkbook(file); - } catch (e) { - if (e instanceof TypeError == false) - throw(e); - throw("helma.Chart needs " + JXLPKGNAME + - " in lib/ext or application directory " + - "[" + JXLPKGURL + "]"); - } - - var getCellStyle = function(c) { - if (!c) - return; - var result = new Object(); - var format = c.getCellFormat(); - var font = format.getFont(); - if (font.getBoldWeight() > 400) - result.bold = true; - result.italic = font.isItalic(); - result.wrap = format.getWrap(); - var type = c.getType(); - var align = format.getAlignment().getDescription(); - if (align == "right" || type == "Number" || type == "Date") - result.align = "right"; - else if (align == "centre") - result.align = "center"; - return result; - } - - if (sheetName) { - var sheet = workbook.getSheet(sheetName); - } else { - var sheet = workbook.getSheet(0); - } - if (!sheet) - return; - - prefix = prefix ? prefix + "_" : "chart_"; - - /** - * Renders the Excel spreadsheet as XHTML table. - */ - this.render = function() { - res.write('\n'); - - var rowBuf = []; - var rows = sheet.getRows(); - var max = 0; - for (var i=0; i max) - max = row.length; - rowBuf.push(row); - } - - for (var i in rowBuf) { - res.write('\n'); - for (var n=0; n"); - if (style.bold) - res.write(""); - if (style.italic) - res.write(""); - } - else - res.write(">"); - res.write(str); - if (style) { - if (style.italic) - res.write(""); - if (style.bold) - res.write(""); - } - res.write('\n'); - } - res.write('\n'); - } - - res.write('
    \n'); - workbook.close(); - }; - - /** - * Returns the spreadsheet as rendered XHTML table. - * @returns The rendered spreadsheet table - * @type String - */ - this.renderAsString = function() { - res.push(); - this.render(); - return res.pop(); - }; - - /** @ignore */ - this.toString = function() { - return "[helma.Chart " + file + "]"; - }; - - for (var i in this) - this.dontEnum(i); - - return this; -} - - -/** @ignore */ -helma.Chart.toString = function() { - return "[helma.Chart]"; -}; - - -/** - * A simple example for using helma.Chart that renders - * the passed file as XHTML table to response. - * @param {String} file The path to the Excel spreadsheet file - */ -helma.Chart.example = function(file) { - // var file = "/path/to/file.xls"; - var chart = new helma.Chart(file); - chart.render(); - return; -}; - - -helma.lib = "Chart"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Color.js b/modules/helma/Color.js deleted file mode 100644 index 32e011ae..00000000 --- a/modules/helma/Color.js +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Color.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - - -/** - * @fileoverview Fields and methods of the helma.Chart prototype - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Color.js') - */ - -// take care of any dependencies -app.addRepository("modules/core/String.js"); - -/** - * Define the global namespace if not existing - */ -if (!global.helma) { - global.helma = {}; -} - -/** - * Constructs a new instance of helma.Color. - * @class Instances of this class provide methods for - * converting HTML color names into their corresponding - * RGB values and vice versa, or retrieving single RGB color values. - * @param {Number|String} R Either the red fraction of the color, - * or the name of the color. - * @param {Number} G The green fraction - * @param {Number} B The blue fraction - * @returns A newly created helma.Color instance - * @constructor - */ -helma.Color = function(R, G, B) { - var value = null; - var name = null; - var hex = null; - var rgb = null; - - /** - * Returns the decimal value of this color, or of a specified - * color channel. - * @param {String} channel An optional color channel which - * decimal value should be returned. Must be either "red", - * "green" or "blue". If no channel is specified this - * method returns the decimal value of the color itself. - * @returns The decimal value of this color or a single channel. - * @type Number - */ - this.valueOf = function(channel) { - if (channel) { - if (!rgb) { - var compose = function(n, bits) { - var div = Math.pow(2, bits); - remainder = n % div; - return Math.floor(n/div); - } - var remainder = value; - rgb = { - red: compose(remainder, 16), - green: compose(remainder, 8), - blue: compose(remainder, 0) - }; - } - return rgb[channel]; - } - return value; - }; - - /** - * Returns the hexidecimal value of this color (without - * a leading hash sign). - * @returns The hexidecimal value of this color - * @type String - */ - this.toString = function() { - if (!value) - return null; - if (!hex) - hex = value.toString(16).pad("0", 6, String.LEFT); - return hex; - }; - - - /** - * Returns the trivial name of this color - * @returns The trivial name of this color - * @type String - */ - this.getName = function() { - return helma.Color.COLORVALUES[value]; - }; - - /** - * Main constructor body - */ - if (arguments.length % 2 == 0) - throw("Insufficient arguments for creating Color"); - if (arguments.length == 1) { - if (R.constructor == Number) { - value = R; - } else if (R.constructor == String) { - R = R.toLowerCase(); - if (helma.Color.COLORNAMES[R]) { - this.name = R; - value = helma.Color.COLORNAMES[R]; - } else { - if (R.startsWith("#")) { - R = R.substring(1); - } - value = parseInt(R, 16); - this.name = helma.Color.COLORVALUES[value]; - } - } - } else { - value = R * Math.pow(2, 16) + G * Math.pow(2, 8) + B; - } - - if (value == null || isNaN(value)) - throw("helma.Color: invalid argument " + R); - - for (var i in this) - this.dontEnum(i); - - return this; -}; - - -/** - * Creates a new helma.Color instance based on a color name. - * @param {String} name The color name (eg. "darkseagreen") - * @returns An instance of helma.Color representing the color specified - * @type helma.Color - */ -helma.Color.fromName = function(name) { - var value = helma.Color.COLORNAMES[name.toLowerCase()]; - return new helma.Color(value || 0); -}; - - -/** - * Creates a new helma.Color instance based on a HSL color - * representation. This method is adapted from the HSLtoRGB - * conversion method as described at - * http://www1.tip.nl/~t876506/ColorDesign.html#hr. - * @param {Number} H The hue fraction of the color definition - * @param {Number} S The saturation fraction - * @param {Number} L The lightness fraction - * @returns An instance of helma.Color representing the corresponding - * RGB color definition. - * @type helma.Color - */ -helma.Color.fromHsl = function(H,S,L) { - function H1(H,S,L) { - var R = 1; var G = 6*H; var B = 0; - G = G*S + 1 - S; B = B*S + 1 - S; - R = R*L; G = G*L; B = B*L; - return [R,G,B]; - } - - function H2(H,S,L) { - var R = 1-6*(H - 1/6); var G = 1; var B = 0; - R = R*S + 1 - S; B = B*S + 1 - S; - R = R*L; G = G*L; B = B*L; - return [R,G,B]; - } - - function H3(H,S,L) { - var R = 0; var G = 1; var B = 6*(H - 1/3); - R = R*S + 1 - S; B = B*S + 1 - S; - R = R*L; G = G*L; B = B*L - return [R,G,B]; - } - - function H4(H,S,L) { - var R = 0; var G = 1-6*(H - 1/2); var B = 1; - R = R*S + 1 - S; G = G*S + 1 - S; - R = R*L; G = G*L; B = B*L; - return [R,G,B]; - } - - function H5(H,S,L) { - var R = 6*(H - 2/3); var G = 0; var B = 1; - R = R*S + 1 - S; G = G*S + 1 - S; - R = R*L; G = G*L; B = B*L; - return [R,G,B]; - } - - function H6(H,S,L) { - var R = 1; var G = 0; var B = 1-6*(H - 5/6); - G = G*S + 1 - S; B = B*S + 1 - S; - R = R*L; G = G*L; B = B*L; - return [R,G,B]; - } - - // H [0-1] is divided into 6 equal sectors. - // From within each sector the proper conversion function is called. - var rgb; - if (H < 1/6) rgb = H1(H,S,L); - else if (H < 1/3) rgb = H2(H,S,L); - else if (H < 1/2) rgb = H3(H,S,L); - else if (H < 2/3) rgb = H4(H,S,L); - else if (H < 5/6) rgb = H5(H,S,L); - else rgb = H6(H,S,L); - - return new helma.Color( - Math.round(rgb[0]*255), - Math.round(rgb[1]*255), - Math.round(rgb[2]*255) - ); -}; - - -/** - * Contains the hexadecimal values of named colors. - * @type Object - * @final - */ -helma.Color.COLORNAMES = { - black: 0x000000, - maroon: 0x800000, - green: 0x008000, - olive: 0x808000, - navy: 0x000080, - purple: 0x800080, - teal: 0x008080, - silver: 0xc0c0c0, - gray: 0x808080, - red: 0xff0000, - lime: 0x00ff00, - yellow: 0xffff00, - blue: 0x0000ff, - fuchsia: 0xff00ff, - aqua: 0x00ffff, - white: 0xffffff, - aliceblue: 0xf0f8ff, - antiquewhite: 0xfaebd7, - aquamarine: 0x7fffd4, - azure: 0xf0ffff, - beige: 0xf5f5dc, - blueviolet: 0x8a2be2, - brown: 0xa52a2a, - burlywood: 0xdeb887, - cadetblue: 0x5f9ea0, - chartreuse: 0x7fff00, - chocolate: 0xd2691e, - coral: 0xff7f50, - cornflowerblue: 0x6495ed, - cornsilk: 0xfff8dc, - crimson: 0xdc143c, - darkblue: 0x00008b, - darkcyan: 0x008b8b, - darkgoldenrod: 0xb8860b, - darkgray: 0xa9a9a9, - darkgreen: 0x006400, - darkkhaki: 0xbdb76b, - darkmagenta: 0x8b008b, - darkolivegreen: 0x556b2f, - darkorange: 0xff8c00, - darkorchid: 0x9932cc, - darkred: 0x8b0000, - darksalmon: 0xe9967a, - darkseagreen: 0x8fbc8f, - darkslateblue: 0x483d8b, - darkslategray: 0x2f4f4f, - darkturquoise: 0x00ced1, - darkviolet: 0x9400d3, - deeppink: 0xff1493, - deepskyblue: 0x00bfff, - dimgray: 0x696969, - dodgerblue: 0x1e90ff, - firebrick: 0xb22222, - floralwhite: 0xfffaf0, - forestgreen: 0x228b22, - gainsboro: 0xdcdcdc, - ghostwhite: 0xf8f8ff, - gold: 0xffd700, - goldenrod: 0xdaa520, - greenyellow: 0xadff2f, - honeydew: 0xf0fff0, - hotpink: 0xff69b4, - indianred: 0xcd5c5c, - indigo: 0x4b0082, - ivory: 0xfffff0, - khaki: 0xf0e68c, - lavender: 0xe6e6fa, - lavenderblush: 0xfff0f5, - lawngreen: 0x7cfc00, - lemonchiffon: 0xfffacd, - lightblue: 0xadd8e6, - lightcoral: 0xf08080, - lightcyan: 0xe0ffff, - lightgoldenrodyellow: 0xfafad2, - lightgreen: 0x90ee90, - lightgrey: 0xd3d3d3, - lightpink: 0xffb6c1, - lightsalmon: 0xffa07a, - lightseagreen: 0x20b2aa, - lightskyblue: 0x87cefa, - lightslategray: 0x778899, - lightsteelblue: 0xb0c4de, - lightyellow: 0xffffe0, - limegreen: 0x32cd32, - linen: 0xfaf0e6, - mediumaquamarine: 0x66cdaa, - mediumblue: 0x0000cd, - mediumorchid: 0xba55d3, - mediumpurple: 0x9370db, - mediumseagreen: 0x3cb371, - mediumslateblue: 0x7b68ee, - mediumspringgreen: 0x00fa9a, - mediumturquoise: 0x48d1cc, - mediumvioletred: 0xc71585, - midnightblue: 0x191970, - mintcream: 0xf5fffa, - mistyrose: 0xffe4e1, - moccasin: 0xffe4b5, - navajowhite: 0xffdead, - oldlace: 0xfdf5e6, - olivedrab: 0x6b8e23, - orange: 0xffa500, - orangered: 0xff4500, - orchid: 0xda70d6, - palegoldenrod: 0xeee8aa, - palegreen: 0x98fb98, - paleturquoise: 0xafeeee, - palevioletred: 0xdb7093, - papayawhip: 0xffefd5, - peachpuff: 0xffdab9, - peru: 0xcd853f, - pink: 0xffc0cb, - plum: 0xdda0dd, - powderblue: 0xb0e0e6, - rosybrown: 0xbc8f8f, - royalblue: 0x4169e1, - saddlebrown: 0x8b4513, - salmon: 0xfa8072, - sandybrown: 0xf4a460, - seagreen: 0x2e8b57, - seashell: 0xfff5ee, - sienna: 0xa0522d, - skyblue: 0x87ceeb, - slateblue: 0x6a5acd, - slategray: 0x708090, - snow: 0xfffafa, - springgreen: 0x00ff7f, - steelblue: 0x4682b4, - tan: 0xd2b48c, - thistle: 0xd8bfd8, - tomato: 0xff6347, - turquoise: 0x40e0d0, - violet: 0xee82ee, - wheat: 0xf5deb3, - whitesmoke: 0xf5f5f5, - yellowgreen: 0x9acd32 -}; - - -/** - * Contains the color names for specific hex values - * @type Object - * @final - */ -helma.Color.COLORVALUES = {}; - -for (var i in helma.Color.COLORNAMES) { - helma.Color.COLORVALUES[helma.Color.COLORNAMES[i]] = i; -} - - -/** @ignore */ -helma.Color.toString = function() { - return "[helma.Color]"; -}; - - -helma.lib = "Color"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Database.js b/modules/helma/Database.js deleted file mode 100644 index 23fb8150..00000000 --- a/modules/helma/Database.js +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Database.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Properties and methods of the helma.Database prototype. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Database.js') - */ - -if (!global.helma) { - global.helma = {}; -} - -/** - * Constructor for Database objects, providing access through relational - * databases through JDBC. It is usually simpler to use one of the factory - * methods {@link #createInstance} or {@link #getInstance}. - * @class

    This class provides access to a relational database through JDBC. - * There are two convenient ways to create instances of this class.

    - * - *

    The first is to use {@link #getInstance helma.Database.getInstance()} - * to obtain a connection to a DB that is defined in the application's - * db.properties and managed by Helma. The second way is to define and create - * a database connection locally using - * {@link #createInstance helma.Database.createInstance()} and passing it - * all necessary parameters.

    - * - *

    This class provides two ways of interaction: - * The {@link #query} method allows to issue SQL queries, returning a result set. - * The {@link #execute} provides a way to issue SQL statements that do not - * return a result set.

    - * - *

    Database connections allocated by this class are be managed and eventually - * disposed by Helma.

    - * - * @param {DbSource} source instance of a helma.objectmodel.db.DbSource - * @constructor - */ -helma.Database = function(source) { - var Types = java.sql.Types; - var DbSource = Packages.helma.objectmodel.db.DbSource; - - if (typeof(source) == "string") - source = app.getDbSource(source); - if (!(source instanceof DbSource)) - throw "helma.Database requires a helma.objectmodel.db.DbSource argument"; - - /** - * Get the java.sql.Connection for this Database instance. This can be used - * to operate on the connection directly, without going through the helma.Database - * class. - * @return {java.sql.Connection} the JDBC connection - */ - this.getConnection = function() { - return source.getConnection(); - }; - - /** - * Returns the lower case name of the underlying database product. - * @return {String} the name of the DB product - */ - this.getProductName = function() { - return source.getConnection().getMetaData().getDatabaseProductName().toLowerCase(); - }; - - /** - * Returns true if this is an Oracle database. - * @return {boolean} true if this is an Oracle database. - */ - this.isOracle = function() { - return source.isOracle(); - }; - - /** - * Returns true if this is a MySQL database. - * @return {boolean} true if this is an MySQL database. - */ - this.isMySql = function() { - return source.isMySQL(); - }; - - /** - * Returns true if this is a PostgreSQL database. - * @return {boolean} true if this is a PostgreSQL database. - */ - this.isPostgreSql = function() { - return source.isPostgreSQL(); - }; - - /** - * Executes the given SQL statement. The result set is returned - * as JavaScript Array containing a JavaScript Object for each result. - * @param {String} sql an SQL query statement - * @return {Array} an Array containing the result set - */ - this.query = function(sql) { - var isLogSqlEnabled = (getProperty("logSQL", "false").toLowerCase() == "true"); - var logTimeStart = isLogSqlEnabled ? java.lang.System.currentTimeMillis() : 0; - var connection = source.getConnection(); - connection.setReadOnly(true); - var statement = connection.createStatement(); - var resultSet = statement.executeQuery(sql); - var metaData = resultSet.getMetaData(); - var max = metaData.getColumnCount(); - var types = []; - for (var i=1; i <= max; i++) { - types[i] = metaData.getColumnType(i); - } - var result = []; - while (resultSet.next()) { - var row = {} - for (var i=1; i<=max; i+=1) { - switch (types[i]) { - case Types.BIT: - case Types.BOOLEAN: - row[metaData.getColumnLabel(i)] = resultSet.getBoolean(i); - break; - case Types.TINYINT: - case Types.BIGINT: - case Types.SMALLINT: - case Types.INTEGER: - row[metaData.getColumnLabel(i)] = resultSet.getLong(i); - break; - case Types.REAL: - case Types.FLOAT: - case Types.DOUBLE: - case Types.DECIMAL: - case Types.NUMERIC: - row[metaData.getColumnLabel(i)] = resultSet.getDouble(i); - break; - case Types.VARBINARY: - case Types.BINARY: - case Types.LONGVARBINARY: - case Types.LONGVARCHAR: - case Types.CHAR: - case Types.VARCHAR: - case Types.CLOB: - case Types.OTHER: - row[metaData.getColumnLabel(i)] = resultSet.getString(i); - break; - case Types.DATE: - case Types.TIME: - case Types.TIMESTAMP: - row[metaData.getColumnLabel(i)] = resultSet.getTimestamp(i); - break; - case Types.NULL: - row[metaData.getColumnLabel(i)] = null; - break; - default: - row[metaData.getColumnLabel(i)] = resultSet.getString(i); - break; - } - } - result[result.length] = row; - } - var logTimeStop = isLogSqlEnabled ? java.lang.System.currentTimeMillis() : 0; - if (isLogSqlEnabled) { - var tableName = metaData.getColumnCount() > 0 ? metaData.getTableName(1) : null; - app.getLogger("helma." + app.name + ".sql").info("SQL DIRECT_QUERY " + (tableName || "-") + " " + (logTimeStop - logTimeStart) + ": " + sql); - } - try { - statement.close(); - resultSet.close(); - } catch (error) { - // ignore - } - return result; - }; - - /** - * Executes the given SQL statement, which may be an INSERT, UPDATE, - * or DELETE statement or an SQL statement that returns nothing, - * such as an SQL data definition statement. The return value is an integer that - * indicates the number of rows that were affected by the statement. - * @param {String} sql an SQL statement - * @return {int} either the row count for INSERT, UPDATE or - * DELETE statements, or 0 for SQL statements that return nothing - */ - this.execute = function(sql) { - var isLogSqlEnabled = (getProperty("logSQL", "false").toLowerCase() == "true"); - var logTimeStart = isLogSqlEnabled ? java.lang.System.currentTimeMillis() : 0; - var connection = source.getConnection(); - connection.setReadOnly(false); - var statement = connection.createStatement(); - var result; - try { - result = statement.executeUpdate(sql); - } finally { - try { - statement.close(); - } catch (error) { - // ignore - } - } - var logTimeStop = isLogSqlEnabled ? java.lang.System.currentTimeMillis() : 0; - if (isLogSqlEnabled) { - app.getLogger("helma." + app.name + ".sql").info("SQL DIRECT_EXECUTE - " + (logTimeStop - logTimeStart) + ": " + sql); - } - return result; - }; - - /** - * Return the name of the Helma DbSource object. - * @return {String} the DbSource name - */ - this.getName = function() { - return source.getName(); - }; - - /** - * Return the name of the JDBC driver used by this Database instance. - * @return {String} the JDBC driver name - */ - this.getDriverName = function() { - return source.getDriverName(); - }; - - /** - * @ignore - */ - this.toString = function() { - return "[helma.Database " + this.getName() + "]"; - }; - - for (var i in this) - this.dontEnum(i); - - return this; -}; - -/** - * Create a new Database instance using the given parameters. - *

    Some of the parameters support shortcuts for known database products. - * The url parameter recognizes the values "mysql", "oracle" and - * "postgresql". For those databases, it is also possible to pass just - * hostname or hostname:port as url - * parameters instead of the full JDBC URL.

    - * @param {String} driver the class name of the JDBC driver. As - * shortcuts, the values "mysql", "oracle" and "postgresql" are - * recognized. - * @param {String} url the JDBC URL. - * @param {String} name the name of the database to use - * @param {String} user the the username - * @param {String} password the password - * @return {helma.Database} a helma.Database instance - */ -helma.Database.createInstance = function(driver, url, name, user, password) { - var DbSource = Packages.helma.objectmodel.db.DbSource; - - if (!driver || !url || !name) - throw("Insufficient arguments to create helma.db.Connection"); - if (typeof password != "string") - password = ""; - - var MYSQL = "mysql"; - var ORACLE = "oracle"; - var POSTGRESQL = "postgresql"; - var JDBC = "jdbc:"; - var DRIVER_MYSQL = "com.mysql.jdbc.Driver"; - var DRIVER_ORACLE = "oracle.jdbc.driver.OracleDriver"; - var DRIVER_POSTGRESQL = "org.postgresql.Driver"; - - if (driver == MYSQL) { - driver = DRIVER_MYSQL; - if (url.indexOf(JDBC) != 0) - url = "jdbc:mysql://" + url + "/" + name; - } else if (driver == ORACLE) { - driver = DRIVER_ORACLE; - if (url.indexOf(JDBC) != 0) - url = "jdbc:oracle:thin:@" + url + ":" + name; - } else if (driver == POSTGRESQL) { - driver = DRIVER_POSTGRESQL; - if (url.indexOf(JDBC) != 0) - url = "jdbc:postgresql://" + url + "/" + name; - } - var props = new Packages.helma.util.ResourceProperties(); - props.put(name + ".url", url); - props.put(name + ".driver", driver); - if (user) { - props.put(name + ".user", user) - } - if (password) { - props.put(name + ".password", password); - } - return new helma.Database(new DbSource(name, props)); -} - -/** - * Get a Database instance using the Database source defined in the - * application's db.properties file with the given name. - * @param {String} name the name of the DB source as defined in db.properties - * @return {helma.Database} a helma.Database instance - */ -helma.Database.getInstance = function(name) { - return new helma.Database(app.getDbSource(name)); -} - -/** - * @ignore - */ -helma.Database.toString = function() { - return "[helma.Database]"; -}; - -/** - * @ignore - */ -helma.Database.example = function() { - var type = "mysql"; - var host = "localhost"; - var user = "root"; - var pw = ""; - var name = "mysql"; - var db = new helma.Database(type, host, user, pw, name); - var result = db.query("select count(*) from db"); - res.write(result.toSource()); - return; -}; - - -helma.lib = "Database"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/File.js b/modules/helma/File.js deleted file mode 100644 index c5ad66f6..00000000 --- a/modules/helma/File.js +++ /dev/null @@ -1,760 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2007 Helma Software. All Rights Reserved. - * - * $RCSfile: File.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - - -/** - * @fileoverview Default properties and methods of the File prototype. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/File.js') - */ - - -/** - * Define the global namespace if not existing - */ -if (!global.helma) { - global.helma = {}; -} - - -/** - * Constructor for File objects, providing read and - * write access to the file system. - * @class This class represents a local file or directory - * @param {String} path as String, can be either absolute or relative to the helma home directory - * @constructor - */ -helma.File = function(path) { - var BufferedReader = java.io.BufferedReader; - var File = java.io.File; - var Writer = java.io.Writer; - var FileReader = java.io.FileReader; - var PrintWriter = java.io.PrintWriter; - var FileOutputStream = java.io.FileOutputStream; - var OutputStreamWriter = java.io.OutputStreamWriter; - var FileInputStream = java.io.FileInputStream; - var InputStreamReader = java.io.InputStreamReader; - var EOFException = java.io.EOFException; - var IllegalStateException = java.lang.IllegalStateException; - var IllegalArgumentException = java.lang.IllegalArgumentException - - var self = this; - - var file; - try { - // immediately convert to absolute path - java.io.File is - // incredibly stupid when dealing with relative file names - if (arguments.length > 1) - file = new File(path, arguments[1]).getAbsoluteFile(); - else - file = new File(path).getAbsoluteFile(); - } catch (e) { - throw(e); - } - - var readerWriter; - var atEOF = false; - var lastLine = null; - - var setError = function(e) { - self.lastError = e; - }; - - this.lastError = null; - - /** @ignore */ - this.toString = function() { - return file.toString(); - }; - - /** - * Returns the name of the file or directory represented by this File object. - *

    - * This is just the last name in the pathname's name sequence. - * If the pathname's name sequence is empty, then the empty - * string is returned. - * - * @returns String containing the name of the file or directory - * @type String - */ - this.getName = function() { - var name = file.getName(); - return (name == null ? "" : name); - }; - - /** - * Returns true if the file represented by this File object - * is currently open. - * - * @returns Boolean - * @type Boolean - */ - this.isOpened = function() { - return (readerWriter != null); - }; - - /** - * Opens the file represented by this File object. If the file exists, - * it is used for reading, otherwise it is opened for writing. - * If the encoding argument is specified, it is used to read or write - * the file. Otherwise, the platform's default encoding is used. - * - * @param {Object} options an optional argument holder object. - * The following options are supported: - *
    • charset name of encoding to use for reading or writing
    • - *
    • append whether to append to the file if it exists
    - * @returns Boolean true if the operation succeeded - * @type Boolean - */ - this.open = function(options) { - if (self.isOpened()) { - setError(new IllegalStateException("File already open")); - return false; - } - // We assume that the BufferedReader and PrintWriter creation - // cannot fail except if the FileReader/FileWriter fails. - // Otherwise we have an open file until the reader/writer - // get garbage collected. - var charset = options && options.charset; - var append = options && options.append; - try { - if (file.exists() && !append) { - if (charset) { - readerWriter = new BufferedReader( - new InputStreamReader(new FileInputStream(file), charset)); - } else { - readerWriter = new BufferedReader(new FileReader(file)); - } - } else { - if (append && charset) { - readerWriter = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(file, true), charset)); - } else if (append) { - readerWriter = new PrintWriter( - new OutputStreamWriter(new FileOutputStream(file, true))); - } else if (charset) { - readerWriter = new PrintWriter(file, charset); - } else { - readerWriter = new PrintWriter(file); - } - } - return true; - } catch (e) { - setError(e); - return false; - } - return; - }; - - /** - * Tests whether the file or directory represented by this File object exists. - * - * @returns Boolean true if the file or directory exists; false otherwise - * @type Boolean - */ - this.exists = function() { - return file.exists(); - }; - - /** - * Returns the pathname string of this File object's parent directory. - * - * @returns String containing the pathname of the parent directory - * @type String - */ - this.getParent = function() { - if (!file.getParent()) - return null; - return new helma.File(file.getParent()); - }; - - /** - * This methods reads characters until an end of line/file is encountered - * then returns the string for these characters (without any end of line - * character). - * - * @returns String of the next unread line in the file - * @type String - */ - this.readln = function() { - if (!self.isOpened()) { - setError(new IllegalStateException("File not opened")); - return null; - } - if (!(readerWriter instanceof BufferedReader)) { - setError(new IllegalStateException("File not opened for reading")); - return null; - } - if (atEOF) { - setError(new EOFException()); - return null; - } - if (lastLine != null) { - var line = lastLine; - lastLine = null; - return line; - } - var reader = readerWriter; - // Here lastLine is null, return a new line - try { - var line = readerWriter.readLine(); - if (line == null) { - atEOF = true; - setError(new EOFException()); - } - return line; - } catch (e) { - setError(e); - return null; - } - return; - }; - - /** - * Appends a string to the file represented by this File object. - * - * @param {String} what as String, to be written to the file - * @returns Boolean - * @type Boolean - * @see #writeln - */ - this.write = function(what) { - if (!self.isOpened()) { - setError(new IllegalStateException("File not opened")); - return false; - } - if (!(readerWriter instanceof PrintWriter)) { - setError(new IllegalStateException("File not opened for writing")); - return false; - } - if (what != null) { - readerWriter.print(what.toString()); - } - return true; - }; - - /** - * Appends a string with a platform specific end of - * line to the file represented by this File object. - * - * @param {String} what as String, to be written to the file - * @returns Boolean - * @type Boolean - * @see #write - */ - this.writeln = function(what) { - if (self.write(what)) { - readerWriter.println(); - return true; - } - return false; - }; - - /** - * Tests whether this File object's pathname is absolute. - *

    - * The definition of absolute pathname is system dependent. - * On UNIX systems, a pathname is absolute if its prefix is "/". - * On Microsoft Windows systems, a pathname is absolute if its prefix - * is a drive specifier followed by "\\", or if its prefix is "\\". - * - * @returns Boolean if this abstract pathname is absolute, false otherwise - * @type Boolean - */ - this.isAbsolute = function() { - return file.isAbsolute(); - }; - - /** - * Deletes the file or directory represented by this File object. - * - * @returns Boolean - * @type Boolean - */ - this.remove = function() { - if (self.isOpened()) { - setError(new IllegalStateException("An openened file cannot be removed")); - return false; - } - return file["delete"](); - }; - - /** - * List of all files within the directory represented by this File object. - *

    - * You may pass a RegExp Pattern to return just files matching this pattern. - *

    - * Example: var xmlFiles = dir.list(/.*\.xml/); - * - * @param {RegExp} pattern as RegExp, optional pattern to test each file name against - * @returns Array the list of file names - * @type Array - */ - this.list = function(pattern) { - if (self.isOpened()) - return null; - if (!file.isDirectory()) - return null; - if (pattern) { - var fileList = file.list(); - var result = []; - for (var i in fileList) { - if (pattern.test(fileList[i])) - result.push(fileList[i]); - } - return result; - } - return file.list(); - }; - - /** - * Purges the content of the file represented by this File object. - * - * @returns Boolean - * @type Boolean - */ - this.flush = function() { - if (!self.isOpened()) { - setError(new IllegalStateException("File not opened")); - return false; - } - if (readerWriter instanceof Writer) { - try { - readerWriter.flush(); - } catch (e) { - setError(e); - return false; - } - } else { - setError(new IllegalStateException("File not opened for write")); - return false; // not supported by reader - } - return true; - }; - - /** - * Closes the file represented by this File object. - * - * @returns Boolean - * @type Boolean - */ - this.close = function() { - if (!self.isOpened()) - return false; - try { - atEOF = false; - lastLine = null; - readerWriter.close(); - readerWriter = null; - return true; - } catch (e) { - setError(e); - readerWriter = null; - return false; - } - }; - - /** - * Returns the pathname string of this File object. - *

    - * The resulting string uses the default name-separator character - * to separate the names in the name sequence. - * - * @returns String of this file's pathname - * @type String - */ - this.getPath = function() { - var path = file.getPath(); - return (path == null ? "" : path); - }; - - /** - * Contains the last error that occured, if any. - * @returns String - * @type String - * @see #clearError - */ - this.error = function() { - if (this.lastError == null) { - return ""; - } else { - var exceptionName = this.lastError.getClass().getName(); - var l = exceptionName.lastIndexOf("."); - if (l > 0) - exceptionName = exceptionName.substring(l + 1); - return exceptionName + ": " + this.lastError.getMessage(); - } - }; - - /** - * Clears any error message that may otherwise be returned by the error method. - * - * @see #error - */ - this.clearError = function() { - this.lastError = null; - return; - }; - - /** - * Tests whether the application can read the file - * represented by this File object. - * - * @returns Boolean true if the file exists and can be read; false otherwise - * @type Boolean - */ - this.canRead = function() { - return file.canRead(); - }; - - /** - * Tests whether the file represented by this File object is writable. - * - * @returns Boolean true if the file exists and can be modified; false otherwise. - * @type Boolean - */ - this.canWrite = function() { - return file.canWrite(); - }; - - /** - * Returns the absolute pathname string of this file. - *

    - * If this File object's pathname is already absolute, then the pathname - * string is simply returned as if by the getPath() method. If this - * abstract pathname is the empty abstract pathname then the pathname - * string of the current user directory, which is named by the system - * property user.dir, is returned. Otherwise this pathname is resolved - * in a system-dependent way. On UNIX systems, a relative pathname is - * made absolute by resolving it against the current user directory. - * On Microsoft Windows systems, a relative pathname is made absolute - * by resolving it against the current directory of the drive named by - * the pathname, if any; if not, it is resolved against the current user - * directory. - * - * @returns String The absolute pathname string - * @type String - */ - this.getAbsolutePath = function() { - var absolutPath = file.getAbsolutePath(); - return (absolutPath == null ? "" : absolutPath); - }; - - /** - * Returns the length of the file represented by this File object. - *

    - * The return value is unspecified if this pathname denotes a directory. - * - * @returns Number The length, in bytes, of the file, or 0L if the file does not exist - * @type Number - */ - this.getLength = function() { - return file.length(); - }; - - /** - * Tests whether the file represented by this File object is a directory. - * - * @returns Boolean true if this File object is a directory and exists; false otherwise - * @type Boolean - */ - this.isDirectory = function() { - return file.isDirectory(); - }; - - /** - * Tests whether the file represented by this File object is a normal file. - *

    - * A file is normal if it is not a directory and, in addition, satisfies - * other system-dependent criteria. Any non-directory file created by a - * Java application is guaranteed to be a normal file. - * - * @returns Boolean true if this File object is a normal file and exists; false otherwise - * @type Boolean - */ - this.isFile = function() { - return file.isFile(); - }; - - /** - * Returns the time when the file represented by this File object was last modified. - *

    - * A number representing the time the file was last modified, - * measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), - * or 0L if the file does not exist or if an I/O error occurs. - * - * @returns Number in milliseconds since 00:00:00 GMT, January 1, 1970 - * @type Number - */ - this.lastModified = function() { - return file.lastModified(); - }; - - /** - * Creates the directory represented by this File object. - * - * @returns Boolean true if the directory was created; false otherwise - * @type Boolean - */ - this.makeDirectory = function() { - if (self.isOpened()) - return false; - // don't do anything if file exists or use multi directory version - return (file.exists() || file.mkdirs()); - }; - - /** - * Renames the file represented by this File object. - *

    - * Whether or not this method can move a file from one - * filesystem to another is platform-dependent. The return - * value should always be checked to make sure that the - * rename operation was successful. - * - * @param {FileObject} toFile as FileObject of the new path - * @returns true if the renaming succeeded; false otherwise - * @type Boolean - */ - this.renameTo = function(toFile) { - if (toFile == null) { - setError(new IllegalArgumentException("Uninitialized target File object")); - return false; - } - if (self.isOpened()) { - setError(new IllegalStateException("An openened file cannot be renamed")); - return false; - } - if (toFile.isOpened()) { - setError(new IllegalStateException("You cannot rename to an openened file")); - return false; - } - return file.renameTo(new java.io.File(toFile.getAbsolutePath())); - }; - - /** - * Returns true if the file represented by this File object - * has been read entirely and the end of file has been reached. - * - * @returns Boolean - * @type Boolean - */ - this.eof = function() { - if (!self.isOpened()) { - setError(new IllegalStateException("File not opened")); - return true; - } - if (!(readerWriter instanceof BufferedReader)) { - setError(new IllegalStateException("File not opened for read")); - return true; - } - if (atEOF) - return true; - if (lastLine != null) - return false; - try { - lastLine = readerWriter.readLine(); - if (lastLine == null) - atEOF = true; - return atEOF; - } catch (e) { - setError(e); - return true; - } - }; - - /** - * This methods reads all the lines contained in the - * file and returns them. - * - * @return String of all the lines in the file - * @type String - */ - this.readAll = function() { - // Open the file for readAll - if (self.isOpened()) { - setError(new IllegalStateException("File already open")); - return null; - } - try { - if (file.exists()) { - readerWriter = new BufferedReader(new FileReader(file)); - } else { - setError(new IllegalStateException("File does not exist")); - return null; - } - if (!file.isFile()) { - setError(new IllegalStateException("File is not a regular file")); - return null; - } - - // read content line by line to setup proper eol - var buffer = new java.lang.StringBuffer(file.length() * 1.10); - while (true) { - var line = readerWriter.readLine(); - if (line == null) - break; - if (buffer.length() > 0) - buffer.append("\n"); // EcmaScript EOL - buffer.append(line); - } - - // Close the file - readerWriter.close(); - readerWriter = null; - return buffer.toString(); - } catch (e) { - readerWriter = null; - setError(e); - return null; - } - }; - - - /** - * This method removes a directory recursively . - *

    - * DANGER! DANGER! HIGH VOLTAGE! - * The directory is deleted recursively without - * any warning or precautious measures. - */ - this.removeDirectory = function() { - if (!file.isDirectory()) - return false; - var arr = file.list(); - for (var i=0; i
    - * Useful for passing it to a function instead of an request object. - */ - this.toByteArray = function() { - if (!this.exists()) - return null; - var body = new java.io.ByteArrayOutputStream(); - var stream = new java.io.BufferedInputStream( - new java.io.FileInputStream(this.getAbsolutePath()) - ); - var buf = java.lang.reflect.Array.newInstance( - java.lang.Byte.TYPE, 1024 - ); - var read; - while ((read = stream.read(buf)) > -1) - body.write(buf, 0, read); - stream.close(); - return body.toByteArray(); - }; - - for (var i in this) - this.dontEnum(i); - - return this; -} - - -/** @ignore */ -helma.File.toString = function() { - return "[helma.File]"; -}; - - -helma.File.separator = java.io.File.separator; - - -helma.lib = "File"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Ftp.js b/modules/helma/Ftp.js deleted file mode 100644 index 67296bfa..00000000 --- a/modules/helma/Ftp.js +++ /dev/null @@ -1,568 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2007 Helma Software. All Rights Reserved. - * - * $RCSfile: Ftp.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - - -/** - * @fileoverview Default properties and methods of the FTP prototype. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Ftp.js') - */ - -// requires helma.File -app.addRepository("modules/helma/File.js"); - -/** - * Define the global namespace if not existing - */ -if (!global.helma) { - global.helma = {}; -} - -/** - * Constructor for FTP client objects, to send and receive files from an FTP server. - *

    - * @class This class represents a FTP client, providing - * access to an FTP server. - * - * @example var ftp = new helma.Ftp("ftp.mydomain.com"); - * @param {String} server as String, the address of the FTP Server to connect to - * @constructor - */ -helma.Ftp = function(server) { - var OK = 0; - var SOCKET = 1; - var TIMEOUT = 2; - var LOGIN = 10; - var LOGOUT = 11; - var BINARY = 20; - var ASCII = 21; - var ACTIVE = 22; - var PASSIVE = 23; - var CD = 30; - var LCD = 31; - var PWD = 32; - var DIR = 33; - var MKDIR = 34; - var RMDIR = 35; - var GET = 40; - var PUT = 41; - var DELETE = 42; - var RENAME = 43; - - var FTP = Packages.org.apache.commons.net.ftp.FTP; - var FtpClient = Packages.org.apache.commons.net.ftp.FTPClient; - var BufferedInputStream = java.io.BufferedInputStream; - var BufferedOutputStream = java.io.BufferedOutputStream; - var FileInputStream = java.io.FileInputStream; - var FileOutputStream = java.io.FileOutputStream; - var ByteArrayInputStream = java.io.ByteArrayInputStream; - var ByteArrayOutputStream = java.io.ByteArrayOutputStream; - - var self = this; - var className = "helma.Ftp"; - - var ftpclient = new FtpClient(); - var localDir; - - var error = function(methName, errMsg) { - var tx = java.lang.Thread.currentThread(); - tx.dumpStack(); - app.log("Error in " + className + ":" + methName + ": " + errMsg); - return; - }; - - var debug = function(methName, msg) { - msg = msg ? " " + msg : ""; - app.debug(className + ":" + methName + msg); - return; - }; - - var setStatus = function(status) { - if (self.status === OK) { - self.status = status; - } - return; - }; - - var getStatus = function() { - return self.status; - }; - - this.server = server; - this.status = OK; - - /** @ignore */ - this.toString = function() { - return "[helma.Ftp " + server + "]"; - }; - - /** - * Set the default timeout in milliseconds to use when opening a socket. - */ - this.setReadTimeout = function(timeout) { - try { - ftpclient.setDefaultTimeout(timeout); - debug("setReadTimeout", timeout); - return true; - } catch(x) { - error("setReadTimeout", x); - setStatus(SOCKET); - } - return false; - }; - - /** - * Sets the timeout in milliseconds to use when reading from the data connection. - */ - this.setTimeout = function(timeout) { - try { - ftpclient.setDataTimeout(timeout); - debug("setTimeout", timeout); - return true; - } catch(x) { - error("setTimeout", x); - setStatus(TIMEOUT); - } - return false; - }; - - /** - * Logs in to the FTP server. - * - * @param {String} username as String - * @param {String} password as String - * @return Boolean true if the login was successful, otherwise false - * @type Boolean - */ - this.login = function(username, password) { - try { - ftpclient.connect(this.server); - var result = ftpclient.login(username, password); - debug("login", username + "@" + server); - return result; - } catch(x) { - error("login", x); - setStatus(LOGIN); - } - return false; - }; - - /** - * Sets transfer mode to binary for transmitting images and other non-text files. - * - * @example ftp.binary(); - */ - this.binary = function() { - try { - var result = ftpclient.setFileType(FTP.BINARY_FILE_TYPE); - debug("binary"); - return result; - } catch(x) { - error("binary", x); - setStatus(BINARY); - } - return false; - }; - - /** - * Sets transfer mode to ascii for transmitting text-based data. - * - * @example ftp.ascii(); - */ - this.ascii = function() { - try { - var result = ftpclient.setFileType(FTP.ASCII_FILE_TYPE); - debug("ascii"); - return result; - } catch(x) { - error("ascii", x); - setStatus(ASCII); - } - return false; - }; - - /** - * Switches the connection to use active mode. - * - * @example ftp.active(); - */ - this.active = function() { - try { - ftpclient.enterLocalActiveMode(); - debug("active"); - return true; - } catch(x) { - error("active", x); - setStatus(ACTIVE); - } - return false; - }; - - /** - * Switches the connection to use passive mode. - * - * @example ftp.passive(); - */ - this.passive = function() { - try { - ftpclient.enterLocalPassiveMode(); - debug("passive"); - return true; - } catch(x) { - error("passive", x); - setStatus(PASSIVE); - } - return false; - }; - - /** - * Returns the path of the current working directory. - * - * @example var remotepath = ftp.pwd(); - * @type String - * @return String containing the current working directory path - */ - this.pwd = function() { - try { - debug("pwd"); - return ftpclient.printWorkingDirectory(); - } catch(x) { - error("pwd", x); - setStatus(PWD); - } - return; - }; - - /** - * Returns a listing of the files contained in a directory on the FTP server. - *

    - * Lists the files contained in the current working - * directory or, if an alternative path is specified, the - * files contained in the specified directory. - * - * @example var filelist = ftp.dir(); - * @param {String} path as String, optional alternative directory - * @return Array containing the list of files in that directory - * @type Array - */ - this.dir = function(path) { - try { - debug("dir", path); - return ftpclient.listNames(path ? path : "."); - } catch(x) { - error("dir", x); - setStatus(DIR); - } - return; - }; - - /** - * Creates a new directory on the server. - *

    - * The name of the directory is determined as the function's - * string parameter. Returns false when an error occured - * (e.g. due to access restrictions, directory already - * exists etc.), otherwise true. - * - * @param {String} dir as String, the name of the directory to be created - * @return Boolean true if the directory was successfully created, false if there was an error - * @type Boolean - */ - this.mkdir = function(dir) { - try { - var result = ftpclient.makeDirectory(dir); - debug("mkdir", dir); - return result; - } catch(x) { - error("mkdir", x); - setStatus(MKDIR); - } - return false; - }; - - /** - * Deletes a directory on the FTP server. - * - * @param {String} dir as String, the name of the directory to be deleted - * @return Boolean true if the deletion was successful, false otherwise - * @type Boolean - */ - this.rmdir = function(dir) { - try { - var result = ftpclient.removeDirectory(dir); - debug("rmdir", dir); - return result; - } catch(x) { - error("rmdir", x); - setStatus(RMDIR); - } - return false; - }; - - /** - * Changes the working directory on the FTP server. - * - * @example ftp.cd("/home/users/fred/www"); // use absolute pathname - * @example ftp.cd(".."); // change to parent directory - * @example ftp.cd("images"); // use relative pathname - * @param {String} dir as String, the path that the remote working directory should be changed to - */ - this.cd = function(path) { - try { - var result = ftpclient.changeWorkingDirectory(path); - debug("cd", path); - return result; - } catch(x) { - error("cd", x); - setStatus(CD); - } - return false; - }; - - /** - * Changes the working directory of the local machine when being connected to an FTP server. - * - * @example ftp.lcd("/home/users/fred/www"); // use absolute pathname - * @example ftp.lcd(".."); // change to parent directory - * @example ftp.lcd("images"); // use relative pathname - * @param {String} dir as String, the path that the local working directory should be changed to - */ - this.lcd = function(dir) { - try { - localDir = new helma.File(dir); - if (!localDir.exists()) { - localDir.mkdir(); - debug("lcd", dir); - } - return true; - } catch(x) { - error("lcd", x); - setStatus(LCD); - } - return false; - }; - - /** - * Transfers a file from the local file system to the remote server. - *

    - * Returns true if the transmission was successful, otherwise false. - * - * @param {String} localFile as String, the name of the file to be uploaded - * @param {String} remoteFile as String, the name of the remote destination file - * @return Boolean true if the file was successfully uploaded, false if there was an error - * @type Boolean - */ - this.putFile = function(localFile, remoteFile) { - try { - if (localFile instanceof File || localFile instanceof helma.File) { - var f = localFile; - } else if (typeof localFile == "string") { - if (localDir == null) - var f = new helma.File(localFile); - else - var f = new helma.File(localDir, localFile); - } - var stream = new BufferedInputStream( - new FileInputStream(f.getPath()) - ); - if (!remoteFile) { - remoteFile = f.getName(); - } - var result = ftpclient.storeFile(remoteFile, stream); - stream.close(); - debug("putFile", remoteFile); - return result; - } catch(x) { - error("putFile", x); - setStatus(PUT); - } - return false; - }; - - /** - * Transfers text from a string to a file on the FTP server. - * - * @example ftp.putString("Hello, World!", "message.txt"); - * @param {String} str as String, the text content that should be uploaded - * @param {String} remoteFile as String, the name of the remote destination file - * @param {String} charset as String, optional - * @return Boolean true if the file was successfully uploaded, false if there was an error - * @type Boolean - */ - this.putString = function(str, remoteFile, charset) { - try { - str = new java.lang.String(str); - var bytes = charset ? str.getBytes(charset) : str.getBytes(); - var stream = ByteArrayInputStream(bytes); - var result = ftpclient.storeFile(remoteFile, stream); - debug("putString", remoteFile); - return result; - } catch(x) { - error("putString", x); - setStatus(PUT); - } - return false; - }; - - /** - * Transfers a byte array to a file on the FTP server. - * @param {Array} bytes The byte array that should be uploaded - * @param {String} remoteFile The name of the remote destination file - * @return Boolean True if the file was successfully uploaded, false if there was an error - * @type Boolean - */ - this.putBytes = function(bytes, remoteFile) { - try { - var stream = ByteArrayInputStream(bytes); - var result = ftpclient.storeFile(remoteFile, stream); - debug("putBytes", remoteFile); - return result; - } catch(x) { - error("putBytes", x); - setStatus(PUT); - } - return false; - }; - - /** - * Transfers a file from the FTP server to the local file system. - * - * @example ftp.getFile(".htaccess", "htaccess.txt"); - * @param {String} remoteFile as String, the name of the file that should be downloaded - * @param {String} localFile as String, the name which the file should be stored under - * @see #cd - * @see #lcd - */ - this.getFile = function(remoteFile, localFile) { - try { - if (localDir == null) - var f = new helma.File(localFile); - else - var f = new helma.File(localDir, localFile); - var stream = new BufferedOutputStream( - new FileOutputStream(f.getPath()) - ); - var result = ftpclient.retrieveFile(remoteFile, stream); - stream.close(); - debug("getFile", remoteFile); - return result; - } catch(x) { - error("getFile", x); - setStatus(GET); - } - return false; - }; - - /** - * Retrieves a file from the FTP server and returns it as string. - * - * @example var str = ftp.getString("messages.txt"); - * @param {String} remoteFile as String, the name of the file that should be downloaded - * @return String containing the data of the downloaded file - * @type String - * @see #cd - */ - this.getString = function(remoteFile) { - try { - var stream = ByteArrayOutputStream(); - ftpclient.retrieveFile(remoteFile, stream); - debug("getString", remoteFile); - return stream.toString(); - } catch(x) { - error("getString", x); - setStatus(GET); - } - return; - }; - - /** - * Deletes a file on the FTP server. - * - * @example var str = ftp.deleteFile("messages.txt"); - * @param {String} remoteFile as String, the name of the file to be deleted - * @return Boolean true if the deletion was successful, false otherwise - * @type Boolean - */ - this.deleteFile = function(remoteFile) { - try { - var result = ftpclient.deleteFile(remoteFile); - debug("deleteFile", remoteFile); - return result; - } catch(x) { - error("deleteFile", x); - setStatus(DELETE); - } - return false; - }; - - /** - * Renames a file on the FTP server. - * - * @example var success = ftp.renameFile("messages.tmp", "messages.txt"); - * @param {String} from the name of the original file - * @param {String} to the new name the original file should get - * @return Boolean true if renaming the remote file was successful, false otherwise - * @type Boolean - */ - this.renameFile = function(from, to) { - try { - var result = ftpclient.rename(from, to); - debug("renameFile", from + "->" + to); - return result; - } catch(x) { - error("renameFile", x); - setStatus(RENAME); - } - return false; - }; - - /** - * Terminates the current FTP session. - */ - this.logout = function() { - try { - var result = ftpclient.logout(); - ftpclient.disconnect(); - debug("logout"); - return result; - } catch(x) { - error("logout", x); - setStatus(LOGOUT); - } - return false; - }; - - for (var i in this) - this.dontEnum(i); - - return this; -} - - -/** @ignore */ -helma.Ftp.toString = function() { - return "[helma.Ftp]"; -}; - - -helma.lib = "Ftp"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Group.js b/modules/helma/Group.js deleted file mode 100644 index a15081dc..00000000 --- a/modules/helma/Group.js +++ /dev/null @@ -1,875 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Group.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview A JavaScript library wrapping - * Packages.helma.extensions.helmagroups - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Group.js') - */ - -// Define the global namespace if not existing -if (!global.helma) { - global.helma = {}; -} - -/** - * Constructs a new helma.Group Object. - * @class This is what is retrieved through groups.get(groupName), - * wrapping the root object of each group tree. - * @param {FIXME} javaGroup FIXME - * @constructor - */ -helma.Group = function(javaGroup) { - // private variable containing the wrapper object - var groupRoot = new helma.Group.GroupObject(javaGroup.getRoot()); - - /** - * @returns the wrapped java object Group - */ - this.getJavaObject = function() { - return javaGroup; - }; - - /** - * sets a key/value pair on the group's root, - * wraps the function of the wrapper object - */ - this.set = function(key, val, sendMode) { - groupRoot.set(key, val, sendMode); - return; - }; - - /** - * removes a key from the group's root, - * wraps the function of the root GroupObject - */ - this.remove = function(key, sendMode) { - return groupRoot.remove(key, sendMode); - }; - - /** - * retrieves a key from the group's root, - * wraps the function of the root GroupObject - */ - this.get = function(key) { - return groupRoot.get(key); - }; - - /** - * @see helma.Group.GroupObject.listChildren - */ - this.listChildren = function() { - return groupRoot.listChildren(); - }; - - /** - * @see helma.Group.GroupObject.listProperties - */ - this.listProperties = function() { - return groupRoot.listProperties(); - }; - - /** - * @see helma.Group.GroupObject.countChildren - */ - this.countChildren = function() { - return groupRoot.countChildren(); - }; - - /** - * @see helma.Group.GroupObject.countProperties - */ - this.countProperties = function() { - return groupRoot.countProperties(); - }; - - /** - * calls a function in all connected applications - * (to be specific: in all registered localClients). - * @param method name of the method in xmlrpc-style: test - * is called as root.test(), stories.137.render - * is called as root.stories.get("137").render() etc etc. - * @param argArr array of arguments to the remote method - * @param sendMode as defined for helma.Group.GroupObject - * @returns array of result objects - */ - this.callFunction = function(method, argArr, sendMode) { - groups.checkWriteAccess(javaGroup); - if (sendMode == null) { - sendMode = helma.Group.GroupObject.DEFAULT_GET; - } - var argVec = new java.util.Vector(); - for (var i=0; i - *
  • a String
  • - *
  • a String containing slashes
  • - *
  • an Array containing String keys
  • - * - * @param {Number} The value to set the property to. - * @param {Object} The mode to use when committing the change to - * the helma.Group - */ - this.set = function(key, val, sendMode) { - if (!key) { - throw "helma.Group.GroupObject.set(): key can't be null"; - } - checkWriteAccess(); - // check content type of value: - var ok = false; - if (val == null) - ok = true; - else if (typeof(val) == "string") - ok = true; - else if (typeof(val) == "number") - ok = true; - else if (typeof(val) == "boolean") - ok = true; - else if (val instanceof Date) - ok = true; - else if (val instanceof helma.Group.GroupObject) - ok = true; - if (ok == false) { - throw "only primitive values, Date and helma.Group.GroupObject allowed in helma.Group.GroupObject.set()"; - } - if (sendMode == null) { - sendMode = helma.Group.GroupObject.DEFAULT_GET; - } - - if (keyIsPath(key)) { - var obj = createPath(this, key); - if (obj != null) { - obj.set(getLastKeyElement(key), val, sendMode); - } - } else { - // set a property/child of this object - if (val == null) { - // null values aren't permitted in the group, - // setting a property to null is the same as deleting it - this.remove(key, sendMode); - } else if (val instanceof helma.Group.GroupObject) { - // replicate helma.Group.GroupObject - javaGroupObject.put(key, val.getJavaObject(), sendMode); - } else { - // put the primitive property (or maybe replicate, - // decision's up to helma.Group.GroupObject) - if (val instanceof Date) { - // convert javascript dates to java dates - val = new java.util.Date(val.getTime()); - } - javaGroupObject.put(key, val, sendMode); - } - } - return; - }; - - - - /** - * Removes a property or a child GroupObject from this instance. - * The Key may be a String, an Array or a String with separator characters ("/"). - * In the latter two cases the argument is considered a path and - * the function walks down that path to find the GroupObject and - * deletes it. - * @param {Object} key Either - *
      - *
    • a String
    • - *
    • a String containing slashes
    • - *
    • an Array containing String keys
    • - *
    - * @param {Number} The mode to use when committing the change to - * the helma.Group - */ - this.remove = function(key, sendMode) { - checkWriteAccess(); - if (sendMode == null) { - sendMode = helma.Group.GroupObject.DEFAULT_GET; - } - if (keyIsPath(key)) { - var obj = walkPath(this, key); - if (obj != null) { - obj.remove(getLastKeyElement(key)); - } - } else { - javaGroupObject.remove(key, sendMode); - } - return; - }; - - - /** - * Returns either a property or a child GroupObject from - * this GroupObject instance. The key passed as argument - * may be a String, an Array containing Strings or a - * String containing separator characters ("/"). In the latter - * two cases the argument is considered a path and - * the function walks down that path to find the requested - * GroupObject. - * @param {Object} key Either - *
      - *
    • a String
    • - *
    • a String containing slashes
    • - *
    • an Array containing String keys
    • - *
    - * @return Depending on the argument either the appropriate property - * value or a helma.Group.GroupObject - * @type Object - */ - this.get = function(key) { - if (key == null) { - return null; - } - if (keyIsPath(key)) { - var obj = walkPath(this, key); - if (obj != null) { - return obj.get(getLastKeyElement(key)); - } else { - return null; - } - } else if (javaGroupObject.hasProperty(key)) { - // we got a primitive property - var val = javaGroupObject.getProperty(key); - if (val instanceof java.util.Date) { - // convert java dates to javascript dates - val = new Date(val); - } - return val; - } else if (javaGroupObject.hasChild(key)) { - // we got a child object - return new helma.Group.GroupObject(javaGroupObject.getChild(key)); - } - return null; - }; - - - /** - * Gets a property from this GroupObject. The key passed as argument - * is always considered a property even if it contains a slash. - * This is actually a workaround for the fact that other - * instances of the group not using the javascript extension aren't forbidden - * to add properties containing a slash in the property's name. - * So, using this extension we can at least read the property. - * @param {String} key The name of the property to return - * @returns The value of the property - * @type Object - */ - this.getProperty = function(key) { - if (key == null) { - return null; - } else if (javaGroupObject.hasProperty(key)) { - // we got a primitive property - var val = javaGroupObject.getProperty(key); - if (val instanceof java.util.Date) { - // convert java dates to javascript dates - val = new Date(val); - } - return val; - } - return null; - } - - - /** - * Exchanges this GroupObject with the one passed - * as argument. This is done by exchanging the wrapped - * instance of helma.extensions.helmagroups.GroupObject - * @param {GroupObject} The GroupObject to use - * @returns The GroupObject with the exchanged wrapped java object - * @type GroupObject - */ - this.wrap = function(newGroupObject) { - checkWriteAccess(); - if (javaGroupObject.getState() != helmagroups.GroupObject.REPLICATED) { - throw "helma.Group.GroupObject.wrap() may only be called on replicated GroupObjects"; - } - if (newGroupObject == null || !(newGroupObject instanceof helma.Group.GroupObject)) { - throw "helma.Group.GroupObject.wrap() requires a helma.Group.GroupObject as an argument"; - } - javaGroupObject.wrap(newGroupObject.getJavaObject()); - return this; - }; - - /** - * Clones this GroupObject and returns it. - * This method should be considered if many properties - * of a GroupObject must be set or modified since every - * change to an already replicated GroupObject will - * result in immediate network traffic. Using unwrap - * one can modify several properties and then commit - * the GroupObject at once using {@link #wrap). - * @returns A clone of this GroupObject - * @type GroupObject - */ - this.unwrap = function() { - var javaGroupObjectClone = javaGroupObject.clone(); - javaGroupObjectClone.setChildren(new java.util.Hashtable()); - javaGroupObjectClone.setState(helmagroups.GroupObject.LOCAL); - javaGroupObjectClone.setPath(null); - return new helma.Group.GroupObject(javaGroupObjectClone); - }; - - /** - * Converts this GroupObject into a vanilla Object - * @returns An Object containing all properties of this GroupObject - * @type Object - */ - this.toJSObject = function() { - var key; - var obj = {}; - var e = javaGroupObject.properties(); - while(e.hasMoreElements()) { - obj[key = e.nextElement()] = javaGroupObject.getProperty(key); - } - return obj; - }; - - /** - * Returns an Array containing all child GroupObjects - * @returns An Array containing GroupObjects - * @type Array - */ - this.listChildren = function() { - var arr = []; - var e = javaGroupObject.children(); - while(e.hasMoreElements()) { - arr.push(e.nextElement()); - } - return arr; - }; - - /** - * Returns an Array containing all property - * names of this GroupObject instance - * @returns An Array containing property names - * @type Array - */ - this.listProperties = function() { - var arr = []; - var e = javaGroupObject.properties(); - while(e.hasMoreElements()) { - arr.push(e.nextElement()); - } - return arr; - }; - - /** - * Returns the number of child GroupObjects - * @returns The number of child GroupObjects of this - * helma.Group.GroupObject instance - * @type Number - */ - this.countChildren = function() { - var ht = javaGroupObject.getChildren(); - if (ht == null) { - return 0; - } else { - return ht.size(); - } - }; - - /** - * Returns the number of properties of this GroupObject - * @return The number of properties - * @type Number - */ - this.countProperties = function() { - var ht = javaGroupObject.getProperties(); - return (ht == null) ? 0 : ht.size(); - }; - - /** - * Returns true if the GroupObject is not replicated - * @returns True if this GroupObject is still local - * @type Boolean - */ - this.isLocal = function() { - return (javaGroupObject.getState() - == helmagroups.GroupObject.LOCAL); - }; - - /** @ignore */ - this.toString = function() { - return javaGroupObject.toString(); - }; - - return this; -}; - -/** - * Static properties of GroupObject constructor function. - * These values determine if and for how many confirmation of the - * group members this instance waits after a modification. - * These values are passed through to org.jgroups.blocks.GroupRequest, - * for further comments see the sourcecode of that class - */ -// wait just for the first response -helma.Group.GroupObject.GET_FIRST = 1; -// wait until all members have responded -helma.Group.GroupObject.GET_ALL = 2; -// wait for majority (50% + 1) to respond -helma.Group.GroupObject.GET_MAJORITY = 3; -// wait for majority of all members (may block!) -helma.Group.GroupObject.GET_ABS_MAJORITY = 4; -// don't wait for any response (fire & forget) -helma.Group.GroupObject.GET_NONE = 6; -// default: wait for all responses -helma.Group.GroupObject.DEFAULT_GET = helma.Group.GroupObject.GET_ALL; - -/** - * This is mounted as "groups". - * @class The root for all groups started in this application - * @constructor - */ -helma.Group.Manager = function() { - var helmagroups = Packages.helma.extensions.helmagroups; - var extension = helmagroups.GroupExtension.self; - - if (extension == null) { - throw("helma.Group.Manager requires the HelmaGroups Extension \ - located in lib/ext or the application's top-level directory \ - [http://adele.helma.org/download/helma/contrib/helmagroups/]"); - } - - - /** - * get a java object Group for a groupname. - * object is fetched regardless of connection status - * @returns null if group is not defined - */ - var getJavaGroup = function(name) { - return extension.checkAppLink(app.name).get(name); - }; - - - /** - * visible to scripting env: get a group, wrapped as a javascript helma.Group object. - * the group must be defined in app.properties: group.nameXX = - * and can then be accessed like this group.get("nameXX") - * @returns null if group is not defined or not connected - */ - this.get = function(name) { - var javaGroup = getJavaGroup(name); - if (javaGroup == null || javaGroup.isConnected() == false) { - return null; - } else { - return new helma.Group(javaGroup); - } - }; - - - /** - * checks for write access to a group according to app.properties - * group.nameXX.writable must be true so that this function returns - * @param nameOrJGroup can be the name of a group or a java Group itself - * @throws an error if group is not writable - */ - this.checkWriteAccess = function(nameOrJGroup) { - var extension = helmagroups.GroupExtension.self; - var jAppLink = extension.checkAppLink(app.name); - if (nameOrJGroup instanceof helmagroups.Group) { - // arg was a Group - var javaGroup = nameOrJGroup; - } else { - // arg was the name of the group - var javaGroup = jAppLink.get(nameOrJGroup); - } - if (javaGroup != null && jAppLink.isWritable(javaGroup) == false) { - throw("tried to access write-protected group"); - } - return true; - }; - - - /** - * try to connect a group - * @returns false if group is not found - */ - this.connect = function(name) { - var javaGroup = getJavaGroup(name); - if (javaGroup == null) { - return false; - } - javaGroup.connect(); - return true; - }; - - - /** - * try to disconnect from a group - * @returns false if group is not found - */ - this.disconnect = function(name) { - var javaGroup = getJavaGroup(name); - if (javaGroup == null) { - return false; - } - javaGroup.disconnect(); - return true; - }; - - - /** - * try to disconnect and connect again to a group - * @returns false if group is not found - */ - this.reconnect = function(name) { - var javaGroup = getJavaGroup(name); - if (javaGroup == null) { - return false; - } - javaGroup.reconnect(); - return true; - }; - - - /** - * try to reset a group (if application may write in group). - * all instances of the group empty their cache. - * @returns false if group is not found - */ - this.reset = function(name) { - var javaGroup = getJavaGroup(name); - if (javaGroup == null) { - return false; - } - groups.checkWriteAccess(javaGroup); - javaGroup.reset(); - return true; - }; - - - /** - * try to destroy a group (if application may write in group). - * all other instances of the group disconnect - * @returns false if group is not found - */ - this.destroy = function(name) { - var javaGroup = getJavaGroup(name); - if (javaGroup == null) { - return false; - } - groups.checkWriteAccess(javaGroup); - javaGroup.destroy(); - return true; - }; - - - /** - * try to restart a group (if application may write in group). - * all other instances of the group disconnect and reconnect - each app after a different pause - * so that they don't all come up at the same moment - * @returns false if group is not found - */ - this.restart = function(name) { - var javaGroup = getJavaGroup(name); - if (javaGroup == null) { - return false; - } - groups.checkWriteAccess(javaGroup); - javaGroup.restart(); - return true; - }; - - - /** - * list the members of this group (ie instances of Group, one helma server is one instance) - * @returns array of strings, false if group is not found - */ - this.listMembers = function(name) { - var javaGroup = getJavaGroup(name); - if (javaGroup == null) { - return false; - } - var addrArr = javaGroup.info.listMembers(); - var arr = []; - for (var i=0; i
    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Html.js') - */ - -// take care of any dependencies -app.addRepository('modules/core/String.js'); -app.addRepository('modules/core/Object.js'); -app.addRepository('modules/core/Array.js'); - -/** - * Define the global namespace if not existing - */ -if (!global.helma) { - global.helma = {}; -} - -/** - * Creates a new instance of helma.Html - * @class This class provides various methods for rendering - * X/Html tags. - * @returns A newly created instance of helma.Html - * @constructor - */ -helma.Html = function() { - return this; -}; - -/** - * Static helper method that renders an arbitrary markup part. - * @param {String} name The element's name - * @param {String} start Prefix of each rendered element - * @param {String} end Suffix of each rendered element - * @param {Object} attr Optional element attributes - */ -helma.Html.renderMarkupPart = function(name, start, end, attr) { - res.write(start); - res.write(name); - if (attr) { - for (var i in attr) { - if (i == "prefix" || i == "suffix" || - i == "default" || attr[i] == null) { - continue; - } - res.write(" "); - res.write(i); - res.write("=\""); - res.write(attr[i]); - res.write("\""); - } - } - res.write(end); - return; -}; - -/** - * Static helper method used in helma.Html.checkBox - * and helma.Html.dropDown to check if a current value - * matches against one or more selected values passed - * as argument - * @param {String} value The current value to check - * @param {String|Array} selectedValue Either a single - * value to check against the current value, or an array - * containing values. - * @returns True in case the value is among the selected - * values, false otherwise - * @type Boolean - */ -helma.Html.isSelected = function(value, selectedValue) { - if (selectedValue == null || value == null) - return false; - if (selectedValue instanceof Array) - return selectedValue.contains(value); - return value == selectedValue; -}; - - -/** @ignore */ -helma.Html.prototype.toString = function() { - return "[helma.Html]"; -}; - -/** - * Renders the opening tag of an arbitrary x/html tag - * @param {String} name The tag name - * @param {Object} attr An optional object containing element attributes - */ -helma.Html.prototype.openTag = function(name, attr) { - helma.Html.renderMarkupPart(name, "<", ">", attr); - return; -}; - -/** - * Returns the opening tag of an arbitrary x/html tag - * @param {String} name The tag name - * @param {Object} attr An optional object containing element attributes - * @returns The rendered x/html opening tag - * @type String - * @see #openTag - */ -helma.Html.prototype.openTagAsString = function(name, attr) { - res.push(); - helma.Html.renderMarkupPart(name, "<", ">", attr); - return res.pop(); -}; - -/** - * Renders the closing tag of an arbitrary x/html tag - * @param {String} name The tag name - */ -helma.Html.prototype.closeTag = function(name) { - helma.Html.renderMarkupPart(name, "", null); - return; -}; - -/** - * Returns the closing tag of an arbitray x/html element - * @param {String} name The tag name - * @returns The rendered closing tag - * @type String - * @see #closeTag - */ -helma.Html.prototype.closeTagAsString = function(name) { - res.push(); - helma.Html.renderMarkupPart(name, "", null); - return res.pop(); -}; - -/** - * Renders an empty arbitrary x/html tag ("contentless tag") - * @param {String} name The tag name - * @param {Object} attr An optional object containing tag attributes - */ -helma.Html.prototype.tag = function(name, attr) { - helma.Html.renderMarkupPart(name, "<", " />", attr); - return; -}; - -/** - * Returns an empty arbitrary x/html tag ("contentless tag") - * @param {String} name The tag name - * @param {Object} attr An optional object containing tag attributes - * @returns The rendered element - * @type String - * @see #tag - */ -helma.Html.prototype.tagAsString = function(name, attr) { - res.push(); - helma.Html.renderMarkupPart(name, "<", " />", attr); - return res.pop(); -}; - -/** - * Renders an arbitrary x/html element - * @param {String} name The element name - * @param {String} str The content of the element - * @param {Object} attr An optional object containing element attributes - */ -helma.Html.prototype.element = function(name, str, attr) { - helma.Html.renderMarkupPart(name, "<", ">", attr); - res.write(str); - helma.Html.renderMarkupPart(name, ""); - return; -}; - -/** - * Return an arbitrary x/html element - * @param {String} name The element name - * @param {String} str The content of the element - * @param {Object} attr An optional object containing element attributes - * @returns The rendered element - * @type String - * @see #element - */ -helma.Html.prototype.elementAsString = function(name, str, attr) { - res.push(); - this.element(name, str, attr); - return res.pop(); -}; - -/** - * Renders an x/html link tag - * @param {Object} attr An object containing the link attributes - * @param {String} text The text to appear as link - */ -helma.Html.prototype.link = function(attr, text) { - if (!attr) { - res.write("[Html.link: insufficient arguments]"); - return; - } - this.openTag("a", attr); - res.write(text); - this.closeTag("a"); - return; -}; - -/** - * Returns a rendered x/html link tag - * @param {Object} attr An object containing the link attributes - * @param {String} text The text to appear as link - * @returns The rendered link tag - * @type String - * @see #link - */ -helma.Html.prototype.linkAsString = function(attr, text) { - res.push(); - this.link(attr, text); - return res.pop(); -}; - -/** - * Renders an x/html input tag of type "hidden" - * @param {Object} param An object containing the tag attributes - */ -helma.Html.prototype.hidden = function(param) { - if (!param) { - res.write("[Html.hidden: insufficient arguments]"); - return; - } - var attr = Object.prototype.reduce.call(param); - attr.type = "hidden"; - attr.value = (attr.value != null) ? encodeForm(attr.value) : ""; - this.tag("input", attr); - return; -}; - -/** - * Returns a rendered x/html input tag of type "hidden" - * @param {Object} attr An object containing the tag attributes - * @returns The rendered input element - * @type String - * @see #hidden - */ -helma.Html.prototype.hiddenAsString = function(attr) { - res.push(); - this.hidden(attr); - return res.pop(); -}; - -/** - * Renders an x/html text input tag - * @param {Object} param An object containing the tag attributes - */ -helma.Html.prototype.input = function(param) { - if (!param) { - res.write("[Html.input: insufficient arguments]"); - return; - } - var attr = Object.prototype.reduce.call(param); - attr.type = param.type || "text"; - attr.value = (attr.value != null) ? encodeForm(attr.value) : ""; - this.tag("input", attr); - return; -}; - -/** - * Returns a rendered x/html text input tag - * @param {Object} attr An object containing the tag attributes - * @returns The rendered text input tag - * @type String - * @see #input - */ -helma.Html.prototype.inputAsString = function(attr) { - res.push(); - this.input(attr); - return res.pop(); -}; - -/** - * Renders an x/html textarea tag - * @param {Object} param An object containing the tag attributes - */ -helma.Html.prototype.textArea = function(param) { - if (!param) { - res.write("[Html.textArea: insufficient arguments]"); - return; - } - var attr = Object.prototype.reduce.call(param); - var value = (attr.value != null) ? encodeForm(attr.value) : ""; - delete attr.value; - this.openTag("textarea", attr); - res.write(value); - this.closeTag("textarea"); - return; -}; - -/** - * Returns a rendered x/html textarea tag - * @param {Object} attr An object containing the tag attributes - * @returns The rendered textarea tag - * @type String - * @see #textArea - */ -helma.Html.prototype.textAreaAsString = function(attr) { - res.push(); - this.textArea(attr); - return res.pop(); -}; - -/** - * Renders an x/html checkbox input tag - * @param {Object} param An object containing the tag attributes - */ -helma.Html.prototype.checkBox = function(param) { - if (!param) { - res.write("[Html.checkBox: insufficient arguments]"); - return; - } - var attr = Object.prototype.reduce.call(param); - attr.type = "checkbox"; - if (attr.selectedValue != null) { - if (helma.Html.isSelected(param.value, param.selectedValue)) - attr.checked = "checked"; - else - delete attr.checked; - delete attr.selectedValue; - } - this.tag("input", attr); - return; -}; - -/** - * Returns a rendered x/html checkbox input tag - * @param {Object} attr An object containing the tag attributes - * @returns The rendered checkbox tag - * @type String - * @see #checkBox - */ -helma.Html.prototype.checkBoxAsString = function(attr) { - res.push(); - this.checkBox(attr); - return res.pop(); -}; - -/** - * Renders an x/html radiobutton input tag - * @param {Object} param An object containing the tag attributes - */ -helma.Html.prototype.radioButton = function(param) { - if (!param) { - res.write("[Html.radioButton: insufficient arguments]"); - return; - } - var attr = Object.prototype.reduce.call(param); - attr.type = "radio"; - if (attr.selectedValue != null) { - if (attr.value == attr.selectedValue) - attr.checked = "checked"; - else - delete attr.checked; - delete attr.selectedValue; - } - this.tag("input", attr); - return; -}; - -/** - * Returns a rendered x/html radio input tag - * @param {Object} attr An object containing the tag attributes - * @returns The rendered element - * @type String - * @see #radioButton - */ -helma.Html.prototype.radioButtonAsString = function(attr) { - res.push(); - this.radioButton(attr); - return res.pop(); -}; - -/** - * Renders an x/html submit input tag - * @param {Object} param An object containing the tag attributes - */ -helma.Html.prototype.submit = function(param) { - if (!param) { - res.write("[Html.submit: insufficient arguments]"); - return; - } - var attr = Object.prototype.reduce.call(param); - attr.type = "submit"; - if (!attr.name) - attr.name = attr.type; - attr.value = (attr.value != null) ? encodeForm(attr.value) : attr.type; - this.tag("input", attr); - return; -}; - -/** - * Returns a rendered x/html submit input tag - * @param {Object} attr An object containing the tag attributes - * @returns The rendered submit input tag - * @type String - * @see #submit - */ -helma.Html.prototype.submitAsString = function(attr) { - res.push(); - this.submit(attr); - return res.pop(); -}; - -/** - * Renders an x/html button input tag - * @param {Object} param An object containing the tag attributes - */ -helma.Html.prototype.button = function(param) { - if (!param) { - res.write("[Html.button: insufficient arguments]"); - return; - } - var attr = Object.prototype.reduce.call(param); - attr.type = "button"; - if (!attr.name) - attr.name = attr.type; - attr.value = (attr.value != null) ? encodeForm(attr.value) : attr.type; - this.tag("input", attr); - return; -}; - -/** - * Returns a rendered x/html button input tag - * @param {Object} param An object containing the tag attributes - * @returns The rendered button input tag - * @type String - * @see #button - */ -helma.Html.prototype.buttonAsString = function(attr) { - res.push(); - this.button(attr); - return res.pop(); -}; - -/** - * Renders a x/html drop down select box - * @param {Object} param An object containing the tag attributes - * @param {Array} options Either an array of strings, an array with - * several {value: v, display: d} objects, or a collection - * of ["value", "display"] arrays in an array - * @param {String} selectedValue The value to pre-select - * @param {String} firstOption An optional first option to display in the - * select box (this option will always have no value) - */ -helma.Html.prototype.dropDown = function(param, options, selectedValue, firstOption) { - if (!param) { - res.write("[Html.dropDown: insufficient arguments]"); - return; - } - var attr = Object.prototype.reduce.call(param); - this.openTag("select", attr); - res.write("\n "); - if (firstOption) { - this.openTag("option", {value: ""}); - res.write(firstOption); - this.closeTag("option"); - res.write("\n "); - } - var hasOpenGroup = false; - for (var i in options) { - if (options[i].group) { - hasOpenGroup && html.closeTag("optgroup"); - html.openTag("optgroup", {label: options[i].group}); - hasOpenGroup = true; - } - var attr = new Object(); - var display = ""; - if ((options[i] instanceof Array) && options[i].length > 0) { - // option is an array - attr.value = options[i][0]; - display = options[i][1]; - } else if (options[i].value != null && options[i].display != null) { - // option is an object - attr.value = options[i].value; - if (options[i]["class"] != null) { - attr["class"] = options[i]["class"]; - } - display = options[i].display; - } else { - // assume option is a string - attr.value = i; - display = options[i]; - } - if (helma.Html.isSelected(attr.value, selectedValue)) - attr.selected = "selected"; - this.openTag("option", attr); - res.write(display); - this.closeTag("option"); - res.write("\n "); - } - hasOpenGroup && html.closeTag("optgroup"); - this.closeTag("select"); - res.write("\n "); - return; -}; - -/** - * Returns a rendered x/html drop down select box - * @param {Object} param An object containing the tag attributes - * @param {Array} options Either an array of strings, an array with - * several {value: v, display: d} objects, or a collection - * of ["value", "display"] arrays in an array - * @param {String} selectedValue The value to pre-select - * @param {String} firstOption An optional first option to display in the - * select box (this option will always have no value) - * @returns The rendered drop down select box - * @type String - * @see #dropDown - */ -helma.Html.prototype.dropDownAsString = function(attr, options, selectedValue, firstOption) { - res.push(); - this.dropDown(attr, options, selectedValue, firstOption); - return res.pop(); -}; - -/** - * Renders an image map based on an array containing the map parameters. - * @param {String} name The name of the image map - * @param {Array} param An array containing objects, where each of them - * contains the attributes for a single image map entry - */ -helma.Html.prototype.map = function(name, param) { - if (!name || !param) { - res.write("[Html.map: insufficient arguments]"); - return; - } - this.openTag("map", {name: name}); - var attr = Object.prototype.reduce.call(param); - for (var i in areas) { - if (!areas[i].alt) - areas[i].alt = ""; - if (!areas[i].shape) - areas[i].shape = "rect"; - this.openTag("area", areas[i]); - } - this.closeTag("map"); - return; -}; - -/** - * Returns a rendered image map based on an array containing the map parameters. - * @param {String} name The name of the image map - * @param {Array} areas An array containing objects, where each of them - * contains the attributes for a single image map entry - * @returns The rendered image map - * @type String - * @see #map - */ -helma.Html.prototype.mapAsString = function(name, areas) { - res.push(); - this.map(name, areas); - return res.pop(); -}; - -/** - * Renders a complete x/html table. - * @param {Array} headers An array containing table headers - * @param {Array} data A two-dimensional array containing the table data - * @param {Object} param An object containing the following properties: - *
      - *
    • table: Attributes to render within the opening <table> tag
    • - *
    • tr: Attributes to render within each <tr> tag
    • - *
    • td: Attributes to render within each <td> tag
    • - *
    • th: Attributes to render within each <th> tag
    • - *
    • trHead: Attributes to render within each <tr> tag - in the header area of the table
    • - *
    • trEven: Attributes to render within each even <tr> tag
    • - *
    • trOdd: Attributes to render within each odd <tr> tag
    • - *
    • tdEven: Attributes to render within each even <td> tag
    • - *
    • tdOdd: Attributes to render within each odd <td> tag
    • - *
    • thEven: Attributes to render within each even <th> tag
    • - *
    • thOdd: Attributes to render within each odd <th> tag
    • - *
    - */ -helma.Html.prototype.table = function(headers, data, param) { - if (!param) { - res.write("[Html.table: insufficient arguments]"); - return; - } - var attr = Object.prototype.reduce.call(param); - if (!attr.trHead) attr.trHead = attr.tr; - if (!attr.trEven) attr.trEven = attr.tr; - if (!attr.trOdd) attr.trOdd = attr.tr; - if (!attr.tdEven) attr.tdEven = attr.td; - if (!attr.tdOdd) attr.tdOdd = attr.td; - if (!attr.thEven) attr.thEven = attr.th; - if (!attr.thOdd) attr.thOdd = attr.th; - this.openTag("table", attr.table); - if (headers) { - this.openTag("tr", attr.trHead); - for (var i in headers) { - var evenOdd = i % 2 == 0 ? "Even" : "Odd"; - this.openTag("th", attr["th"+evenOdd]); - res.write(headers[i]); - this.closeTag("th"); - } - this.closeTag("tr"); - } - for (var i in data) { - var evenOdd = i % 2 == 0 ? "Even" : "Odd"; - this.openTag("tr", attr["tr"+evenOdd]); - for (var j in data[i]) { - var evenOddCell = j % 2 == 0 ? "Even" : "Odd"; - this.openTag("td", attr["td"+evenOddCell]); - res.write(data[i][j]); - this.closeTag("td"); - } - this.closeTag("tr"); - } - this.closeTag("table"); - return; -}; - -/** - * Returns a rendered x/html table - * @param {Array} headers An array containing table headers - * @param {Array} data A two-dimensional array containing the table data - * @param {Object} attr For a description see {@link #table} - * @returns The rendered table - * @type String - * @see #table - */ -helma.Html.prototype.tableAsString = function(headers, data, attr) { - res.push(); - this.table(headers, data, attr); - return res.pop(); -}; - -/*********************************************************************/ -/* */ -/* the following functions should be deliberately altered or removed */ -/* (most of these can easily be replaced by the methods they call) */ -/* */ -/*********************************************************************/ - -/** - * Renders an x/html opening link tag - * @param {Object} attr An object containing the tag attributes - */ -helma.Html.prototype.openLink = function(attr) { - this.openTag("a", attr); - return; -}; - -/** - * Returns an x/html opening link tag - * @param {Object} attr An object containing the tag attributes - * @returns The rendered open link tag - * @type String - * @see #openTag - */ -helma.Html.prototype.openLinkAsString = function(attr) { - return this.openTagAsString("a", attr); -}; - -/** - * Renders an x/html closing link tag - */ -helma.Html.prototype.closeLink = function() { - this.closeTag("a"); - return; -}; - -/** - * Returns a rendered x/html closing link tag - * @returns Rhe rendered closing link tag - * @type String - * @see #closeLink - */ -helma.Html.prototype.closeLinkAsString = function() { - return this.closeTagAsString("a"); -}; - -/** - * Renders a color definition string. If the string passed as - * argument contains only hex characters it will be prefixed with a - * hash sign if necessary, otherwise this method assumes that the - * value is a named color (eg. "yellow"). - * @param {String} c The color definintion - * @deprecated - */ -helma.Html.prototype.color = function(c) { - if (c) { - var nonhex = /[^0-9,a-f]/gi; - if (!c.match(nonhex)) { - c = c.pad("0", 6); - res.write("#"); - } - } - res.write(c); - return; -}; - -/** - * Returns a color definition. - * @param {String} c The color definintion - * @returns The rendered color definition - * @type String - * @see #color - * @deprecated - */ -helma.Html.prototype.colorAsString = function(c) { - res.push(); - this.color(c); - return res.pop(); -}; - -/** - * Renders an x/html opening form tag - * @param {Object} attr An object containing the tag attributes - */ -helma.Html.prototype.form = function(attr) { - this.openTag("form", attr); - return; -}; - -/** - * Returns an x/html opening form tag - * @param {Object} attr An object containing the tag attributes - * @returns The rendered opening form tag - * @type String - * @see #form - */ -helma.Html.prototype.formAsString = function(attr) { - res.push(); - this.form(attr); - return res.pop(); -}; - -/** - * Renders an x/html password input tag - * @param {Object} attr An object containing the tag attributes - */ -helma.Html.prototype.password = function(attr) { - if (!attr) { - res.write("[Html.password: insufficient arguments]"); - return; - } - attr.type = "password"; - this.tag("input", attr); - return; -}; - -/** - * Returns a rendered x/html password input tag - * @param {Object} attr An object containing the tag attributes - * @returns The rendered password input tag - * @type String - * @see #password - */ -helma.Html.prototype.passwordAsString = function(attr) { - res.push(); - this.password(attr); - return res.pop(); -}; - -/** - * Renders an x/html file input tag - * @param {Object} attr An object containing the tag attributes - */ -helma.Html.prototype.file = function(attr) { - if (!attr) { - res.write("[Html.file: insufficient arguments]"); - return; - } - attr.type = "file"; - this.tag("input", attr); - return; -}; - -/** - * Returns a rendered x/html file input tag - * @param {Object} attr An object containing the tag attributes - * @returns The rendered file input tag - * @type String - * @see #file - */ -helma.Html.prototype.fileAsString = function(attr) { - res.push(); - this.file(attr); - return res.pop(); -}; - -/** - * Parses the string passed as argument and converts any - * URL in it into a link tag - * @param {String} str The string wherein URLs should be - * converted into link tags - * @returns The string containing URLs converted into link tags - * @type String - */ -helma.Html.prototype.activateUrls = function(str) { - var re = /(^|\/>|\s+)([fhtpsr]+:\/\/[^\s]+?)([\.,;:\)\]\"]?)(?=[\s<]|$)/gim; - var func = function(str, p1, p2, p3) { - res.push(); - res.write(p1); - res.write(''); - res.write(p2.clip(50, "...", true)); - res.write(''); - res.write(p3); - return res.pop(); - }; - return str.replace(re, func); -}; - -/** - * Creates a new TableWriter instance - * @class This class provides various methods for - * programmatically creating an x/html table. - * @param {Number} numberOfColumns The number of columns in the table - * @param {Object} attr An object containing attributes to use when - * rendering the single table elements. For a description see {@link #table}. - * @returns An instance of TableWriter - * @constructor - */ -helma.Html.TableWriter = function(numberOfColumns, attr) { - if (isNaN(numberOfColumns)) - throw "Illegal argument in TableWriter(): first argument must be a number"; - if (numberOfColumns < 1) - throw "Illegal argument in TableWriter(): first argument must be > 1"; - /** @private */ - this.ncols = numberOfColumns; - /** @private */ - this.written = 0; - // if no attributes object given, create an empty one - if (!attr) - attr = {}; - if (!attr.trEven) attr.trEven = attr.tr; - if (!attr.trOdd) attr.trOdd = attr.tr; - if (!attr.trHead) attr.trHead = attr.trEven; - if (!attr.tdEven) attr.tdEven = attr.td; - if (!attr.tdOdd) attr.tdOdd = attr.td; - if (!attr.thEven) attr.thEven = attr.th; - if (!attr.thOdd) attr.thOdd = attr.th; - /** @private */ - this.attr = attr; - - /** - * If set to true the first row of the table data is rendered - * using <th> tags (defaults to false). - * @type Boolean - */ - this.writeHeader = false; - - /** - * If set to true the TableWriter returns the rendered table - * as string, otherwise the table is written directly to response, - * which is the default. - * @type Boolean - */ - this.writeString = false; - - this.dontEnum("ncols", "written", "attr", "writeHeader", "writeString"); - - return this; -}; - -/** @ignore */ -helma.Html.TableWriter.prototype.toString = function() { - return "[helma.Html.TableWriter]"; -} - -/** - * Writes a single table cell to response. - * @param {String} text The content of the table cess - * @param {Object} attr An optional object containig attributes - * to render for this table cell - */ -helma.Html.TableWriter.prototype.write = function(text, attr) { - // set up some variables - var isHeaderRow = (this.writeHeader && this.written < this.ncols); - var isNewRow = (this.written % this.ncols == 0); - var isEvenRow = ((this.written / this.ncols) % 2 == 0); - var isEvenCol = ((this.written % this.ncols) % 2 == 0); - // write out table and table row tags - if (this.written == 0) { - if (this.writeString) - res.push(); - helma.Html.prototype.openTag.call(this, "table", this.attr.table); - helma.Html.prototype.openTag.call(this, "tr", this.attr.trHead); - } else if (isNewRow) { - helma.Html.prototype.closeTag.call(this, "tr"); - if (isEvenRow) - helma.Html.prototype.openTag.call(this, "tr", this.attr.trEven); - else - helma.Html.prototype.openTag.call(this, "tr", this.attr.trOdd); - } - // get the attribute object for the table cell - if (!attr) { - // no explicit attribute given - if (isEvenCol) { - attr = isHeaderRow ? this.attr.thEven : this.attr.tdEven; - } else { - attr = isHeaderRow ? this.attr.thOdd : this.attr.tdOdd; - } - } - // write out table cell tag - helma.Html.prototype.openTag.call(this, isHeaderRow ? "th" : "td", attr); - // write out table cell contents - if (text) { - res.write(text); - } - // close table cell - helma.Html.prototype.closeTag.call(this, isHeaderRow ? "th" : "td"); - if (attr && !isNaN(attr.colspan)) { - this.written += attr.colspan; - } else { - this.written += 1; - } - return; -}; - -/** - * Closes all open table tags. If {@link #writeString} is set to - * true, this method returns the rendered table. - * @returns The rendered table, if {@link #writeString} is set to - * true, otherwise void. - * @type String - */ -helma.Html.TableWriter.prototype.close = function() { - if (this.written > 0) { - while (this.written++ % this.ncols != 0) - res.write(""); - res.write(""); - this.written = 0; - } - if (this.writeString) - return res.pop(); - return; -}; - - - -helma.lib = "Html"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -for (var i in helma[helma.lib].TableWriter.prototype) - helma[helma.lib].TableWriter.prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Http.js b/modules/helma/Http.js deleted file mode 100644 index f1cab23d..00000000 --- a/modules/helma/Http.js +++ /dev/null @@ -1,833 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Http.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - - -/** - * @fileoverview Fields and methods of the helma.Http class. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Http.js') - */ - -// take care of any dependencies -app.addRepository('modules/core/Date.js'); - - -/** - * Define the global namespace if not existing - */ -if (!global.helma) { - global.helma = {}; -} - -/** - * Creates a new instance of helma.Http - * @class This class provides functionality to programatically issue - * an Http request based on java.net.HttpUrlConnection. - * By default the request will use method GET. - * @returns A newly created helma.Http instance - * @constructor - */ -helma.Http = function() { - var self = this; - var proxy = null; - var content = ""; - var userAgent = "Helma Http Client"; - var method = "GET"; - var cookies = null; - var credentials = null; - var followRedirects = true; - var binaryMode = false; - var headers = {}; - var timeout = { - "connect": 0, - "socket": 0 - }; - var maxResponseSize = null; - var maxTries = 5; - var currentTries = 0; - - var responseHandler = function(connection, result) { - var input; - var stream; - try { - stream = connection.getInputStream(); - } catch (error) { - stream = connection.getErrorStream(); - } - if (stream) { - if (connection.getContentEncoding() === 'gzip') { - stream = new java.util.zip.GZIPInputStream(stream); - } - input = new java.io.BufferedInputStream(stream); - } - if (input) { - var body = new java.io.ByteArrayOutputStream(); - var buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024); - var len; - var currentSize = 0; - while ((len = input.read(buf)) > -1) { - body.write(buf, 0, len); - currentSize += len; - if (maxResponseSize && currentSize > maxResponseSize) { - throw new Error("Maximum allowed response size is exceeded"); - } - } - try { - input.close(); - } catch (error) { - // safe to ignore - } - if (binaryMode) { - result.content = body.toByteArray(); - } else { - result.content = result.charset ? - body.toString(result.charset) : - body.toString(); - } - // adjust content length - if (result.content) { - result.length = result.content.length; - } - } - }; - - /** @private */ - var setTimeout = function(type, value) { - var v = java.lang.System.getProperty("java.specification.version"); - if (parseFloat(v, 10) >= 1.5) { - timeout[type] = value; - } else { - app.logger.warn("helma.Http: Timeouts can only be set with Java Runtime version >= 1.5"); - } - return true; - } - - /** - * Sets the proxy host and port for later use. The argument must - * be in host:port format (eg. "proxy.example.com:3128"). - * @param {String} proxyString The proxy to use for this request - * @see #getProxy - */ - this.setProxy = function(proxyString) { - var idx = proxyString.indexOf(":"); - var host = proxyString.substring(0, idx); - var port = proxyString.substring(idx+1); - if (java.lang.Class.forName("java.net.Proxy") != null) { - // construct a proxy instance - var socket = new java.net.InetSocketAddress(host, port); - proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, socket); - } else { - // the pre jdk1.5 way: set the system properties - var sys = java.lang.System.getProperties(); - if (host) { - app.logger.warn("[Helma Http Client] WARNING: setting system http proxy to " + host + ":" + port); - sys.put("http.proxySet", "true"); - sys.put("http.proxyHost", host); - sys.put("http.proxyPort", port); - } - } - return; - }; - - /** - * Returns the proxy in host:port format - * @return The proxy defined for this request - * @type String - * @see #setProxy - */ - this.getProxy = function() { - if (proxy != null) { - return proxy.address().getHostName() + ":" + proxy.address().getPort(); - } else if (sys.get("http.proxySet") == "true") { - return sys.get("http.proxyHost") + ":" + sys.get("http.proxyPort"); - } else { - return null; - } - }; - - /** - * Sets the credentials for basic http authentication - * @param {String} username The username - * @param {String} password The password - */ - this.setCredentials = function(username, password) { - var str = username + ":" + password; - credentials = str.enbase64(); - return; - } - - /** - * Sets the content to send to the remote server within this request. - * @param {String|Object} stringOrObject The content of the request, which - * can be either a string or an object. In the latter case all properties - * and their values are concatenated into a single string. - * If a property is an array, then for each value the propertyname and value pair is added. - * If the name of an array property ends with "_array" then the _array part is removed. - */ - this.setContent = function(stringOrObject) { - if (stringOrObject != null) { - if (stringOrObject.constructor == Object) { - res.push(); - var value; - for (var key in stringOrObject) { - value = stringOrObject[key]; - if (value instanceof Array) { - if (key.substring(key.length - 6) == "_array") - key = key.substring(0,key.length - 6); - for (var i = 0; i < value.length; i++) { - res.write(encodeURIComponent(key)); - res.write("="); - res.write(encodeURIComponent(value[i])); - res.write("&"); - } - } else { - res.write(encodeURIComponent(key)); - res.write("="); - res.write(encodeURIComponent(value)); - res.write("&"); - } - } - content = res.pop(); - content = content.substring(0, content.length-1); - } else { - content = stringOrObject.toString(); - } - } else { - content = null; - } - return; - }; - - /** - * Sets the request method to use. - * @param {String} m The method to use (GET, POST ...) - * @see #getMethod - */ - this.setMethod = function(m) { - method = m; - return; - }; - - /** - * Returns the currently defined request method. - * @returns The method used - * @type String - * @see #setMethod - */ - this.getMethod = function() { - return method; - }; - - /** - * Sets a single HTTP request header field - * @param {String} name The name of the header field - * @param {String} value The value of the header field - * @see #getHeader - */ - this.setHeader = function(name, value) { - headers[name] = value; - return; - }; - - /** - * Returns the value of the request header field with the given name - * @param {String} name The name of the request header field - * @returns The value of the request header field - * @type String - * @see #setHeader - */ - this.getHeader = function(name) { - return headers[name]; - }; - - /** - * Adds a cookie with the name and value passed as arguments - * to the list of cookies to send to the remote server. - * @param {String} name The name of the cookie - * @param {String} value The value of the cookie - * @see #getCookie - * @see #getCookies - */ - this.setCookie = function(name, value) { - if (name != null && value != null) { - // store the cookie in the cookies map - if (!cookies) { - cookies = {}; - } - cookies[name] = new helma.Http.Cookie(name, value); - } - return; - }; - - /** - * Returns the value of the cookie with the given name - * @param {String} name The name of the cookie - * @returns The value of the cookie - * @type String - * @see #setCookie - */ - this.getCookie = function(name) { - return (cookies != null) ? cookies[name] : null; - }; - - /** - * Adds the cookies passed as argument to the list of cookies to send - * to the remote server. - * @param {Array} cookies An array containing objects with the properties - * "name" (the name of the cookie) and "value" (the value of the cookie) set. - */ - this.setCookies = function(cookies) { - if (cookies != null) { - for (var i=0; i - *
  • url: (String) The Url of the request
  • - *
  • location: (String) The value of the location header field
  • - *
  • code: (Number) The HTTP response code
  • - *
  • message: (String) An optional HTTP response message
  • - *
  • length: (Number) The content length of the response
  • - *
  • type: (String) The mimetype of the response
  • - *
  • charset: (String) The character set of the response
  • - *
  • encoding: (String) An optional encoding to use with the response
  • - *
  • lastModified: (String) The value of the lastModified response header field
  • - *
  • eTag: (String) The eTag as received from the remote server
  • - *
  • cookie: (helma.Http.Cookie) An object containing the cookie parameters, if the remote - server has set the "Set-Cookie" header field
  • - *
  • headers: (java.util.Map) A map object containing the headers, access them using get("headername") - *
  • content: (String|ByteArray) The response received from the server. Can be either - a string or a byte array (see #setBinaryMode)
  • - * - */ - this.getUrl = function(url, opt) { - if (typeof url == "string") { - if (!(url = helma.Http.evalUrl(url))) - throw new Error("'" + url + "' is not a valid URL."); - } else if (!(url instanceof java.net.URL)) { - throw new Error("'" + url + "' is not a valid URL."); - } - - var conn = proxy ? url.openConnection(proxy) : url.openConnection(); - // Note: we must call setInstanceFollowRedirects() instead of - // static method setFollowRedirects(), as the latter will - // set the default value for all url connections, and will not work for - // url connections that have already been created. - conn.setInstanceFollowRedirects(followRedirects); - conn.setAllowUserInteraction(false); - conn.setRequestMethod(method); - conn.setRequestProperty("User-Agent", userAgent); - - if (opt) { - if (opt instanceof Date) - conn.setIfModifiedSince(opt.getTime()); - else if ((typeof opt == "string") && (opt.length > 0)) - conn.setRequestProperty("If-None-Match", opt); - } - - var userinfo; - if (userinfo = url.getUserInfo()) { - userinfo = userinfo.split(/:/, 2); - this.setCredentials(userinfo[0], userinfo[1]); - } - if (credentials != null) { - conn.setRequestProperty("Authorization", "Basic " + credentials); - } - // set timeouts - if (parseFloat(java.lang.System.getProperty("java.specification.version"), 10) >= 1.5) { - conn.setConnectTimeout(timeout.connect); - conn.setReadTimeout(timeout.socket); - } - // set header fields - for (var i in headers) { - conn.setRequestProperty(i, headers[i]); - } - // set cookies - if (cookies != null) { - var arr = []; - for (var i in cookies) { - arr[arr.length] = cookies[i].getFieldValue(); - } - conn.setRequestProperty("Cookie", arr.join(";")); - } - // set content - if (content) { - conn.setRequestProperty("Content-Length", content.length); - conn.setDoOutput(true); - var out = new java.io.OutputStreamWriter(conn.getOutputStream()); - out.write(content); - out.flush(); - out.close(); - } - - var result = { - url: conn.getURL(), - location: conn.getHeaderField("location"), - code: conn.getResponseCode(), - message: conn.getResponseMessage(), - length: conn.getContentLength(), - type: conn.getContentType(), - encoding: conn.getContentEncoding(), - lastModified: null, - eTag: conn.getHeaderField("ETag"), - cookies: null, - headers: conn.getHeaderFields(), - content: null, - } - - // java.net.URLConnection does not follow redirects from http to https - // See https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4620571 - if (followRedirects && [301, 303].contains(result.code) && result.location) { - currentTries += 1; - if (currentTries >= maxTries) throw new Error('Too many redirects'); - return this.getUrl(result.location, opt); - } - - // parse all "Set-Cookie" header fields into an array of - // helma.Http.Cookie instances - var setCookies = conn.getHeaderFields().get("Set-Cookie"); - if (setCookies != null) { - var arr = []; - var cookie; - for (var i=0; i 0) { - result.cookies = arr; - } - } - - var lastmod = conn.getLastModified(); - if (lastmod) { - result.lastModified = new Date(lastmod); - } - - if (maxResponseSize && result.length > maxResponseSize) { - throw new Error("Maximum allowed response size is exceeded"); - } - - if (result.type && result.type.indexOf("charset=") != -1) { - var charset = result.type.substring(result.type.indexOf("charset=") + 8); - charset = charset.replace(/[;"]/g, '').trim(); - result.charset = charset; - } - - // invoke response handler - responseHandler(conn, result); - - conn.disconnect(); - return result; - } - - /** @ignore */ - this.toString = function() { - return "[Helma Http Client]"; - }; - - for (var i in this) - this.dontEnum(i); - - return this; -}; - - -/** - * Evaluates the url passed as argument. - * @param {String} url The url or uri string to evaluate - * @returns If the argument is a valid url, this method returns - * a new instance of java.net.URL, otherwise it returns null. - * @type java.net.URL - */ -helma.Http.evalUrl = function(url) { - try { - return new java.net.URL(url); - } catch (err) { - return null; - } -}; - - -/** - * Sets the global http proxy setting. If no proxy definition - * is passed to this method, any existing proxy setting is - * cleared. Internally this method sets the system properties - * http.proxySet, http.proxyHost and - * http.proxyPort. Keep in mind that this is valid for - * the whole Java Virtual Machine, therefor using this method - * can potentially influence other running Helma applications too! - * @param {String} proxyString A proxy definition in host:port - * format (eg. "proxy.example.com:3128"); - * @member helma.Http - */ -helma.Http.setProxy = function(proxyString) { - var sys = java.lang.System.getProperties(); - if (proxyString) { - var idx = proxyString.indexOf(":"); - var host = proxyString.substring(0, idx); - var port = proxyString.substring(idx+1); - if (!port) - port = "3128"; - else if (typeof port == "number") - port = port.toString(); - app.logger.info("helma.Http.setProxy " + proxyString); - sys.put("http.proxySet", "true"); - sys.put("http.proxyHost", host); - sys.put("http.proxyPort", port); - } else { - sys.put("http.proxySet", "false"); - sys.put("http.proxyHost", ""); - sys.put("http.prodyPort", ""); - } - return; - -}; - - -/** - * Returns the proxy setting of the Java Virtual Machine - * the Helma application server is running in. If no - * proxy is set, this method returns boolean false. - * @returns The global proxy setting in host:port - * format (eg. "proxy.example.com:3128"), or boolean false. - * @type String|Boolean - * @member helma.Http - */ -helma.Http.getProxy = function() { - var sys = java.lang.System.getProperties(); - if (sys.get("http.proxySet") == "true") - return sys.get("http.proxyHost") + ":" + sys.get("http.proxyPort"); - return false; -}; - - -/** - * Static helper method to check if a request issued agains a - * Helma application is authorized or not. - * @param {String} name The username to check req.username against - * @param {String} pwd The password to check req.password against - * @return True if the request is authorized, false otherwise. In - * the latter case the current response is reset and the response code - * is set to "401" ("Authentication required"). - * @type Boolean - */ -helma.Http.isAuthorized = function(name, pwd) { - if (!req.username || !req.password || - req.username != name || req.password != pwd) { - res.reset(); - res.status = 401; - res.realm = "Helma Http Authorization"; - res.write("Authorization required."); - return false; - } else { - return true; - } -}; - -/** @ignore */ -helma.Http.toString = function() { - return "[helma.Http]"; -}; - -/** - * Creates a new instance of helma.Http.Cookie - * @class Instances of this object represent a HTTP cookie - * @param {String} name The name of the cookie - * @param {String} value The value of the cookie - * @returns A newly created Cookie instance - * @constructor - */ -helma.Http.Cookie = function(name, value) { - /** - * The name of the Cookie - * @type String - */ - this.name = name; - - /** - * The value of the Cookie - * @type String - */ - this.value = value; - - /** - * An optional date defining the lifetime of this cookie - * @type Date - */ - this.expires = null; - - /** - * An optional path where this cookie is valid - * @type String - */ - this.path = null; - - /** - * An optional domain where this cookie is valid - * @type String - */ - this.domain = null; - - return this; -} - -/** - * An instance of java.text.SimpleDateFormat used for both parsing - * an "expires" string into a date and vice versa - * @type java.text.SimpleDateFormat - * @final - */ -helma.Http.Cookie.DATEFORMAT = new java.text.SimpleDateFormat("EEE, dd-MMM-yy HH:mm:ss z"); - - -/** - * A regular expression used for parsing cookie strings - * @type RegExp - * @final - */ -helma.Http.Cookie.PATTERN = /([^=;]+)=?([^;]*)(?:;\s*|$)/g; - - -/** - * Parses the cookie string passed as argument into an instance of helma.Http - * @param {String} cookieStr The cookie string as received from the remote server - * @returns An instance of helma.Http.Cookie containing the cookie parameters - * @type helma.Http.Cookie - */ -helma.Http.Cookie.parse = function(cookieStr) { - if (cookieStr != null) { - var cookie = new helma.Http.Cookie; - var m = helma.Http.Cookie.PATTERN.exec(cookieStr); - if (m) { - cookie.name = m[1].trim(); - cookie.value = m[2] ? m[2].trim() : ""; - } - while ((m = helma.Http.Cookie.PATTERN.exec(cookieStr)) != null) { - var key = m[1].trim(); - var value = m[2] ? m[2].trim() : ""; - switch (key.toLowerCase()) { - case "expires": - // try to parse the expires date string into a date object - try { - cookie.expires = helma.Http.Cookie.DATEFORMAT.parse(value); - } catch (e) { - // ignore - } - break; - default: - cookie[key.toLowerCase()] = value; - break; - } - } - return cookie; - } - return null; -}; - -/** - * Returns this cookie in a format useable to set the HTTP header field "Cookie" - * @return This cookie formatted as HTTP header field value - * @type String - */ -helma.Http.Cookie.prototype.getFieldValue = function() { - return this.name + "=" + this.value; -}; - -/** @ignore */ -helma.Http.Cookie.prototype.toString = function() { - return "[helma.Http.Cookie " + this.name + " " + this.value + "]"; -}; - -helma.lib = "Http"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -for (var i in helma[helma.lib].Cookie.prototype) - helma[helma.lib].Cookie.prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Image.js b/modules/helma/Image.js deleted file mode 100644 index 0d82691b..00000000 --- a/modules/helma/Image.js +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Image.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Methods of the helma.Image module. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Image.js') - */ - -if (!global.helma) { - global.helma = {}; -} - -/** - * Returns an Image object, generated from the specified source. - *

    - * If the JIMI package is installed, an instance of - * helma.image.jimi.JimiGenerator will be returned. Otherwise, - * if the javax.imageio package is available, an instance of - * helma.image.imageio.ImageIOGenerator is returned. - * Additionally, the class of the ImageGenerator implementation - * to be used can be set using the imageGenerator - * property in either the app.properties or server.properties - * file. - * - * - * @param {helma.File|java.io.File|String} arg image source, filename or url - * @return a new Image object - * @singleton - * @see Packages.helma.image.ImageGenerator - * @see Packages.helma.image.jimi.JimiGenerator - * @see Packages.helma.image.imageio.ImageIOGenerator - */ -helma.Image = function(arg) { - // according to - // http://grazia.helma.org/pipermail/helma-dev/2004-June/001253.html - var generator = Packages.helma.image.ImageGenerator.getInstance(); - return generator.createImage(arg); -} - -/** @ignore */ -helma.Image.toString = function() { - return "[helma.Image]"; -}; - - -/** - * Returns an ImageInfo object for the specified image file. - * - * @param {helma.File|java.io.File|String} arg image source, filename or url - * @returns an ImageInfo object - * @memberof helma.Image - * @see Packages.helma.image.ImageInfo - */ -helma.Image.getInfo = function(arg) { - if (arguments.length != 1) { - throw new java.lang.IllegalArgumentException( - "Image.getInfo() expects one argument" - ); - } - - var inp, result; - var info = new Packages.helma.image.ImageInfo(); - // FIXME: we need a byte array for class comparison - var b = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 0); - - try { - if (arg instanceof java.io.InputStream) { - inp = new java.io.InputStream(arg); - // FIXME: here comes a dirty hack to check for a byte array - } else if (arg.getClass && arg.getClass() == b.getClass()) { - inp = new java.io.ByteArrayInputStream(arg); - } else if (arg instanceof java.io.File) { - inp = new java.io.FileInputStream(arg); - } else if (arg instanceof helma.File) { - inp = new java.io.FileInputStream(arg.getFile()); - } else if (typeof arg == "string") { - var str = arg; - // try to interpret argument as URL if it contains a colon, - // otherwise or if URL is malformed interpret as file name. - if (str.indexOf(":") > -1) { - try { - var url = new java.net.URL(str); - inp = url.openStream(); - } catch (mux) { - inp = new java.io.FileInputStream(str); - } - } else { - inp = new java.io.FileInputStream(str); - } - } - if (inp == null) { - var msg = "Unrecognized argument in Image.getInfo(): "; - msg += (arg == null ? "null" : arg.getClass().toString()); - throw new java.lang.IllegalArgumentException(msg); - } - info.setInput(inp); - if (info.check()) { - result = info; - } - } catch (e) { - // do nothing, returns null later - } finally { - if (inp != null) { - try { - inp.close(); - } catch (e) {} - } - } - - return result; -}; - - -/** - * Writes a 1x1 pixel transparent spacer GIF image to the - * response buffer and sets the content type to image/gif. - * - * @memberof helma.Image - */ -helma.Image.spacer = function() { - res.contentType = "image/gif"; - res.writeBinary([71,73,70,56,57,97,2,0,2,0,-128,-1,0,-64,-64,-64,0,0,0,33,-7,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,64,2,2,68,1,0,59]); - return; -}; - -helma.lib = "Image"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; - - - diff --git a/modules/helma/Mail.js b/modules/helma/Mail.js deleted file mode 100644 index 5ea1a3b3..00000000 --- a/modules/helma/Mail.js +++ /dev/null @@ -1,705 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2007 Helma Software. All Rights Reserved. - * - * $RCSfile: Mail.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Fields and methods of the helma.Mail class. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Mail.js') - */ - -// take care of any dependencies -app.addRepository('modules/helma/File.js'); - -/** - * Define the global namespace if not existing - */ -if (!global.helma) { - global.helma = {}; -} - -/** - * Mail client enabling you to send e-mail via SMTP using Packages.javax.mail. - *

    - * @class This class provides functionality to sending - * Email messages. - * A mail client object is created by using the helma.Mail() - * constructor. The mail object then can be manipulated and sent - * using the methods listed below. - *

    - * You will either need to set your mail server via the smtp - * property in the app.properties or server.properties file - * or pass the hostname of the mail server you want to use as a - * parameter to the constructor. - *

    - * Note: Make sure that the SMTP server itself is well-configured, - * so that it accepts e-mails coming from your server and does - * not deny relaying. Best and fastest configuration is of course - * if you run your own SMTP server (e.g. postfix) which might be - * a bit tricky to set up, however.

    - * - * @param {String} smtp as String, the hostname of the mail server - * @constructor - */ -helma.Mail = function(host, port) { - // Error code values for this.status - var OK = 0; - var SUBJECT = 10; - var TEXT = 11; - var MIMEPART = 12; - var TO = 20; - var CC = 21; - var BCC = 22; - var FROM = 23; - var REPLYTO = 24; - var SETHEADER = 25; - var ADDHEADER = 26; - var GETHEADER = 27; - var REMOVEHEADER = 28; - var SEND = 30; - var MAILPKG = Packages.javax.mail; - - var self = this; - var errStr = "Error in helma.Mail"; - - var System = java.lang.System; - var Properties = java.util.Properties; - var IOException = java.io.IOException; - var Wrapper = Packages.org.mozilla.javascript.Wrapper; - var FileDataSource = Packages.javax.activation.FileDataSource; - var DataHandler = Packages.javax.activation.DataHandler; - - var MimePart = Packages.helma.util.MimePart; - var MimePartDataSource = Packages.helma.util.MimePartDataSource; - - var BodyPart = MAILPKG.BodyPart; - var Message = MAILPKG.Message; - var Session = MAILPKG.Session; - var InternetAddress = MAILPKG.internet.InternetAddress; - var AddressException = MAILPKG.internet.AddressException; - var MimeBodyPart = MAILPKG.internet.MimeBodyPart; - var MimeMessage = MAILPKG.internet.MimeMessage; - var MimeUtility = MAILPKG.internet.MimeUtility; - var MimeMultipart = MAILPKG.internet.MimeMultipart; - - var buffer, multipart, multipartType = "mixed"; - var username, password; - - var setStatus = function(status) { - if (self.status === OK) { - self.status = status; - } - return; - }; - - var getStatus = function() { - return self.status; - }; - - var addRecipient = function(addstr, name, type) { - if (addstr.indexOf("@") < 0) { - throw new AddressException(); - } - if (name != null) { - var address = new InternetAddress(addstr, - MimeUtility.encodeWord(name.toString())); - } else { - var address = new InternetAddress(addstr); - } - message.addRecipient(type, address); - return; - }; - - /** - * Adds the content stored in this helma.Mail instance - * to the wrapped message. - * @private - */ - var setContent = function() { - if (buffer != null) { - if (multipart != null) { - var part = new MimeBodyPart(); - part.setContent(buffer.toString(), "text/plain"); - multipart.addBodyPart(part, 0); - message.setContent(multipart); - } else { - message.setText(buffer.toString()); - } - } else if (multipart != null) { - message.setContent(multipart); - } else { - message.setText(""); - } - return; - }; - - /** - * Returns the text buffer of this mail message - * @returns The text buffer of this mail message - * @type java.lang.StringBuffer - * @private - */ - this.getBuffer = function() { - return buffer; - }; - - /** - * Returns the mime multipart object of this mail message - * @returns The mime multipart object of this mail message - * @type javax.mail.internet.MimeMultipart - * @private - */ - this.getMultipart = function() { - return multipart; - }; - - /** - * Sets username and password to use for SMTP authentication. - * @param {String} uname The username to use - * @param {String} pwd The password to use - */ - this.setAuthentication = function(uname, pwd) { - if (uname && pwd) { - username = uname; - password = pwd; - // enable smtp authentication - props.put("mail.smtp.auth", "true"); - } - return; - } - - /** - * Returns the wrapped message - * @returns The wrapped message - * @type javax.mail.internet.MimeMessage - */ - this.getMessage = function() { - return message; - }; - - /** - * Switches debug mode on or off. - * @param {Boolean} debug If true debug mode is enabled - */ - this.setDebug = function(debug) { - session.setDebug(debug === true); - }; - - /** - * The status of this Mail object. This equals 0 unless - * an error occurred. See {@link helma.Mail Mail.js} source code for a list of - * possible error codes. - */ - this.status = OK; - - /** - * Sets the sender of an e-mail message. - *

    - * The first argument specifies the receipient's - * e-mail address. The optional second argument - * specifies the name of the recipient. - * - * @param {String} addstr as String, sender email address - * @param {String} name as String, optional sender name - */ - this.setFrom = function(addstr, name) { - try { - if (addstr.indexOf("@") < 0) { - throw new AddressException(); - } - if (name != null) { - var address = new InternetAddress(addstr, - MimeUtility.encodeWord(name.toString())); - } else { - var address = new InternetAddress(addstr); - } - message.setFrom(address); - } catch (mx) { - app.logger.error(errStr + ".setFrom(): " + mx); - setStatus(FROM); - } - return; - }; - - /** - * Set a header in the e-mail message. If the given header is already set the previous - * value is replaced with the new one. - * @param name a header name - * @param value the header value - */ - this.setHeader = function(name, value) { - try { - message.addHeader(name, MimeUtility.encodeText(value)); - } catch (mx) { - app.logger.error(errStr + ".setHeader(): " + mx); - setStatus(SETHEADER); - } - return; - } - - /** - * Set a header in the e-mail message. If the given header is already set the previous - * value is replaced with the new one. - * @param name a header name - * @param value the header value - */ - this.addHeader = function(name, value) { - try { - message.addHeader(name, MimeUtility.encodeText(value)); - } catch (mx) { - app.logger.error(errStr + ".addHeader(): " + mx); - setStatus(ADDHEADER); - } - return; - } - - /** - * Get all the headers for this header name. - * Returns null if no headers for this header name are available. - * @param name a header name - * @return {String[]} a string array of header values, or null - */ - this.getHeader = function(name) { - var value = null; - try { - value = message.getHeader(name); - if (value && value.length) { - for (var i = 0; i < value.length; i++) { - value[i] = MimeUtility.decodeText(value[i]); - } - } - } catch (mx) { - app.logger.error(errStr + ".getHeader(): " + mx); - setStatus(GETHEADER); - } - return value; - } - - /** - * Remove all headers with this name. - * @param name the header name - */ - this.removeHeader = function(name) { - try { - message.removeHeader(name); - } catch (mx) { - app.logger.error(errStr + ".removeHeader(): " + mx); - setStatus(REMOVEHEADER); - } - return; - } - - /** - * Sets the Reply-To address of an e-mail message. - * - * @param {String} addstr as String, the reply-to email address - */ - this.setReplyTo = function(addstr) { - try { - if (addstr.indexOf("@") < 0) { - throw new AddressException(); - } - var address = [new InternetAddress(addstr)]; - message.setReplyTo(address); - } catch (mx) { - app.logger.error(errStr + ".setReplyTo(): " + mx); - setStatus(REPLYTO); - } - return; - } - - /** - * Sets the recipient of an e-mail message. - *   - * The first argument specifies the receipient's - * e-mail address. The optional second argument - * specifies the name of the recipient. - * - * @param {String} addstr as String, receipients email address - * @param {String} name as String, optional receipients name - * @see #addTo - */ - this.setTo = function(addstr, name) { - try { - addRecipient(addstr, name, Message.RecipientType.TO); - } catch (mx) { - app.logger.error(errStr + ".setTo(): " + mx); - setStatus(TO); - } - return; - }; - - /** - * Adds a recipient to the address list of an e-mail message. - *

    - * The first argument specifies the receipient's - * e-mail address. The optional second argument - * specifies the name of the recipient. - * - * @param {String} addstr as String, receipients email address - * @param {String} name as String, optional receipients name - * @see setTo - */ - this.addTo = function(addstr, name) { - try { - addRecipient(addstr, name, Message.RecipientType.TO); - } catch (mx) { - app.logger.error(errStr + ".addTo(): " + mx); - setStatus(TO); - } - return; - } - - /** - * Adds a recipient to the list of addresses to get a "carbon copy" - * of an e-mail message. - *

    - * The first argument specifies the receipient's - * e-mail address. The optional second argument - * specifies the name of the recipient. - * - * @param {String} addstr as String, receipients email address - * @param {String} name as String, optional receipients name - */ - this.addCC = function(addstr, name) { - try { - addRecipient(addstr, name, Message.RecipientType.CC); - } catch (mx) { - app.logger.error(errStr + ".addCC(): " + mx); - setStatus(CC); - } - return; - } - - /** - * Adds a recipient to the list of addresses to get a "blind carbon copy" of an e-mail message. - *

    - * The first argument specifies the receipient's - * e-mail address. The optional second argument - * specifies the name of the recipient. - * - * @param {String} addstr as String, receipients email address - * @param {String} name as String, optional receipients name - */ - this.addBCC = function(addstr, name) { - try { - addRecipient(addstr, name, Message.RecipientType.BCC); - } catch (mx) { - app.logger.error(errStr + ".addBCC(): " + mx); - setStatus(BCC); - } - return; - } - - /** - * Sets the subject of an e-mail message. - * - * @param {String} subject as String, the email subject - */ - this.setSubject = function(subject) { - if (!subject) { - return; - } - try { - message.setSubject(MimeUtility.encodeWord(subject.toString())); - } catch (mx) { - app.logger.error(errStr + ".setSubject(): " + mx); - setStatus(SUBJECT); - } - return; - }; - - /** - * Sets the body text of an e-mail message. - * - * @param {String} text as String, to be appended to the message body - * @see #addText - */ - this.setText = function(text) { - if (text) { - buffer = new java.lang.StringBuffer(text); - } - return; - }; - - /** - * Appends a string to the body text of an e-mail message. - * - * @param {String} text as String, to be appended to the message body - * @see #setText - */ - this.addText = function(text) { - if (buffer == null) { - buffer = new java.lang.StringBuffer(text); - } else { - buffer.append(text); - } - return; - }; - - /** - * Sets the MIME multiparte message subtype. The default value is - * "mixed" for messages of type multipart/mixed. A common value - * is "alternative" for the multipart/alternative MIME type. - * @param {String} messageType the MIME subtype such as "mixed" or "alternative". - * @see #getMultipartType - * @see #addPart - */ - this.setMultipartType = function(messageType) { - multipartType = messageType; - return; - }; - - /** - * Returns the MIME multiparte message subtype. The default value is - * "mixed" for messages of type multipart/mixed. - * @return the MIME subtype - * @type String - * @see #setMultipartType - * @see #addPart - */ - this.getMultipartType = function(messageType) { - return multipartType; - }; - - /** - * Adds an attachment to an e-mail message. - *

    - * The attachment needs to be either a helma.util.MimePart Object retrieved - * through the global getURL function, or a {@link helma.File} object, or a String. - *

    - * Use the getURL() function to retrieve a MIME object or wrap a - * helma.File object around a file of the local file system. - * - * @param {fileOrMimeObjectOrString} obj File, Mime object or String to attach to the email - * @param {String} filename optional name of the attachment - * @param {String} contentType optional content type (only if first argument is a string) - * @see global.getURL - * @see helma.util.MimePart - * @see helma.File - */ - this.addPart = function(obj, filename, contentType) { - try { - if (obj == null) { - throw new IOException( - errStr + ".addPart: method called with wrong number of arguments." - ); - } - if (multipart == null) { - multipart = new MimeMultipart(multipartType); - } - if (obj instanceof Wrapper) { - obj = obj.unwrap(); - } - - var part; - if (obj instanceof BodyPart) { - // we already got a body part, no need to convert it - part = obj; - } else { - part = new MimeBodyPart(); - if (typeof obj == "string") { - part.setContent(obj.toString(), contentType || "text/plain"); - } else if (obj instanceof File || obj instanceof helma.File) { - var source = new FileDataSource(obj.getPath()); - part.setDataHandler(new DataHandler(source)); - } else if (obj instanceof MimePart) { - var source = new MimePartDataSource(obj); - part.setDataHandler(new DataHandler(source)); - } - } - if (filename != null) { - try { - part.setFileName(filename.toString()); - } catch (x) {} - } else if (obj instanceof File || obj instanceof helma.File) { - try { - part.setFileName(obj.getName()); - } catch (x) {} - } - multipart.addBodyPart(part); - } catch (mx) { - app.logger.error(errStr + ".addPart(): " + mx); - setStatus(MIMEPART); - } - return; - }; - - /** - * Saves this mail RFC 822 formatted into a file. The name of the - * file is prefixed with "helma.Mail" followed by the current time - * in milliseconds and a random number. - * @param {helma.File} dir An optional directory where to save - * this mail to. If omitted the mail will be saved in the system's - * temp directory. - */ - this.writeToFile = function(dir) { - if (!dir || !dir.exists() || !dir.canWrite()) { - dir = new java.io.File(System.getProperty("java.io.tmpdir")); - } - var fileName = "helma.Mail." + (new Date()).getTime() + - "." + Math.round(Math.random() * 1000000); - var file = new java.io.File(dir, fileName); - if (file.exists()) { - file["delete"](); - } - try { - setContent(); - var fos = new java.io.FileOutputStream(file); - var os = new java.io.BufferedOutputStream(fos); - message.writeTo(os); - os.close(); - app.logger.info("helma.Mail.saveTo(): saved mail to " + - file.getAbsolutePath()); - } catch (e) { - app.logger.error(errStr + ".saveTo(): " + e); - } - return; - }; - - /** - * Returns the source of this mail as RFC 822 formatted string. - * @returns The source of this mail as RFC 822 formatted string - * @type String - */ - this.getSource = function() { - try { - setContent(); - var buf = new java.io.ByteArrayOutputStream(); - var os = new java.io.BufferedOutputStream(buf); - message.writeTo(os); - os.close(); - return buf.toString(); - } catch (e) { - app.logger.error(errStr + ".getSource(): " + e); - } - return null; - }; - - /** - * Sends an e-mail message. - *

    - * This function sends the message using the SMTP - * server as specified when the Mail object was - * constructed using helma.Mail. - *

    - * If no smtp hostname was specified when the Mail - * object was constructed, the smtp property in either - * the app.properties or server.properties file needs - * to be set in order for this to work. - *

    - * As a fallback, the message will then be written to - * file using the {@link #writeToFile} method. - * Additionally, the location of the message files can - * be determined by setting smtp.dir in app.properties - * to the desired file path. - */ - this.send = function() { - if (this.status > OK) { - app.logger.error(errStr + ".send(): Status is " + this.status); - return; - } - if (host != null) { - try { - setContent(); - message.setSentDate(new Date()); - var transport = session.getTransport("smtp"); - if (username && password) { - transport.connect(host, username, password); - } else { - transport.connect(); - } - message.saveChanges(); - transport.sendMessage(message, message.getAllRecipients()); - } catch (mx) { - app.logger.error(errStr + ".send(): " + mx); - setStatus(SEND); - } finally { - if (transport != null && transport.isConnected()) { - transport.close(); - } - } - } else { - // no smtp host is given, so write the mail to a file - this.writeToFile(getProperty("smtp.dir")); - } - return; - }; - - /** - * Main constructor body - */ - var props = new Properties(); - if (host || (host = getProperty("smtp"))) { - props.put("mail.transport.protocol", "smtp"); - props.put("mail.smtp.host", String(host)); - props.put("mail.smtp.port", String(port || 25)); - props.put("mail.smtp.starttls.enable", - getProperty("smtp.tls") || "false"); - props.put("mail.mime.charset", - getProperty("smtp.charset") || - System.getProperty("mail.charset") || - "ISO-8859-15"); - } - - this.setAuthentication(getProperty("smtp.username"), - getProperty("smtp.password")); - var session = Session.getInstance(props); - var message = new MimeMessage(session); - - for (var i in this) - this.dontEnum(i); - - return this; -} - - -/** @ignore */ -helma.Mail.toString = function() { - return "[helma.Mail]"; -}; - - -/** @ignore */ -helma.Mail.prototype.toString = function() { - return "[helma.Mail Object]"; -}; - -helma.Mail.example = function(host, sender, addr, subject, text) { - // var smtp = "smtp.host.dom"; - // var sender = "sender@host.dom"; - // var addr = "recipient@host.dom"; - // var subject = "Hello, World!"; - // var text = "This is a test."; - var port = 25; - var msg = new helma.Mail(host, port); - msg.setFrom(sender); - msg.addTo(addr); - msg.setSubject(subject); - msg.setText(text); - msg.send(); - res.write(msg.status); - return; -}; - - -helma.lib = "Mail"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Search.js b/modules/helma/Search.js deleted file mode 100644 index c4b97dd1..00000000 --- a/modules/helma/Search.js +++ /dev/null @@ -1,1458 +0,0 @@ -// -// A wrapper for Apache Lucene for use with Helma Object Publisher -// Copyright (c) 2005-2006 Robert Gaggl -// -// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// -// -// $Revision$ -// $Author$ -// $Date$ -// - - -/** - * @fileoverview Fields and methods of the helma.Search class - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Search.js') - */ - -// take care of any dependencies -app.addRepository('modules/helma/lucene-core-2.2.0.jar'); -app.addRepository('modules/helma/lucene-analyzers-2.2.0.jar'); - - -if (!global.helma) { - global.helma = {}; -} - -/** - * Constructs a new instance of helma.Search. This merely - * checks if the Apache Lucene library is in the application - * classpath. - * @class This class provides functionality for - * creating a fulltext search index based on Apache Lucene. - * @returns A newly created instance of this prototype. - * @constructor - * @author Robert Gaggl - */ -helma.Search = function() { - try { - var c = java.lang.Class.forName("org.apache.lucene.analysis.Analyzer", - true, app.getClassLoader()); - var pkg = Packages.org.apache.lucene.LucenePackage.get(); - var version = parseFloat(pkg.getSpecificationVersion()); - if (version < 2.2) { - throw "Incompatible version"; - } - } catch (e) { - throw "helma.Search needs lucene.jar in version >= 2.2 \ - in lib/ext or application directory \ - [http://lucene.apache.org/]"; - } - return this; -}; - - -/*************************************** - ***** S T A T I C M E T H O D S ***** - ***************************************/ - -/** @ignore */ -helma.Search.toString = function() { - return "[helma.Search]"; -}; - -/** - * Returns a new Analyzer instance depending on the key - * passed as argument. Currently supported arguments are - * "br" (BrazilianAnalyzer), "cn" (ChineseAnalyzer), "cz" (CzechAnalyzer), - * "nl" (DutchAnalyzer), "fr" (FrenchAnalyzer), "de" (GermanAnalyzer), - * "el" (GreekAnalyzer), "keyword" (KeywordAnalyzer), "ru" (RussianAnalyzer), - * "simple" (SimpleAnalyzer), "snowball" (SnowballAnalyzer), "stop" (StopAnalyzer) - * "whitespace" (WhitespaceAnalyzer). If no argument is given, a StandardAnalyzer - * is returned. - * @param {String} key The key identifying the analyzer - * @returns A newly created Analyzer instance - * @type {org.apache.lucene.analysis.Analyzer} - */ -helma.Search.getAnalyzer = function(key) { - var pkg = Packages.org.apache.lucene; - switch (key) { - case "br": - return new pkg.analysis.br.BrazilianAnalyzer(); - case "cn": - return new pkg.analysis.cn.ChineseAnalyzer(); - case "cz": - return new pkg.analysis.cz.CzechAnalyzer(); - case "nl": - return new pkg.analysis.nl.DutchAnalyzer(); - case "fr": - return new pkg.analysis.fr.FrenchAnalyzer(); - case "de": - return new pkg.analysis.de.GermanAnalyzer(); - case "el": - return new pkg.analysis.el.GreekAnalyzer(); - case "keyword": - return new pkg.analysis.KeywordAnalyzer(); - case "ru": - return new pkg.analysis.ru.RussianAnalyzer(); - case "simple": - return new pkg.analysis.SimpleAnalyzer(); - case "snowball": - return new pkg.analysis.snowball.SnowballAnalyzer(); - case "stop": - return new pkg.analysis.StopAnalyzer(); - case "whitespace": - return new pkg.analysis.WhitespaceAnalyzer(); - default: - return new pkg.analysis.standard.StandardAnalyzer(); - } -}; - -/** - * Constructs a new QueryFilter instance. This class - * wraps a lucene QueryFilter. - * @param {helma.Search.Query} q The query object to use as - * the basis for the QueryFilter instance. - * @returns A newly created QueryFilter instance. - * @constructor - */ -helma.Search.QueryFilter = function(q) { - var filter = new Packages.org.apache.lucene.search.QueryFilter(q.getQuery()); - - /** - * Returns the wrapped filter instance - * @type org.apache.lucene.search.QueryFilter - */ - this.getFilter = function() { - return filter; - }; - - return this; -}; - -/** @ignore */ -helma.Search.QueryFilter.prototype.toString = function() { - return this.getFilter().toString(); -}; - - - -/********************************************* - ***** P R O T O T Y P E M E T H O D S ***** - *********************************************/ - - -/** @ignore */ -helma.Search.prototype.toString = function() { - return helma.Search.toString(); -}; - -/** - * Returns an instance of org.apache.lucene.store.FSDirectory. If - * no index is present in the given directory, it is created on the fly. - * @param {File|helma.File|java.io.File|String} dir The directory - * where the index is located or should be created at. - * @param {Boolean} create If true the index will be created, removing - * any existing index in the same directory - * @returns The index directory. - * @type org.apache.lucene.store.FSDirectory - */ -helma.Search.prototype.getDirectory = function(dir, create) { - if (!dir) { - throw "helma.Search.getDirectory(): insufficient arguments."; - } - var d; - if (dir.constructor == String) { - d = new java.io.File(dir); - } else if (dir.constructor == File || dir.constructor == helma.File) { - d = new java.io.File(dir.getAbsolutePath()); - } else if (!((d = dir) instanceof java.io.File)) { - throw "helma.Search.getDirectory(): " + dir + " is not a valid argument."; - } - return Packages.org.apache.lucene.store.FSDirectory.getDirectory(d, - create === true || !d.exists()); -}; - -/** - * Returns a RAM directory object. - * @param {File|helma.File|java.io.File|String} dir Optional directory - * containing a Lucene index from which this RAM directory should be created. - * @returns A RAM directory instance. - * @type org.apache.lucene.store.RAMDirectory - */ -helma.Search.prototype.getRAMDirectory = function(dir) { - if (dir != null) { - var d; - if (dir.constructor == String) { - d = new java.io.File(dir); - } else if (dir.constructor == File || dir.constructor == helma.File) { - d = new java.io.File(dir.getAbsolutePath()); - } else if (!((d = dir) instanceof java.io.File)) { - throw "helma.Search.getRAMDirectory(): " + dir + " is not a valid argument."; - } - if (!d.exists()) { - throw "helma.Search.getRAMDirectory(): " + dir + " does not exist."; - } - return Packages.org.apache.lucene.store.RAMDirectory(d); - } - return Packages.org.apache.lucene.store.RAMDirectory(); -}; - -/** - * Creates a new Lucene index in the directory passed as - * argument, using an optional analyzer, and returns an instance - * of helma.Search.Index. Any already existing index in this - * directory will be preserved. - * @param {org.apache.lucene.store.Directory} dir The directory - * where the index should be stored. This can be either a - * FSDirectory or a RAMDirectory instance. - * @param {org.apache.lucene.analysis.Analyzer} analyzer The analyzer to - * use for the index. If not specified a StandardAnalyzer will be used. - * @returns The index instance. - * @type helma.Search.Index - */ -helma.Search.prototype.createIndex = function(dir, analyzer) { - if (!dir || !(dir instanceof Packages.org.apache.lucene.store.Directory)) { - throw "Index directory missing or invalid."; - } else if (!analyzer) { - // no analyzer given, use a StandardAnalyzer - analyzer = helma.Search.getAnalyzer(); - } - var index = new helma.Search.Index(dir, analyzer); - if (!Packages.org.apache.lucene.index.IndexReader.indexExists(dir)) { - index.create(); - } - return index; -}; - - -/********************* - ***** I N D E X ***** - *********************/ - - -/** - * Creates a new instance of helma.Search.Index - * @class Instances of this class represent a Lucene search index - * located in either a directory on disk or in RAM. This class - * provides various methods for modifying the underlying Lucene index. - * @param {org.apache.lucene.store.Directory} directory The directory - * where the Lucene index is located at. - * @param {org.apache.lucene.analysis.Analyzer} analyzer The analyzer - * to use when modifying the index. - * @constructor - */ -helma.Search.Index = function(directory, analyzer) { - - /** - * Returns an IndexWriter instance that can be used to add documents to - * the underlying index or to perform various other modifying operations. - * If the index is currently locked this method will try for the next - * two seconds to create the IndexWriter, otherwise it will - * throw an error. - * @param {Boolean} create True to create the index (overwriting an - * existing index), false to append to an existing index. Defaults to false - * @param {Boolean} autoCommit Enables or disables auto commit (defaults to - * false) - * @returns An IndexWriter instance. - * @type org.apache.lucene.index.IndexWriter - */ - this.getWriter = function(create, autoCommit) { - try { - return new Packages.org.apache.lucene.index.IndexWriter(directory, - (autoCommit === true), analyzer, (create === true)); - } catch (e) { - throw "Failed to get IndexWriter due to active lock (Thread " - + java.lang.Thread.currentThread().getId() + ")"; - } - }; - - /** - * Returns an IndexReader instance. Due to locking issues an - * IndexModifier should be used for deleting documents. - * @returns An IndexReader instance - * @type org.apache.lucene.index.IndexReader - */ - this.getReader = function() { - return Packages.org.apache.lucene.index.IndexReader.open(directory); - }; - - /** - * Returns the directory the underlying Lucene index is located at. - * @returns The directory of this index - * @type org.apache.lucene.store.Directory - */ - this.getDirectory = function() { - return directory; - }; - - /** - * Returns the analyzer used within this index. - * @returns The analyzer used within this index. - * @type org.apache.lucene.analysis.Analyer - */ - this.getAnalyzer = function() { - return analyzer; - }; - - /** - * Returns a searcher for querying this index. - * @returns A searcher useable for querying the index. - * @type helma.Search.Searcher - */ - this.getSearcher = function() { - return new helma.Search.Searcher(this); - }; - - /** @ignore */ - this.toString = function() { - return ("[Lucene Index " + directory + "]"); - }; - - return this; -}; - -/** - * Merges the indexes passed as argument into this one. - * @param {org.apache.lucene.store.Directory} dir At least one - * index director to add to this index. - */ -helma.Search.Index.prototype.addIndexes = function(dir /* [, dir[, dir...] */) { - var dirs = java.lang.reflect.Array.newInstance( - Packages.org.apache.lucene.store.Directory, - arguments.length); - for (var i=0;i 0) { - var arr = java.lang.reflect.Array.newInstance(pkg.SortField, this.sortFields.size()); - var sort = pkg.Sort(this.sortFields.toArray(arr)); - if (filter) { - hits = searcher.search(query, filter, sort); - } else { - hits = searcher.search(query, sort); - } - } else if (filter) { - hits = searcher.search(query, filter); - } else { - hits = searcher.search(query); - } - this.hits = new helma.Search.HitCollection(hits); - return this.hits.length(); -}; - -/** - * Sets a field as result sorting field. This method can be called - * with a different number of arguments: - * sortBy(fieldName) - * sortBy(fieldName, type) - * sortBy(fieldName, reverse) - * sortBy(fieldName, type, reverse) - * @param {String} fieldName The name of the field in the index by which - * the search result should be ordered. - * @param {String} type The type of the field defined by argument fieldName. - * Valid arguments are "string", "float", "int", "score", "doc", "auto", "custom". - * Default is "auto". See http://lucene.apache.org/java/docs/api/org/apache/lucene/search/SortField.html - * for an explanation. - */ -helma.Search.Searcher.prototype.sortBy = function(fieldName /** type, reverse */) { - var pkg = Packages.org.apache.lucene.search; - if (!this.sortFields) - this.sortFields = new java.util.Vector(); - var f = fieldName; - var t = pkg.SortField.AUTO; - var r = false; - if (arguments.length == 3) { - t = pkg.SortField[arguments[1].toUpperCase()]; - r = arguments[2]; - } else if (arguments.length == 2) { - if (arguments[1].constructor == Boolean) { - r = arguments[1]; - } else { - t = pkg.SortField[arguments[1].toUpperCase()]; - } - } - this.sortFields.add(new pkg.SortField(f, t, r)); - return; -}; - -/** - * Closes the wrapped IndexSearcher instance. - */ -helma.Search.Searcher.prototype.close = function() { - var s = this.getSearcher(); - if (s != null) { - s.close(); - } - return; -}; - -/** - * Creates a new instance of helma.Search.HitCollection - * @class This class provides Helma-like methods for accessing - * a collection of search hits. - * @param {org.lucene.search.Hits} hits The hit collection returned - * by lucene. - * @constructor - */ -helma.Search.HitCollection = function(hits) { - /** - * Silently converts the hit at the given index position into - * an instance of helma.Search.Document. - * @param {Number} idx The index position of the hit - * @returns The document object at the given index position - * @type helma.Search.Document - */ - this.get = function(idx) { - var doc = new helma.Search.Document(hits.doc(idx)); - doc.id = hits.id(idx); - doc.score = hits.score(idx); - doc.rank = idx +1; - return doc; - }; - - /** - * Returns the number of hits in this collection. - * @returns The number of hits. - * @type Number - */ - this.size = function() { - return (hits != null) ? hits.length() : 0; - }; - - /** - * Returns the number of hits in this collection. - * This method is deprecated, use {@link #size} instead. - * @returns The number of hits. - * @type Number - * @deprecated - * @see #size - */ - this.length = function() { - return this.size(); - }; - - /** - * Executes a provided function once per hit. - * @param {Function} fun Function to execute for each element - * @param {Object} context Object to use as "this" when executing callback. - * @see https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array/ForEach - */ - this.forEach = function(func, context) { - if (typeof func != "function") { - throw new TypeError(); - } - var len = this.size(); - for (var i = 0; i < len; i += 1) { - var hit = this.get(i); - if (hit) { - func.call(context, hit, i, hits); - } - } - return; - }; - - return this; -}; - -/** @ignore */ -helma.Search.HitCollection.prototype.toString = function() { - return "[HitCollection]"; -}; - -/*********************************************** - ***** Q U E R Y C O N S T R U C T O R S ***** - ***********************************************/ - -/** - * Creates a new instance of helma.Search.Query - * @class Base class for the various query constructors. Don't - * call this directly, as it provides just basic methods used - * in all of its extends. - * @constructor - */ -helma.Search.Query = function() { - /** - * The wrapped query instance - * @type org.apache.lucene.search.Query - * @private - */ - this.query = null; - - return this; -}; - -/** - * Returns the wrapped Lucene Query object. - * @returns The wrapped query object - * @type org.apache.lucene.search.Query - */ -helma.Search.Query.prototype.getQuery = function() { - return this.query; -}; - -/** @ignore */ -helma.Search.Query.prototype.toString = function(field) { - return "[" + this.getQuery().toString(field) + "]"; -}; - -/** - * Returns the boost factor of this query. - * @type Number - */ -helma.Search.Query.prototype.getBoost = function() { - return this.getQuery().getBoost(); -}; - -/** - * Sets the boost factor of this query clause to - * the given number. Documents matching this query - * will have their score multiplied with the given - * factor - * @param {Number} fact The factor to multiply the score - * of matching documents with. - */ -helma.Search.Query.prototype.setBoost = function(fact) { - this.getQuery().setBoost(fact); - return; -}; - -/** - * Creates a new instance of helma.Search.TermQuery - * @class This class represents a simple Term Query. - * @param {String} field The name of the field - * @param {String} str The value of the field - * @constructor - * @extends helma.Search.Query - */ -helma.Search.TermQuery = function(field, str) { - var t = new Packages.org.apache.lucene.index.Term(field, str); - /** - * Contains the wrapped TermQuery instance - * @type org.apache.lucene.search.TermQuery - */ - this.query = new Packages.org.apache.lucene.search.TermQuery(t); - return this; -}; -helma.Search.TermQuery.prototype = new helma.Search.Query; - -/** - * Creates a new instance of helma.Search.BooleanQuery - * @class This class represents a Boolean Query, providing - * various methods for combining other Query instances using boolean operators. - * @param String name of the field - * @param String query string - * @returns Object BooleanQuery object - * @constructor - * @extends helma.Search.Query - */ -helma.Search.BooleanQuery = function(field, str, clause, analyzer) { - /** - * Contains the wrapped BooleanQuery instance - * @type org.apache.lucene.search.BooleanQuery - */ - this.query = new Packages.org.apache.lucene.search.BooleanQuery(); - - /** - * Main constructor body - */ - if (field && str) { - this.addTerm.apply(this, arguments); - } - - return this; -}; -helma.Search.BooleanQuery.prototype = new helma.Search.Query; - -/** - * Adds a term to the wrapped query object. This method can be called - * with two, three or four arguments, eg.: - *
    addTerm("fieldname", "querystring")
    - * addTerm("fieldname", "querystring", "and")
    - * addTerm("fieldname", "querystring", helma.Search.getAnalyzer("de"))
    - * addTerm("fieldname", "querystring", "not", helma.Search.getAnalyzer("simple"))
    - * @param {String|Array} field Either a String or an Array containing Strings - * that determine the index field(s) to match - * @param {String} str Query string to match - * @param {String} clause Boolean clause ("or", "not" or "and", default is "and") - * @param {org.apache.lucene.analysis.Analyzer} analyzer An analyzer to use - */ -helma.Search.BooleanQuery.prototype.addTerm = function(field, str, clause, analyzer) { - var pkg = Packages.org.apache.lucene; - if (arguments.length == 3 && arguments[2] instanceof pkg.analysis.Analyzer) { - analyzer = arguments[2]; - clause = "or"; - } - if (!analyzer) { - analyzer = helma.Search.getAnalyzer(); - } - - var fields = (field instanceof Array) ? field : [field]; - var parser = new pkg.queryParser.MultiFieldQueryParser(fields, analyzer); - this.addQuery(parser.parse(str), clause); - return; -}; - -/** - * Adds an additional query clause to this query. - * @param {helma.Search.Query} q The query to add - * @param {String} clause Boolean clause ("or", "not", or "and", default is "and") - */ -helma.Search.BooleanQuery.prototype.addQuery = function(q, clause) { - var pkg = Packages.org.apache.lucene; - var booleanClause; - if (q instanceof helma.Search.Query) { - q = q.getQuery(); - } - switch (clause) { - case "and": - booleanClause = pkg.search.BooleanClause.Occur.MUST; - break; - case "not": - booleanClause = pkg.search.BooleanClause.Occur.MUST_NOT; - break; - default: - booleanClause = pkg.search.BooleanClause.Occur.SHOULD; - break; - } - this.getQuery().add(q, booleanClause); - return; -}; - -/** - * Constructs a new helma.Search.PhraseQuery instance that wraps - * a Lucene Phrase Query object. - * @class Instances of this class represent a phrase query. - * @param {String} field The name of the field - * @param {String} str The phrase query string - * @returns A newly created PhraseQuery instance - * @constructor - * @extends helma.Search.Query - */ -helma.Search.PhraseQuery = function(field, str) { - /** - * Contains the wrapped PhraseQuery instance - * @type org.apache.lucene.search.PhraseQuery - */ - this.query = new Packages.org.apache.lucene.search.PhraseQuery(); - - /** - * add a term to the end of the phrase query - */ - this.addTerm = function(field, str) { - var t = new Packages.org.apache.lucene.index.Term(field, str); - this.query.add(t); - return; - }; - - if (field && str) - this.addTerm(field, str); - delete this.base; - return this; -}; -helma.Search.PhraseQuery.prototype = new helma.Search.Query; - -/** - * Constructs a new helma.Search.RangeQuery instance. - * @class Instances of this class represent a range - * query, wrapping a Lucene RangeQuery instance. - * @param {String} field The name of the field - * @param {String} from The minimum value to match (can be null) - * @param {String} to The maximum value to match (can be null) - * @param {Boolean} inclusive If true the given min/max values are included - * @returns A newly created RangeQuery instance - * @constructor - * @extends helma.Search.Query - */ -helma.Search.RangeQuery = function(field, from, to, inclusive) { - if (!field) - throw "Missing field name in RangeQuery()"; - if (arguments.length < 4) - inclusive = true; - var t1 = from ? new Packages.org.apache.lucene.index.Term(field, from) : null; - var t2 = to ? new Packages.org.apache.lucene.index.Term(field, to) : null; - /** - * Contains the wrapped RangeQuery instance - * @type org.apache.lucene.search.RangeQuery - */ - this.query = new Packages.org.apache.lucene.search.RangeQuery(t1, t2, inclusive); - return this; -}; -helma.Search.RangeQuery.prototype = new helma.Search.Query; - -/** - * Constructs a new helma.Search.FuzzyQuery instance. - * @class Instances of this class represent a fuzzy query - * @param {String} field The name of the field - * @param {String} str The query string to match - * @returns A newly created FuzzyQuery instance - * @constructor - * @extends helma.Search.Query - */ -helma.Search.FuzzyQuery = function(field, str) { - var t = new Packages.org.apache.lucene.index.Term(field, str); - /** - * Contains the wrapped FuzzyQuery instance - * @type org.apache.lucene.search.FuzzyQuery - */ - this.query = new Packages.org.apache.lucene.search.FuzzyQuery(t); - return this; -}; -helma.Search.FuzzyQuery.prototype = new helma.Search.Query; - -/** - * Constructs a new helma.Search.PrefixQuery instance. - * @class Instances of this class represent a prefix query - * @param {String} field The name of the field - * @param {String} str The query string to match - * @returns A newly created PrefixQuery instance - * @constructor - * @extends helma.Search.Query - */ -helma.Search.PrefixQuery = function(field, str) { - var t = new Packages.org.apache.lucene.index.Term(field, str); - /** - * Contains the wrapped PrefixQuery instance - * @type org.apache.lucene.search.PrefixQuery - */ - this.query = new Packages.org.apache.lucene.search.PrefixQuery(t); - return this; -}; -helma.Search.PrefixQuery.prototype = new helma.Search.Query; - -/** - * Constructs a new helma.Search.WildcardQuery instance. - * @class Instances of this class represent a wildcard query. - * @param {String} field The name of the field - * @param {String} str The query string to match - * @returns A newly created WildcardQuery instance - * @constructor - * @extends helma.Search.Query - */ -helma.Search.WildcardQuery = function(field, str) { - var t = new Packages.org.apache.lucene.index.Term(field, str); - /** - * Contains the wrapped WildcardQuery instance - * @type org.apache.lucene.search.WildcardQuery - */ - this.query = new Packages.org.apache.lucene.search.WildcardQuery(t); - return this; -}; -helma.Search.WildcardQuery.prototype = new helma.Search.Query; - - - -/*************************** - ***** D O C U M E N T ***** - ***************************/ - - -/** - * Creates a new instance of helma.Search.Document. - * @class Instances of this class represent a single - * index document. This class provides various methods for - * adding content to such documents. - * @param {org.apache.lucene.document.Document} document Optional Lucene Document object - * that should be wrapped by this Document instance. - * @constructor - */ -helma.Search.Document = function(document) { - if (!document) { - document = new Packages.org.apache.lucene.document.Document(); - } - - /** - * Returns the wrapped Lucene Document object - * @returns The wrapped Document object - * @type org.apache.lucene.document.Document - */ - this.getDocument = function() { - return document; - }; - - return this; -}; - -/** - * Adds a field to this document. - * @param {String|helma.Search.Document.Field} name The name of the field, or - * an instance of {@link helma.Search.Document.Field}, in which case the other - * arguments are ignored. - * @param {String} value The value of the field - * @param {Object} options Optional object containing the following properties - * (each of them is optional too): - *
      - *
    • store (String) Defines whether and how the value is stored - * in the field. Accepted values are "no", "yes" and "compress" (defaults to "yes")
    • - *
    • index (String) Defines whether and how the value is indexed - * in the field. Accepted values are "no", "tokenized", "unTokenized" and - * "noNorms" (defaults to "tokenized")
    • - *
    • termVector (String) Defines if and how the fiels should have - * term vectors. Accepted values are "no", "yes", "withOffsets", "withPositions" - * and "withPositionsAndOffsets" (defaults to "no")
    • - *
    - */ -helma.Search.Document.prototype.addField = function(name, value, options) { - if (!name) { - throw "helma.Search: missing arguments to Document.addField"; - } else if (arguments.length == 1) { - if (arguments[0] instanceof Packages.org.apache.lucene.document.Field) { - this.getDocument().add(arguments[0]); - } else if (arguments[0] instanceof helma.Search.Document.Field) { - this.getDocument().add(arguments[0].getField()); - } - return; - } - - // for backwards compatibility only - if (options != null) { - if (typeof(options.store) === "boolean") { - options.store = (options.store === true) ? "yes" : "no"; - } - if (typeof(options.index) === "boolean") { - if (options.index === true) { - options.index = (options.tokenize === true) ? "tokenized" : "unTokenized"; - } else { - options.index = "no"; - } - delete options.tokenize; - } - } - this.addField(new helma.Search.Document.Field(name, value, options)); - return; -}; - -/** - * Returns a single document field. - * @param {String} name The name of the field in this document object. - * @returns The field with the given name - * @type helma.Search.Document.Field - */ -helma.Search.Document.prototype.getField = function(name) { - var f = this.getDocument().getField(name); - if (f != null) { - return new helma.Search.Document.Field(f); - } - return null; -}; - -/** - * Returns the fields of a document object. If a name is passed as argument, - * this method returns only the fields with the given name - * @param {String} name Optional name of the fields to return - * @returns An array containing all fields in this document object. - * @type Array - */ -helma.Search.Document.prototype.getFields = function(name) { - var fields; - if (name != null) { - fields = this.getDocument().getFields(name); - } else { - fields = this.getDocument().getFields().toArray(); - } - var size = fields.length; - var result = new Array(size); - for (var i=0; i - *
  • store (String) Defines whether and how the value is stored - * in the field. Accepted values are "no", "yes" and "compress" (defaults to "yes")
  • - *
  • index (String) Defines whether and how the value is indexed - * in the field. Accepted values are "no", "tokenized", "unTokenized" and - * "noNorms" (defaults to "tokenized")
  • - *
  • termVector (String) Defines if and how the fiels should have - * term vectors. Accepted values are "no", "yes", "withOffsets", "withPositions" - * and "withPositionsAndOffsets" (defaults to "no")
  • - * - */ -helma.Search.Document.Field = function(name, value, options) { - var field; - - /** - * Contains the name of the field - * @type String - */ - this.name = undefined; // for documentation purposes only - this.__defineGetter__("name", function() { - return field.name(); - }); - - /** - * Contains the string value of the field - * @type String - */ - this.value = undefined; // for documentation purposes only - this.__defineGetter__("value", function() { - return field.stringValue(); - }); - - /** - * Contains the value of the field converted into a date object. - * @type String - */ - this.dateValue = undefined; // for documentation purposes only - this.__defineGetter__("dateValue", function() { - return Packages.org.apache.lucene.document.DateTools.stringToDate(this.value); - }); - - /** - * Returns the wrapped field instance - * @returns The wrapped field - * @type org.apache.lucene.document.Field - */ - this.getField = function() { - return field; - }; - - /** - * Main constructor body - */ - if (arguments.length == 1 && arguments[0] instanceof Packages.org.apache.lucene.document.Field) { - // calling the constructor with a single field argument is - // only used internally (eg. in Document.getFields()) - field = arguments[0]; - } else { - var pkg = Packages.org.apache.lucene.document.Field; - // default options - var store = pkg.Store.YES; - var index = pkg.Index.TOKENIZED; - var termVector = pkg.TermVector.NO; - - var opt; - if (options != null) { - if (options.store != null) { - opt = options.store.toUpperCase(); - if (opt == "YES" || opt == "NO" || opt == "COMPRESS") { - store = pkg.Store[opt]; - } else { - app.logger.warn("helma.Search: unknown field storage option '" + - options.store + "'"); - } - } - if (options.index != null) { - opt = options.index.toUpperCase(); - if (opt == "TOKENIZED" || opt == "NO") { - index = pkg.Index[opt]; - } else if (opt == "UNTOKENIZED") { - index = pkg.Index.UN_TOKENIZED; - } else if (opt == "NONORMS") { - index = pkg.Index.NO_NORMS; - } else { - app.logger.warn("helma.Search: unknown field indexing option '" + - options.index + "'"); - } - } - if (options.termVector != null) { - opt = options.termVector.toUpperCase(); - if (opt == "NO" || opt == "YES") { - termVector = pkg.TermVector[opt]; - } else if (opt == "WITHOFFSETS") { - termVector = pkg.TermVector.WITH_OFFSETS; - } else if (opt == "WITHPOSITIONS") { - termVector = pkg.TermVector.WITH_POSITIONS; - } else if (opt == "WITHPOSITIONSANDOFFSETS") { - termVector = pkg.TermVector.WITH_POSITIONS_OFFSETS; - } else { - app.logger.warn("helma.Search: unknown field term vector option '" + - options.termVector + "'"); - } - } - } - - // construct the field instance and add it to this document - field = new Packages.org.apache.lucene.document.Field( - name, helma.Search.Document.Field.valueToString(value), - store, index, termVector); - } - - return this; -}; - -/** - * Converts the value passed as argument to the appropriate string value. For - * null values this method returns an empty string. - * @param {Object} value The value to convert into a string - * @returns The value converted into a string - * @type String - */ -helma.Search.Document.Field.valueToString = function(value) { - var pkg = Packages.org.apache.lucene.document; - if (value != null) { - if (value.constructor === Date) { - return pkg.DateTools.timeToString(value.getTime(), pkg.DateTools.Resolution.MINUTE); - } else if (value.constructor !== String) { - return String(value); - } - return value; - } - return ""; -}; - -/** @ignore */ -helma.Search.Document.Field.prototype.toString = function() { - return "[Field '" + this.name + "' (" + this.getField().toString() + ")]"; -}; - -/** - * Returns the boost factor of this field. - * @returns The boost factor of this field - * @type Number - */ -helma.Search.Document.Field.prototype.getBoost = function() { - return this.getField().getBoost(); -}; - -/** - * Sets the boost factor of this field. - * @param {Number} boost The boost factor of this field - */ -helma.Search.Document.Field.prototype.setBoost = function(boost) { - this.getField().setBoost(boost); - app.logger.debug("boost is now: " + this.getField().getBoost()); - return; -}; - -/** - * Returns true if this field is indexed - * @returns True if this field's value is indexed, false otherwise - * @type Boolean - */ -helma.Search.Document.Field.prototype.isIndexed = function() { - return this.getField().isIndexed(); -}; - -/** - * Returns true if this field's value is stored in compressed form in the index - * @returns True if this field's value is compressed, false otherwise - * @type Boolean - */ -helma.Search.Document.Field.prototype.isCompressed = function() { - return this.getField().isCompressed(); -}; - -/** - * Returns true if this field's value is stored in the index - * @returns True if this field's value is stored, false otherwise - * @type Boolean - */ -helma.Search.Document.Field.prototype.isStored = function() { - return this.getField().isStored(); -}; - -/** - * Returns true if this field's value is tokenized - * @returns True if this field's value is tokenized, false otherwise - * @type Boolean - */ -helma.Search.Document.Field.prototype.isTokenized = function() { - return this.getField().isTokenized(); -}; - -/** - * Returns true if this field's term vector is stored in the index - * @returns True if this field's term vector is stored, false otherwise - * @type Boolean - */ -helma.Search.Document.Field.prototype.isTermVectorStored = function() { - return this.getField().isTermVectorStored(); -}; - - -helma.lib = "Search"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Skin.js b/modules/helma/Skin.js deleted file mode 100644 index 60325858..00000000 --- a/modules/helma/Skin.js +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Skin.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - - -/** - * @fileoverview Fields and methods of the helma.Skin class. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Skin.js') - */ - - -// define the helma namespace, if not existing -if (!global.helma) { - global.helma = {}; -} - -/** - * Constructs a new instance of helma.Skin - * @class Instances of this class represent a Helma skin. In addition - * to the standard skin functionality this class allows creation of - * a skin based on a Base64 encoded source. - * @param {String} source The source of the skin - * @param {Boolean} encFlag If true the source will be Base64-decoded. - * @constructor - * @returns A newly created instance of helma.Skin - */ -helma.Skin = function(source, encFlag) { - /** @ignore */ - var Base64 = Packages.helma.util.Base64; - - if (!encFlag) { - var skin = createSkin(source); - } else { - var encoded = source; - source = new java.lang.String(source); - var bytes = Base64.decode(source.toCharArray()); - var skin = createSkin(new java.lang.String(bytes, "UTF-8")); - } - - /** @ignore */ - this.toString = function() { - return source; - }; - - /** - * Returns the source of the skin as Base64 encoded string - * @returns The source of the skin as Base64 encoded string - * @type String - */ - this.valueOf = function() { - if (encFlag) { - return encoded; - } - var bytes = new java.lang.String(source).getBytes("UTF-8"); - return new java.lang.String(Base64.encode(bytes)); - }; - - /** - * Renders the skin. - * @param {Object} param An optional parameter object to pass to the skin. - */ - this.render = function(param) { - return renderSkin(skin, param); - }; - - /** - * Returns the rendered skin. - * @param {Object} param An optional parameter object to pass to the skin. - * @type String - */ - this.renderAsString = function(param) { - return renderSkinAsString(skin, param); - }; - - /** - * Returns true if the skin contains a macro with the name - * and optional handler passed as argument. - * @param {String} name The name of the macro - * @param {String} handler An optional macro handler name - * @returns True if the skin contains this macro at least once, - * false otherwise. - * @type Boolean - */ - this.containsMacro = function(name, handler) { - res.push(); - res.write("<% *"); - if (handler) { - res.write(handler); - res.write("."); - } - res.write(name); - res.write(" *%>"); - var re = new RegExp(res.pop(), "g"); - return re.test(source); - }; - - for (var i in this) - this.dontEnum(i); - - return this; -}; - - -helma.lib = "Skin"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Ssh.js b/modules/helma/Ssh.js deleted file mode 100644 index 76d47966..00000000 --- a/modules/helma/Ssh.js +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Ssh.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - - -/** - * @fileoverview Fields and methods of the helma.Ssh class. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Ssh.js') - */ - -// take care of any dependencies -app.addRepository('modules/helma/File.js'); -app.addRepository('modules/helma/ganymed-ssh2-build208.jar'); - -// define the helma namespace, if not existing -if (!global.helma) { - global.helma = {}; -} - -/** - * Creates a new instance of helma.Ssh - * @class This class provides methods for connecting to a remote - * server via secure shell (ssh) and copying files from/to a remote - * server using secure copy (scp). It utilizes "Ganymed SSH-2 for Java" - * (see http://www.ganymed.ethz.ch/ssh2/). - * @param {String} server The server to connect to - * @param {helma.File|java.io.File|String} hosts Either a file - * containing a list of known hosts, or the path pointing to a - * file. This argument is optional. - * @constructor - * @returns A newly created instance of helma.Ssh - * @author Robert Gaggl - */ -helma.Ssh = function(server, hosts) { - var SSHPKG = Packages.ch.ethz.ssh2; - var SSHPKGNAME = "ganymed-ssh2.jar"; - var SSHPKGURL = "http://www.ganymed.ethz.ch/ssh2"; - var className = "helma.Ssh"; - var paranoid = false; - var verifier = null; - var knownHosts, connection; - - // check if necessary jar file is in classpath - try { - knownHosts = new SSHPKG.KnownHosts(); - connection = new SSHPKG.Connection(server); - } catch (e) { - if (e instanceof TypeError == false) - throw(e); - throw("helma.Ssh needs " + SSHPKGNAME + - " in lib/ext or application directory " + - "[" + SSHPKGURL + "]"); - } - - /** - * A simple verifier for verifying host keys - * @private - */ - var SimpleVerifier = { - verifyServerHostKey: function(hostname, port, serverHostKeyAlgorithm, serverHostKey) { - var result = knownHosts.verifyHostkey(hostname, serverHostKeyAlgorithm, serverHostKey); - switch (result) { - case SSHPKG.KnownHosts.HOSTKEY_IS_OK: - debug("verifyServerHostKey", "received known host key, proceeding"); - return true; - case SSHPKG.KnownHosts.HOSTKEY_IS_NEW: - if (paranoid == true) { - debug("verifyServerHostKey", "received unknown host key, rejecting"); - return false; - } else { - debug("verifyServerHostKey", "received new host key, adding temporarily to known hosts"); - var hn = java.lang.reflect.Array.newInstance(java.lang.String, 1); - hn[0] = hostname; - knownHosts.addHostkey(hn, serverHostKeyAlgorithm, serverHostKey); - return true; - } - case SSHPKG.KnownHosts.HOSTKEY_HAS_CHANGED: - debug("verifyServerHostKey", "WARNING: host key has changed, rejecting"); - default: - return false; - } - return; - } - }; - - /** - * Converts the argument into an instance of java.io.File - * @param {helma.File|java.io.File|String} file Either a file - * object or the path to a file as string - * @returns The argument converted into a file object - * @type java.io.File - * @private - */ - var getFile = function(file) { - if (file instanceof helma.File) { - return new java.io.File(file.getAbsolutePath()); - } else if (file instanceof java.io.File) { - return file; - } else if (file.constructor == String) { - return new java.io.File(file); - } - return null; - }; - - /** - * Connects to the remote server - * @return Boolean - * @private - */ - var connect = function() { - try { - var info = connection.connect(verifier); - debug("connect", "connected to server " + server); - return true; - } catch (e) { - error("connect", "connection to " + server + " failed."); - } - return false; - }; - - /** - * Private helper method for debugging output using app.logger - * @param {String} methodName The name of the method - * @param {String} msg The debug message to write to event log file - * @private - */ - var debug = function(methodName, msg) { - var msg = msg ? " " + msg : ""; - app.logger.debug(className + ":" + methodName + msg); - return; - }; - - /** - * Private helper method for error output using app.logger - * @param {String} methodName The name of the method - * @param {String} msg The error message to write to event log file - * @private - */ - var error = function(methodName, msg) { - var tx = java.lang.Thread.currentThread(); - tx.dumpStack(); - app.logger.error(className + ":" + methodName + ": " + msg); - return; - }; - - /** - * Opens the file passed as argument and adds the known hosts - * therein to the list of known hosts for this client. - * @param {helma.File|java.io.File|String} file Either a file object - * or the path to a file containing a list of known hosts - * @returns True if adding the list was successful, false otherwise - * @type Boolean - */ - this.addKnownHosts = function(file) { - try { - knownHosts.addHostkeys(getFile(file)); - verifier = new SSHPKG.ServerHostKeyVerifier(SimpleVerifier); - return true; - } catch (e) { - error("addKnownHosts", "Missing or invalid known hosts file '" + file + "'"); - } - return false; - }; - - /** - * Connects to a remote host using plain username/password authentication. - * @param {String} username The username - * @param {String} password The password - * @returns True in case the connection attempt was successful, false otherwise. - * @type Boolean - */ - this.connect = function(username, password) { - if (!username || !password) { - error("connect", "Insufficient arguments."); - } else if (connect() && connection.authenticateWithPassword(username, password)) { - debug("connect", "authenticated using password"); - return true; - } else { - error("connect", "Authentication failed!"); - } - return false; - }; - - /** - * Connects to a remote host using a private key and the corresponding - * passphrase. - * @param {String} username The username - * @param {helma.File|java.io.File|String} key Either a file object - * representing the private key file, or the path to it. - * @param {String} passphrase The passphrase of the private key, if necessary. - * @returns True in case the connection attempt was successful, false otherwise. - * @type Boolean - */ - this.connectWithKey = function(username, key, passphrase) { - var keyFile; - if (!username || !(keyFile = getFile(key))) { - error("connectWithKey", "Insufficient or wrong arguments."); - } else if (connect() && connection.authenticateWithPublicKey(username, keyFile, passphrase)) { - debug("connectWithKey", "authenticated with key"); - return true; - } else { - error("connectWithKey", "Authentication failed!"); - } - return false; - }; - - /** - * Disconnects this client from the remote server. - */ - this.disconnect = function() { - connection.close(); - debug("disconnect", "disconnected from server " + server); - return; - }; - - /** - * Returns true if this client is currently connected. - * @returns True in case this client is connected, false otherwise. - * @type Boolean - */ - this.isConnected = function() { - return (connection != null && connection.isAuthenticationComplete()); - }; - - /** - * Copies a local file to the remote server - * @param {String|Array} localFile Either the path to a single local - * file or an array containing multiple file paths that should be - * copied to the remote server. - * @param {String} remoteDir The path to the remote destination directory - * @param {String} mode An optional 4-digit permission mode string (eg. - * 0755); - * @returns True in case the operation was successful, false otherwise. - * @type Boolean - */ - this.put = function(localFile, remoteDir, mode) { - if (!localFile || !remoteDir) { - error("put", "Insufficient arguments."); - } else if (!this.isConnected()) { - error("put", "Not connected. Please establish a connection first."); - } else { - try { - var scp = connection.createSCPClient(); - if (mode != null) - scp.put(localFile, remoteDir, mode); - else - scp.put(localFile, remoteDir); - debug("put", "copied '" + localFile + "' to '" + remoteDir + "'"); - return true; - } catch (e) { - error("put", e); - } - } - return false; - }; - - /** - * Retrieves a file from the remote server and stores it locally. - * @param {String|Array} remoteFile Either the path to a single remote - * file or an array containing multiple file paths that should be - * copied onto the local disk. - * @param {String} targetDir The path to the local destination directory - * @returns True if the copy process was successful, false otherwise. - * @type Boolean - */ - this.get = function(remoteFile, targetDir) { - if (!remoteFile || !targetDir) { - error("get", "Insufficient arguments."); - } else if (!this.isConnected()) { - error("get", "Not connected. Please establish a connection first."); - } else { - try { - var scp = connection.createSCPClient(); - scp.get(remoteFile, targetDir); - debug("get", "copied '" + remoteFile + "' to '" + targetDir + "'"); - return true; - } catch (e) { - error("get", e); - } - } - return false; - }; - - /** - * Executes a single command on the remote server. - * @param {String} cmd The command to execute on the remote server. - * @return The result of the command execution - * @type String - */ - this.execCommand = function(cmd) { - if (!this.isConnected()) { - error("execCommand", "Not connected. Please establish a connection first."); - } else { - var session = connection.openSession(); - try { - session.execCommand(cmd); - var stdout = new SSHPKG.StreamGobbler(session.getStdout()); - var br = new java.io.BufferedReader(new java.io.InputStreamReader(stdout)); - res.push(); - while (true) { - if (!(line = br.readLine())) - break; - res.writeln(line); - } - debug("execCommand", "executed command '" + cmd + "'"); - return res.pop(); - } catch (e) { - error("execCommand", e); - } finally { - session.close(); - } - } - }; - - /** - * Toggles paranoid mode. If set to true this client tries to - * verify the host key against the its list of known hosts - * during connection and rejects if the host key is not found - * therein or is different. - * @param {Boolean} p Either true or false - */ - this.setParanoid = function(p) { - paranoid = (p === true); - return; - }; - - /** - * Returns true if this client is in paranoid mode. - * @return Boolean - * @see #setParanoid - */ - this.isParanoid = function() { - return paranoid; - }; - - /** - * main constructor body - */ - if (hosts) { - this.addKnownHosts(hosts); - } - - for (var i in this) - this.dontEnum(i); - return this; -}; - - -/** @ignore */ -helma.Ssh.toString = function() { - return "[helma.Ssh]"; -}; - - -helma.lib = "Ssh"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/Url.js b/modules/helma/Url.js deleted file mode 100644 index 081f765d..00000000 --- a/modules/helma/Url.js +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2007 Helma Software. All Rights Reserved. - * - * $RCSfile: Url.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Fields and methods of the helma.Url class. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Url.js') - */ - -if (!global.helma) { - global.helma = {}; -} - - -/** - * Creates a helma.Url object from a provided url string. - * - * @constructor - */ -helma.Url = function(str) { - if (!str || !helma.Url.PATTERN.test(str)) - throw Error("Cannot create helma.Url: insufficient arguments"); - - // filter punctuation from user-generated urls - // FIXME: a) can this be done in helma.Url.PATTERN? - // b) should it be done rather in methods like activateUrls? - str = str.replace(/[,.;:]\s/, ""); - - var parts = helma.Url.PATTERN.exec(str); - /** - * Protocol segment of this URL - */ - this.protocol = parts[1]; - - if (!parts[2]) { - if (parts[3]) - /** - * User name segment of this URL - */ - this.user = parts[3]; - } else { - this.user = parts[2]; - if (parts[3]) - /** - * Password segment of this URL - */ - this.password = parts[3]; - } - - if (!parts[4]) - throw Error("Cannot create helma.Url: missing host part"); - - /** - * Fully qualified domain name segment of this URL - */ - this.domainName = parts[4]; // actually, the fully-qualified domain name - var fqdnParts = this.domainName.split("."); - if (fqdnParts.length < 3) - this.host = ""; - else { - /** - * Host name segment of this URL - */ - this.host = fqdnParts[0]; - fqdnParts.splice(0, 1); - } - /** - * Top level domain name segment of this URL - */ - this.topLevelDomain = fqdnParts[fqdnParts.length-1]; - /** - * Domain name segment of this URL - */ - this.domain = fqdnParts.join("."); - - /** - * Request path segment of this URL as string - */ - this.pathString = parts[5] || ""; - if (this.pathString.indexOf("/") == 0) - this.pathString = this.pathString.substring(1); - /** - * Request path segment of this URL as array - */ - this.path = this.pathString.split("/"); - /** - * File name segment of this URL - */ - this.file = this.path.pop(); - - if (parts[6]) { - /** - * Query parameter segment of this URL as string - */ - this.queryString = parts[6]; - var pairs; - /** - * Query parameter segment of this URL as object - */ - this.query = {}; - parts = parts[6].split("&"); - for (var i in parts) { - pairs = parts[i].split("="); - this.query[pairs[0]] = pairs[1]; - } - } - - return this; -}; - - -helma.Url.PATTERN = /^([^:]*):\/\/+(?:([^\/]*):)?(?:([^\/]*)@)?([\w\-_.]*[^.])(\/[^?]*)?(?:\?(.*))?$/; diff --git a/modules/helma/Zip.js b/modules/helma/Zip.js deleted file mode 100644 index ab17f4f4..00000000 --- a/modules/helma/Zip.js +++ /dev/null @@ -1,523 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Zip.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * @fileoverview Fields and methods of the helma.Zip class. - *

    - * To use this optional module, its repository needs to be added to the - * application, for example by calling app.addRepository('modules/helma/Zip.js') - */ - -// take care of any dependencies -app.addRepository('modules/helma/File.js'); - -// define the helma namespace, if not existing -if (!global.helma) { - global.helma = {}; -} - -/** - * Constructs a new helma.Zip instance - * @class Instances of this class represent a single zip archive - * and provide various methods for extracting entries or manipulating - * the contents of the archive. - * @param {helma.File|java.io.File|String} file Either - * a file object representing the .zip file on disk, or the - * path to the .zip file as string. - * @constructor - * @returns A newly created instance of helma.Zip. - * @author Robert Gaggl - */ -helma.Zip = function(file) { - - /** - * Private method that extracts the data of a single file - * in a .zip archive. If a destination path is given it - * writes the extracted data directly to disk using the - * name of the ZipEntry Object, otherwise it returns the - * byte array containing the extracted data. - * @param {java.util.zip.ZipFile} zFile The zip archive to extract - * the file from. - * @param {java.util.zip.ZipEntry} entry The zip entry to extract - * @param {String} destPath The destination path where the extracted - * file should be stored. - * @returns If no destination path is given, this method returns - * the contents of the extracted file as ByteArray, otherwise - * it returns null. - * @private - */ - var extractEntry = function(zFile, entry, destPath) { - var size = entry.getSize(); - if (entry.isDirectory() || size <= 0) - return null; - - var zInStream = new java.io.BufferedInputStream(zFile.getInputStream(entry)); - var buf = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, size); - zInStream.read(buf, 0, size); - zInStream.close(); - - if (!destPath) { - // no filesystem destination given, so return - // the byte array containing the extracted data - return buf; - } - // extract the file to the given path - var dest = new java.io.File(destPath, entry.getName()); - if (entry.isDirectory()) - dest.mkdirs(); - else if (buf) { - if (!dest.getParentFile().exists()) - dest.getParentFile().mkdirs(); - try { - var outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(dest)); - outStream.write(buf, 0, size); - } finally { - if (outStream) outStream.close(); - } - } - return null; - }; - - /** - * Private method for adding a single file to the Zip archive - * represented by this helma.Zip instance - * @param {java.util.zip.ZipOutputStream} zOutStream The output - * stream to write to - * @param {java.io.File} f The file that should be added to the - * Zip archive. - * @param {Number} level The compression-level between 0-9. - * @param {String} pathPrefix The path of the directory within the - * Zip archive where the file should be added (optional). - * @private - */ - var addFile = function(zOutStream, f, level, pathPrefix) { - var fInStream = new java.io.BufferedInputStream(new java.io.FileInputStream(f)); - buf = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, f.length()); - fInStream.read(buf, 0, f.length()); - - var name = new java.lang.StringBuffer(); - if (pathPrefix) { - // append clean pathPrefix to name buffer - var st = new java.util.StringTokenizer(pathPrefix, "\\/"); - while (st.hasMoreTokens()) { - name.append(st.nextToken()); - name.append("/"); - } - } - name.append(f.getName()); - var entry = new java.util.zip.ZipEntry(name.toString()); - entry.setSize(f.length()); - entry.setTime(f.lastModified()); - zOutStream.setLevel(level); - zOutStream.putNextEntry(entry); - zOutStream.write(buf, 0, buf.length); - zOutStream.closeEntry(); - fInStream.close(); - return; - }; - - /** - * Private helper method that converts the argument into - * an instance of java.io.File. - * @param {helma.File|java.io.File} f Either a file object or - * the path to a file as string - * @return The argument converted into a file object - * @type java.io.File - * @private - */ - var evalFile = function(f) { - var result; - if (f instanceof java.io.File) { - result = f; - } else if (f instanceof helma.File || typeof(f) == "string") { - result = new java.io.File(f); - } - if (!result.exists()) { - throw "Error creating Zip Object: File '" + f + "' doesn't exist."; - } - return result; - }; - - /** - * Returns an array containing the entries of the archive - * represented by this helma.Zip instance. - * @returns The entries stored in the zip archive - * @type helma.Zip.Content - */ - this.list = function() { - var result = new helma.Zip.Content(); - var zFile = new java.util.zip.ZipFile(file); - var entries = zFile.entries(); - while (entries.hasMoreElements()) { - result.add(new helma.Zip.Entry(entries.nextElement())); - } - zFile.close(); - return result; - }; - - /** - * Extracts a single file from the zip archive represented - * by this helma.Zip instance. If a destination path is given it - * writes the extracted data directly to disk using the - * name of the zip entry, otherwise the resulting entry object - * contains the extracted data in the property data. - * @param {String} name The name of the file to extract - * @param {String} destPath An optional destination path where - * the extracted file should be stored. - * @returns An object containing the entry's properties - * @type helma.Zip.Entry - * @see helma.Zip.Entry - */ - this.extract = function(name, destPath) { - var zFile = new java.util.zip.ZipFile(file); - var entry = zFile.getEntry(name); - if (!entry) - return null; - var result = new helma.Zip.Entry(entry); - result.data = extractEntry(zFile, entry, destPath); - zFile.close(); - return result; - }; - - /** - * Extracts all files within the zip archive represented by - * this helma.Zip instance. If a destination path is given it - * stores the files directly on disk, while preserving any directory - * structure within the archive. If no destination path is given, - * the resulting entry objects will contain the extracted data - * in their property data. - * @param {String} destPath An optional destination path where the - * files in the zip archive should be stored. - * @returns An object containing the extracted entries. - * @type helma.Zip.Content - * @see helma.Zip.Entry - */ - this.extractAll = function(destPath) { - var result = new helma.Zip.Content(); - var zFile = new java.util.zip.ZipFile(file); - var entries = zFile.entries(); - while (entries.hasMoreElements()) { - var entry = entries.nextElement(); - var e = new helma.Zip.Entry(entry); - e.data = extractEntry(zFile, entry, destPath); - result.add(e); - } - zFile.close(); - return result; - }; - - /** - * Adds a single file or a whole directory (recursive!) to the zip archive - * @param {helma.File|java.io.File|String} f Either a file object - * or the path to a file or directory on disk that should be added to the - * archive. If the argument represents a directory, its contents will be added - * recursively to the archive. - * @param {Number} level An optional compression level to use. The argument - * must be between zero and 9 (default: 9 = best compression). - * @param {String} pathPrefix An optional path prefix to use within the archive. - */ - this.add = function (f, level, pathPrefix) { - var f = evalFile(f); - - // evaluate arguments - if (arguments.length == 2) { - if (typeof arguments[1] == "string") { - pathPrefix = arguments[1]; - level = 9; - } else { - level = parseInt(arguments[1], 10); - pathPrefix = null; - } - } else if (level == null || isNaN(level)) { - level = 9; - } - // only levels between 0 and 9 are allowed - level = Math.max(0, Math.min(9, level)); - - if (f.isDirectory()) { - // add a whole directory to the zip file (recursive!) - var files = (new helma.File(f.getAbsolutePath())).listRecursive(); - for (var i in files) { - var fAdd = new java.io.File(files[i]); - if (!fAdd.isDirectory()) { - var p = fAdd.getPath().substring(f.getAbsolutePath().length, fAdd.getParent().length); - if (pathPrefix) - p = pathPrefix + p; - addFile(zOutStream, fAdd, level, p); - } - } - } else { - addFile(zOutStream, f, level, pathPrefix); - } - return; - }; - - /** - * Adds a new entry to the zip file. - * @param {ByteArray} buf A byte array containing the data to add - * to the archive. - * @param {String} name The name of the file to add, containing - * an optional path prefix - * @param {Number} level The compression level to use (0-9, defaults to 9). - */ - this.addData = function(buf, name, level) { - var entry = new java.util.zip.ZipEntry(name); - entry.setSize(buf.length); - entry.setTime(new Date()); - if (level == null || isNaN(level)) { - zOutStream.setLevel(9); - } else { - zOutStream.setLevel(Math.max(0, Math.min(9, parseInt(level, 10)))); - } - zOutStream.putNextEntry(entry); - zOutStream.write(buf, 0, buf.length); - zOutStream.closeEntry(); - return; - }; - - /** - * Closes the zip archive. This method should be called when - * all operations have been finished, to ensure that no open - * file handles are left. - */ - this.close = function() { - zOutStream.close(); - return; - }; - - /** - * Returns the binary data of the zip archive. - * @returns A ByteArray containing the binary data of the zip archive - * @type ByteArray - */ - this.getData = function() { - zOutStream.close(); - fOutStream.close(); - var inputStream = new java.io.FileInputStream(tempFile); - var bOutStream = new java.io.ByteArrayOutputStream(); - var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 8192); - try { - var chunk; - while ((chunk = inputStream.read(buffer)) !== -1) { - bOutStream.write(buffer, 0, chunk); - } - bOutStream.flush(); - } catch (ex) { - app.log(ex); - } finally { - if (inputStream) inputStream.close(); - if (bOutStream) bOutStream.close(); - } - return bOutStream.toByteArray(); - }; - - /** - * Saves the archive. - * @param {String} dest The full destination path including the name - * where the zip archive should be saved. - */ - this.save = function(dest) { - if (!dest) - throw new Error("no destination for ZipFile given"); - // first of all, close the ZipOutputStream - zOutStream.close(); - fOutStream.close(); - var destFile = new java.io.File(dest); - try { - if (destFile.exists()) destFile['delete'](); - java.nio.file.Files.move(tempFile.toPath(), destFile.toPath()); - } catch (ex) { - app.log(ex); - } - return; - }; - - /** @ignore */ - this.toString = function() { - if (file) { - return "[helma.Zip " + file.getAbsolutePath() + "]"; - } else { - return "[helma.Zip]"; - } - }; - - /** - * constructor body - */ - var tempFile = new java.io.File.createTempFile('zip-', ''); - var fOutStream = new java.io.FileOutputStream(tempFile); - var zOutStream = new java.util.zip.ZipOutputStream(fOutStream); - - if (file) { - file = evalFile(file); - } - - for (var i in this) - this.dontEnum(i); - - return this; -} - -/** - * Creates a new helma.Zip.Content instance - * @class Instances of this class represent the content - * of a zip archive. - * @constructor - * @returns A newly created instance of helma.Zip.Content - */ -helma.Zip.Content = function() { - /** - * The table of contents of the archive - * @type Array - */ - this.toc = []; - - /** - * The files contained in the zip archive, where - * each directory level is a separate object containing - * the entries (files and directories) as properties. - */ - this.files = {}; - - /** - * Adds a zip entry object to the table of contents - * and the files collection - * @param {helma.Zip.Entry} entry The entry to add to the - * zip archive - */ - this.add = function(entry) { - // add the file to the table of contents array - this.toc[this.toc.length] = entry; - // plus add it to the files tree - var arr = entry.name.split(/[\\\/]/); - var cnt = 0; - var curr = this.files; - var propName; - while (cnt < arr.length-1) { - propName = arr[cnt++]; - if (!curr[propName]) { - curr[propName] = {}; - } - curr = curr[propName]; - } - curr[arr[cnt]] = entry; - return; - }; - - for (var i in this) - this.dontEnum(i); - - return this; -}; - - -/** @ignore */ -helma.Zip.Content.prototype.toString = function() { - return "[helma.Zip.Content]"; -} - - -/** - * Creates a new instance of helma.Zip.Entry - * @class Instances of this class represent a single zip archive entry, - * containing the (meta)data of the entry. - * @param {java.util.zip.ZipEntry} entry The zip entry object whose metadata - * should be stored in this instance - * @constructor - * @returns A newly created helma.Zip.Entry instance. - */ -helma.Zip.Entry = function(entry) { - /** - * The name of the zip archive entry - * @type String - */ - this.name = entry.getName(); - - /** - * The size of the entry in bytes - * @type Number - */ - this.size = entry.getSize(); - - /** - * The file date of the entry - * @type Date - */ - this.time = entry.getTime() ? new Date(entry.getTime()) : null; - - /** - * True if the entry is a directory, false otherwise - * @type Boolean - */ - this.isDirectory = entry.isDirectory(); - - /** - * The data of the zip entry - * @type ByteArray - */ - this.data = null; - - for (var i in this) - this.dontEnum(i); - return this; -}; - - -/** @ignore */ -helma.Zip.Entry.prototype.toString = function() { - return "[helma.Zip.Entry]"; -} - - -/** - * Extracts all files in the zip archive data passed as argument - * and returns them. - * @param {ByteArray} zipData A ByteArray containing the data of the zip archive - * @returns The entries of the zip archive - * @type helma.Zip.Content - */ -helma.Zip.extractData = function(zipData) { - var zInStream = new java.util.zip.ZipInputStream(new java.io.ByteArrayInputStream(zipData)); - var result = new helma.Zip.Content(); - - var entry; - while ((entry = zInStream.getNextEntry()) != null) { - var eParam = new helma.Zip.Entry(entry); - if (eParam.isDirectory) - continue; - if (eParam.size == -1) - eParam.size = 16384; - var bos = new java.io.ByteArrayOutputStream(eParam.size); - var buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 8192); - var count; - while ((count = zInStream.read(buf)) != -1) - bos.write(buf, 0, count); - eParam.data = bos.toByteArray(); - eParam.size = bos.size(); - result.add(eParam); - } - zInStream.close(); - return result; -}; - - -helma.lib = "Zip"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/helma/all.js b/modules/helma/all.js deleted file mode 100644 index 3b3dfd0e..00000000 --- a/modules/helma/all.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile: Aspects.js,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -// convenience SingleFileRepository to load all the -// Javascript library files in ./modules/helma - -/** @namespace helma */ - -app.addRepository('modules/helma/Aspects.js'); -app.addRepository('modules/helma/Chart.js'); -app.addRepository('modules/helma/Color.js'); -app.addRepository('modules/helma/Database.js'); -app.addRepository('modules/helma/File.js'); -app.addRepository('modules/helma/Ftp.js'); -app.addRepository('modules/helma/Html.js'); -app.addRepository('modules/helma/Http.js'); -app.addRepository('modules/helma/Image.js'); -app.addRepository('modules/helma/Mail.js'); -app.addRepository('modules/helma/Search.js'); -app.addRepository('modules/helma/Skin.js'); -app.addRepository('modules/helma/Ssh.js'); -app.addRepository('modules/helma/Url.js'); -app.addRepository('modules/helma/Zip.js'); diff --git a/modules/helma/build.gradle b/modules/helma/build.gradle deleted file mode 100644 index 401dd406..00000000 --- a/modules/helma/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -dependencies { - runtimeOnly 'ch.ethz.ganymed:ganymed-ssh2:build209' - runtimeOnly 'net.sourceforge.jexcelapi:jxl:2.5.7' - runtimeOnly 'org.apache.lucene:lucene-analyzers:2.2.0' - runtimeOnly 'org.apache.lucene:lucene-core:2.2.0' -} - -jar.enabled = false -compileJava.enabled = false -compileTestJava.enabled = false -processResources.enabled = false -processTestResources.enabled = false -test.enabled = false - -tasks.register('deps', Copy) { - from sourceSets.main.runtimeClasspath - into '.' -} diff --git a/modules/helma/ganymed-ssh2-build208.jar b/modules/helma/ganymed-ssh2-build208.jar deleted file mode 100644 index 8ca7bd74..00000000 Binary files a/modules/helma/ganymed-ssh2-build208.jar and /dev/null differ diff --git a/modules/helma/jxl-2.5.7.jar b/modules/helma/jxl-2.5.7.jar deleted file mode 100644 index fc1a5a55..00000000 Binary files a/modules/helma/jxl-2.5.7.jar and /dev/null differ diff --git a/modules/helma/licenses/ganymed-ssh2.txt b/modules/helma/licenses/ganymed-ssh2.txt deleted file mode 100644 index 8a1a974a..00000000 --- a/modules/helma/licenses/ganymed-ssh2.txt +++ /dev/null @@ -1,86 +0,0 @@ -Copyright (c) 2006 - 2011 Christian Plattner. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -a.) Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -b.) Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -c.) Neither the name of Christian Plattner nor the names of its contributors may - be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - - -This software includes work that was released under the following license: - -Copyright (c) 2005 - 2006 Swiss Federal Institute of Technology (ETH Zurich), - Department of Computer Science (http://www.inf.ethz.ch), - Christian Plattner. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -a.) Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -b.) Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -c.) Neither the name of ETH Zurich nor the names of its contributors may - be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - - -The Java implementations of the AES, Blowfish and 3DES ciphers have been -taken (and slightly modified) from the cryptography package released by -"The Legion Of The Bouncy Castle". - -Their license states the following: - -Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle -(http://www.bouncycastle.org) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/modules/helma/licenses/jxl.txt b/modules/helma/licenses/jxl.txt deleted file mode 100644 index a47ada12..00000000 --- a/modules/helma/licenses/jxl.txt +++ /dev/null @@ -1,125 +0,0 @@ -GNU GENERAL PUBLIC LICENSE -Version 2, June 1991 - -Copyright (C) 1989, 1991 Free Software Foundation, Inc. -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - -Everyone is permitted to copy and distribute verbatim copies -of this license document, but changing it is not allowed. -Preamble -The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. - -To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. - -For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. - -We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. - -Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. - -Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. - -The precise terms and conditions for copying, distribution and modification follow. - -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. - -1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. - -You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. - -2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: - -a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. -b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. -c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) -These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. - -3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: - -a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, -b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, -c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) -The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. - -If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - -4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. - -5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. - -6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. - -7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. - -This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - -8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. - -9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. - -10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - -NO WARRANTY - -11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -END OF TERMS AND CONDITIONS -How to Apply These Terms to Your New Programs -If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - -one line to give the program's name and an idea of what it does. -Copyright (C) yyyy name of author - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this when it starts in an interactive mode: - -Gnomovision version 69, Copyright (C) year name of author -Gnomovision comes with ABSOLUTELY NO WARRANTY; for details -type `show w'. This is free software, and you are welcome -to redistribute it under certain conditions; type `show c' -for details. -The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: - -Yoyodyne, Inc., hereby disclaims all copyright -interest in the program `Gnomovision' -(which makes passes at compilers) written -by James Hacker. - -signature of Ty Coon, 1 April 1989 -Ty Coon, President of Vice -This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. diff --git a/modules/helma/licenses/lucene-analyzers.txt b/modules/helma/licenses/lucene-analyzers.txt deleted file mode 100644 index d6456956..00000000 --- a/modules/helma/licenses/lucene-analyzers.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/modules/helma/licenses/lucene-core.txt b/modules/helma/licenses/lucene-core.txt deleted file mode 100644 index d6456956..00000000 --- a/modules/helma/licenses/lucene-core.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/modules/helma/lucene-analyzers-2.2.0.jar b/modules/helma/lucene-analyzers-2.2.0.jar deleted file mode 100644 index 86226042..00000000 Binary files a/modules/helma/lucene-analyzers-2.2.0.jar and /dev/null differ diff --git a/modules/helma/lucene-core-2.2.0.jar b/modules/helma/lucene-core-2.2.0.jar deleted file mode 100644 index 2469481c..00000000 Binary files a/modules/helma/lucene-core-2.2.0.jar and /dev/null differ diff --git a/modules/jala/README.md b/modules/jala/README.md deleted file mode 100644 index 331e0c87..00000000 --- a/modules/jala/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# About Jala - -Jala is an open-source collection of JavaScript modules for Helma Object Publisher. Copyright 2004 ORF Online und Teletext GmbH, Vienna (Austria). You can find more information about each module in the API Documentation located in the `docs` directory. - -## Licensing - -Jala itself is licensed under the Apache 2.0 License, but parts of Jala require third party libraries coming with different licenses. You can find all necessary information in the `licenses` directory. - -## Installation - -Move the Jala folder into the `modules` directory of your Helma installation. To include a certain Jala module simply add the following line to your Helma application's source code (replace `[name]` with the desired module name): - - app.addRepository("./modules/jala/code/[name].js"); - -If you want to include the whole Jala package at once, you can use the `all` module for convenience: - - app.addRepository("./modules/jala/code/all.js"); - -Alternatively, you can import the Jala module from within Helma's -`apps.properties` file (replace `[appName]` with the name of your Helma application, `[n]` with a number between 0 and 9 and `[moduleName]` with the desired module -name): - - [appName].respository.[n] = ./modules/jala/code/[moduleName].js - -More information about the `addRepository()` method and generally including repositories in a Helma application is available at -http://helma.org/stories/77712/. - -## Contact, Bugs and Feedback - -The Jala Project is hosted at https://dev.orf.at/jala/ providing all necessary information about Subversion access, Ticketing, Releases etc. - -Although we encourage you to post your questions and comments as ticket, we also provide a mailing list for convenience (details at -https://dev.orf.at/trac/jala/wiki/MailingList). - -For immediate contact you can reach the developers via jaladev AT gmail.com. diff --git a/modules/jala/build.gradle b/modules/jala/build.gradle deleted file mode 100644 index 3b9b6684..00000000 --- a/modules/jala/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -dependencies { - runtimeOnly 'dom4j:dom4j:1.1.3' - runtimeOnly 'jaxen:jaxen:1.1-beta-8' - runtimeOnly 'net.sf.javamusictag:jid3lib:0.5.4' - - // FIXME: Did not find these two or appropriate replacements for them - //runtime 'id3:de.ueberdosis.mp3info:1.6.0d9' - //runtime 'javadns:org.wonderly:?' -} - -jar.enabled = false -compileJava.enabled = false -compileTestJava.enabled = false -processResources.enabled = false -processTestResources.enabled = false -test.enabled = false - -tasks.register('deps', Copy) { - from sourceSets.main.runtimeClasspath - into 'lib' -} diff --git a/modules/jala/build.properties b/modules/jala/build.properties deleted file mode 100644 index 387dc22a..00000000 --- a/modules/jala/build.properties +++ /dev/null @@ -1,7 +0,0 @@ -## build properties for jsdoc api documentation -## all paths *must* be relative to the directory where -## this file is located - -docs.source = ./code -docs.destination = ./docs -docs.projectName = Jala 1.3 diff --git a/modules/jala/code/.jsdoc/summary.html b/modules/jala/code/.jsdoc/summary.html deleted file mode 100644 index 3474c714..00000000 --- a/modules/jala/code/.jsdoc/summary.html +++ /dev/null @@ -1 +0,0 @@ -Jala is a Helma-based library and utility project initially developed to ease the work at ORF.at's software development department. diff --git a/modules/jala/code/AsyncRequest.js b/modules/jala/code/AsyncRequest.js deleted file mode 100644 index 40c19c7a..00000000 --- a/modules/jala/code/AsyncRequest.js +++ /dev/null @@ -1,175 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.AsyncRequest class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * Creates a new AsyncRequest instance. - * @class This class is used to create requests of type "INTERNAL" - * (like cron-jobs) that are processed in a separate thread and - * therefor asynchronous. - * @param {Object} obj Object in whose context the method should be called - * @param {String} funcName Name of the function to call - * @param {Array} args Array containing the arguments that should be passed - * to the function (optional). This option is deprecated, instead - * pass the arguments directly to the {@link #run} method. - * @constructor - * @returns A new instance of AsyncRequest - * @type AsyncRequest - * @deprecated Use the {@link http://helma.zumbrunn.net/reference/core/app.html#invokeAsync - * app.invokeAsync} method instead (built-in into Helma as - * of version 1.6) - */ -jala.AsyncRequest = function(obj, funcName, args) { - app.logger.warn("Use of jala.AsyncRequest is deprecated in this version."); - app.logger.warn("This module will probably be removed in a " + - "future version of Jala."); - - /** - * Contains a reference to the thread started by this AsyncRequest - * @type java.lang.Thread - * @private - */ - var thread; - - /** - * Contains the timeout defined for this AsyncRequest (in milliseconds) - * @type Number - * @private - */ - var timeout; - - /** - * Contains the number of milliseconds to wait before starting - * the asynchronous request. - * @type Number - * @private - */ - var delay; - - /** - * Run method necessary to implement java.lang.Runnable. - * @private - */ - var runner = function() { - // evaluator that will handle the request - var ev = app.__app__.getEvaluator(); - - if (delay != null) { - java.lang.Thread.sleep(delay); - } - try { - if (args === undefined || args === null || args.constructor != Array) { - args = []; - } - if (timeout != null) { - ev.invokeInternal(obj, funcName, args, timeout); - } else { - ev.invokeInternal(obj, funcName, args); - } - } catch (e) { - // ignore it, but log it - app.log("[Runner] Caught Exception: " + e); - } finally { - // release the ev in any case - app.__app__.releaseEvaluator(ev); - // remove reference to underlying thread - thread = null; - } - return; - }; - - /** - * Sets the timeout of this asynchronous request. - * @param {Number} seconds Thread-timeout. - */ - this.setTimeout = function(seconds) { - timeout = seconds * 1000; - return; - }; - - /** - * Defines the delay to wait before evaluating this asynchronous request. - * @param {Number} millis Milliseconds to wait - */ - this.setDelay = function(millis) { - delay = millis; - return; - }; - - /** - * Starts this asynchronous request. Any arguments passed to - * this method will be passed to the method executed by - * this AsyncRequest instance. - */ - this.run = function() { - if (arguments.length > 0) { - // convert arguments object into array - args = Array.prototype.slice.call(arguments, 0, arguments.length); - } - thread = (new java.lang.Thread(new java.lang.Runnable({"run": runner}))); - thread.start(); - return; - }; - - /** - * Starts this asynchronous request. - * @deprecated Use {@link #run} instead - */ - this.evaluate = function() { - this.run.apply(this, arguments); - return; - }; - - /** - * Returns true if the underlying thread is alive - * @returns True if the underlying thread is alive, - * false otherwise. - * @type Boolean - */ - this.isAlive = function() { - return thread != null && thread.isAlive(); - } - - /** @ignore */ - this.toString = function() { - return "[jala.AsyncRequest]"; - }; - - /** - * Main constructor body - */ - if (!obj || !funcName) - throw "jala.AsyncRequest: insufficient arguments."; - return this; -} diff --git a/modules/jala/code/BitTorrent.js b/modules/jala/code/BitTorrent.js deleted file mode 100644 index 05ad1311..00000000 --- a/modules/jala/code/BitTorrent.js +++ /dev/null @@ -1,429 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.BitTorrent class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * Module dependencies - */ -app.addRepository("modules/core/String.js"); -app.addRepository("modules/helma/File.js"); - - -/** - * Constructs a new BitTorrent file. - * @class This class provides methods to create a BitTorrent - * metadata file from any desired file. - * @param {String} trackerUrl The URL string of the tracker. - * @param {String} filePath The path to the original file. - * @returns A new BitTorrent file. - * @constructor - */ -jala.BitTorrent = function(filePath, trackerUrl) { - var self = this; - self.arguments = arguments; - - // FIXME: Add support for multitracker mode as specified in - // http://www.bittornado.com/docs/multitracker-spec.txt - - var torrent, sourceFile, torrentFile; - var pieceLength = 256; - - var updateTorrent = function() { - if (torrent.info) { - return torrent; - } - - var file = new java.io.File(filePath); - if (!file.exists()) { - throw Error("File " + file + " does not exist!"); - } - - var md5 = java.security.MessageDigest.getInstance("MD5"); - var sha1 = java.security.MessageDigest.getInstance("SHA-1"); - - var fis = new java.io.FileInputStream(file); - var bis = new java.io.BufferedInputStream(fis); - var cache = new java.io.ByteArrayOutputStream(); - - var pieces = []; - var length = pieceLength * 1024; - var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, length); - - while (bis.read(buffer, 0, buffer.length) > -1) { - app.debug("Updating SHA-1 hash with " + buffer.length + " bytes"); - sha1.reset(); - sha1["update(byte[])"](buffer); - cache["write(byte[])"](buffer); - pieces.push(new java.lang.String(sha1.digest())); - } - - bis.close(); - fis.close(); - - torrent.info = { - //md5sum: new java.lang.String(md5.digest(cache.toByteArray())), - length: cache.size(), - name: file.getName(), - "piece length": length, - pieces: pieces.join("") - }; - - return torrent; - }; - - /** - * Get all available property names. - * @returns The list of property names. - * @type Array - */ - this.keys = function() { - var keys = []; - for (var i in torrent) { - keys.push(i); - } - keys.sort(); - return keys; - }; - - /** - * Get a torrent property. - * @param {String} name The name of the property. - * @returns The value of the property. - */ - this.get = function(name) { - return torrent[name]; - }; - - /** - * Set a torrent property. - * @param {String} name The name of the property. - * @param {Object} value The property's value. - */ - this.set = function(name, value) { - if (typeof torrent[name] == "undefined") { - throw Error("Cannot set torrent property " + name); - } - torrent[name] = value; - delete torrent.info; - return; - }; - - /** - * Get the creation date of the torrent. - * @returns The torrent's creation date. - * @type Date - */ - this.getCreationDate = function() { - return new Date(torrent["creation date"] * 1000); - }; - - /** - * Set the creation date of the torrent. - * @param {Date} date The desired creation date. - */ - this.setCreationDate = function(date) { - this.set("creation date", Math.round((date || new Date()).getTime() / 1000)); - return; - }; - - /** - * Get the piece length of the torrent. - * @returns The torrent's piece length. - * @type Number - */ - this.getPieceLength = function() { - return pieceLength; - }; - - /** - * Set the piece length of the torrent. - * @param {Number} length The desired piece length. - */ - this.setPieceLength = function(length) { - pieceLength = length; - delete torrent.info; - return; - }; - - /** - * Returns the underlying torrent file. - * @returns The torrent file. - * @type helma.File - */ - this.getTorrentFile = function() { - return torrentFile; - }; - - /** - * Returns the underlying source file. - * @returns The source file. - * @type helma.File - */ - this.getSourceFile = function() { - return sourceFile; - }; - - /** - * Saves the torrent as file. - * @param {String} filename An optional name for the torrent file. - * If no name is given it will be composed from name of source - * file as defined in the torrent plus the ending ".torrent". - */ - this.save = function(filename) { - updateTorrent(); - if (!filename) { - filename = torrent.info.name + ".torrent"; - } - torrentFile = new helma.File(sourceFile.getParent(), filename); - torrentFile.remove(); - torrentFile.open(); - torrentFile.write(jala.BitTorrent.bencode(torrent)); - torrentFile.close(); - return; - }; - - /** - * Get a string representation of the torrent. - * @returns The torrent as string. - * @type String - */ - this.toString = function() { - return "[jala.BitTorrent " + filePath + "]"; - }; - - if (String(filePath).endsWith(".torrent")) { - torrentFile = new helma.File(filePath); - torrent = jala.BitTorrent.bdecode(torrentFile.readAll()); - sourceFile = new helma.File(torrent.info.name); - } else { - torrent = { - announce: trackerUrl || null, - "announce-list": null, - "creation date": null, - comment: null, - "created by": null, - }; - this.setCreationDate(); - sourceFile = new helma.File(filePath); - } - - return this; -}; - - -/** - * The bencode method. Turns an arbitrary JavaScript - * object structure into a corresponding encoded - * string. - * @param {Object} obj The target JavaScript object. - * @returns The encoded string. - * @type String - */ -jala.BitTorrent.bencode = function(obj) { - var bencode = arguments.callee; - var str = obj.toString(); - res.push(); - switch (obj.constructor) { - case Array: - res.write("l"); - for (var i in obj) { - if (obj[i]) - res.write(bencode(obj[i])); - } - res.write("e"); - break; - - case Number: - res.write("i" + str + "e"); - break; - - case Object: - res.write("d"); - var keys = []; - for (var i in obj) { - keys.push(i); - } - keys.sort(); - var key; - for (var i in keys) { - key = keys[i]; - if (obj[key]) { - res.write(bencode(key)); - res.write(bencode(obj[key])); - } - } - res.write("e"); - break; - - default: - res.write(str.length + ":" + str); - } - return res.pop(); -}; - - -/** - * The bdecode method. Turns an encoded string into - * a corresponding JavaScript object structure. - * FIXME: Handle with caution... - * @param {String} code The encoded string. - * @returns The decoded JavaScript structure. - * @type Object - */ -jala.BitTorrent.bdecode = function(code) { - var DICTIONARY = "d"; - var LIST = "l"; - var INTEGER = "i"; - var STRING = "s"; - var END = "e"; - - var stack = []; - var overflowCounter = 0; - - var position = -1, current; - - function getResult() { - update(); - var result; - switch (current) { - case DICTIONARY: - result = bdecodeDictionary(); - break; - case LIST: - result = bdecodeList(); - break; - case INTEGER: - result = bdecodeInteger(); - break; - case END: - case null: - //res.debug("*** end detected in getResult()"); - result = null; - break; - default: - result = bdecodeString(); - } - return result; - } - - function update() { - position += 1; - current = code.charAt(position); - /* res.debug("stack: " + stack); - res.debug("position: " + position); - res.debug("current: " + current); - res.debug("remains: " + code.substr(position)); */ - return; - } - - function overflow() { - if (overflowCounter++ > 100) - throw Error("Error parsing bdecoded string"); - return false; - } - - function bdecodeDictionary() { - stack.push(DICTIONARY); - var dictionary = {}, key, value; - while (current && !overflow()) { - key = getResult(); - if (key === null) - break; - value = getResult(); - if (key && value) - dictionary[key] = value; - else - break; - } - stack.pop(); - return dictionary; - } - - function bdecodeList() { - stack.push(LIST); - var list = [], value; - while (current && !overflow()) { - var value = getResult(); - if (value) - list.push(value); - else - break; - } - stack.pop(); - return list; - } - - function bdecodeInteger() { - var integer = ""; - stack.push(integer); - while (current && !overflow()) { - update(); - if (current == "e") - break; - integer += current; - } - if (isNaN(integer)) - throw("Error in bdecoded integer: " + integer + " is not a number"); - //res.debug("integer = " + integer); - stack.pop(); - return parseInt(integer); - } - - function bdecodeString() { - var length = current, string = ""; - stack.push(string); - update(); - while (current && current != ":" && !overflow()) { - length += current; - update(); - } - if (isNaN(length)) - throw("Error in bdecoded string: invalid length " + length); - //res.debug("length = " + length); - length = parseInt(length); - if (length > code.length - position) - throw Error("Error parsing bdecoded string"); - for (var i=0; i - *
  • name (String): The name of the table
  • - *
  • schema (String): The name of the schema the table belongs to
  • - *
  • columns (Array): An array of column metadata (see {@link #getColumns})
  • - *
  • keys (Array): An array containing primary key column names (see {@link #getPrimaryKeys}
  • - * - * @type Array - */ -jala.db.metadata.getTables = function(dbMetadata, tablePattern, schemaPattern) { - var result = []; - var tableMeta = null; - try { - tableMeta = dbMetadata.getTables(null, (schemaPattern || "%"), - (tablePattern || "%"), null); - while (tableMeta.next()) { - var tableName = tableMeta.getString("TABLE_NAME"); - var schemaName = tableMeta.getString("TABLE_SCHEM") || null; - result.push({ - "name": tableName, - "schema": schemaName, - "columns": jala.db.metadata.getColumns(dbMetadata, tableName, schemaName), - "keys": jala.db.metadata.getPrimaryKeys(dbMetadata, tableName, schemaName) - }); - } - return result; - } finally { - if (tableMeta != null) { - tableMeta.close(); - } - } - return null; -}; - -/** - * Returns the column metadata of a table (or multiple tables, if a tableName - * pattern matching several tables is specified). - * @param {java.sql.DatabaseMetaData} dbMetadata The metadata to use for retrieval - * @param {String} tablePattern Optional table name pattern - * @param {String} schemaPattern Optional schema name pattern - * @param {String} columnPattern Optional column name pattern - * @returns An array containing column metadata. Each one is represented by a - * javascript object containing the following properties: - *
      - *
    • name (String): The name of the column
    • - *
    • type (Number): The data type of the column
    • - *
    • length (Number): The maximum length of the column
    • - *
    • nullable (Boolean): True if the column may contain null values, false otherwise
    • - *
    • default (String): The default value of the column
    • - *
    • precision (Number): The precision of the column
    • - *
    • scale (Number): The radix of the column
    • - *
    - * @type Array - */ -jala.db.metadata.getColumns = function(dbMetadata, tablePattern, schemaPattern, columnPattern) { - var result = []; - var columnMeta = null; - try { - columnMeta = dbMetadata.getColumns(null, schemaPattern || null, - tablePattern || null, columnPattern || "%"); - while (columnMeta.next()) { - result.push({ - "name": columnMeta.getString("COLUMN_NAME"), - "type": columnMeta.getInt("DATA_TYPE"), - "length": columnMeta.getInt("COLUMN_SIZE"), - "nullable": (columnMeta.getInt("NULLABLE") == dbMetadata.typeNoNulls) ? false : true, - "default": columnMeta.getString("COLUMN_DEF"), - "precision": columnMeta.getInt("DECIMAL_DIGITS"), - "scale": columnMeta.getInt("NUM_PREC_RADIX") - }); - } - return result; - } finally { - if (columnMeta != null) { - columnMeta.close(); - } - } - return null; -}; - -/** - * Returns an array containing the primary key names of the specified table. - * @param {java.sql.DatabaseMetaData} dbMetadata The metadata to use for retrieval - * @param {String} tableName The name of the table - * @param {String} schemaName Optional name of the schema - * @returns An array containing the primary key column names - * @type Array - */ -jala.db.metadata.getPrimaryKeys = function(dbMetadata, tableName, schemaName) { - var result = []; - var keyMeta = null; - try { - // retrieve the primary keys of the table - var keyMeta = dbMetadata.getPrimaryKeys(null, schemaName || null, tableName); - while (keyMeta.next()) { - result.push(keyMeta.getString("COLUMN_NAME")); - } - return result; - } finally { - if (keyMeta != null) { - keyMeta.close(); - } - } - return null; -}; - - -/** - * Returns the table metadata of the given database. The optional patterns - * can contain "_" for matching a single character or "%" for any - * character sequence. - * @param {helma.Database} database The database to connect to - * @param {String} schemaPattern An optional schema name pattern - * @param {String} tablePattern An optional table name pattern - * @returns An array containing the metadata of all matching tables (see {@link #getTables}) - * @type Array - */ -jala.db.getTableMetadata = function(database, tablePattern, schemaPattern) { - var conn = null; - try { - conn = database.getConnection(); - return jala.db.metadata.getTables(conn.getMetaData(), tablePattern, schemaPattern); - } finally { - if (conn != null) { - conn.close(); - } - } - return null; -}; - - - - -/***************************************** - *** D A T A B A S E S E R V E R *** - *****************************************/ - - -/** - * Returns a new Server instance. - * @class Instances of this class represent a H2 database listener that - * allows multiple databases to be accessed via tcp. - *
    Important: You need the h2.jar in directory "lib/ext" - * of your helma installation for this library to work, which you can get - * at http://www.h2database.com/. - * @param {helma.File} baseDir The directory where the database files - * are located or should be stored - * @param {Number} port The port to listen on (defaults to 9001) - * @param {Boolean} createOnDemand If true this server will create non-existing - * databases on-the-fly, if false it only accepts connections to already - * existing databases in the given base directory - * @param {Boolean} makePublic If true this database is reachable from outside, - * if false it's only reachable from localhost - * @param {Boolean} useSsl If true SSL will be used to encrypt the connection - * @returns A newly created Server instance - * @constructor - */ -jala.db.Server = function(baseDir, port) { - - /** - * Private variable containing the h2 server instance - * @type org.h2.tools.Server - * @private - */ - var server = null; - - /** - * An object containing configuration properties used when creating - * the server instance - * @private - */ - var config = { - "baseDir": baseDir.getAbsolutePath(), - "tcpPort": port || 9092, - "tcpSSL": false, - "ifExists": true, - "tcpAllowOthers": false, - "log": false - }; - - /** - * Returns the wrapped database server instance - * @returns The wrapped database server - * @type org.h2.tools.Server - * @private - */ - this.getServer = function() { - return server; - }; - - /** - * Returns the directory used by this server instance - * @returns The directory where the databases used by this - * server are located in - * @type helma.File - */ - this.getDirectory = function() { - return baseDir; - }; - - /** - * Returns the port this server listens on - * @returns The port this server listens on - * @type Number - */ - this.getPort = function() { - return config.tcpPort; - }; - - /** - * Returns the config of this server - * @returns The config of this server - * @private - */ - this.getConfig = function() { - return config; - }; - - /** - * Starts the database server. - * @returns True in case the server started successfully, false otherwise - * @type Boolean - */ - this.start = function() { - if (server != null && server.isRunning(true)) { - throw "jala.db.Server: already listening on port " + this.getPort(); - } - // convert properties into an array - var config = this.getConfig(); - var args = []; - for (var propName in config) { - args.push("-" + propName); - args.push(config[propName].toString()); - } - // create the server instance - server = Packages.org.h2.tools.Server.createTcpServer(args); - try { - server.start(); - } catch (e) { - app.logger.error("jala.db.Server: unable to start server, reason: " + e); - return false; - } - app.logger.info("jala.db.Server: listening on localhost:" + this.getPort()); - return true; - }; - - - return this; -}; - -/** @ignore */ -jala.db.Server.prototype.toString = function() { - return "[Jala Database Server]"; -}; - -/** - * Stops the database server. - * @returns True if stopping the server was successful, false otherwise - * @type Boolean - */ -jala.db.Server.prototype.stop = function() { - try { - this.getServer().stop(); - app.logger.info("jala.db.Server: stopped listening on localhost:" + - this.getPort()); - } catch (e) { - app.logger.error("jala.db.Server: Unable to stop, reason: " + e); - return false; - } - return true; -}; - -/** - * Returns true if the database server is running. - * @returns True if the database server is running - * @type Boolean - */ -jala.db.Server.prototype.isRunning = function() { - return this.getServer().isRunning(true); -}; - -/** - * Toggles the use of Ssl encryption within this server. This should be set - * before starting the server. - * @param {Boolean} bool If true SSL encryption will be used, false - * otherwise. If no argument is given, this method returns the - * current setting. - * @returns The current setting if no argument is given, or void - * @type Boolean - */ -jala.db.Server.prototype.useSsl = function(bool) { - var config = this.getConfig(); - if (bool != null) { - config.tcpSSL = (bool === true); - } else { - return config.tcpSSL; - } - return; -}; - -/** - * If called with boolean true as argument, this server creates databases - * on-the-fly, otherwise it only accepts connections to already existing - * databases. This should be set before starting the server. - * @param {Boolean} bool If true this server creates non-existing databases - * on demand, if false it only allows connections to existing databases. - * If no argument is given, this method returns the current setting. - * @returns The current setting if no argument is given, or void - * @type Boolean - */ -jala.db.Server.prototype.createOnDemand = function(bool) { - var config = this.getConfig(); - if (bool != null) { - config.ifExists = (bool === false); - } else { - return !config.ifExists; - } - return; -}; - -/** - * If called with boolean true as argument, this server accepts connections - * from outside localhost. This should be set before starting the server. - * @param {Boolean} bool If true this server accepts connections from outside - * localhost. If no argument is given, this method returns the current setting. - * @returns The current setting if no argument is given, or void - * @type Boolean - */ -jala.db.Server.prototype.isPublic = function(bool) { - var config = this.getConfig(); - if (bool != null) { - config.tcpAllowOthers = (bool === true); - } else { - return config.tcpAllowOthers; - } - return; -}; - -/** - * Returns the JDBC Url to use for connections to a given database. - * @param {String} name An optional name of a database running - * @param {Object} props Optional connection properties to add - * @returns The JDBC Url to use for connecting to a database - * within this sever - * @type String - */ -jala.db.Server.prototype.getUrl = function(name, props) { - res.push(); - res.write("jdbc:h2:"); - res.write(this.useSsl() ? "ssl" : "tcp"); - res.write("://localhost:"); - res.write(this.getPort()); - res.write("/"); - res.write(name); - res.write(jala.db.getPropertyString(props)) - return res.pop(); -}; - -/** - * Returns a properties object containing the connection properties - * of the database with the given name. - * @param {String} name The name of the database - * @param {String} username Optional username to use for this connection - * @param {String} password Optional password to use for this connection - * @param {Object} props An optional parameter object containing - * connection properties to add to the connection Url. - * @returns A properties object containing the connection properties - * @type helma.util.ResourceProperties - */ -jala.db.Server.prototype.getProperties = function(name, username, password, props) { - var rp = new Packages.helma.util.ResourceProperties(); - rp.put(name + ".url", this.getUrl(name, props)); - rp.put(name + ".driver", "org.h2.Driver"); - rp.put(name + ".user", username || "sa"); - rp.put(name + ".password", password || ""); - return rp; -}; - -/** - * Returns a connection to a database within this server. - * @param {String} name The name of the database running - * within this server - * @param {String} username Optional username to use for this connection - * @param {String} password Optional password to use for this connection - * @param {Object} props An optional parameter object - * containing connection properties to add to the connection Url. - * @returns A connection to the specified database - * @type helma.Database - */ -jala.db.Server.prototype.getConnection = function(name, username, password, props) { - var rp = this.getProperties(name, username, password, props); - var dbSource = new Packages.helma.objectmodel.db.DbSource(name, rp); - return new helma.Database(dbSource); -}; - - - -/***************************** - *** D A T A T Y P E *** - *****************************/ - - -/** - * Returns a newly created DataType instance. - * @class Instances of this class represent a data type. Each instance - * contains the code number as defined in java.sql.Types, the name of - * the data type as defined in java.sql.Types and optional creation parameters - * allowed for this data type. - * @param {Number} type The sql code number of this data type - * @param {String} typeName The type name of this data type, as used within sql statements - * @param {String} params Optional creation parameters allowed for this data type. - * @returns A newly created instance of DataType. - * @constructor - * @private - */ -jala.db.DataType = function(type, typeName, params) { - - /** - * Returns the sql type code number as defined in java.sql.Types - * @returns The sql type code number of this data type - * @type Number - */ - this.getType = function() { - return type; - }; - - /** - * Returns the type name of this data type, which can be - * used in sql queries. - * @returns The type name of this data type - * @type String - */ - this.getTypeName = function() { - return typeName; - }; - - /** - * Returns the creation parameter string of this data type - * @returns The creation parameter string of this data type - * @type String - */ - this.getParams = function() { - return params; - }; - - /** @ignore */ - this.toString = function() { - return "[DataType " + - " CODE: " + code + - ", SQL: " + sqlType + - ", PARAMS: " + params + "]"; - }; - - return this; -}; - -/** - * Returns true if values for this data type should be surrounded - * by (single) quotes. - * @returns True if values for this data type should be surrounded - * by quotes, false if not - * @type Boolean - */ -jala.db.DataType.prototype.needsQuotes = function() { - switch (this.getType()) { - case java.sql.Types.CHAR: - case java.sql.Types.VARCHAR: - case java.sql.Types.LONGVARCHAR: - case java.sql.Types.BINARY: - case java.sql.Types.VARBINARY: - case java.sql.Types.LONGVARBINARY: - case java.sql.Types.DATE: - case java.sql.Types.TIME: - case java.sql.Types.TIMESTAMP: - return true; - default: - return false; - } -}; - - - -/*********************************** - *** R A M D A T A B A S E *** - ***********************************/ - - -/** - * Returns a newly created RamDatabase instance. - * @class Instances of this class represent an in-memory sql database. - *
    Important: You need the h2.jar in directory "lib/ext" - * of your helma installation for this library to work, which you can get - * at http://www.h2database.com/. - * @param {String} name The name of the database. If not given a private - * un-named database is created, that can only be accessed through this instance - * of jala.db.RamDatabase - * @param {String} username Optional username (defaults to "sa"). This username - * is used when creating the database, so the same should be used when - * creating subsequent instances of jala.db.RamDatabase pointing to a named - * database. - * @param {String} password Optional password (defaults to ""). - * @returns A newly created instance of RamDatabase - * @constructor - */ -jala.db.RamDatabase = function(name, username, password) { - - /** - * Returns the name of the database - * @returns The name of the database - * @type String - */ - this.getName = function() { - return name; - }; - - /** - * Returns the username of this database - * @returns The username of this database - * @type String - */ - this.getUsername = function() { - return username || "sa"; - }; - - /** - * Returns the password of this database - * @returns The password of this database - * @type String - */ - this.getPassword = function() { - return password || ""; - }; - - return; -}; - -/** @ignore */ -jala.db.RamDatabase.prototype.toString = function() { - return "[Jala RamDatabase " + this.getName() + "]"; -} - -/** - * Returns the JDBC Url to connect to this database - * @param {Object} props Optional connection properties to add - * @returns The JDBC url to use for connecting to this database - * @type String - */ -jala.db.RamDatabase.prototype.getUrl = function(props) { - var url = "jdbc:h2:" + this.getDatabasePath(); - if (props != null) { - url += jala.db.getPropertyString(props); - } - return url; -}; - -/** - * Returns the path of this database, which is used by jala.db.Server - * when adding the database to its set of hosted databases. - * @returns The path of this database within a server instance - * @type String - * @private - */ -jala.db.RamDatabase.prototype.getDatabasePath = function() { - return "mem:" + this.getName(); -} - -/** - * Returns a properties object containing the connection properties - * for this database. - * @param {Object} props An optional parameter object containing - * connection properties to add to the connection Url. - * @returns A properties object containing the connection properties - * @type helma.util.ResourceProperties - */ -jala.db.RamDatabase.prototype.getProperties = function(props) { - var name = this.getName(); - var rp = new Packages.helma.util.ResourceProperties(); - rp.put(name + ".url", this.getUrl(props)); - rp.put(name + ".driver", "org.h2.Driver"); - rp.put(name + ".user", this.getUsername()); - rp.put(name + ".password", this.getPassword()); - return rp; -}; - -/** - * Returns a connection to this database - * @param {Object} An optional parameter object containing connection - * properties to add to the connection Url. - * @returns A connection to this database - * @type helma.Database - */ -jala.db.RamDatabase.prototype.getConnection = function(props) { - var name = this.getName(); - var rp = this.getProperties(props); - var dbSource = new Packages.helma.objectmodel.db.DbSource(name, rp); - return new helma.Database(dbSource); -}; - -/** - * Stops this in-process database by issueing a "SHUTDOWN" sql command. - */ -jala.db.RamDatabase.prototype.shutdown = function() { - var conn = this.getConnection(); - conn.execute("SHUTDOWN"); - return; -}; - -/** - * Creates a table in this database. - * @param {String} name The name of the table - * @param {Array} columns The columns to create in the table. Each column - * must be described using an object containing the following properties: - *
      - *
    • name (String): The name of the column
    • - *
    • type (Number): The type of the column as defined in java.sql.Types
    • - *
    • nullable (Boolean): If true the column may contain null values (optional, defaults to true)
    • - *
    • length (Number): The maximum length of the column (optional)
    • - *
    • precision (Number): The precision to use (optional)
    • - *
    • unique (Boolean): If true the column may only contain unique values (optional, defaults to false)
    • - *
    • default (Object): The default value to use (optional)
    • - *
    - * @param {String} primaryKey The name of the column that contains - * the primary key - * @private - */ -jala.db.RamDatabase.prototype.createTable = function(tableName, columns, primaryKey) { - res.push(); - res.write("CREATE TABLE "); - res.write(tableName); - res.write(" ("); - var column, dataType, params; - for (var i=0;i 0) { - res.write("("); - res.write(arr.join(",")); - res.write(")"); - } - } - if (column["default"]) { - res.write(" DEFAULT "); - if (dataType.needsQuotes() === true) { - res.write("'"); - res.write(column["default"]); - res.write("'"); - } else { - res.write(column["default"]); - } - } - if (column.nullable === false) { - res.write(" NOT NULL"); - } - if (i < columns.length - 1) { - res.write(", "); - } - } - if (primaryKey != null) { - res.write(", PRIMARY KEY ("); - if (primaryKey instanceof Array) { - res.write(primaryKey.join(", ")); - } else { - res.write(primaryKey); - } - res.write(")"); - } - res.write(")"); - var sql = res.pop(); - try { - var conn = this.getConnection(); - conn.execute(sql); - app.logger.info("Successfully created table " + tableName); - app.logger.debug("Sql statement used: " + sql); - return true; - } catch (e) { - app.logger.error("Unable to create table " + tableName + ", reason: " + e); - return false; - } -}; - -/** - * Drops the table with the given name - * @param {String} tableName The name of the table - * @returns True if the table was successfully dropped, false otherwise - * @type Boolean - */ -jala.db.RamDatabase.prototype.dropTable = function(tableName) { - var conn = this.getConnection(); - var sql = "DROP TABLE " + tableName; - conn.execute(sql); - return; -}; - -/** - * Returns true if the table exists already in the database - * @param {String} name The name of the table - * @returns True if the table exists, false otherwise - * @type Boolean - */ -jala.db.RamDatabase.prototype.tableExists = function(name) { - var conn = this.getConnection().getConnection(); - var meta = conn.getMetaData(); - var t = meta.getTables(null, "PUBLIC", "%", null); - var tableName; - try { - while (t.next()) { - tableName = t.getString(3).toUpperCase(); - if (tableName.toLowerCase() === name.toLowerCase()) { - return true; - } - } - return false; - } finally { - if (t != null) { - t.close(); - } - } -}; - -/** - * Copies all tables in the database passed as argument into this embedded database. - * If any of the tables already exists in this database, they will be removed before - * re-created. Please mind that this method ignores any indexes in the source database, - * but respects the primary key settings. - * @param {helma.Database} database The database to copy the tables from - * @param {Array} tables An optional array containing the names of the tables to copy. - * If not given all tables are copied - */ -jala.db.RamDatabase.prototype.copyTables = function(database, tables) { - // retrieve the metadata for all tables in this schema - var conn = null; - try { - conn = database.getConnection(); - var dbMetadata = conn.getMetaData(); - if (tables === null || tables === undefined) { - // no tables specified, so copy all available - tables = jala.db.metadata.getTableNames(dbMetadata); - } - - for (let tableName of tables) { - // drop the table if it exists - if (this.tableExists(tableName)) { - this.dropTable(tableName); - } - // retrieve the table metadata and create the table - var metadata = jala.db.metadata.getTables(dbMetadata, tableName); - if (metadata !== null && metadata.length > 0) { - this.createTable(metadata[0].name, metadata[0].columns, metadata[0].keys); - } - } - } finally { - if (conn != null) { - conn.close(); - } - } - return; -}; - -/** - * Returns an array containing all available data types. - * @returns All available data types - * @type Array - * @see jala.db.DataType - * @private - */ -jala.db.RamDatabase.prototype.getDataTypes = function() { - // data types are cached for performance reasons - if (!arguments.callee.cache) { - // java.sql data types - arguments.callee.cache = []; - var con = this.getConnection().getConnection(); - var meta = con.getMetaData(); - var rs = meta.getTypeInfo(); - var code, name, params; - while (rs.next()) { - code = rs.getInt("DATA_TYPE"); - name = rs.getString("TYPE_NAME"); - params = rs.getString("CREATE_PARAMS"); - arguments.callee.cache.push(new jala.db.DataType(code, name, params)); - } - } - return arguments.callee.cache; -}; - -/** - * Returns the data type for the code passed as argument - * @param {Number} type The type code as defined in java.sql.Types - * @returns The data type object for the code - * @type jala.db.DataType - * @private - */ -jala.db.RamDatabase.prototype.getDataType = function(type) { - var types = this.getDataTypes(); - var dataType; - for (var i=0;iImportant: You need the h2.jar in directory "lib/ext" - * of your helma installation for this library to work, which you can get - * at http://www.h2database.com/. - * @param {String} name The name of the database. This name is used as - * prefix for all database files - * @param {helma.File} directory The directory where the database files - * should be stored in. - * @param {String} username Optional username (defaults to "sa"). This username - * is used when creating the database, so the same should be used when - * creating subsequent instances of jala.db.FileDatabase pointing to the - * same database - * @param {String} password Optional password (defaults to ""). - * @returns A newly created FileDatabase instance - * @constructor - */ -jala.db.FileDatabase = function(name, directory, username, password) { - - /** - * Returns the name of the database. This name is used as prefix - * for all files of this database in the specified directory - * @returns The name of the database - * @type String - */ - this.getName = function() { - return name; - }; - - /** - * Returns the directory where the database files are stored. - * @returns The directory where this database is stored. - * @type helma.File - */ - this.getDirectory = function() { - return directory; - }; - - /** - * Returns the username of this database - * @returns The username of this database - * @type String - */ - this.getUsername = function() { - return username || "sa"; - }; - - /** - * Returns the password of this database - * @returns The password of this database - * @type String - */ - this.getPassword = function() { - return password || ""; - }; - - if (!name || typeof(name) != "string" || - !directory || !(directory instanceof helma.File)) { - throw "jala.db.FileDatabase: Missing or invalid arguments" - } else if (!directory.exists()) { - throw "jala.db.FileDatabase: directory '" + directory + "' does not exist"; - } - - return this; -}; -// extend RamDatabase -jala.db.FileDatabase.prototype = new jala.db.RamDatabase(); - -/** @ignore */ -jala.db.FileDatabase.prototype.toString = function() { - return "[Jala FileDatabase '" + this.getName() + "' in " - + this.getDirectory().getAbsolutePath() + "]"; -}; - -/** - * Returns the path of this database, which is used when adding - * the database to a server instance. - * @returns The path of this database within a server instance - * @type String - * @private - */ -jala.db.FileDatabase.prototype.getDatabasePath = function() { - var directory = new helma.File(this.getDirectory(), this.getName()); - return "file:" + directory.getAbsolutePath(); -}; - -/** - * Deletes all files of this database on disk. Note that this also - * closes the database before removing it. - * @returns True in case the database was removed successfully, false otherwise - * @type Boolean - */ -jala.db.FileDatabase.prototype.remove = function() { - var directory = this.getDirectory(); - try { - // shut down the database - this.shutdown(); - Packages.org.h2.tools.DeleteDbFiles.execute( - directory.getAbsolutePath(), - this.getName(), - false - ); - } catch(e) { - app.logger.error("jala.db: Unable to delete database in " + - directory.getAbsolutePath() + ", reason: " + e); - return false; - } - return true; -}; - -/** - * Creates a backup of this database, using the file passed as argument. The - * result will be a zipped file containing the database files - * @param {helma.File} file The file to write the backup to - * @returns True if the database backup was created successfully, false otherwise - * @type Boolean - */ -jala.db.FileDatabase.prototype.backup = function(file) { - try { - Packages.org.h2.tools.Backup.execute( - file.getAbsolutePath(), - this.getDirectory().getAbsolutePath(), - this.getName(), - false - ); - } catch (e) { - app.logger.error("jala.db: Unable to backup database to '" + - file.getAbsolutePath() + ", reason: " + e); - return false; - } - return true; -}; - -/** - * Restores this database using a backup on disk. - * @param {helma.File} backupFile The backup file to use for restore - * @returns True if the database was successfully restored, false otherwise - * @type Boolean - */ -jala.db.FileDatabase.prototype.restore = function(backupFile) { - try { - Packages.org.h2.tools.Restore.execute( - backupFile.getAbsolutePath(), - this.getDirectory().getAbsolutePath(), - this.getName(), - false - ); - } catch (e) { - app.logger.error("jala.db: Unable to restore database using '" + - backupFile.getAbsolutePath() + ", reason: " + e); - return false; - } - return true; -}; diff --git a/modules/jala/code/Date.js b/modules/jala/code/Date.js deleted file mode 100644 index 0a282af1..00000000 --- a/modules/jala/code/Date.js +++ /dev/null @@ -1,545 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - -/** - * @fileoverview Fields and methods of the jala.Date class. - */ - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * HelmaLib dependencies - */ -app.addRepository("modules/core/Date.js"); -app.addRepository("modules/helma/Html.js"); - -/** - * Constructs a new Renderings object. - * @class This class provides various convenience - * methods for rendering purposes. - * @constructor - */ -jala.Date = function() { - return this; -}; - -/** - * Renders a timestamp as set of DropDown boxes, following the - * format passed as argument. Every <select> - * item is prefixed with a string so that it can be retrieved - * easily from the values of a submitted POST request. - * @param {String} prefix The prefix to use for all dropdown boxes, eg. "postdate" - * @param {Date} date A Date object to use as preselection (optional) - * @param {Object} fmt Array containing one parameter object for every single - * select box that should be rendered, with the following properties set: - *
      - *
    • pattern - The date format pattern that should be rendered. Valid - * patterns are: "dd", "MM", "yyyy", "HH", "ss".
    • - *
    • firstOption - The string to use as first option, eg.: "choose a day"
    • - *
    - */ -jala.Date.prototype.renderEditor = function(prefix, date, fmt) { - /** - * rendering method - * @private - */ - var render = function(param, date) { - switch (param.pattern) { - case "dd": - param.offset = 1; - param.max = 31; - param.selected = (date ? date.getDate() : null); - break; - - case "MM": - param.offset = 1; - param.max = 12; - param.selected = (date ? date.getMonth() +1 : null); - break; - - case "yyyy": - param.offset = 2002; - param.max = 20; - param.selected = (date ? date.getFullYear() : null); - break; - - case "HH": - param.offset = 0; - param.max = 24; - param.selected = (date ? date.getHours() : null); - break; - - case "mm": - param.offset = 0; - param.max = 60; - param.selected = (date ? date.getMinutes() : null); - break; - - case "ss": - param.offset = 0; - param.max = 60; - param.selected = (date ? date.getSeconds() : null); - break; - } - - var key = prefix + ":" + param.pattern; - if (req.data[key]) - param.selected = req.data[key]; - var options = []; - var opt; - for (var i=0;i days) { - renderer.renderDay(null); - } else { - date.setDate(daycnt); - if ((dayObj = collection.get(date.format(accessNameFormat))) != null) { - idx = collection.contains(dayObj); - if (idx > -1) { - if (idx > firstDayIndex) { - firstDayIndex = idx; - } - if (idx < lastDayIndex) { - lastDayIndex = idx; - } - } - } - selected = (today != null) ? date.equals(today) : false; - renderer.renderDay(date, dayObj != null, selected); - daycnt++; - } - } - renderer.renderRow(res.pop()); - } - var prevMonth = prevNextMonth("prev", firstDayIndex) || null; - var nextMonth = prevNextMonth("next", lastDayIndex) || null; - renderer.renderCalendar(date, res.pop(), prevMonth, nextMonth); - return; -}; - -/** - * Returns a rendered calendar - * @see #renderCalendar - * @type String - */ -jala.Date.Calendar.prototype.getCalendar = function(today) { - res.push(); - this.render(today); - return res.pop(); -}; - -/** - * Returns a new instance of the default calendar renderer. - * @class A default renderer to use in conjunction with jala.Date.Calendar - * @param {jala.Date.Calendar} calendar The calendar utilizing this renderer - * @returns A newly created instance of jala.Date.Calendar.Renderer - * @constructor - */ -jala.Date.Calendar.Renderer = function(calendar) { - - /** - * An instance of helma.Html used for rendering the calendar - * @type helma.Html - */ - this.html = new helma.Html(); - - /** - * The calendar utilizing this renderer instance - * @type jala.Date.Calendar - */ - this.calendar = calendar; - - return this; -}; - -/** @ignore */ -jala.Date.Calendar.Renderer.prototype.toString = function() { - return "[Jala Calendar Default Renderer]"; -}; - -/** - * Renders a single cell in the calendar day header row directly to response. - * @param {String} text The text to display in the header field. - */ -jala.Date.Calendar.Renderer.prototype.renderDayHeader = function(text) { - this.html.element("th", text); - return; -}; - -/** - * Renders a single calendar row directly to response. - * @param {String} row The body of the calendar row. - */ -jala.Date.Calendar.Renderer.prototype.renderRow = function(row) { - this.html.element("tr", row); - return; -}; - -/** - * Renders a single day within the calendar directly to response. - * @param {Date} date A date instance representing the day within the calendar. - * @param {Boolean} isExisting True if there is a child object in the calendar's - * collection to which the date cell should link to - * @param {Boolean} isSelected True if this calendar day should be rendered - * as selected day. - */ -jala.Date.Calendar.Renderer.prototype.renderDay = function(date, isExisting, isSelected) { - var attr = {"class": "jala-calendar-day day"}; - if (isSelected === true) { - attr["class"] += " jala-calendar-selected selected"; - } - this.html.openTag("td", attr); - if (date != null) { - var text = date.getDate(); - if (isExisting === true) { - attr = {"href": this.calendar.getCollection().href() + - date.format(this.calendar.getHrefFormat())}; - this.html.link(attr, text); - } else { - res.write(text); - } - } - this.html.closeTag("td"); - return; -}; - -/** - * Renders a link to the previous or next month's calendar directly to response. - * @param {Date} date A date object set to the previous or next available - * month. This can be null in case there is no previous or next month. - */ -jala.Date.Calendar.Renderer.prototype.renderPrevNextLink = function(date) { - if (date != null) { - var attr = {"href": this.calendar.getCollection().href() + - date.format(this.calendar.getHrefFormat())}; - this.html.link(attr, date.format("MMMM", this.calendar.getLocale())); - } - return; -}; - -/** - * Renders the calendar directly to response. - * @param {Date} date A date object representing this calendar's month and year. - * Please mind that the day will be set to the last date in this - * month. - * @param {String} body The rendered calendar weeks including the day header - * (basically the whole kernel of the table). - * @param {Date} prevMonth A date object set to the last available date of - * the previous month. This can be used to render a navigation link to - * the previous month. - * @param {Date} nextMonth A date object set to the first available date - * of the next month. This can be used to render a navigation link to - * the next month. - */ -jala.Date.Calendar.Renderer.prototype.renderCalendar = function(date, body, prevMonth, nextMonth) { - var locale = this.calendar.getLocale(); - this.html.openTag("table", {"class": "jala-calendar calendar"}); - this.html.openTag("thead"); - this.html.openTag("tr"); - this.html.openTag("th", {"colspan": 7}); - res.write(date.format("MMMM", locale)); - res.write(' '); - res.write(date.format("yyyy", locale)); - this.html.closeTag("th"); - this.html.closeTag("tr"); - this.html.closeTag("thead"); - this.html.element("tbody", body); - this.html.openTag("tfoot"); - this.html.openTag("tr"); - this.html.openTag("td", {"class": "jala-calendar-left left", "colspan": 3}); - this.renderPrevNextLink(prevMonth); - this.html.closeTag("td"); - this.html.openTag("td"); - this.html.closeTag("td"); - this.html.openTag("td", {"class": "jala-calendar-right right", "colspan": 3}); - this.renderPrevNextLink(nextMonth); - this.html.closeTag("td"); - this.html.closeTag("tr"); - this.html.closeTag("tfoot"); - this.html.closeTag("table"); - return; -}; - -/** - * Default date class instance. - * @type jala.Date - * @final - */ -jala.date = new jala.Date(); diff --git a/modules/jala/code/DnsClient.js b/modules/jala/code/DnsClient.js deleted file mode 100644 index 810cf15b..00000000 --- a/modules/jala/code/DnsClient.js +++ /dev/null @@ -1,312 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.DnsClient class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * Jala dependencies - */ -app.addRepository(getProperty("jala.dir", "modules/jala") + - "/lib/javadns.jar"); - -/** - * Constructs a new DnsClient object. - * @class This is a wrapper around the Dns Client by wonderly.org - * providing methods for querying Dns servers. For more information - * about the Java DNS client visit - * https://javadns.dev.java.net/. - * Please mind that the nameserver specified must accept queries on port - * 53 TCP (the Java DNS client used doesn't support UDP nameserver queries), - * and that reverse lookups are not supported. - * @param {String} nameServer IP-Address or FQDN of nameserver to query - * @constructor - */ -jala.DnsClient = function(nameServer) { - /** - * Contains the IP Adress/FQDN of the name server to query. - * @type String - */ - this.nameServer = nameServer; - - if (!this.nameServer) { - throw "jala.DnsClient: missing nameserver argument"; - } else { - // test if required javadns library is available - try { - var clazz = java.lang.Class.forName("org.wonderly.net.dns.Query", - false, app.getClassLoader()) - } catch (e) { - throw "jala.DnsClient requires JavaDNS.jar" - + " in lib/ext or application directory " - + "[https://javadns.dev.java.net/]"; - } - } - - return this; -}; - -/** @ignore */ -jala.DnsClient.PKG = Packages.org.wonderly.net.dns; - -/** - * The "A" record/query type. - * @type Number - * @final - */ -jala.DnsClient.TYPE_A = jala.DnsClient.PKG.Question.TYPE_A; - -/** - * The "CNAME" record/query type. - * @type Number - * @final - */ -jala.DnsClient.TYPE_CNAME = jala.DnsClient.PKG.Question.TYPE_CNAME; - -/** - * The "MX" record/query type. - * @type Number - * @final - */ -jala.DnsClient.TYPE_MX = jala.DnsClient.PKG.Question.TYPE_MX; - -/** - * The "NS" record/query type. - * @type Number - * @final - */ -jala.DnsClient.TYPE_NS = jala.DnsClient.PKG.Question.TYPE_NS; - -/** - * The "PTR" record/query type. - * @type Number - * @final - */ -jala.DnsClient.TYPE_PTR = jala.DnsClient.PKG.Question.TYPE_PTR; - -/** - * The "SOA" record/query type. - * @type Number - * @final - */ -jala.DnsClient.TYPE_SOA = jala.DnsClient.PKG.Question.TYPE_SOA; - -/** - * The "TXT" record/query type. - * @type Number - * @final - */ -jala.DnsClient.TYPE_TXT = jala.DnsClient.PKG.Question.TYPE_TXT; - -/** - * The "WKS" record/query type. - * @type Number - * @final - */ -jala.DnsClient.TYPE_WKS = jala.DnsClient.PKG.Question.TYPE_WKS; - -/** - * Queries the nameserver for a specific domain - * and the given type of record. - * @param {String} dName The domain name to query for - * @param {Number} queryType The type of records to retrieve - * @returns The records retrieved from the nameserver - * @type org.wonderly.net.dns.RR - */ -jala.DnsClient.prototype.query = function(dName, queryType) { - if (dName == null) { - throw new Error("no domain-name to query for"); - } - if (queryType == null) { - queryType = jala.DnsClient.TYPE_A; - } - // construct the question for querying the nameserver - var question = new jala.DnsClient.PKG.Question(dName, - queryType, - jala.DnsClient.PKG.Question.CLASS_IN); - // construct the query - var query = new jala.DnsClient.PKG.Query(question); - // run the query - query.runQuery(this.nameServer); - // wrap the records received in instances of jala.DnsClient.Record - var answers = query.getAnswers(); - var arr = []; - for (var i=0;i<% param.label prefix=' ' suffix='\n' %><% param.controls prefix=' ' suffix='\n' %><% param.help prefix=' ' suffix='\n' %>"); - - /** - * Contains a map of component objects. - * @type Object - */ - this.components = {}; - - /** - * Returns an array containing the components - * of this jala.Form instance. - * @returns The components of this jala.Form instance. - * @type Array - */ - this.listComponents = function() { - return components; - }; - - /** - * Adds a component to this jala.Form instance - * @param {jala.Form.Component.Input} component - */ - this.addComponent = function(component) { - component.setForm(this); - components.push(component); - this.components[component.name] = component; - return; - }; - - /** - * Returns true if this instance of jala.Form contains at least - * one component doing a file upload. - * @see jala.Form.Component#containsFileUpload - * @type Boolean - */ - this.containsFileUpload = function() { - for (var i=0; ithe name of the element
  • - *
  • the parsed value of the element if all requirements have - * been fulfilled. E.g., for a date editor, the parsed value would - * be a date object.
  • - *
  • the map containing all user inputs as string (req.data)
  • - *
  • the form object
  • - * @see #validate - * @type Function - */ - this.validator; - - this.__defineGetter__("validator", function() { return validator; }); - this.__defineSetter__("validator", function(newValidator) { - if (newValidator instanceof Function) { - validator = newValidator; - } else { - throw "Invalid argument: validator must be a function"; - } - return; - }); - - return this; -}; -// extend jala.Form.Component -jala.Form.extend(jala.Form.Component.Input, jala.Form.Component); - -/** - * Validates the input provided to this component. First, - * checkRequirements is called. If no error occurs, the input - * is parsed using parseValue and passed on to the validator - * function. - * @see #checkRequirements - * @see #parseValue - * @param {jala.Form.Tracker} tracker Tracker object collecting - * request data, error messages and parsed values. - */ -jala.Form.Component.Input.prototype.validate = function(tracker) { - var error = this.checkRequirements(tracker.reqData); - if (error != null) { - tracker.errors[this.name] = error; - } else { - tracker.values[this.name] = this.parseValue(tracker.reqData); - if (this.validator) { - error = this.validator.call( - this.form.getDataObject(), - this.name, - tracker.values[this.name], - tracker.reqData, - this.form - ); - if (error != null) { - tracker.errors[this.name] = error; - } - } - } - return; -}; - -/** - * Saves the parsed value using setValue. - * @see #setValue - * @param {jala.Form.Tracker} tracker Tracker object collecting - * request data, error messages and parsed values. - * @param {Object} destObj (optional) object whose values will be changed. - */ -jala.Form.Component.Input.prototype.save = function(tracker, destObj) { - this.setValue(destObj, tracker.values[this.name]); - return; -}; - -/** - * Retrieves the property which is edited by this component. - *
      - *
    • If no getter is given, the method returns the primitive property - * of the data object with the same name as the component.
    • - *
    • If a getter function is defined, it is executed with the scope - * of the data object and the return value is used as default value. - * The name of the component is passed to the getter function - * as an argument.
    • - *
    - * @returns The value of the property - * @type String|Number|Date - */ -jala.Form.Component.Input.prototype.getValue = function() { - if (this.form.getTracker()) { - // handling re-rendering - return null; - } else { - var getter = (this.getter) ? this.getter : this.form.getter; - return getter.call(this.form.getDataObject(), this.name); - } -}; - -/** - * Sets a property of the object passed as argument to the given value. - *
  • If no setter is set at the component, the primitive property - * of the data object is changed.
  • - *
  • If a setter function is defined it is executed with the data object - * as scope and with the name and new value provided as arguments
  • - *
  • If the setter is explicitly set to null, no changes are made at all.
  • - * @param {Object} destObj (optional) object whose values will be changed. - * @param {Object} value The value to set the property to - * @returns True in case the update was successful, false otherwise. - * @see jala.Form#setter - */ -jala.Form.Component.Input.prototype.setValue = function(destObj, value) { - // default value for this.setter is undefined, so if it has been - // set to explicitly null, we don't save the value. in this case, - // we assume, the property is handled outside of jala.Form or purposely - // ignored at all. - if (this.setter !== null) { - var setter = (this.setter) ? this.setter : this.form.setter; - setter.call(destObj, this.name, value); - } - return; -}; - -/** - * Renders this component including label, error and help messages directly - * to response. - */ -jala.Form.Component.Input.prototype.render = function() { - var className = (this.getRequirement(jala.Form.REQUIRE) == true) ? "require" : "optional"; - if (this.getClassName()) { - className += " " + this.getClassName(); - } - var tracker = this.form.getTracker(); - if (tracker && tracker.errors[this.name]) { - className += " error"; - } - - jala.Form.html.openTag("div", - {id: this.createDomId(), - "class": "component " + className} - ); - res.write("\n"); - renderSkin(this.form.componentSkin, this); - jala.Form.html.closeTag("div"); - res.write("\n"); - return; -}; - -/** - * If the error tracker holds an error message for this component, - * it is wrapped in a div-tag and returned as a string. - * @returns Rendered string - * @type String - */ -jala.Form.Component.Input.prototype.renderError = function() { - var tracker = this.form.getTracker(); - if (tracker && tracker.errors[this.name]) { - return jala.Form.html.elementAsString("div", - tracker.errors[this.name], - {"class": "errorText"} - ); - } - return null; -}; - -/** - * Returns the rendered label of this component - * @returns The rendered label of this component - * @type String - */ -jala.Form.Component.Input.prototype.renderLabel = function() { - return jala.Form.html.elementAsString( - "label", - this.getLabel() || "", - {"for": this.createDomId("control")} - ); -}; - -/** - * If this component contains a help message, it is wrapped in - * a div-tag and returned as a string. - * @returns The rendered help message - * @type String - */ -jala.Form.Component.Input.prototype.renderHelp = function() { - var help = this.getHelp(); - if (help) { - return jala.Form.html.elementAsString( - "div", - help, - {"class": "helpText"} - ); - } - return null; -}; - - -/** - * Renders this component including label, error and help messages - * directly to response - */ -jala.Form.Component.Input.prototype.render_macro = function() { - this.render(); - return; -}; - -/** - * Renders the control(s) of this component - */ -jala.Form.Component.Input.prototype.controls_macro = function() { - var attr = this.getControlAttributes(); - var tracker = this.form.getTracker() - if (tracker) { - this.renderControls(attr, null, tracker.reqData); - } else { - this.renderControls(attr, this.getValue()); - } - return; -}; - -/** - * Renders this component's error message (if set) directly to response - */ -jala.Form.Component.Input.prototype.error_macro = function() { - res.write(this.renderError()); - return; -}; - -/** - * Renders this component's label. - */ -jala.Form.Component.Input.prototype.label_macro = function() { - res.write(this.renderLabel()); - return; -}; - -/** - * Renders this component's help text, if set. - */ -jala.Form.Component.Input.prototype.help_macro = function() { - res.write(this.renderHelp()); - return; -}; - -/** - * Renders this component's id - * @see jala.Form#createDomId - */ -jala.Form.Component.Input.prototype.id_macro = function() { - res.write(this.createDomId()); - return; -}; - -/** - * Renders this component's name - */ -jala.Form.Component.Input.prototype.name_macro = function() { - res.write(this.name); - return; -}; - -/** - * Renders this component's type - */ -jala.Form.Component.Input.prototype.type_macro = function() { - res.write(this.getType()); - return; -}; - -/** - * Renders this component's class name. - * Note that this is just the class name that has been explicitly - * assigned using setClassName. - * @see #setClassName - */ -jala.Form.Component.Input.prototype.class_macro = function() { - var className = this.getClassName(); - if (className) { - res.write(className); - } - return; -}; - - -/** - * Creates a new attribute object for this element. - * @returns Object with properties id, name, class - * @type Object - */ -jala.Form.Component.Input.prototype.getControlAttributes = function() { - var attr = { - id: this.createDomId("control"), - name: this.name, - "class": this.getType() - }; - if (this.getClassName()) { - attr["class"] += " " + this.getClassName(); - } - return attr; -}; - -/** - * Checks user input for maximum length, minimum length and require - * if the corresponding options have been set using the require method. - * @param {Object} reqData request data - * @returns String containing error message or null if everything is ok. - * @type String - * @see #require - */ -jala.Form.Component.Input.prototype.checkLength = function(reqData) { - var require = this.getRequirement(jala.Form.REQUIRE); - var minLength = this.getRequirement(jala.Form.MINLENGTH); - var maxLength = this.getRequirement(jala.Form.MAXLENGTH); - - if (require && (reqData[this.name] == null || reqData[this.name].trim() == "")) { - return this.getMessage(jala.Form.REQUIRE, "Please enter text into this field."); - } else if (maxLength && reqData[this.name].length > maxLength) { - return this.getMessage(jala.Form.MAXLENGTH, "Input for this field is too long ({0} characters). Please enter no more than {1} characters.", - reqData[this.name].length, maxLength); - } else if (minLength) { - // set an error if the element is required but the input is too short - // but don't throw an error if the element is optional and empty - if (reqData[this.name].length < minLength && - (require || (!require && reqData[this.name].length > 0))) { - return this.getMessage(jala.Form.MINLENGTH, "Input for this field is too short ({0} characters). Please enter at least {1} characters.", - reqData[this.name].length, minLength); - } - } - return null; -}; - -/** - * Checks user input against options set using the require method. - * @param {Object} reqData request data - * @returns String containing error message or null if everything is ok. - * @type String - * @see #checkLength - * @see #require - */ -jala.Form.Component.Input.prototype.checkRequirements = function(reqData) { - return this.checkLength(reqData); -}; - -/** - * Parses the string input from the form and creates the datatype that - * is edited with this component. For the input component this method - * is not of much use, but subclasses that edit other datatypes may use - * it. For example, a date editor should convert the user input from string - * to a date object. - * @param {Object} reqData request data - * @returns parsed value - * @type Object - */ -jala.Form.Component.Input.prototype.parseValue = function(reqData) { - return reqData[this.name]; -}; - -/** - * Renders the html form elements to the response. - * This method shall be overridden by subclasses of input component. - * @param {Object} attr Basic attributes for the html form elements. - * @param {Object} value Value to be used for rendering this element. - * @param {Object} reqData Request data for the whole form. This argument is - * passed only if the form is re-rendered after an error occured. - */ -jala.Form.Component.Input.prototype.renderControls = function(attr, value, reqData) { - attr.value = (reqData) ? reqData[this.name] : value; - if (this.getRequirement(jala.Form.MAXLENGTH)) { - attr.maxlength = this.getRequirement(jala.Form.MAXLENGTH); - } - jala.Form.html.input(attr); - return; -}; - -/** - * Constructs a newly created Password component instance - * @class Subclass of jala.Form.Component.Input which renders and validates a - * password input tag. - * @base jala.Form.Component.Input - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Password component instance - * @constructor - */ -jala.Form.Component.Password = function Password(name) { - jala.Form.Component.Password.superConstructor.apply(this, arguments); - return this; -}; -// extend jala.Form.Component.Input -jala.Form.extend(jala.Form.Component.Password, jala.Form.Component.Input); - -/** - * Renders a password input tag to the response. - * @param {Object} attr Basic attributes for this element. - * @param {Object} value Value to be used for rendering this element. - * @param {Object} reqData Request data for the whole form. This argument is - * passed only if the form is re-rendered after an error occured. - */ -jala.Form.Component.Password.prototype.renderControls = function(attr, value, reqData) { - attr.value = (reqData) ? reqData[this.name] : value; - if (this.getRequirement(jala.Form.MAXLENGTH)) { - attr.maxlength = this.getRequirement(jala.Form.MAXLENGTH); - } - jala.Form.html.password(attr); - return; -}; - -/** - * Constructs a newly created Hidden component instance - * @class Subclass of jala.Form.Component.Input which renders and validates a - * hidden input tag. - * @base jala.Form.Component.Input - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Hidden component instance - * @constructor - */ -jala.Form.Component.Hidden = function Hidden(name) { - jala.Form.Component.Hidden.superConstructor.apply(this, arguments); - return this; -}; -// extend jala.Form.Component.Input -jala.Form.extend(jala.Form.Component.Hidden, jala.Form.Component.Input); - -/** - * Renders this component directly to response. For a hidden tag, this is - * just an input element, no div tag or anything. - */ -jala.Form.Component.Hidden.prototype.render = function() { - var attr = this.getControlAttributes(); - var tracker = this.form.getTracker() - if (tracker) { - this.renderControls(attr, null, tracker.reqData); - } else { - this.renderControls(attr, this.getValue()); - } - return; -}; - -/** - * Renders a hidden input tag to the response. - * @param {Object} attr Basic attributes for this element. - * @param {Object} value Value to be used for rendering this element. - * @param {Object} reqData Request data for the whole form. This argument is - * passed only if the form is re-rendered after an error occured. - */ -jala.Form.Component.Hidden.prototype.renderControls = function(attr, value, reqData) { - attr.value = (reqData) ? reqData[this.name] : value; - jala.Form.html.hidden(attr); - return; -}; - -/** - * Constructs a new Textarea component. - * @class Subclass of jala.Form.Component.Input which renders and validates a - * textarea input field. - * @base jala.Form.Component.Input - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Textarea component instance - * @constructor - */ -jala.Form.Component.Textarea = function Textarea(name) { - jala.Form.Component.Textarea.superConstructor.apply(this, arguments); - - var rows, cols = undefined; - - /** - * Returns the row numbers for this component. - * @returns row numbers - * @type String - */ - this.getRows = function() { - return rows; - }; - - /** - * Sets the row numbers for this component. - * @param {String} newRows new row numbers - */ - this.setRows = function(newRows) { - rows = newRows; - return; - }; - - /** - * Returns the col numbers for this component. - * @returns col numbers - * @type String - */ - this.getCols = function() { - return cols; - }; - - /** - * Sets the col numbers for this component. - * @param {String} newCols new col numbers - */ - this.setCols = function(newCols) { - cols = newCols; - return; - }; - - return this; -}; -// extend jala.Form.Component.Input -jala.Form.extend(jala.Form.Component.Textarea, jala.Form.Component.Input); - -/** - * Renders a textarea input field to the response. - * @param {Object} attr Basic attributes for this element. - * @param {Object} value Value to be used for rendering this element. - * @param {Object} reqData Request data for the whole form. This argument is - * passed only if the form is re-rendered after an error occured. - */ -jala.Form.Component.Textarea.prototype.renderControls = function(attr, value, reqData) { - attr.value = (reqData) ? reqData[this.name] : value; - attr.rows = this.getRows() || 5; - attr.cols = this.getCols() || 25; - jala.Form.html.textArea(attr); - return; -}; - -/** - * Constructs a new Date component instance - * @class Subclass of jala.Form.Component.Input which renders and validates a - * date editor. - * @base jala.Form.Component.Input - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Date component - * @constructor - */ -jala.Form.Component.Date = function Date(name) { - jala.Form.Component.Date.superConstructor.apply(this, arguments); - - var dateFormat = "d.M.yyyy H:m"; - var dateFormatObj; - - /** - * Returns the date format for this component. - * @returns date format object - * @type java.text.SimpleDateFormat - */ - this.getDateFormat = function() { - if (!dateFormatObj || dateFormatObj.toPattern() != dateFormat) { - dateFormatObj = new java.text.SimpleDateFormat(dateFormat); - } - return dateFormatObj; - }; - - /** - * Sets the date format for this component. - * @param {String} newDateFormat new date format - */ - this.setDateFormat = function(newDateFormat) { - dateFormat = newDateFormat; - return; - }; - - return this; -}; -// extend jala.Form.Component.Input -jala.Form.extend(jala.Form.Component.Date, jala.Form.Component.Input); - -/** - * Renders a textarea tag to the response. - * @param {Object} attr Basic attributes for this element. - * @param {Object} value Value to be used for rendering this element. - * @param {Object} reqData Request data for the whole form. This argument is - * passed only if the form is re-rendered after an error occured. - */ -jala.Form.Component.Date.prototype.renderControls = function(attr, value, reqData) { - if (reqData) { - attr.value = reqData[this.name]; - } else if (value instanceof Date) { - attr.value = this.getDateFormat().format(value); - } - if (this.getRequirement(jala.Form.MAXLENGTH)) { - attr.maxlength = this.getRequirement(jala.Form.MAXLENGTH); - } - jala.Form.html.input(attr); - return; -}; - -/** - * Validates user input from a date editor. - * @param {Object} reqData request data - * @returns null if everything is ok or string containing error message - * @type String - */ -jala.Form.Component.Date.prototype.checkRequirements = function(reqData) { - try { - this.parseValue(reqData); - return null; - } catch(e) { - return this.getMessage("invalid", "This date cannot be parsed."); - } -}; - -/** - * Parses the string input from the form and converts it to a date object. - * Throws an error if the string cannot be parsed. - * @param {Object} reqData request data - * @returns parsed date value - * @type Date - */ -jala.Form.Component.Date.prototype.parseValue = function(reqData) { - return this.getDateFormat().parse(reqData[this.name]); -}; - -/** - * Constructs a new Select component instance - * @class Subclass of jala.Form.Component.Input which renders and validates a - * dropdown element. - * @base jala.Form.Component.Input - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Select component - * @constructor - */ -jala.Form.Component.Select = function Select(name) { - jala.Form.Component.Select.superConstructor.apply(this, arguments); - - var options, firstOption = undefined; - - /** - * Returns the option list for this component. - */ - this.getOptions = function() { - return options; - }; - - /** - * Sets the option list for this component. - * The argument may either be an array that will be used as option list, - * or a function that is called when the option component is rendered and - * has to return an option array. - * For both arrays those formats are allowed: - *
  • Array of arrays [ [val, display], [val, display], .. ]
  • - *
  • Array of objects [ {value:val, display:display}, .. ]
  • - *
  • Array of strings [ display, display, .. ] In this case, - * the index position of the string will be the value.
  • - * @param {Array|Function} newOptions Array or function defining option list. - */ - this.setOptions = function(newOptions) { - options = newOptions; - return; - }; - - /** - * Returns the text that should be displayed if no value is selected. - * @type String - */ - this.getFirstOption = function() { - return firstOption; - }; - - /** - * Sets the text that is displayed if no value is selected - * @param {String} newFirstOption text to display as first option element. - */ - this.setFirstOption = function(newFirstOption) { - firstOption = newFirstOption; - return; - }; - - return this; -}; -// extend jala.Form.Component.Input -jala.Form.extend(jala.Form.Component.Select, jala.Form.Component.Input); - -/** - * Renders a dropdown element to the response. - * @param {Object} attr Basic attributes for this element. - * @param {Object} value Value to be used for rendering this element. - * @param {Object} reqData Request data for the whole form. This argument is - * passed only if the form is re-rendered after an error occured. - */ -jala.Form.Component.Select.prototype.renderControls = function(attr, value, reqData) { - value = (reqData) ? reqData[this.name] : value; - jala.Form.html.dropDown(attr, this.parseOptions(), value, this.getFirstOption()); - return; -}; - -/** - * Validates user input from a dropdown element by making sure that - * the option value list contains the user input. - * @see jala.Form.Component.Select#checkOptions - * @param {Object} reqData request data - * @returns string containing error message or null if everything is ok. - * @type String - */ -jala.Form.Component.Select.prototype.checkRequirements = function(reqData) { - return this.checkOptions(reqData); -}; - -/** - * Creates an array of options for a dropdown element or a - * group of radiobuttons. If options field of this element's - * config is an array, that array is returned. - * If options is a function, its return value is returned. - * @returns array of options - * @type Array - */ -jala.Form.Component.Select.prototype.parseOptions = function() { - var options = this.getOptions(); - if (options != null) { - if (options instanceof Array) { - return options; - } else if (options instanceof Function) { - return options.call(this.form.getDataObject(), this.name); - } - } - return []; -}; - -/** - * Checks user input for optiongroups: Unless require("checkoptions") - * has ben set to false, the user input must exist in the option array. - * @param {Object} reqData request data - * @returns null if everything is ok or string containing error message - * @type String - */ -jala.Form.Component.Select.prototype.checkOptions = function(reqData) { - // if field is required, an empty option is not allowed: - var found = (!this.getRequirement(jala.Form.REQUIRE) && !reqData[this.name]); - if (!found) { - if (this.getRequirement(jala.Form.CHECKOPTIONS) === false) { - // exit, if option check shall be suppressed - return null; - } - var options = this.parseOptions(); - var val = reqData[this.name]; - for (var i=0; i 0) { - // option is an array (1st element = value, 2nd = display) - if (options[i][0] == reqData[this.name]) { - found = true; - break; - } - } else if (options[i].value && options[i].display) { - // option is an object with fields value + display - if (options[i].value == reqData[this.name]) { - found = true; - break; - } - } else { - // option is a string, value is index number - if (i == reqData[this.name]) { - found = true; - break; - } - } - } - } - if (!found) { - return "Please select a valid option."; - } - return null; -}; - -/** - * Creates a new Radio component instance - * @class Subclass of jala.Form.Component.Input which renders and validates a - * set of radio buttons. - * @base jala.Form.Component.Select - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Radio component - * @constructor - */ -jala.Form.Component.Radio = function Radio(name) { - jala.Form.Component.Radio.superConstructor.apply(this, arguments); - return this; -}; -// extend jala.Form.Component.Select -jala.Form.extend(jala.Form.Component.Radio, jala.Form.Component.Select); - -/** - * Renders a set of radio buttons to the response. - * @param {Object} attr Basic attributes for this element. - * @param {Object} value Value to be used for rendering this element. - */ -jala.Form.Component.Radio.prototype.renderControls = function(attr, value) { - var options = this.parseOptions(); - var optionAttr, optionDisplay; - for (var i=0; i 0) { - optionAttr.value = options[i][0]; - optionDisplay = options[i][1]; - } else if (options[i].value && options[i].display) { - optionAttr.value = options[i].value; - optionDisplay = options[i].display; - } else { - optionAttr.value = i; - optionDisplay = options[i]; - } - if (String(value) == String(optionAttr.value)) { - optionAttr.checked = "checked"; - } - jala.Form.html.radioButton(optionAttr); - res.write(optionDisplay); - jala.Form.html.tag("br"); - } - return; -}; - -/** - * Validates user input from a set of radio buttons and makes sure that - * option value list contains the user input. - * @see jala.Form.Component.Select#checkOptions - * @param {Object} reqData request data - * @returns null if everything is ok or string containing error message - * @type String - */ -jala.Form.Component.Radio.prototype.checkRequirements = function(reqData) { - return this.checkOptions(reqData); -}; - -/** - * Creates a new Checkbox component instance - * @class Subclass of jala.Form.Component.Input which renders and validates a - * checkbox. - * @base jala.Form.Component.Input - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Checkbox component instance - * @constructor - */ -jala.Form.Component.Checkbox = function Checkbox(name) { - jala.Form.Component.Checkbox.superConstructor.apply(this, arguments); - return this; -}; -// extend jala.Form.Component.Input -jala.Form.extend(jala.Form.Component.Checkbox, jala.Form.Component.Input); - -/** - * Renders an checkbox to the response. - * @param {Object} attr Basic attributes for this element. - * @param {Object} value Value to be used for rendering this element. - */ -jala.Form.Component.Checkbox.prototype.renderControls = function(attr, value, reqData) { - if (value == 1 || (reqData && reqData[this.name] == "1")) { - attr.checked = "checked"; - } - attr.value = "1"; - jala.Form.html.checkBox(attr); - return; -}; - -/** - * Parses the string input from the form. For a checked box, the value is 1, - * for an unchecked box the value is 0. - * @param {Object} reqData request data - * @returns parsed value - * @type Number - */ -jala.Form.Component.Checkbox.prototype.parseValue = function(reqData) { - return (reqData[this.name] == "1") ? 1 : 0; -}; - -/** - * Validates user input from checkbox. - * @param {Object} reqData request data - * @returns null if everything is ok or string containing error message - * @type String - */ -jala.Form.Component.Checkbox.prototype.checkRequirements = function(reqData) { - if (reqData[this.name] && reqData[this.name] != "1") { - return this.getMessage("invalid", "The value of this checkbox is invalid."); - } - return null; -}; - -/** - * Creates a new File component instance - * @class Subclass of jala.Form.Component.Input which renders and validates a - * file upload. - * @base jala.Form.Component.Input - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created File component - * @constructor - */ -jala.Form.Component.File = function File(name) { - jala.Form.Component.File.superConstructor.apply(this, arguments); - - this.containsFileUpload = function() { - return true; - }; - - return this; -}; -// extend jala.Form.Component.Input -jala.Form.extend(jala.Form.Component.File, jala.Form.Component.Input); - -/** - * Renders a file input tag to the response. - * @param {Object} attr Basic attributes for this element. - * @param {Object} value Value to be used for rendering this element. - * @param {Object} reqData Request data for the whole form. This argument is - * passed only if the form is re-rendered after an error occured. - */ -jala.Form.Component.File.prototype.renderControls = function(attr, value, reqData) { - var contentType = this.getRequirement(jala.Form.CONTENTTYPE); - if (contentType) { - attr.accept = (contentType instanceof Array) ? contentType.join(",") : contentType; - } - jala.Form.html.file(attr); - return; -}; - -/** - * Validates a file upload by making sure it's there (if REQUIRE is set), - * checking the file size, the content type and by trying to construct an image. - * @param {Object} reqData request data - * @param {jala.Form.Tracker} tracker jala.Form.Tracker object storing possible error messages - * @returns null if everything is ok or string containing error message - * @type String - */ -jala.Form.Component.File.prototype.checkRequirements = function(reqData) { - - if (reqData[this.name].contentLength == 0) { - // no upload - if (this.getRequirement(jala.Form.REQUIRE) == true) { - return this.getMessage(jala.Form.REQUIRE, "File upload is required."); - } else { - // no further checks necessary, exit here - return null; - } - } - - var maxLength = this.getRequirement(jala.Form.MAXLENGTH); - if (maxLength && reqData[this.name].contentLength > maxLength) { - return this.getMessage(jala.Form.MAXLENGTH, "This file is too big ({0} bytes), maximum allowed size {1} bytes.", - reqData[this.name].contentLength, maxLength); - } - - var contentType = this.getRequirement(jala.Form.CONTENTTYPE); - if (contentType) { - var arr = (contentType instanceof Array) ? contentType : [contentType]; - if (arr.indexOf(reqData[this.name].contentType) == -1) { - return this.getMessage(jala.Form.CONTENTTYPE, "The file type {0} is not allowed.", - reqData[this.name].contentType); - } - } - - return null; -}; - - -/** - * Creates a new Image component instance - * @class Subclass of jala.Form.Component.File which renders a file upload - * and validates uploaded files as images. - * @base jala.Form.Component.File - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Image component - * @constructor - */ -// FIXME: see below -jala.Form.Component.Image = function() {}; - -/** - * FIXME: JSDoc has some sever problems with this class. - * It's somehow due to the named method ("Image") that it - * always appears as global static object. - * Wrapping the method in another function which immediately - * is executed seems to solve this problem and could be used - * as a work-around for similar issues. - */ -jala.Form.Component.Image = (function() { - return function Image(name) { - jala.Form.Component.Image.superConstructor.apply(this, arguments); - return this; - }; -})(); - -// extend jala.Form.Component.File -jala.Form.extend(jala.Form.Component.Image, jala.Form.Component.File); - -/** - * Validates an image upload by making sure it's there (if REQUIRE is set), - * checking the file size, the content type and by trying to construct an image. - * If the file is an image, width and height limitations set by require are - * checked. - * @param {Object} reqData request data - * @type String - */ -jala.Form.Component.Image.prototype.checkRequirements = function(reqData) { - var re = this.constructor.superConstructor.prototype.checkRequirements.call(this, reqData); - if (re) { - return re; - } - - if (reqData[this.name].contentLength > 0) { - var helmaImg = undefined; - try { - helmaImg = new Image(reqData[this.name]); - } catch (imgError) { - return this.getMessage("invalid", "This image file can't be processed."); - } - - var maxWidth = this.getRequirement(jala.Form.MAXWIDTH); - if (maxWidth && helmaImg.getWidth() > maxWidth) { - return this.getMessage("maxwidth", "This image is too wide."); - } - - var minWidth = this.getRequirement(jala.Form.MINWIDTH); - if (minWidth && helmaImg.getWidth() < minWidth) { - return this.getMessage("minwidth", "This image is not wide enough."); - } - - var maxHeight = this.getRequirement(jala.Form.MAXHEIGHT); - if (maxHeight && helmaImg.getHeight() > maxHeight) { - return this.getMessage("maxheight", "This image is too tall."); - } - - var minHeight = this.getRequirement(jala.Form.MINHEIGHT); - if (minHeight && helmaImg.getHeight() < minHeight) { - return this.getMessage("minheight", "This image is not tall enough."); - } - } - - return null; -}; - - - -/** - * Creates a new Button component instance - * @class Subclass of jala.Form.Component.Input which renders a button. - * @base jala.Form.Component.Input - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Button component - * @constructor - */ -jala.Form.Component.Button = function Button(name) { - jala.Form.Component.Button.superConstructor.apply(this, arguments); - - /** - * Private field containing the value of the button (ie. the visible text) - * @type String - */ - var value; - - /** - * Returns the value set for this button. - * @returns value - * @type String - */ - this.getValue = function() { - return value; - }; - - /** - * Sets the value for this button. - * @param {String} newValue new value - */ - this.setValue = function(newValue) { - value = newValue; - return; - }; - - return this; -}; -// extend jala.Form.Component -jala.Form.extend(jala.Form.Component.Button, jala.Form.Component.Input); - -/** - * Renders a button to the response. - * @param {Object} attr Basic attributes for this element. - * @param {Object} value Value to be used for rendering this element. - * @param {Object} reqData Request data for the whole form. This argument is - * passed only if the form is re-rendered after an error occured. - */ -jala.Form.Component.Button.prototype.render = function(attr, value, reqData) { - var classStr = (this.getClassName()) ? " " + this.getClassName() : ""; - var attr = { - id: this.createDomId(), - "class": "component" + classStr - }; - jala.Form.html.openTag("div", attr); - res.write("\n "); - - this.renderControls(this.getControlAttributes(), this.getValue()); - res.write("\n"); - - jala.Form.html.closeTag("div"); - res.write("\n"); - return; -}; - -/** - * Creates a new attribute object for this button. - * @returns Object with all attributes set for this button. - * @type Object - */ -jala.Form.Component.Button.prototype.renderControls = function(attr, value) { - if (value) { - attr.value = value; - } - jala.Form.html.button(attr); - return; -}; - - -/** - * Creates a new Submit component instance - * @class Subclass of jala.Form.Component.Button which renders a submit button. - * @base jala.Form.Component.Button - * @param {String} name Name of the component, used as name of the html controls. - * @returns A newly created Submit component - * @constructor - */ -jala.Form.Component.Submit = function Submit(name) { - jala.Form.Component.Submit.superConstructor.apply(this, arguments); - - return this; -}; -// extend jala.Form.Component.Button -jala.Form.extend(jala.Form.Component.Submit, jala.Form.Component.Button); - -/** - * Creates a new attribute object for this button. - * @returns Object with all attributes set for this button. - * @type Object - */ -jala.Form.Component.Submit.prototype.renderControls = function(attr, value) { - if (value) { - attr.value = value; - } - jala.Form.html.submit(attr); - return; -}; - - -/** - * static default getter function used to return a field - * from the data object. - * @param {String} name Name of the property. - * @type Object - */ -jala.Form.propertyGetter = function(name, value) { - return this[name]; -}; - -/** - * static default setter function used to change a field - * of the data object. - * @param {String} name Name of the property. - * @param {Object} value New value of the property. - */ -jala.Form.propertySetter = function(name, value) { - this[name] = value; -}; - - -/** - * A generic container for error-messages and values - * @class Instances of this class can contain error-messages and values - * @constructor - * @type jala.Form.Tracker - */ -jala.Form.Tracker = function(reqData) { - - /** - * A map containing input from request data - * @type Object - */ - this.reqData = reqData; - - /** - * A map containing parsed values (only for those fields that didn't - * fail during checkRequirements method). - * @type Object - */ - this.values = {}; - - /** - * A map containing error messages - * @type Object - */ - this.errors = {}; - - return this; -}; - -/** @ignore */ -jala.Form.Tracker.toString = function() { - return "[jala.Form.Tracker]"; -}; - -/** @ignore */ -jala.Form.Tracker.prototype.toString = jala.Form.Tracker.toString; - -/** - * Returns true if an error has been set for at least one component. - * @returns true if form encountered an error. - * @type Boolean - */ -jala.Form.Tracker.prototype.hasError = function() { - for (var keys in this.errors) { - return true; - } - return false; -}; - -/** - * Returns the number of components for which this instance has - * tracked an error. - * @returns Number of components that did not validate. - * @type Number - */ -jala.Form.Tracker.prototype.countErrors = function() { - var ct = 0; - for (var keys in this.errors) { - ct++; - } - return ct; -}; - -/** - * Helper method. - * @private - */ -jala.Form.Tracker.prototype.debug = function() { - for (var key in this.errors) { - res.debug(key + ":" + this.errors[key]); - } - return; -}; - - diff --git a/modules/jala/code/Global.js b/modules/jala/code/Global.js deleted file mode 100644 index 0c75f031..00000000 --- a/modules/jala/code/Global.js +++ /dev/null @@ -1,130 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the Global prototype. - */ - - -/** - * Returns true if the value passed as argument is either a string literal, - * an instance of String or of java.lang.String. - * @param {Object} val The value to test - * @returns True if the value is a string, false otherwise - * @type Boolean - */ -function isString(val) { - return typeof(val) == "string" || - val instanceof java.lang.String || - val instanceof String; -}; - -/** - * Returns true if the value passed as argument is either a boolean - * literal or an instance of Boolean. - * @param {Object} val The value to test - * @returns True if the value is a boolean, false otherwise - * @type Boolean - */ -function isBoolean(val) { - return typeof(val) == "boolean" || - val instanceof Boolean; -}; - -/** - * Returns true if the value passed as argument is either a number, - * an instance of Number or of java.lang.Number. - * @param {Object} val The value to test - * @returns True if the value is a number, false otherwise - * @type Boolean - */ -function isNumber(val) { - return typeof(val) == "number" || - val instanceof java.lang.Number || - val instanceof Number; -}; - -/** - * Returns true if the value passed as argument is null. - * @param {Object} val The value to test - * @returns True if the value is null, false otherwise - * @type Boolean - */ -function isNull(val) { - return val === null; -}; - -/** - * Returns true if the value passed as argument is undefined. - * @param {Object} val The value to test - * @returns True if the value is undefined, false otherwise - * @type Boolean - */ -function isUndefined(val) { - return val === undefined; -}; - -/** - * Returns true if the value passed as argument is an array. - * @param {Object} val The value to test - * @returns True if the value is an array, false otherwise - * @type Boolean - */ -function isArray(val) { - return val instanceof Array; -}; - -/** - * Returns true if the value passed as argument is either a Javascript date - * or an instance of java.util.Date. - * @param {Object} val The value to test - * @returns True if the value is a date, false otherwise - * @type Boolean - */ -function isDate(val) { - return val instanceof Date || - val instanceof java.util.Date; -}; - -/** - * Returns true if the value passed as argument is either a Javascript - * object or an instance of java.lang.Object. - * @param {Object} val The value to test - * @returns True if the value is an object, false otherwise - * @type Boolean - */ -function isObject(val) { - return val instanceof Object || - val instanceof java.lang.Object; -}; - -/** - * Returns true if the value passed as argument is a function. - * @param {Object} val The value to test - * @returns True if the argument is a function, false otherwise - * @type Boolean - */ -function isFunction(val) { - return val instanceof Function; -}; \ No newline at end of file diff --git a/modules/jala/code/History.js b/modules/jala/code/History.js deleted file mode 100644 index 215166ac..00000000 --- a/modules/jala/code/History.js +++ /dev/null @@ -1,253 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.History class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * Constructs a new History object. - * @class This class is an implementation of a Browser-like history - * stack suitable to use in any Helma application. The difference - * to a Browser's history is that this implementation ignores - * POST requests and checks if Urls in the stack are still valid to - * prevent eg. redirections to a HopObject's url that has been deleted. - * Plus it is capable to create new "intermediate" history-stacks - * and this way maintain a "history of histories" which is needed for - * eg. editing sessions in a popup window that should use their own - * request history without interfering with the history of the - * main window. - * @constructor - */ -jala.History = function() { - var MAX = 40; - - /** - * Stack constructor - * @private - */ - var Stack = function(id) { - this.items = []; - this.id = id; - return this; - }; - - /** - * Returns the current url including query string - * @private - */ - var getUrl = function() { - var query; - var url = path.href(req.action); - try { - if (query = req.getServletRequest().getQueryString()) - url += "?" + query; - } catch (e) { - // ignore - } - return url; - } - - /** - * Checks if a request is valid for being added - * to the history stack. This method returns false - * for all POST-requests or requests whose action name - * contains a dot (to prevent requests for external stylesheets - * or the like from being recorded). - * @private - * @type Boolean - */ - var isValid = function() { - // FIXME: we should check for mimetype of response instead - // of assuming that requests containing a dot aren't worth - // being put into history stack ... - if (req.isPost() || (req.action && req.action.contains("."))) - return false; - return true; - }; - - /** - * returns a single Stack instance - * @private - */ - var getStack = function() { - if (history.length < 1) - history.push(new Stack(getUrl())); - return history[history.length -1]; - }; - - /** - * Variable containing the history-stacks - * @private - */ - var history = []; - - /** - * Initializes a new history stack, adds - * it to the array of stacks (which makes it - * the default one to use for further requests) - * and records the current request Url. - */ - this.add = function() { - if (!isValid()) - return; - var url = getUrl(); - if (getStack().id != url) { - history.push(new Stack(url)); - this.push(); - } - return; - }; - - /** - * Removes the current history stack - */ - this.remove = function() { - history.pop(); - return; - }; - - /** - * Records a request Url in the currently active - * history stack. - */ - this.push = function() { - if (isValid()) { - var obj = path[path.length-1]; - var url = getUrl(); - var stack = getStack(); - if (stack.items.length < 1 || stack.items[stack.items.length -1].url != url) { - if (stack.items.length >= MAX) - stack.items.shift(); - stack.items.push({ - url: url, - path: path.href().substring(root.href().length).replace(/\+/g, " ") - }); - } - } - return; - }; - - /** - * Clears the currently active history stack - */ - this.clear = function() { - getStack().items.length = 0; - return; - }; - - /** - * Redirects the client back to the first valid - * request in history. Please mind that searching for - * a valid Url starts at history.length - 2. - * @param {Number} offset The index position in the stack to start - * searching at - */ - this.redirect = function(offset) { - res.redirect(this.pop(offset)); - return; - }; - - /** - * Retrieves the first valid request Url in history - * stack starting with a given offset. The default offset is 1. - * Any valid Url found is removed from the stack, therefor - * this method alters the contents of the history stack. - * @param {Number} offset The index position in history stack to start - * searching at - * @return The Url of the request - * @type String - */ - this.pop = function(offset) { - /** - * checks if a referrer is stil valid - * @private - */ - var isValidPath = function(p) { - var arr = p.split("/"); - var obj = root; - for (var i=0;i 0) { - while (cut-- > 0) { - obj = stack.items.pop(); - } - } - while (stack.items.length > 0) { - obj = stack.items.pop(); - // check if url is valid - if (isValidPath(obj.path)) { - return obj.url; - } - } - return path.href(); - }; - - /** - * Retrieves the request Url at the given position - * in the current history stack. If no offset is given - * the last Url in the stack is returned. This method - * does not alter the stack contents! - * @param {Number} offset The index position in history stack to start - * searching at - * @return The Url of the request - * @type String - */ - this.peek = function(offset) { - var stack = getStack(); - return stack.items[stack.items.length - (offset != null ? offset : 1)]; - }; - - /** - * Returns the contents of all history stacks - * as string - * @return The history stacks as string - * @type String - */ - this.dump = function() { - return history.toSource(); - }; - - /** @ignore */ - this.toString = function() { - return "[History " + getStack().toSource() + "]"; - }; - - return this; -} diff --git a/modules/jala/code/HopObject.js b/modules/jala/code/HopObject.js deleted file mode 100644 index 657a24c7..00000000 --- a/modules/jala/code/HopObject.js +++ /dev/null @@ -1,177 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - -/** - * @fileoverview Additional fields and methods of the HopObject class. - */ - -/** - * HelmaLib dependencies - */ -app.addRepository("modules/core/String.js"); -app.addRepository("modules/helma/File.js"); - -/** - * Constructs a name from an object which - * is unique in the underlying HopObject collection. - * @param {Object} obj The object representing or containing - * the alias name. Possible object types include: - *
      - *
    • File
    • - *
    • helma.File
    • - *
    • java.io.File
    • - *
    • String
    • - *
    • java.lang.String
    • - *
    • Packages.helma.util.MimePart
    • - *
    - * @param {Number} maxLength The maximum length of the alias - * @returns The resulting alias - * @type String - */ -HopObject.prototype.getAccessName = function(obj, maxLength) { - /** - * Private method checking if the key passed as argument is already - * existing in this object - * @param {String} key The key string to test - * @returns True in case the key is already in use, false otherwise - * @type Boolean - */ - var isReserved = function(obj, key) { - return key === "." || - key === ".." || - obj[key] != null || - obj[key + "_action"] != null || - obj.get(key) != null - }; - - // prepare name depending on argument - var name; - var clazz = obj.constructor || obj.getClass(); - switch (clazz) { - case File: - case helma.File: - case java.io.File: - case Packages.helma.util.MimePart: - // first fix bloody ie/win file paths containing backslashes - name = obj.getName().split(/[\\\/]/).pop(); - if (name.contains(".")) - name = name.substring(0, name.lastIndexOf(".")); - break; - case String: - case java.lang.String: - name = obj; - break; - default: - name = obj.toString(); - } - - // remove all (back)slashes - var accessName = name.replace(/[\\\/]/g, ""); - // remove all plus signs - accessName = accessName.replace("+",""); - if (accessName.length > maxLength) { - accessName = accessName.substring(0, maxLength); - } - var result = accessName; - if (isReserved(this, result)) { - var len = result.length; - var counter = 1; - var overflow; - while (isReserved(this, result)) { - result = accessName + "-" + counter.toString(); - if ((overflow = result.length - maxLength) > 0) { - result = accessName.substring(0, accessName.length - overflow) + - "-" + counter.toString(); - if (result.length > maxLength) { - throw "Unable to create accessname due to limit restriction"; - } - } - counter += 1; - } - } - return result; -}; - - -/** - * Returns true if the internal state of this HopObject is TRANSIENT. - * @returns True if this HopObject is marked as transient, false otherwise. - * @type Boolean - */ -HopObject.prototype.isTransient = function() { - return this.__node__.getState() === Packages.helma.objectmodel.INodeState.TRANSIENT; -}; - -/** - * Returns true if the internal state of this HopObject is VIRTUAL. - * @returns True if this HopObject is marked as virtual, false otherwise. - * @type Boolean - */ -HopObject.prototype.isVirtual = function() { - return this.__node__.getState() === Packages.helma.objectmodel.INodeState.VIRTUAL; -}; - -/** - * Returns true if the internal state of this HopObject is INVALID. - * @returns True if this HopObject is marked as invalid, false otherwise. - * @type Boolean - */ -HopObject.prototype.isInvalid = function() { - return this.__node__.getState() === Packages.helma.objectmodel.INodeState.INVALID; -}; - -/** - * Returns true if the internal state of this HopObject is CLEAN. - * @returns True if this HopObject is marked as clean, false otherwise. - * @type Boolean - */ -HopObject.prototype.isClean = function() { - return this.__node__.getState() === Packages.helma.objectmodel.INodeState.CLEAN; -}; - -/** - * Returns true if the internal state of this HopObject is NEW. - * @returns True if this HopObject is marked as new, false otherwise. - * @type Boolean - */ -HopObject.prototype.isNew = function() { - return this.__node__.getState() === Packages.helma.objectmodel.INodeState.NEW; -}; - -/** - * Returns true if the internal state of this HopObject is MODIFIED. - * @returns True if this HopObject is marked as modified, false otherwise. - * @type Boolean - */ -HopObject.prototype.isModified = function() { - return this.__node__.getState() === Packages.helma.objectmodel.INodeState.MODIFIED; -}; - -/** - * Returns true if the internal state of this HopObject is DELETED. - * @returns True if this HopObject is marked as deleted, false otherwise. - * @type Boolean - */ -HopObject.prototype.isDeleted = function() { - return this.__node__.getState() === Packages.helma.objectmodel.INodeState.DELETED; -}; diff --git a/modules/jala/code/HtmlDocument.js b/modules/jala/code/HtmlDocument.js deleted file mode 100644 index ae5626cf..00000000 --- a/modules/jala/code/HtmlDocument.js +++ /dev/null @@ -1,156 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - -/** - * @fileoverview Fields and methods of the jala.HtmlDocument class. - */ - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - -/** - * Jala dependencies - */ -(function() { - var jalaDir = getProperty("jala.dir", "modules/jala"); - app.addRepository(jalaDir + "/lib/dom4j-1.6.1.jar"); - app.addRepository(jalaDir + "/lib/jaxen-1.1-beta-8.jar"); -})(); - -/** - * Construct a new HTML document. - * @class This class provides easy access to the elements of - * an arbitrary HTML document. By using TagSoup, Dom4J and Jaxen - * even invalid HTML can be parsed, turned into an object tree - * and easily be processed with XPath expressions. - * @param {String} source The HTML source code. - * @returns A new HTML document. - * @constructor - */ -jala.HtmlDocument = function(source) { - var REQUIREMENTS = { - "dom4j-1.6.1": "http://www.dom4j.org", - "jaxen-1.1-beta-8": "http://www.jaxen.org" - }; - - var reader = new java.io.StringReader(source); - var dom4j = Packages.org.dom4j; - var tagsoup = "org.ccil.cowan.tagsoup.Parser"; - - try { - var saxReader = new dom4j.io.SAXReader(tagsoup); - var document = saxReader.read(reader); - document.normalize(); - } catch(e) { - res.push(); - res.write("\njala.HtmlDocument requires the following Java "); - res.write("packages in ext/lib or application directory:\n"); - for (var i in REQUIREMENTS) { - res.write(i); - res.write(".jar"); - res.write(" ["); - res.write(REQUIREMENTS[i]); - res.write("]\n"); - } - throw (e + res.pop()); - } - - /** - * Get all document nodes from an XPath expression. - * @param {String} xpathExpr An XPath expression. - * @returns A list of HTML elements. - * @type org.dom4j.tree.DefaultElement - */ - this.scrape = function(xpathExpr) { - return document.selectNodes(xpathExpr); - }; - - /** - * Get all link elements of the HTML document. - * @returns A list of link elements. - * @type Array - */ - this.getLinks = function() { - var result = []; - var list = this.scrape("//html:a"); - for (var i=0; i 0) { - object.attributes = new Array; - for (n=0; nlanguage[_COUNTRY][_variant], where language - * is a valid ISO Language Code (eg. "de"), COUNTRY a valid ISO - * Country Code (eg. "AT"), and variant an identifier for the variant to use. - * @returns The locale for the given id - * @type java.util.Locale - */ -jala.I18n.prototype.getLocale = function(localeId) { - if (localeId) { - if (localeId.indexOf("_") > -1) { - var arr = localeId.split("_"); - if (arr.length == 3) { - return new java.util.Locale(arr[0], arr[1], arr[2]); - } else { - return new java.util.Locale(arr[0], arr[1]); - } - } else { - return new java.util.Locale(localeId); - } - } - return java.util.Locale.getDefault(); -} - -/** - * Tries to "translate" the given message key into a localized - * message. - * @param {String} key The message to translate (required) - * @param {String} plural The plural form of the message to translate - * @param {Number} amount A number to determine whether to use the - * singular or plural form of the message - * @returns The localized message or the appropriate key if no - * localized message was found - * @type String - */ -jala.I18n.prototype.translate = function(singularKey, pluralKey, amount) { - var translation = null; - if (singularKey) { - // use the getter method for retrieving the locale - var locale = this.getLocaleGetter()(); - var catalog, key; - if ((catalog = jala.i18n.getCatalog(locale))) { - if (arguments.length == 3 && amount != 1) { // is plural - key = pluralKey; - } else { - key = singularKey; - } - if (!(translation = catalog[key])) { - translation = key; - app.logger.debug("jala.i18n.translate(): Can't find message '" + - key + "' for locale '" + locale + "'"); - } - } else { - app.logger.debug("jala.i18n.translate(): Can't find message catalog for locale '" + locale + "'"); - if (!pluralKey || amount == 1) { - translation = singularKey; - } else { - translation = pluralKey; - } - } - } - return translation; -}; - -/** - * Helper method to get the message catalog - * corresponding to the actual locale. - * @params {java.util.Locale} locale - * @returns The message catalog. - */ -jala.I18n.prototype.getCatalog = function(locale) { - if (!jala.I18n.catalogs) { - jala.I18n.catalogs = {}; - } - - var catalog = jala.I18n.catalogs[locale]; - - if (catalog) return catalog; - - var messages = this.getMessages(); - - if (locale && messages) { - catalog = messages[locale.toLanguageTag()]; - jala.I18n.catalogs[locale] = catalog; - } - - return catalog; -}; - -/** - * Converts the message passed as argument into an instance - * of java.text.MessageFormat, and formats it using the - * replacement values passed. - * @param {String} message The message to format - * @param {Array} values An optional array containing replacement values - * @returns The formatted message or, if the formatting fails, the - * message passed as argument. - * @type String - * @see http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html - */ -jala.I18n.prototype.formatMessage = function(message, values) { - if (message) { - var args = null; - if (values != null && values.length > 0) { - args = java.lang.reflect.Array.newInstance(java.lang.Object, values.length); - var arg; - for (var i=0;inumber must - * match the number of the additional argument (starting with zero). - * @param {String} key The message to localize - * @returns The translated message - * @type String - * @see #translate - * @see #formatMessage - */ -jala.I18n.prototype.gettext = function(key /** [value 0][, value 1][, ...] */) { - return this.formatMessage(this.translate(key), - Array.prototype.splice.call(arguments, 1)); -}; - -/** - * Returns a localized message for the message key passed as - * argument. In contrast to gettext() this method - * can handle plural forms based on the amount passed as argument. - * If no localization is found, the appropriate message key is - * returned. Any additional arguments passed to this function - * will be used as replacement values during message rendering. - * To reference these values the message can contain placeholders - * following "{number}" notation, where number must - * match the number of the additional argument (starting with zero). - * @param {String} singularKey The singular message to localize - * @param {String} pluralKey The plural form of the message to localize - * @param {Number} amount The amount which is used to determine - * whether the singular or plural form of the message should be returned. - * @returns The translated message - * @type String - * @see #translate - * @see #formatMessage - */ -jala.I18n.prototype.ngettext = function(singularKey, pluralKey, amount /** [value 0][, value 1][, ...] */) { - return this.formatMessage(this.translate(singularKey, pluralKey, amount || 0), - Array.prototype.splice.call(arguments, 2)); -}; - -/** - * A simple proxy method which is used to mark a message string - * for the i18n parser as to be translated. - * @param {String} key The message that should be seen by the - * i18n parser as to be translated. - * @returns The message in unmodified form - * @type String - */ -jala.I18n.prototype.markgettext = function(key) { - return key; -}; - -/** - * Returns a translated message. The following macro attributes - * are accepted: - *
      - *
    • text: The message to translate (required)
    • - *
    • plural: The plural form of the message
    • - *
    • values: A list of replacement values. Use a comma to separate more - * than one value. Each value is either interpreted as a global property - * (if it doesn't containg a dot) or as a property name of the given macro - * handler object (eg. "user.name"). If the value of the property is a - * HopObject or an Array this macro uses the size() resp. length of the - * object, otherwise the string representation of the object will be used.
    • - *
    - * @returns The translated message - * @type String - * @see #gettext - * @see #ngettext - */ -jala.I18n.prototype.message_macro = function(param) { - if (param.text) { - var args = [param.text]; - if (param.plural) { - args[args.length] = param.plural; - } - if (param.values != null) { - var arr = param.values.split(/\s*,\s*/g); - // convert replacement values: if the value name doesn't contain - // a dot, look for a global property with that name, otherwise - // for a property of the specified macro handler object. - var propName, dotIdx, handlerName, handler; - for (var i=0;i 0) { - var handlerName = propName.substring(0, dotIdx); - if (handlerName == "request") { - handler = req.data; - } else if (handlerName == "response") { - handler = res.data; - } else if (!(handler = res.handlers[handlerName])) { - continue; - } - propName = propName.substring(dotIdx + 1); - // primitive security: don't allow access to internal properties - // and a property named "password" - if (propName.charAt(0) != "_" && propName.toLowerCase() != "password") { - value = handler[propName]; - } - } else { - value = global[propName]; - } - if (value != null) { - // if its a HopObject collection or Array, use its size/length - // as value - if (value instanceof HopObject) { - value = value.size(); - } else if (value instanceof Array) { - value = value.length; - } - } - args[args.length] = value; - } - } - } - if (param.plural) { - return this.ngettext.apply(this, args); - } else { - return this.gettext.apply(this, args); - } - } - return; -}; - -/** - * Default i18n class instance. - * @type jala.I18n - * @final - */ -jala.i18n = new jala.I18n(); - -/** - * For convenience reasons the public methods and macros are - * put into global scope too - */ -var gettext = function() { - return jala.i18n.gettext.apply(jala.i18n, arguments); -}; -var ngettext = function() { - return jala.i18n.ngettext.apply(jala.i18n, arguments); -}; -var markgettext = function() { - return jala.i18n.markgettext.apply(jala.i18n, arguments); -}; -var message_macro = function() { - return jala.i18n.message_macro.apply(jala.i18n, arguments); -}; diff --git a/modules/jala/code/ImageFilter.js b/modules/jala/code/ImageFilter.js deleted file mode 100644 index d20ff9b2..00000000 --- a/modules/jala/code/ImageFilter.js +++ /dev/null @@ -1,362 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.ImageFilter class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * Constructs a new ImageFilter object - * @class This class provides several image manipulating - * methods. Most of this filter library is based on filters created - * by Janne Kipin for JAlbum. For more information have a look - * at http://www.ratol.fi/~jakipina/java/ - * @param {Object} img Either -
      -
    • an instance of helma.image.ImageWrapper
    • -
    • the path to the image file as String
    • -
    • an instance of helma.File representing the image file
    • -
    • an instance of java.io.File representing the image file
    • -
    - * @constructor - */ -jala.ImageFilter = function(img) { - /** - * The buffered image to work on - * @type java.awt.image.BufferedImage - * @private - */ - var bi; - - /** - * Perfoms a gaussian operation (unsharp masking or blurring) - * on the image using the kernelFactory passed as argument - * @param {Number} radius The radius - * @param {Number} amount The amount - * @param {Function} kernelFactory Factory method to call for building the kernel - * @private - */ - var gaussianOp = function(radius, amount, kernelFactory) { - var DEFAULT_RADIUS = 2; - var MINIMUM_RADIUS = 1; - var MAXIMUM_RADIUS = 10; - var DEFAULT_AMOUNT = 15; - var MINIMUM_AMOUNT = 1; - var MAXIMUM_AMOUNT = 100; - - // correct arguments if necessary - if (isNaN(radius = Math.min(Math.max(radius, MINIMUM_RADIUS), MAXIMUM_RADIUS))) - radius = DEFAULT_RADIUS; - if (isNaN(amount = Math.min(Math.max(amount, MINIMUM_AMOUNT), MAXIMUM_AMOUNT))) - amount = DEFAULT_AMOUNT; - - if ((bi.getWidth() < bi.getHeight()) && (radius > bi.getWidth())) { - radius = bi.getWidth(); - } else if ((bi.getHeight() < bi.getWidth()) && (radius > bi.getHeight())) { - radius = bi.getHeight(); - } - - var size = (radius * 2) + 1; - var deviation = amount / 20; - var elements = kernelFactory(size, deviation); - var large = jala.ImageFilter.getEnlargedImageWithMirroring(bi, radius); - var resultImg = new java.awt.image.BufferedImage(large.getWidth(), large.getHeight(), large.getType()); - var kernel = new java.awt.image.Kernel(size, size, elements); - var cop = new java.awt.image.ConvolveOp(kernel, java.awt.image.ConvolveOp.EDGE_NO_OP, null); - cop.filter(large, resultImg); - // replace the wrapped buffered image with the modified one - bi = resultImg.getSubimage(radius, radius, bi.getWidth(), bi.getHeight()); - return; - }; - - /** - * Sharpens the image using a plain sharpening kernel. - * @param {Number} amount The amount of sharpening to apply - */ - this.sharpen = function(amount) { - var DEFAULT = 20; - var MINIMUM = 1; - var MAXIMUM = 100; - // correct argument if necessary - if (isNaN(Math.min(Math.max(amount, MINIMUM), MAXIMUM))) - amount = DEFAULT; - var sharpened = new java.awt.image.BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType()); - var kernel = new java.awt.image.Kernel(3, 3, jala.ImageFilter.getSharpeningKernel(amount)); - var cop = new java.awt.image.ConvolveOp(kernel, java.awt.image.ConvolveOp.EDGE_NO_OP, null); - cop.filter(bi, sharpened); - bi = sharpened; - return; - }; - - /** - * Performs an unsharp mask operation on the image - * @param {Number} radius The radius - * @param {Number} amount The amount - */ - this.unsharpMask = function(radius, amount) { - gaussianOp(radius, amount, jala.ImageFilter.getUnsharpMaskKernel); - return; - }; - - /** - * Performs a gaussian blur operation on the image - * @param {Number} radius The radius - * @param {Number} amount The amount - */ - this.gaussianBlur = function(radius, amount) { - gaussianOp(radius, amount, jala.ImageFilter.getGaussianBlurKernel); - return; - }; - - - /** - * Returns the image that has been worked on - * @return An instance of helma.image.ImageWrapper - * @type helma.image.ImageWrapper - */ - this.getImage = function() { - var generator = Packages.helma.image.ImageGenerator.getInstance(); - return new Packages.helma.image.ImageWrapper(bi, - bi.getWidth(), - bi.getHeight(), - generator); - }; - - /** - * Returns the wrapped image as byte array, to use eg. in conjunction - * with res.writeBinary() - * @returns The wrapped image as byte array - * @type byte[] - */ - this.getBytes = function() { - var outStream = new java.io.ByteArrayOutputStream(); - Packages.javax.imageio.ImageIO.write(bi, "jpeg", outStream); - var bytes = outStream.toByteArray(); - outStream.close(); - return bytes; - }; - - /** - * constructor body - * @ignore - */ - if (arguments.length == 0 || img == null) { - throw "jala.ImageFilter: insufficient arguments"; - } else if (img instanceof Packages.helma.image.ImageWrapper) { - bi = img.getBufferedImage(); - } else { - if (typeof(img) == "string") { - var inStream = new java.io.FileInputStream(new java.io.File(img)); - } else { - var inStream = new java.io.FileInputStream(img); - } - var decoder = Packages.com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(inStream); - bi = decoder.decodeAsBufferedImage(); - } - - return this; -}; - -/** @ignore */ -jala.ImageFilter.prototype.toString = function() { - return "[jala.ImageFilter]"; -}; - -/** - * Transforms an image into a bigger one while mirroring the edges - * This method is used to apply the filtering up to the edges - * of an image (otherwise the image would keep an unmodified - * border). - * @param {java.awt.image.BufferedImage} bi The buffered image to transform - * @param {Number} size The size of the border area - * @returns The transformed image - * @type java.awt.image.BufferedImage - * @private - */ -jala.ImageFilter.getEnlargedImageWithMirroring = function(bi, size) { - - var doFlip = function(bi, sx, sy, dist) { - var out = new java.awt.image.BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType()); - var transform = java.awt.geom.AffineTransform.getScaleInstance(sx, sy); - (sx < sy) ? transform.translate(-dist, 0) : transform.translate(0, -dist); - var atop = new java.awt.image.AffineTransformOp(transform, - java.awt.image.AffineTransformOp.TYPE_NEAREST_NEIGHBOR); - out = atop["filter(java.awt.image.BufferedImage,java.awt.image.BufferedImage)"](bi, null); - return out; - } - - var doHorizontalFlip = function(bi) { - return doFlip(bi, -1, 1, bi.getWidth()); - } - - var doVerticalFlip = function(bi) { - return doFlip(bi, 1, -1, bi.getHeight()); - } - - var width = bi.getWidth() + 2 * size; - var height = bi.getHeight() + 2 * size; - var out = new java.awt.image.BufferedImage(width, height, bi.getType()); - var g = out.createGraphics(); - // due to method overloading exactly define the method to be called - var func = "drawImage(java.awt.Image,int,int,java.awt.image.ImageObserver)"; - g[func](bi, size, size, null); - - var part; - //top-left corner - part = bi.getSubimage(0, 0, size, size); - part = doHorizontalFlip(part); - part = doVerticalFlip(part); - g[func](part, 0, 0, null); - //top-right corner - part = bi.getSubimage(bi.getWidth()-size, 0, size, size); - part = doHorizontalFlip(part); - part = doVerticalFlip(part); - g[func](part, width-size, 0, null); - //bottom-left corner - part = bi.getSubimage(0, bi.getHeight()-size, size, size); - part = doHorizontalFlip(part); - part = doVerticalFlip(part); - g[func](part, 0, height-size, null); - //bottom-right corner - part = bi.getSubimage(bi.getWidth()-size, bi.getHeight()-size, size, size); - part = doHorizontalFlip(part); - part = doVerticalFlip(part); - g[func](part, width-size, height-size, null); - //left border - part = bi.getSubimage(0, 0, size, bi.getHeight()); - part = doHorizontalFlip(part); - g[func](part, 0, size, null); - //right border - part = bi.getSubimage(bi.getWidth()-size, 0, size, bi.getHeight()); - part = doHorizontalFlip(part); - g[func](part, width-size, size, null); - //top border - part = bi.getSubimage(0, 0, bi.getWidth(), size); - part = doVerticalFlip(part); - g[func](part, size, 0, null); - //bottom border - part = bi.getSubimage(0, bi.getHeight()-size, bi.getWidth(), size); - part = doVerticalFlip(part); - g[func](part, size, height-size, null); - return out; -}; - -/** - * Factory method for a gaussian blur kernel - * @returns The gaussian blur kernel - * @param {Number} size The size of the kernel - * @param {Number} deviation The deviation to use - * @returns The gaussian blur kernel - * @type float[] - * @private - */ -jala.ImageFilter.getGaussianBlurKernel = function(size, deviation) { - var nominator = 2 * deviation * deviation; - var kernel = java.lang.reflect.Array.newInstance(java.lang.Float.TYPE, size*size); - var center = (size - 1) / 2; - var limit = size - 1; - var xx, yy; - var sum = 0; - var value = 0; - for (var y=0; y= y) { - //calculate new value - xx = center - x; - yy = center - y; - value = Math.exp(-(xx*xx + yy*yy) / nominator); - kernel[(y*size)+x] = value; - sum += value; - } else { - //copy existing value - value = kernel[(x*size)+y]; - kernel[(y*size)+x] = value; - sum += value; - } - } else { - xx = x; - yy = y; - if (yy > center) - yy = limit - yy; - if (xx > center) - xx = limit - xx; - value = kernel[(yy*size)+xx]; - kernel[(y*size)+x] = value; - sum += value; - } - } - } - for (var i=0; i 0) { - // convert the array with sortfields to a java array - var arr = java.lang.reflect.Array.newInstance(pkg.search.SortField, sortFields.length); - sortFields.forEach(function(sortField, idx) { - arr[idx] = sortField; - }); - var sort = pkg.search.Sort(arr); - if (filter) { - hits = searcher.search(query, filter, sort); - } else { - hits = searcher.search(query, sort); - } - } else if (filter) { - hits = searcher.search(query, filter); - } else { - hits = searcher.search(query); - } - this.log("debug", "Query: " + query.toString()); - return new helma.Search.HitCollection(hits); -}; - -/** - * Parses the query string passed as argument into a lucene Query instance - * @param {String} queryStr The query string to parse - * @param {Array} fields An array containing the names of the files to search in - * @param {Object} boostMap An optional object containing properties whose name denotes - * the name of the field to boost in the query, and the value the boost value. - * @returns The query - * @type org.apache.lucene.search.Query - */ -jala.IndexManager.prototype.parseQuery = function(queryStr, fields, boostMap) { - if (queryStr == null || typeof(queryStr) !== "string") { - throw "IndexManager.parseQuery(): missing or invalid query string"; - } - if (fields == null || fields.constructor !== Array || fields.length < 1) { - throw "IndexManager.parseQuery(): missing fields argument"; - } - var query = null; - var analyzer = this.getIndex().getAnalyzer(); - var pkg = Packages.org.apache.lucene; - var map = null; - if (boostMap != null) { - // convert the javascript object into a HashMap - map = new java.util.HashMap(); - for (var name in boostMap) { - map.put(name, new java.lang.Float(boostMap[name])); - } - } - var parser; - try { - if (fields.length > 1) { - parser = new pkg.queryParser.MultiFieldQueryParser(fields, analyzer, map); - } else { - parser = new pkg.queryParser.QueryParser(fields, analyzer); - } - query = parser.parse(queryStr); - } catch (e) { - // ignore, but write a message to debug log - app.logger.debug("Unable to construct search query '" + queryStr + - "', reason: " + e); - } - return query; -}; - -/** - * Parses the query passed as argument and returns a caching filter. If an array - * with more than one query strings is passed as argument, this method constructs - * a boolean query filter where all queries in the array must match. - * @param {String|Array} query Either a query string, or an array containing - * one or more query strings - * @param {org.apache.lucene.analysis.Analyzer} analyzer Optional analyzer - * to use when parsing the filter query - * @returns A caching query filter - * @type org.apache.lucene.search.CachingWrapperFilter - */ -jala.IndexManager.prototype.parseQueryFilter = function(query, analyzer) { - var filter = null; - if (query != null) { - var pkg = Packages.org.apache.lucene; - // use the index' analyzer if none has been specified - if (analyzer == null) { - analyzer = this.getIndex().getAnalyzer(); - } - var parser = new pkg.queryParser.QueryParser("", analyzer); - var filterQuery; - try { - if (query.constructor === Array) { - if (query.length > 1) { - filterQuery = new pkg.search.BooleanQuery(); - query.forEach(function(queryStr){ - filterQuery.add(parser.parse(queryStr), pkg.search.BooleanClause.Occur.MUST); - }, this); - } else { - filterQuery = parser.parse(query[0]); - } - } else { - filterQuery = parser.parse(query); - } - filter = new pkg.search.CachingWrapperFilter(new pkg.search.QueryWrapperFilter(filterQuery)); - } catch (e) { - app.logger.debug("Unable to parse query filter '" + query + "', reason: " + e); - } - } - return filter; -}; - - - -/********************* - ***** J O B ***** - *********************/ - - -/** - * Creates a new Job instance. - * @class Instances of this class represent a single index - * manipulation job to be processed by the index manager. - * @param {Number} id The Id of the job - * @param {Number} type The type of job, which can be either - * jala.IndexManager.Job.ADD, jala.IndexManager.Job.REMOVE - * or jala.IndexManager.Job.OPTIMIZE. - * @param {Object} data The data needed to process the job. - * @returns A newly created Job instance. - * @constructor - * @see jala.IndexManager.Job - */ -jala.IndexManager.Job = function(type, callback) { - /** - * The type of the job - * @type Number - */ - this.type = type; - - /** - * The data needed to process this job. For adding jobs this property - * must contain the {@link helma.Search.Document} instance to add to - * the index. For removal job this property must contain the unique identifier - * of the document that should be removed from the index. For optimizing - * jobs this property is null. - */ - this.callback = callback; - - /** - * An internal error counter which is increased whenever processing - * the job failed. - * @type Number - * @see jala.IndexManager.MAXTRIES - */ - this.errors = 0; - - /** - * The date and time at which this job was created. - * @type Date - */ - this.createtime = new Date(); - - return this; -}; - -/** @ignore */ -jala.IndexManager.Job.prototype.toString = function() { - return "[Job (type: " + this.type + ")]"; -}; - -/** - * Constant defining an add job - * @type Number - * @final - */ -jala.IndexManager.Job.ADD = "add"; - -/** - * Constant defining a removal job - * @type Number - * @final - */ -jala.IndexManager.Job.REMOVE = "remove"; - -/** - * Constant defining an optimizing job - * @type Number - * @final - */ -jala.IndexManager.Job.OPTIMIZE = "optimize"; diff --git a/modules/jala/code/ListRenderer.js b/modules/jala/code/ListRenderer.js deleted file mode 100644 index 215237cc..00000000 --- a/modules/jala/code/ListRenderer.js +++ /dev/null @@ -1,1130 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.ListRenderer class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * HelmaLib dependencies - */ -app.addRepository("modules/helma/Html.js"); - -/** - * @class - * @param {HopObject|ArrayList|Array} coll The collection this ListRenderer - * operates on, or - for backwards compatibility only - a parameter object containing - * the collection and any other optional configuration parameters. - * @param {Object} renderer An optional renderer to use. If this is set, - * any rendering method defined in this renderer overrides the default renderer. - * @constructor - */ -jala.ListRenderer = function(coll, renderer) { - - /** - * The collection this ListRenderer operates on - * @type HopObject|ArrayList - * @private - */ - var collection = null; - - /** - * Private variable containing the number of items to display - * on one page. Defaults to 10. - * @type Number - * @private - */ - var pageSize = 10; - - /** - * Private variable containing the maximum number of pages to display - * within this ListRenderer instance - * @type Number - * @private - */ - var maxPages = Number.MAX_VALUE; - - /** - * Private variable containing the maximum number of days to display - * within this ListRenderer instance. If set to null this check - * is not used. - * @type Number - * @private - */ - var maxDays = null; - - /** - * Private variable containing the base href of this ListRenderer - * @type String - * @private - */ - var baseHref = null; - - /** - * Private variable containing the name of the skin to render for - * a single list item - * @type String - * @private - */ - var itemSkin = null; - - /** - * Private variable containing any optional url parameters to append to - * every navigation link rendered by this ListRenderer instance. - * @type String - * @private - */ - var urlParameters = null; - - /** - * Private variable containing the name of the url parameter containing - * the page number to display. Defaults to "page". - * @type String - * @private - */ - var urlParameterName = "page"; - - /** - * Internal cache for rendered navigation elements - * @private - */ - this.cache = { - pageNavigation: null, - prevLink: null, - nextLink: null, - maxDayDate: null, - nextItem: null - }; - - /** - * Returns the collection this ListRenderer instance operates on - * @returns The collection of this ListRenderer - * @type HopObject|Array - */ - this.getCollection = function() { - return collection; - }; - - /** - * Sets the collection of this ListRenderer - * @param {HopObject|ArrayList|Array} coll The collection this ListRenderer instance - * should operate on - */ - this.setCollection = function(coll) { - if (coll != null) { - if (coll instanceof Array) { - // wrap array in an ArrayList instance - collection = new jala.ListRenderer.ArrayList(coll); - } else { - collection = coll; - } - } - return; - }; - - /** - * Returns the number of items displayed on one page - * @returns The number of items displayed on a single page - * @type Number - */ - this.getPageSize = function() { - return pageSize; - }; - - /** - * Sets the number of items to display on a single page - * @param {Number} size The number of items to display on one page - */ - this.setPageSize = function(size) { - if (size != null && !isNaN(size)) { - pageSize = parseInt(size, 10); - } - return; - }; - - /** - * Returns the current page index. This is either the page url parameter - * or the page number 1. - * @returns The current page number (starts with 1). - * @type Number - * @see #setUrlParameterName - */ - this.getCurrentPage = function() { - var pageNr = parseInt(req.data[this.getUrlParameterName()], 10); - if (!pageNr || isNaN(pageNr)) { - pageNr = 1; - } - return Math.min(Math.max(1, pageNr), this.getTotalPages()); - }; - - /** - * Returns the maximum number of pages handled by this ListRenderer instance - * @returns The maximum number of pages - * @type Number - */ - this.getMaxPages = function() { - return maxPages; - }; - - /** - * Sets the maximum number of pages to display - * @param {Number} pages The maximum number of pages to display - */ - this.setMaxPages = function(pages) { - if (pages != null && !isNaN(pages)) { - maxPages = parseInt(pages, 10); - } - return; - }; - - /** - * Returns the maximum number of days handled by this ListRenderer instance - * @returns The maximum number of days - * @type Number - */ - this.getMaxDays = function() { - return maxDays; - }; - - /** - * Sets the maximum number of days to display - * @param {Number} days The maximum number of days to display - */ - this.setMaxDays = function(days) { - if (days != undefined && !isNaN(days)) { - maxDays = parseInt(days, 10); - } - return; - }; - - /** - * Gets the Date offset indicated by parameter maxDays as Number for runtime efficent comparison - * @type Number - */ - this.getMaxDayDate = function() { - if (this.cache.maxDayDate != null) { - return this.cache.maxDayDate; - } - this.cache.maxDayDate = parseInt((new Date((new Date()).getTime() - (maxDays * Date.ONEDAY))).format("yyyyMMdd"), 10); - return this.cache.maxDayDate; - }; - - /** - * @returns {Object} the next Item - */ - this.getNextItem = function() { - if (this.cache.nextItem !== null) { - return this.cache.nextItem; - } - var nextItemIndex = this.getEndIndex() + 1; - this.cache.nextItem = "none"; - if (collection.size() > nextItemIndex) { - this.cache.nextItem = collection.get(nextItemIndex); - } - return this.cache.nextItem; - }; - - /** - * @returns {Boolean} wether there is a next item - */ - this.hasNext = function() { - var nextItem = this.getNextItem(); - var nextIsDisplayable = false; - var collection = this.getCollection(); - if (maxDays != undefined) { - if (nextItem != "none" && nextItem.getDayDate() >= this.getMaxDayDate()) { - nextIsDisplayable = true; - } - } else { - if (nextItem != "none") { - nextIsDisplayable = true; - } - } - if (collection.size() && - nextIsDisplayable === true) { - return true; - } - return false; - }; - - /** - * Returns the total number of pages handled by this ListRenderer instance - * (which is the collection size divided by the page size). - * @returns The total number of pages - * @type Number - */ - this.getTotalPages = function() { - var collectionSize = collection.size(); - var pages = Math.ceil(collectionSize / pageSize); - if (maxPages > 0) { - return Math.min(maxPages, pages); - } - return pages; - }; - - /** - * Returns the base href of this ListRenderer instance - * @returns The base href of this ListRenderer instance - * @type String - */ - this.getBaseHref = function() { - return baseHref; - }; - - /** - * Sets the base href of this ListRenderer instance. All links rendered - * will start with the href passed as argument - * @param {String} href The base href to use for rendering links - */ - this.setBaseHref = function(href) { - if (href != null) { - baseHref = href; - } - return; - }; - - /** - * Returns the name of the skin rendered for a single list item - * @returns The name of the list item skin - * @type Number - */ - this.getItemSkin = function() { - return itemSkin; - }; - - /** - * Sets the name of the skin to render for every list item - * @param {String} name The name of the skin to render for every list item - */ - this.setItemSkin = function(name) { - if (name != null) { - itemSkin = name; - } - return; - }; - - /** - * Returns the name of the URL parameter name containing the index - * of the page to display - * @returns The name of the page URL parameter name - * @type String - */ - this.getUrlParameterName = function() { - return urlParameterName; - }; - - /** - * Sets the name of the URL parameter name containing the index of the page - * to display - * @param {String} name The name of the page URL parameter - */ - this.setUrlParameterName = function(name) { - if (name != null) { - urlParameterName = name; - } - return; - }; - - /** - * Returns any additional URL parameters included in every navigation link - * rendered by this ListRenderer instance. - * @returns A string containing additional URL parameters - * @type String - */ - this.getUrlParameters = function() { - return urlParameters; - }; - - /** - * Sets additional parameters to include in every navigation link - * @param {String} params A string to append to every navigation URL - */ - this.setUrlParameters = function(params) { - if (params != null) { - urlParameters = params; - } - return; - }; - - /** - * Returns the renderer used by this ListRenderer instance - */ - this.getRenderer = function() { - return renderer; - }; - - /** - * Sets the renderer to be used by this ListRenderer instance - * @param {Object} r The renderer to use - */ - this.setRenderer = function(r) { - if (r != null) { - renderer = r; - } - return; - }; - - /** - * Main constructor body - */ - if (!coll) { - throw "jala.ListRenderer: insufficient arguments"; - } else if (coll instanceof jala.ListRenderer.ArrayList || - coll instanceof Array || - coll instanceof HopObject) { - this.setCollection(coll); - } else if (coll.collection != null) { - // this is for backwards compatibility only - the former ListRenderer - // signature allowed just one parameter object as argument - this.setCollection(coll.collection); - this.setBaseHref(coll.href); - this.setUrlParameters(coll.urlParams); - this.setUrlParameterName(coll.urlParamName); - this.setPageSize(coll.itemsPerPage); - this.setMaxPages(coll.maxPages); - this.setMaxDays(coll.maxDays); - this.setItemSkin(coll.itemSkin); - } else { - throw "jala.ListRenderer: invalid argument " + coll; - } - return this; -}; - -/** - * Static instance of helma.Html - * @type helma.Html - * @private - */ -jala.ListRenderer.html = new helma.Html(); - -/** @ignore */ -jala.ListRenderer.prototype.toString = function() { - return "[jala.ListRenderer]"; -}; - -/** - * Returns the href of a page. If no argument is given, the href - * of the current page is returned. Any URL parameters set with - * {@link #setUrlParameters} are added to the href. - * @param {Number} page The optional page number to include in the href. - * @returns The href of the page - * @type String - * @see #setUrlParameters - * @see #setUrlParameterName - */ -jala.ListRenderer.prototype.getPageHref = function(page) { - var pageNr = (page != null && !isNaN(page)) ? page : this.getCurrentPage(); - var urlParams = this.getUrlParameters(); - res.push(); - res.write(this.getBaseHref()); - if (pageNr || urlParams) { - res.write("?"); - if (urlParams) { - res.write(urlParams); - res.write("&"); - } - if (pageNr) { - res.write(this.getUrlParameterName()); - res.write("="); - res.write(pageNr); - } - } - return res.pop(); -}; - -/** - * Returns the zero-based index position of the first item of the current page - * in the collection this ListRenderer operates on. - * @returns The index position of the first item in the list - * @type Number - */ -jala.ListRenderer.prototype.getStartIndex = function() { - return (this.getCurrentPage() -1) * this.getPageSize(); -}; - -/** - * Returns the zero-based index position of the last item of the current page - * in the collection this ListRenderer operates on. - * @returns The index position of the last item in the list - * @type Number - */ -jala.ListRenderer.prototype.getEndIndex = function() { - var start = this.getStartIndex(); - return Math.min(start + this.getPageSize(), this.getCollection().size()) - 1; -}; - -/** - * Returns the render function to use for a given part of the list. If this - * ListRenderer doesn't have a renderer attached, or if the renderer doesn't - * have the appropriate rendering function, the default renderer is used. - * @param {String} part The part of the page. Valid arguments are - * "list", "pageNavigation" and "pageLink". - * @param {String} fName The name of the rendering function to return - * @returns The function to call for rendering the desired part of the list - * @type Function - * @private - * @see jala.ListRenderer#defaultRenderer - */ -jala.ListRenderer.prototype.getRenderFunction = function(part, fName) { - - var getFunction = function(renderer, name) { - var handler; - if ((handler = renderer[part]) != null) { - if (handler[name] instanceof Function) { - return handler[name]; - } - } - return null; - }; - - var result; - var renderer = this.getRenderer(); - if (renderer != null) { - if (!fName || !(result = getFunction(renderer, fName))) { - result = getFunction(renderer, "default"); - } - } - if (!result) { - result = getFunction(jala.ListRenderer.defaultRenderer, "default"); - } - return result; -}; - -/** - * Renders the list of items for one page directly to response. - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @see #getList - */ -jala.ListRenderer.prototype.renderList = function(param) { - var collection = this.getCollection(); - var totalPages = this.getTotalPages(); - var currentPage = this.getCurrentPage(); - var pageSize = this.getPageSize(); - var maxDays = this.getMaxDays(); - var itemSkin = this.getItemSkin(); - - if (totalPages > 0) { - if (!param) { - param = {}; - } - var idx = this.getStartIndex(); - var stop = this.getEndIndex(); - // preload objects if collection is a HopObject one - if (collection instanceof HopObject) { - collection.prefetchChildren(idx, stop - idx); - } - // add various item and list related properties to the parameter object - param.counter = 1; - param.index = idx + 1; - param.stop = stop; - param.pageSize = pageSize; - param.itemsPerPage = pageSize; // for backwards compatibility only - param.collectionSize = collection.size(); - if (!param.skin && itemSkin) { - param.skin = itemSkin; - } - - var renderFunc = this.getRenderFunction("list", param.type); - var item, prevItem; - while (idx <= stop) { - item = collection.get(idx++); - if ((maxDays != undefined) && (item.getDayDate() < this.getMaxDayDate())) { - idx = stop; - break; - } - renderFunc(item, prevItem, param); - prevItem = item; - param.counter += 1; - param.index += 1; - } - } - return; -}; - -/** - * Returns the rendered list of collection items as string - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @returns The rendered list - * @type String - * @see #renderList - */ -jala.ListRenderer.prototype.getList = function(param) { - res.push(); - this.renderList(param); - return res.pop() || null; -}; - -/** - * Returns the rendered list of collection items as string - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @returns The rendered list - * @type String - * @see #renderList - * @deprecated Use {@link #getList} instead - */ -jala.ListRenderer.prototype.renderListAsString = function(param) { - return this.getList(param); -}; - -/** - * Renders a link to the previous page directly to response. - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @see #getPrevLink - */ -jala.ListRenderer.prototype.renderPrevLink = function(param) { - res.write(this.getPrevLink(param)); - return; -}; - -/** - * Returns a rendered link to the previous page as string. For performance - * reasons this method caches the rendered link in the local cache of this - * ListRenderer instance. - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @returns A rendered link to the previous page - * @type String - * @see #renderPrevLink - */ -jala.ListRenderer.prototype.getPrevLink = function(param) { - if (!this.cache.prevLink) { - res.push(); - var collection = this.getCollection(); - var currentPage = this.getCurrentPage(); - if (collection.size() && currentPage > 1) { - param.index = currentPage - 1; - param.href = this.getPageHref(param.index); - this.getRenderFunction("pageLink", param.type)("prev", param); - } - this.cache.prevLink = res.pop(); - } - return this.cache.prevLink || null; -}; - -/** - * Returns a rendered link to the previous page as string - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @returns A rendered link to the previous page - * @type String - * @deprecated Use {@link #getPrevLink} instead - */ -jala.ListRenderer.prototype.renderPrevLinkAsString = function(param) { - return this.getPrevLink(param); -}; - -/** - * Renders a link to the next page directly to response. - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @see #getNextLink - */ -jala.ListRenderer.prototype.renderNextLink = function(param) { - res.write(this.getNextLink(param)); - return; -}; - -/** - * Returns a rendered link to the previous page as string. For performance - * reasons this method caches the rendered link in the local cache of this - * ListRenderer instance. - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @returns A rendered link to the previous page - * @type String - * @see #renderNextLink - */ -jala.ListRenderer.prototype.getNextLink = function(param) { - if (!this.cache.nextLink) { - res.push(); - var collection = this.getCollection(); - var currentPage = this.getCurrentPage(); - var totalPages = this.getTotalPages(); - var nextItem = this.getNextItem(); - var nextIsDisplayable = false; - if (this.getMaxDays() != undefined) { - if (nextItem != "none" && nextItem.getDayDate() >= this.getMaxDayDate()) { - nextIsDisplayable = true; - } - } else { - if (nextItem != "none") { - nextIsDisplayable = true; - } - } - if (collection.size() && currentPage < totalPages && nextIsDisplayable === true) { - param.index = currentPage + 1; - param.href = this.getPageHref(param.index); - this.getRenderFunction("pageLink", param.type)("next", param); - } - this.cache.nextLink = res.pop(); - } - return this.cache.nextLink || null; -}; - -/** - * Returns a rendered link to the previous page as string - * @returns A rendered link to the next page - * @type String - * @deprecated Use {@link #getNextLink} instead - */ -jala.ListRenderer.prototype.renderNextLinkAsString = function(param) { - return this.getNextLink(param); -}; - -/** - * Renders the page navigation bar directly to response. For performance reasons - * this method caches the rendered page navigation in the local cache of this - * ListRenderer instance. - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @see #getPageNavigation - */ -jala.ListRenderer.prototype.renderPageNavigation = function(param) { - if (!this.cache.pageNavigation) { - var collection = this.getCollection(); - var totalPages = this.getTotalPages(); - var currentPage = this.getCurrentPage(); - var pageSize = this.getPageSize(); - - if (totalPages > 1) { - var renderFunc = this.getRenderFunction("pageNavigation", param.type); - if (!renderFunc) { - return "[Render function missing]"; - } - - // render the navigation-bar - res.push(); - if (currentPage > 1) { - renderFunc("item", { - text: param.previous || "prev", - url: this.getPageHref(currentPage -1), - }); - } - var navLength = parseInt(param.length, 10) || 10; - var pageNr = 1 + Math.floor((currentPage -1) / navLength) * navLength; - if (pageNr > 1) { - renderFunc("item", { - text: param.previousN || "[..]", - url: this.getPageHref(pageNr - navLength), - }); - } - var stop = Math.min(pageNr + navLength, totalPages +1); - do { - renderFunc("item", { - text: (param.itemPrefix || "") + pageNr + (param.itemSuffix || ""), - url: this.getPageHref(pageNr), - selected: pageNr == currentPage - }); - } while ((pageNr += 1) < stop); - - if (pageNr <= totalPages) { - renderFunc("item", { - text: param.nextN || "[..]", - url: this.getPageHref(pageNr), - }); - } - if (currentPage < totalPages) { - renderFunc("item", { - text: param.next || "next", - url: this.getPageHref(currentPage +1), - }); - } - var navigation = res.pop(); - res.push(); - renderFunc("navigation", { - from: ((currentPage -1) * pageSize) +1, - to: Math.min(((currentPage -1) * pageSize) + pageSize, collection.size()), - total: collection.size(), - pageNavigation: navigation, - }); - this.cache.pageNavigation = res.pop(); - } - } - res.write(this.cache.pageNavigation); - return; -}; - -/** - * Returns the rendered page navigation bar as string - * @param {Object} param Object containing extra parameters (e.g. from a macro call). - * @returns The rendered page navigation - * @type String - * @see #renderPageNavigation - */ -jala.ListRenderer.prototype.getPageNavigation = function(param) { - res.push(); - this.renderPageNavigation(param); - return res.pop() || null; -}; - -/** - * Returns the rendered page navigation bar as string - * @returns The rendered page navigation bar - * @type String - * @deprecated Use {@link #getPageNavigation} instead - */ -jala.ListRenderer.prototype.renderPageNavigationAsString = function(param) { - return this.getPageNavigation(param); -}; - - - -/********************************* - ********** M A C R O S ********** - *********************************/ - - -/** - * Either renders the maximum number of items per page, or - * sets the limit to a given number. - * @param {Object} param Extra macro parameters: - *
      - *
    • to - The maximum number of items per page to be set. - *
    - * If no limit is set, this macro returns the current number - * of items per page. - * @returns The current maximum number of items per page - * @type Number - */ -jala.ListRenderer.prototype.limit_macro = function(param) { - if (param.to) { - this.setPageSize(param.to); - return; - } else { - return this.getPageSize(); - } -}; - -/** - * Returns a rendered link to the previous page. - * @param {Object} param Extra macro parameters: - *
      - *
    • type - The type of renderer to be applied.
    • - *
    - * @returns A rendered link to the previous page - * @type String - * @see #renderPrevLink - */ -jala.ListRenderer.prototype.prevLink_macro = function(param) { - return this.getPrevLink(param); -}; - -/** - * Returns a rendered link to the next page. - * @param {Object} param Extra macro parameters: - *
      - *
    • type - The type of renderer to be applied.
    • - *
    - * @returns A rendered link to the next page - * @type String - * @see #renderNextLink - */ -jala.ListRenderer.prototype.nextLink_macro = function(param) { - return this.getNextLink(param); -}; - -/** - * Returns the rendered page navigation bar. - * @param {Object} param Extra macro parameters: - *
      - *
    • type - The type of renderer to be applied.
    • - *
    - * @returns The rendered page navigation bar - * @type String - * @see #getPageNavigation - */ -jala.ListRenderer.prototype.pageNavigation_macro = function(param) { - return this.getPageNavigation(param); -}; - -/** - * Returns the total number of items - * @returns The total number of items in the collection this ListRenderer - * instance is working on - * @type Number - */ -jala.ListRenderer.prototype.size_macro = function() { - return Math.min(this.getMaxPages() * this.getPageSize(), - this.getCollection().size()); -}; - -/** - * Returns the total number of pages - * @returns The total number of pages available - * @type Number - */ -jala.ListRenderer.prototype.totalPages_macro = function() { - return this.getTotalPages(); -}; - -/** - * Returns the current page number - * @returns The current page number - * @type Number - */ -jala.ListRenderer.prototype.currentPage_macro = function() { - return this.getCurrentPage(); -}; - -/** - * Returns the start item number in the current page - * @returns The start item number in the current page - * @type Number - */ -jala.ListRenderer.prototype.currentStart_macro = function() { - return this.getStartIndex() + 1; -}; - -/** - * Returns the end item number in the current page - * @returns The end item number in the current page - * @type Number - */ -jala.ListRenderer.prototype.currentEnd_macro = function() { - return this.getEndIndex() + 1; -}; - -/** - * Renders the current page of this list. - * @param {Object} param Extra macro parameters: - *
      - *
    • skin - The name of the list skin to render for each item in the list.
    • - *
    • type - The type of renderer to be applied.
    • - *
    - * @see #renderList - */ -jala.ListRenderer.prototype.render_macro = function(param) { - var skinName; - if (!(skinName = param.skin || this.getItemSkin())) { - res.write("[Name of skin missing]"); - } else { - this.renderList(param); - } - return; -}; - - - -/***************************************************** - ********** D E F A U L T R E N D E R E R ********** - *****************************************************/ - - -/** - * Default Renderer object containing functions - * used for rendering different list items (eg. page navigation, - * prev/next links and list items). - * @final - */ -jala.ListRenderer.defaultRenderer = {}; - -/** - * List renderer object - */ -jala.ListRenderer.defaultRenderer.list = {}; - -/** - * Default renderer method for a list - * @param {Object} item The current list item to render. - * @param {Object} prevItem The previous list item - * @param {Object} param A parameter object containing macro attributes - * and some parameters set by the ListRenderer. - */ -jala.ListRenderer.defaultRenderer.list["default"] = function(item, prevItem, param) { - var p = {"class": (param.index % 2 == 0 ? "even" : "odd")}; - item.renderSkin(param.skin, p); - return; -}; - -/** - * Pagenavigation renderer object - */ -jala.ListRenderer.defaultRenderer.pageNavigation = {}; - -/** - * Default renderer method for a page navigation bar. - * @param {String} what A string indicating what should be rendered. Can be - * either "item" or "navigation" (the former is a single page link, the latter - * is the whole navigation. - * @param {Object} A parameter object containing the macro attributes and some - * attributes set by the ListRenderer. - */ -jala.ListRenderer.defaultRenderer.pageNavigation["default"] = function(what, param) { - var skin; - switch (what) { - case "item": - if (param.selected == true) { - param["class"] = "selected"; - } else { - delete param["class"]; - } - param.text = jala.ListRenderer.html.linkAsString({href: param.url}, param.text); - if (param.skin != null) { - renderSkin(param.skin, param); - } else if ((skin = app.getSkin("Global", "pageNavigationItem", res.skinpath)) != null) { - renderSkin(skin, param); - } else { - if (param["class"]) { - res.write(''); - } else { - res.write(""); - } - res.write(param.text); - res.write(''); - } - break; - - case "navigation": - if (param.skin != null) { - renderSkin(param.skin, param); - } else if ((skin = app.getSkin("Global", "pageNavigation", res.skinpath)) != null) { - renderSkin(skin, param); - } else { - res.write('"); - } - break; - } - return; -}; - -/** - * Pagelink renderer object - */ -jala.ListRenderer.defaultRenderer.pageLink = {}; - -/** - * Default rendering method for a page link (aka "prev/next" link) - * @param {String} what A string indicating what should be rendered. Can be - * either "prev" or "next" - * @param {Object} param A parameter object containing macro attributes and - * some set by the ListRenderer. - */ -jala.ListRenderer.defaultRenderer.pageLink["default"] = function(what, param) { - delete param.index; - if (param.skin) { - renderSkin(param.skin, param); - } else { - jala.ListRenderer.html.link(param, param.text || what); - } - return; -}; - - - -/***************************************** - ********** A R R A Y L I S T ********** - *****************************************/ - - -/** - * Creates a new ArrayList instance. - * @class A simple wrapper around an array to use in conjunction - * with jala.ListRenderer. This wrapper can either handle complete arrays - * or subsections of an array. In the latter case the wrapper needs offset - * and total size information as argument to mimick a complete array. - * @param {Array} arr The array (or a subsection of an array) to wrap - * @param {Number} offset An optional offset to use (mandatory if the array - * is just a subsection). - * @param {Number} total An optional total size of the array. This argument is - * mandatory if the wrapped array is just a subsection. - * @returns A newly created ArrayList instance - * @constructor - */ -jala.ListRenderer.ArrayList = function(arr, offset, total) { - /** - * The offset of this ArrayList instance. This might be > zero for - * ArrayList instances wrapping just a subsection, that is - * mimicking a bigger list. - * @type Number - */ - this.offset = offset || 0; - - /** - * The length of this ArrayList instance. - * @type Number - */ - this.length = total || arr.length; - - /** - * Returns the element at the index position passed - * as argument. If the wrapped array is just a subsection - * the index position passed will be corrected using - * the offset. - * @param {Number} idx The index position of the element - * to return - * @returns The element at the given index position - */ - this.get = function(idx) { - return arr[(this.offset > 0) ? idx - offset : idx]; - }; - - /** - * Returns the size of this ArrayList, which is either - * the length of the wrapped array or the total size - * passed as argument to the constructor (in case the wrapped - * array is just a subsection). - * @returns The size of this ArrayList instance - * @type Number - */ - this.size = function() { - return this.length; - }; - - /** - * Returns true if this ArrayList is a subsection of a bigger array - * @returns True if this ArrayList is a subsection of a bigger array - * @type Boolean - */ - this.isSubset = function() { - return offset || total ? true : false; - }; - - /** - * Returns the actual size of this ArrayList's wrapped array. - * @returns The actual size of this ArrayList's wrapped array. - * @type Number - */ - this.subsetSize = function() { - return arr.length; - }; - - return this; -}; - -/** @ignore */ -jala.ListRenderer.ArrayList.prototype.toString = function() { - return "[jala.ListRenderer.ArrayList]"; -}; diff --git a/modules/jala/code/Mp3.js b/modules/jala/code/Mp3.js deleted file mode 100644 index 2a8cfcd9..00000000 --- a/modules/jala/code/Mp3.js +++ /dev/null @@ -1,1521 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - -/** - * @fileoverview Fields and methods of the jala.audio package. - */ - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - -// Load java libraries -(function() { - var jalaDir = getProperty("jala.dir", "modules/jala"); - // JavaMusicTag (org.farng.mp3.*) - app.addRepository(jalaDir + "/lib/jid3lib-0.5.4.jar"); - // Mp3Info (de.ueberdosis.mp3info.*, required for parseDuration) - app.addRepository(jalaDir + "/lib/id3-1.6.0d9.jar"); -})(); - -// Resolve HelmaLib dependencies -app.addRepository("modules/helma/File.js"); - -/** - * Constructs a new jala.Mp3 wrapper and - * parses the header data of the MP3 file. - * The standard fields for a tag are accessible - * as properties of the new object. - * - * @class This is a class representing an MP3 file - * providing methods to access its metadata. - * - * @param {String|File} file The mp3 file to be parsed, either as - * path string or as any kind of file object - * - * @constructor - */ -jala.Mp3 = function(file) { - - // check and normalize file argument - if (!file) { - throw "jala.Mp3: missing argument"; - } else { - file = new helma.File(file); - } - - try { - var clazz = java.lang.Class.forName("org.farng.mp3.MP3File", - false, app.getClassLoader()) - } catch (e) { - throw "jala.Mp3 requires jid3lib-0.5.4.jar" - + " in lib/ext or modules/jala/lib directory " - + "[http://javamusictag.sourceforge.net/]"; - } - - if (file.getLength() < 128) { - throw "file too short to be an MP3 file (< 128 bytes)"; - } - try { - var mp3File = new Packages.org.farng.mp3.MP3File(file.getAbsolutePath()); - } catch (e) { - throw "error parsing mp3 file: " + e.toString(); - } - - /** - * Returns a helma.File reference to the wrapped file. - * @type helma.File - */ - this.getFile = function() { - return file; - }; - - /** - * Returns the underlying java object - * @type org.farng.mp3.MP3File - */ - this.getJavaObject = function() { - return mp3File; - }; - - - // map to remember tag objects - var tagObjects = {}; - - if (mp3File.hasID3v1Tag()) { - tagObjects[jala.Mp3.Id3v1] = new jala.Mp3.Id3v1(this); - } - - if (mp3File.hasID3v2Tag()) { - tagObjects[jala.Mp3.Id3v2] = new jala.Mp3.Id3v2(this); - } - - /** - * This method creates a new tag object, attaches it - * to the file (thereby replacing an existing tag of - * this type) and returns it. Type is specified using - * the class name in jala.Mp3.*. If a second - * argument is provided, its values are copied into - * the new tag. - * - * @param {Object} tagClass - * @param {Object} tagObject optional tag whose standard - * properties are copied to the new tag. - * @type Object - */ - this.createTag = function(tagClass, tagObject) { - - this.removeTag(tagClass); - tagObjects[tagClass] = new tagClass(this); - // we use zero as default value for empty track numbers. - // this is the same behaviour as with winamp and tag&rename. - tagObjects[tagClass].setTrackNumber("0"); - - if (tagObject) { - tagObjects[tagClass].copyFrom(tagObject); - } - return tagObjects[tagClass]; - }; - - /** - * Returns a tag object, type is specified using the class name - * in jala.Mp3.*. - * @type Object - */ - this.getTag = function(tagClass) { - return tagObjects[tagClass]; - }; - - /** - * Tells if the file contains a certain tag, type is specified - * using the class name in jala.Mp3.* - */ - this.hasTag = function(tagClass) { - return (tagObjects[tagClass]) ? true : false; - }; - - - // field to remember a v2 tag that has to be deleted from the file in save() - var v2JavaTagToDelete = null; - - /** - * Removes a tag from the file, type is specified using the - * class name in jala.Mp3.* - */ - this.removeTag = function(tagClass) { - if (!tagObjects[tagClass]) { - return; - } - - // remember v2 tag here to explicitly delete it from - // the audio file if save() is called ... - // this is a workaround for a bug in JavaMusicTag! - v2JavaTagToDelete = tagObjects[tagClass].getJavaObject(); - - tagObjects[tagClass].removeFromAudio(); - tagObjects[tagClass] = null; - return; - }; - - - /** - * Writes changed metadata back to the source file or to a new file. - * @param {String|helma.File} outFile (optional) save the modified file - * to a different file - * @returns true on success, false if the file contains tags that cannot be saved (Id3v2_2). - * @type Boolean - */ - this.save = function(outFile) { - var tagOptions = Packages.org.farng.mp3.TagOptionSingleton.getInstance(); - // (robert) this appearently fixes the problem that Windows Media Player cannot play files - // anymore if the size of an Id3v2 tag changed - tagOptions.setId3v2PaddingCopyTag(false); - // turn off saving of backup-files: - tagOptions.setOriginalSavedAfterAdjustingID3v2Padding(false); - - if (v2JavaTagToDelete) { - // this is a workaround for a bug in JavaMusicTag: - // MP3File.save() just tries to delete an ID3v2_4 tag, - // but omits 2_3 or 2_2 tags. To be on the safe side - // we have to explicitly remove the deleted v2 tag. - var raf = new java.io.RandomAccessFile(mp3File.getMp3file(), "rw"); - v2JavaTagToDelete["delete"](raf); - v2JavaTagToDelete = null; - raf.close(); - } - - if(tagObjects[jala.Mp3.Id3v2] && tagObjects[jala.Mp3.Id3v2].getSubtype() == 2) { - app.log("Error in jala.Mp3#save: Can't save a tag of version Id3v2_2. Please remove the tag and add a new Id3v2 tag of sub type 3 or 4!"); - return false; - } - - if(outFile) { - var outFile = new helma.File(outFile); - // MP3File.save(file) only saves the tags! - // Thus, we make a hardcopy first. - file.hardCopy(outFile); - } else { - outFile = file; - } - mp3File.save(outFile, - Packages.org.farng.mp3.TagConstant.MP3_FILE_SAVE_OVERWRITE - ); - return true; - }; - - - - // flag to remember if mp3 header has been read - var mp3HeaderRead = false; - - /** - * Makes sure that the mp3 header is read only once - * This takes a few milliseconds, so we only do it when a - * function that depends on header data is called. - * @private - */ - this.readMp3Header = function() { - if (!mp3HeaderRead) { - mp3File.seekMP3Frame(); - mp3HeaderRead = true; - } - return; - }; - - - /** @type String */ - this.album; - - /** @type String */ - this.artist; - - /** @type String */ - this.comment; - - /** @type String */ - this.genre; - - /** @type String */ - this.title; - - /** @type String */ - this.trackNumber; - - /** @type String */ - this.year; - - return this; -}; - -// define getter for standard fields: -try { - jala.Mp3.prototype.__defineGetter__("album", function() { return this.getField("album"); }); - jala.Mp3.prototype.__defineGetter__("artist", function() { return this.getField("artist"); }); - jala.Mp3.prototype.__defineGetter__("comment", function() { return this.getField("comment"); }); - jala.Mp3.prototype.__defineGetter__("genre", function() { return this.getField("genre"); }); - jala.Mp3.prototype.__defineGetter__("title", function() { return this.getField("title"); }); - jala.Mp3.prototype.__defineGetter__("trackNumber", function() { return this.getField("trackNumber"); }); - jala.Mp3.prototype.__defineGetter__("year", function() { return this.getField("year"); }); -} catch (e) { - // older helma versions can't handle __defineGetter__ -} - - -/** - * Array defining valid genres in ID3v1 - * @type Array - * @final - */ -jala.Mp3.GENRES = ["Blues", "Classic Rock", "Country", "Dance", "Disco", - "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", - "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", - "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", - "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", - "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", - "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", - "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", - "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", - "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", - "Native American", "Cabaret", "New Wave", "Psychadelic", "Rave", - "Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", "Polka", - "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk", "Folk-Rock", - "National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival", "Celtic", - "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", - "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", - "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", "Opera", - "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove", - "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", - "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet", "Punk Rock", "Drum Solo", - "Acapella", "Euro-House", "Dance Hall"]; - - -/** - * Array defining mp3 modes. - * @type Array - * @final - */ -jala.Mp3.MODES = ["Stereo", "Joint stereo", "Dual channel", "Mono"]; - - -/** - * Array defining valid text encodings. Note: UTF-8 is valid for v2.4 only. - * UTF-16 with BOM doesn't work with Winamp etc - use UTF-16BE instead! - * The index position within the array defines the number used in the mp3 file. - * @type Array - * @final - */ -jala.Mp3.TEXT_ENCODINGS = ["ISO-8859-1", "UTF-16", "UTF-16BE", "UTF-8"]; - - -/** - * Array defining valid picture types. Note: Most image tagged files come with - * one picture of picture type null! - * The index position within the array defines the number used in the mp3 file. - * @type Array - * @final - */ -jala.Mp3.PICTURE_TYPES = ["Other", "32x32 pixels 'file icon' (PNG only)", - "Other file icon", "Cover (front)", "Cover (back)", "Leaflet page", - "Media (e.g. label side of CD)", "Lead artist/lead performer/soloist", - "Artist/performer", "Conductor", "Band/Orchestra", "Composer", - "Lyricist/text writer", "Recording Location", "During recording", - "During performance", "Movie/video screen capture", "A bright coloured fish", - "Illustration", "Band/artist logotype", "Publisher/Studio logotype"]; - - -/** - * Maps the name of the standard fields to frame ids in the different versions - * of ID3v2. - * @type Object - * @private - * @final - */ -jala.Mp3.FIELD_MAPPING = { - "album": ["", "", "TALB", "TALB", "TALB"], - "artist": ["", "", "TPE1", "TPE1", "TPE1"], - "comment": ["", "", "COMM", "COMM", "COMM"], - "genre": ["", "", "TCON", "TCON", "TCON"], - "title": ["", "", "TIT2", "TIT2", "TIT2"], - "subtitle": ["", "", "TIT3", "TIT3", "TIT3"], - "trackNumber": ["", "", "TRCK", "TRCK", "TRCK"], - "year": ["", "", "TYER", "TYER", "TDRC"], - "author": ["", "", "TCOM", "TCOM", "TCOM"], - "copyright": ["", "", "TCOP", "TCOP", "TCOP"], - "url": ["", "", "WXXX", "WXXX", "WXXX"], - "image": ["", "", "APIC", "APIC", "APIC"] -}; - - -/** - * Helper method to copy the standard fields from one tag - * to another - * @param {Object} src object with setter methods for fields album, artist, - * comment, title, trackNumber, genre and year. - * @param {Object} dest object with getter methods for fields album, artist, - * comment, title, trackNumber, genre and year. - * @returns changed object - * @type Object - * @private - */ -jala.Mp3.copyFields = function(src, dest) { - dest.setAlbum(src.getAlbum()); - dest.setArtist(src.getArtist()); - dest.setComment(src.getComment()); - dest.setTitle(src.getTitle()); - dest.setTrackNumber(src.getTrackNumber()); - dest.setGenre(src.getGenre()); - dest.setYear(src.getYear()); - return dest; -}; - - -/** - * Helper function to handle arguments that may either be a - * number or an object that matches a value in an array. - * In the first case the number itself is returned, in the latter - * case the index position within the array is returned. - * @param {Number|Object} arg argument as number or object - * @param {Array} values Array of objects. - * @returns The number the argument represents - * @type Number - * @private - */ -jala.Mp3.normalizeArg = function(arg, values, defaultValue) { - if (arg == null) { - return defaultValue; - } else if (!isNaN(arg)) { - return parseInt(arg); - } else { - var idx = values.indexOf(arg); - if (idx > 0) { - return idx; - } - } - return null; -}; - - -/** - * The audio length of the file in seconds at best estimate - * from the file info (method returns immediately). - * This method calculates based on the bitrate. Therefore it - * has to produce wrong results for files encoded with variable - * bitrate (vbr). For these files parseDuration() can be used. - * @returns length in seconds - * @type Number - * @see #parseDuration - */ -jala.Mp3.prototype.getDuration = function() { - var bitrate = this.getBitRate(); - if (bitrate != 0) { - return Math.round(this.getSize() / (bitrate * 1000 / 8)); - } - return 0; -}; - - -/** - * Parses the audio file to extract the precise duration of the audio. - * The upside is that it works fine for files with variable bitrates. - * The downside is that this action may take a few seconds depending on - * the size of the audio file. - * @returns length in seconds - * @type Number - * @see #getDuration - */ -jala.Mp3.prototype.parseDuration = function() { - try { - Packages.de.ueberdosis.util.OutputCtr.setLevel(0); // turn off debug output - var reader = Packages.de.ueberdosis.mp3info.ID3Reader(this.getFile().getAbsolutePath()); - var tag = reader.getExtendedID3Tag(); - return tag.getRuntime(); - } catch (e) { - throw "jala.Mp3#parseDuration requires id3-1.6.0d9.jar" - + " in lib/ext or modules/jala/lib directory " - + "[http://sourceforge.net/projects/mp3info/]"; - } -}; - - -/** - * Returns the file size in bytes. - * @type Number - */ -jala.Mp3.prototype.getSize = function() { - return this.getFile().getLength(); -}; - - -/** - * Returns the bit rate the file was encoded with. - * @type Number - */ -jala.Mp3.prototype.getBitRate = function() { - this.readMp3Header() - return this.getJavaObject().getBitRate(); -}; - - -/** - * Returns the channel mode the file was encoded with. - * @type String - */ -jala.Mp3.prototype.getChannelMode = function() { - this.readMp3Header() - return jala.Mp3.MODES[this.getJavaObject().getMode()]; -}; - - -/** - * Returns the frequency the file was encoded with. - * @type Number - */ -jala.Mp3.prototype.getFrequency = function() { - this.readMp3Header() - return this.getJavaObject().getFrequency(); -}; - - -/** - * Returns true if the file is (or seems to be) encoded with - * variable bit rate. FIXME: The current implementation returned - * true for all test files. - * @type Boolean - */ -jala.Mp3.prototype.isVariableBitRate = function() { - this.readMp3Header() - return this.getJavaObject().isVariableBitRate(); -}; - - -/** - * Returns the information for a field from the tags: At first the ID3v2 - * tag is checked. If it isn't present or doesn't contain the field, - * the ID3v1 tag is checked. - * @type {String} - * @private - */ -jala.Mp3.prototype.getField = function(fieldName) { - var funcName = "get" + fieldName.charAt(0).toUpperCase() + fieldName.substring(1); - var tag, value; - var getValue = function() { - if (tag[funcName] != null && tag[funcName] instanceof Function) { - return tag[funcName](); - } - return null; - }; - - if ((tag = this.getV2Tag()) != null && (value = getValue()) != null) { - return value; - } - if ((tag = this.getV1Tag()) != null && (value = getValue()) != null) { - return value; - } - return null; -}; - -/** - * Sets the value of the field with the given name to the value specified, - * in both ID3v1 and ID3v2 tags, but only if the appropriate setter method - * exists. - * @param {String} fieldName The name of the field to set - * @param {String} value The value of the field - * @private - */ -jala.Mp3.prototype.setField = function(fieldName, value) { - if (value != null) { - var funcName = "set" + fieldName.charAt(0).toUpperCase() + fieldName.substring(1); - var setValue = function(tag) { - if (tag[funcName] != null && tag[funcName] instanceof Function) { - tag[funcName](value); - } - return; - }; - - setValue(this.getV2Tag() || this.createV2Tag()); - setValue(this.getV1Tag() || this.createV1Tag()); - } - return; -}; - - -/** - * If the file doesn't contain an ID3v1 tag, this method - * creates a new ID3v1 tag object, attaches it to the file - * and returns it. If a second argument is provided, its - * values are copied into the new tag. - * - * @param {Object} tagObject optional tag whose standard - * properties are copied to the new tag. - * @type jala.Mp3.Id3v1 - */ -jala.Mp3.prototype.createV1Tag = function(tagObject) { - return this.createTag(jala.Mp3.Id3v1, tagObject); -}; - - -/** - * If the file doesn't contain an ID3v2 tag, this method - * creates a new ID3v2 tag object, attaches it to the file - * and returns it. If a second argument is provided, its - * values are copied into the new tag. - * - * @param {Object} tagObject optional tag whose standard - * properties are copied to the new tag. - * @type jala.Mp3.Id3v2 - */ -jala.Mp3.prototype.createV2Tag = function(tagObject) { - return this.createTag(jala.Mp3.Id3v2, tagObject); -}; - - -/** - * @type jala.Mp3.Id3v1 - */ -jala.Mp3.prototype.getV1Tag = function() { - return this.getTag(jala.Mp3.Id3v1); -}; - - -/** - * @type jala.Mp3.Id3v2 - */ -jala.Mp3.prototype.getV2Tag = function() { - return this.getTag(jala.Mp3.Id3v2); -}; - - -/** - * Returns true if the file contains a ID3v1 tag. - * @type Boolean - */ -jala.Mp3.prototype.hasV1Tag = function() { - return this.hasTag(jala.Mp3.Id3v1); -}; - - -/** - * Returns true if the file contains a ID3v2 tag. - * @type Boolean - */ -jala.Mp3.prototype.hasV2Tag = function() { - return this.hasTag(jala.Mp3.Id3v2); -}; - - -/** - * Removes the ID3v1 tag from the file. - */ -jala.Mp3.prototype.removeV1Tag = function() { - this.removeTag(jala.Mp3.Id3v1); -}; - - -/** - * Removes the ID3v2 tag from the file. - */ -jala.Mp3.prototype.removeV2Tag = function() { - return this.removeTag(jala.Mp3.Id3v2); -}; - - -/** @ignore */ -jala.Mp3.prototype.toString = function() { - return "[jala.Mp3 " + this.getFile() + "]"; -}; - -/** - * Returns a plain JavaScript object containing the values of - * all fields stored in either the Id3 V1 or V2 tag - * @returns An object containing the values of all fields - */ -jala.Mp3.prototype.getMetadata = function() { - var result = {}; - // generic metadata values - result.size = this.getSize(); - result.isVariableBitRate = this.isVariableBitRate(); - result.bitrate = this.getBitRate(); - result.frequency = this.getFrequency(); - result.channelMode = this.getChannelMode(); - result.duration = this.parseDuration(); - // Id3 tag values - var fields = [ - "title", - "subtitle", - "author", - "url", - "trackNumber", - "year", - "album", - "artist", - "comment", - "genre", - "copyright", - ]; - var fieldName; - for (var i=0; i get the correct encoding string from constant - encoding = jala.Mp3.TEXT_ENCODINGS[encoding]; - } - return new java.lang.String(new java.lang.String(str).getBytes(encoding)); -}; - - -/** - * Decodes a string using the given encoding. - * @param {String} str string to decode - * @param {String} encoding encoding to use - * @returns decoded string - * @type String - * @private - */ -jala.Mp3.Id3v2.prototype.decodeText = function(str, encoding) { - if (!isNaN(encoding)) { - // if encoding is the byte value -> get the correct encoding string from constant - encoding = jala.Mp3.TEXT_ENCODINGS[encoding] - } - var rawStr = new java.lang.String(str); - return "" + new java.lang.String(rawStr.getBytes(), encoding); -}; - - -/** - * This method can be used to retrieve an arbitrary text frame - * of the underlying tag. For the list of valid identifiers - * and their meaning see http://www.id3.org/ - * The identifiers vary across the sub versions of id3v2 tags, - * use getSubtype to make sure you use the correct version. - * @param {String} id Frame identifier according to Id3v2 specification - * or shortcut as defined in jala.Mp3.FIELD_MAPPING. - * @returns String contained in the frame - * @type String - * @see #getSubtype - */ -jala.Mp3.Id3v2.prototype.getTextContent = function(idStr) { - var id = idStr; - if (jala.Mp3.FIELD_MAPPING[idStr]) { - id = jala.Mp3.FIELD_MAPPING[idStr][this.getSubtype()]; - } - var frame = this.getJavaObject().getFrame(id); - if (frame) { - var body = frame.getBody(); - if (!(body instanceof Packages.org.farng.mp3.id3.FrameBodyUnsupported)) { - return this.decodeText(body.getText(), body.getObject("Text Encoding")); - } - } - return null; -} - - -/** - * This method can be used to set an arbitrary field - * of the underlying tag. For the list of valid identifiers - * and their meaning see http://www.id3.org/ - * The identifiers vary across the sub versions of id3v2 tags, - * use getSubtype to make sure you use the correct version. - * @param {String} id Frame identifier according to Id3v2 specification - * @param {String} value - * @type String - * @see #getSubtype - */ -jala.Mp3.Id3v2.prototype.setTextContent = function(idStr, val) { - var id = idStr; - if (jala.Mp3.FIELD_MAPPING[idStr]) { - id = jala.Mp3.FIELD_MAPPING[idStr][this.getSubtype()]; - } - var frame = this.getJavaObject().getFrame(id); - if (frame) { - var body = frame.getBody(); - // frame already exists, use its encoding: - body.setText(this.encodeText(val, body.getObject("Text Encoding"))); - } else { - // new frame is created, use our own encoding: - var body = new Packages.org.farng.mp3.id3["FrameBody" + id]( - this.getTextEncoding(), this.encodeText(val, this.getTextEncoding()) - ); - this.getJavaObject().setFrame(this.createFrameObject(body)); - } - return; -}; - - -/** - * Creates a new frame object that fits to the tag version. - * @param {org.farng.mp3.id3.AbstractID3v2FrameBody} body frame body object - * @returns new frame object - * @type org.farng.mp3.id.ID3v2_2 - * @private - */ -jala.Mp3.Id3v2.prototype.createFrameObject = function(body) { - var subtype = this.getSubtype(); - if (subtype == 2) { - return new Packages.org.farng.mp3.id3.ID3v2_2Frame(body); - } else if (subtype == 3) { - return new Packages.org.farng.mp3.id3.ID3v2_3Frame(body); - } else if (subtype == 4 || subtype == 0) { - return new Packages.org.farng.mp3.id3.ID3v2_4Frame(body); - } - return null; -}; - - -/** - * Returns the version number of this id3v2 (values 2 to 4 for id3v2.2 to id3v2.4) - * @returns The version number of this Id3v2 tag - * @type Number - */ -jala.Mp3.Id3v2.prototype.getSubtype = function() { - // AbstractID3v2#getRevision() only works for newly constructed tag objects, - // but not for tag objects that have been read from a file. - // so we make a class comparison to find out the subtype: - var obj = this.getJavaObject(); - if (obj instanceof Packages.org.farng.mp3.id3.ID3v2_4) { - return 4; - } else if (obj instanceof Packages.org.farng.mp3.id3.ID3v2_3) { - return 3; - } else if (obj instanceof Packages.org.farng.mp3.id3.ID3v2_2) { - return 2; - } - return 0; -}; - - -/** - * Returns the album information of the tag. - * @returns string containing album name - * @type String - */ -jala.Mp3.Id3v2.prototype.getAlbum = function() { - return this.getTextContent("album"); -}; - - -/** - * Returns the artist information of the tag. - * @returns string containing artist name - * @type String - */ -jala.Mp3.Id3v2.prototype.getArtist = function() { - return this.getTextContent("artist"); -}; - - -/** - * Returns the comment information of the tag. - * @returns string containing comment - * @type String - */ -jala.Mp3.Id3v2.prototype.getComment = function() { - var frame = this.getFrame("comment", "eng", ""); - if (frame) { - var str = frame.getBody().getText(); - return this.decodeText(str, frame.getBody().getObject("Text Encoding")); - } - return null; -}; - - -/** - * Returns the title information of the tag. - * @returns string containing title - * @type String - */ -jala.Mp3.Id3v2.prototype.getTitle = function() { - return this.getTextContent("title"); -}; - - -/** - * Returns the subtitle information of the tag. - * @returns string containing subtitle - * @type String - */ -jala.Mp3.Id3v2.prototype.getSubtitle = function() { - return this.getTextContent("subtitle"); -}; - - -/** - * Returns the track number information of the tag. - * @returns string representing track number - * @type String - */ -jala.Mp3.Id3v2.prototype.getTrackNumber = function() { - return this.getTextContent("trackNumber"); -}; - - -/** - * Returns the genre information of the tag. - * @returns string containing genre name - * @type String - */ -jala.Mp3.Id3v2.prototype.getGenre = function() { - return this.getTextContent("genre"); -}; - - -/** - * Returns the year information of the tag. - * @returns string representing year - * @type String - */ -jala.Mp3.Id3v2.prototype.getYear = function() { - return this.getTextContent("year"); -}; - - -/** - * Returns the author information of the tag. - * @returns string containing author information - * @type String - */ -jala.Mp3.Id3v2.prototype.getAuthor = function() { - return this.getTextContent("author"); -}; - - -/** - * Returns the copyright information of the tag. - * @returns The copyright information of the tag - * @type String - */ -jala.Mp3.Id3v2.prototype.getCopyright = function() { - return this.getTextContent("copyright"); -}; - - -/** - * Returns the Url stored in this tag - * @returns The url stored in this tag - * @type String - */ -jala.Mp3.Id3v2.prototype.getUrl = function() { - var frame = this.getFrame("url", ""); - if (frame) { - return frame.getBody().getUrlLink(); - } - return null; -}; - - -/** - * Sets the album information. - * @param {String} album - */ -jala.Mp3.Id3v2.prototype.setAlbum = function(album) { - this.setTextContent("album", album); - return; -}; - - -/** - * Sets the artist information. - * @param {String} artist - */ -jala.Mp3.Id3v2.prototype.setArtist = function(artist) { - this.setTextContent("artist", artist); - return; -}; - - -/** - * Sets the comment - * @param {String} comment - */ -jala.Mp3.Id3v2.prototype.setComment = function(comment) { - // comment (COMM) isn't a text frame. it supports the getText() - // method but its constructor has a different signature. - var frame = this.getFrame("comment", "eng", ""); - if (frame) { - frame.getBody().setText(this.encodeText(comment, frame.getBody().getObject("Text Encoding"))); - } else { - var body = new Packages.org.farng.mp3.id3.FrameBodyCOMM( - this.getTextEncoding(), "eng", "", this.encodeText(comment, this.getTextEncoding()) - ); - this.getJavaObject().setFrame(this.createFrameObject(body)); - } - return; -}; - - -/** - * Sets the title information - * @param {String} title - */ -jala.Mp3.Id3v2.prototype.setTitle = function(title) { - this.setTextContent("title", title); - return; -}; - - -/** - * Sets the subtitle information - * @param {String} title - */ -jala.Mp3.Id3v2.prototype.setSubtitle = function(title) { - this.setTextContent("subtitle", title); - return; -}; - - -/** - * Sets the track number information. - * @param {Number} trackNumber - */ -jala.Mp3.Id3v2.prototype.setTrackNumber = function(trackNumber) { - this.setTextContent("trackNumber", trackNumber); - return; -}; - - -/** - * Sets the genre information. A list of genre names that are compatible - * with ID3v1 tags is located in jala.Mp3.GENRES. - * @param {String} genre - */ -jala.Mp3.Id3v2.prototype.setGenre = function(genre) { - this.setTextContent("genre", genre); - return; -}; - - -/** - * Sets the year information. - * @param {Number} year - */ -jala.Mp3.Id3v2.prototype.setYear = function(year) { - this.setTextContent("year", year); - return; -}; - - -/** - * Sets the author information in this tag - * @param {String} author The author information to set - */ -jala.Mp3.Id3v2.prototype.setAuthor = function(author) { - this.setTextContent("author", author); - return; -}; - - -/** - * Sets the copyright information in this tag - * @param {String} copyright The copyright information to set - */ -jala.Mp3.Id3v2.prototype.setCopyright = function(copyright) { - this.setTextContent("copyright", copyright); - return; -}; - - -/** - * Stores the Url passed as argument in this tag. - * @param {String} url The url to store in this tag - * @param {String} desc An optiona description of the Url - */ -jala.Mp3.Id3v2.prototype.setUrl = function(url, desc) { - var frame = this.getFrame("url", ""); - if (frame) { - frame.getBody().setUrlLink(url); - } else { - var body = new Packages.org.farng.mp3.id3.FrameBodyWXXX( - this.getTextEncoding(), desc, url - ); - this.getJavaObject().setFrame(this.createFrameObject(body)); - } - return; -}; - - -/** - * Extracts the image from the tag - * @param {String} pictureType number describing picture type - * (default is 3, describing a front cover). - * @returns image as mime object - * @type helma.util.MimePart - */ -jala.Mp3.Id3v2.prototype.getImage = function(pictureType) { - // FIXME: maybe add description to arguments of getFrame? - // more testing needed... - pictureType = jala.Mp3.normalizeArg(pictureType, - jala.Mp3.PICTURE_TYPES, 3); - - var frame = this.getFrame("image", new java.lang.Character(pictureType)); - if (frame) { - var body = frame.getBody(); - var mimeType = body.getObject("MIME Type"); - var imageType = mimeType.substring(6); - var imageName = this.getAudio().getFile().getName().replace(/\.[^\.]+$/i, "") + "." + imageType; - return new Packages.helma.util.MimePart( - imageName, - body.getObject("Picture Data"), - mimeType - ); - } - return null; -}; - - -/** - * adds an image to the file. - * @param {Number} pictureType number determining picture type - * @param {String} mimeType mime type of image - * @param {Array} byteArray image binary data - * @param {String} desc optional description - * @see jala.Mp3 - */ -jala.Mp3.Id3v2.prototype.setImage = function(pictureType, mimeType, byteArray) { - pictureType = jala.Mp3.normalizeArg(pictureType, - jala.Mp3.PICTURE_TYPES, 3); - - var frame = this.getFrame("image", new java.lang.Character(pictureType)); - if (frame) { - if (mimeType && byteArray) { - // set new image data - frame.getBody().setObject("MIME Type", mimeType); - frame.getBody().setObject("Picture Data", byteArray); - } - } else { - // add new image to tag - var body = new Packages.org.farng.mp3.id3.FrameBodyAPIC( - this.getTextEncoding(), - mimeType, - new java.lang.Long(pictureType), - new java.lang.Character(pictureType), - byteArray - ); - this.getJavaObject().setFrame(this.createFrameObject(body)); - } - return; -}; - - -/** @ignore */ -jala.Mp3.Id3v2.prototype.debug = function() { - return "
    " + this.getJavaObject().toString() + "
    "; -}; - - -/** @ignore */ -jala.Mp3.Id3v2.toString = function() { - return "[jala.Mp3.Id3v2]"; -}; - -/** @ignore */ -jala.Mp3.Id3v2.prototype.toString = jala.Mp3.Id3v2.toString; - - -// FIXME: report bug in JavaMusicTag: -// if you delete a v2 tag and call save() JMT calls the delete method of an ID3v2_4 tag. -// this way a 2_2 or 2_3 tag in the file isn't found and not deleted. -// Mp3.save() has a workaround for this. - diff --git a/modules/jala/code/PodcastWriter.js b/modules/jala/code/PodcastWriter.js deleted file mode 100644 index ba7b173a..00000000 --- a/modules/jala/code/PodcastWriter.js +++ /dev/null @@ -1,130 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.PodcastWriter class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * Jala dependencies - */ -app.addRepository(getProperty("jala.dir", "modules/jala") + - "/code/Rss20Writer.js"); - -/** - * @class Class to create, modify and render standard-compliant - * RSS 2.0 feeds including support for Apple's Podcast specification. - * @constructor - * @extends jala.Rss20Writer - * @param {String} header Optional XML header. - */ -jala.PodcastWriter = function(header) { - jala.Rss20Writer.apply(this, arguments); - - var CATEGORY = { - name: "itunes:category", - attributes: { - name: "text" - } - }; - - var OWNER = { - name: "itunes:owner", - value: [{ - name: "itunes:name" - }, { - name: "itunes:email" - }] - }; - - this.addNamespace("itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd"); - - this.extendChannel([{ - name: "itunes:author" - }, { - name: "itunes:subtitle" - }, { - name: "itunes:summary" - }, { - name: "itunes:new-feed-url" - }, { - name: "itunes:image", - attributes: [{ - name: "href" - }] - }, { - name: "itunes:link", - attributes: [{ - name: "rel" - }, { - name: "type" - }, { - name: "href" - }] - }]); - - this.getChannel().setValue(this.createElement(OWNER)); - - this.extendItem([{ - name: "itunes:duration" - }, { - name: "itunes:subtitle" - }]); - - /** - * Add an iTunes Podcast category. - * @param {String} name The category's name. - * @param {String} subName The (optional) sub-category's name. - * @param {jala.XmlWriter.XmlElement} parent Optional parent - * element to add the category to. - */ - this.addItunesCategory = function(name, subName, parent) { - if (!parent) - parent = this.getChannel(); - var cat = this.createElement(CATEGORY); - cat.populate({attributes: {text: name}}); - if (subName) { - var subCat = this.createElement(CATEGORY); - subCat.populate({attributes: {text: subName}}); - cat.addValue(subCat); - } - parent.addValue(cat); - return; - }; - - return this; -}; - - -/** A typical XML header as default. - @type {String} - @final */ -jala.PodcastWriter.XMLHEADER = ''; diff --git a/modules/jala/code/RemoteContent.js b/modules/jala/code/RemoteContent.js deleted file mode 100644 index 6106413d..00000000 --- a/modules/jala/code/RemoteContent.js +++ /dev/null @@ -1,307 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - -/** - * @fileoverview Fields and methods of the jala.RemoteContent class. - */ - -// HelmaLib dependencies -app.addRepository("modules/core/String.js"); -app.addRepository("modules/core/Object.js"); -app.addRepository("modules/core/Date.js"); -app.addRepository("modules/helma/Http.js"); - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - -/** - * Construct a new remote content handler. - * @class API to define, fetch and update content - * from a remote site. - * @param {String} url The URL string of the remote site. - * @param {Integer} method The method to retrieve the remote content. - * @param {File} storage The cache directory. - * @returns A new remote content handler. - * @extends helma.Http - * @constructor - */ -jala.RemoteContent = function(url, method, storage) { - if (typeof PropertyMgr == "undefined") - var PropertyMgr = {}; - - var NULLSTR = ""; - var key = url.md5(); - var fname = key + jala.RemoteContent.SUFFIX; - var cache; - method = (method != null ? method.toLowerCase() : null); - - // depending on the method argument the instance - // becomes extent of the appropriate remote client - switch (method) { - case jala.RemoteContent.XMLRPC: - break; - default: - helma.Http.call(this); - break; - } - - if (!storage) { - storage = jala.RemoteContent.CACHEDIR; - if (!storage.exists() || !storage.isDirectory()) - storage.mkdir(storage.getAbsolutePath()); - } - - var getCache = function() { - switch (storage.constructor) { - case HopObject: - cache = storage; - break; - - case PropertyMgr: - cache = storage.getAll(); - break; - - default: - var f = new File(storage, fname); - cache = f.exists() ? Xml.read(f) : new HopObject(); - } - return cache; - }; - - var setCache = function() { - cache.url = url; - cache.method = method; - if (!cache.interval) { - cache.interval = Date.ONEHOUR; - } - cache.lastUpdate = new Date(); - cache = cache.clone(new HopObject()); - - switch (storage.constructor) { - case HopObject: - for (var i in cache) - storage[i] = cache[i]; - break; - - case PropertyMgr: - storage.setAll(cache); - break; - - default: - var f = new File(storage, fname); - Xml.write(cache, f); - } - return; - }; - - cache = getCache(); - - /** - * Set the interval the remote content's - * cache is bound to be updated. - * @param {Number} interval The interval value in milliseconds. - */ - this.setInterval = function(interval) { - cache.interval = parseInt(interval, 10); - return; - }; - - /** - * Get an arbitrary property of the remote content. - * @param {String} key The name of the property. - * @returns The value of the property. - */ - this.get = function(key) { - return cache[key]; - } - - /** - * Get all available property names. - * @returns The list of property names. - * @type Array - */ - this.getKeys = function() { - var keys = []; - for (var i in cache) { - keys.push(i); - } - return keys.sort(); - }; - - /** - * Tests whether the remote content needs to be updated. - * @returns True if the remote content needs to be updated. - * @type Boolean - */ - this.needsUpdate = function() { - if (!cache.lastUpdate) { - return true; - } else { - var max = new Date() - cache.interval; - if (max - cache.lastUpdate > 0) { - return true; - } - } - return false; - }; - - /** - * Get the updated and cached remote content. - * @returns The content as retrieved from the remote site. - * @type String - */ - this.update = function() { - app.debug("[jala.RemoteContent] Retrieving " + url); - var result; - switch (method) { - case jala.RemoteContent.XMLRPC: - break; - default: - result = this.getUrl(url, cache.lastModified || cache.eTag); - if (result.code != 200 && cache.content) { - // preserve the content received before - result.content = cache.content; - } - result.interval = cache.interval; - cache = result; - } - setCache(); - return cache.content; - }; - - /** - * Flushes (empties) the cached remote content. - */ - this.clear = function() { - switch (storage.constructor) { - case HopObject: - for (var i in storage) - delete storage[i]; - break; - - case PropertyMgr: - storage.reset(); - break; - - default: - var f = new File(storage, fname); - f.remove(); - } - return; - }; - - /** - * Get a string representation of the remote content. - * @returns The remote content as string. - * @type String - */ - this.toString = function() { - return cache.content || NULLSTR; - }; - - /** - * Get the value of the remote content. - * @returns The remote content including response header data. - * @type Object - */ - this.valueOf = function() { - return cache; - }; - - return this; -}; - -/** - * A constant representing the HTTP retrieval method. - * @type int - * @final - */ -jala.RemoteContent.HTTP = 1; - -/** - * A constant representing the XML-RPC retrieval method. - * @type int - * @final - */ -jala.RemoteContent.XMLRPC = 2; - -/** - * The default name of the cache directory. - * @type String - * @final - */ -jala.RemoteContent.SUFFIX = ".cache"; - -/** - * The default cache directory. - * @type File - * @final - */ -jala.RemoteContent.CACHEDIR = new File(app.dir, jala.RemoteContent.SUFFIX); - -/** - * Remove all remote content from a file-based cache. - * @param {File} cache An optional target directory. - */ -jala.RemoteContent.flush = function(cache) { - jala.RemoteContent.forEach(function(rc) { - rc.clear(); - return; - }); - return; -}; - -/** - * Apply a custom method on all remote content in a file-based cache. - * @param {Function} callback The callback method to be executed - * for each remote content file. - * @param {File} cache An optional target directory. - */ -jala.RemoteContent.forEach = function(callback, cache) { - if (!cache) - cache = jala.RemoteContent.CACHEDIR; - var f, rc; - var files = cache.list(); - for (var i in files) { - f = new File(cache, files[i]); - if (!files[i].endsWith(jala.RemoteContent.SUFFIX)) - continue; - rc = new jala.RemoteContent(Xml.read(f).url); - if (callback && callback.constructor == Function) - callback(rc); - } - return; -}; - -/** - * Apply a custom method on all remote content in a file-based cache. - * @param {Function} callback The callback method to be executed - * for each remote content file. - * @param {File} cache An optional target directory. - * @deprecated Use {@link #forEach} instead. - */ -jala.RemoteContent.exec = function() { - jala.RemoteContent.forEach.apply(this, arguments); -}; diff --git a/modules/jala/code/Rss20Writer.js b/modules/jala/code/Rss20Writer.js deleted file mode 100644 index 6edc0137..00000000 --- a/modules/jala/code/Rss20Writer.js +++ /dev/null @@ -1,334 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.Rss20Writer class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * Jala dependencies - */ -app.addRepository(getProperty("jala.dir", "modules/jala") + - "/code/XmlWriter.js"); - -/** - * @class Class to create, modify and render standard-compliant - * RSS 2.0 feeds. - * @constructor - * @extends jala.XmlWriter - * @param {String} header Optional XML header. - */ -jala.Rss20Writer = function(header) { - // defines the prototype of this constructor - jala.XmlWriter.apply(this, arguments); - - // this should do the same but alas, helma throws - // an error the very first time it is executed: - //arguments.callee.prototype = new jala.XmlWriterInterface(); - - var DATEFMT = "EEE, dd MMM yyyy HH:mm:ss Z"; - - var CATEGORY = { - name: "category", - amount: Infinity, - attributes: { - name: "domain", - } - }; - - var ITEM = { - name: "item", - amount: Infinity, - value: [{ - name: "title", - required: true - }, { - name: "link", - }, { - name: "description", - }, { - name: "author", - }, { - name: "comments", - }, { - name: "enclosure", - attributes: [{ - name: "url", - required: true - }, { - name: "length", - required: true - }, { - name: "type", - required: true - }] - }, { - name: "guid", - attributes: [{ - name: "isPermaLink", - type: Boolean - }] - }, { - name: "pubDate", - type: Date, - format: DATEFMT - }, { - name: "source", - attributes: [{ - name: "url", - required: true - }] - }] - }; - - var CHANNEL = { - name: "channel", - value: [{ - name: "title", - required: true - }, { - name: "link", - required: true - }, { - name: "description", - required: true - }, { - name: "language", - }, { - name: "copyright", - }, { - name: "managingEditor", - }, { - name: "webMaster", - }, { - name: "pubDate", - type: Date, - format: DATEFMT - }, { - name: "lastBuildDate", - type: Date, - format: DATEFMT - }, { - name: "generator", - }, { - name: "docs", - }, { - name: "cloud", - attributes: [{ - name: "domain", - }, { - name: "port", - type: Number, - format: "#" - }, { - name: "path", - }, { - name: "registerProcedure", - }, { - name: "protocol", - }] - }, { - name: "ttl", - type: Number, - format: "#" - }, { - name: "rating", - }, { - name: "skipHours", - }, { - name: "skipDays", - }] - }; - - var IMAGE = { - name: "image", - value: [{ - name: "url", - required: true - }, { - name: "title", - required: true - }, { - name: "link", - required: true - }, { - name: "width", - type: Number, - format: "#" - }, { - name: "height", - type: Number, - format: "#" - }, { - name: "description", - }] - }; - - var TEXTINPUT = { - name: "textinput", - value: [{ - name: "title", - required: true - }, { - name: "description", - required: true - }, { - name: "name", - required: true - }, { - name: "link", - required: true - }] - }; - - var ROOT = { - name: "rss", - attributes: [{ - name: "version", - value: "2.0" - }] - }; - - var xmlroot = this.createElement(ROOT); - var channel = this.createElement(CHANNEL); - xmlroot.setValue(channel); - - /** - * Get the writer's root element. - * @returns The writer's root element. - * @type jala.XmlWriter.XmlElement - */ - this.getRoot = function() { - return xmlroot; - }; - - /** - * Add child elements to the channel template. - * @param {Array} ext List of additional child elements. - */ - this.extendChannel = function(ext) { - this.extend(CHANNEL, ext); - channel = this.createElement(CHANNEL); - xmlroot.setValue(channel); - return; - }; - - /** - * Get the writer's channel element. - * @returns The writer's channel element. - * @type jala.XmlWriter.XmlElement - */ - this.getChannel = function() { - return channel; - }; - - /** - * Populate the channel element with data. - * @param {Object} data An XmlWriter-compliant object structure. - * @returns The populated channel element. - * @type jala.XmlWriter.XmlElement - */ - this.setChannel = function(data) { - return channel.populate(data); - }; - - /** - * Add child elements to the item template. - * @param {Array} ext List of additional child elements. - */ - this.extendItem = function(ext) { - this.extend(ITEM, ext); - return; - }; - - /** - * Get a new and innocent item element. - * @param {Object} data An XmlWriter-compliant object structure. - * @returns A new and innocent item element. - * @type jala.XmlWriter.XmlElement - */ - this.createItem = function(data) { - var item = this.createElement(ITEM); - item.populate(data); - return item; - }; - - /** - * Add an item element to the channel element. - * @param {jala.XmlWriter.XmlElement} item The item element to add. - */ - this.addItem = function(item) { - channel.addValue(item); - return; - }; - - /** - * Add a category element to an arbitrary element. - * @param {String} name The name of the category. - * @param {String} domain The domain of the category. - * @param {jala.XmlWriter.XmlElement} parent The optional parent element. - */ - this.addCategory = function(name, domain, parent) { - if (!parent) - parent = channel; - var cat = this.createElement(CATEGORY); - cat.populate({ - value: name, - attributes: {domain: domain} - }); - parent.addValue(cat); - return; - }; - - /** - * Populate the image element with data. - * @param {Object} data An XmlWriter-compliant object structure. - */ - this.setImage = function(data) { - var image = this.createElement(IMAGE); - image.populate(data); - channel.setValue(image); - return; - }; - - /** - * Populate the textInput element with data. - * @param {Object} data An XmlWriter-compliant object structure. - */ - this.setTextInput = function(data) { - var textInput = this.createElement(TEXTINPUT); - textInput.populate(data); - channel.setValue(textInput); - return; - }; - - return this; -}; diff --git a/modules/jala/code/Utilities.js b/modules/jala/code/Utilities.js deleted file mode 100644 index cd6bd706..00000000 --- a/modules/jala/code/Utilities.js +++ /dev/null @@ -1,246 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - -/** - * @fileoverview Fields and methods of the jala.Utilities class. - */ - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - -/** - * HelmaLib dependencies - */ -app.addRepository("modules/core/Number.js"); - -/** - * Construct a utility object. - * @class This class contains various convenience methods - * which do not fit in any other class. - * @returns A new utitilty object. - * @constructor - */ -jala.Utilities = function() { - return this; -}; - -/** - * Return a string representation of the utitility class. - * @returns [jala.Utilities] - * @type String - */ -jala.Utilities.toString = function() { - return "[jala.Utilities]"; -}; - -/** - * Return a string representation of the utitility object. - * @returns [jala.Utilities Object] - * @type String - */ -jala.Utilities.prototype.toString = function() { - return "[jala.Utilities Object]"; -}; - -/** - * Default utility class instance. - * @type jala.Utilities - * @final - */ -jala.util = new jala.Utilities(); - -/** - * Creates a random password with different levels of security. - * @param {Number} len The length of the password (default: 8) - * @param {Number} level The security level - *
      - *
    • 0 - containing only vowels or consonants (default)
    • - *
    • 1 - throws in a number at random position
    • - *
    • 2 - throws in a number and a special character at random position
    • - *
    - * @returns The resulting password - * @type String - */ -jala.Utilities.prototype.createPassword = function(len, level) { - len = len || 8; - level = level || 0; - - var LETTERSONLY = 0; - var WITHNUMBERS = 1; - var WITHSPECIALS = 2; - - var vowels = ['a', 'e', 'i', 'o', 'u']; - var consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']; - var specials = ['.', '#', '!', '$', '%', '&', '?']; - - var posNum = level > LETTERSONLY ? Math.floor(Math.random() * (len - 2)) : -1; - var posSpecial = level > WITHNUMBERS ? Math.floor(Math.random() * (len - 3)) : -2; - if (posNum == posSpecial) { - posSpecial += 1; - } - - res.push(); - // loop to create characters: - var i, rnd; - for (i=0; i<(len-level); i+=1) { - if(i % 2 == 0) { - // every 2nd one is a vowel - rnd = Math.floor(Math.random() * vowels.length); - res.write(vowels[rnd]); - } else { - // every 2nd one is a consonant - rnd = Math.floor(Math.random() * consonants.length); - res.write(consonants[rnd]); - } - if (i == posNum) { - // increased password security: - // throw in a number at random - rnd = Math.floor(Math.random() * specials.length); - res.write(String(rnd + 1)); - } - if (i == posSpecial) { - // increased password security: - // throw in a number at random - rnd = Math.floor(Math.random() * specials.length); - res.write(specials[rnd]); - } - } - return res.pop(); -}; - -/** - * Static field indicating a removed object property. - * @type Number - * @final - */ -jala.Utilities.VALUE_REMOVED = -1; - -/** - * Static field indicating ad added object property. - * @type Number - * @final - */ -jala.Utilities.VALUE_ADDED = 1; - -/** - * Static field indicating a modified object property. - * @type Number - * @final - */ -jala.Utilities.VALUE_MODIFIED = 2; - -/** - * Returns an array containing the properties that are - * added, removed or modified in one object compared to another. - * @param {Object} obj1 The first of two objects which should be compared - * @param {Object} obj2 The second of two objects which should be compared - * @returns An Object containing all properties that are added, removed - * or modified in the second object compared to the first. - * Each property contains a status field with an integer value - * which can be checked against the static jala.Utility fields - * VALUE_ADDED, VALUE_MODIFIED and VALUE_REMOVED. - * @type Object - */ -jala.Utilities.prototype.diffObjects = function(obj1, obj2) { - var childDiff, value1, value2; - var diff = {}; - var foundDiff = false; - - for (var propName in obj1) { - if (obj2[propName] === undefined || obj2[propName] === "" || obj2[propName] === null) { - diff[propName] = {status: jala.Utilities.VALUE_REMOVED}; - foundDiff = true; - } - } - for (var propName in obj2) { - value1 = obj1[propName]; - value2 = obj2[propName]; - if (value1 == null) { - diff[propName] = {status: jala.Utilities.VALUE_ADDED, - value: value2}; - foundDiff = true; - } else { - switch (value2.constructor) { - case HopObject: - case Object: - if (childDiff = this.diffObjects(value1, value2)) { - diff[propName] = childDiff; - foundDiff = true; - } - break; - default: - if (value2 != null && value2 !== "") { - if (value1 === null || value1 === undefined || value1 === "") { - diff[propName] = {status: jala.Utilities.VALUE_ADDED, - value: value2}; - foundDiff = true; - } else if (value1 != value2) { - diff[propName] = {status: jala.Utilities.VALUE_MODIFIED, - value: value2}; - foundDiff = true; - } - } - break; - } - } - } - return foundDiff ? diff : null; -}; - -/** - * Patches an object with a "diff" object created by the - * {@link #diffObjects} method. - * Please mind that this method is recursive, it descends - * along the "diff" object structure. - * @param {Object} obj The Object the diff should be applied to - * @param {Object} diff A "diff" object created by the {@link #diffObjects} method - * @returns The patched Object with all differences applied - * @type Object - */ -jala.Utilities.prototype.patchObject = function(obj, diff) { - var propDiff, value1; - for (var propName in diff) { - propDiff = diff[propName]; - value1 = obj[propName]; - if (propDiff.status != null) { - switch (propDiff.status) { - case jala.Utilities.VALUE_REMOVED: - // app.debug("applyDiff(): removing property " + propName); - delete obj[propName]; - break; - case jala.Utilities.VALUE_ADDED: - case jala.Utilities.VALUE_MODIFIED: - default: - // app.debug("applyDiff(): changing property " + propName + " to " + propDiff.value); - obj[propName] = propDiff.value; - break; - } - } else { - // app.debug("applyDiff(): descending to child object " + propName); - this.patchObject(value1, propDiff); - } - } - return obj; -}; diff --git a/modules/jala/code/XmlRpcRequest.js b/modules/jala/code/XmlRpcRequest.js deleted file mode 100644 index df55778a..00000000 --- a/modules/jala/code/XmlRpcRequest.js +++ /dev/null @@ -1,461 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.XmlRpcRequest class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - - -/** - * A constructor for XmlRpc request objects - * @class Instances of this class provide the necessary functionality - * for issueing XmlRpc requests to a remote service. - * @param {String} url The url of the XmlRpc entry point - * @param {String} methodName The name of the method to call - * @returns A newly created jala.XmlRpcRequest instance - * @constructor - */ -jala.XmlRpcRequest = function(url, methodName) { - /** @ignore */ - var proxy = null; - /** @ignore */ - var timeout = { - "connect": 0, - "socket": 0 - }; - /** @ignore */ - var debug = false; - /** @ignore */ - var credentials = null; - // default input and output encoding - /** @ignore */ - var inputEncoding = "UTF-8"; - /** @ignore */ - var outputEncoding = "UTF-8"; - - /** - * Returns the URL of this request - * @returns The URL of this request - * @type java.net.URL - */ - this.getUrl = function() { - return new java.net.URL(url); - }; - - /** - * Sets the proxy host and port. For Java runtimes < 1.5 this method - * sets the appropriate system properties (so this has an effect on - * all requests based on java.net.URL), for all others the proxy - * is only set for this request. - * @param {String} proxyString The proxy string in the form 'fqdn:port' - * (eg. my.proxy.com:3128) - */ - this.setProxy = function(proxyString) { - if (proxyString && proxyString.trim()) { - var idx = proxyString.indexOf(":"); - if (idx > 0) { - var host = proxyString.substring(0, idx); - var port = proxyString.substring(idx+1); - if (host != null && port != null) { - if (java.lang.Class.forName("java.net.Proxy") != null) { - // construct a proxy instance - var socket = new java.net.InetSocketAddress(host, port); - proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, socket); - } else { - // the pre jdk1.5 way: set the system properties - var sys = java.lang.System.getProperties(); - if (host) { - app.log("[Jala XmlRpc Client] WARNING: setting system http proxy to " - + host + ":" + port); - sys.put("http.proxySet", "true"); - sys.put("http.proxyHost", host); - sys.put("http.proxyPort", port); - } - } - } - } - } - return; - }; - - /** - * Returns the proxy object. This method will only return - * a value if using a java runtime > 1.5 - * @returns The proxy to use for this request - * @type java.net.Proxy - * @see #setProxy - */ - this.getProxy = function() { - return proxy; - }; - - /** - * Sets the credentials for basic http authentication to - * use with this request. - * @param {String} username The username - * @param {String} password The password - */ - this.setCredentials = function(username, password) { - var str = username + ":" + password; - credentials = str.enbase64(); - return; - }; - - /** - * Returns the credentials of this request - * @returns The base46 encoded credentials of this request - * @type String - */ - this.getCredentials = function() { - return credentials; - }; - - /** - * Sets the connection timeout to the specified milliseconds. - * @param {Number} millis The timeout to use as connection timeout - */ - this.setTimeout = function(millis) { - timeout.connect = millis; - return; - }; - - /** - * Sets the socket timeout to the specified milliseconds. - * @param {Number} millis The timeout to use as socket timeout - */ - this.setReadTimeout = function(millis) { - timeout.socket = millis; - return; - }; - - /** - * Returns the connection timeout of this request - * @returns The connection timeout value in milliseconds - * @type Number - */ - this.getTimeout = function() { - return timeout.connect; - }; - - /** - * Returns the socket timeout of this request - * @returns The socket timeout value in milliseconds - * @type Number - */ - this.getReadTimeout = function() { - return timeout.socket; - }; - - /** - * Returns the name of the remote function to call - * @returns The name of the remote function - * @type String - */ - this.getMethodName = function() { - return methodName; - }; - - /** - * Sets both input and output encoding to the - * specified encoding string - * @param {String} enc The encoding to use for - * both input and output. This must be a valid - * java encoding string. - */ - this.setEncoding = function(enc) { - inputEncoding = enc; - outputEncoding = enc; - return; - }; - - /** - * Sets the input encoding to the specified encoding string - * @param {String} enc The encoding to use for input. This must be a valid - * java encoding string. - */ - this.setInputEncoding = function(enc) { - inputEncoding = enc; - return; - }; - - /** - * Sets the output encoding to the specified encoding string - * @param {String} enc The encoding to use for output. This must be a valid - * java encoding string. - */ - this.setOutputEncoding = function(enc) { - outputEncoding = enc; - return; - }; - - /** - * Returns the input encoding - * @returns The input encoding used by this request - * @type String - */ - this.getInputEncoding = function() { - return inputEncoding; - }; - - /** - * Returns the output encoding - * @returns The output encoding used by this request - * @type String - */ - this.getOutputEncoding = function() { - return outputEncoding; - }; - - /** - * Enables or disables the debug mode. If enabled the xml source - * of both request and response is included in the result properties - * 'requestXml' and 'responseXml' - * @param {Boolean} flag True or false. - */ - this.setDebug = function(flag) { - debug = flag; - return; - }; - - /** - * Returns true if debug is enabled for this request, false otherwise - * @returns True if debugging is enabled, false otherwise - * @type Boolean - */ - this.debug = function() { - return debug == true; - }; - - return this; -}; - -/** @ignore */ -jala.XmlRpcRequest.prototype.toString = function() { - return "[Jala XmlRpc Request]"; -}; - -/** - * Calling this method executes the remote method using - * the arguments specified. - * @returns The result of this XmlRpc request - * @type Object - */ -jala.XmlRpcRequest.prototype.execute = function(/** [arg1][, arg2][, ...] */) { - // if in debug mode, log the time the request took to event log - if (app.__app__.debug() == true) { - var start = new Date(); - } - - var tz = java.util.TimeZone.getDefault(); - var reqProcessor = new Packages.org.apache.xmlrpc.XmlRpcClientRequestProcessor(tz); - var resProcessor = new Packages.org.apache.xmlrpc.XmlRpcClientResponseProcessor(tz); - // create the result object - var result = { - error: null, - result: null, - requestXml: null, - responseXml: null - }; - - // convert arguments into their appropriate java representations - var params = new java.util.Vector(); - for (var i=0;i= 1.5) { - conn.setConnectTimeout(this.getTimeout()); - conn.setReadTimeout(this.getReadTimeout()); - } else { - app.logger.debug("WARNING: timeouts can only be using a Java runtime >= 1.5"); - } - // set authentication credentials if defined - if (this.getCredentials() != null) { - conn.setRequestProperty("Authorization", "Basic " + this.getCredentials()); - } - - try { - conn.setDoOutput(true); - var outStream = conn.getOutputStream(); - outStream["write(byte[])"](requestBytes); - outStream.flush(); - outStream.close(); - - if (conn.getContentLength() > 0) { - var inStream = conn.getInputStream(); - if (this.debug() == true) { - inStream = new java.io.BufferedInputStream(conn.getInputStream()); - var outStream = new java.io.ByteArrayOutputStream(); - var buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024); - var bytes; - while ((bytes = inStream.read(buf)) > -1) { - outStream.write(buf, 0, bytes); - } - result.responseXml = outStream.toString(this.getInputEncoding()); - inStream.close(); - // change the inStream and don't set the input encoding of - // the response processor, since the conversion already happened above - inStream = new java.io.ByteArrayInputStream(outStream.toByteArray()); - } - resProcessor.setInputEncoding(this.getInputEncoding()); - var parsedResult = resProcessor.decodeResponse(inStream); - if (parsedResult instanceof java.lang.Exception) { - result.error = parsedResult; - } else { - result.result = jala.XmlRpcRequest.convertResult(parsedResult); - } - } - } catch (e) { - result.error = "[Jala XmlRpc Request] Error executing " + this.getMethodName() - + " with arguments " + jala.XmlRpcRequest.argumentsToString(arguments) - + ", the error is: " + e.toString(); - } - if (app.__app__.debug() == true) { - app.logger.debug("[Jala XmlRpc Request] (" + ((new Date()) - start) + " ms): executed '" - + this.getMethodName() + "' with arguments: " - + jala.XmlRpcRequest.argumentsToString(arguments)); - } - return result; -}; - -/** - * Helper method for converting a Javascript object into - * its appropriate Java object. - * @param {Object} obj The Javascript object to convert - * @returns The appropriate Java representation of the object - * @type java.lang.Object - */ -jala.XmlRpcRequest.convertArgument = function(obj) { - var result; - if (obj instanceof Array) { - // convert into Vector - result = new java.util.Vector(obj.length); - for (var i=0;i 0) { - result = new java.lang.Double(obj); - } else { - result = new java.lang.Integer(obj); - } - } else if (obj instanceof Object) { - // convert into Hashtable - result = new java.util.Hashtable(); - for (var key in obj) { - if (obj[key] != null) { - result.put(key, jala.XmlRpcRequest.convertArgument(obj[key])); - } - } - } else { - result = obj; - } - return result; -}; - -/** - * Converts a Java object into its appropriate Javascript representation. - * @param {java.lang.Object} obj The Java object to convert - * @returns The appropriate Javascript representation of the Java object - * @type Object - */ -jala.XmlRpcRequest.convertResult = function(obj) { - var result; - if (obj instanceof java.util.Vector) { - // convert into Array - result = []; - var e = obj.elements(); - while (e.hasMoreElements()) { - result.push(jala.XmlRpcRequest.convertResult(e.nextElement())); - } - } else if (obj instanceof java.util.Hashtable) { - // convert into Object - result = {}; - var e = obj.keys(); - var key; - while (e.hasMoreElements()) { - key = e.nextElement(); - result[key] = jala.XmlRpcRequest.convertResult(obj.get(key)); - } - } else if (obj instanceof java.lang.String) { - result = String(obj); - } else if (obj instanceof java.lang.Number) { - result = Number(obj); - } else if (obj instanceof java.lang.Boolean) { - result = Boolean(obj); - } else if (obj instanceof java.lang.Date) { - result = new Date(obj.getTime()); - } else { - result = obj; - } - return result; -}; - -/** - * Helper method to format an arguments array into - * a string useable for debugging output. - * @param {Object} args An arguments array - * @returns The arguments array formatted as string - * @type String - */ -jala.XmlRpcRequest.argumentsToString = function(args) { - var arr = []; - for (var i=0;i'; - var LOCALE = java.util.Locale.ENGLISH; - - var write = function(str) { - return res.write(str); - }; - - var writeln = function(str) { - res.write(str); - res.write("\n"); - return; - }; - - var getString = function(data, format) { - if (data == null) - return; - switch (data.constructor) { - case String: - return encodeXml(data); - case Number: - case Date: - if (format && data.format) - return encodeXml(data.format(format, LOCALE)); - else if (data.toUTCString) - return encodeXml(data.toUTCString()); - else - return encodeXml(data.toString()); - break; - case Object: - return null; - } - return encodeXml(data.toString()); - }; - - /** @ignore */ - var XmlElement = function(data) { - if (!data) - throw Error("Insufficient arguments to create XmlElement"); - - var children = {}; - var properties = [ - "name", - "attributes", - "type", - "required", - "format", - "readonly" - ]; - - if (data.value) { - if (data.value.constructor == Object) { - this.value = [new XmlElement(data.value)]; - } else if (data.value.constructor == Array) { - this.value = []; - for (var i in data.value) { - this.value[i] = new XmlElement(data.value[i]); - } - } else - throw Error("Cannot handle unknown type of template value"); - } - - for (var i in properties) { - var key = properties[i]; - this[key] = data[key] || null; - } - - if (this.attributes) { - this.attributes = self.clone(this.attributes); - if (this.attributes.constructor == Object) - this.attributes = [this.attributes]; - } else { - this.attributes = []; - } - - return this; - }; - - /** @ignore */ - XmlElement.toString = function() { - return "[XmlElement constructor]"; - }; - - /** @ignore */ - XmlElement.prototype.setValue = function(element) { - if (element.constructor != this.constructor) - throw Error("Invalid type for XmlElement addition"); - if (!this.value) - this.value = []; - else { - var pos = this.contains(element); - if (pos > -1) - this.value.splice(pos, 1); - } - this.addValue(element); - return this; - }; - - /** @ignore */ - XmlElement.prototype.addValue = function(element) { - if (element.constructor != this.constructor) - throw Error("Invalid type for XmlElement addition"); - if (!this.value) - this.value = []; - this.value.push(element); - return this; - }; - - /** @ignore */ - XmlElement.prototype.contains = function(element) { - if (!this.value || !element) - return -1; - for (var i in this.value) { - if (this.value[i].name == element.name) - return i; - } - return -1; - }; - - /** @ignore */ - XmlElement.prototype.populate = function(data) { - if (this.attributes) { - var value; - for (var i in this.attributes) { - var attr = this.attributes[i]; - if (!attr.name) - throw Error("Cannot populate unnamed attribute entry"); - if (data && data.attributes) - value = data.attributes[attr.name]; - if (data && (data.value || data.attributes) && !value && attr.required) { - throw Error('Missing required ' + (attr.type || Object).name + ' attribute "' + - attr.name + '" in element <' + this.name + '> (' + value + ")"); - } - if (value && attr.type && attr.type != value.constructor) { - throw Error('Type mismatch in attribute "' + - this.name + ":" + attr.name + '"'); - } - if (value) { - app.debug("populating attribute " + attr.name + - " with " + value.constructor.name + ": " + value.toSource()); - } - if (!attr.readonly) { - attr.value = getString(value, attr.format) || attr.value ; - } - } - } - - if (data && data.value) // && data.value.constructor == Object) - data = data.value; - - if (this.value && data) { - for (var i in this.value) { - var element = this.value[i]; - element.populate(data[element.name]); - } - } else { - if (!data && this.required) - throw Error('Missing required element "' + this.name + '"'); - if (data && this.type && this.type != data.constructor) { - throw Error('Type mismatch in element "' + this.name + '"'); - } - if (data) { - app.debug("populating element <" + this.name + "> with " + - (this.type || Object).name + ": " + data.toSource()); - } - if (!this.readonly) - this.value = getString(data, this.format) || this.value; - } - - return; - }; - - /** @ignore */ - XmlElement.prototype.write = function(path) { - if (!path) - path = ""; - - if (!this.value && !this.attributes) - return; - - var attrBuffer = new java.lang.StringBuffer(); - if (this.attributes) { - for (var a in this.attributes) { - var attr = this.attributes[a]; - if (attr.value) { - attrBuffer.append(" " + attr.name + '="'); - attrBuffer.append(attr.value); - attrBuffer.append('"'); - } - } - } - - var attrSize = attrBuffer.length(); - if (!this.value && attrSize < 1) - return; - - write("<" + this.name); - if (attrSize > 0) { - display = true; - write(attrBuffer.toString()); - } - if (this.value) { - write(">"); - if (this.value && this.value.constructor == Array) { - for (var i in this.value) - this.value[i].write(path+"/"+this.name); - } else - write(this.value); - write("\n"); - } else - write("/>\n"); - return; - }; - - /** @ignore */ - XmlElement.prototype.toString = function() { - return "[XmlElement: " + this.toSource() + "]"; - }; - - /** - * Get a newly created XML element. - * @param {Object} data The XML data as object tree. - * @returns The resulting XML element. - * @type jala.XmlWriter.XmlElement - */ - this.createElement = function(data) { - return new XmlElement(data); - }; - - /** - * Get the root XML element of this writer. - * @returns The root XML element. - * @type jala.XmlWriter.XmlElement - */ - this.getRoot = function() { - return new XmlElement({}); - }; - - /** - * Extend a template object. - * @param {Object} template The template object. - * @param {Object} ext The extension object. - * @returns The XML writer. - * @type jala.XmlWriter - */ - this.extend = function(template, ext) { - if (ext.constructor == Object) - ext = [ext]; - if (ext.constructor == Array) { - for (var i in ext) - template.value.push(ext[i]); - } - return this; - }; - - /** - * Add a namespace to this writer. - * @param {String} name The name of the namespace. - * @param {String} url The URL string of the namespace. - * @returns The XML root element. - * @type jala.XmlWriter.XmlElement - */ - this.addNamespace = function(name, url) { - var ref = this.getRoot(); - ref.attributes.push({ - name: "xmlns:" + name, - value: url - }); - return ref; - }; - - /** - * Write the XML to the response buffer. - */ - this.write = function() { - res.contentType = "text/xml"; - writeln(XMLHEADER); - this.getRoot().write(); - return; - }; - - /** - * Get the XML output as string. - * @returns The XML output. - * @type String - */ - this.toString = function() { - res.push(); - this.write(); - return res.pop(); - }; - - /** - * Clone this XML writer. - * @param {Object} The clone templare. - * @returns The cloned XML writer. - * @type jala.XmlWriter - */ - this.clone = function(obj) { - if (!obj || typeof obj != "object") - return obj; - var copy = new obj.constructor; - for (var i in obj) { - if (obj[i].constructor == Object || - obj[i].constructor == Array) - copy[i]= this.clone(obj[i]); - else - copy[i] = obj[i]; - } - return copy; - }; - - return this; -}; - diff --git a/modules/jala/code/all.js b/modules/jala/code/all.js deleted file mode 100644 index 049f528d..00000000 --- a/modules/jala/code/all.js +++ /dev/null @@ -1,75 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Wrapper for automatic inclusion of all Jala modules. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - /** @namespace jala */ - global.jala = {}; -} - - -(function() { - var packages = [ - "AsyncRequest", - "BitTorrent", - "Date", - "DnsClient", - "Captcha", - "Form", - "History", - "HtmlDocument", - "HopObject", - "I18n", - "ImageFilter", - "IndexManager", - "ListRenderer", - "Mp3", - "PodcastWriter", - "RemoteContent", - "Rss20Writer", - "Utilities", - "XmlRpcRequest", - "XmlWriter" - ]; - var jalaDir = getProperty("jala.dir", "modules/jala"); - for (var i in packages) { - app.addRepository(jalaDir + "/code/" + packages[i] + ".js"); - } - return; -})(); - - -/** - * Get a string representation of the Jala library. - * @returns [Jala JavaScript Application Library] - * @type String - */ -jala.toString = function() { - return "[Jala JavaScript Application Library]"; -}; diff --git a/modules/jala/docs/Global.html b/modules/jala/docs/Global.html deleted file mode 100644 index bc9833cc..00000000 --- a/modules/jala/docs/Global.html +++ /dev/null @@ -1,692 +0,0 @@ - - - - - -Global - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class Global

    -
    Object
    -   |
    -   +--Global
    -
    - - -
    -
    - -
    class - Global - - -
    - -
    - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - - <static> Boolean - - - - - isArray(<Object> val) - -
    -            - Returns true if the value passed as argument is an array. -
    - - <static> Boolean - - - - - isBoolean(<Object> val) - -
    -            - Returns true if the value passed as argument is either a boolean - literal or an instance of Boolean. -
    - - <static> Boolean - - - - - isDate(<Object> val) - -
    -            - Returns true if the value passed as argument is either a Javascript date - or an instance of java.util.Date. -
    - - <static> Boolean - - - - - isFunction(<Object> val) - -
    -            - Returns true if the value passed as argument is a function. -
    - - <static> Boolean - - - - - isNull(<Object> val) - -
    -            - Returns true if the value passed as argument is null. -
    - - <static> Boolean - - - - - isNumber(<Object> val) - -
    -            - Returns true if the value passed as argument is either a number, - an instance of Number or of java.lang.Number. -
    - - <static> Boolean - - - - - isObject(<Object> val) - -
    -            - Returns true if the value passed as argument is either a Javascript - object or an instance of java.lang.Object. -
    - - <static> Boolean - - - - - isString(<Object> val) - -
    -            - Returns true if the value passed as argument is either a string literal, - an instance of String or of java.lang.String. -
    - - <static> Boolean - - - - - isUndefined(<Object> val) - -
    -            - Returns true if the value passed as argument is undefined. -
    - - - -

    - - - - - - - - - - - - - - - - - -


    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    isArray

    -
    <static> Boolean isArray(<Object> val)
    - -
      Returns true if the value passed as argument is an array.
    - - - - -
      - Parameters: - -
        val - The value to test -
      - -
    - - - - -
      - Returns: -
        - True if the value is an array, false otherwise -
      -
    - - - - - -
    - - -

    isBoolean

    -
    <static> Boolean isBoolean(<Object> val)
    - -
      Returns true if the value passed as argument is either a boolean - literal or an instance of Boolean.
    - - - - -
      - Parameters: - -
        val - The value to test -
      - -
    - - - - -
      - Returns: -
        - True if the value is a boolean, false otherwise -
      -
    - - - - - -
    - - -

    isDate

    -
    <static> Boolean isDate(<Object> val)
    - -
      Returns true if the value passed as argument is either a Javascript date - or an instance of java.util.Date.
    - - - - -
      - Parameters: - -
        val - The value to test -
      - -
    - - - - -
      - Returns: -
        - True if the value is a date, false otherwise -
      -
    - - - - - -
    - - -

    isFunction

    -
    <static> Boolean isFunction(<Object> val)
    - -
      Returns true if the value passed as argument is a function.
    - - - - -
      - Parameters: - -
        val - The value to test -
      - -
    - - - - -
      - Returns: -
        - True if the argument is a function, false otherwise -
      -
    - - - - - -
    - - -

    isNull

    -
    <static> Boolean isNull(<Object> val)
    - -
      Returns true if the value passed as argument is null.
    - - - - -
      - Parameters: - -
        val - The value to test -
      - -
    - - - - -
      - Returns: -
        - True if the value is null, false otherwise -
      -
    - - - - - -
    - - -

    isNumber

    -
    <static> Boolean isNumber(<Object> val)
    - -
      Returns true if the value passed as argument is either a number, - an instance of Number or of java.lang.Number.
    - - - - -
      - Parameters: - -
        val - The value to test -
      - -
    - - - - -
      - Returns: -
        - True if the value is a number, false otherwise -
      -
    - - - - - -
    - - -

    isObject

    -
    <static> Boolean isObject(<Object> val)
    - -
      Returns true if the value passed as argument is either a Javascript - object or an instance of java.lang.Object.
    - - - - -
      - Parameters: - -
        val - The value to test -
      - -
    - - - - -
      - Returns: -
        - True if the value is an object, false otherwise -
      -
    - - - - - -
    - - -

    isString

    -
    <static> Boolean isString(<Object> val)
    - -
      Returns true if the value passed as argument is either a string literal, - an instance of String or of java.lang.String.
    - - - - -
      - Parameters: - -
        val - The value to test -
      - -
    - - - - -
      - Returns: -
        - True if the value is a string, false otherwise -
      -
    - - - - - -
    - - -

    isUndefined

    -
    <static> Boolean isUndefined(<Object> val)
    - -
      Returns true if the value passed as argument is undefined.
    - - - - -
      - Parameters: - -
        val - The value to test -
      - -
    - - - - -
      - Returns: -
        - True if the value is undefined, false otherwise -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/HopObject.html b/modules/jala/docs/HopObject.html deleted file mode 100644 index 96486a2f..00000000 --- a/modules/jala/docs/HopObject.html +++ /dev/null @@ -1,581 +0,0 @@ - - - - - -HopObject - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class HopObject

    -
    Object
    -   |
    -   +--HopObject
    -
    - - -
    -
    - -
    class - HopObject - - -
    - -
    - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - getAccessName(<Object> obj, <Number> maxLength) - -
    -            - Constructs a name from an object which - is unique in the underlying HopObject collection. -
    - -  Boolean - - - - - isClean() - -
    -            - Returns true if the internal state of this HopObject is CLEAN. -
    - -  Boolean - - - - - isDeleted() - -
    -            - Returns true if the internal state of this HopObject is DELETED. -
    - -  Boolean - - - - - isInvalid() - -
    -            - Returns true if the internal state of this HopObject is INVALID. -
    - -  Boolean - - - - - isModified() - -
    -            - Returns true if the internal state of this HopObject is MODIFIED. -
    - -  Boolean - - - - - isNew() - -
    -            - Returns true if the internal state of this HopObject is NEW. -
    - -  Boolean - - - - - isTransient() - -
    -            - Returns true if the internal state of this HopObject is TRANSIENT. -
    - -  Boolean - - - - - isVirtual() - -
    -            - Returns true if the internal state of this HopObject is VIRTUAL. -
    - - - -

    - - - - - - - - - - - - - - - - - -


    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    getAccessName

    -
    String getAccessName(<Object> obj, <Number> maxLength)
    - -
      Constructs a name from an object which - is unique in the underlying HopObject collection.
    - - - - -
      - Parameters: - -
        obj - The object representing or containing the alias name. Possible object types include:
        • File
        • helma.File
        • java.io.File
        • String
        • java.lang.String
        • Packages.helma.util.MimePart
        -
      - -
        maxLength - The maximum length of the alias -
      - -
    - - - - -
      - Returns: -
        - The resulting alias -
      -
    - - - - - -
    - - -

    isClean

    -
    Boolean isClean()
    - -
      Returns true if the internal state of this HopObject is CLEAN.
    - - - - - - - -
      - Returns: -
        - True if this HopObject is marked as clean, false otherwise. -
      -
    - - - - - -
    - - -

    isDeleted

    -
    Boolean isDeleted()
    - -
      Returns true if the internal state of this HopObject is DELETED.
    - - - - - - - -
      - Returns: -
        - True if this HopObject is marked as deleted, false otherwise. -
      -
    - - - - - -
    - - -

    isInvalid

    -
    Boolean isInvalid()
    - -
      Returns true if the internal state of this HopObject is INVALID.
    - - - - - - - -
      - Returns: -
        - True if this HopObject is marked as invalid, false otherwise. -
      -
    - - - - - -
    - - -

    isModified

    -
    Boolean isModified()
    - -
      Returns true if the internal state of this HopObject is MODIFIED.
    - - - - - - - -
      - Returns: -
        - True if this HopObject is marked as modified, false otherwise. -
      -
    - - - - - -
    - - -

    isNew

    -
    Boolean isNew()
    - -
      Returns true if the internal state of this HopObject is NEW.
    - - - - - - - -
      - Returns: -
        - True if this HopObject is marked as new, false otherwise. -
      -
    - - - - - -
    - - -

    isTransient

    -
    Boolean isTransient()
    - -
      Returns true if the internal state of this HopObject is TRANSIENT.
    - - - - - - - -
      - Returns: -
        - True if this HopObject is marked as transient, false otherwise. -
      -
    - - - - - -
    - - -

    isVirtual

    -
    Boolean isVirtual()
    - -
      Returns true if the internal state of this HopObject is VIRTUAL.
    - - - - - - - -
      - Returns: -
        - True if this HopObject is marked as virtual, false otherwise. -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/allclasses-frame.html b/modules/jala/docs/allclasses-frame.html deleted file mode 100644 index 34273ae9..00000000 --- a/modules/jala/docs/allclasses-frame.html +++ /dev/null @@ -1,323 +0,0 @@ - - - - - - All Classes - - - - - - -

    - -All Classes -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Global -
    -
    HopObject -
    -
    jala -
    -
    jala.AsyncRequest -
    -
    jala.BitTorrent -
    -
    jala.Captcha -
    -
    jala.Date -
    -
    jala.Date.Calendar -
    -
    jala.Date.Calendar.Renderer -
    -
    jala.db -
    -
    jala.db.FileDatabase -
    -
    jala.db.RamDatabase -
    -
    jala.db.Server -
    -
    jala.DnsClient -
    -
    jala.DnsClient.Record -
    -
    jala.Form -
    -
    jala.Form.Component -
    -
    jala.Form.Component.Button -
    -
    jala.Form.Component.Checkbox -
    -
    jala.Form.Component.Date -
    -
    jala.Form.Component.Fieldset -
    -
    jala.Form.Component.File -
    -
    jala.Form.Component.Hidden -
    -
    jala.Form.Component.Image -
    -
    jala.Form.Component.Input -
    -
    jala.Form.Component.Password -
    -
    jala.Form.Component.Radio -
    -
    jala.Form.Component.Select -
    -
    jala.Form.Component.Skin -
    -
    jala.Form.Component.Submit -
    -
    jala.Form.Component.Textarea -
    -
    jala.Form.Tracker -
    -
    jala.History -
    -
    jala.HtmlDocument -
    -
    jala.I18n -
    -
    jala.ImageFilter -
    -
    jala.IndexManager -
    -
    jala.IndexManager.Job -
    -
    jala.ListRenderer -
    -
    jala.ListRenderer.ArrayList -
    -
    jala.Mp3 -
    -
    jala.Mp3.Id3v1 -
    -
    jala.Mp3.Id3v2 -
    -
    jala.PodcastWriter -
    -
    jala.RemoteContent -
    -
    jala.Rss20Writer -
    -
    jala.Utilities -
    -
    jala.XmlRpcRequest -
    -
    jala.XmlWriter -
    -
    - - - diff --git a/modules/jala/docs/allclasses-noframe.html b/modules/jala/docs/allclasses-noframe.html deleted file mode 100644 index d26edc54..00000000 --- a/modules/jala/docs/allclasses-noframe.html +++ /dev/null @@ -1,322 +0,0 @@ - - - - -Jala 1.3 All Classes - - - - - - -

    Jala 1.3

    - -All Classes -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Global -
    -
    HopObject -
    -
    jala -
    -
    jala.AsyncRequest -
    -
    jala.BitTorrent -
    -
    jala.Captcha -
    -
    jala.Date -
    -
    jala.Date.Calendar -
    -
    jala.Date.Calendar.Renderer -
    -
    jala.db -
    -
    jala.db.FileDatabase -
    -
    jala.db.RamDatabase -
    -
    jala.db.Server -
    -
    jala.DnsClient -
    -
    jala.DnsClient.Record -
    -
    jala.Form -
    -
    jala.Form.Component -
    -
    jala.Form.Component.Button -
    -
    jala.Form.Component.Checkbox -
    -
    jala.Form.Component.Date -
    -
    jala.Form.Component.Fieldset -
    -
    jala.Form.Component.File -
    -
    jala.Form.Component.Hidden -
    -
    jala.Form.Component.Image -
    -
    jala.Form.Component.Input -
    -
    jala.Form.Component.Password -
    -
    jala.Form.Component.Radio -
    -
    jala.Form.Component.Select -
    -
    jala.Form.Component.Skin -
    -
    jala.Form.Component.Submit -
    -
    jala.Form.Component.Textarea -
    -
    jala.Form.Tracker -
    -
    jala.History -
    -
    jala.HtmlDocument -
    -
    jala.I18n -
    -
    jala.ImageFilter -
    -
    jala.IndexManager -
    -
    jala.IndexManager.Job -
    -
    jala.ListRenderer -
    -
    jala.ListRenderer.ArrayList -
    -
    jala.Mp3 -
    -
    jala.Mp3.Id3v1 -
    -
    jala.Mp3.Id3v2 -
    -
    jala.PodcastWriter -
    -
    jala.RemoteContent -
    -
    jala.Rss20Writer -
    -
    jala.Utilities -
    -
    jala.XmlRpcRequest -
    -
    jala.XmlWriter -
    -
    - - - diff --git a/modules/jala/docs/constant-values.html b/modules/jala/docs/constant-values.html deleted file mode 100644 index 8ec35f01..00000000 --- a/modules/jala/docs/constant-values.html +++ /dev/null @@ -1,331 +0,0 @@ - - - - -Jala 1.3 Constant Values - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - -
    -

    Constant Field Values

    -
    - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - jala.Form -
    MINLENGTH"minlength"
    MAXLENGTH"maxlength"
    REQUIRE"require"
    CHECKOPTIONS"checkoptions"
    CONTENTTYPE"contenttype"
    MAXWIDTH"maxwidth"
    MINWIDTH"minwidth"
    MAXHEIGHT"maxheight"
    MINHEIGHT"minheight"
    -

    - -

    - - - - - - - - - - - - - - - - - - - - - - - -
    - jala.IndexManager -
    MAXTRIES10
    NORMAL1
    REBUILDING2
    -

    - -

    - - - - - - - - - - - - - - - - - - - - - - - -
    - jala.IndexManager.Job -
    ADD"add"
    REMOVE"remove"
    OPTIMIZE"optimize"
    -

    - -

    - - - - - - - - - - - - - -
    - jala.PodcastWriter -
    XMLHEADER''
    -

    - -

    - - - - - - - - - - - - - - - - - - - - - - - -
    - jala.RemoteContent -
    HTTP1
    XMLRPC2
    SUFFIX".cache"
    -

    - -

    - - - - - - - - - - - - - - - - - - -
    - jala.Utilities -
    VALUE_ADDED1
    VALUE_MODIFIED2
    -

    - -

    - - -


    - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/help-doc.html b/modules/jala/docs/help-doc.html deleted file mode 100644 index f52b22c1..00000000 --- a/modules/jala/docs/help-doc.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - -Jala 1.3 API Help - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - -
    -
    -

    -How This API Document Is Organized

    -
    -This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

    -Class

    -
    - -

    -Each class has its own separate page. Each of these pages has three sections consisting of a class description, summary tables, and detailed member descriptions:

      -
    • Class inheritance diagram
    • Direct Subclasses
    • Class declaration
    • Class description -

      -

    • Field Summary
    • Constructor Summary
    • Method Summary -

      -

    • Field Detail
    • Constructor Detail
    • Method Detail
    -Each summary entry contains the first sentence from the detailed description for that item.
    - - -

    -Index

    -
    -The Index contains an alphabetic list of all classes, constructors, methods, and fields.
    -

    -Prev/Next

    -These links take you to the next or previous class, interface, package, or related page.

    -Frames/No Frames

    -These links show and hide the HTML frames. All pages are available with or without frames. -

    - - -This help file applies to API documentation generated using the standard doclet. - -
    -


    - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/index-all.html b/modules/jala/docs/index-all.html deleted file mode 100644 index e7b51bcf..00000000 --- a/modules/jala/docs/index-all.html +++ /dev/null @@ -1,3562 +0,0 @@ - - - - - -Index () - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - -A B C D E F G H I J K L M N O P Q R S T U V W X Y -
    - - -

    -A

    - -
    -
    ADD - -Class field in class jala.IndexManager.Job -
      -
    - -
    -
    add() - -Instance method in class jala.History -
      -
    - -
    -
    add(doc) - -Instance method in class jala.IndexManager -
      -
    - -
    -
    addCategory(name, domain, parent) - -Instance method in class jala.Rss20Writer -
      -
    - -
    -
    addComponent(component) - -Instance method in class jala.Form -
      -
    - -
    -
    addItem(item) - -Instance method in class jala.Rss20Writer -
      -
    - -
    -
    addItunesCategory(name, subName, parent) - -Instance method in class jala.PodcastWriter -
      -
    - -
    -
    addNamespace(name, url) - -Instance method in class jala.XmlWriter -
      -
    - -
    -
    album - -Instance field in class jala.Mp3 -
      -
    - -
    -
    argumentsToString(args) - -Class method in class jala.XmlRpcRequest -
      -
    - -
    -
    artist - -Instance field in class jala.Mp3 -
      -
    - -
    - -

    -B

    - -
    -
    backup(file) - -Instance method in class jala.db.FileDatabase -
      -
    - -
    -
    bdecode(code) - -Class method in class jala.BitTorrent -
      -
    - -
    -
    bencode(obj) - -Class method in class jala.BitTorrent -
      -
    - -
    - -

    -C

    - -
    -
    CACHEDIR - -Class field in class jala.RemoteContent -
      -
    - -
    -
    calendar - -Instance field in class jala.Date.Calendar.Renderer -
      -
    - -
    -
    callback - -Instance field in class jala.IndexManager.Job -
      -
    - -
    -
    checkLength(reqData) - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    CHECKOPTIONS - -Class field in class jala.Form -
      -
    - -
    -
    checkOptions(reqData) - -Instance method in class jala.Form.Component.Select -
      -
    - -
    -
    checkRequirements(reqData) - -Instance method in class jala.Form.Component.Checkbox -
      -
    - -
    -
    checkRequirements(reqData) - -Instance method in class jala.Form.Component.Date -
      -
    - -
    -
    checkRequirements(reqData) - -Instance method in class jala.Form.Component.File -
      -
    - -
    -
    checkRequirements(reqData) - -Instance method in class jala.Form.Component.Image -
      -
    - -
    -
    checkRequirements(reqData) - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    checkRequirements(reqData) - -Instance method in class jala.Form.Component.Radio -
      -
    - -
    -
    checkRequirements(reqData) - -Instance method in class jala.Form.Component.Select -
      -
    - -
    -
    class_macro() - -Instance method in class jala.Form -
      -
    - -
    -
    class_macro() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    clear() - -Instance method in class jala.History -
      -
    - -
    -
    clear() - -Instance method in class jala.RemoteContent -
      -
    - -
    -
    clone(obj) - -Instance method in class jala.XmlWriter -
      -
    - -
    -
    close_macro() - -Instance method in class jala.Form -
      -
    - -
    -
    cname - -Instance field in class jala.DnsClient.Record -
      -
    - -
    -
    comment - -Instance field in class jala.Mp3 -
      -
    - -
    -
    componentSkin - -Instance field in class jala.Form -
      -
    - -
    -
    containsFileUpload() - -Instance method in class jala.Form -
      -
    - -
    -
    CONTENTTYPE - -Class field in class jala.Form -
      -
    - -
    -
    controls_macro() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    convertArgument(obj) - -Class method in class jala.XmlRpcRequest -
      -
    - -
    -
    convertResult(obj) - -Class method in class jala.XmlRpcRequest -
      -
    - -
    -
    copyFrom(tag) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    copyFrom(tag) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    copyTables(database, tables) - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    countErrors() - -Instance method in class jala.Form -
      -
    - -
    -
    countErrors() - -Instance method in class jala.Form.Tracker -
      -
    - -
    -
    create(config, dataObj) - -Class method in class jala.Form -
      -
    - -
    -
    createDomId() - -Instance method in class jala.Form -
      -
    - -
    -
    createDomId(idPart) - -Instance method in class jala.Form.Component -
      -
    - -
    -
    createElement(data) - -Instance method in class jala.XmlWriter -
      -
    - -
    -
    createItem(data) - -Instance method in class jala.Rss20Writer -
      -
    - -
    -
    createOnDemand(bool) - -Instance method in class jala.db.Server -
      -
    - -
    -
    createPassword(len, level) - -Instance method in class jala.Utilities -
      -
    - -
    -
    createTag(tagClass, tagObject) - -Instance method in class jala.Mp3 -
      -
    - -
    -
    createtime - -Instance field in class jala.IndexManager.Job -
      -
    - -
    -
    createV1Tag(tagObject) - -Instance method in class jala.Mp3 -
      -
    - -
    -
    createV2Tag(tagObject) - -Instance method in class jala.Mp3 -
      -
    - -
    -
    currentEnd_macro() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    currentPage_macro() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    currentStart_macro() - -Instance method in class jala.ListRenderer -
      -
    - -
    - -

    -D

    - -
    -
    date - -Class field in class jala -
      -
    - -
    -
    db - -Class field in class jala -
      -
    - -
    -
    debug() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    defaultRenderer - -Class field in class jala.ListRenderer -
      -
    - -
    -
    diffObjects(obj1, obj2) - -Instance method in class jala.Utilities -
      -
    - -
    -
    dropTable(tableName) - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    dump() - -Instance method in class jala.History -
      -
    - -
    -
    dump(file, props) - -Instance method in class jala.db.RamDatabase -
      -
    - -
    - -

    -E

    - -
    -
    email - -Instance field in class jala.DnsClient.Record -
      -
    - -
    -
    error_macro() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    errors - -Instance field in class jala.Form.Tracker -
      -
    - -
    -
    errors - -Instance field in class jala.IndexManager.Job -
      -
    - -
    -
    evaluate() - -Instance method in class jala.AsyncRequest -
      -
    - -
    -
    exec() - -Class method in class jala.RemoteContent -
      -
    - -
    -
    execute() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    extend(subClass, superClass) - -Class method in class jala.Form -
      -
    - -
    -
    extend(template, ext) - -Instance method in class jala.XmlWriter -
      -
    - -
    -
    extendChannel(ext) - -Instance method in class jala.Rss20Writer -
      -
    - -
    -
    extendItem(ext) - -Instance method in class jala.Rss20Writer -
      -
    - -
    - -

    -F

    - -
    -
    flush(cache) - -Class method in class jala.RemoteContent -
      -
    - -
    -
    forEach(callback, cache) - -Class method in class jala.RemoteContent -
      -
    - -
    -
    formatMessage(message, values) - -Instance method in class jala.I18n -
      -
    - -
    - -

    -G

    - -
    -
    gaussianBlur(radius, amount) - -Instance method in class jala.ImageFilter -
      -
    - -
    -
    genre - -Instance field in class jala.Mp3 -
      -
    - -
    -
    GENRES - -Class field in class jala.Mp3 -
      -
    - -
    -
    get(idx) - -Instance method in class jala.ListRenderer.ArrayList -
      -
    - -
    -
    get(key) - -Instance method in class jala.RemoteContent -
      -
    - -
    -
    get(name) - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    getAccessName(obj, maxLength) - -Instance method in class HopObject -
      -
    - -
    -
    getAccessNameFormat() - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    getAlbum() - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getAlbum() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getAll(elementName) - -Instance method in class jala.HtmlDocument -
      -
    - -
    -
    getArtist() - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getArtist() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getAudio() - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getAudio() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getAuthor() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getBaseHref() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getBitRate() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getBytes() - -Instance method in class jala.ImageFilter -
      -
    - -
    -
    getCalendar(today) - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    getCaptcha() - -Instance method in class jala.Captcha -
      -
    - -
    -
    getCatalog(locale) - -Instance method in class jala.I18n -
      -
    - -
    -
    getChannel() - -Instance method in class jala.Rss20Writer -
      -
    - -
    -
    getChannelMode() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getClassName() - -Instance method in class jala.Form -
      -
    - -
    -
    getCollection() - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    getCollection() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getComment() - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getComment() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getConnection(name, username, password, props) - -Instance method in class jala.db.Server -
      -
    - -
    -
    getConnection(props) - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    getControlAttributes() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    getCopyright() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getCreationDate() - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    getCredentials() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    getCurrentPage() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getData() - -Instance method in class jala.DnsClient.Record -
      -
    - -
    -
    getDataObject() - -Instance method in class jala.Form -
      -
    - -
    -
    getDirectory() - -Instance method in class jala.db.FileDatabase -
      -
    - -
    -
    getDirectory() - -Instance method in class jala.db.Server -
      -
    - -
    -
    getDuration() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getEndIndex() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getErrorMessage() - -Instance method in class jala.Form -
      -
    - -
    -
    getFile() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getFrequency() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getGenre() - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getGenre() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getHrefFormat() - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    getImage() - -Instance method in class jala.ImageFilter -
      -
    - -
    -
    getImage(pictureType) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getInputEncoding() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    getItemSkin() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getJavaObject() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getJavaObject() - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getJavaObject() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getKeys() - -Instance method in class jala.RemoteContent -
      -
    - -
    -
    getLinks() - -Instance method in class jala.HtmlDocument -
      -
    - -
    -
    getList(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getLocale() - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    getLocale(localeId) - -Instance method in class jala.I18n -
      -
    - -
    -
    getLocaleGetter() - -Instance method in class jala.I18n -
      -
    - -
    -
    getMaxPages() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getMessages() - -Instance method in class jala.I18n -
      -
    - -
    -
    getMetadata() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getMethodName() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    getName() - -Instance method in class jala.db.FileDatabase -
      -
    - -
    -
    getName() - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    getNextLink(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getOutputEncoding() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    getPageHref(page) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getPageNavigation(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getPageSize() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getPassword() - -Instance method in class jala.db.FileDatabase -
      -
    - -
    -
    getPassword() - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    getPieceLength() - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    getPort() - -Instance method in class jala.db.Server -
      -
    - -
    -
    getPrevLink(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getProperties(name, username, password, props) - -Instance method in class jala.db.Server -
      -
    - -
    -
    getProperties(props) - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    getProxy() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    getReadTimeout() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    getRenderer() - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    getRenderer() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getRoot() - -Instance method in class jala.Rss20Writer -
      -
    - -
    -
    getRoot() - -Instance method in class jala.XmlWriter -
      -
    - -
    -
    getSize() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getSourceFile() - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    getStartIndex() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getSubtitle() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getSubtype() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getTag(tagClass) - -Instance method in class jala.Mp3 -
      -
    - -
    -
    gettext(key ) - -Instance method in class jala.I18n -
      -
    - -
    -
    getTextContent(id) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getTextContent(idStr) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getTextEncoding() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getTimeout() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    getTimeZone() - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    getTitle() - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getTitle() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getTorrentFile() - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    getTotalPages() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getTracker() - -Instance method in class jala.Form -
      -
    - -
    -
    getTrackNumber() - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getTrackNumber() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getUrl() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    getUrl() - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    getUrl(name, props) - -Instance method in class jala.db.Server -
      -
    - -
    -
    getUrl(props) - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    getUrlParameterName() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getUrlParameters() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    getUsername() - -Instance method in class jala.db.FileDatabase -
      -
    - -
    -
    getUsername() - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    getV1Tag() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getV2Tag() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    getValue() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    getYear() - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    getYear() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    Global - - class Global -
      -
    - -
    - -

    -H

    - -
    -
    handle(reqData, destObj) - -Instance method in class jala.Form -
      -
    - -
    -
    hasError() - -Instance method in class jala.Form -
      -
    - -
    -
    hasError() - -Instance method in class jala.Form.Tracker -
      -
    - -
    -
    hasTag(tagClass) - -Instance method in class jala.Mp3 -
      -
    - -
    -
    hasV1Tag() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    hasV2Tag() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    help_macro() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    HopObject - - class HopObject -
      -
    - -
    -
    host - -Instance field in class jala.DnsClient.Record -
      -
    - -
    -
    html - -Instance field in class jala.Date.Calendar.Renderer -
      -
    - -
    -
    html - -Class field in class jala.Form -
      -
    - -
    -
    HTTP - -Class field in class jala.RemoteContent -
      -
    - -
    - -

    -I

    - -
    -
    i18n - -Class field in class jala -
      -
    - -
    -
    id_macro() - -Instance method in class jala.Form -
      -
    - -
    -
    id_macro() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    ipAddress - -Instance field in class jala.DnsClient.Record -
      -
    - -
    -
    isAlive() - -Instance method in class jala.AsyncRequest -
      -
    - -
    -
    isArray(val) - -Class method in class Global -
      -
    - -
    -
    isBoolean(val) - -Class method in class Global -
      -
    - -
    -
    isClean() - -Instance method in class HopObject -
      -
    - -
    -
    isDate(val) - -Class method in class Global -
      -
    - -
    -
    isDeleted() - -Instance method in class HopObject -
      -
    - -
    -
    isEmail(name, value, reqData, formObj) - -Class method in class jala.Form -
      -
    - -
    -
    isFunction(val) - -Class method in class Global -
      -
    - -
    -
    isInvalid() - -Instance method in class HopObject -
      -
    - -
    -
    isModified() - -Instance method in class HopObject -
      -
    - -
    -
    isNew() - -Instance method in class HopObject -
      -
    - -
    -
    isNull(val) - -Class method in class Global -
      -
    - -
    -
    isNumber(val) - -Class method in class Global -
      -
    - -
    -
    isObject(val) - -Class method in class Global -
      -
    - -
    -
    isPublic(bool) - -Instance method in class jala.db.Server -
      -
    - -
    -
    isRunning() - -Instance method in class jala.db.Server -
      -
    - -
    -
    isString(val) - -Class method in class Global -
      -
    - -
    -
    isSubset() - -Instance method in class jala.ListRenderer.ArrayList -
      -
    - -
    -
    isTransient() - -Instance method in class HopObject -
      -
    - -
    -
    isUndefined(val) - -Class method in class Global -
      -
    - -
    -
    isUrl(name, value, reqData, formObj) - -Class method in class jala.Form -
      -
    - -
    -
    isVariableBitRate() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    isVirtual() - -Instance method in class HopObject -
      -
    - -
    - -

    -J

    - -
    -
    jala - - class jala -
      -
    - -
    -
    jala.AsyncRequest - - class jala.AsyncRequest -
      -
    - -
    -
    jala.AsyncRequest(obj, funcName, args) - -Constructor in class jala.AsyncRequest -
      -
    - -
    -
    jala.BitTorrent - - class jala.BitTorrent -
      -
    - -
    -
    jala.BitTorrent(filePath, trackerUrl) - -Constructor in class jala.BitTorrent -
      -
    - -
    -
    jala.Captcha - - class jala.Captcha -
      -
    - -
    -
    jala.Captcha() - -Constructor in class jala.Captcha -
      -
    - -
    -
    jala.Date - - class jala.Date -
      -
    - -
    -
    jala.Date() - -Constructor in class jala.Date -
      -
    - -
    -
    jala.Date.Calendar - - class jala.Date.Calendar -
      -
    - -
    -
    jala.Date.Calendar(collection) - -Constructor in class jala.Date.Calendar -
      -
    - -
    -
    jala.Date.Calendar.Renderer - - class jala.Date.Calendar.Renderer -
      -
    - -
    -
    jala.Date.Calendar.Renderer(calendar) - -Constructor in class jala.Date.Calendar.Renderer -
      -
    - -
    -
    jala.db - - class jala.db -
      -
    - -
    -
    jala.db.FileDatabase - - class jala.db.FileDatabase -
      -
    - -
    -
    jala.db.FileDatabase(name, directory, username, password) - -Constructor in class jala.db.FileDatabase -
      -
    - -
    -
    jala.db.RamDatabase - - class jala.db.RamDatabase -
      -
    - -
    -
    jala.db.RamDatabase(name, username, password) - -Constructor in class jala.db.RamDatabase -
      -
    - -
    -
    jala.db.Server - - class jala.db.Server -
      -
    - -
    -
    jala.db.Server(baseDir, port) - -Constructor in class jala.db.Server -
      -
    - -
    -
    jala.DnsClient - - class jala.DnsClient -
      -
    - -
    -
    jala.DnsClient(nameServer) - -Constructor in class jala.DnsClient -
      -
    - -
    -
    jala.DnsClient.Record - - class jala.DnsClient.Record -
      -
    - -
    -
    jala.DnsClient.Record(data) - -Constructor in class jala.DnsClient.Record -
      -
    - -
    -
    jala.Form - - class jala.Form -
      -
    - -
    -
    jala.Form(name, dataObj) - -Constructor in class jala.Form -
      -
    - -
    -
    jala.Form.Component - - class jala.Form.Component -
      -
    - -
    -
    jala.Form.Component(name) - -Constructor in class jala.Form.Component -
      -
    - -
    -
    jala.Form.Component.Button - - class jala.Form.Component.Button -
      -
    - -
    -
    jala.Form.Component.Button(name) - -Constructor in class jala.Form.Component.Button -
      -
    - -
    -
    jala.Form.Component.Checkbox - - class jala.Form.Component.Checkbox -
      -
    - -
    -
    jala.Form.Component.Checkbox(name) - -Constructor in class jala.Form.Component.Checkbox -
      -
    - -
    -
    jala.Form.Component.Date - - class jala.Form.Component.Date -
      -
    - -
    -
    jala.Form.Component.Date(name) - -Constructor in class jala.Form.Component.Date -
      -
    - -
    -
    jala.Form.Component.Fieldset - - class jala.Form.Component.Fieldset -
      -
    - -
    -
    jala.Form.Component.Fieldset(name) - -Constructor in class jala.Form.Component.Fieldset -
      -
    - -
    -
    jala.Form.Component.File - - class jala.Form.Component.File -
      -
    - -
    -
    jala.Form.Component.File(name) - -Constructor in class jala.Form.Component.File -
      -
    - -
    -
    jala.Form.Component.Hidden - - class jala.Form.Component.Hidden -
      -
    - -
    -
    jala.Form.Component.Hidden(name) - -Constructor in class jala.Form.Component.Hidden -
      -
    - -
    -
    jala.Form.Component.Image - - class jala.Form.Component.Image -
      -
    - -
    -
    jala.Form.Component.Image() - -Constructor in class jala.Form.Component.Image -
      -
    - -
    -
    jala.Form.Component.Input - - class jala.Form.Component.Input -
      -
    - -
    -
    jala.Form.Component.Input(name) - -Constructor in class jala.Form.Component.Input -
      -
    - -
    -
    jala.Form.Component.Password - - class jala.Form.Component.Password -
      -
    - -
    -
    jala.Form.Component.Password(name) - -Constructor in class jala.Form.Component.Password -
      -
    - -
    -
    jala.Form.Component.Radio - - class jala.Form.Component.Radio -
      -
    - -
    -
    jala.Form.Component.Radio(name) - -Constructor in class jala.Form.Component.Radio -
      -
    - -
    -
    jala.Form.Component.Select - - class jala.Form.Component.Select -
      -
    - -
    -
    jala.Form.Component.Select(name) - -Constructor in class jala.Form.Component.Select -
      -
    - -
    -
    jala.Form.Component.Skin - - class jala.Form.Component.Skin -
      -
    - -
    -
    jala.Form.Component.Skin(name) - -Constructor in class jala.Form.Component.Skin -
      -
    - -
    -
    jala.Form.Component.Submit - - class jala.Form.Component.Submit -
      -
    - -
    -
    jala.Form.Component.Submit(name) - -Constructor in class jala.Form.Component.Submit -
      -
    - -
    -
    jala.Form.Component.Textarea - - class jala.Form.Component.Textarea -
      -
    - -
    -
    jala.Form.Component.Textarea(name) - -Constructor in class jala.Form.Component.Textarea -
      -
    - -
    -
    jala.Form.Tracker - - class jala.Form.Tracker -
      -
    - -
    -
    jala.Form.Tracker(reqData) - -Constructor in class jala.Form.Tracker -
      -
    - -
    -
    jala.History - - class jala.History -
      -
    - -
    -
    jala.History() - -Constructor in class jala.History -
      -
    - -
    -
    jala.HtmlDocument - - class jala.HtmlDocument -
      -
    - -
    -
    jala.HtmlDocument(source) - -Constructor in class jala.HtmlDocument -
      -
    - -
    -
    jala.I18n - - class jala.I18n -
      -
    - -
    -
    jala.I18n() - -Constructor in class jala.I18n -
      -
    - -
    -
    jala.ImageFilter - - class jala.ImageFilter -
      -
    - -
    -
    jala.ImageFilter(img) - -Constructor in class jala.ImageFilter -
      -
    - -
    -
    jala.IndexManager - - class jala.IndexManager -
      -
    - -
    -
    jala.IndexManager(name, dir, lang) - -Constructor in class jala.IndexManager -
      -
    - -
    -
    jala.IndexManager.Job - - class jala.IndexManager.Job -
      -
    - -
    -
    jala.IndexManager.Job(type, callback) - -Constructor in class jala.IndexManager.Job -
      -
    - -
    -
    jala.ListRenderer - - class jala.ListRenderer -
      -
    - -
    -
    jala.ListRenderer(coll, renderer) - -Constructor in class jala.ListRenderer -
      -
    - -
    -
    jala.ListRenderer.ArrayList - - class jala.ListRenderer.ArrayList -
      -
    - -
    -
    jala.ListRenderer.ArrayList(arr, offset, total) - -Constructor in class jala.ListRenderer.ArrayList -
      -
    - -
    -
    jala.Mp3 - - class jala.Mp3 -
      -
    - -
    -
    jala.Mp3(file) - -Constructor in class jala.Mp3 -
      -
    - -
    -
    jala.Mp3.Id3v1 - - class jala.Mp3.Id3v1 -
      -
    - -
    -
    jala.Mp3.Id3v1(audioObj) - -Constructor in class jala.Mp3.Id3v1 -
      -
    - -
    -
    jala.Mp3.Id3v2 - - class jala.Mp3.Id3v2 -
      -
    - -
    -
    jala.Mp3.Id3v2(audioObj) - -Constructor in class jala.Mp3.Id3v2 -
      -
    - -
    -
    jala.PodcastWriter - - class jala.PodcastWriter -
      -
    - -
    -
    jala.PodcastWriter(header) - -Constructor in class jala.PodcastWriter -
      -
    - -
    -
    jala.RemoteContent - - class jala.RemoteContent -
      -
    - -
    -
    jala.RemoteContent(url, method, storage) - -Constructor in class jala.RemoteContent -
      -
    - -
    -
    jala.Rss20Writer - - class jala.Rss20Writer -
      -
    - -
    -
    jala.Rss20Writer(header) - -Constructor in class jala.Rss20Writer -
      -
    - -
    -
    jala.Utilities - - class jala.Utilities -
      -
    - -
    -
    jala.Utilities() - -Constructor in class jala.Utilities -
      -
    - -
    -
    jala.XmlRpcRequest - - class jala.XmlRpcRequest -
      -
    - -
    -
    jala.XmlRpcRequest(url, methodName) - -Constructor in class jala.XmlRpcRequest -
      -
    - -
    -
    jala.XmlWriter - - class jala.XmlWriter -
      -
    - -
    -
    jala.XmlWriter(header) - -Constructor in class jala.XmlWriter -
      -
    - -
    - -

    -K

    - -
    -
    keys() - -Instance method in class jala.BitTorrent -
      -
    - -
    - -

    -L

    - -
    -
    label_macro() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    length - -Instance field in class jala.ListRenderer.ArrayList -
      -
    - -
    -
    limit_macro(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    listComponents() - -Instance method in class jala.Form -
      -
    - -
    -
    log() - -Instance method in class jala.IndexManager -
      -
    - -
    - -

    -M

    - -
    -
    markgettext(key) - -Instance method in class jala.I18n -
      -
    - -
    -
    MAXHEIGHT - -Class field in class jala.Form -
      -
    - -
    -
    MAXLENGTH - -Class field in class jala.Form -
      -
    - -
    -
    MAXTRIES - -Class field in class jala.IndexManager -
      -
    - -
    -
    MAXWIDTH - -Class field in class jala.Form -
      -
    - -
    -
    message_macro(param) - -Instance method in class jala.I18n -
      -
    - -
    -
    MINHEIGHT - -Class field in class jala.Form -
      -
    - -
    -
    MINLENGTH - -Class field in class jala.Form -
      -
    - -
    -
    MINWIDTH - -Class field in class jala.Form -
      -
    - -
    -
    MODES - -Class field in class jala.Mp3 -
      -
    - -
    -
    mx - -Instance field in class jala.DnsClient.Record -
      -
    - -
    - -

    -N

    - -
    -
    name - -Instance field in class jala.Form -
      -
    - -
    -
    name_macro() - -Instance method in class jala.Form -
      -
    - -
    -
    name_macro() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    nameServer - -Instance field in class jala.DnsClient -
      -
    - -
    -
    needsUpdate() - -Instance method in class jala.RemoteContent -
      -
    - -
    -
    nextLink_macro(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    ngettext(singularKey, pluralKey, amount ) - -Instance method in class jala.I18n -
      -
    - -
    -
    NORMAL - -Class field in class jala.IndexManager -
      -
    - -
    - -

    -O

    - -
    -
    offset - -Instance field in class jala.ListRenderer.ArrayList -
      -
    - -
    -
    open_macro() - -Instance method in class jala.Form -
      -
    - -
    -
    OPTIMIZE - -Class field in class jala.IndexManager.Job -
      -
    - -
    -
    optimize() - -Instance method in class jala.IndexManager -
      -
    - -
    - -

    -P

    - -
    -
    pageNavigation_macro(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    parseDuration() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    parseOptions() - -Instance method in class jala.Form.Component.Select -
      -
    - -
    -
    parseValue(reqData) - -Instance method in class jala.Form.Component.Checkbox -
      -
    - -
    -
    parseValue(reqData) - -Instance method in class jala.Form.Component.Date -
      -
    - -
    -
    parseValue(reqData) - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    patchObject(obj, diff) - -Instance method in class jala.Utilities -
      -
    - -
    -
    peek(offset) - -Instance method in class jala.History -
      -
    - -
    -
    PICTURE_TYPES - -Class field in class jala.Mp3 -
      -
    - -
    -
    pop(offset) - -Instance method in class jala.History -
      -
    - -
    -
    prevLink_macro(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    propertyGetter(name, value) - -Class method in class jala.Form -
      -
    - -
    -
    propertySetter(name, value) - -Class method in class jala.Form -
      -
    - -
    -
    push() - -Instance method in class jala.History -
      -
    - -
    - -

    -Q

    - -
    -
    query(dName, queryType) - -Instance method in class jala.DnsClient -
      -
    - -
    -
    queryMailHost(dName) - -Instance method in class jala.DnsClient -
      -
    - -
    - -

    -R

    - -
    -
    REBUILDING - -Class field in class jala.IndexManager -
      -
    - -
    -
    redirect(offset) - -Instance method in class jala.History -
      -
    - -
    -
    REMOVE - -Class field in class jala.IndexManager.Job -
      -
    - -
    -
    remove() - -Instance method in class jala.db.FileDatabase -
      -
    - -
    -
    remove() - -Instance method in class jala.History -
      -
    - -
    -
    remove(id) - -Instance method in class jala.IndexManager -
      -
    - -
    -
    removeFromAudio() - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    removeTag(tagClass) - -Instance method in class jala.Mp3 -
      -
    - -
    -
    removeV1Tag() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    removeV2Tag() - -Instance method in class jala.Mp3 -
      -
    - -
    -
    render() - -Instance method in class jala.Form -
      -
    - -
    -
    render() - -Instance method in class jala.Form.Component -
      -
    - -
    -
    render() - -Instance method in class jala.Form.Component.Fieldset -
      -
    - -
    -
    render() - -Instance method in class jala.Form.Component.Hidden -
      -
    - -
    -
    render() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    render() - -Instance method in class jala.Form.Component.Skin -
      -
    - -
    -
    render(attr, value, reqData) - -Instance method in class jala.Form.Component.Button -
      -
    - -
    -
    render(today) - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    render_macro() - -Instance method in class jala.Form -
      -
    - -
    -
    render_macro() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    render_macro(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    renderAsString(param) - -Instance method in class jala.Form -
      -
    - -
    -
    renderCalendar(date, body, prevMonth, nextMonth) - -Instance method in class jala.Date.Calendar.Renderer -
      -
    - -
    -
    renderControls(attr, value) - -Instance method in class jala.Form.Component.Button -
      -
    - -
    -
    renderControls(attr, value) - -Instance method in class jala.Form.Component.Radio -
      -
    - -
    -
    renderControls(attr, value) - -Instance method in class jala.Form.Component.Submit -
      -
    - -
    -
    renderControls(attr, value, reqData) - -Instance method in class jala.Form.Component.Checkbox -
      -
    - -
    -
    renderControls(attr, value, reqData) - -Instance method in class jala.Form.Component.Date -
      -
    - -
    -
    renderControls(attr, value, reqData) - -Instance method in class jala.Form.Component.File -
      -
    - -
    -
    renderControls(attr, value, reqData) - -Instance method in class jala.Form.Component.Hidden -
      -
    - -
    -
    renderControls(attr, value, reqData) - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    renderControls(attr, value, reqData) - -Instance method in class jala.Form.Component.Password -
      -
    - -
    -
    renderControls(attr, value, reqData) - -Instance method in class jala.Form.Component.Select -
      -
    - -
    -
    renderControls(attr, value, reqData) - -Instance method in class jala.Form.Component.Textarea -
      -
    - -
    -
    renderDay(date, isExisting, isSelected) - -Instance method in class jala.Date.Calendar.Renderer -
      -
    - -
    -
    renderDayHeader(text) - -Instance method in class jala.Date.Calendar.Renderer -
      -
    - -
    -
    renderEditor(prefix, date, fmt) - -Instance method in class jala.Date -
      -
    - -
    -
    renderEditorAsString(prefix, date, pattern) - -Instance method in class jala.Date -
      -
    - -
    -
    renderError() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    renderHelp() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    renderImage() - -Instance method in class jala.Captcha -
      -
    - -
    -
    renderLabel() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    renderList(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    renderListAsString(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    renderNextLink(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    renderNextLinkAsString(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    renderPageNavigation(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    renderPageNavigationAsString(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    renderPrevLink(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    renderPrevLinkAsString(param) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    renderPrevNextLink(date) - -Instance method in class jala.Date.Calendar.Renderer -
      -
    - -
    -
    renderRow(row) - -Instance method in class jala.Date.Calendar.Renderer -
      -
    - -
    -
    reqData - -Instance field in class jala.Form.Tracker -
      -
    - -
    -
    REQUIRE - -Class field in class jala.Form -
      -
    - -
    -
    restore(backupFile) - -Instance method in class jala.db.FileDatabase -
      -
    - -
    -
    run() - -Instance method in class jala.AsyncRequest -
      -
    - -
    -
    runScript(file, props, charset, continueOnError) - -Instance method in class jala.db.RamDatabase -
      -
    - -
    - -

    -S

    - -
    -
    save(destObj, val) - -Instance method in class jala.Form.Component -
      -
    - -
    -
    save(filename) - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    save(outFile) - -Instance method in class jala.Mp3 -
      -
    - -
    -
    save(tracker, destObj) - -Instance method in class jala.Form -
      -
    - -
    -
    save(tracker, destObj) - -Instance method in class jala.Form.Component.Fieldset -
      -
    - -
    -
    save(tracker, destObj) - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    scrape(xpathExpr) - -Instance method in class jala.HtmlDocument -
      -
    - -
    -
    set(name, value) - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    setAccessNameFormat(fmt) - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    setAlbum(album) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    setAlbum(album) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setArtist(artist) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    setArtist(artist) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setAuthor(author) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setBaseHref(href) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    setChannel(data) - -Instance method in class jala.Rss20Writer -
      -
    - -
    -
    setClassName(newClassName) - -Instance method in class jala.Form -
      -
    - -
    -
    setCollection(coll) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    setComment(comment) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    setComment(comment) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setCopyright(copyright) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setCreationDate(date) - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    setCredentials(username, password) - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    setDataObject(newDataObj) - -Instance method in class jala.Form -
      -
    - -
    -
    setDebug(flag) - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    setDelay(millis) - -Instance method in class jala.AsyncRequest -
      -
    - -
    -
    setEncoding(enc) - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    setErrorMessage(newErrorMessage) - -Instance method in class jala.Form -
      -
    - -
    -
    setGenre(genre) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    setGenre(genre) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setHandler(handler) - -Instance method in class jala.I18n -
      -
    - -
    -
    setHrefFormat(fmt) - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    setImage(data) - -Instance method in class jala.Rss20Writer -
      -
    - -
    -
    setImage(pictureType, mimeType, byteArray) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setInputEncoding(enc) - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    setInterval(interval) - -Instance method in class jala.RemoteContent -
      -
    - -
    -
    setItemSkin(name) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    setLocale(loc) - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    setLocaleGetter(func) - -Instance method in class jala.I18n -
      -
    - -
    -
    setMaxPages(pages) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    setMessages(msgObject) - -Instance method in class jala.I18n -
      -
    - -
    -
    setMetadata(metadata) - -Instance method in class jala.Mp3 -
      -
    - -
    -
    setOutputEncoding(enc) - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    setPageSize(size) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    setPieceLength(length) - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    setProxy(proxyString) - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    setReadTimeout(millis) - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    setRenderer(r) - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    setRenderer(r) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    setSubtitle(title) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setTextContent(id, val) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    setTextContent(idStr, val) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setTextEncoding(encType) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setTextInput(data) - -Instance method in class jala.Rss20Writer -
      -
    - -
    -
    setTimeout(millis) - -Instance method in class jala.XmlRpcRequest -
      -
    - -
    -
    setTimeout(seconds) - -Instance method in class jala.AsyncRequest -
      -
    - -
    -
    setTimeZone(tz) - -Instance method in class jala.Date.Calendar -
      -
    - -
    -
    setTitle(title) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    setTitle(title) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setTracker(newTracker) - -Instance method in class jala.Form -
      -
    - -
    -
    setTrackNumber(trackNumber) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    setTrackNumber(trackNumber) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setUrl(url, desc) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    setUrlParameterName(name) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    setUrlParameters(params) - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    setValue(destObj, value) - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    setYear(year) - -Instance method in class jala.Mp3.Id3v1 -
      -
    - -
    -
    setYear(year) - -Instance method in class jala.Mp3.Id3v2 -
      -
    - -
    -
    sharpen(amount) - -Instance method in class jala.ImageFilter -
      -
    - -
    -
    shutdown() - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    size() - -Instance method in class jala.ListRenderer.ArrayList -
      -
    - -
    -
    size_macro() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    start() - -Instance method in class jala.db.Server -
      -
    - -
    -
    stop() - -Instance method in class jala.db.Server -
      -
    - -
    -
    subsetSize() - -Instance method in class jala.ListRenderer.ArrayList -
      -
    - -
    -
    SUFFIX - -Class field in class jala.RemoteContent -
      -
    - -
    - -

    -T

    - -
    -
    tableExists(name) - -Instance method in class jala.db.RamDatabase -
      -
    - -
    -
    text - -Instance field in class jala.DnsClient.Record -
      -
    - -
    -
    TEXT_ENCODINGS - -Class field in class jala.Mp3 -
      -
    - -
    -
    title - -Instance field in class jala.Mp3 -
      -
    - -
    -
    toString() - -Instance method in class jala.BitTorrent -
      -
    - -
    -
    toString() - -Instance method in class jala.Captcha -
      -
    - -
    -
    toString() - -Instance method in class jala.HtmlDocument -
      -
    - -
    -
    toString() - -Instance method in class jala.RemoteContent -
      -
    - -
    -
    toString() - -Instance method in class jala.Utilities -
      -
    - -
    -
    toString() - -Instance method in class jala.XmlWriter -
      -
    - -
    -
    totalPages_macro() - -Instance method in class jala.ListRenderer -
      -
    - -
    -
    trackNumber - -Instance field in class jala.Mp3 -
      -
    - -
    -
    translate(singularKey, pluralKey, amount) - -Instance method in class jala.I18n -
      -
    - -
    -
    type - -Instance field in class jala.DnsClient.Record -
      -
    - -
    -
    type - -Instance field in class jala.IndexManager.Job -
      -
    - -
    -
    TYPE_A - -Class field in class jala.DnsClient -
      -
    - -
    -
    TYPE_CNAME - -Class field in class jala.DnsClient -
      -
    - -
    -
    type_macro() - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    TYPE_MX - -Class field in class jala.DnsClient -
      -
    - -
    -
    TYPE_NS - -Class field in class jala.DnsClient -
      -
    - -
    -
    TYPE_PTR - -Class field in class jala.DnsClient -
      -
    - -
    -
    TYPE_SOA - -Class field in class jala.DnsClient -
      -
    - -
    -
    TYPE_TXT - -Class field in class jala.DnsClient -
      -
    - -
    -
    TYPE_WKS - -Class field in class jala.DnsClient -
      -
    - -
    - -

    -U

    - -
    -
    unsharpMask(radius, amount) - -Instance method in class jala.ImageFilter -
      -
    - -
    -
    update() - -Instance method in class jala.RemoteContent -
      -
    - -
    -
    useSsl(bool) - -Instance method in class jala.db.Server -
      -
    - -
    -
    util - -Class field in class jala -
      -
    - -
    - -

    -V

    - -
    -
    validate(input) - -Instance method in class jala.Captcha -
      -
    - -
    -
    validate(reqData) - -Instance method in class jala.Form -
      -
    - -
    -
    validate(tracker) - -Instance method in class jala.Form.Component -
      -
    - -
    -
    validate(tracker) - -Instance method in class jala.Form.Component.Fieldset -
      -
    - -
    -
    validate(tracker) - -Instance method in class jala.Form.Component.Input -
      -
    - -
    -
    VALUE_ADDED - -Class field in class jala.Utilities -
      -
    - -
    -
    VALUE_MODIFIED - -Class field in class jala.Utilities -
      -
    - -
    -
    VALUE_REMOVED - -Class field in class jala.Utilities -
      -
    - -
    -
    valueOf() - -Instance method in class jala.RemoteContent -
      -
    - -
    -
    values - -Instance field in class jala.Form.Tracker -
      -
    - -
    - -

    -W

    - -
    -
    write() - -Instance method in class jala.XmlWriter -
      -
    - -
    - -

    -X

    - -
    -
    XMLHEADER - -Class field in class jala.PodcastWriter -
      -
    - -
    -
    XMLRPC - -Class field in class jala.RemoteContent -
      -
    - -
    - -

    -Y

    - -
    -
    year - -Instance field in class jala.Mp3 -
      -
    - -
    - -A B C D E F G H I J K L M N O P Q R S T U V W X Y - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/index.html b/modules/jala/docs/index.html deleted file mode 100644 index 8a7b7ade..00000000 --- a/modules/jala/docs/index.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - -Generated Javascript Documentation - - - - - - - - - - - - - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to <A HREF="allclasses-frame.html">Non-frame version.</A> - diff --git a/modules/jala/docs/jala.AsyncRequest.html b/modules/jala/docs/jala.AsyncRequest.html deleted file mode 100644 index 5b8f5c3d..00000000 --- a/modules/jala/docs/jala.AsyncRequest.html +++ /dev/null @@ -1,510 +0,0 @@ - - - - - -jala.AsyncRequest - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.AsyncRequest

    -
    Object
    -   |
    -   +--jala.AsyncRequest
    -
    - - -
    -
    - -
    class - jala.AsyncRequest - - -
    - -

    -
    This class is used to create requests of type "INTERNAL" - (like cron-jobs) that are processed in a separate thread and - therefor asynchronous. -
    Deprecated Use the app.invokeAsync method instead (built-in into Helma as of version 1.6)

    Defined in AsyncRequest.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.AsyncRequest - - (<Object> obj, <String> funcName, <Array> args) - -
    -             - Creates a new AsyncRequest instance. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - evaluate() - -
    -            - Starts this asynchronous request. -
    - -  Boolean - - - - - isAlive() - -
    -            - Returns true if the underlying thread is alive -
    - -  void - - - - - run() - -
    -            - Starts this asynchronous request. -
    - -  void - - - - - setDelay(<Number> millis) - -
    -            - Defines the delay to wait before evaluating this asynchronous request. -
    - -  void - - - - - setTimeout(<Number> seconds) - -
    -            - Sets the timeout of this asynchronous request. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.AsyncRequest

    -
    jala.AsyncRequest(<Object> obj, <String> funcName, <Array> args)
    - - -
      - Creates a new AsyncRequest instance. -
    - - - -
      - Parameters: - -
        obj - Object in whose context the method should be called -
      - -
        funcName - Name of the function to call -
      - -
        args - Array containing the arguments that should be passed to the function (optional). This option is deprecated, instead pass the arguments directly to the run() method. -
      - - -
    - - - - -
      - Returns: -
        - A new instance of AsyncRequest -
      -
    - - - - - -
      -Deprecated Use the app.invokeAsync method instead (built-in into Helma as of version 1.6)

      -
    - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    evaluate

    -
    void evaluate()
    - -
      Starts this asynchronous request.
    - - - - - - - - - - -
      - Deprecated Use run() instead

      -
    - - -
    - - -

    isAlive

    -
    Boolean isAlive()
    - -
      Returns true if the underlying thread is alive
    - - - - - - - -
      - Returns: -
        - True if the underlying thread is alive, false otherwise. -
      -
    - - - - - -
    - - -

    run

    -
    void run()
    - -
      Starts this asynchronous request. Any arguments passed to - this method will be passed to the method executed by - this AsyncRequest instance.
    - - - - - - - - - - - -
    - - -

    setDelay

    -
    void setDelay(<Number> millis)
    - -
      Defines the delay to wait before evaluating this asynchronous request.
    - - - - -
      - Parameters: - -
        millis - Milliseconds to wait -
      - -
    - - - - - - - - -
    - - -

    setTimeout

    -
    void setTimeout(<Number> seconds)
    - -
      Sets the timeout of this asynchronous request.
    - - - - -
      - Parameters: - -
        seconds - Thread-timeout. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.BitTorrent.html b/modules/jala/docs/jala.BitTorrent.html deleted file mode 100644 index 71bed863..00000000 --- a/modules/jala/docs/jala.BitTorrent.html +++ /dev/null @@ -1,879 +0,0 @@ - - - - - -jala.BitTorrent - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.BitTorrent

    -
    Object
    -   |
    -   +--jala.BitTorrent
    -
    - - -
    -
    - -
    class - jala.BitTorrent - - -
    - -

    -
    This class provides methods to create a BitTorrent - metadata file from any desired file. -
    Defined in BitTorrent.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.BitTorrent - - (<String> filePath, <String> trackerUrl) - -
    -             - Constructs a new BitTorrent file. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Object - - - - - get(<String> name) - -
    -            - Get a torrent property. -
    - -  Date - - - - - getCreationDate() - -
    -            - Get the creation date of the torrent. -
    - -  Number - - - - - getPieceLength() - -
    -            - Get the piece length of the torrent. -
    - -  helma.File - - - - - getSourceFile() - -
    -            - Returns the underlying source file. -
    - -  helma.File - - - - - getTorrentFile() - -
    -            - Returns the underlying torrent file. -
    - -  Array - - - - - keys() - -
    -            - Get all available property names. -
    - -  void - - - - - save(<String> filename) - -
    -            - Saves the torrent as file. -
    - -  void - - - - - set(<String> name, <Object> value) - -
    -            - Set a torrent property. -
    - -  void - - - - - setCreationDate(<Date> date) - -
    -            - Set the creation date of the torrent. -
    - -  void - - - - - setPieceLength(<Number> length) - -
    -            - Set the piece length of the torrent. -
    - -  String - - - - - toString() - -
    -            - Get a string representation of the torrent. -
    - - <static> Object - - - - - bdecode(<String> code) - -
    -            - The bdecode method. -
    - - <static> String - - - - - bencode(<Object> obj) - -
    -            - The bencode method. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.BitTorrent

    -
    jala.BitTorrent(<String> filePath, <String> trackerUrl)
    - - -
      - Constructs a new BitTorrent file. -
    - - - -
      - Parameters: - -
        filePath - The path to the original file. -
      - -
        trackerUrl - The URL string of the tracker. -
      - - -
    - - - - -
      - Returns: -
        - A new BitTorrent file. -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    get

    -
    Object get(<String> name)
    - -
      Get a torrent property.
    - - - - -
      - Parameters: - -
        name - The name of the property. -
      - -
    - - - - -
      - Returns: -
        - The value of the property. -
      -
    - - - - - -
    - - -

    getCreationDate

    -
    Date getCreationDate()
    - -
      Get the creation date of the torrent.
    - - - - - - - -
      - Returns: -
        - The torrent's creation date. -
      -
    - - - - - -
    - - -

    getPieceLength

    -
    Number getPieceLength()
    - -
      Get the piece length of the torrent.
    - - - - - - - -
      - Returns: -
        - The torrent's piece length. -
      -
    - - - - - -
    - - -

    getSourceFile

    -
    helma.File getSourceFile()
    - -
      Returns the underlying source file.
    - - - - - - - -
      - Returns: -
        - The source file. -
      -
    - - - - - -
    - - -

    getTorrentFile

    -
    helma.File getTorrentFile()
    - -
      Returns the underlying torrent file.
    - - - - - - - -
      - Returns: -
        - The torrent file. -
      -
    - - - - - -
    - - -

    keys

    -
    Array keys()
    - -
      Get all available property names.
    - - - - - - - -
      - Returns: -
        - The list of property names. -
      -
    - - - - - -
    - - -

    save

    -
    void save(<String> filename)
    - -
      Saves the torrent as file.
    - - - - -
      - Parameters: - -
        filename - An optional name for the torrent file. If no name is given it will be composed from name of source file as defined in the torrent plus the ending ".torrent". -
      - -
    - - - - - - - - -
    - - -

    set

    -
    void set(<String> name, <Object> value)
    - -
      Set a torrent property.
    - - - - -
      - Parameters: - -
        name - The name of the property. -
      - -
        value - The property's value. -
      - -
    - - - - - - - - -
    - - -

    setCreationDate

    -
    void setCreationDate(<Date> date)
    - -
      Set the creation date of the torrent.
    - - - - -
      - Parameters: - -
        date - The desired creation date. -
      - -
    - - - - - - - - -
    - - -

    setPieceLength

    -
    void setPieceLength(<Number> length)
    - -
      Set the piece length of the torrent.
    - - - - -
      - Parameters: - -
        length - The desired piece length. -
      - -
    - - - - - - - - -
    - - -

    toString

    -
    String toString()
    - -
      Get a string representation of the torrent.
    - - - - - - - -
      - Returns: -
        - The torrent as string. -
      -
    - - - - - -
    - - -

    bdecode

    -
    <static> Object bdecode(<String> code)
    - -
      The bdecode method. Turns an encoded string into - a corresponding JavaScript object structure. - FIXME: Handle with caution...
    - - - - -
      - Parameters: - -
        code - The encoded string. -
      - -
    - - - - -
      - Returns: -
        - The decoded JavaScript structure. -
      -
    - - - - - -
    - - -

    bencode

    -
    <static> String bencode(<Object> obj)
    - -
      The bencode method. Turns an arbitrary JavaScript - object structure into a corresponding encoded - string.
    - - - - -
      - Parameters: - -
        obj - The target JavaScript object. -
      - -
    - - - - -
      - Returns: -
        - The encoded string. -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Captcha.html b/modules/jala/docs/jala.Captcha.html deleted file mode 100644 index 742e675b..00000000 --- a/modules/jala/docs/jala.Captcha.html +++ /dev/null @@ -1,461 +0,0 @@ - - - - - -jala.Captcha - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Captcha

    -
    Object
    -   |
    -   +--jala.Captcha
    -
    - - -
    -
    - -
    class - jala.Captcha - - -
    - -

    -
    Wrapper class for the - JCaptcha library. - A captcha (an acronym for "completely automated public - Turing test to tell computers and humans apart") is a - type of challenge-response test used in computing to - determine whether or not the user is human. -
    Defined in Captcha.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Captcha - - () - -
    -             - Construct a new captcha. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  com.octo.captcha.Captcha - - - - - getCaptcha() - -
    -            - Get a new captcha object. -
    - -  void - - - - - renderImage() - -
    -            - Render a new captcha image. -
    - -  String - - - - - toString() - -
    -            - Get a string representation of the captcha object. -
    - -  Boolean - - - - - validate(<String> input) - -
    -            - Validate a user's input with the prompted captcha. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Captcha

    -
    jala.Captcha()
    - - -
      - Construct a new captcha. -
    - - - - - - - - -
      - Returns: -
        - A new captcha. -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    getCaptcha

    -
    com.octo.captcha.Captcha getCaptcha()
    - -
      Get a new captcha object.
    - - - - - - - -
      - Returns: -
        - A new captcha object. -
      -
    - - - - - -
    - - -

    renderImage

    -
    void renderImage()
    - -
      Render a new captcha image.
    - - - - - - - - - - - -
    - - -

    toString

    -
    String toString()
    - -
      Get a string representation of the captcha object.
    - - - - - - - -
      - Returns: -
        - A string representation of the captcha object. -
      -
    - - - - - -
    - - -

    validate

    -
    Boolean validate(<String> input)
    - -
      Validate a user's input with the prompted captcha.
    - - - - -
      - Parameters: - -
        input - The user's input. -
      - -
    - - - - -
      - Returns: -
        - True if the user's input matches the captcha. -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Date.Calendar.Renderer.html b/modules/jala/docs/jala.Date.Calendar.Renderer.html deleted file mode 100644 index 25121432..00000000 --- a/modules/jala/docs/jala.Date.Calendar.Renderer.html +++ /dev/null @@ -1,580 +0,0 @@ - - - - - -jala.Date.Calendar.Renderer - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Date.Calendar.Renderer

    -
    Object
    -   |
    -   +--jala.Date.Calendar.Renderer
    -
    - - -
    -
    - -
    class - jala.Date.Calendar.Renderer - - -
    - -

    -
    A default renderer to use in conjunction with jala.Date.Calendar -
    Defined in Date.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  jala.Date.Calendarcalendar -
    -           The calendar utilizing this renderer instance
    -  helma.Htmlhtml -
    -           An instance of helma.Html used for rendering the calendar
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Date.Calendar.Renderer - - (<jala.Date.Calendar> calendar) - -
    -             - Returns a new instance of the default calendar renderer. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - renderCalendar(<Date> date, <String> body, <Date> prevMonth, <Date> nextMonth) - -
    -            - Renders the calendar directly to response. -
    - -  void - - - - - renderDay(<Date> date, <Boolean> isExisting, <Boolean> isSelected) - -
    -            - Renders a single day within the calendar directly to response. -
    - -  void - - - - - renderDayHeader(<String> text) - -
    -            - Renders a single cell in the calendar day header row directly to response. -
    - -  void - - - - - renderPrevNextLink(<Date> date) - -
    -            - Renders a link to the previous or next month's calendar directly to response. -
    - -  void - - - - - renderRow(<String> row) - -
    -            - Renders a single calendar row directly to response. -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    calendar

    -
    jala.Date.Calendar calendar
    -
      - The calendar utilizing this renderer instance - -
    -
    - - -

    html

    -
    helma.Html html
    -
      - An instance of helma.Html used for rendering the calendar - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Date.Calendar.Renderer

    -
    jala.Date.Calendar.Renderer(<jala.Date.Calendar> calendar)
    - - -
      - Returns a new instance of the default calendar renderer. -
    - - - -
      - Parameters: - -
        calendar - The calendar utilizing this renderer -
      - - -
    - - - - -
      - Returns: -
        - A newly created instance of jala.Date.Calendar.Renderer -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    renderCalendar

    -
    void renderCalendar(<Date> date, <String> body, <Date> prevMonth, <Date> nextMonth)
    - -
      Renders the calendar directly to response.
    - - - - -
      - Parameters: - -
        date - A date object representing this calendar's month and year. Please mind that the day will be set to the last date in this month. -
      - -
        body - The rendered calendar weeks including the day header (basically the whole kernel of the table). -
      - -
        prevMonth - A date object set to the last available date of the previous month. This can be used to render a navigation link to the previous month. -
      - -
        nextMonth - A date object set to the first available date of the next month. This can be used to render a navigation link to the next month. -
      - -
    - - - - - - - - -
    - - -

    renderDay

    -
    void renderDay(<Date> date, <Boolean> isExisting, <Boolean> isSelected)
    - -
      Renders a single day within the calendar directly to response.
    - - - - -
      - Parameters: - -
        date - A date instance representing the day within the calendar. -
      - -
        isExisting - True if there is a child object in the calendar's collection to which the date cell should link to -
      - -
        isSelected - True if this calendar day should be rendered as selected day. -
      - -
    - - - - - - - - -
    - - -

    renderDayHeader

    -
    void renderDayHeader(<String> text)
    - -
      Renders a single cell in the calendar day header row directly to response.
    - - - - -
      - Parameters: - -
        text - The text to display in the header field. -
      - -
    - - - - - - - - -
    - - -

    renderPrevNextLink

    -
    void renderPrevNextLink(<Date> date)
    - -
      Renders a link to the previous or next month's calendar directly to response.
    - - - - -
      - Parameters: - -
        date - A date object set to the previous or next available month. This can be null in case there is no previous or next month. -
      - -
    - - - - - - - - -
    - - -

    renderRow

    -
    void renderRow(<String> row)
    - -
      Renders a single calendar row directly to response.
    - - - - -
      - Parameters: - -
        row - The body of the calendar row. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Date.Calendar.html b/modules/jala/docs/jala.Date.Calendar.html deleted file mode 100644 index 6dde6026..00000000 --- a/modules/jala/docs/jala.Date.Calendar.html +++ /dev/null @@ -1,911 +0,0 @@ - - - - - -jala.Date.Calendar - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Date.Calendar

    -
    Object
    -   |
    -   +--jala.Date.Calendar
    -
    - - -
    -
    - -
    class - jala.Date.Calendar - - -
    - -

    -
    This class represents a calendar based based on a grouped - collection of HopObjects. It provides several methods for rendering - the calendar plus defining locale and timezone settings. -
    Defined in Date.js

    -

    - -
    - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.Date.Calendar.Renderer
    -  - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Date.Calendar - - (<HopObject> collection) - -
    -             - Creates a new instance of jala.Data.Calendar -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - getAccessNameFormat() - -
    -            - Returns the format of the access name used by this calendar to access - child group objects of the collection this calendar is operating on. -
    - -  String - - - - - getCalendar(today) - -
    -            - Returns a rendered calendar -
    - -  HopObject - - - - - getCollection() - -
    -            - Returns the collection this calendar object works on -
    - -  String - - - - - getHrefFormat() - -
    -            - Returns the date formatting pattern used to render hrefs. -
    - -  java.util.Locale - - - - - getLocale() - -
    -            - Returns the locale used within this calendar instance. -
    - -  Object - - - - - getRenderer() - -
    -            - Returns the renderer used by this calendar. -
    - -  java.util.Locale - - - - - getTimeZone() - -
    -            - Returns the locale used within this calendar instance. -
    - -  void - - - - - render(today) - -
    -            - Renders the calendar using either a custom renderer defined - using setRenderer() or the default one. -
    - -  void - - - - - setAccessNameFormat(<String> fmt) - -
    -            - Sets the format of the group name to use when trying to access - child objects of the collection this calendar is operating on. -
    - -  void - - - - - setHrefFormat(<String> fmt) - -
    -            - Sets the format of the hrefs to render by this calendar - to the format pattern passed as argument. -
    - -  void - - - - - setLocale(<java.util.Locale> loc) - -
    -            - Sets the locale to use within this calendar object -
    - -  void - - - - - setRenderer(<Object> r) - -
    -            - Sets the renderer to use. -
    - -  void - - - - - setTimeZone(tz) - -
    -            - Sets the locale to use within this calendar object -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Date.Calendar

    -
    jala.Date.Calendar(<HopObject> collection)
    - - -
      - Creates a new instance of jala.Data.Calendar -
    - - - -
      - Parameters: - -
        collection - A grouped HopObject collection to work on -
      - - -
    - - - - -
      - Returns: -
        - A newly created jala.Date.Calendar instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    getAccessNameFormat

    -
    String getAccessNameFormat()
    - -
      Returns the format of the access name used by this calendar to access - child group objects of the collection this calendar is operating on. - The default format is "yyyyMMdd".
    - - - - - - - -
      - Returns: -
        - The date formatting pattern used to access child objects -
      -
    - - - - - - - -
    - - -

    getCalendar

    -
    String getCalendar(today)
    - -
      Returns a rendered calendar
    - - - - - - - - - - - - - -
    - - -

    getCollection

    -
    HopObject getCollection()
    - -
      Returns the collection this calendar object works on
    - - - - - - - -
      - Returns: -
        - The HopObject collection of this calendar -
      -
    - - - - - -
    - - -

    getHrefFormat

    -
    String getHrefFormat()
    - -
      Returns the date formatting pattern used to render hrefs. The default - format is "yyyyMMdd".
    - - - - - - - -
      - Returns: -
        - The date formatting pattern -
      -
    - - - - - - - -
    - - -

    getLocale

    -
    java.util.Locale getLocale()
    - -
      Returns the locale used within this calendar instance. By default - the locale used by this calendar is the default locale of the - Java Virtual Machine running Helma.
    - - - - - - - -
      - Returns: -
        - The locale of this calendar -
      -
    - - - - - - - -
    - - -

    getRenderer

    -
    Object getRenderer()
    - -
      Returns the renderer used by this calendar.
    - - - - - - - -
      - Returns: -
        - The calendar renderer -
      -
    - - - - - - - -
    - - -

    getTimeZone

    -
    java.util.Locale getTimeZone()
    - -
      Returns the locale used within this calendar instance. By default - the timezone used by this calendar is the default timezone - of the Java Virtual Machine running Helma.
    - - - - - - - -
      - Returns: -
        - The locale of this calendar -
      -
    - - - - - - - -
    - - -

    render

    -
    void render(today)
    - -
      Renders the calendar using either a custom renderer defined - using setRenderer() or the default one.
    - - - - - - - - - - - - - -
    - - -

    setAccessNameFormat

    -
    void setAccessNameFormat(<String> fmt)
    - -
      Sets the format of the group name to use when trying to access - child objects of the collection this calendar is operating on.
    - - - - -
      - Parameters: - -
        fmt - The date format pattern to use for accessing child objects -
      - -
    - - - - - - - - - - -
    - - -

    setHrefFormat

    -
    void setHrefFormat(<String> fmt)
    - -
      Sets the format of the hrefs to render by this calendar - to the format pattern passed as argument.
    - - - - -
      - Parameters: - -
        fmt - The date format pattern to use for rendering the href -
      - -
    - - - - - - - - - - -
    - - -

    setLocale

    -
    void setLocale(<java.util.Locale> loc)
    - -
      Sets the locale to use within this calendar object
    - - - - -
      - Parameters: - -
        loc - The locale to use -
      - -
    - - - - - - - - - - -
    - - -

    setRenderer

    -
    void setRenderer(<Object> r)
    - -
      Sets the renderer to use.
    - - - - -
      - Parameters: - -
        r - The renderer to use -
      - -
    - - - - - - - - - - -
    - - -

    setTimeZone

    -
    void setTimeZone(tz)
    - -
      Sets the locale to use within this calendar object
    - - - - -
      - Parameters: - -
        loc - The locale to use -
      - -
    - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Date.html b/modules/jala/docs/jala.Date.html deleted file mode 100644 index 1c371558..00000000 --- a/modules/jala/docs/jala.Date.html +++ /dev/null @@ -1,389 +0,0 @@ - - - - - -jala.Date - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Date

    -
    Object
    -   |
    -   +--jala.Date
    -
    - - -
    -
    - -
    class - jala.Date - - -
    - -

    -
    This class provides various convenience - methods for rendering purposes. -
    Defined in Date.js

    -

    - -
    - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.Date.Calendar
    -  - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Date - - () - -
    -             - Constructs a new Renderings object. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - renderEditor(<String> prefix, <Date> date, <Object> fmt) - -
    -            - Renders a timestamp as set of DropDown boxes, following the - format passed as argument. -
    - -  String - - - - - renderEditorAsString(prefix, date, pattern) - -
    -            - Returns a timestamp as set of dropdown-boxes -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Date

    -
    jala.Date()
    - - -
      - Constructs a new Renderings object. -
    - - - - - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    renderEditor

    -
    void renderEditor(<String> prefix, <Date> date, <Object> fmt)
    - -
      Renders a timestamp as set of DropDown boxes, following the - format passed as argument. Every <select> - item is prefixed with a string so that it can be retrieved - easily from the values of a submitted POST request.
    - - - - -
      - Parameters: - -
        prefix - The prefix to use for all dropdown boxes, eg. "postdate" -
      - -
        date - A Date object to use as preselection (optional) -
      - -
        fmt - Array containing one parameter object for every single select box that should be rendered, with the following properties set:
        • pattern - The date format pattern that should be rendered. Valid patterns are: "dd", "MM", "yyyy", "HH", "ss".
        • firstOption - The string to use as first option, eg.: "choose a day"
        -
      - -
    - - - - - - - - -
    - - -

    renderEditorAsString

    -
    String renderEditorAsString(prefix, date, pattern)
    - -
      Returns a timestamp as set of dropdown-boxes
    - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.DnsClient.Record.html b/modules/jala/docs/jala.DnsClient.Record.html deleted file mode 100644 index ea3fdd72..00000000 --- a/modules/jala/docs/jala.DnsClient.Record.html +++ /dev/null @@ -1,484 +0,0 @@ - - - - - -jala.DnsClient.Record - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.DnsClient.Record

    -
    Object
    -   |
    -   +--jala.DnsClient.Record
    -
    - - -
    -
    - -
    class - jala.DnsClient.Record - - -
    - -

    -
    Instances of this class wrap record data as received - from the nameserver. -
    Defined in DnsClient.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  Stringcname -
    -           The CNAME of this record.
    -  Stringemail -
    -           The email address responsible for a name server.
    -  Stringhost -
    -           The name of the host.
    -  StringipAddress -
    -           The IP address of the host.
    -  Stringmx -
    -           The name of the mail exchanging server.
    -  Stringtext -
    -           Descriptive text as received from the nameserver.
    -  Numbertype -
    -           The type of the nameserver record represented by this Answer instance.
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.DnsClient.Record - - (<org.wonderly.net.dns.RR> data) - -
    -             - Constructs a new instance of jala.DnsClient.Record. -
    - - - -  - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  org.wonderly.net.dns.RR - - - - - getData() - -
    -            - Returns the wrapped nameserver record data -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    cname

    -
    String cname
    -
      - The CNAME of this record. This will only be set for records - of type CNAME - -
    -
    - - -

    email

    -
    String email
    -
      - The email address responsible for a name server. This property - will only be set for records of type SOA - -
    -
    - - -

    host

    -
    String host
    -
      - The name of the host. This will only be set for records - of type A, AAAA and NS. - -
    -
    - - -

    ipAddress

    -
    String ipAddress
    -
      - The IP address of the host. This will only be set for records - of type A and AAAA - -
    -
    - - -

    mx

    -
    String mx
    -
      - The name of the mail exchanging server. This is only set for - records of type MX - -
    -
    - - -

    text

    -
    String text
    -
      - Descriptive text as received from the nameserver. This is only - set for records of type TXT - -
    -
    - - -

    type

    -
    Number type
    -
      - The type of the nameserver record represented by this Answer instance. - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.DnsClient.Record

    -
    jala.DnsClient.Record(<org.wonderly.net.dns.RR> data)
    - - -
      - Constructs a new instance of jala.DnsClient.Record. -
    - - - -
      - Parameters: - -
        data - The data as received from the nameserver -
      - - -
    - - - - -
      - Returns: -
        - A newly constructed Record instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    getData

    -
    org.wonderly.net.dns.RR getData()
    - -
      Returns the wrapped nameserver record data
    - - - - - - - -
      - Returns: -
        - The wrapped data -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.DnsClient.html b/modules/jala/docs/jala.DnsClient.html deleted file mode 100644 index 8f3d752f..00000000 --- a/modules/jala/docs/jala.DnsClient.html +++ /dev/null @@ -1,591 +0,0 @@ - - - - - -jala.DnsClient - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.DnsClient

    -
    Object
    -   |
    -   +--jala.DnsClient
    -
    - - -
    -
    - -
    class - jala.DnsClient - - -
    - -

    -
    This is a wrapper around the Dns Client by wonderly.org - providing methods for querying Dns servers. For more information - about the Java DNS client visit - https://javadns.dev.java.net/. - Please mind that the nameserver specified must accept queries on port - 53 TCP (the Java DNS client used doesn't support UDP nameserver queries), - and that reverse lookups are not supported. -
    Defined in DnsClient.js

    -

    - -
    - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.DnsClient.Record
    -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  StringnameServer -
    -           Contains the IP Adress/FQDN of the name server to query.
    - <static>  <final> NumberTYPE_A -
    -           The "A" record/query type.
    - <static>  <final> NumberTYPE_CNAME -
    -           The "CNAME" record/query type.
    - <static>  <final> NumberTYPE_MX -
    -           The "MX" record/query type.
    - <static>  <final> NumberTYPE_NS -
    -           The "NS" record/query type.
    - <static>  <final> NumberTYPE_PTR -
    -           The "PTR" record/query type.
    - <static>  <final> NumberTYPE_SOA -
    -           The "SOA" record/query type.
    - <static>  <final> NumberTYPE_TXT -
    -           The "TXT" record/query type.
    - <static>  <final> NumberTYPE_WKS -
    -           The "WKS" record/query type.
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.DnsClient - - (<String> nameServer) - -
    -             - Constructs a new DnsClient object. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  org.wonderly.net.dns.RR - - - - - query(<String> dName, <Number> queryType) - -
    -            - Queries the nameserver for a specific domain - and the given type of record. -
    - -  org.wonderly.net.dns.RR - - - - - queryMailHost(<String> dName) - -
    -            - Convenience method to query for the MX-records - of the domain passed as argument. -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    nameServer

    -
    String nameServer
    -
      - Contains the IP Adress/FQDN of the name server to query. - -
    -
    - - -

    TYPE_A

    -
    <static> <final> Number TYPE_A
    -
      - The "A" record/query type. - -
    -
    - - -

    TYPE_CNAME

    -
    <static> <final> Number TYPE_CNAME
    -
      - The "CNAME" record/query type. - -
    -
    - - -

    TYPE_MX

    -
    <static> <final> Number TYPE_MX
    -
      - The "MX" record/query type. - -
    -
    - - -

    TYPE_NS

    -
    <static> <final> Number TYPE_NS
    -
      - The "NS" record/query type. - -
    -
    - - -

    TYPE_PTR

    -
    <static> <final> Number TYPE_PTR
    -
      - The "PTR" record/query type. - -
    -
    - - -

    TYPE_SOA

    -
    <static> <final> Number TYPE_SOA
    -
      - The "SOA" record/query type. - -
    -
    - - -

    TYPE_TXT

    -
    <static> <final> Number TYPE_TXT
    -
      - The "TXT" record/query type. - -
    -
    - - -

    TYPE_WKS

    -
    <static> <final> Number TYPE_WKS
    -
      - The "WKS" record/query type. - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.DnsClient

    -
    jala.DnsClient(<String> nameServer)
    - - -
      - Constructs a new DnsClient object. -
    - - - -
      - Parameters: - -
        nameServer - IP-Address or FQDN of nameserver to query -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    query

    -
    org.wonderly.net.dns.RR query(<String> dName, <Number> queryType)
    - -
      Queries the nameserver for a specific domain - and the given type of record.
    - - - - -
      - Parameters: - -
        dName - The domain name to query for -
      - -
        queryType - The type of records to retrieve -
      - -
    - - - - -
      - Returns: -
        - The records retrieved from the nameserver -
      -
    - - - - - -
    - - -

    queryMailHost

    -
    org.wonderly.net.dns.RR queryMailHost(<String> dName)
    - -
      Convenience method to query for the MX-records - of the domain passed as argument.
    - - - - -
      - Parameters: - -
        dName - The domain name to query for -
      - -
    - - - - -
      - Returns: -
        - The records retrieved from the nameserver -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Button.html b/modules/jala/docs/jala.Form.Component.Button.html deleted file mode 100644 index b863fff4..00000000 --- a/modules/jala/docs/jala.Form.Component.Button.html +++ /dev/null @@ -1,411 +0,0 @@ - - - - - -jala.Form.Component.Button - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Button

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.Button
    -
    - -
    -
    - Direct Known Subclasses: -
    - jala.Form.Component.Submit -
    -
    - - -
    -
    - -
    class - jala.Form.Component.Button - -
    extends jala.Form.Component.Input - - -
    - -

    -
    Subclass of jala.Form.Component.Input which renders a button. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Button - - (<String> name) - -
    -             - Creates a new Button component instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - render(<Object> attr, <Object> value, <Object> reqData) - -
    -            - Renders a button to the response. -
    - -  Object - - - - - renderControls(attr, value) - -
    -            - Creates a new attribute object for this button. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength, checkRequirements, parseValue -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Button

    -
    jala.Form.Component.Button(<String> name)
    - - -
      - Creates a new Button component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Button component -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    render

    -
    void render(<Object> attr, <Object> value, <Object> reqData)
    - -
      Renders a button to the response.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for this element. -
      - -
        value - Value to be used for rendering this element. -
      - -
        reqData - Request data for the whole form. This argument is passed only if the form is re-rendered after an error occured. -
      - -
    - - - - - - - - -
    - - -

    renderControls

    -
    Object renderControls(attr, value)
    - -
      Creates a new attribute object for this button.
    - - - - - - - -
      - Returns: -
        - Object with all attributes set for this button. -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Checkbox.html b/modules/jala/docs/jala.Form.Component.Checkbox.html deleted file mode 100644 index 283c7603..00000000 --- a/modules/jala/docs/jala.Form.Component.Checkbox.html +++ /dev/null @@ -1,460 +0,0 @@ - - - - - -jala.Form.Component.Checkbox - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Checkbox

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.Checkbox
    -
    - - -
    -
    - -
    class - jala.Form.Component.Checkbox - -
    extends jala.Form.Component.Input - - -
    - -

    -
    Subclass of jala.Form.Component.Input which renders and validates a - checkbox. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Checkbox - - (<String> name) - -
    -             - Creates a new Checkbox component instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - checkRequirements(<Object> reqData) - -
    -            - Validates user input from checkbox. -
    - -  Number - - - - - parseValue(<Object> reqData) - -
    -            - Parses the string input from the form. -
    - -  void - - - - - renderControls(<Object> attr, <Object> value, reqData) - -
    -            - Renders an checkbox to the response. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, render, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Checkbox

    -
    jala.Form.Component.Checkbox(<String> name)
    - - -
      - Creates a new Checkbox component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Checkbox component instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    checkRequirements

    -
    String checkRequirements(<Object> reqData)
    - -
      Validates user input from checkbox.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - null if everything is ok or string containing error message -
      -
    - - - - - -
    - - -

    parseValue

    -
    Number parseValue(<Object> reqData)
    - -
      Parses the string input from the form. For a checked box, the value is 1, - for an unchecked box the value is 0.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - parsed value -
      -
    - - - - - -
    - - -

    renderControls

    -
    void renderControls(<Object> attr, <Object> value, reqData)
    - -
      Renders an checkbox to the response.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for this element. -
      - -
        value - Value to be used for rendering this element. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Date.html b/modules/jala/docs/jala.Form.Component.Date.html deleted file mode 100644 index 62a7abd3..00000000 --- a/modules/jala/docs/jala.Form.Component.Date.html +++ /dev/null @@ -1,463 +0,0 @@ - - - - - -jala.Form.Component.Date - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Date

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.Date
    -
    - - -
    -
    - -
    class - jala.Form.Component.Date - -
    extends jala.Form.Component.Input - - -
    - -

    -
    Subclass of jala.Form.Component.Input which renders and validates a - date editor. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Date - - (<String> name) - -
    -             - Constructs a new Date component instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - checkRequirements(<Object> reqData) - -
    -            - Validates user input from a date editor. -
    - -  Date - - - - - parseValue(<Object> reqData) - -
    -            - Parses the string input from the form and converts it to a date object. -
    - -  void - - - - - renderControls(<Object> attr, <Object> value, <Object> reqData) - -
    -            - Renders a textarea tag to the response. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, render, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Date

    -
    jala.Form.Component.Date(<String> name)
    - - -
      - Constructs a new Date component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Date component -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    checkRequirements

    -
    String checkRequirements(<Object> reqData)
    - -
      Validates user input from a date editor.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - null if everything is ok or string containing error message -
      -
    - - - - - -
    - - -

    parseValue

    -
    Date parseValue(<Object> reqData)
    - -
      Parses the string input from the form and converts it to a date object. - Throws an error if the string cannot be parsed.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - parsed date value -
      -
    - - - - - -
    - - -

    renderControls

    -
    void renderControls(<Object> attr, <Object> value, <Object> reqData)
    - -
      Renders a textarea tag to the response.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for this element. -
      - -
        value - Value to be used for rendering this element. -
      - -
        reqData - Request data for the whole form. This argument is passed only if the form is re-rendered after an error occured. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Fieldset.html b/modules/jala/docs/jala.Form.Component.Fieldset.html deleted file mode 100644 index 9f581f95..00000000 --- a/modules/jala/docs/jala.Form.Component.Fieldset.html +++ /dev/null @@ -1,419 +0,0 @@ - - - - - -jala.Form.Component.Fieldset - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Fieldset

    -
    Object
    -   |
    -   +--jala.Form.Component.Fieldset
    -
    - - -
    -
    - -
    class - jala.Form.Component.Fieldset - - -
    - -

    -
    Instances of this class represent a form fieldset containing - numerous form components -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Fieldset - - (<String> name) - -
    -             - Constructs a new Fieldset instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - render() - -
    -            - Renders all components within the fieldset. -
    - -  void - - - - - save(<jala.Form.Tracker> tracker, <Object> destObj) - -
    -            - Saves all components within the fieldset. -
    - -  void - - - - - validate(<jala.Form.Tracker> tracker) - -
    -            - Validates all components within the fieldset. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Fieldset

    -
    jala.Form.Component.Fieldset(<String> name)
    - - -
      - Constructs a new Fieldset instance -
    - - - -
      - Parameters: - -
        name - The name of the fieldset -
      - - -
    - - - - -
      - Returns: -
        - A newly created Fieldset instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    render

    -
    void render()
    - -
      Renders all components within the fieldset.
    - - - - - - - - - - - -
    - - -

    save

    -
    void save(<jala.Form.Tracker> tracker, <Object> destObj)
    - -
      Saves all components within the fieldset.
    - - - - -
      - Parameters: - -
        tracker - -
      - -
        destObj - -
      - -
    - - - - - - - - -
    - - -

    validate

    -
    void validate(<jala.Form.Tracker> tracker)
    - -
      Validates all components within the fieldset.
    - - - - -
      - Parameters: - -
        tracker - -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.File.html b/modules/jala/docs/jala.Form.Component.File.html deleted file mode 100644 index e218bfa9..00000000 --- a/modules/jala/docs/jala.Form.Component.File.html +++ /dev/null @@ -1,425 +0,0 @@ - - - - - -jala.Form.Component.File - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.File

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.File
    -
    - -
    -
    - Direct Known Subclasses: -
    - jala.Form.Component.Image -
    -
    - - -
    -
    - -
    class - jala.Form.Component.File - -
    extends jala.Form.Component.Input - - -
    - -

    -
    Subclass of jala.Form.Component.Input which renders and validates a - file upload. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.File - - (<String> name) - -
    -             - Creates a new File component instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - checkRequirements(<Object> reqData) - -
    -            - Validates a file upload by making sure it's there (if REQUIRE is set), - checking the file size, the content type and by trying to construct an image. -
    - -  void - - - - - renderControls(<Object> attr, <Object> value, <Object> reqData) - -
    -            - Renders a file input tag to the response. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, render, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength, parseValue -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.File

    -
    jala.Form.Component.File(<String> name)
    - - -
      - Creates a new File component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created File component -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    checkRequirements

    -
    String checkRequirements(<Object> reqData)
    - -
      Validates a file upload by making sure it's there (if REQUIRE is set), - checking the file size, the content type and by trying to construct an image.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
        tracker - jala.Form.Tracker object storing possible error messages -
      - -
    - - - - -
      - Returns: -
        - null if everything is ok or string containing error message -
      -
    - - - - - -
    - - -

    renderControls

    -
    void renderControls(<Object> attr, <Object> value, <Object> reqData)
    - -
      Renders a file input tag to the response.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for this element. -
      - -
        value - Value to be used for rendering this element. -
      - -
        reqData - Request data for the whole form. This argument is passed only if the form is re-rendered after an error occured. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Hidden.html b/modules/jala/docs/jala.Form.Component.Hidden.html deleted file mode 100644 index 0b2e631f..00000000 --- a/modules/jala/docs/jala.Form.Component.Hidden.html +++ /dev/null @@ -1,398 +0,0 @@ - - - - - -jala.Form.Component.Hidden - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Hidden

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.Hidden
    -
    - - -
    -
    - -
    class - jala.Form.Component.Hidden - -
    extends jala.Form.Component.Input - - -
    - -

    -
    Subclass of jala.Form.Component.Input which renders and validates a - hidden input tag. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Hidden - - (<String> name) - -
    -             - Constructs a newly created Hidden component instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - render() - -
    -            - Renders this component directly to response. -
    - -  void - - - - - renderControls(<Object> attr, <Object> value, <Object> reqData) - -
    -            - Renders a hidden input tag to the response. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength, checkRequirements, parseValue -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Hidden

    -
    jala.Form.Component.Hidden(<String> name)
    - - -
      - Constructs a newly created Hidden component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Hidden component instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    render

    -
    void render()
    - -
      Renders this component directly to response. For a hidden tag, this is - just an input element, no div tag or anything.
    - - - - - - - - - - - -
    - - -

    renderControls

    -
    void renderControls(<Object> attr, <Object> value, <Object> reqData)
    - -
      Renders a hidden input tag to the response.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for this element. -
      - -
        value - Value to be used for rendering this element. -
      - -
        reqData - Request data for the whole form. This argument is passed only if the form is re-rendered after an error occured. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Image.html b/modules/jala/docs/jala.Form.Component.Image.html deleted file mode 100644 index bf6833a0..00000000 --- a/modules/jala/docs/jala.Form.Component.Image.html +++ /dev/null @@ -1,376 +0,0 @@ - - - - - -jala.Form.Component.Image - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Image

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.File
    -               |
    -               +--jala.Form.Component.Image
    -
    - - -
    -
    - -
    class - jala.Form.Component.Image - -
    extends jala.Form.Component.File - - -
    - -

    -
    Subclass of jala.Form.Component.File which renders a file upload - and validates uploaded files as images. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Image - - () - -
    -             - Creates a new Image component instance -
    - - - -  - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - checkRequirements(<Object> reqData) - -
    -            - Validates an image upload by making sure it's there (if REQUIRE is set), - checking the file size, the content type and by trying to construct an image. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.File
    - -renderControls -
    -  - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, render, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength, parseValue -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Image

    -
    jala.Form.Component.Image()
    - - -
      - Creates a new Image component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Image component -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    checkRequirements

    -
    String checkRequirements(<Object> reqData)
    - -
      Validates an image upload by making sure it's there (if REQUIRE is set), - checking the file size, the content type and by trying to construct an image. - If the file is an image, width and height limitations set by require are - checked.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Input.html b/modules/jala/docs/jala.Form.Component.Input.html deleted file mode 100644 index a0d3131b..00000000 --- a/modules/jala/docs/jala.Form.Component.Input.html +++ /dev/null @@ -1,1258 +0,0 @@ - - - - - -jala.Form.Component.Input - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Input

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -
    - -
    -
    - Direct Known Subclasses: -
    - jala.Form.Component.Hidden, jala.Form.Component.Checkbox, jala.Form.Component.File, jala.Form.Component.Password, jala.Form.Component.Button, jala.Form.Component.Select, jala.Form.Component.Textarea, jala.Form.Component.Date -
    -
    - - -
    -
    - -
    class - jala.Form.Component.Input - - -
    - -

    -
    Instances of this class represent a single form input field. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Input - - (<String> name) - -
    -             - Creates a new input component instance. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - checkLength(<Object> reqData) - -
    -            - Checks user input for maximum length, minimum length and require - if the corresponding options have been set using the require method. -
    - -  String - - - - - checkRequirements(<Object> reqData) - -
    -            - Checks user input against options set using the require method. -
    - -  void - - - - - class_macro() - -
    -            - Renders this component's class name. -
    - -  void - - - - - controls_macro() - -
    -            - Renders the control(s) of this component -
    - -  void - - - - - error_macro() - -
    -            - Renders this component's error message (if set) directly to response -
    - -  Object - - - - - getControlAttributes() - -
    -            - Creates a new attribute object for this element. -
    - -  String|Number|Date - - - - - getValue() - -
    -            - Retrieves the property which is edited by this component. -
    - -  void - - - - - help_macro() - -
    -            - Renders this component's help text, if set. -
    - -  void - - - - - id_macro() - -
    -            - Renders this component's id -
    - -  void - - - - - label_macro() - -
    -            - Renders this component's label. -
    - -  void - - - - - name_macro() - -
    -            - Renders this component's name -
    - -  Object - - - - - parseValue(<Object> reqData) - -
    -            - Parses the string input from the form and creates the datatype that - is edited with this component. -
    - -  void - - - - - render() - -
    -            - Renders this component including label, error and help messages directly - to response. -
    - -  void - - - - - render_macro() - -
    -            - Renders this component including label, error and help messages - directly to response -
    - -  void - - - - - renderControls(<Object> attr, <Object> value, <Object> reqData) - -
    -            - Renders the html form elements to the response. -
    - -  String - - - - - renderError() - -
    -            - If the error tracker holds an error message for this component, - it is wrapped in a div-tag and returned as a string. -
    - -  String - - - - - renderHelp() - -
    -            - If this component contains a help message, it is wrapped in - a div-tag and returned as a string. -
    - -  String - - - - - renderLabel() - -
    -            - Returns the rendered label of this component -
    - -  void - - - - - save(<jala.Form.Tracker> tracker, <Object> destObj) - -
    -            - Saves the parsed value using setValue. -
    - -  Object - - - - - setValue(<Object> destObj, <Object> value) - -
    -            - Sets a property of the object passed as argument to the given value. -
    - -  void - - - - - type_macro() - -
    -            - Renders this component's type -
    - -  void - - - - - validate(<jala.Form.Tracker> tracker) - -
    -            - Validates the input provided to this component. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Input

    -
    jala.Form.Component.Input(<String> name)
    - - -
      - Creates a new input component instance. -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html control. -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    checkLength

    -
    String checkLength(<Object> reqData)
    - -
      Checks user input for maximum length, minimum length and require - if the corresponding options have been set using the require method.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - String containing error message or null if everything is ok. -
      -
    - - - - - - - -
    - - -

    checkRequirements

    -
    String checkRequirements(<Object> reqData)
    - -
      Checks user input against options set using the require method.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - String containing error message or null if everything is ok. -
      -
    - - - - - - - -
    - - -

    class_macro

    -
    void class_macro()
    - -
      Renders this component's class name. - Note that this is just the class name that has been explicitly - assigned using setClassName.
    - - - - - - - - - - - - - -
    - - -

    controls_macro

    -
    void controls_macro()
    - -
      Renders the control(s) of this component
    - - - - - - - - - - - -
    - - -

    error_macro

    -
    void error_macro()
    - -
      Renders this component's error message (if set) directly to response
    - - - - - - - - - - - -
    - - -

    getControlAttributes

    -
    Object getControlAttributes()
    - -
      Creates a new attribute object for this element.
    - - - - - - - -
      - Returns: -
        - Object with properties id, name, class -
      -
    - - - - - -
    - - -

    getValue

    -
    String|Number|Date getValue()
    - -
      Retrieves the property which is edited by this component. -
        -
      • If no getter is given, the method returns the primitive property - of the data object with the same name as the component.
      • -
      • If a getter function is defined, it is executed with the scope - of the data object and the return value is used as default value. - The name of the component is passed to the getter function - as an argument.
      • -
    - - - - - - - -
      - Returns: -
        - The value of the property -
      -
    - - - - - -
    - - -

    help_macro

    -
    void help_macro()
    - -
      Renders this component's help text, if set.
    - - - - - - - - - - - -
    - - -

    id_macro

    -
    void id_macro()
    - -
      Renders this component's id
    - - - - - - - - - - - - - -
    - - -

    label_macro

    -
    void label_macro()
    - -
      Renders this component's label.
    - - - - - - - - - - - -
    - - -

    name_macro

    -
    void name_macro()
    - -
      Renders this component's name
    - - - - - - - - - - - -
    - - -

    parseValue

    -
    Object parseValue(<Object> reqData)
    - -
      Parses the string input from the form and creates the datatype that - is edited with this component. For the input component this method - is not of much use, but subclasses that edit other datatypes may use - it. For example, a date editor should convert the user input from string - to a date object.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - parsed value -
      -
    - - - - - -
    - - -

    render

    -
    void render()
    - -
      Renders this component including label, error and help messages directly - to response.
    - - - - - - - - - - - -
    - - -

    render_macro

    -
    void render_macro()
    - -
      Renders this component including label, error and help messages - directly to response
    - - - - - - - - - - - -
    - - -

    renderControls

    -
    void renderControls(<Object> attr, <Object> value, <Object> reqData)
    - -
      Renders the html form elements to the response. - This method shall be overridden by subclasses of input component.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for the html form elements. -
      - -
        value - Value to be used for rendering this element. -
      - -
        reqData - Request data for the whole form. This argument is passed only if the form is re-rendered after an error occured. -
      - -
    - - - - - - - - -
    - - -

    renderError

    -
    String renderError()
    - -
      If the error tracker holds an error message for this component, - it is wrapped in a div-tag and returned as a string.
    - - - - - - - -
      - Returns: -
        - Rendered string -
      -
    - - - - - -
    - - -

    renderHelp

    -
    String renderHelp()
    - -
      If this component contains a help message, it is wrapped in - a div-tag and returned as a string.
    - - - - - - - -
      - Returns: -
        - The rendered help message -
      -
    - - - - - -
    - - -

    renderLabel

    -
    String renderLabel()
    - -
      Returns the rendered label of this component
    - - - - - - - -
      - Returns: -
        - The rendered label of this component -
      -
    - - - - - -
    - - -

    save

    -
    void save(<jala.Form.Tracker> tracker, <Object> destObj)
    - -
      Saves the parsed value using setValue.
    - - - - -
      - Parameters: - -
        tracker - Tracker object collecting request data, error messages and parsed values. -
      - -
        destObj - (optional) object whose values will be changed. -
      - -
    - - - - - - - - - - -
    - - -

    setValue

    -
    Object setValue(<Object> destObj, <Object> value)
    - -
      Sets a property of the object passed as argument to the given value. -
    • If no setter is set at the component, the primitive property - of the data object is changed.
    • -
    • If a setter function is defined it is executed with the data object - as scope and with the name and new value provided as arguments
    • -
    • If the setter is explicitly set to null, no changes are made at all.
    - - - - -
      - Parameters: - -
        destObj - (optional) object whose values will be changed. -
      - -
        value - The value to set the property to -
      - -
    - - - - -
      - Returns: -
        - True in case the update was successful, false otherwise. -
      -
    - - - - - - - -
    - - -

    type_macro

    -
    void type_macro()
    - -
      Renders this component's type
    - - - - - - - - - - - -
    - - -

    validate

    -
    void validate(<jala.Form.Tracker> tracker)
    - -
      Validates the input provided to this component. First, - checkRequirements is called. If no error occurs, the input - is parsed using parseValue and passed on to the validator - function.
    - - - - -
      - Parameters: - -
        tracker - Tracker object collecting request data, error messages and parsed values. -
      - -
    - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Password.html b/modules/jala/docs/jala.Form.Component.Password.html deleted file mode 100644 index f450869a..00000000 --- a/modules/jala/docs/jala.Form.Component.Password.html +++ /dev/null @@ -1,362 +0,0 @@ - - - - - -jala.Form.Component.Password - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Password

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.Password
    -
    - - -
    -
    - -
    class - jala.Form.Component.Password - -
    extends jala.Form.Component.Input - - -
    - -

    -
    Subclass of jala.Form.Component.Input which renders and validates a - password input tag. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Password - - (<String> name) - -
    -             - Constructs a newly created Password component instance -
    - - - -  - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - renderControls(<Object> attr, <Object> value, <Object> reqData) - -
    -            - Renders a password input tag to the response. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, render, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength, checkRequirements, parseValue -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Password

    -
    jala.Form.Component.Password(<String> name)
    - - -
      - Constructs a newly created Password component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Password component instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    renderControls

    -
    void renderControls(<Object> attr, <Object> value, <Object> reqData)
    - -
      Renders a password input tag to the response.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for this element. -
      - -
        value - Value to be used for rendering this element. -
      - -
        reqData - Request data for the whole form. This argument is passed only if the form is re-rendered after an error occured. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Radio.html b/modules/jala/docs/jala.Form.Component.Radio.html deleted file mode 100644 index 117dcd14..00000000 --- a/modules/jala/docs/jala.Form.Component.Radio.html +++ /dev/null @@ -1,431 +0,0 @@ - - - - - -jala.Form.Component.Radio - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Radio

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.Select
    -               |
    -               +--jala.Form.Component.Radio
    -
    - - -
    -
    - -
    class - jala.Form.Component.Radio - -
    extends jala.Form.Component.Select - - -
    - -

    -
    Subclass of jala.Form.Component.Input which renders and validates a - set of radio buttons. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Radio - - (<String> name) - -
    -             - Creates a new Radio component instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - checkRequirements(<Object> reqData) - -
    -            - Validates user input from a set of radio buttons and makes sure that - option value list contains the user input. -
    - -  void - - - - - renderControls(<Object> attr, <Object> value) - -
    -            - Renders a set of radio buttons to the response. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Select
    - -parseOptions, checkOptions -
    -  - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, render, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength, parseValue -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Radio

    -
    jala.Form.Component.Radio(<String> name)
    - - -
      - Creates a new Radio component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Radio component -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    checkRequirements

    -
    String checkRequirements(<Object> reqData)
    - -
      Validates user input from a set of radio buttons and makes sure that - option value list contains the user input.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - null if everything is ok or string containing error message -
      -
    - - - - - - - -
    - - -

    renderControls

    -
    void renderControls(<Object> attr, <Object> value)
    - -
      Renders a set of radio buttons to the response.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for this element. -
      - -
        value - Value to be used for rendering this element. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Select.html b/modules/jala/docs/jala.Form.Component.Select.html deleted file mode 100644 index 9a4bdeea..00000000 --- a/modules/jala/docs/jala.Form.Component.Select.html +++ /dev/null @@ -1,524 +0,0 @@ - - - - - -jala.Form.Component.Select - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Select

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.Select
    -
    - -
    -
    - Direct Known Subclasses: -
    - jala.Form.Component.Radio -
    -
    - - -
    -
    - -
    class - jala.Form.Component.Select - -
    extends jala.Form.Component.Input - - -
    - -

    -
    Subclass of jala.Form.Component.Input which renders and validates a - dropdown element. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Select - - (<String> name) - -
    -             - Constructs a new Select component instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - checkOptions(<Object> reqData) - -
    -            - Checks user input for optiongroups: Unless require("checkoptions") - has ben set to false, the user input must exist in the option array. -
    - -  String - - - - - checkRequirements(<Object> reqData) - -
    -            - Validates user input from a dropdown element by making sure that - the option value list contains the user input. -
    - -  Array - - - - - parseOptions() - -
    -            - Creates an array of options for a dropdown element or a - group of radiobuttons. -
    - -  void - - - - - renderControls(<Object> attr, <Object> value, <Object> reqData) - -
    -            - Renders a dropdown element to the response. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, render, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength, parseValue -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Select

    -
    jala.Form.Component.Select(<String> name)
    - - -
      - Constructs a new Select component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Select component -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    checkOptions

    -
    String checkOptions(<Object> reqData)
    - -
      Checks user input for optiongroups: Unless require("checkoptions") - has ben set to false, the user input must exist in the option array.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - null if everything is ok or string containing error message -
      -
    - - - - - -
    - - -

    checkRequirements

    -
    String checkRequirements(<Object> reqData)
    - -
      Validates user input from a dropdown element by making sure that - the option value list contains the user input.
    - - - - -
      - Parameters: - -
        reqData - request data -
      - -
    - - - - -
      - Returns: -
        - string containing error message or null if everything is ok. -
      -
    - - - - - - - -
    - - -

    parseOptions

    -
    Array parseOptions()
    - -
      Creates an array of options for a dropdown element or a - group of radiobuttons. If options field of this element's - config is an array, that array is returned. - If options is a function, its return value is returned.
    - - - - - - - -
      - Returns: -
        - array of options -
      -
    - - - - - -
    - - -

    renderControls

    -
    void renderControls(<Object> attr, <Object> value, <Object> reqData)
    - -
      Renders a dropdown element to the response.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for this element. -
      - -
        value - Value to be used for rendering this element. -
      - -
        reqData - Request data for the whole form. This argument is passed only if the form is re-rendered after an error occured. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Skin.html b/modules/jala/docs/jala.Form.Component.Skin.html deleted file mode 100644 index 51fc872b..00000000 --- a/modules/jala/docs/jala.Form.Component.Skin.html +++ /dev/null @@ -1,344 +0,0 @@ - - - - - -jala.Form.Component.Skin - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Skin

    -
    Object
    -   |
    -   +--jala.Form.Component
    -         |
    -         +--jala.Form.Component.Skin
    -
    - - -
    -
    - -
    class - jala.Form.Component.Skin - -
    extends jala.Form.Component - - -
    - -

    -
    Subclass of jala.Form.Component that allows rendering a skin - within a form. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Skin - - (<String> name) - -
    -             - -
    - - - -  - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - render() - -
    -            - Renders the skin named by this component to the response. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component
    - -createDomId, validate, save -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Skin

    -
    jala.Form.Component.Skin(<String> name)
    - - - - -
      - Parameters: - -
        name - The name of the component, used as the name of the skin -
      - - -
    - - - - -
      - Returns: -
        - A newly created Skin component instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    render

    -
    void render()
    - -
      Renders the skin named by this component to the response.
    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Submit.html b/modules/jala/docs/jala.Form.Component.Submit.html deleted file mode 100644 index 07452f56..00000000 --- a/modules/jala/docs/jala.Form.Component.Submit.html +++ /dev/null @@ -1,370 +0,0 @@ - - - - - -jala.Form.Component.Submit - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Submit

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.Button
    -               |
    -               +--jala.Form.Component.Submit
    -
    - - -
    -
    - -
    class - jala.Form.Component.Submit - -
    extends jala.Form.Component.Button - - -
    - -

    -
    Subclass of jala.Form.Component.Button which renders a submit button. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Submit - - (<String> name) - -
    -             - Creates a new Submit component instance -
    - - - -  - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Object - - - - - renderControls(attr, value) - -
    -            - Creates a new attribute object for this button. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Button
    - -render -
    -  - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength, checkRequirements, parseValue -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Submit

    -
    jala.Form.Component.Submit(<String> name)
    - - -
      - Creates a new Submit component instance -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Submit component -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    renderControls

    -
    Object renderControls(attr, value)
    - -
      Creates a new attribute object for this button.
    - - - - - - - -
      - Returns: -
        - Object with all attributes set for this button. -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.Textarea.html b/modules/jala/docs/jala.Form.Component.Textarea.html deleted file mode 100644 index fd0de8c4..00000000 --- a/modules/jala/docs/jala.Form.Component.Textarea.html +++ /dev/null @@ -1,362 +0,0 @@ - - - - - -jala.Form.Component.Textarea - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component.Textarea

    -
    Object
    -   |
    -   +--jala.Form.Component.Input
    -         |
    -         +--jala.Form.Component.Textarea
    -
    - - -
    -
    - -
    class - jala.Form.Component.Textarea - -
    extends jala.Form.Component.Input - - -
    - -

    -
    Subclass of jala.Form.Component.Input which renders and validates a - textarea input field. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component.Textarea - - (<String> name) - -
    -             - Constructs a new Textarea component. -
    - - - -  - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - renderControls(<Object> attr, <Object> value, <Object> reqData) - -
    -            - Renders a textarea input field to the response. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Form.Component.Input
    - -validate, save, getValue, setValue, render, renderError, renderLabel, renderHelp, render_macro, controls_macro, error_macro, label_macro, help_macro, id_macro, name_macro, type_macro, class_macro, getControlAttributes, checkLength, checkRequirements, parseValue -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component.Textarea

    -
    jala.Form.Component.Textarea(<String> name)
    - - -
      - Constructs a new Textarea component. -
    - - - -
      - Parameters: - -
        name - Name of the component, used as name of the html controls. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Textarea component instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    renderControls

    -
    void renderControls(<Object> attr, <Object> value, <Object> reqData)
    - -
      Renders a textarea input field to the response.
    - - - - -
      - Parameters: - -
        attr - Basic attributes for this element. -
      - -
        value - Value to be used for rendering this element. -
      - -
        reqData - Request data for the whole form. This argument is passed only if the form is re-rendered after an error occured. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Component.html b/modules/jala/docs/jala.Form.Component.html deleted file mode 100644 index 205e8872..00000000 --- a/modules/jala/docs/jala.Form.Component.html +++ /dev/null @@ -1,550 +0,0 @@ - - - - - -jala.Form.Component - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Component

    -
    Object
    -   |
    -   +--jala.Form.Component
    -
    - -
    -
    - Direct Known Subclasses: -
    - jala.Form.Component.Skin -
    -
    - - -
    -
    - -
    class - jala.Form.Component - - -
    - -

    - Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.Form.Component.Fieldset
    - <static class>jala.Form.Component.Skin
    - <static class>jala.Form.Component.Input
    - <static class>jala.Form.Component.Password
    - <static class>jala.Form.Component.Hidden
    - <static class>jala.Form.Component.Textarea
    - <static class>jala.Form.Component.Date
    - <static class>jala.Form.Component.Select
    - <static class>jala.Form.Component.Radio
    - <static class>jala.Form.Component.Checkbox
    - <static class>jala.Form.Component.File
    - <static class>jala.Form.Component.Image
    - <static class>jala.Form.Component.Button
    - <static class>jala.Form.Component.Submit
    -  - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Component - - (name) - -
    -             - The abstract base class for all components. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - createDomId(<String> idPart) - -
    -            - Creates a DOM identifier based on the name of the form, - the name of the component and an additional string. -
    - -  void - - - - - render() - -
    -            - Function to render a component. -
    - -  void - - - - - save(destObj, val) - -
    -            - Function to save the data of a component. -
    - -  Object - - - - - validate(<jala.Form.Tracker> tracker) - -
    -            - Function to validate a component. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Component

    -
    jala.Form.Component(name)
    - - -
      - The abstract base class for all components. -
    - - - - - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    createDomId

    -
    String createDomId(<String> idPart)
    - -
      Creates a DOM identifier based on the name of the form, - the name of the component and an additional string. - The items will be chained using camel casing.
    - - - - -
      - Parameters: - -
        idPart - Optional string appended to component's id. -
      - -
    - - - - -
      - Returns: -
        - The DOM Id -
      -
    - - - - - -
    - - -

    render

    -
    void render()
    - -
      Function to render a component. - Subclasses of jala.Form.Component may override this function.
    - - - - - - - - - - - -
    - - -

    save

    -
    void save(destObj, val)
    - -
      Function to save the data of a component. - Subclasses of jala.Form.Component may override this function.
    - - - - - - - - - - - -
    - - -

    validate

    -
    Object validate(<jala.Form.Tracker> tracker)
    - -
      Function to validate a component. - Subclasses of jala.Form.Component may override this function.
    - - - - -
      - Parameters: - -
        tracker - object tracking errors and holding parsed values and request data. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.Tracker.html b/modules/jala/docs/jala.Form.Tracker.html deleted file mode 100644 index 90cfe375..00000000 --- a/modules/jala/docs/jala.Form.Tracker.html +++ /dev/null @@ -1,441 +0,0 @@ - - - - - -jala.Form.Tracker - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form.Tracker

    -
    Object
    -   |
    -   +--jala.Form.Tracker
    -
    - - -
    -
    - -
    class - jala.Form.Tracker - - -
    - -

    -
    Instances of this class can contain error-messages and values -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  Objecterrors -
    -           A map containing error messages
    -  ObjectreqData -
    -           A map containing input from request data
    -  Objectvalues -
    -           A map containing parsed values (only for those fields that didn't - fail during checkRequirements method).
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form.Tracker - - (reqData) - -
    -             - A generic container for error-messages and values -
    - - - -  - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Number - - - - - countErrors() - -
    -            - Returns the number of components for which this instance has - tracked an error. -
    - -  Boolean - - - - - hasError() - -
    -            - Returns true if an error has been set for at least one component. -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    errors

    -
    Object errors
    -
      - A map containing error messages - -
    -
    - - -

    reqData

    -
    Object reqData
    -
      - A map containing input from request data - -
    -
    - - -

    values

    -
    Object values
    -
      - A map containing parsed values (only for those fields that didn't - fail during checkRequirements method). - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form.Tracker

    -
    jala.Form.Tracker(reqData)
    - - -
      - A generic container for error-messages and values -
    - - - - - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    countErrors

    -
    Number countErrors()
    - -
      Returns the number of components for which this instance has - tracked an error.
    - - - - - - - -
      - Returns: -
        - Number of components that did not validate. -
      -
    - - - - - -
    - - -

    hasError

    -
    Boolean hasError()
    - -
      Returns true if an error has been set for at least one component.
    - - - - - - - -
      - Returns: -
        - true if form encountered an error. -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Form.html b/modules/jala/docs/jala.Form.html deleted file mode 100644 index 2fffb0f8..00000000 --- a/modules/jala/docs/jala.Form.html +++ /dev/null @@ -1,2034 +0,0 @@ - - - - - -jala.Form - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Form

    -
    Object
    -   |
    -   +--jala.Form
    -
    - - -
    -
    - -
    class - jala.Form - - -
    - -

    -
    A class that renders forms, validates submitted form data and - stores the data in a specified object. -
    Defined in Form.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.Form.Component
    - <static class>jala.Form.Tracker
    -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  SkincomponentSkin -
    -           Contains the default component skin
    -  Stringname -
    -           Readonly reference to the name of the form
    - <static>  <final> StringCHECKOPTIONS -
    -           Constant used by require function to define that a select or - radio component should validate only if the user input is contained - in the list of options provided.
    - <static>  <final> StringCONTENTTYPE -
    -           Constant used by require function to define that a file upload - component should validate only if the file's content type is - in the list of allowed content types provided.
    - <static>  helma.Htmlhtml -
    -           The HTML renderer used by jala.Form
    - <static>  <final> StringMAXHEIGHT -
    -           Constant used by require function to define that an image upload - component should validate only if the image's height is less than - the value provided.
    - <static>  <final> StringMAXLENGTH -
    -           Constant used by require function to define that a component - should not validate if userinput exceeds a maximum length.
    - <static>  <final> StringMAXWIDTH -
    -           Constant used by require function to define that an image upload - component should validate only if the image's width is less than - the value provided.
    - <static>  <final> StringMINHEIGHT -
    -           Constant used by require function to define that an image upload - component should validate only if the image's height is more than - the value provided.
    - <static>  <final> StringMINLENGTH -
    -           Constant used by require function to define that a component - should not validate if userinput is shorter than a given length.
    - <static>  <final> StringMINWIDTH -
    -           Constant used by require function to define that an image upload - component should validate only if the image's width is more than - the value provided.
    - <static>  <final> StringREQUIRE -
    -           Constant used by require function to define that a component - should validate only if the user did provide input.
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Form - - (<String> name, <Object> dataObj) - -
    -             - Constructs a new Form instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - addComponent(<jala.Form.Component.Input> component) - -
    -            - Adds a component to this jala.Form instance -
    - -  String - - - - - class_macro() - -
    -            - Returns the class name of the form -
    - -  void - - - - - close_macro() - -
    -            - Writes the form closing tag to response -
    - -  Boolean - - - - - containsFileUpload() - -
    -            - Returns true if this instance of jala.Form contains at least - one component doing a file upload. -
    - -  Number - - - - - countErrors() - -
    -            - If this instance of jala.Form holds a jala.Form.Tracker - instance it returns the number of components that didn't - validate. -
    - -  String - - - - - createDomId() - -
    -            - Creates a DOM identifier based on the arguments passed. -
    - -  String - - - - - getClassName() - -
    -            - Returns the class name set for this form instance. -
    - -  Object - - - - - getDataObject() - -
    -            - Returns the data object containing the values used - for rendering the form. -
    - -  String - - - - - getErrorMessage() - -
    -            - Returns the general error message printed above the form - if any of the components didn't validate. -
    - -  jala.Form.Tracker - - - - - getTracker() - -
    -            - Returns the tracker object this form instance uses for collecting - error messages and parsed values. -
    - -  Boolean - - - - - handle(<Object> reqData, <Object> destObj) - -
    -            - Parses form input, applies check functions and stores the values - if the form does validate. -
    - -  Boolean - - - - - hasError() - -
    -            - Returns true if this instance of jala.Form holds a jala.Form.Tracker - instance and at least one error has been set on this tracker. -
    - -  String - - - - - id_macro() - -
    -            - Returns the id (equal to the name) of the form -
    - -  Array - - - - - listComponents() - -
    -            - Returns an array containing the components - of this jala.Form instance. -
    - -  String - - - - - name_macro() - -
    -            - Returns the name (equal to the id) of the form -
    - -  void - - - - - open_macro() - -
    -            - Writes the form opening tag to response -
    - -  void - - - - - render() - -
    -            - Renders this form including all components to response. -
    - -  void - - - - - render_macro() - -
    -            - Renders the whole form to response -
    - -  String - - - - - renderAsString(param) - -
    -            - renders the form as a string -
    - -  void - - - - - save(<jala.Form.Tracker> tracker, <Object> destObj) - -
    -            - Sets the parsed values on an object. -
    - -  void - - - - - setClassName(<String> newClassName) - -
    -            - Sets an extra classname for this form instance -
    - -  void - - - - - setDataObject(newDataObj) - -
    -            - Sets the data object which is being edited by this form. -
    - -  void - - - - - setErrorMessage(<String> newErrorMessage) - -
    -            - Sets the general error message printed above the form if any - of the components didn't validate. -
    - -  void - - - - - setTracker(<jala.Form.Tracker> newTracker) - -
    -            - Sets the tracker object this form instance uses for collecting - error messages and parsed values. -
    - -  jala.Form.Tracker - - - - - validate(<Object> reqData) - -
    -            - Validates user input from a submitted form by calling each - component's validate method. -
    - - <static> jala.Form - - - - - create(<Object> config, dataObj) - -
    -            - Parses a plain javascript object tree and configures a - new jala.Form instance according to the properties. -
    - - <static> void - - - - - extend(<Function> subClass, <Function> superClass) - -
    -            - Utility to set up the prototype, constructor, superclass and superconstructor - properties to support an inheritance strategy that can chain constructors and methods. -
    - - <static> String - - - - - isEmail(<String> name, <String> value, <Object> reqData, <jala.Form> formObj) - -
    -            - Static validator function to test values for being a valid email address. -
    - - <static> String - - - - - isUrl(<String> name, <String> value, <Object> reqData, <jala.Form> formObj) - -
    -            - Static validator function to test values for being a valid url. -
    - - <static> Object - - - - - propertyGetter(<String> name, value) - -
    -            - static default getter function used to return a field - from the data object. -
    - - <static> void - - - - - propertySetter(<String> name, <Object> value) - -
    -            - static default setter function used to change a field - of the data object. -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    componentSkin

    -
    Skin componentSkin
    -
      - Contains the default component skin - -
    -
    - - -

    name

    -
    String name
    -
      - Readonly reference to the name of the form - -
    -
    - - -

    CHECKOPTIONS

    -
    <static> <final> String CHECKOPTIONS
    -
      - Constant used by require function to define that a select or - radio component should validate only if the user input is contained - in the list of options provided. - Value: "checkoptions" - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - -

    CONTENTTYPE

    -
    <static> <final> String CONTENTTYPE
    -
      - Constant used by require function to define that a file upload - component should validate only if the file's content type is - in the list of allowed content types provided. - Value: "contenttype" - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - -

    html

    -
    <static> helma.Html html
    -
      - The HTML renderer used by jala.Form - -
    -
    - - -

    MAXHEIGHT

    -
    <static> <final> String MAXHEIGHT
    -
      - Constant used by require function to define that an image upload - component should validate only if the image's height is less than - the value provided. - Value: "maxheight" - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - -

    MAXLENGTH

    -
    <static> <final> String MAXLENGTH
    -
      - Constant used by require function to define that a component - should not validate if userinput exceeds a maximum length. - Value: "maxlength" - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - -

    MAXWIDTH

    -
    <static> <final> String MAXWIDTH
    -
      - Constant used by require function to define that an image upload - component should validate only if the image's width is less than - the value provided. - Value: "maxwidth" - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - -

    MINHEIGHT

    -
    <static> <final> String MINHEIGHT
    -
      - Constant used by require function to define that an image upload - component should validate only if the image's height is more than - the value provided. - Value: "min-height" - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - -

    MINLENGTH

    -
    <static> <final> String MINLENGTH
    -
      - Constant used by require function to define that a component - should not validate if userinput is shorter than a given length. - Value: "minlength" - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - -

    MINWIDTH

    -
    <static> <final> String MINWIDTH
    -
      - Constant used by require function to define that an image upload - component should validate only if the image's width is more than - the value provided. - Value: "minwidth" - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - -

    REQUIRE

    -
    <static> <final> String REQUIRE
    -
      - Constant used by require function to define that a component - should validate only if the user did provide input. - Value: "require" - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Form

    -
    jala.Form(<String> name, <Object> dataObj)
    - - -
      - Constructs a new Form instance -
    - - - -
      - Parameters: - -
        name - The name of the form -
      - -
        dataObj - An optional object used to retrieve values to display in the form input fields contained in this Form instance. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Form instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    addComponent

    -
    void addComponent(<jala.Form.Component.Input> component)
    - -
      Adds a component to this jala.Form instance
    - - - - -
      - Parameters: - -
        component - -
      - -
    - - - - - - - - -
    - - -

    class_macro

    -
    String class_macro()
    - -
      Returns the class name of the form
    - - - - - - - -
      - Returns: -
        - The class name of this Form instance -
      -
    - - - - - -
    - - -

    close_macro

    -
    void close_macro()
    - -
      Writes the form closing tag to response
    - - - - - - - - - - - -
    - - -

    containsFileUpload

    -
    Boolean containsFileUpload()
    - -
      Returns true if this instance of jala.Form contains at least - one component doing a file upload.
    - - - - - - - - - - -
      - See:
        - jala.Form.Component#containsFileUpload
      -
    - - -
    - - -

    countErrors

    -
    Number countErrors()
    - -
      If this instance of jala.Form holds a jala.Form.Tracker - instance it returns the number of components that didn't - validate.
    - - - - - - - -
      - Returns: -
        - Number of components that didn't validate. -
      -
    - - - - - -
    - - -

    createDomId

    -
    String createDomId()
    - -
      Creates a DOM identifier based on the arguments passed. The - resulting Id will be prefixed with the name of the form. - All arguments will be chained using camel casing.
    - - - - - - - -
      - Returns: -
        - The DOM Id -
      -
    - - - - - -
    - - -

    getClassName

    -
    String getClassName()
    - -
      Returns the class name set for this form instance.
    - - - - - - - -
      - Returns: -
        - class name -
      -
    - - - - - -
    - - -

    getDataObject

    -
    Object getDataObject()
    - -
      Returns the data object containing the values used - for rendering the form.
    - - - - - - - -
      - Returns: -
        - The data object of this jala.Form instance -
      -
    - - - - - -
    - - -

    getErrorMessage

    -
    String getErrorMessage()
    - -
      Returns the general error message printed above the form - if any of the components didn't validate.
    - - - - - - - -
      - Returns: -
        - error message -
      -
    - - - - - -
    - - -

    getTracker

    -
    jala.Form.Tracker getTracker()
    - -
      Returns the tracker object this form instance uses for collecting - error messages and parsed values.
    - - - - - - - -
      - Returns: -
        - tracker object -
      -
    - - - - - -
    - - -

    handle

    -
    Boolean handle(<Object> reqData, <Object> destObj)
    - -
      Parses form input, applies check functions and stores the values - if the form does validate. Otherwise this method returns false - without saving so that the form can be reprinted with error messages.
    - - - - -
      - Parameters: - -
        reqData - input from form -
      - -
        destObj - object whose values should be chanegd -
      - -
    - - - - -
      - Returns: -
        - False if one of the checks failed, true if the element was saved correctly. -
      -
    - - - - - -
    - - -

    hasError

    -
    Boolean hasError()
    - -
      Returns true if this instance of jala.Form holds a jala.Form.Tracker - instance and at least one error has been set on this tracker.
    - - - - - - - -
      - Returns: -
        - true if an error has been encountered. -
      -
    - - - - - -
    - - -

    id_macro

    -
    String id_macro()
    - -
      Returns the id (equal to the name) of the form
    - - - - - - - -
      - Returns: -
        - The id of this Form instance -
      -
    - - - - - -
    - - -

    listComponents

    -
    Array listComponents()
    - -
      Returns an array containing the components - of this jala.Form instance.
    - - - - - - - -
      - Returns: -
        - The components of this jala.Form instance. -
      -
    - - - - - -
    - - -

    name_macro

    -
    String name_macro()
    - -
      Returns the name (equal to the id) of the form
    - - - - - - - -
      - Returns: -
        - The name of this Form instance -
      -
    - - - - - -
    - - -

    open_macro

    -
    void open_macro()
    - -
      Writes the form opening tag to response
    - - - - - - - - - - - -
    - - -

    render

    -
    void render()
    - -
      Renders this form including all components to response.
    - - - - - - - - - - - -
    - - -

    render_macro

    -
    void render_macro()
    - -
      Renders the whole form to response
    - - - - - - - - - - - -
    - - -

    renderAsString

    -
    String renderAsString(param)
    - -
      renders the form as a string
    - - - - - - - -
      - Returns: -
        - rendered form -
      -
    - - - - - -
    - - -

    save

    -
    void save(<jala.Form.Tracker> tracker, <Object> destObj)
    - -
      Sets the parsed values on an object. By default the internally - stored tracker and data objects are used, but those may be - overridden here.
    - - - - -
      - Parameters: - -
        tracker - (optional) tracker object holding parsed data from form input. -
      - -
        destObj - (optional) object whose values will be changed. By default the dataObj passed to the constructor or to setDataObject is used. -
      - -
    - - - - - - - - -
    - - -

    setClassName

    -
    void setClassName(<String> newClassName)
    - -
      Sets an extra classname for this form instance
    - - - - -
      - Parameters: - -
        newClassName - new classname -
      - -
    - - - - - - - - -
    - - -

    setDataObject

    -
    void setDataObject(newDataObj)
    - -
      Sets the data object which is being edited by this form. This object - is used to get the default values when first printing the form and - - if no other object is provided - receives the changed values in save.
    - - - - -
      - Parameters: - -
        dataObj - The object which is being edited by this form. -
      - -
    - - - - - - - - - - -
    - - -

    setErrorMessage

    -
    void setErrorMessage(<String> newErrorMessage)
    - -
      Sets the general error message printed above the form if any - of the components didn't validate.
    - - - - -
      - Parameters: - -
        newErrorMessage - error message -
      - -
    - - - - - - - - -
    - - -

    setTracker

    -
    void setTracker(<jala.Form.Tracker> newTracker)
    - -
      Sets the tracker object this form instance uses for collecting - error messages and parsed values.
    - - - - -
      - Parameters: - -
        newTracker - -
      - -
    - - - - - - - - -
    - - -

    validate

    -
    jala.Form.Tracker validate(<Object> reqData)
    - -
      Validates user input from a submitted form by calling each - component's validate method.
    - - - - -
      - Parameters: - -
        reqData - Optional submitted form data. If not specified req.data is used. -
      - -
    - - - - -
      - Returns: -
        - tracker object with error fields set. -
      -
    - - - - - -
    - - -

    create

    -
    <static> jala.Form create(<Object> config, dataObj)
    - -
      Parses a plain javascript object tree and configures a - new jala.Form instance according to the properties. - Propertynames are matched with constants and setter-functions, - the property "type" is used to create new component objects.
    - - - - -
      - Parameters: - -
        config - object tree containing config -
      - -
    - - - - -
      - Returns: -
        - A newly created jala.Form instance based on the config specified -
      -
    - - - - - -
    - - -

    extend

    -
    <static> void extend(<Function> subClass, <Function> superClass)
    - -
      Utility to set up the prototype, constructor, superclass and superconstructor - properties to support an inheritance strategy that can chain constructors and methods.
    - - - - -
      - Parameters: - -
        subClass - the object which inherits superClass' functions -
      - -
        superClass - the object to inherit -
      - -
    - - - - - - - - -
    - - -

    isEmail

    -
    <static> String isEmail(<String> name, <String> value, <Object> reqData, <jala.Form> formObj)
    - -
      Static validator function to test values for being a valid email address.
    - - - - -
      - Parameters: - -
        name - name of the property being validated. -
      - -
        value - value in form input -
      - -
        reqData - the whole request-data-object, in case properties depend on each other -
      - -
        formObj - instance of jala.Form -
      - -
    - - - - -
      - Returns: -
        - Error message or null -
      -
    - - - - - -
    - - -

    isUrl

    -
    <static> String isUrl(<String> name, <String> value, <Object> reqData, <jala.Form> formObj)
    - -
      Static validator function to test values for being a valid url.
    - - - - -
      - Parameters: - -
        name - name of the property being validated. -
      - -
        value - value in form input -
      - -
        reqData - the whole request-data-object, in case properties depend on each other -
      - -
        formObj - instance of jala.Form -
      - -
    - - - - -
      - Returns: -
        - Error message or null -
      -
    - - - - - -
    - - -

    propertyGetter

    -
    <static> Object propertyGetter(<String> name, value)
    - -
      static default getter function used to return a field - from the data object.
    - - - - -
      - Parameters: - -
        name - Name of the property. -
      - -
    - - - - - - - - -
    - - -

    propertySetter

    -
    <static> void propertySetter(<String> name, <Object> value)
    - -
      static default setter function used to change a field - of the data object.
    - - - - -
      - Parameters: - -
        name - Name of the property. -
      - -
        value - New value of the property. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.History.html b/modules/jala/docs/jala.History.html deleted file mode 100644 index 75d19aec..00000000 --- a/modules/jala/docs/jala.History.html +++ /dev/null @@ -1,635 +0,0 @@ - - - - - -jala.History - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.History

    -
    Object
    -   |
    -   +--jala.History
    -
    - - -
    -
    - -
    class - jala.History - - -
    - -

    -
    This class is an implementation of a Browser-like history - stack suitable to use in any Helma application. The difference - to a Browser's history is that this implementation ignores - POST requests and checks if Urls in the stack are still valid to - prevent eg. redirections to a HopObject's url that has been deleted. - Plus it is capable to create new "intermediate" history-stacks - and this way maintain a "history of histories" which is needed for - eg. editing sessions in a popup window that should use their own - request history without interfering with the history of the - main window. -
    Defined in History.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.History - - () - -
    -             - Constructs a new History object. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - add() - -
    -            - Initializes a new history stack, adds - it to the array of stacks (which makes it - the default one to use for further requests) - and records the current request Url. -
    - -  void - - - - - clear() - -
    -            - Clears the currently active history stack -
    - -  String - - - - - dump() - -
    -            - Returns the contents of all history stacks - as string -
    - -  String - - - - - peek(<Number> offset) - -
    -            - Retrieves the request Url at the given position - in the current history stack. -
    - -  String - - - - - pop(<Number> offset) - -
    -            - Retrieves the first valid request Url in history - stack starting with a given offset. -
    - -  void - - - - - push() - -
    -            - Records a request Url in the currently active - history stack. -
    - -  void - - - - - redirect(<Number> offset) - -
    -            - Redirects the client back to the first valid - request in history. -
    - -  void - - - - - remove() - -
    -            - Removes the current history stack -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.History

    -
    jala.History()
    - - -
      - Constructs a new History object. -
    - - - - - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    add

    -
    void add()
    - -
      Initializes a new history stack, adds - it to the array of stacks (which makes it - the default one to use for further requests) - and records the current request Url.
    - - - - - - - - - - - -
    - - -

    clear

    -
    void clear()
    - -
      Clears the currently active history stack
    - - - - - - - - - - - -
    - - -

    dump

    -
    String dump()
    - -
      Returns the contents of all history stacks - as string
    - - - - - - - -
      - Returns: -
        - The history stacks as string -
      -
    - - - - - -
    - - -

    peek

    -
    String peek(<Number> offset)
    - -
      Retrieves the request Url at the given position - in the current history stack. If no offset is given - the last Url in the stack is returned. This method - does not alter the stack contents!
    - - - - -
      - Parameters: - -
        offset - The index position in history stack to start searching at -
      - -
    - - - - -
      - Returns: -
        - The Url of the request -
      -
    - - - - - -
    - - -

    pop

    -
    String pop(<Number> offset)
    - -
      Retrieves the first valid request Url in history - stack starting with a given offset. The default offset is 1. - Any valid Url found is removed from the stack, therefor - this method alters the contents of the history stack.
    - - - - -
      - Parameters: - -
        offset - The index position in history stack to start searching at -
      - -
    - - - - -
      - Returns: -
        - The Url of the request -
      -
    - - - - - -
    - - -

    push

    -
    void push()
    - -
      Records a request Url in the currently active - history stack.
    - - - - - - - - - - - -
    - - -

    redirect

    -
    void redirect(<Number> offset)
    - -
      Redirects the client back to the first valid - request in history. Please mind that searching for - a valid Url starts at history.length - 2.
    - - - - -
      - Parameters: - -
        offset - The index position in the stack to start searching at -
      - -
    - - - - - - - - -
    - - -

    remove

    -
    void remove()
    - -
      Removes the current history stack
    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.HtmlDocument.html b/modules/jala/docs/jala.HtmlDocument.html deleted file mode 100644 index 190b24e8..00000000 --- a/modules/jala/docs/jala.HtmlDocument.html +++ /dev/null @@ -1,483 +0,0 @@ - - - - - -jala.HtmlDocument - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.HtmlDocument

    -
    Object
    -   |
    -   +--jala.HtmlDocument
    -
    - - -
    -
    - -
    class - jala.HtmlDocument - - -
    - -

    -
    This class provides easy access to the elements of - an arbitrary HTML document. By using TagSoup, Dom4J and Jaxen - even invalid HTML can be parsed, turned into an object tree - and easily be processed with XPath expressions. -
    Defined in HtmlDocument.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.HtmlDocument - - (<String> source) - -
    -             - Construct a new HTML document. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Array - - - - - getAll(<String> elementName) - -
    -            - Retrieves all elements by name from the document. -
    - -  Array - - - - - getLinks() - -
    -            - Get all link elements of the HTML document. -
    - -  org.dom4j.tree.DefaultElement - - - - - scrape(<String> xpathExpr) - -
    -            - Get all document nodes from an XPath expression. -
    - -  String - - - - - toString() - -
    -            - Get a string representation of the HTML document. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.HtmlDocument

    -
    jala.HtmlDocument(<String> source)
    - - -
      - Construct a new HTML document. -
    - - - -
      - Parameters: - -
        source - The HTML source code. -
      - - -
    - - - - -
      - Returns: -
        - A new HTML document. -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    getAll

    -
    Array getAll(<String> elementName)
    - -
      Retrieves all elements by name from the document. - The returned object structure is compatible for usage - in jala.XmlWriter.
    - - - - -
      - Parameters: - -
        elementName - The name of the desired element -
      - -
    - - - - -
      - Returns: -
        - The list of available elements in the document -
      -
    - - - - - -
    - - -

    getLinks

    -
    Array getLinks()
    - -
      Get all link elements of the HTML document.
    - - - - - - - -
      - Returns: -
        - A list of link elements. -
      -
    - - - - - -
    - - -

    scrape

    -
    org.dom4j.tree.DefaultElement scrape(<String> xpathExpr)
    - -
      Get all document nodes from an XPath expression.
    - - - - -
      - Parameters: - -
        xpathExpr - An XPath expression. -
      - -
    - - - - -
      - Returns: -
        - A list of HTML elements. -
      -
    - - - - - -
    - - -

    toString

    -
    String toString()
    - -
      Get a string representation of the HTML document.
    - - - - - - - -
      - Returns: -
        - A string representation of the HTML document. -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.I18n.html b/modules/jala/docs/jala.I18n.html deleted file mode 100644 index 633ca818..00000000 --- a/modules/jala/docs/jala.I18n.html +++ /dev/null @@ -1,951 +0,0 @@ - - - - - -jala.I18n - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.I18n

    -
    Object
    -   |
    -   +--jala.I18n
    -
    - - -
    -
    - -
    class - jala.I18n - - -
    - -

    -
    This class provides various functions and macros for - internationalization of Helma applications. -
    Defined in I18n.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.I18n - - () - -
    -             - Constructs a new instance of jala.I18n -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - formatMessage(<String> message, <Array> values) - -
    -            - Converts the message passed as argument into an instance - of java.text.MessageFormat, and formats it using the - replacement values passed. -
    - -  Object - - - - - getCatalog(locale) - -
    -            - Helper method to get the message catalog - corresponding to the actual locale. -
    - -  java.util.Locale - - - - - getLocale(localeId) - -
    -            - Returns the locale for the given id, which is expected to follow - the form language[_COUNTRY][_variant], where language - is a valid ISO Language Code (eg. -
    - -  Function - - - - - getLocaleGetter() - -
    -            - Get the method for retrieving the locale. -
    - -  Object - - - - - getMessages() - -
    -            - Get the message object. -
    - -  String - - - - - gettext(<String> key ) - -
    -            - Returns a localized message for the message key passed as - argument. -
    - -  String - - - - - markgettext(<String> key) - -
    -            - A simple proxy method which is used to mark a message string - for the i18n parser as to be translated. -
    - -  String - - - - - message_macro(param) - -
    -            - Returns a translated message. -
    - -  String - - - - - ngettext(<String> singularKey, <String> pluralKey, <Number> amount ) - -
    -            - Returns a localized message for the message key passed as - argument. -
    - -  void - - - - - setHandler(<Object> handler) - -
    -            - Set (overwrite) the default handler containing - the messages (ie. -
    - -  void - - - - - setLocaleGetter(<Function> func) - -
    -            - Set the method for retrieving the locale. -
    - -  void - - - - - setMessages(<Object> msgObject) - -
    -            - Overwrite the default object containing - the messages (ie. -
    - -  String - - - - - translate(singularKey, pluralKey, <Number> amount) - -
    -            - Tries to "translate" the given message key into a localized - message. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.I18n

    -
    jala.I18n()
    - - -
      - Constructs a new instance of jala.I18n -
    - - - - - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    formatMessage

    -
    String formatMessage(<String> message, <Array> values)
    - -
      Converts the message passed as argument into an instance - of java.text.MessageFormat, and formats it using the - replacement values passed.
    - - - - -
      - Parameters: - -
        message - The message to format -
      - -
        values - An optional array containing replacement values -
      - -
    - - - - -
      - Returns: -
        - The formatted message or, if the formatting fails, the message passed as argument. -
      -
    - - - - -
      - See:
        - http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html
      -
    - - -
    - - -

    getCatalog

    -
    Object getCatalog(locale)
    - -
      Helper method to get the message catalog - corresponding to the actual locale.
    - - - - - - - -
      - Returns: -
        - The message catalog. -
      -
    - - - - - -
    - - -

    getLocale

    -
    java.util.Locale getLocale(localeId)
    - -
      Returns the locale for the given id, which is expected to follow - the form language[_COUNTRY][_variant], where language - is a valid ISO Language Code (eg. "de"), COUNTRY a valid ISO - Country Code (eg. "AT"), and variant an identifier for the variant to use.
    - - - - - - - -
      - Returns: -
        - The locale for the given id -
      -
    - - - - - -
    - - -

    getLocaleGetter

    -
    Function getLocaleGetter()
    - -
      Get the method for retrieving the locale.
    - - - - - - - -
      - Returns: -
        - The getter method -
      -
    - - - - - -
    - - -

    getMessages

    -
    Object getMessages()
    - -
      Get the message object.
    - - - - - - - -
      - Returns: -
        - The object containing the messages -
      -
    - - - - - -
    - - -

    gettext

    -
    String gettext(<String> key )
    - -
      Returns a localized message for the message key passed as - argument. If no localization is found, the message key - is returned. Any additional arguments passed to this function - will be used as replacement values during message rendering. - To reference these values the message can contain placeholders - following "{number}" notation, where number must - match the number of the additional argument (starting with zero).
    - - - - -
      - Parameters: - -
        key - The message to localize -
      - -
    - - - - -
      - Returns: -
        - The translated message -
      -
    - - - - - - - -
    - - -

    markgettext

    -
    String markgettext(<String> key)
    - -
      A simple proxy method which is used to mark a message string - for the i18n parser as to be translated.
    - - - - -
      - Parameters: - -
        key - The message that should be seen by the i18n parser as to be translated. -
      - -
    - - - - -
      - Returns: -
        - The message in unmodified form -
      -
    - - - - - -
    - - -

    message_macro

    -
    String message_macro(param)
    - -
      Returns a translated message. The following macro attributes - are accepted: -
        -
      • text: The message to translate (required)
      • -
      • plural: The plural form of the message
      • -
      • values: A list of replacement values. Use a comma to separate more - than one value. Each value is either interpreted as a global property - (if it doesn't containg a dot) or as a property name of the given macro - handler object (eg. "user.name"). If the value of the property is a - HopObject or an Array this macro uses the size() resp. length of the - object, otherwise the string representation of the object will be used.
      • -
    - - - - - - - -
      - Returns: -
        - The translated message -
      -
    - - - - - - - -
    - - -

    ngettext

    -
    String ngettext(<String> singularKey, <String> pluralKey, <Number> amount )
    - -
      Returns a localized message for the message key passed as - argument. In contrast to gettext() this method - can handle plural forms based on the amount passed as argument. - If no localization is found, the appropriate message key is - returned. Any additional arguments passed to this function - will be used as replacement values during message rendering. - To reference these values the message can contain placeholders - following "{number}" notation, where number must - match the number of the additional argument (starting with zero).
    - - - - -
      - Parameters: - -
        singularKey - The singular message to localize -
      - -
        pluralKey - The plural form of the message to localize -
      - -
        amount - The amount which is used to determine whether the singular or plural form of the message should be returned. -
      - -
    - - - - -
      - Returns: -
        - The translated message -
      -
    - - - - - - - -
    - - -

    setHandler

    -
    void setHandler(<Object> handler)
    - -
      Set (overwrite) the default handler containing - the messages (ie. a vanilla EcmaScript object).
    - - - - -
      - Parameters: - -
        handler - The handler containing the message object -
      - -
    - - - - - - - - - - -
    - - -

    setLocaleGetter

    -
    void setLocaleGetter(<Function> func)
    - -
      Set the method for retrieving the locale.
    - - - - -
      - Parameters: - -
        func - The getter method -
      - -
    - - - - - - - - -
    - - -

    setMessages

    -
    void setMessages(<Object> msgObject)
    - -
      Overwrite the default object containing - the messages (ie. a vanilla EcmaScript object).
    - - - - -
      - Parameters: - -
        msgObject - The object containing the messages -
      - -
    - - - - - - - - -
    - - -

    translate

    -
    String translate(singularKey, pluralKey, <Number> amount)
    - -
      Tries to "translate" the given message key into a localized - message.
    - - - - -
      - Parameters: - -
        amount - A number to determine whether to use the singular or plural form of the message -
      - -
        key - The message to translate (required) -
      - -
        plural - The plural form of the message to translate -
      - -
    - - - - -
      - Returns: -
        - The localized message or the appropriate key if no localized message was found -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.ImageFilter.html b/modules/jala/docs/jala.ImageFilter.html deleted file mode 100644 index 5451df17..00000000 --- a/modules/jala/docs/jala.ImageFilter.html +++ /dev/null @@ -1,510 +0,0 @@ - - - - - -jala.ImageFilter - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.ImageFilter

    -
    Object
    -   |
    -   +--jala.ImageFilter
    -
    - - -
    -
    - -
    class - jala.ImageFilter - - -
    - -

    -
    This class provides several image manipulating - methods. Most of this filter library is based on filters created - by Janne Kipin for JAlbum. For more information have a look - at http://www.ratol.fi/~jakipina/java/ -
    Defined in ImageFilter.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.ImageFilter - - (<Object> img) - -
    -             - Constructs a new ImageFilter object -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - gaussianBlur(<Number> radius, <Number> amount) - -
    -            - Performs a gaussian blur operation on the image -
    - -  byte[] - - - - - getBytes() - -
    -            - Returns the wrapped image as byte array, to use eg. -
    - -  helma.image.ImageWrapper - - - - - getImage() - -
    -            - Returns the image that has been worked on -
    - -  void - - - - - sharpen(<Number> amount) - -
    -            - Sharpens the image using a plain sharpening kernel. -
    - -  void - - - - - unsharpMask(<Number> radius, <Number> amount) - -
    -            - Performs an unsharp mask operation on the image -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.ImageFilter

    -
    jala.ImageFilter(<Object> img)
    - - -
      - Constructs a new ImageFilter object -
    - - - -
      - Parameters: - -
        img - Either
        • an instance of helma.image.ImageWrapper
        • the path to the image file as String
        • an instance of helma.File representing the image file
        • an instance of java.io.File representing the image file
        -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    gaussianBlur

    -
    void gaussianBlur(<Number> radius, <Number> amount)
    - -
      Performs a gaussian blur operation on the image
    - - - - -
      - Parameters: - -
        radius - The radius -
      - -
        amount - The amount -
      - -
    - - - - - - - - -
    - - -

    getBytes

    -
    byte[] getBytes()
    - -
      Returns the wrapped image as byte array, to use eg. in conjunction - with res.writeBinary()
    - - - - - - - -
      - Returns: -
        - The wrapped image as byte array -
      -
    - - - - - -
    - - -

    getImage

    -
    helma.image.ImageWrapper getImage()
    - -
      Returns the image that has been worked on
    - - - - - - - -
      - Returns: -
        - An instance of helma.image.ImageWrapper -
      -
    - - - - - -
    - - -

    sharpen

    -
    void sharpen(<Number> amount)
    - -
      Sharpens the image using a plain sharpening kernel.
    - - - - -
      - Parameters: - -
        amount - The amount of sharpening to apply -
      - -
    - - - - - - - - -
    - - -

    unsharpMask

    -
    void unsharpMask(<Number> radius, <Number> amount)
    - -
      Performs an unsharp mask operation on the image
    - - - - -
      - Parameters: - -
        radius - The radius -
      - -
        amount - The amount -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.IndexManager.Job.html b/modules/jala/docs/jala.IndexManager.Job.html deleted file mode 100644 index a1db9cc8..00000000 --- a/modules/jala/docs/jala.IndexManager.Job.html +++ /dev/null @@ -1,447 +0,0 @@ - - - - - -jala.IndexManager.Job - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.IndexManager.Job

    -
    Object
    -   |
    -   +--jala.IndexManager.Job
    -
    - - -
    -
    - -
    class - jala.IndexManager.Job - - -
    - -

    -
    Instances of this class represent a single index - manipulation job to be processed by the index manager. -
    Defined in IndexManager.js

    See:

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  Objectcallback -
    -           The data needed to process this job.
    -  Datecreatetime -
    -           The date and time at which this job was created.
    -  Numbererrors -
    -           An internal error counter which is increased whenever processing - the job failed.
    -  Numbertype -
    -           The type of the job
    - <static>  <final> NumberADD -
    -           Constant defining an add job
    - <static>  <final> NumberOPTIMIZE -
    -           Constant defining an optimizing job
    - <static>  <final> NumberREMOVE -
    -           Constant defining a removal job
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.IndexManager.Job - - (<Number> type, callback) - -
    -             - Creates a new Job instance. -
    - - - -  - - - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    callback

    -
    Object callback
    -
      - The data needed to process this job. For adding jobs this property - must contain the helma.Search.Document instance to add to - the index. For removal job this property must contain the unique identifier - of the document that should be removed from the index. For optimizing - jobs this property is null. - -
    -
    - - -

    createtime

    -
    Date createtime
    -
      - The date and time at which this job was created. - -
    -
    - - -

    errors

    -
    Number errors
    -
      - An internal error counter which is increased whenever processing - the job failed. - -
    -
    - - -

    type

    -
    Number type
    -
      - The type of the job - -
    -
    - - -

    ADD

    -
    <static> <final> Number ADD
    - -
    - - -

    OPTIMIZE

    -
    <static> <final> Number OPTIMIZE
    - -
    - - -

    REMOVE

    -
    <static> <final> Number REMOVE
    - -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.IndexManager.Job

    -
    jala.IndexManager.Job(<Number> type, callback)
    - - -
      - Creates a new Job instance. -
    - - - -
      - Parameters: - -
        type - The type of job, which can be either jala.IndexManager.Job.ADD, jala.IndexManager.Job.REMOVE or jala.IndexManager.Job.OPTIMIZE. -
      - -
        id - The Id of the job -
      - -
        data - The data needed to process the job. -
      - - -
    - - - - -
      - Returns: -
        - A newly created Job instance. -
      -
    - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.IndexManager.html b/modules/jala/docs/jala.IndexManager.html deleted file mode 100644 index 0c198138..00000000 --- a/modules/jala/docs/jala.IndexManager.html +++ /dev/null @@ -1,615 +0,0 @@ - - - - - -jala.IndexManager - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.IndexManager

    -
    Object
    -   |
    -   +--jala.IndexManager
    -
    - - -
    -
    - -
    class - jala.IndexManager - - -
    - -

    -
    This class basically sits on top of a helma.Search.Index instance - and provides methods for adding, removing and optimizing the underlying index. - All methods generate jobs that are put into an internal queue which is - processed asynchronously by a separate worker thread. This means all calls - to add(), remove() and optimize() will return immediately, but the changes to - the index will be done within a short delay. Please keep in mind to change the - status of this IndexManager instance to REBUILDING before starting to rebuild - the index, as this ensures that all add/remove/optimize jobs will stay in the - queue and will only be processed after switching the status back to NORMAL. - This ensures that objects that have been modified during a rebuilding process - are re-indexed properly afterwards. -
    Defined in IndexManager.js

    See:

      - helma.Search.createIndex
    -

    - -
    - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.IndexManager.Job
    -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    - <static>  <final> NumberMAXTRIES -
    -           Constant defining the maximum number of tries to add/remove - an object to/from the underlying index.
    - <static>  <final> NumberNORMAL -
    -           Constant defining normal mode of this index manager.
    - <static>  <final> NumberREBUILDING -
    -           Constant defining rebuilding mode of this index manager.
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.IndexManager - - (<String> name, <helma.File> dir, <String> lang) - -
    -             - Constructs a new IndexManager object. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Boolean - - - - - add(<helma.Search.Document> doc) - -
    -            - Queues the document object passed as argument for addition to the underlying - index. -
    - -  void - - - - - log() - -
    -            - Helper function that prefixes every log message with - the name of the IndexManager. -
    - -  Boolean - - - - - optimize() - -
    -            - Queues the optimization of the underlying index. -
    - -  Boolean - - - - - remove(<Number> id) - -
    -            - Queues the removal of all index documents whose identifier value ("id" by default) - matches the number passed as argument. -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    MAXTRIES

    -
    <static> <final> Number MAXTRIES
    -
      - Constant defining the maximum number of tries to add/remove - an object to/from the underlying index. - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - -

    NORMAL

    -
    <static> <final> Number NORMAL
    - -
    - - -

    REBUILDING

    -
    <static> <final> Number REBUILDING
    -
      - Constant defining rebuilding mode of this index manager. - -

      -

      -
      See Also:
      Constant Field Values
      - - - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.IndexManager

    -
    jala.IndexManager(<String> name, <helma.File> dir, <String> lang)
    - - -
      - Constructs a new IndexManager object. -
    - - - -
      - Parameters: - -
        name - The name of the index, which is the name of the directory the index already resides or will be created in. -
      - -
        dir - The base directory where this index's directory is already existing or will be created in. -
      - -
        lang - The language of the documents in this index. This leads to the proper Lucene analyzer being used for indexing documents. -
      - - -
    - - - - - - - - -
      -See:
        - helma.Search.createIndex
      -
    - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    add

    -
    Boolean add(<helma.Search.Document> doc)
    - -
      Queues the document object passed as argument for addition to the underlying - index. This includes that all existing documents with the same identifier will - be removed before the object passed as argument is added.
    - - - - -
      - Parameters: - -
        doc - The document object that should be added to the underlying index. -
      - -
    - - - - -
      - Returns: -
        - True if the job was added successfully to the internal queue, false otherwise. -
      -
    - - - - -
      - See:
        - helma.Search.Document
      -
    - - -
    - - -

    log

    -
    void log()
    - -
      Helper function that prefixes every log message with - the name of the IndexManager.
    - - - - -
      - Parameters: - -
        level - An optional logging level. Accepted values -
      - -
        msg - The log message are "debug", "info", "warn" and "error". -
      - -
    - - - - - - - - -
    - - -

    optimize

    -
    Boolean optimize()
    - -
      Queues the optimization of the underlying index.
    - - - - - - - -
      - Returns: -
        - True if the optimizing job was added, false otherwise, which means that there is already an optimizing job waiting in the queue. -
      -
    - - - - - -
    - - -

    remove

    -
    Boolean remove(<Number> id)
    - -
      Queues the removal of all index documents whose identifier value ("id" by default) - matches the number passed as argument.
    - - - - -
      - Parameters: - -
        id - The identifier value -
      - -
    - - - - -
      - Returns: -
        - True if the removal job was added successfully to the queue, false otherwise. -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.ListRenderer.ArrayList.html b/modules/jala/docs/jala.ListRenderer.ArrayList.html deleted file mode 100644 index fe0c4af7..00000000 --- a/modules/jala/docs/jala.ListRenderer.ArrayList.html +++ /dev/null @@ -1,547 +0,0 @@ - - - - - -jala.ListRenderer.ArrayList - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.ListRenderer.ArrayList

    -
    Object
    -   |
    -   +--jala.ListRenderer.ArrayList
    -
    - - -
    -
    - -
    class - jala.ListRenderer.ArrayList - - -
    - -

    -
    A simple wrapper around an array to use in conjunction - with jala.ListRenderer. This wrapper can either handle complete arrays - or subsections of an array. In the latter case the wrapper needs offset - and total size information as argument to mimick a complete array. -
    Defined in ListRenderer.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  Numberlength -
    -           The length of this ArrayList instance.
    -  Numberoffset -
    -           The offset of this ArrayList instance.
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.ListRenderer.ArrayList - - (<Array> arr, <Number> offset, <Number> total) - -
    -             - Creates a new ArrayList instance. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Object - - - - - get(<Number> idx) - -
    -            - Returns the element at the index position passed - as argument. -
    - -  Boolean - - - - - isSubset() - -
    -            - Returns true if this ArrayList is a subsection of a bigger array -
    - -  Number - - - - - size() - -
    -            - Returns the size of this ArrayList, which is either - the length of the wrapped array or the total size - passed as argument to the constructor (in case the wrapped - array is just a subsection). -
    - -  Number - - - - - subsetSize() - -
    -            - Returns the actual size of this ArrayList's wrapped array. -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    length

    -
    Number length
    -
      - The length of this ArrayList instance. - -
    -
    - - -

    offset

    -
    Number offset
    -
      - The offset of this ArrayList instance. This might be > zero for - ArrayList instances wrapping just a subsection, that is - mimicking a bigger list. - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.ListRenderer.ArrayList

    -
    jala.ListRenderer.ArrayList(<Array> arr, <Number> offset, <Number> total)
    - - -
      - Creates a new ArrayList instance. -
    - - - -
      - Parameters: - -
        arr - The array (or a subsection of an array) to wrap -
      - -
        offset - An optional offset to use (mandatory if the array is just a subsection). -
      - -
        total - An optional total size of the array. This argument is mandatory if the wrapped array is just a subsection. -
      - - -
    - - - - -
      - Returns: -
        - A newly created ArrayList instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    get

    -
    Object get(<Number> idx)
    - -
      Returns the element at the index position passed - as argument. If the wrapped array is just a subsection - the index position passed will be corrected using - the offset.
    - - - - -
      - Parameters: - -
        idx - The index position of the element to return -
      - -
    - - - - -
      - Returns: -
        - The element at the given index position -
      -
    - - - - - -
    - - -

    isSubset

    -
    Boolean isSubset()
    - -
      Returns true if this ArrayList is a subsection of a bigger array
    - - - - - - - -
      - Returns: -
        - True if this ArrayList is a subsection of a bigger array -
      -
    - - - - - -
    - - -

    size

    -
    Number size()
    - -
      Returns the size of this ArrayList, which is either - the length of the wrapped array or the total size - passed as argument to the constructor (in case the wrapped - array is just a subsection).
    - - - - - - - -
      - Returns: -
        - The size of this ArrayList instance -
      -
    - - - - - -
    - - -

    subsetSize

    -
    Number subsetSize()
    - -
      Returns the actual size of this ArrayList's wrapped array.
    - - - - - - - -
      - Returns: -
        - The actual size of this ArrayList's wrapped array. -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.ListRenderer.html b/modules/jala/docs/jala.ListRenderer.html deleted file mode 100644 index 7a9324be..00000000 --- a/modules/jala/docs/jala.ListRenderer.html +++ /dev/null @@ -1,2339 +0,0 @@ - - - - - -jala.ListRenderer - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.ListRenderer

    -
    Object
    -   |
    -   +--jala.ListRenderer
    -
    - - -
    -
    - -
    class - jala.ListRenderer - - -
    - -

    -

    Defined in ListRenderer.js

    -

    - -
    - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.ListRenderer.ArrayList
    -  - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    - <static>  <final> ObjectdefaultRenderer -
    -           Default Renderer object containing functions - used for rendering different list items (eg.
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.ListRenderer - - (<HopObject|ArrayList|Array> coll, <Object> renderer) - -
    -             - -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Number - - - - - currentEnd_macro() - -
    -            - Returns the end item number in the current page -
    - -  Number - - - - - currentPage_macro() - -
    -            - Returns the current page number -
    - -  Number - - - - - currentStart_macro() - -
    -            - Returns the start item number in the current page -
    - -  String - - - - - getBaseHref() - -
    -            - Returns the base href of this ListRenderer instance -
    - -  HopObject|Array - - - - - getCollection() - -
    -            - Returns the collection this ListRenderer instance operates on -
    - -  Number - - - - - getCurrentPage() - -
    -            - Returns the current page index. -
    - -  Number - - - - - getEndIndex() - -
    -            - Returns the zero-based index position of the last item of the current page - in the collection this ListRenderer operates on. -
    - -  Number - - - - - getItemSkin() - -
    -            - Returns the name of the skin rendered for a single list item -
    - -  String - - - - - getList(<Object> param) - -
    -            - Returns the rendered list of collection items as string -
    - -  Number - - - - - getMaxPages() - -
    -            - Returns the maximum number of pages handled by this ListRenderer instance -
    - -  String - - - - - getNextLink(<Object> param) - -
    -            - Returns a rendered link to the previous page as string. -
    - -  String - - - - - getPageHref(<Number> page) - -
    -            - Returns the href of a page. -
    - -  String - - - - - getPageNavigation(<Object> param) - -
    -            - Returns the rendered page navigation bar as string -
    - -  Number - - - - - getPageSize() - -
    -            - Returns the number of items displayed on one page -
    - -  String - - - - - getPrevLink(<Object> param) - -
    -            - Returns a rendered link to the previous page as string. -
    - -  Object - - - - - getRenderer() - -
    -            - Returns the renderer used by this ListRenderer instance -
    - -  Number - - - - - getStartIndex() - -
    -            - Returns the zero-based index position of the first item of the current page - in the collection this ListRenderer operates on. -
    - -  Number - - - - - getTotalPages() - -
    -            - Returns the total number of pages handled by this ListRenderer instance - (which is the collection size divided by the page size). -
    - -  String - - - - - getUrlParameterName() - -
    -            - Returns the name of the URL parameter name containing the index - of the page to display -
    - -  String - - - - - getUrlParameters() - -
    -            - Returns any additional URL parameters included in every navigation link - rendered by this ListRenderer instance. -
    - -  Number - - - - - limit_macro(<Object> param) - -
    -            - Either renders the maximum number of items per page, or - sets the limit to a given number. -
    - -  String - - - - - nextLink_macro(<Object> param) - -
    -            - Returns a rendered link to the next page. -
    - -  String - - - - - pageNavigation_macro(<Object> param) - -
    -            - Returns the rendered page navigation bar. -
    - -  String - - - - - prevLink_macro(<Object> param) - -
    -            - Returns a rendered link to the previous page. -
    - -  void - - - - - render_macro(<Object> param) - -
    -            - Renders the current page of this list. -
    - -  void - - - - - renderList(<Object> param) - -
    -            - Renders the list of items for one page directly to response. -
    - -  String - - - - - renderListAsString(<Object> param) - -
    -            - Returns the rendered list of collection items as string -
    - -  void - - - - - renderNextLink(<Object> param) - -
    -            - Renders a link to the next page directly to response. -
    - -  String - - - - - renderNextLinkAsString(param) - -
    -            - Returns a rendered link to the previous page as string -
    - -  Object - - - - - renderPageNavigation(<Object> param) - -
    -            - Renders the page navigation bar directly to response. -
    - -  String - - - - - renderPageNavigationAsString(param) - -
    -            - Returns the rendered page navigation bar as string -
    - -  void - - - - - renderPrevLink(<Object> param) - -
    -            - Renders a link to the previous page directly to response. -
    - -  String - - - - - renderPrevLinkAsString(<Object> param) - -
    -            - Returns a rendered link to the previous page as string -
    - -  void - - - - - setBaseHref(<String> href) - -
    -            - Sets the base href of this ListRenderer instance. -
    - -  void - - - - - setCollection(<HopObject|ArrayList|Array> coll) - -
    -            - Sets the collection of this ListRenderer -
    - -  void - - - - - setItemSkin(<String> name) - -
    -            - Sets the name of the skin to render for every list item -
    - -  void - - - - - setMaxPages(<Number> pages) - -
    -            - Sets the maximum number of pages to display -
    - -  void - - - - - setPageSize(<Number> size) - -
    -            - Sets the number of items to display on a single page -
    - -  void - - - - - setRenderer(<Object> r) - -
    -            - Sets the renderer to be used by this ListRenderer instance -
    - -  void - - - - - setUrlParameterName(<String> name) - -
    -            - Sets the name of the URL parameter name containing the index of the page - to display -
    - -  void - - - - - setUrlParameters(<String> params) - -
    -            - Sets additional parameters to include in every navigation link -
    - -  Number - - - - - size_macro() - -
    -            - Returns the total number of items -
    - -  Number - - - - - totalPages_macro() - -
    -            - Returns the total number of pages -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    defaultRenderer

    -
    <static> <final> Object defaultRenderer
    -
      - Default Renderer object containing functions - used for rendering different list items (eg. page navigation, - prev/next links and list items). - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.ListRenderer

    -
    jala.ListRenderer(<HopObject|ArrayList|Array> coll, <Object> renderer)
    - - - - -
      - Parameters: - -
        coll - The collection this ListRenderer operates on, or - for backwards compatibility only - a parameter object containing the collection and any other optional configuration parameters. -
      - -
        renderer - An optional renderer to use. If this is set, any rendering method defined in this renderer overrides the default renderer. -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    currentEnd_macro

    -
    Number currentEnd_macro()
    - -
      Returns the end item number in the current page
    - - - - - - - -
      - Returns: -
        - The end item number in the current page -
      -
    - - - - - -
    - - -

    currentPage_macro

    -
    Number currentPage_macro()
    - -
      Returns the current page number
    - - - - - - - -
      - Returns: -
        - The current page number -
      -
    - - - - - -
    - - -

    currentStart_macro

    -
    Number currentStart_macro()
    - -
      Returns the start item number in the current page
    - - - - - - - -
      - Returns: -
        - The start item number in the current page -
      -
    - - - - - -
    - - -

    getBaseHref

    -
    String getBaseHref()
    - -
      Returns the base href of this ListRenderer instance
    - - - - - - - -
      - Returns: -
        - The base href of this ListRenderer instance -
      -
    - - - - - -
    - - -

    getCollection

    -
    HopObject|Array getCollection()
    - -
      Returns the collection this ListRenderer instance operates on
    - - - - - - - -
      - Returns: -
        - The collection of this ListRenderer -
      -
    - - - - - -
    - - -

    getCurrentPage

    -
    Number getCurrentPage()
    - -
      Returns the current page index. This is either the page url parameter - or the page number 1.
    - - - - - - - -
      - Returns: -
        - The current page number (starts with 1). -
      -
    - - - - - - - -
    - - -

    getEndIndex

    -
    Number getEndIndex()
    - -
      Returns the zero-based index position of the last item of the current page - in the collection this ListRenderer operates on.
    - - - - - - - -
      - Returns: -
        - The index position of the last item in the list -
      -
    - - - - - -
    - - -

    getItemSkin

    -
    Number getItemSkin()
    - -
      Returns the name of the skin rendered for a single list item
    - - - - - - - -
      - Returns: -
        - The name of the list item skin -
      -
    - - - - - -
    - - -

    getList

    -
    String getList(<Object> param)
    - -
      Returns the rendered list of collection items as string
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - -
      - Returns: -
        - The rendered list -
      -
    - - - - - - - -
    - - -

    getMaxPages

    -
    Number getMaxPages()
    - -
      Returns the maximum number of pages handled by this ListRenderer instance
    - - - - - - - -
      - Returns: -
        - The maximum number of pages -
      -
    - - - - - -
    - - -

    getNextLink

    -
    String getNextLink(<Object> param)
    - -
      Returns a rendered link to the previous page as string. For performance - reasons this method caches the rendered link in the local cache of this - ListRenderer instance.
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - -
      - Returns: -
        - A rendered link to the previous page -
      -
    - - - - - - - -
    - - -

    getPageHref

    -
    String getPageHref(<Number> page)
    - -
      Returns the href of a page. If no argument is given, the href - of the current page is returned. Any URL parameters set with - setUrlParameters() are added to the href.
    - - - - -
      - Parameters: - -
        page - The optional page number to include in the href. -
      - -
    - - - - -
      - Returns: -
        - The href of the page -
      -
    - - - - - - - -
    - - -

    getPageNavigation

    -
    String getPageNavigation(<Object> param)
    - -
      Returns the rendered page navigation bar as string
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - -
      - Returns: -
        - The rendered page navigation -
      -
    - - - - - - - -
    - - -

    getPageSize

    -
    Number getPageSize()
    - -
      Returns the number of items displayed on one page
    - - - - - - - -
      - Returns: -
        - The number of items displayed on a single page -
      -
    - - - - - -
    - - -

    getPrevLink

    -
    String getPrevLink(<Object> param)
    - -
      Returns a rendered link to the previous page as string. For performance - reasons this method caches the rendered link in the local cache of this - ListRenderer instance.
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - -
      - Returns: -
        - A rendered link to the previous page -
      -
    - - - - - - - -
    - - -

    getRenderer

    -
    Object getRenderer()
    - -
      Returns the renderer used by this ListRenderer instance
    - - - - - - - - - - - -
    - - -

    getStartIndex

    -
    Number getStartIndex()
    - -
      Returns the zero-based index position of the first item of the current page - in the collection this ListRenderer operates on.
    - - - - - - - -
      - Returns: -
        - The index position of the first item in the list -
      -
    - - - - - -
    - - -

    getTotalPages

    -
    Number getTotalPages()
    - -
      Returns the total number of pages handled by this ListRenderer instance - (which is the collection size divided by the page size).
    - - - - - - - -
      - Returns: -
        - The total number of pages -
      -
    - - - - - -
    - - -

    getUrlParameterName

    -
    String getUrlParameterName()
    - -
      Returns the name of the URL parameter name containing the index - of the page to display
    - - - - - - - -
      - Returns: -
        - The name of the page URL parameter name -
      -
    - - - - - -
    - - -

    getUrlParameters

    -
    String getUrlParameters()
    - -
      Returns any additional URL parameters included in every navigation link - rendered by this ListRenderer instance.
    - - - - - - - -
      - Returns: -
        - A string containing additional URL parameters -
      -
    - - - - - -
    - - -

    limit_macro

    -
    Number limit_macro(<Object> param)
    - -
      Either renders the maximum number of items per page, or - sets the limit to a given number.
    - - - - -
      - Parameters: - -
        param - Extra macro parameters:
        • to - The maximum number of items per page to be set.
        If no limit is set, this macro returns the current number of items per page. -
      - -
    - - - - -
      - Returns: -
        - The current maximum number of items per page -
      -
    - - - - - -
    - - -

    nextLink_macro

    -
    String nextLink_macro(<Object> param)
    - -
      Returns a rendered link to the next page.
    - - - - -
      - Parameters: - -
        param - Extra macro parameters:
        • type - The type of renderer to be applied.
        -
      - -
    - - - - -
      - Returns: -
        - A rendered link to the next page -
      -
    - - - - - - - -
    - - -

    pageNavigation_macro

    -
    String pageNavigation_macro(<Object> param)
    - -
      Returns the rendered page navigation bar.
    - - - - -
      - Parameters: - -
        param - Extra macro parameters:
        • type - The type of renderer to be applied.
        -
      - -
    - - - - -
      - Returns: -
        - The rendered page navigation bar -
      -
    - - - - - - - -
    - - -

    prevLink_macro

    -
    String prevLink_macro(<Object> param)
    - -
      Returns a rendered link to the previous page.
    - - - - -
      - Parameters: - -
        param - Extra macro parameters:
        • type - The type of renderer to be applied.
        -
      - -
    - - - - -
      - Returns: -
        - A rendered link to the previous page -
      -
    - - - - - - - -
    - - -

    render_macro

    -
    void render_macro(<Object> param)
    - -
      Renders the current page of this list.
    - - - - -
      - Parameters: - -
        param - Extra macro parameters:
        • skin - The name of the list skin to render for each item in the list.
        • type - The type of renderer to be applied.
        -
      - -
    - - - - - - - - - - -
    - - -

    renderList

    -
    void renderList(<Object> param)
    - -
      Renders the list of items for one page directly to response.
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - - - - - - - -
    - - -

    renderListAsString

    -
    String renderListAsString(<Object> param)
    - -
      Returns the rendered list of collection items as string
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - -
      - Returns: -
        - The rendered list -
      -
    - - - - - - - -
    - - -

    renderNextLink

    -
    void renderNextLink(<Object> param)
    - -
      Renders a link to the next page directly to response.
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - - - - - - - -
    - - -

    renderNextLinkAsString

    -
    String renderNextLinkAsString(param)
    - -
      Returns a rendered link to the previous page as string
    - - - - - - - -
      - Returns: -
        - A rendered link to the next page -
      -
    - - - - - - - -
    - - -

    renderPageNavigation

    -
    Object renderPageNavigation(<Object> param)
    - -
      Renders the page navigation bar directly to response. For performance reasons - this method caches the rendered page navigation in the local cache of this - ListRenderer instance.
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - - - - - - - -
    - - -

    renderPageNavigationAsString

    -
    String renderPageNavigationAsString(param)
    - -
      Returns the rendered page navigation bar as string
    - - - - - - - -
      - Returns: -
        - The rendered page navigation bar -
      -
    - - - - - - - -
    - - -

    renderPrevLink

    -
    void renderPrevLink(<Object> param)
    - -
      Renders a link to the previous page directly to response.
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - - - - - - - -
    - - -

    renderPrevLinkAsString

    -
    String renderPrevLinkAsString(<Object> param)
    - -
      Returns a rendered link to the previous page as string
    - - - - -
      - Parameters: - -
        param - Object containing extra parameters (e.g. from a macro call). -
      - -
    - - - - -
      - Returns: -
        - A rendered link to the previous page -
      -
    - - - - - - - -
    - - -

    setBaseHref

    -
    void setBaseHref(<String> href)
    - -
      Sets the base href of this ListRenderer instance. All links rendered - will start with the href passed as argument
    - - - - -
      - Parameters: - -
        href - The base href to use for rendering links -
      - -
    - - - - - - - - -
    - - -

    setCollection

    -
    void setCollection(<HopObject|ArrayList|Array> coll)
    - -
      Sets the collection of this ListRenderer
    - - - - -
      - Parameters: - -
        coll - The collection this ListRenderer instance should operate on -
      - -
    - - - - - - - - -
    - - -

    setItemSkin

    -
    void setItemSkin(<String> name)
    - -
      Sets the name of the skin to render for every list item
    - - - - -
      - Parameters: - -
        name - The name of the skin to render for every list item -
      - -
    - - - - - - - - -
    - - -

    setMaxPages

    -
    void setMaxPages(<Number> pages)
    - -
      Sets the maximum number of pages to display
    - - - - -
      - Parameters: - -
        pages - The maximum number of pages to display -
      - -
    - - - - - - - - -
    - - -

    setPageSize

    -
    void setPageSize(<Number> size)
    - -
      Sets the number of items to display on a single page
    - - - - -
      - Parameters: - -
        size - The number of items to display on one page -
      - -
    - - - - - - - - -
    - - -

    setRenderer

    -
    void setRenderer(<Object> r)
    - -
      Sets the renderer to be used by this ListRenderer instance
    - - - - -
      - Parameters: - -
        r - The renderer to use -
      - -
    - - - - - - - - -
    - - -

    setUrlParameterName

    -
    void setUrlParameterName(<String> name)
    - -
      Sets the name of the URL parameter name containing the index of the page - to display
    - - - - -
      - Parameters: - -
        name - The name of the page URL parameter -
      - -
    - - - - - - - - -
    - - -

    setUrlParameters

    -
    void setUrlParameters(<String> params)
    - -
      Sets additional parameters to include in every navigation link
    - - - - -
      - Parameters: - -
        params - A string to append to every navigation URL -
      - -
    - - - - - - - - -
    - - -

    size_macro

    -
    Number size_macro()
    - -
      Returns the total number of items
    - - - - - - - -
      - Returns: -
        - The total number of items in the collection this ListRenderer instance is working on -
      -
    - - - - - -
    - - -

    totalPages_macro

    -
    Number totalPages_macro()
    - -
      Returns the total number of pages
    - - - - - - - -
      - Returns: -
        - The total number of pages available -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Mp3.Id3v1.html b/modules/jala/docs/jala.Mp3.Id3v1.html deleted file mode 100644 index 21dedf33..00000000 --- a/modules/jala/docs/jala.Mp3.Id3v1.html +++ /dev/null @@ -1,1102 +0,0 @@ - - - - - -jala.Mp3.Id3v1 - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Mp3.Id3v1

    -
    Object
    -   |
    -   +--jala.Mp3.Id3v1
    -
    - - -
    -
    - -
    class - jala.Mp3.Id3v1 - - -
    - -

    -
    This class represents an Id3v1 tag. -
    Defined in Mp3.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Mp3.Id3v1 - - (audioObj) - -
    -             - Constructs a new Id3v1 tag from an Mp3 file -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - copyFrom(tag) - -
    -            - Copies standard fields from another tag. -
    - -  String - - - - - getAlbum() - -
    -            - Returns the album information of the tag. -
    - -  String - - - - - getArtist() - -
    -            - Returns the artist information of the tag. -
    - -  jala.Mp3 - - - - - getAudio() - -
    -            - Returns the wrapper for the underlying audio file. -
    - -  String - - - - - getComment() - -
    -            - Returns the comment information of the tag. -
    - -  String - - - - - getGenre() - -
    -            - Returns the genre information of the tag. -
    - -  org.farng.mp3.id3.AbstractID3v1 - - - - - getJavaObject() - -
    -            - Returns the java representation of the tag, - class depends on the actual library used. -
    - -  Object - - - - - getTextContent(<String> id) - -
    -            - This method could be used to retrieve an arbitrary field - of the underlying tag. -
    - -  String - - - - - getTitle() - -
    -            - Returns the title information of the tag. -
    - -  String - - - - - getTrackNumber() - -
    -            - Returns the track number information of the tag. -
    - -  String - - - - - getYear() - -
    -            - Returns the year information of the tag. -
    - -  void - - - - - setAlbum(<String> album) - -
    -            - Sets the album information. -
    - -  void - - - - - setArtist(<String> artist) - -
    -            - Sets the artist information. -
    - -  void - - - - - setComment(<String> comment) - -
    -            - Sets the comment -
    - -  void - - - - - setGenre(<String> genre) - -
    -            - Sets the genre information. -
    - -  void - - - - - setTextContent(<String> id, val) - -
    -            - This method could be used to set an arbitrary field - of the underlying tag. -
    - -  void - - - - - setTitle(<String> title) - -
    -            - Sets the title information -
    - -  void - - - - - setTrackNumber(<Number> trackNumber) - -
    -            - Sets the track number information. -
    - -  void - - - - - setYear(<Number> year) - -
    -            - Sets the year information. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Mp3.Id3v1

    -
    jala.Mp3.Id3v1(audioObj)
    - - -
      - Constructs a new Id3v1 tag from an Mp3 file -
    - - - -
      - Parameters: - -
        mp3File - -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    copyFrom

    -
    void copyFrom(tag)
    - -
      Copies standard fields from another tag.
    - - - - -
      - Parameters: - -
        src - object with getter methods for fields album, artist, comment, title, trackNumber, genre and year. -
      - -
    - - - - - - - - -
    - - -

    getAlbum

    -
    String getAlbum()
    - -
      Returns the album information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing album name -
      -
    - - - - - -
    - - -

    getArtist

    -
    String getArtist()
    - -
      Returns the artist information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing artist name -
      -
    - - - - - -
    - - -

    getAudio

    -
    jala.Mp3 getAudio()
    - -
      Returns the wrapper for the underlying audio file.
    - - - - - - - - - - - -
    - - -

    getComment

    -
    String getComment()
    - -
      Returns the comment information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing comment -
      -
    - - - - - -
    - - -

    getGenre

    -
    String getGenre()
    - -
      Returns the genre information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing genre name -
      -
    - - - - - -
    - - -

    getJavaObject

    -
    org.farng.mp3.id3.AbstractID3v1 getJavaObject()
    - -
      Returns the java representation of the tag, - class depends on the actual library used.
    - - - - - - - - - - - -
    - - -

    getTextContent

    -
    Object getTextContent(<String> id)
    - -
      This method could be used to retrieve an arbitrary field - of the underlying tag. For Id3v1 tags all information - is available through getter and setter methods, so this - implementation always returns null.
    - - - - -
      - Parameters: - -
        id - -
      - -
    - - - - -
      - Returns: -
        - null -
      -
    - - - - - -
    - - -

    getTitle

    -
    String getTitle()
    - -
      Returns the title information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing title -
      -
    - - - - - -
    - - -

    getTrackNumber

    -
    String getTrackNumber()
    - -
      Returns the track number information of the tag.
    - - - - - - - -
      - Returns: -
        - string representing track number or null if tag doesn't contain a track number. -
      -
    - - - - - -
    - - -

    getYear

    -
    String getYear()
    - -
      Returns the year information of the tag.
    - - - - - - - -
      - Returns: -
        - string representing year -
      -
    - - - - - -
    - - -

    setAlbum

    -
    void setAlbum(<String> album)
    - -
      Sets the album information.
    - - - - -
      - Parameters: - -
        album - -
      - -
    - - - - - - - - -
    - - -

    setArtist

    -
    void setArtist(<String> artist)
    - -
      Sets the artist information.
    - - - - -
      - Parameters: - -
        artist - -
      - -
    - - - - - - - - -
    - - -

    setComment

    -
    void setComment(<String> comment)
    - -
      Sets the comment
    - - - - -
      - Parameters: - -
        comment - -
      - -
    - - - - - - - - -
    - - -

    setGenre

    -
    void setGenre(<String> genre)
    - -
      Sets the genre information. A list of genre names that are valid - for ID3v1 tags is located in jala.Mp3.GENRES.
    - - - - -
      - Parameters: - -
        genre - -
      - -
    - - - - - - - - -
    - - -

    setTextContent

    -
    void setTextContent(<String> id, val)
    - -
      This method could be used to set an arbitrary field - of the underlying tag. For Id3v1 tags all information - is available through getter and setter methods, so this - implementation does nothing.
    - - - - -
      - Parameters: - -
        id - -
      - -
        value - -
      - -
    - - - - - - - - -
    - - -

    setTitle

    -
    void setTitle(<String> title)
    - -
      Sets the title information
    - - - - -
      - Parameters: - -
        title - -
      - -
    - - - - - - - - -
    - - -

    setTrackNumber

    -
    void setTrackNumber(<Number> trackNumber)
    - -
      Sets the track number information.
    - - - - -
      - Parameters: - -
        trackNumber - -
      - -
    - - - - - - - - -
    - - -

    setYear

    -
    void setYear(<Number> year)
    - -
      Sets the year information.
    - - - - -
      - Parameters: - -
        year - -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Mp3.Id3v2.html b/modules/jala/docs/jala.Mp3.Id3v2.html deleted file mode 100644 index b2b0bd1a..00000000 --- a/modules/jala/docs/jala.Mp3.Id3v2.html +++ /dev/null @@ -1,1733 +0,0 @@ - - - - - -jala.Mp3.Id3v2 - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Mp3.Id3v2

    -
    Object
    -   |
    -   +--jala.Mp3.Id3v2
    -
    - - -
    -
    - -
    class - jala.Mp3.Id3v2 - - -
    - -

    -
    This class represents an Id3v2 tag. -
    Defined in Mp3.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Mp3.Id3v2 - - (audioObj) - -
    -             - Constructs a new Id3v2 tag from an Mp3 file -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - copyFrom(tag) - -
    -            - Copies standard fields from another tag. -
    - -  String - - - - - getAlbum() - -
    -            - Returns the album information of the tag. -
    - -  String - - - - - getArtist() - -
    -            - Returns the artist information of the tag. -
    - -  jala.Mp3 - - - - - getAudio() - -
    -            - Returns the wrapper for the underlying audio file. -
    - -  String - - - - - getAuthor() - -
    -            - Returns the author information of the tag. -
    - -  String - - - - - getComment() - -
    -            - Returns the comment information of the tag. -
    - -  String - - - - - getCopyright() - -
    -            - Returns the copyright information of the tag. -
    - -  String - - - - - getGenre() - -
    -            - Returns the genre information of the tag. -
    - -  helma.util.MimePart - - - - - getImage(<String> pictureType) - -
    -            - Extracts the image from the tag -
    - -  org.farng.mp3.id3.AbstractID3v2 - - - - - getJavaObject() - -
    -            - returns the java representation of the tag, - class depends on the actual library used. -
    - -  String - - - - - getSubtitle() - -
    -            - Returns the subtitle information of the tag. -
    - -  Number - - - - - getSubtype() - -
    -            - Returns the version number of this id3v2 (values 2 to 4 for id3v2.2 to id3v2.4) -
    - -  String - - - - - getTextContent(idStr) - -
    -            - This method can be used to retrieve an arbitrary text frame - of the underlying tag. -
    - -  Number - - - - - getTextEncoding() - -
    -            - Returns the text encoding used when setting values. -
    - -  String - - - - - getTitle() - -
    -            - Returns the title information of the tag. -
    - -  String - - - - - getTrackNumber() - -
    -            - Returns the track number information of the tag. -
    - -  String - - - - - getUrl() - -
    -            - Returns the Url stored in this tag -
    - -  String - - - - - getYear() - -
    -            - Returns the year information of the tag. -
    - -  void - - - - - removeFromAudio() - -
    -            - Removes the tag from the audio file and - nulls out the wrapper. -
    - -  void - - - - - setAlbum(<String> album) - -
    -            - Sets the album information. -
    - -  void - - - - - setArtist(<String> artist) - -
    -            - Sets the artist information. -
    - -  void - - - - - setAuthor(<String> author) - -
    -            - Sets the author information in this tag -
    - -  void - - - - - setComment(<String> comment) - -
    -            - Sets the comment -
    - -  void - - - - - setCopyright(<String> copyright) - -
    -            - Sets the copyright information in this tag -
    - -  void - - - - - setGenre(<String> genre) - -
    -            - Sets the genre information. -
    - -  void - - - - - setImage(<Number> pictureType, <String> mimeType, <Array> byteArray) - -
    -            - adds an image to the file. -
    - -  void - - - - - setSubtitle(<String> title) - -
    -            - Sets the subtitle information -
    - -  String - - - - - setTextContent(idStr, val) - -
    -            - This method can be used to set an arbitrary field - of the underlying tag. -
    - -  void - - - - - setTextEncoding(<Number|String> encType) - -
    -            - sets the text encoding used when creating new frames - (the encoding type of old frames can't be changed with - JavaMusicTag) -
    - -  void - - - - - setTitle(<String> title) - -
    -            - Sets the title information -
    - -  void - - - - - setTrackNumber(<Number> trackNumber) - -
    -            - Sets the track number information. -
    - -  void - - - - - setUrl(<String> url, <String> desc) - -
    -            - Stores the Url passed as argument in this tag. -
    - -  void - - - - - setYear(<Number> year) - -
    -            - Sets the year information. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Mp3.Id3v2

    -
    jala.Mp3.Id3v2(audioObj)
    - - -
      - Constructs a new Id3v2 tag from an Mp3 file -
    - - - -
      - Parameters: - -
        mp3File - -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    copyFrom

    -
    void copyFrom(tag)
    - -
      Copies standard fields from another tag.
    - - - - -
      - Parameters: - -
        src - object with getter methods for fields album, artist, comment, title, trackNumber, genre and year. -
      - -
    - - - - - - - - -
    - - -

    getAlbum

    -
    String getAlbum()
    - -
      Returns the album information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing album name -
      -
    - - - - - -
    - - -

    getArtist

    -
    String getArtist()
    - -
      Returns the artist information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing artist name -
      -
    - - - - - -
    - - -

    getAudio

    -
    jala.Mp3 getAudio()
    - -
      Returns the wrapper for the underlying audio file.
    - - - - - - - - - - - -
    - - -

    getAuthor

    -
    String getAuthor()
    - -
      Returns the author information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing author information -
      -
    - - - - - -
    - - -

    getComment

    -
    String getComment()
    - -
      Returns the comment information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing comment -
      -
    - - - - - -
    - - -

    getCopyright

    -
    String getCopyright()
    - -
      Returns the copyright information of the tag.
    - - - - - - - -
      - Returns: -
        - The copyright information of the tag -
      -
    - - - - - -
    - - -

    getGenre

    -
    String getGenre()
    - -
      Returns the genre information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing genre name -
      -
    - - - - - -
    - - -

    getImage

    -
    helma.util.MimePart getImage(<String> pictureType)
    - -
      Extracts the image from the tag
    - - - - -
      - Parameters: - -
        pictureType - number describing picture type (default is 3, describing a front cover). -
      - -
    - - - - -
      - Returns: -
        - image as mime object -
      -
    - - - - - -
    - - -

    getJavaObject

    -
    org.farng.mp3.id3.AbstractID3v2 getJavaObject()
    - -
      returns the java representation of the tag, - class depends on the actual library used.
    - - - - - - - - - - - -
    - - -

    getSubtitle

    -
    String getSubtitle()
    - -
      Returns the subtitle information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing subtitle -
      -
    - - - - - -
    - - -

    getSubtype

    -
    Number getSubtype()
    - -
      Returns the version number of this id3v2 (values 2 to 4 for id3v2.2 to id3v2.4)
    - - - - - - - -
      - Returns: -
        - The version number of this Id3v2 tag -
      -
    - - - - - -
    - - -

    getTextContent

    -
    String getTextContent(idStr)
    - -
      This method can be used to retrieve an arbitrary text frame - of the underlying tag. For the list of valid identifiers - and their meaning see http://www.id3.org/ - The identifiers vary across the sub versions of id3v2 tags, - use getSubtype to make sure you use the correct version.
    - - - - -
      - Parameters: - -
        id - Frame identifier according to Id3v2 specification or shortcut as defined in jala.Mp3.FIELD_MAPPING. -
      - -
    - - - - -
      - Returns: -
        - String contained in the frame -
      -
    - - - - - - - -
    - - -

    getTextEncoding

    -
    Number getTextEncoding()
    - -
      Returns the text encoding used when setting values.
    - - - - - - - -
      - Returns: -
        - The text encoding -
      -
    - - - - - -
    - - -

    getTitle

    -
    String getTitle()
    - -
      Returns the title information of the tag.
    - - - - - - - -
      - Returns: -
        - string containing title -
      -
    - - - - - -
    - - -

    getTrackNumber

    -
    String getTrackNumber()
    - -
      Returns the track number information of the tag.
    - - - - - - - -
      - Returns: -
        - string representing track number -
      -
    - - - - - -
    - - -

    getUrl

    -
    String getUrl()
    - -
      Returns the Url stored in this tag
    - - - - - - - -
      - Returns: -
        - The url stored in this tag -
      -
    - - - - - -
    - - -

    getYear

    -
    String getYear()
    - -
      Returns the year information of the tag.
    - - - - - - - -
      - Returns: -
        - string representing year -
      -
    - - - - - -
    - - -

    removeFromAudio

    -
    void removeFromAudio()
    - -
      Removes the tag from the audio file and - nulls out the wrapper.
    - - - - - - - - - - - -
    - - -

    setAlbum

    -
    void setAlbum(<String> album)
    - -
      Sets the album information.
    - - - - -
      - Parameters: - -
        album - -
      - -
    - - - - - - - - -
    - - -

    setArtist

    -
    void setArtist(<String> artist)
    - -
      Sets the artist information.
    - - - - -
      - Parameters: - -
        artist - -
      - -
    - - - - - - - - -
    - - -

    setAuthor

    -
    void setAuthor(<String> author)
    - -
      Sets the author information in this tag
    - - - - -
      - Parameters: - -
        author - The author information to set -
      - -
    - - - - - - - - -
    - - -

    setComment

    -
    void setComment(<String> comment)
    - -
      Sets the comment
    - - - - -
      - Parameters: - -
        comment - -
      - -
    - - - - - - - - -
    - - -

    setCopyright

    -
    void setCopyright(<String> copyright)
    - -
      Sets the copyright information in this tag
    - - - - -
      - Parameters: - -
        copyright - The copyright information to set -
      - -
    - - - - - - - - -
    - - -

    setGenre

    -
    void setGenre(<String> genre)
    - -
      Sets the genre information. A list of genre names that are compatible - with ID3v1 tags is located in jala.Mp3.GENRES.
    - - - - -
      - Parameters: - -
        genre - -
      - -
    - - - - - - - - -
    - - -

    setImage

    -
    void setImage(<Number> pictureType, <String> mimeType, <Array> byteArray)
    - -
      adds an image to the file.
    - - - - -
      - Parameters: - -
        pictureType - number determining picture type -
      - -
        mimeType - mime type of image -
      - -
        byteArray - image binary data -
      - -
        desc - optional description -
      - -
    - - - - - - - - - - -
    - - -

    setSubtitle

    -
    void setSubtitle(<String> title)
    - -
      Sets the subtitle information
    - - - - -
      - Parameters: - -
        title - -
      - -
    - - - - - - - - -
    - - -

    setTextContent

    -
    String setTextContent(idStr, val)
    - -
      This method can be used to set an arbitrary field - of the underlying tag. For the list of valid identifiers - and their meaning see http://www.id3.org/ - The identifiers vary across the sub versions of id3v2 tags, - use getSubtype to make sure you use the correct version.
    - - - - -
      - Parameters: - -
        id - Frame identifier according to Id3v2 specification -
      - -
        value - -
      - -
    - - - - - - - - - - -
    - - -

    setTextEncoding

    -
    void setTextEncoding(<Number|String> encType)
    - -
      sets the text encoding used when creating new frames - (the encoding type of old frames can't be changed with - JavaMusicTag)
    - - - - -
      - Parameters: - -
        encType - the new encoding type as number or string -
      - -
    - - - - - - - - - - -
    - - -

    setTitle

    -
    void setTitle(<String> title)
    - -
      Sets the title information
    - - - - -
      - Parameters: - -
        title - -
      - -
    - - - - - - - - -
    - - -

    setTrackNumber

    -
    void setTrackNumber(<Number> trackNumber)
    - -
      Sets the track number information.
    - - - - -
      - Parameters: - -
        trackNumber - -
      - -
    - - - - - - - - -
    - - -

    setUrl

    -
    void setUrl(<String> url, <String> desc)
    - -
      Stores the Url passed as argument in this tag.
    - - - - -
      - Parameters: - -
        url - The url to store in this tag -
      - -
        desc - An optiona description of the Url -
      - -
    - - - - - - - - -
    - - -

    setYear

    -
    void setYear(<Number> year)
    - -
      Sets the year information.
    - - - - -
      - Parameters: - -
        year - -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Mp3.html b/modules/jala/docs/jala.Mp3.html deleted file mode 100644 index 0132fa7f..00000000 --- a/modules/jala/docs/jala.Mp3.html +++ /dev/null @@ -1,1481 +0,0 @@ - - - - - -jala.Mp3 - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Mp3

    -
    Object
    -   |
    -   +--jala.Mp3
    -
    - - -
    -
    - -
    class - jala.Mp3 - - -
    - -

    -
    This is a class representing an MP3 file - providing methods to access its metadata. - -
    Defined in Mp3.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.Mp3.Id3v1
    - <static class>jala.Mp3.Id3v2
    -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  Objectalbum -
    -           
    -  Objectartist -
    -           
    -  Objectcomment -
    -           
    -  Objectgenre -
    -           
    -  Objecttitle -
    -           
    -  ObjecttrackNumber -
    -           
    -  Objectyear -
    -           
    - <static>  <final> ArrayGENRES -
    -           Array defining valid genres in ID3v1
    - <static>  <final> ArrayMODES -
    -           Array defining mp3 modes.
    - <static>  <final> ArrayPICTURE_TYPES -
    -           Array defining valid picture types.
    - <static>  <final> ArrayTEXT_ENCODINGS -
    -           Array defining valid text encodings.
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Mp3 - - (<String|File> file) - -
    -             - Constructs a new jala.Mp3 wrapper and - parses the header data of the MP3 file. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Object - - - - - createTag(<Object> tagClass, <Object> tagObject) - -
    -            - This method creates a new tag object, attaches it - to the file (thereby replacing an existing tag of - this type) and returns it. -
    - -  jala.Mp3.Id3v1 - - - - - createV1Tag(<Object> tagObject) - -
    -            - If the file doesn't contain an ID3v1 tag, this method - creates a new ID3v1 tag object, attaches it to the file - and returns it. -
    - -  jala.Mp3.Id3v2 - - - - - createV2Tag(<Object> tagObject) - -
    -            - If the file doesn't contain an ID3v2 tag, this method - creates a new ID3v2 tag object, attaches it to the file - and returns it. -
    - -  Number - - - - - getBitRate() - -
    -            - Returns the bit rate the file was encoded with. -
    - -  String - - - - - getChannelMode() - -
    -            - Returns the channel mode the file was encoded with. -
    - -  Number - - - - - getDuration() - -
    -            - The audio length of the file in seconds at best estimate - from the file info (method returns immediately). -
    - -  helma.File - - - - - getFile() - -
    -            - Returns a helma.File reference to the wrapped file. -
    - -  Number - - - - - getFrequency() - -
    -            - Returns the frequency the file was encoded with. -
    - -  org.farng.mp3.MP3File - - - - - getJavaObject() - -
    -            - Returns the underlying java object -
    - -  Object - - - - - getMetadata() - -
    -            - Returns a plain JavaScript object containing the values of - all fields stored in either the Id3 V1 or V2 tag -
    - -  Number - - - - - getSize() - -
    -            - Returns the file size in bytes. -
    - -  Object - - - - - getTag(tagClass) - -
    -            - Returns a tag object, type is specified using the class name - in jala.Mp3.*. -
    - -  jala.Mp3.Id3v1 - - - - - getV1Tag() - -
    -            - -
    - -  jala.Mp3.Id3v2 - - - - - getV2Tag() - -
    -            - -
    - -  Object - - - - - hasTag(tagClass) - -
    -            - Tells if the file contains a certain tag, type is specified - using the class name in jala.Mp3. -
    - -  Boolean - - - - - hasV1Tag() - -
    -            - Returns true if the file contains a ID3v1 tag. -
    - -  Boolean - - - - - hasV2Tag() - -
    -            - Returns true if the file contains a ID3v2 tag. -
    - -  Boolean - - - - - isVariableBitRate() - -
    -            - Returns true if the file is (or seems to be) encoded with - variable bit rate. -
    - -  Number - - - - - parseDuration() - -
    -            - Parses the audio file to extract the precise duration of the audio. -
    - -  void - - - - - removeTag(tagClass) - -
    -            - Removes a tag from the file, type is specified using the - class name in jala.Mp3.* -
    - -  void - - - - - removeV1Tag() - -
    -            - Removes the ID3v1 tag from the file. -
    - -  Object - - - - - removeV2Tag() - -
    -            - Removes the ID3v2 tag from the file. -
    - -  Boolean - - - - - save(<String|helma.File> outFile) - -
    -            - Writes changed metadata back to the source file or to a new file. -
    - -  void - - - - - setMetadata(<Object> metadata) - -
    -            - Stores the metadata passed as argument in the ID2 v1 and v2 tags - of the wrapped MP3 file. -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    album

    -
    Object album
    -
      - - -
    -
    - - -

    artist

    -
    Object artist
    -
      - - -
    -
    - - -

    comment

    -
    Object comment
    -
      - - -
    -
    - - -

    genre

    -
    Object genre
    -
      - - -
    -
    - - -

    title

    -
    Object title
    -
      - - -
    -
    - - -

    trackNumber

    -
    Object trackNumber
    -
      - - -
    -
    - - -

    year

    -
    Object year
    -
      - - -
    -
    - - -

    GENRES

    -
    <static> <final> Array GENRES
    -
      - Array defining valid genres in ID3v1 - -
    -
    - - -

    MODES

    -
    <static> <final> Array MODES
    -
      - Array defining mp3 modes. - -
    -
    - - -

    PICTURE_TYPES

    -
    <static> <final> Array PICTURE_TYPES
    -
      - Array defining valid picture types. Note: Most image tagged files come with - one picture of picture type null! - The index position within the array defines the number used in the mp3 file. - -
    -
    - - -

    TEXT_ENCODINGS

    -
    <static> <final> Array TEXT_ENCODINGS
    -
      - Array defining valid text encodings. Note: UTF-8 is valid for v2.4 only. - UTF-16 with BOM doesn't work with Winamp etc - use UTF-16BE instead! - The index position within the array defines the number used in the mp3 file. - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Mp3

    -
    jala.Mp3(<String|File> file)
    - - -
      - Constructs a new jala.Mp3 wrapper and - parses the header data of the MP3 file. - The standard fields for a tag are accessible - as properties of the new object. -
    - - - -
      - Parameters: - -
        file - The mp3 file to be parsed, either as path string or as any kind of file object -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    createTag

    -
    Object createTag(<Object> tagClass, <Object> tagObject)
    - -
      This method creates a new tag object, attaches it - to the file (thereby replacing an existing tag of - this type) and returns it. Type is specified using - the class name in jala.Mp3.*. If a second - argument is provided, its values are copied into - the new tag.
    - - - - -
      - Parameters: - -
        tagClass - -
      - -
        tagObject - optional tag whose standard properties are copied to the new tag. -
      - -
    - - - - - - - - -
    - - -

    createV1Tag

    -
    jala.Mp3.Id3v1 createV1Tag(<Object> tagObject)
    - -
      If the file doesn't contain an ID3v1 tag, this method - creates a new ID3v1 tag object, attaches it to the file - and returns it. If a second argument is provided, its - values are copied into the new tag.
    - - - - -
      - Parameters: - -
        tagObject - optional tag whose standard properties are copied to the new tag. -
      - -
    - - - - - - - - -
    - - -

    createV2Tag

    -
    jala.Mp3.Id3v2 createV2Tag(<Object> tagObject)
    - -
      If the file doesn't contain an ID3v2 tag, this method - creates a new ID3v2 tag object, attaches it to the file - and returns it. If a second argument is provided, its - values are copied into the new tag.
    - - - - -
      - Parameters: - -
        tagObject - optional tag whose standard properties are copied to the new tag. -
      - -
    - - - - - - - - -
    - - -

    getBitRate

    -
    Number getBitRate()
    - -
      Returns the bit rate the file was encoded with.
    - - - - - - - - - - - -
    - - -

    getChannelMode

    -
    String getChannelMode()
    - -
      Returns the channel mode the file was encoded with.
    - - - - - - - - - - - -
    - - -

    getDuration

    -
    Number getDuration()
    - -
      The audio length of the file in seconds at best estimate - from the file info (method returns immediately). - This method calculates based on the bitrate. Therefore it - has to produce wrong results for files encoded with variable - bitrate (vbr). For these files parseDuration() can be used.
    - - - - - - - -
      - Returns: -
        - length in seconds -
      -
    - - - - - - - -
    - - -

    getFile

    -
    helma.File getFile()
    - -
      Returns a helma.File reference to the wrapped file.
    - - - - - - - - - - - -
    - - -

    getFrequency

    -
    Number getFrequency()
    - -
      Returns the frequency the file was encoded with.
    - - - - - - - - - - - -
    - - -

    getJavaObject

    -
    org.farng.mp3.MP3File getJavaObject()
    - -
      Returns the underlying java object
    - - - - - - - - - - - -
    - - -

    getMetadata

    -
    Object getMetadata()
    - -
      Returns a plain JavaScript object containing the values of - all fields stored in either the Id3 V1 or V2 tag
    - - - - - - - -
      - Returns: -
        - An object containing the values of all fields -
      -
    - - - - - -
    - - -

    getSize

    -
    Number getSize()
    - -
      Returns the file size in bytes.
    - - - - - - - - - - - -
    - - -

    getTag

    -
    Object getTag(tagClass)
    - -
      Returns a tag object, type is specified using the class name - in jala.Mp3.*.
    - - - - - - - - - - - -
    - - -

    getV1Tag

    -
    jala.Mp3.Id3v1 getV1Tag()
    - - - - - - - - - - - -
    - - -

    getV2Tag

    -
    jala.Mp3.Id3v2 getV2Tag()
    - - - - - - - - - - - -
    - - -

    hasTag

    -
    Object hasTag(tagClass)
    - -
      Tells if the file contains a certain tag, type is specified - using the class name in jala.Mp3.
    - - - - - - - - - - - -
    - - -

    hasV1Tag

    -
    Boolean hasV1Tag()
    - -
      Returns true if the file contains a ID3v1 tag.
    - - - - - - - - - - - -
    - - -

    hasV2Tag

    -
    Boolean hasV2Tag()
    - -
      Returns true if the file contains a ID3v2 tag.
    - - - - - - - - - - - -
    - - -

    isVariableBitRate

    -
    Boolean isVariableBitRate()
    - -
      Returns true if the file is (or seems to be) encoded with - variable bit rate. FIXME: The current implementation returned - true for all test files.
    - - - - - - - - - - - -
    - - -

    parseDuration

    -
    Number parseDuration()
    - -
      Parses the audio file to extract the precise duration of the audio. - The upside is that it works fine for files with variable bitrates. - The downside is that this action may take a few seconds depending on - the size of the audio file.
    - - - - - - - -
      - Returns: -
        - length in seconds -
      -
    - - - - - - - -
    - - -

    removeTag

    -
    void removeTag(tagClass)
    - -
      Removes a tag from the file, type is specified using the - class name in jala.Mp3.*
    - - - - - - - - - - - -
    - - -

    removeV1Tag

    -
    void removeV1Tag()
    - -
      Removes the ID3v1 tag from the file.
    - - - - - - - - - - - -
    - - -

    removeV2Tag

    -
    Object removeV2Tag()
    - -
      Removes the ID3v2 tag from the file.
    - - - - - - - - - - - -
    - - -

    save

    -
    Boolean save(<String|helma.File> outFile)
    - -
      Writes changed metadata back to the source file or to a new file.
    - - - - -
      - Parameters: - -
        outFile - (optional) save the modified file to a different file -
      - -
    - - - - -
      - Returns: -
        - true on success, false if the file contains tags that cannot be saved (Id3v2_2). -
      -
    - - - - - -
    - - -

    setMetadata

    -
    void setMetadata(<Object> metadata)
    - -
      Stores the metadata passed as argument in the ID2 v1 and v2 tags - of the wrapped MP3 file.
    - - - - -
      - Parameters: - -
        metadata - An object containing the fields to set and their values. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.PodcastWriter.html b/modules/jala/docs/jala.PodcastWriter.html deleted file mode 100644 index e0c9f295..00000000 --- a/modules/jala/docs/jala.PodcastWriter.html +++ /dev/null @@ -1,416 +0,0 @@ - - - - - -jala.PodcastWriter - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.PodcastWriter

    -
    Object
    -   |
    -   +--jala.XmlWriter
    -         |
    -         +--jala.Rss20Writer
    -               |
    -               +--jala.PodcastWriter
    -
    - - -
    -
    - -
    class - jala.PodcastWriter - -
    extends jala.Rss20Writer - - -
    - -

    -
    Class to create, modify and render standard-compliant - RSS 2.0 feeds including support for Apple's Podcast specification. -
    Defined in PodcastWriter.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    - <static>  <final> StringXMLHEADER -
    -           A typical XML header as default.
    -   - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.PodcastWriter - - (<String> header) - -
    -             - -
    - - - -  - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - addItunesCategory(<String> name, <String> subName, <jala.XmlWriter.XmlElement> parent) - -
    -            - Add an iTunes Podcast category. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.Rss20Writer
    - -getRoot, extendChannel, getChannel, setChannel, extendItem, createItem, addItem, addCategory, setImage, setTextInput -
    -  - -  - - - - - - - -
    Methods inherited from class jala.XmlWriter
    - -createElement, extend, addNamespace, write, toString, clone -
    -  - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    XMLHEADER

    -
    <static> <final> String XMLHEADER
    - -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.PodcastWriter

    -
    jala.PodcastWriter(<String> header)
    - - - - -
      - Parameters: - -
        header - Optional XML header. -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    addItunesCategory

    -
    void addItunesCategory(<String> name, <String> subName, <jala.XmlWriter.XmlElement> parent)
    - -
      Add an iTunes Podcast category.
    - - - - -
      - Parameters: - -
        name - The category's name. -
      - -
        subName - The (optional) sub-category's name. -
      - -
        parent - Optional parent element to add the category to. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.RemoteContent.html b/modules/jala/docs/jala.RemoteContent.html deleted file mode 100644 index 71fd9a62..00000000 --- a/modules/jala/docs/jala.RemoteContent.html +++ /dev/null @@ -1,892 +0,0 @@ - - - - - -jala.RemoteContent - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.RemoteContent

    -
    Object
    -   |
    -   +--helma.Http
    -         |
    -         +--jala.RemoteContent
    -
    - - -
    -
    - -
    class - jala.RemoteContent - -
    extends helma.Http - - -
    - -

    -
    API to define, fetch and update content - from a remote site. -
    Defined in RemoteContent.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    - <static>  <final> FileCACHEDIR -
    -           The default cache directory.
    - <static>  <final> intHTTP -
    -           A constant representing the HTTP retrieval method.
    - <static>  <final> StringSUFFIX -
    -           The default name of the cache directory.
    - <static>  <final> intXMLRPC -
    -           A constant representing the XML-RPC retrieval method.
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.RemoteContent - - (<String> url, <Integer> method, <File> storage) - -
    -             - Construct a new remote content handler. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - clear() - -
    -            - Flushes (empties) the cached remote content. -
    - -  Object - - - - - get(<String> key) - -
    -            - Get an arbitrary property of the remote content. -
    - -  Array - - - - - getKeys() - -
    -            - Get all available property names. -
    - -  Boolean - - - - - needsUpdate() - -
    -            - Tests whether the remote content needs to be updated. -
    - -  void - - - - - setInterval(<Number> interval) - -
    -            - Set the interval the remote content's - cache is bound to be updated. -
    - -  String - - - - - toString() - -
    -            - Get a string representation of the remote content. -
    - -  String - - - - - update() - -
    -            - Get the updated and cached remote content. -
    - -  Object - - - - - valueOf() - -
    -            - Get the value of the remote content. -
    - - <static> void - - - - - exec() - -
    -            - Apply a custom method on all remote content in a file-based cache. -
    - - <static> void - - - - - flush(<File> cache) - -
    -            - Remove all remote content from a file-based cache. -
    - - <static> void - - - - - forEach(<Function> callback, <File> cache) - -
    -            - Apply a custom method on all remote content in a file-based cache. -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    CACHEDIR

    -
    <static> <final> File CACHEDIR
    -
      - The default cache directory. - -
    -
    - - -

    HTTP

    -
    <static> <final> int HTTP
    - -
    - - -

    SUFFIX

    -
    <static> <final> String SUFFIX
    - -
    - - -

    XMLRPC

    -
    <static> <final> int XMLRPC
    - -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.RemoteContent

    -
    jala.RemoteContent(<String> url, <Integer> method, <File> storage)
    - - -
      - Construct a new remote content handler. -
    - - - -
      - Parameters: - -
        url - The URL string of the remote site. -
      - -
        method - The method to retrieve the remote content. -
      - -
        storage - The cache directory. -
      - - -
    - - - - -
      - Returns: -
        - A new remote content handler. -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    clear

    -
    void clear()
    - -
      Flushes (empties) the cached remote content.
    - - - - - - - - - - - -
    - - -

    get

    -
    Object get(<String> key)
    - -
      Get an arbitrary property of the remote content.
    - - - - -
      - Parameters: - -
        key - The name of the property. -
      - -
    - - - - -
      - Returns: -
        - The value of the property. -
      -
    - - - - - -
    - - -

    getKeys

    -
    Array getKeys()
    - -
      Get all available property names.
    - - - - - - - -
      - Returns: -
        - The list of property names. -
      -
    - - - - - -
    - - -

    needsUpdate

    -
    Boolean needsUpdate()
    - -
      Tests whether the remote content needs to be updated.
    - - - - - - - -
      - Returns: -
        - True if the remote content needs to be updated. -
      -
    - - - - - -
    - - -

    setInterval

    -
    void setInterval(<Number> interval)
    - -
      Set the interval the remote content's - cache is bound to be updated.
    - - - - -
      - Parameters: - -
        interval - The interval value in milliseconds. -
      - -
    - - - - - - - - -
    - - -

    toString

    -
    String toString()
    - -
      Get a string representation of the remote content.
    - - - - - - - -
      - Returns: -
        - The remote content as string. -
      -
    - - - - - -
    - - -

    update

    -
    String update()
    - -
      Get the updated and cached remote content.
    - - - - - - - -
      - Returns: -
        - The content as retrieved from the remote site. -
      -
    - - - - - -
    - - -

    valueOf

    -
    Object valueOf()
    - -
      Get the value of the remote content.
    - - - - - - - -
      - Returns: -
        - The remote content including response header data. -
      -
    - - - - - -
    - - -

    exec

    -
    <static> void exec()
    - -
      Apply a custom method on all remote content in a file-based cache.
    - - - - -
      - Parameters: - -
        callback - The callback method to be executed for each remote content file. -
      - -
        cache - An optional target directory. -
      - -
    - - - - - - - - - - -
    - - -

    flush

    -
    <static> void flush(<File> cache)
    - -
      Remove all remote content from a file-based cache.
    - - - - -
      - Parameters: - -
        cache - An optional target directory. -
      - -
    - - - - - - - - -
    - - -

    forEach

    -
    <static> void forEach(<Function> callback, <File> cache)
    - -
      Apply a custom method on all remote content in a file-based cache.
    - - - - -
      - Parameters: - -
        callback - The callback method to be executed for each remote content file. -
      - -
        cache - An optional target directory. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Rss20Writer.html b/modules/jala/docs/jala.Rss20Writer.html deleted file mode 100644 index 5ceca0e8..00000000 --- a/modules/jala/docs/jala.Rss20Writer.html +++ /dev/null @@ -1,760 +0,0 @@ - - - - - -jala.Rss20Writer - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Rss20Writer

    -
    Object
    -   |
    -   +--jala.XmlWriter
    -         |
    -         +--jala.Rss20Writer
    -
    - -
    -
    - Direct Known Subclasses: -
    - jala.PodcastWriter -
    -
    - - -
    -
    - -
    class - jala.Rss20Writer - -
    extends jala.XmlWriter - - -
    - -

    -
    Class to create, modify and render standard-compliant - RSS 2.0 feeds. -
    Defined in Rss20Writer.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Rss20Writer - - (<String> header) - -
    -             - -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - addCategory(<String> name, <String> domain, <jala.XmlWriter.XmlElement> parent) - -
    -            - Add a category element to an arbitrary element. -
    - -  void - - - - - addItem(<jala.XmlWriter.XmlElement> item) - -
    -            - Add an item element to the channel element. -
    - -  jala.XmlWriter.XmlElement - - - - - createItem(<Object> data) - -
    -            - Get a new and innocent item element. -
    - -  void - - - - - extendChannel(<Array> ext) - -
    -            - Add child elements to the channel template. -
    - -  void - - - - - extendItem(<Array> ext) - -
    -            - Add child elements to the item template. -
    - -  jala.XmlWriter.XmlElement - - - - - getChannel() - -
    -            - Get the writer's channel element. -
    - -  jala.XmlWriter.XmlElement - - - - - getRoot() - -
    -            - Get the writer's root element. -
    - -  jala.XmlWriter.XmlElement - - - - - setChannel(<Object> data) - -
    -            - Populate the channel element with data. -
    - -  void - - - - - setImage(<Object> data) - -
    -            - Populate the image element with data. -
    - -  void - - - - - setTextInput(<Object> data) - -
    -            - Populate the textInput element with data. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.XmlWriter
    - -createElement, extend, addNamespace, write, toString, clone -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Rss20Writer

    -
    jala.Rss20Writer(<String> header)
    - - - - -
      - Parameters: - -
        header - Optional XML header. -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    addCategory

    -
    void addCategory(<String> name, <String> domain, <jala.XmlWriter.XmlElement> parent)
    - -
      Add a category element to an arbitrary element.
    - - - - -
      - Parameters: - -
        name - The name of the category. -
      - -
        domain - The domain of the category. -
      - -
        parent - The optional parent element. -
      - -
    - - - - - - - - -
    - - -

    addItem

    -
    void addItem(<jala.XmlWriter.XmlElement> item)
    - -
      Add an item element to the channel element.
    - - - - -
      - Parameters: - -
        item - The item element to add. -
      - -
    - - - - - - - - -
    - - -

    createItem

    -
    jala.XmlWriter.XmlElement createItem(<Object> data)
    - -
      Get a new and innocent item element.
    - - - - -
      - Parameters: - -
        data - An XmlWriter-compliant object structure. -
      - -
    - - - - -
      - Returns: -
        - A new and innocent item element. -
      -
    - - - - - -
    - - -

    extendChannel

    -
    void extendChannel(<Array> ext)
    - -
      Add child elements to the channel template.
    - - - - -
      - Parameters: - -
        ext - List of additional child elements. -
      - -
    - - - - - - - - -
    - - -

    extendItem

    -
    void extendItem(<Array> ext)
    - -
      Add child elements to the item template.
    - - - - -
      - Parameters: - -
        ext - List of additional child elements. -
      - -
    - - - - - - - - -
    - - -

    getChannel

    -
    jala.XmlWriter.XmlElement getChannel()
    - -
      Get the writer's channel element.
    - - - - - - - -
      - Returns: -
        - The writer's channel element. -
      -
    - - - - - -
    - - -

    getRoot

    -
    jala.XmlWriter.XmlElement getRoot()
    - -
      Get the writer's root element.
    - - - - - - - -
      - Returns: -
        - The writer's root element. -
      -
    - - - - - -
    - - -

    setChannel

    -
    jala.XmlWriter.XmlElement setChannel(<Object> data)
    - -
      Populate the channel element with data.
    - - - - -
      - Parameters: - -
        data - An XmlWriter-compliant object structure. -
      - -
    - - - - -
      - Returns: -
        - The populated channel element. -
      -
    - - - - - -
    - - -

    setImage

    -
    void setImage(<Object> data)
    - -
      Populate the image element with data.
    - - - - -
      - Parameters: - -
        data - An XmlWriter-compliant object structure. -
      - -
    - - - - - - - - -
    - - -

    setTextInput

    -
    void setTextInput(<Object> data)
    - -
      Populate the textInput element with data.
    - - - - -
      - Parameters: - -
        data - An XmlWriter-compliant object structure. -
      - -
    - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.Utilities.html b/modules/jala/docs/jala.Utilities.html deleted file mode 100644 index cd58c6e3..00000000 --- a/modules/jala/docs/jala.Utilities.html +++ /dev/null @@ -1,586 +0,0 @@ - - - - - -jala.Utilities - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.Utilities

    -
    Object
    -   |
    -   +--jala.Utilities
    -
    - - -
    -
    - -
    class - jala.Utilities - - -
    - -

    -
    This class contains various convenience methods - which do not fit in any other class. -
    Defined in Utilities.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    - <static>  <final> NumberVALUE_ADDED -
    -           Static field indicating ad added object property.
    - <static>  <final> NumberVALUE_MODIFIED -
    -           Static field indicating a modified object property.
    - <static>  <final> NumberVALUE_REMOVED -
    -           Static field indicating a removed object property.
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Utilities - - () - -
    -             - Construct a utility object. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - createPassword(<Number> len, <Number> level) - -
    -            - Creates a random password with different levels of security. -
    - -  Object - - - - - diffObjects(<Object> obj1, <Object> obj2) - -
    -            - Returns an array containing the properties that are - added, removed or modified in one object compared to another. -
    - -  Object - - - - - patchObject(<Object> obj, <Object> diff) - -
    -            - Patches an object with a "diff" object created by the - diffObjects() method. -
    - -  String - - - - - toString() - -
    -            - Return a string representation of the utitility object. -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    VALUE_ADDED

    -
    <static> <final> Number VALUE_ADDED
    - -
    - - -

    VALUE_MODIFIED

    -
    <static> <final> Number VALUE_MODIFIED
    - -
    - - -

    VALUE_REMOVED

    -
    <static> <final> Number VALUE_REMOVED
    - -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Utilities

    -
    jala.Utilities()
    - - -
      - Construct a utility object. -
    - - - - - - - - -
      - Returns: -
        - A new utitilty object. -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    createPassword

    -
    String createPassword(<Number> len, <Number> level)
    - -
      Creates a random password with different levels of security.
    - - - - -
      - Parameters: - -
        len - The length of the password (default: 8) -
      - -
        level - The security level
        • 0 - containing only vowels or consonants (default)
        • 1 - throws in a number at random position
        • 2 - throws in a number and a special character at random position
        -
      - -
    - - - - -
      - Returns: -
        - The resulting password -
      -
    - - - - - -
    - - -

    diffObjects

    -
    Object diffObjects(<Object> obj1, <Object> obj2)
    - -
      Returns an array containing the properties that are - added, removed or modified in one object compared to another.
    - - - - -
      - Parameters: - -
        obj1 - The first of two objects which should be compared -
      - -
        obj2 - The second of two objects which should be compared -
      - -
    - - - - -
      - Returns: -
        - An Object containing all properties that are added, removed or modified in the second object compared to the first. Each property contains a status field with an integer value which can be checked against the static jala.Utility fields VALUE_ADDED, VALUE_MODIFIED and VALUE_REMOVED. -
      -
    - - - - - -
    - - -

    patchObject

    -
    Object patchObject(<Object> obj, <Object> diff)
    - -
      Patches an object with a "diff" object created by the - diffObjects() method. - Please mind that this method is recursive, it descends - along the "diff" object structure.
    - - - - -
      - Parameters: - -
        obj - The Object the diff should be applied to -
      - - - -
    - - - - -
      - Returns: -
        - The patched Object with all differences applied -
      -
    - - - - - -
    - - -

    toString

    -
    String toString()
    - -
      Return a string representation of the utitility object.
    - - - - - - - -
      - Returns: -
        - [jala.Utilities Object] -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.XmlRpcRequest.html b/modules/jala/docs/jala.XmlRpcRequest.html deleted file mode 100644 index c52e8de2..00000000 --- a/modules/jala/docs/jala.XmlRpcRequest.html +++ /dev/null @@ -1,1235 +0,0 @@ - - - - - -jala.XmlRpcRequest - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.XmlRpcRequest

    -
    Object
    -   |
    -   +--jala.XmlRpcRequest
    -
    - - -
    -
    - -
    class - jala.XmlRpcRequest - - -
    - -

    -
    Instances of this class provide the necessary functionality - for issueing XmlRpc requests to a remote service. -
    Defined in XmlRpcRequest.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.XmlRpcRequest - - (<String> url, <String> methodName) - -
    -             - A constructor for XmlRpc request objects -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Boolean - - - - - debug() - -
    -            - Returns true if debug is enabled for this request, false otherwise -
    - -  Object - - - - - execute() - -
    -            - Calling this method executes the remote method using - the arguments specified. -
    - -  String - - - - - getCredentials() - -
    -            - Returns the credentials of this request -
    - -  String - - - - - getInputEncoding() - -
    -            - Returns the input encoding -
    - -  String - - - - - getMethodName() - -
    -            - Returns the name of the remote function to call -
    - -  String - - - - - getOutputEncoding() - -
    -            - Returns the output encoding -
    - -  java.net.Proxy - - - - - getProxy() - -
    -            - Returns the proxy object. -
    - -  Number - - - - - getReadTimeout() - -
    -            - Returns the socket timeout of this request -
    - -  Number - - - - - getTimeout() - -
    -            - Returns the connection timeout of this request -
    - -  java.net.URL - - - - - getUrl() - -
    -            - Returns the URL of this request -
    - -  void - - - - - setCredentials(<String> username, <String> password) - -
    -            - Sets the credentials for basic http authentication to - use with this request. -
    - -  void - - - - - setDebug(<Boolean> flag) - -
    -            - Enables or disables the debug mode. -
    - -  void - - - - - setEncoding(<String> enc) - -
    -            - Sets both input and output encoding to the - specified encoding string -
    - -  void - - - - - setInputEncoding(<String> enc) - -
    -            - Sets the input encoding to the specified encoding string -
    - -  void - - - - - setOutputEncoding(<String> enc) - -
    -            - Sets the output encoding to the specified encoding string -
    - -  void - - - - - setProxy(<String> proxyString) - -
    -            - Sets the proxy host and port. -
    - -  void - - - - - setReadTimeout(<Number> millis) - -
    -            - Sets the socket timeout to the specified milliseconds. -
    - -  void - - - - - setTimeout(<Number> millis) - -
    -            - Sets the connection timeout to the specified milliseconds. -
    - - <static> String - - - - - argumentsToString(<Object> args) - -
    -            - Helper method to format an arguments array into - a string useable for debugging output. -
    - - <static> java.lang.Object - - - - - convertArgument(<Object> obj) - -
    -            - Helper method for converting a Javascript object into - its appropriate Java object. -
    - - <static> Object - - - - - convertResult(<java.lang.Object> obj) - -
    -            - Converts a Java object into its appropriate Javascript representation. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.XmlRpcRequest

    -
    jala.XmlRpcRequest(<String> url, <String> methodName)
    - - -
      - A constructor for XmlRpc request objects -
    - - - -
      - Parameters: - -
        url - The url of the XmlRpc entry point -
      - -
        methodName - The name of the method to call -
      - - -
    - - - - -
      - Returns: -
        - A newly created jala.XmlRpcRequest instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    debug

    -
    Boolean debug()
    - -
      Returns true if debug is enabled for this request, false otherwise
    - - - - - - - -
      - Returns: -
        - True if debugging is enabled, false otherwise -
      -
    - - - - - -
    - - -

    execute

    -
    Object execute()
    - -
      Calling this method executes the remote method using - the arguments specified.
    - - - - - - - -
      - Returns: -
        - The result of this XmlRpc request -
      -
    - - - - - -
    - - -

    getCredentials

    -
    String getCredentials()
    - -
      Returns the credentials of this request
    - - - - - - - -
      - Returns: -
        - The base46 encoded credentials of this request -
      -
    - - - - - -
    - - -

    getInputEncoding

    -
    String getInputEncoding()
    - -
      Returns the input encoding
    - - - - - - - -
      - Returns: -
        - The input encoding used by this request -
      -
    - - - - - -
    - - -

    getMethodName

    -
    String getMethodName()
    - -
      Returns the name of the remote function to call
    - - - - - - - -
      - Returns: -
        - The name of the remote function -
      -
    - - - - - -
    - - -

    getOutputEncoding

    -
    String getOutputEncoding()
    - -
      Returns the output encoding
    - - - - - - - -
      - Returns: -
        - The output encoding used by this request -
      -
    - - - - - -
    - - -

    getProxy

    -
    java.net.Proxy getProxy()
    - -
      Returns the proxy object. This method will only return - a value if using a java runtime > 1.5
    - - - - - - - -
      - Returns: -
        - The proxy to use for this request -
      -
    - - - - - - - -
    - - -

    getReadTimeout

    -
    Number getReadTimeout()
    - -
      Returns the socket timeout of this request
    - - - - - - - -
      - Returns: -
        - The socket timeout value in milliseconds -
      -
    - - - - - -
    - - -

    getTimeout

    -
    Number getTimeout()
    - -
      Returns the connection timeout of this request
    - - - - - - - -
      - Returns: -
        - The connection timeout value in milliseconds -
      -
    - - - - - -
    - - -

    getUrl

    -
    java.net.URL getUrl()
    - -
      Returns the URL of this request
    - - - - - - - -
      - Returns: -
        - The URL of this request -
      -
    - - - - - -
    - - -

    setCredentials

    -
    void setCredentials(<String> username, <String> password)
    - -
      Sets the credentials for basic http authentication to - use with this request.
    - - - - -
      - Parameters: - -
        username - The username -
      - -
        password - The password -
      - -
    - - - - - - - - -
    - - -

    setDebug

    -
    void setDebug(<Boolean> flag)
    - -
      Enables or disables the debug mode. If enabled the xml source - of both request and response is included in the result properties - 'requestXml' and 'responseXml'
    - - - - -
      - Parameters: - -
        flag - True or false. -
      - -
    - - - - - - - - -
    - - -

    setEncoding

    -
    void setEncoding(<String> enc)
    - -
      Sets both input and output encoding to the - specified encoding string
    - - - - -
      - Parameters: - -
        enc - The encoding to use for both input and output. This must be a valid java encoding string. -
      - -
    - - - - - - - - -
    - - -

    setInputEncoding

    -
    void setInputEncoding(<String> enc)
    - -
      Sets the input encoding to the specified encoding string
    - - - - -
      - Parameters: - -
        enc - The encoding to use for input. This must be a valid java encoding string. -
      - -
    - - - - - - - - -
    - - -

    setOutputEncoding

    -
    void setOutputEncoding(<String> enc)
    - -
      Sets the output encoding to the specified encoding string
    - - - - -
      - Parameters: - -
        enc - The encoding to use for output. This must be a valid java encoding string. -
      - -
    - - - - - - - - -
    - - -

    setProxy

    -
    void setProxy(<String> proxyString)
    - -
      Sets the proxy host and port. For Java runtimes < 1.5 this method - sets the appropriate system properties (so this has an effect on - all requests based on java.net.URL), for all others the proxy - is only set for this request.
    - - - - -
      - Parameters: - -
        proxyString - The proxy string in the form 'fqdn:port' (eg. my.proxy.com:3128) -
      - -
    - - - - - - - - -
    - - -

    setReadTimeout

    -
    void setReadTimeout(<Number> millis)
    - -
      Sets the socket timeout to the specified milliseconds.
    - - - - -
      - Parameters: - -
        millis - The timeout to use as socket timeout -
      - -
    - - - - - - - - -
    - - -

    setTimeout

    -
    void setTimeout(<Number> millis)
    - -
      Sets the connection timeout to the specified milliseconds.
    - - - - -
      - Parameters: - -
        millis - The timeout to use as connection timeout -
      - -
    - - - - - - - - -
    - - -

    argumentsToString

    -
    <static> String argumentsToString(<Object> args)
    - -
      Helper method to format an arguments array into - a string useable for debugging output.
    - - - - -
      - Parameters: - -
        args - An arguments array -
      - -
    - - - - -
      - Returns: -
        - The arguments array formatted as string -
      -
    - - - - - -
    - - -

    convertArgument

    -
    <static> java.lang.Object convertArgument(<Object> obj)
    - -
      Helper method for converting a Javascript object into - its appropriate Java object.
    - - - - -
      - Parameters: - -
        obj - The Javascript object to convert -
      - -
    - - - - -
      - Returns: -
        - The appropriate Java representation of the object -
      -
    - - - - - -
    - - -

    convertResult

    -
    <static> Object convertResult(<java.lang.Object> obj)
    - -
      Converts a Java object into its appropriate Javascript representation.
    - - - - -
      - Parameters: - -
        obj - The Java object to convert -
      - -
    - - - - -
      - Returns: -
        - The appropriate Javascript representation of the Java object -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.XmlWriter.html b/modules/jala/docs/jala.XmlWriter.html deleted file mode 100644 index 7ce2fdda..00000000 --- a/modules/jala/docs/jala.XmlWriter.html +++ /dev/null @@ -1,633 +0,0 @@ - - - - - -jala.XmlWriter - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.XmlWriter

    -
    Object
    -   |
    -   +--jala.XmlWriter
    -
    - -
    -
    - Direct Known Subclasses: -
    - jala.Rss20Writer -
    -
    - - -
    -
    - -
    class - jala.XmlWriter - - -
    - -

    -
    This class defines a generic interface to write - arbitrary and validating XML source code. This is done - by first applying data objects onto template objects, - both in a specified format. Then, the resulting object - tree is transformed into XML. Moreover, template objects - can be extended with other template objects to provide - full flexibility in inheriting subclasses. -
    Defined in XmlWriter.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.XmlWriter - - (<String> header) - -
    -             - Construct a new XML writer. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  jala.XmlWriter.XmlElement - - - - - addNamespace(<String> name, <String> url) - -
    -            - Add a namespace to this writer. -
    - -  jala.XmlWriter - - - - - clone(obj) - -
    -            - Clone this XML writer. -
    - -  jala.XmlWriter.XmlElement - - - - - createElement(<Object> data) - -
    -            - Get a newly created XML element. -
    - -  jala.XmlWriter - - - - - extend(<Object> template, <Object> ext) - -
    -            - Extend a template object. -
    - -  jala.XmlWriter.XmlElement - - - - - getRoot() - -
    -            - Get the root XML element of this writer. -
    - -  String - - - - - toString() - -
    -            - Get the XML output as string. -
    - -  void - - - - - write() - -
    -            - Write the XML to the response buffer. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.XmlWriter

    -
    jala.XmlWriter(<String> header)
    - - -
      - Construct a new XML writer. -
    - - - -
      - Parameters: - -
        header - An optional XML header. -
      - - -
    - - - - -
      - Returns: -
        - A new XML writer. -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    addNamespace

    -
    jala.XmlWriter.XmlElement addNamespace(<String> name, <String> url)
    - -
      Add a namespace to this writer.
    - - - - -
      - Parameters: - -
        name - The name of the namespace. -
      - -
        url - The URL string of the namespace. -
      - -
    - - - - -
      - Returns: -
        - The XML root element. -
      -
    - - - - - -
    - - -

    clone

    -
    jala.XmlWriter clone(obj)
    - -
      Clone this XML writer.
    - - - - -
      - Parameters: - -
        The - clone templare. -
      - -
    - - - - -
      - Returns: -
        - The cloned XML writer. -
      -
    - - - - - -
    - - -

    createElement

    -
    jala.XmlWriter.XmlElement createElement(<Object> data)
    - -
      Get a newly created XML element.
    - - - - -
      - Parameters: - -
        data - The XML data as object tree. -
      - -
    - - - - -
      - Returns: -
        - The resulting XML element. -
      -
    - - - - - -
    - - -

    extend

    -
    jala.XmlWriter extend(<Object> template, <Object> ext)
    - -
      Extend a template object.
    - - - - -
      - Parameters: - -
        template - The template object. -
      - -
        ext - The extension object. -
      - -
    - - - - -
      - Returns: -
        - The XML writer. -
      -
    - - - - - -
    - - -

    getRoot

    -
    jala.XmlWriter.XmlElement getRoot()
    - -
      Get the root XML element of this writer.
    - - - - - - - -
      - Returns: -
        - The root XML element. -
      -
    - - - - - -
    - - -

    toString

    -
    String toString()
    - -
      Get the XML output as string.
    - - - - - - - -
      - Returns: -
        - The XML output. -
      -
    - - - - - -
    - - -

    write

    -
    void write()
    - -
      Write the XML to the response buffer.
    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.db.DataType.html b/modules/jala/docs/jala.db.DataType.html deleted file mode 100644 index e319ed22..00000000 --- a/modules/jala/docs/jala.db.DataType.html +++ /dev/null @@ -1,475 +0,0 @@ - - - - - -jala.db.DataType - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.0 - -
    - -
    - - -

    Class jala.db.DataType

    -
    Object
    -   |
    -   +--jala.db.DataType
    -
    - - -
    -
    - -
    class - jala.db.DataType - - -
    - -

    -
    Instances of this class represent a data type. Each instance - contains the code number as defined in java.sql.Types, the name of - the data type as defined in java.sql.Types and optional creation parameters - allowed for this data type. -
    Defined in Database.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.db.DataType - - (<Number> type, <String> typeName, <String> params) - -
    -             - Returns a newly created DataType instance. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  String - - - - - getParams() - -
    -            - Returns the creation parameter string of this data type -
    - -  Number - - - - - getType() - -
    -            - Returns the sql type code number as defined in java.sql.Types -
    - -  String - - - - - getTypeName() - -
    -            - Returns the type name of this data type, which can be - used in sql queries. -
    - -  Boolean - - - - - needsQuotes() - -
    -            - Returns true if values for this data type should be surrounded - by (single) quotes. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.db.DataType

    -
    jala.db.DataType(<Number> type, <String> typeName, <String> params)
    - - -
      - Returns a newly created DataType instance. -
    - - - -
      - Parameters: - -
        type - The sql code number of this data type -
      - -
        typeName - The type name of this data type, as used within sql statements -
      - -
        params - Optional creation parameters allowed for this data type. -
      - - -
    - - - - -
      - Returns: -
        - A newly created instance of DataType. -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    getParams

    -
    String getParams()
    - -
      Returns the creation parameter string of this data type
    - - - - - - - -
      - Returns: -
        - The creation parameter string of this data type -
      -
    - - - - - -
    - - -

    getType

    -
    Number getType()
    - -
      Returns the sql type code number as defined in java.sql.Types
    - - - - - - - -
      - Returns: -
        - The sql type code number of this data type -
      -
    - - - - - -
    - - -

    getTypeName

    -
    String getTypeName()
    - -
      Returns the type name of this data type, which can be - used in sql queries.
    - - - - - - - -
      - Returns: -
        - The type name of this data type -
      -
    - - - - - -
    - - -

    needsQuotes

    -
    Boolean needsQuotes()
    - -
      Returns true if values for this data type should be surrounded - by (single) quotes.
    - - - - - - - -
      - Returns: -
        - True if values for this data type should be surrounded by quotes, false if not -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.0 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Wed Apr 4 17:06:49 2007
    - - diff --git a/modules/jala/docs/jala.db.FileDatabase.html b/modules/jala/docs/jala.db.FileDatabase.html deleted file mode 100644 index bde70a26..00000000 --- a/modules/jala/docs/jala.db.FileDatabase.html +++ /dev/null @@ -1,637 +0,0 @@ - - - - - -jala.db.FileDatabase - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.db.FileDatabase

    -
    Object
    -   |
    -   +--jala.db.RamDatabase
    -         |
    -         +--jala.db.FileDatabase
    -
    - - -
    -
    - -
    class - jala.db.FileDatabase - -
    extends jala.db.RamDatabase - - -
    - -

    -
    Instances of this class represent a file based in-process database -
    Important: You need the h2.jar in directory "lib/ext" - of your helma installation for this library to work, which you can get - at http://www.h2database.com/. -
    Defined in Database.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.db.FileDatabase - - (<String> name, <helma.File> directory, <String> username, <String> password) - -
    -             - Returns a newly created instance of FileDatabase. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Boolean - - - - - backup(<helma.File> file) - -
    -            - Creates a backup of this database, using the file passed as argument. -
    - -  helma.File - - - - - getDirectory() - -
    -            - Returns the directory where the database files are stored. -
    - -  String - - - - - getName() - -
    -            - Returns the name of the database. -
    - -  String - - - - - getPassword() - -
    -            - Returns the password of this database -
    - -  String - - - - - getUsername() - -
    -            - Returns the username of this database -
    - -  Boolean - - - - - remove() - -
    -            - Deletes all files of this database on disk. -
    - -  Boolean - - - - - restore(<helma.File> backupFile) - -
    -            - Restores this database using a backup on disk. -
    - - - -  - - - - - - - -
    Methods inherited from class jala.db.RamDatabase
    - -getUrl, getProperties, getConnection, shutdown, dropTable, tableExists, copyTables, runScript, dump -
    -  - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.db.FileDatabase

    -
    jala.db.FileDatabase(<String> name, <helma.File> directory, <String> username, <String> password)
    - - -
      - Returns a newly created instance of FileDatabase. -
    - - - -
      - Parameters: - -
        name - The name of the database. This name is used as prefix for all database files -
      - -
        directory - The directory where the database files should be stored in. -
      - -
        username - Optional username (defaults to "sa"). This username is used when creating the database, so the same should be used when creating subsequent instances of jala.db.FileDatabase pointing to the same database -
      - -
        password - Optional password (defaults to ""). -
      - - -
    - - - - -
      - Returns: -
        - A newly created FileDatabase instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    backup

    -
    Boolean backup(<helma.File> file)
    - -
      Creates a backup of this database, using the file passed as argument. The - result will be a zipped file containing the database files
    - - - - -
      - Parameters: - -
        file - The file to write the backup to -
      - -
    - - - - -
      - Returns: -
        - True if the database backup was created successfully, false otherwise -
      -
    - - - - - -
    - - -

    getDirectory

    -
    helma.File getDirectory()
    - -
      Returns the directory where the database files are stored.
    - - - - - - - -
      - Returns: -
        - The directory where this database is stored. -
      -
    - - - - - -
    - - -

    getName

    -
    String getName()
    - -
      Returns the name of the database. This name is used as prefix - for all files of this database in the specified directory
    - - - - - - - -
      - Returns: -
        - The name of the database -
      -
    - - - - - -
    - - -

    getPassword

    -
    String getPassword()
    - -
      Returns the password of this database
    - - - - - - - -
      - Returns: -
        - The password of this database -
      -
    - - - - - -
    - - -

    getUsername

    -
    String getUsername()
    - -
      Returns the username of this database
    - - - - - - - -
      - Returns: -
        - The username of this database -
      -
    - - - - - -
    - - -

    remove

    -
    Boolean remove()
    - -
      Deletes all files of this database on disk. Note that this also - closes the database before removing it.
    - - - - - - - -
      - Returns: -
        - True in case the database was removed successfully, false otherwise -
      -
    - - - - - -
    - - -

    restore

    -
    Boolean restore(<helma.File> backupFile)
    - -
      Restores this database using a backup on disk.
    - - - - -
      - Parameters: - -
        backupFile - The backup file to use for restore -
      - -
    - - - - -
      - Returns: -
        - True if the database was successfully restored, false otherwise -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.db.RamDatabase.html b/modules/jala/docs/jala.db.RamDatabase.html deleted file mode 100644 index da22e63e..00000000 --- a/modules/jala/docs/jala.db.RamDatabase.html +++ /dev/null @@ -1,886 +0,0 @@ - - - - - -jala.db.RamDatabase - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.db.RamDatabase

    -
    Object
    -   |
    -   +--jala.db.RamDatabase
    -
    - -
    -
    - Direct Known Subclasses: -
    - jala.db.FileDatabase -
    -
    - - -
    -
    - -
    class - jala.db.RamDatabase - - -
    - -

    -
    Instances of this class represent an in-memory sql database. -
    Important: You need the h2.jar in directory "lib/ext" - of your helma installation for this library to work, which you can get - at http://www.h2database.com/. -
    Defined in Database.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.db.RamDatabase - - (<String> name, <String> username, <String> password) - -
    -             - Returns a newly created RamDatabase instance. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - copyTables(<helma.Database> database, <Array> tables) - -
    -            - Copies all tables in the database passed as argument into this embedded database. -
    - -  Boolean - - - - - dropTable(<String> tableName) - -
    -            - Drops the table with the given name -
    - -  Boolean - - - - - dump(<helma.File> file, <Object> props) - -
    -            - Dumps the database schema and data into a file -
    - -  helma.Database - - - - - getConnection(props) - -
    -            - Returns a connection to this database -
    - -  String - - - - - getName() - -
    -            - Returns the name of the database -
    - -  String - - - - - getPassword() - -
    -            - Returns the password of this database -
    - -  helma.util.ResourceProperties - - - - - getProperties(<Object> props) - -
    -            - Returns a properties object containing the connection properties - for this database. -
    - -  String - - - - - getUrl(<Object> props) - -
    -            - Returns the JDBC Url to connect to this database -
    - -  String - - - - - getUsername() - -
    -            - Returns the username of this database -
    - -  Boolean - - - - - runScript(<helma.File> file, <Object> props, <String> charset, <Boolean> continueOnError) - -
    -            - Runs the script file passed as argument in the context of this database. -
    - -  void - - - - - shutdown() - -
    -            - Stops this in-process database by issueing a "SHUTDOWN" sql command. -
    - -  Boolean - - - - - tableExists(<String> name) - -
    -            - Returns true if the table exists already in the database -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.db.RamDatabase

    -
    jala.db.RamDatabase(<String> name, <String> username, <String> password)
    - - -
      - Returns a newly created RamDatabase instance. -
    - - - -
      - Parameters: - -
        name - The name of the database. If not given a private un-named database is created, that can only be accessed through this instance of jala.db.RamDatabase -
      - -
        username - Optional username (defaults to "sa"). This username is used when creating the database, so the same should be used when creating subsequent instances of jala.db.RamDatabase pointing to a named database. -
      - -
        password - Optional password (defaults to ""). -
      - - -
    - - - - -
      - Returns: -
        - A newly created instance of RamDatabase -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    copyTables

    -
    void copyTables(<helma.Database> database, <Array> tables)
    - -
      Copies all tables in the database passed as argument into this embedded database. - If any of the tables already exists in this database, they will be removed before - re-created. Please mind that this method ignores any indexes in the source database, - but respects the primary key settings.
    - - - - -
      - Parameters: - -
        database - The database to copy the tables from -
      - -
        tables - An optional array containing the names of the tables to copy. If not given all tables are copied -
      - -
    - - - - - - - - -
    - - -

    dropTable

    -
    Boolean dropTable(<String> tableName)
    - -
      Drops the table with the given name
    - - - - -
      - Parameters: - -
        tableName - The name of the table -
      - -
    - - - - -
      - Returns: -
        - True if the table was successfully dropped, false otherwise -
      -
    - - - - - -
    - - -

    dump

    -
    Boolean dump(<helma.File> file, <Object> props)
    - -
      Dumps the database schema and data into a file
    - - - - -
      - Parameters: - -
        file - The file where the database dump will be -
      - -
        props - Optional object containing connection properties -
      - -
    - - - - -
      - Returns: -
        - True in case the database was successfully dumped, false otherwise -
      -
    - - - - - -
    - - -

    getConnection

    -
    helma.Database getConnection(props)
    - -
      Returns a connection to this database
    - - - - -
      - Parameters: - -
        An - optional parameter object containing connection properties to add to the connection Url. -
      - -
    - - - - -
      - Returns: -
        - A connection to this database -
      -
    - - - - - -
    - - -

    getName

    -
    String getName()
    - -
      Returns the name of the database
    - - - - - - - -
      - Returns: -
        - The name of the database -
      -
    - - - - - -
    - - -

    getPassword

    -
    String getPassword()
    - -
      Returns the password of this database
    - - - - - - - -
      - Returns: -
        - The password of this database -
      -
    - - - - - -
    - - -

    getProperties

    -
    helma.util.ResourceProperties getProperties(<Object> props)
    - -
      Returns a properties object containing the connection properties - for this database.
    - - - - -
      - Parameters: - -
        props - An optional parameter object containing connection properties to add to the connection Url. -
      - -
    - - - - -
      - Returns: -
        - A properties object containing the connection properties -
      -
    - - - - - -
    - - -

    getUrl

    -
    String getUrl(<Object> props)
    - -
      Returns the JDBC Url to connect to this database
    - - - - -
      - Parameters: - -
        props - Optional connection properties to add -
      - -
    - - - - -
      - Returns: -
        - The JDBC url to use for connecting to this database -
      -
    - - - - - -
    - - -

    getUsername

    -
    String getUsername()
    - -
      Returns the username of this database
    - - - - - - - -
      - Returns: -
        - The username of this database -
      -
    - - - - - -
    - - -

    runScript

    -
    Boolean runScript(<helma.File> file, <Object> props, <String> charset, <Boolean> continueOnError)
    - -
      Runs the script file passed as argument in the context of this database. - Use this method to eg. create and/or populate a database.
    - - - - -
      - Parameters: - -
        file - The script file to run -
      - -
        props - Optional object containing connection properties -
      - -
        charset - Optional character set to use (defaults to "UTF-8") -
      - -
        continueOnError - Optional flag indicating whether to continue on error or not (defaults to false) -
      - -
    - - - - -
      - Returns: -
        - True in case the script was executed successfully, false otherwise -
      -
    - - - - - -
    - - -

    shutdown

    -
    void shutdown()
    - -
      Stops this in-process database by issueing a "SHUTDOWN" sql command.
    - - - - - - - - - - - -
    - - -

    tableExists

    -
    Boolean tableExists(<String> name)
    - -
      Returns true if the table exists already in the database
    - - - - -
      - Parameters: - -
        name - The name of the table -
      - -
    - - - - -
      - Returns: -
        - True if the table exists, false otherwise -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.db.Server.html b/modules/jala/docs/jala.db.Server.html deleted file mode 100644 index 5ba94fb1..00000000 --- a/modules/jala/docs/jala.db.Server.html +++ /dev/null @@ -1,850 +0,0 @@ - - - - - -jala.db.Server - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.db.Server

    -
    Object
    -   |
    -   +--jala.db.Server
    -
    - - -
    -
    - -
    class - jala.db.Server - - -
    - -

    -
    Instances of this class represent a H2 database listener that - allows multiple databases to be accessed via tcp. -
    Important: You need the h2.jar in directory "lib/ext" - of your helma installation for this library to work, which you can get - at http://www.h2database.com/. -
    Defined in Database.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.db.Server - - (<helma.File> baseDir, <Number> port) - -
    -             - Returns a new Server instance. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Boolean - - - - - createOnDemand(<Boolean> bool) - -
    -            - If called with boolean true as argument, this server creates databases - on-the-fly, otherwise it only accepts connections to already existing - databases. -
    - -  helma.Database - - - - - getConnection(<String> name, <String> username, <String> password, <Object> props) - -
    -            - Returns a connection to a database within this server. -
    - -  helma.File - - - - - getDirectory() - -
    -            - Returns the directory used by this server instance -
    - -  Number - - - - - getPort() - -
    -            - Returns the port this server listens on -
    - -  helma.util.ResourceProperties - - - - - getProperties(<String> name, <String> username, <String> password, <Object> props) - -
    -            - Returns a properties object containing the connection properties - of the database with the given name. -
    - -  String - - - - - getUrl(<String> name, <Object> props) - -
    -            - Returns the JDBC Url to use for connections to a given database. -
    - -  Boolean - - - - - isPublic(<Boolean> bool) - -
    -            - If called with boolean true as argument, this server accepts connections - from outside localhost. -
    - -  Boolean - - - - - isRunning() - -
    -            - Returns true if the database server is running. -
    - -  Boolean - - - - - start() - -
    -            - Starts the database server. -
    - -  Boolean - - - - - stop() - -
    -            - Stops the database server. -
    - -  Boolean - - - - - useSsl(<Boolean> bool) - -
    -            - Toggles the use of Ssl encryption within this server. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.db.Server

    -
    jala.db.Server(<helma.File> baseDir, <Number> port)
    - - -
      - Returns a new Server instance. -
    - - - -
      - Parameters: - -
        baseDir - The directory where the database files are located or should be stored -
      - -
        port - The port to listen on (defaults to 9001) -
      - -
        createOnDemand - If true this server will create non-existing databases on-the-fly, if false it only accepts connections to already existing databases in the given base directory -
      - -
        makePublic - If true this database is reachable from outside, if false it's only reachable from localhost -
      - -
        useSsl - If true SSL will be used to encrypt the connection -
      - - -
    - - - - -
      - Returns: -
        - A newly created Server instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    createOnDemand

    -
    Boolean createOnDemand(<Boolean> bool)
    - -
      If called with boolean true as argument, this server creates databases - on-the-fly, otherwise it only accepts connections to already existing - databases. This should be set before starting the server.
    - - - - -
      - Parameters: - -
        bool - If true this server creates non-existing databases on demand, if false it only allows connections to existing databases. If no argument is given, this method returns the current setting. -
      - -
    - - - - -
      - Returns: -
        - The current setting if no argument is given, or void -
      -
    - - - - - -
    - - -

    getConnection

    -
    helma.Database getConnection(<String> name, <String> username, <String> password, <Object> props)
    - -
      Returns a connection to a database within this server.
    - - - - -
      - Parameters: - -
        name - The name of the database running within this server -
      - -
        username - Optional username to use for this connection -
      - -
        password - Optional password to use for this connection -
      - -
        props - An optional parameter object containing connection properties to add to the connection Url. -
      - -
    - - - - -
      - Returns: -
        - A connection to the specified database -
      -
    - - - - - -
    - - -

    getDirectory

    -
    helma.File getDirectory()
    - -
      Returns the directory used by this server instance
    - - - - - - - -
      - Returns: -
        - The directory where the databases used by this server are located in -
      -
    - - - - - -
    - - -

    getPort

    -
    Number getPort()
    - -
      Returns the port this server listens on
    - - - - - - - -
      - Returns: -
        - The port this server listens on -
      -
    - - - - - -
    - - -

    getProperties

    -
    helma.util.ResourceProperties getProperties(<String> name, <String> username, <String> password, <Object> props)
    - -
      Returns a properties object containing the connection properties - of the database with the given name.
    - - - - -
      - Parameters: - -
        name - The name of the database -
      - -
        username - Optional username to use for this connection -
      - -
        password - Optional password to use for this connection -
      - -
        props - An optional parameter object containing connection properties to add to the connection Url. -
      - -
    - - - - -
      - Returns: -
        - A properties object containing the connection properties -
      -
    - - - - - -
    - - -

    getUrl

    -
    String getUrl(<String> name, <Object> props)
    - -
      Returns the JDBC Url to use for connections to a given database.
    - - - - -
      - Parameters: - -
        name - An optional name of a database running -
      - -
        props - Optional connection properties to add -
      - -
    - - - - -
      - Returns: -
        - The JDBC Url to use for connecting to a database within this sever -
      -
    - - - - - -
    - - -

    isPublic

    -
    Boolean isPublic(<Boolean> bool)
    - -
      If called with boolean true as argument, this server accepts connections - from outside localhost. This should be set before starting the server.
    - - - - -
      - Parameters: - -
        bool - If true this server accepts connections from outside localhost. If no argument is given, this method returns the current setting. -
      - -
    - - - - -
      - Returns: -
        - The current setting if no argument is given, or void -
      -
    - - - - - -
    - - -

    isRunning

    -
    Boolean isRunning()
    - -
      Returns true if the database server is running.
    - - - - - - - -
      - Returns: -
        - True if the database server is running -
      -
    - - - - - -
    - - -

    start

    -
    Boolean start()
    - -
      Starts the database server.
    - - - - - - - -
      - Returns: -
        - True in case the server started successfully, false otherwise -
      -
    - - - - - -
    - - -

    stop

    -
    Boolean stop()
    - -
      Stops the database server.
    - - - - - - - -
      - Returns: -
        - True if stopping the server was successful, false otherwise -
      -
    - - - - - -
    - - -

    useSsl

    -
    Boolean useSsl(<Boolean> bool)
    - -
      Toggles the use of Ssl encryption within this server. This should be set - before starting the server.
    - - - - -
      - Parameters: - -
        bool - If true SSL encryption will be used, false otherwise. If no argument is given, this method returns the current setting. -
      - -
    - - - - -
      - Returns: -
        - The current setting if no argument is given, or void -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.db.html b/modules/jala/docs/jala.db.html deleted file mode 100644 index 7551bafd..00000000 --- a/modules/jala/docs/jala.db.html +++ /dev/null @@ -1,243 +0,0 @@ - - - - - -jala.db - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala.db

    -
    Object
    -   |
    -   +--jala.db
    -
    - - -
    -
    - -
    class - jala.db - - -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.db.Server
    - <static class>jala.db.DataType
    - <static class>jala.db.RamDatabase
    - <static class>jala.db.FileDatabase
    -  - - - - - - - - - - - - - - - - -  - - - - - -

    - - - - - - - - - - - - - - - - - -


    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/jala.html b/modules/jala/docs/jala.html deleted file mode 100644 index eb12207c..00000000 --- a/modules/jala/docs/jala.html +++ /dev/null @@ -1,423 +0,0 @@ - - - - - -jala - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - -
    - - -

    Class jala

    -
    Object
    -   |
    -   +--jala
    -
    - - -
    -
    - -
    class - jala - - -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.AsyncRequest
    - <static class>jala.BitTorrent
    - <static class>jala.Captcha
    - <static class>jala.Date
    - <static class>jala.DnsClient
    - <static class>jala.Form
    - <static class>jala.History
    - <static class>jala.HtmlDocument
    - <static class>jala.I18n
    - <static class>jala.ImageFilter
    - <static class>jala.IndexManager
    - <static class>jala.ListRenderer
    - <static class>jala.Mp3
    - <static class>jala.PodcastWriter
    - <static class>jala.RemoteContent
    - <static class>jala.Rss20Writer
    - <static class>jala.Utilities
    - <static class>jala.XmlRpcRequest
    - <static class>jala.XmlWriter
    -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    - <static>  <final> jala.Datedate -
    -           Default date class instance.
    - <static>  Objectdb -
    -           Namespace declaration
    - <static>  <final> jala.I18ni18n -
    -           Default i18n class instance.
    - <static>  <final> jala.Utilitiesutil -
    -           Default utility class instance.
    -   - - - - - - - - - - - -  - - - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    date

    -
    <static> <final> jala.Date date
    -
      - Default date class instance. - -
    -
    - - -

    db

    -
    <static> Object db
    -
      - Namespace declaration - -
    -
    - - -

    i18n

    -
    <static> <final> jala.I18n i18n
    -
      - Default i18n class instance. - -
    -
    - - -

    util

    -
    <static> <final> jala.Utilities util
    -
      - Default utility class instance. - -
    -
    - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-AsyncRequest.js.html b/modules/jala/docs/overview-AsyncRequest.js.html deleted file mode 100644 index 88c84e17..00000000 --- a/modules/jala/docs/overview-AsyncRequest.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - AsyncRequest.js - - - - - - -

    - -AsyncRequest.js -
    - - - - - - - - -
    jala.AsyncRequest -
    -
    - - - diff --git a/modules/jala/docs/overview-BitTorrent.js.html b/modules/jala/docs/overview-BitTorrent.js.html deleted file mode 100644 index 40186fe3..00000000 --- a/modules/jala/docs/overview-BitTorrent.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - BitTorrent.js - - - - - - -

    - -BitTorrent.js -
    - - - - - - - - -
    jala.BitTorrent -
    -
    - - - diff --git a/modules/jala/docs/overview-Captcha.js.html b/modules/jala/docs/overview-Captcha.js.html deleted file mode 100644 index a3b39db1..00000000 --- a/modules/jala/docs/overview-Captcha.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - Captcha.js - - - - - - -

    - -Captcha.js -
    - - - - - - - - -
    jala.Captcha -
    -
    - - - diff --git a/modules/jala/docs/overview-Database.js.html b/modules/jala/docs/overview-Database.js.html deleted file mode 100644 index 98301afd..00000000 --- a/modules/jala/docs/overview-Database.js.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - Database.js - - - - - - -

    - -Database.js -
    - - - - - - - - - - - - - - - - -
    jala.db.FileDatabase -
    -
    jala.db.RamDatabase -
    -
    jala.db.Server -
    -
    - - - diff --git a/modules/jala/docs/overview-Date.js.html b/modules/jala/docs/overview-Date.js.html deleted file mode 100644 index 41d49a7d..00000000 --- a/modules/jala/docs/overview-Date.js.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - Date.js - - - - - - -

    - -Date.js -
    - - - - - - - - - - - - - - - - -
    jala.Date -
    -
    jala.Date.Calendar -
    -
    jala.Date.Calendar.Renderer -
    -
    - - - diff --git a/modules/jala/docs/overview-DnsClient.js.html b/modules/jala/docs/overview-DnsClient.js.html deleted file mode 100644 index cd8cfacb..00000000 --- a/modules/jala/docs/overview-DnsClient.js.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - DnsClient.js - - - - - - -

    - -DnsClient.js -
    - - - - - - - - - - - - -
    jala.DnsClient -
    -
    jala.DnsClient.Record -
    -
    - - - diff --git a/modules/jala/docs/overview-Form.js.html b/modules/jala/docs/overview-Form.js.html deleted file mode 100644 index d95bfab3..00000000 --- a/modules/jala/docs/overview-Form.js.html +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - Form.js - - - - - - -

    - -Form.js -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    jala.Form -
    -
    jala.Form.Component -
    -
    jala.Form.Component.Button -
    -
    jala.Form.Component.Checkbox -
    -
    jala.Form.Component.Date -
    -
    jala.Form.Component.Fieldset -
    -
    jala.Form.Component.File -
    -
    jala.Form.Component.Hidden -
    -
    jala.Form.Component.Image -
    -
    jala.Form.Component.Input -
    -
    jala.Form.Component.Password -
    -
    jala.Form.Component.Radio -
    -
    jala.Form.Component.Select -
    -
    jala.Form.Component.Skin -
    -
    jala.Form.Component.Submit -
    -
    jala.Form.Component.Textarea -
    -
    jala.Form.Tracker -
    -
    - - - diff --git a/modules/jala/docs/overview-Global.js.html b/modules/jala/docs/overview-Global.js.html deleted file mode 100644 index 0b33ab65..00000000 --- a/modules/jala/docs/overview-Global.js.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - Global.js - - - - - - -

    - -Global.js -
    - - - - -
    - - - diff --git a/modules/jala/docs/overview-History.js.html b/modules/jala/docs/overview-History.js.html deleted file mode 100644 index f9a292db..00000000 --- a/modules/jala/docs/overview-History.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - History.js - - - - - - -

    - -History.js -
    - - - - - - - - -
    jala.History -
    -
    - - - diff --git a/modules/jala/docs/overview-HopObject.js.html b/modules/jala/docs/overview-HopObject.js.html deleted file mode 100644 index 5096aa7f..00000000 --- a/modules/jala/docs/overview-HopObject.js.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - HopObject.js - - - - - - -

    - -HopObject.js -
    - - - - -
    - - - diff --git a/modules/jala/docs/overview-HtmlDocument.js.html b/modules/jala/docs/overview-HtmlDocument.js.html deleted file mode 100644 index 74abea83..00000000 --- a/modules/jala/docs/overview-HtmlDocument.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - HtmlDocument.js - - - - - - -

    - -HtmlDocument.js -
    - - - - - - - - -
    jala.HtmlDocument -
    -
    - - - diff --git a/modules/jala/docs/overview-I18n.js.html b/modules/jala/docs/overview-I18n.js.html deleted file mode 100644 index 30a1f027..00000000 --- a/modules/jala/docs/overview-I18n.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - I18n.js - - - - - - -

    - -I18n.js -
    - - - - - - - - -
    jala.I18n -
    -
    - - - diff --git a/modules/jala/docs/overview-ImageFilter.js.html b/modules/jala/docs/overview-ImageFilter.js.html deleted file mode 100644 index c949f24b..00000000 --- a/modules/jala/docs/overview-ImageFilter.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - ImageFilter.js - - - - - - -

    - -ImageFilter.js -
    - - - - - - - - -
    jala.ImageFilter -
    -
    - - - diff --git a/modules/jala/docs/overview-IndexManager.js.html b/modules/jala/docs/overview-IndexManager.js.html deleted file mode 100644 index 1b4282eb..00000000 --- a/modules/jala/docs/overview-IndexManager.js.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - IndexManager.js - - - - - - -

    - -IndexManager.js -
    - - - - - - - - - - - - -
    jala.IndexManager -
    -
    jala.IndexManager.Job -
    -
    - - - diff --git a/modules/jala/docs/overview-ListRenderer.js.html b/modules/jala/docs/overview-ListRenderer.js.html deleted file mode 100644 index 9da05948..00000000 --- a/modules/jala/docs/overview-ListRenderer.js.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - ListRenderer.js - - - - - - -

    - -ListRenderer.js -
    - - - - - - - - - - - - -
    jala.ListRenderer -
    -
    jala.ListRenderer.ArrayList -
    -
    - - - diff --git a/modules/jala/docs/overview-Mp3.js.html b/modules/jala/docs/overview-Mp3.js.html deleted file mode 100644 index b20cd0ba..00000000 --- a/modules/jala/docs/overview-Mp3.js.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - Mp3.js - - - - - - -

    - -Mp3.js -
    - - - - - - - - - - - - - - - - -
    jala.Mp3 -
    -
    jala.Mp3.Id3v1 -
    -
    jala.Mp3.Id3v2 -
    -
    - - - diff --git a/modules/jala/docs/overview-PodcastWriter.js.html b/modules/jala/docs/overview-PodcastWriter.js.html deleted file mode 100644 index 266115dd..00000000 --- a/modules/jala/docs/overview-PodcastWriter.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - PodcastWriter.js - - - - - - -

    - -PodcastWriter.js -
    - - - - - - - - -
    jala.PodcastWriter -
    -
    - - - diff --git a/modules/jala/docs/overview-RemoteContent.js.html b/modules/jala/docs/overview-RemoteContent.js.html deleted file mode 100644 index 0d06a163..00000000 --- a/modules/jala/docs/overview-RemoteContent.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - RemoteContent.js - - - - - - -

    - -RemoteContent.js -
    - - - - - - - - -
    jala.RemoteContent -
    -
    - - - diff --git a/modules/jala/docs/overview-Rss20Writer.js.html b/modules/jala/docs/overview-Rss20Writer.js.html deleted file mode 100644 index ef353f62..00000000 --- a/modules/jala/docs/overview-Rss20Writer.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - Rss20Writer.js - - - - - - -

    - -Rss20Writer.js -
    - - - - - - - - -
    jala.Rss20Writer -
    -
    - - - diff --git a/modules/jala/docs/overview-Utilities.js.html b/modules/jala/docs/overview-Utilities.js.html deleted file mode 100644 index df24f343..00000000 --- a/modules/jala/docs/overview-Utilities.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - Utilities.js - - - - - - -

    - -Utilities.js -
    - - - - - - - - -
    jala.Utilities -
    -
    - - - diff --git a/modules/jala/docs/overview-XmlRpcRequest.js.html b/modules/jala/docs/overview-XmlRpcRequest.js.html deleted file mode 100644 index 4570873b..00000000 --- a/modules/jala/docs/overview-XmlRpcRequest.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - XmlRpcRequest.js - - - - - - -

    - -XmlRpcRequest.js -
    - - - - - - - - -
    jala.XmlRpcRequest -
    -
    - - - diff --git a/modules/jala/docs/overview-XmlWriter.js.html b/modules/jala/docs/overview-XmlWriter.js.html deleted file mode 100644 index e0a6fa19..00000000 --- a/modules/jala/docs/overview-XmlWriter.js.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - XmlWriter.js - - - - - - -

    - -XmlWriter.js -
    - - - - - - - - -
    jala.XmlWriter -
    -
    - - - diff --git a/modules/jala/docs/overview-all.js.html b/modules/jala/docs/overview-all.js.html deleted file mode 100644 index e2dce5a2..00000000 --- a/modules/jala/docs/overview-all.js.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - all.js - - - - - - -

    - -all.js -
    - - - - -
    - - - diff --git a/modules/jala/docs/overview-frame.html b/modules/jala/docs/overview-frame.html deleted file mode 100644 index 41ebf84b..00000000 --- a/modules/jala/docs/overview-frame.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - -Overview () - - - - - - -

    Jala 1.3

    - - - - -
    - - - - - -
    All Classes -

    - -Files -
    - -all.js
    - -AsyncRequest.js
    - -BitTorrent.js
    - -Captcha.js
    - -Database.js
    - -Date.js
    - -DnsClient.js
    - -Form.js
    - -Global.js
    - -History.js
    - -HopObject.js
    - -HtmlDocument.js
    - -I18n.js
    - -ImageFilter.js
    - -IndexManager.js
    - -ListRenderer.js
    - -Mp3.js
    - -PodcastWriter.js
    - -RemoteContent.js
    - -Rss20Writer.js
    - -Utilities.js
    - -XmlRpcRequest.js
    - -XmlWriter.js
    - -

    - -

    -  - - diff --git a/modules/jala/docs/overview-summary-AsyncRequest.js.html b/modules/jala/docs/overview-summary-AsyncRequest.js.html deleted file mode 100644 index 2e5de3c2..00000000 --- a/modules/jala/docs/overview-summary-AsyncRequest.js.html +++ /dev/null @@ -1,170 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -


    -
    - -

    AsyncRequest.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.AsyncRequest class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.AsyncRequestThis class is used to create requests of type "INTERNAL" - (like cron-jobs) that are processed in a separate thread and - therefor asynchronous.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-BitTorrent.js.html b/modules/jala/docs/overview-summary-BitTorrent.js.html deleted file mode 100644 index d34bcb31..00000000 --- a/modules/jala/docs/overview-summary-BitTorrent.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    BitTorrent.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.BitTorrent class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.BitTorrentThis class provides methods to create a BitTorrent - metadata file from any desired file.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-Captcha.js.html b/modules/jala/docs/overview-summary-Captcha.js.html deleted file mode 100644 index 70dfe35b..00000000 --- a/modules/jala/docs/overview-summary-Captcha.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    Captcha.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.Captcha class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.CaptchaWrapper class for the - JCaptcha library.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-Database.js.html b/modules/jala/docs/overview-summary-Database.js.html deleted file mode 100644 index d40deebf..00000000 --- a/modules/jala/docs/overview-summary-Database.js.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    Database.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.db package.

    - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - -
    - - Class Summary - -
    jala.db.FileDatabaseInstances of this class represent a file based in-process database -
    Important: You need the h2.jar in directory "lib/ext" - of your helma installation for this library to work, which you can get - at http://www.h2database.com/.
    jala.db.RamDatabaseInstances of this class represent an in-memory sql database.
    jala.db.ServerInstances of this class represent a H2 database listener that - allows multiple databases to be accessed via tcp.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-Date.js.html b/modules/jala/docs/overview-summary-Date.js.html deleted file mode 100644 index 45b3be62..00000000 --- a/modules/jala/docs/overview-summary-Date.js.html +++ /dev/null @@ -1,181 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    Date.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.Date class.

    - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - -
    - - Class Summary - -
    jala.DateThis class provides various convenience - methods for rendering purposes.
    jala.Date.CalendarThis class represents a calendar based based on a grouped - collection of HopObjects.
    jala.Date.Calendar.RendererA default renderer to use in conjunction with jala.Date.Calendar -
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-DnsClient.js.html b/modules/jala/docs/overview-summary-DnsClient.js.html deleted file mode 100644 index 8eb16e9b..00000000 --- a/modules/jala/docs/overview-summary-DnsClient.js.html +++ /dev/null @@ -1,175 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    DnsClient.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.DnsClient class.

    - -

    - -
    - - - - - - - - - - - - - - - - - -
    - - Class Summary - -
    jala.DnsClientThis is a wrapper around the Dns Client by wonderly.org - providing methods for querying Dns servers.
    jala.DnsClient.RecordInstances of this class wrap record data as received - from the nameserver.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-Form.js.html b/modules/jala/docs/overview-summary-Form.js.html deleted file mode 100644 index c85ee5b6..00000000 --- a/modules/jala/docs/overview-summary-Form.js.html +++ /dev/null @@ -1,264 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    Form.js

    - -
    - - - - -

    Summary

    -

    - - This class can be used to render forms and to validate - and store user submits. Further types of form components can be added - by subclassing jala.Form.Component.Input.

    - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - Class Summary - -
    jala.FormA class that renders forms, validates submitted form data and - stores the data in a specified object.
    jala.Form.Component 
    jala.Form.Component.ButtonSubclass of jala.Form.Component.Input which renders a button.
    jala.Form.Component.CheckboxSubclass of jala.Form.Component.Input which renders and validates a - checkbox.
    jala.Form.Component.DateSubclass of jala.Form.Component.Input which renders and validates a - date editor.
    jala.Form.Component.FieldsetInstances of this class represent a form fieldset containing - numerous form components -
    jala.Form.Component.FileSubclass of jala.Form.Component.Input which renders and validates a - file upload.
    jala.Form.Component.HiddenSubclass of jala.Form.Component.Input which renders and validates a - hidden input tag.
    jala.Form.Component.ImageSubclass of jala.Form.Component.File which renders a file upload - and validates uploaded files as images.
    jala.Form.Component.InputInstances of this class represent a single form input field.
    jala.Form.Component.PasswordSubclass of jala.Form.Component.Input which renders and validates a - password input tag.
    jala.Form.Component.RadioSubclass of jala.Form.Component.Input which renders and validates a - set of radio buttons.
    jala.Form.Component.SelectSubclass of jala.Form.Component.Input which renders and validates a - dropdown element.
    jala.Form.Component.SkinSubclass of jala.Form.Component that allows rendering a skin - within a form.
    jala.Form.Component.SubmitSubclass of jala.Form.Component.Button which renders a submit button.
    jala.Form.Component.TextareaSubclass of jala.Form.Component.Input which renders and validates a - textarea input field.
    jala.Form.TrackerInstances of this class can contain error-messages and values -
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-Global.js.html b/modules/jala/docs/overview-summary-Global.js.html deleted file mode 100644 index a486ca23..00000000 --- a/modules/jala/docs/overview-summary-Global.js.html +++ /dev/null @@ -1,324 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    Global.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the Global prototype.

    - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - Method Summary - -
    - - static Boolean - - - - - isArray(<Object> val) - -
    -            - Returns true if the value passed as argument is an array. -
    - - static Boolean - - - - - isBoolean(<Object> val) - -
    -            - Returns true if the value passed as argument is either a boolean - literal or an instance of Boolean. -
    - - static Boolean - - - - - isDate(<Object> val) - -
    -            - Returns true if the value passed as argument is either a Javascript date - or an instance of java.util.Date. -
    - - static Boolean - - - - - isFunction(<Object> val) - -
    -            - Returns true if the value passed as argument is a function. -
    - - static Boolean - - - - - isNull(<Object> val) - -
    -            - Returns true if the value passed as argument is null. -
    - - static Boolean - - - - - isNumber(<Object> val) - -
    -            - Returns true if the value passed as argument is either a number, - an instance of Number or of java.lang.Number. -
    - - static Boolean - - - - - isObject(<Object> val) - -
    -            - Returns true if the value passed as argument is either a Javascript - object or an instance of java.lang.Object. -
    - - static Boolean - - - - - isString(<Object> val) - -
    -            - Returns true if the value passed as argument is either a string literal, - an instance of String or of java.lang.String. -
    - - static Boolean - - - - - isUndefined(<Object> val) - -
    -            - Returns true if the value passed as argument is undefined. -
    -

    - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -


    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-History.js.html b/modules/jala/docs/overview-summary-History.js.html deleted file mode 100644 index 6f521c76..00000000 --- a/modules/jala/docs/overview-summary-History.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    History.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.History class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.HistoryThis class is an implementation of a Browser-like history - stack suitable to use in any Helma application.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-HopObject.js.html b/modules/jala/docs/overview-summary-HopObject.js.html deleted file mode 100644 index fcf4c14f..00000000 --- a/modules/jala/docs/overview-summary-HopObject.js.html +++ /dev/null @@ -1,151 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    HopObject.js

    - -
    - - - - -

    Summary

    -

    - - Additional fields and methods of the HopObject class.

    - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-HtmlDocument.js.html b/modules/jala/docs/overview-summary-HtmlDocument.js.html deleted file mode 100644 index 27b462c1..00000000 --- a/modules/jala/docs/overview-summary-HtmlDocument.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    HtmlDocument.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.HtmlDocument class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.HtmlDocumentThis class provides easy access to the elements of - an arbitrary HTML document.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-I18n.js.html b/modules/jala/docs/overview-summary-I18n.js.html deleted file mode 100644 index 4dc0d79d..00000000 --- a/modules/jala/docs/overview-summary-I18n.js.html +++ /dev/null @@ -1,170 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    I18n.js

    - -
    - - - - -

    Summary

    -

    - - Methods and macros for internationalization - of Helma applications.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.I18nThis class provides various functions and macros for - internationalization of Helma applications.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-ImageFilter.js.html b/modules/jala/docs/overview-summary-ImageFilter.js.html deleted file mode 100644 index a5049352..00000000 --- a/modules/jala/docs/overview-summary-ImageFilter.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    ImageFilter.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.ImageFilter class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.ImageFilterThis class provides several image manipulating - methods.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-IndexManager.js.html b/modules/jala/docs/overview-summary-IndexManager.js.html deleted file mode 100644 index 60a323ab..00000000 --- a/modules/jala/docs/overview-summary-IndexManager.js.html +++ /dev/null @@ -1,175 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    IndexManager.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.IndexManager class.

    - -

    - -
    - - - - - - - - - - - - - - - - - -
    - - Class Summary - -
    jala.IndexManagerThis class basically sits on top of a helma.Search.Index instance - and provides methods for adding, removing and optimizing the underlying index.
    jala.IndexManager.JobInstances of this class represent a single index - manipulation job to be processed by the index manager.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-ListRenderer.js.html b/modules/jala/docs/overview-summary-ListRenderer.js.html deleted file mode 100644 index 9727f143..00000000 --- a/modules/jala/docs/overview-summary-ListRenderer.js.html +++ /dev/null @@ -1,174 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    ListRenderer.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.ListRenderer class.

    - -

    - -
    - - - - - - - - - - - - - - - - - -
    - - Class Summary - -
    jala.ListRenderer 
    jala.ListRenderer.ArrayListA simple wrapper around an array to use in conjunction - with jala.ListRenderer.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-Mp3.js.html b/modules/jala/docs/overview-summary-Mp3.js.html deleted file mode 100644 index 21624a71..00000000 --- a/modules/jala/docs/overview-summary-Mp3.js.html +++ /dev/null @@ -1,179 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    Mp3.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.audio package.

    - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - -
    - - Class Summary - -
    jala.Mp3This is a class representing an MP3 file - providing methods to access its metadata.
    jala.Mp3.Id3v1This class represents an Id3v1 tag.
    jala.Mp3.Id3v2This class represents an Id3v2 tag.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-PodcastWriter.js.html b/modules/jala/docs/overview-summary-PodcastWriter.js.html deleted file mode 100644 index 935ed3a0..00000000 --- a/modules/jala/docs/overview-summary-PodcastWriter.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    PodcastWriter.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.PodcastWriter class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.PodcastWriterClass to create, modify and render standard-compliant - RSS 2.0 feeds including support for Apple's Podcast specification.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-RemoteContent.js.html b/modules/jala/docs/overview-summary-RemoteContent.js.html deleted file mode 100644 index 697ab0b0..00000000 --- a/modules/jala/docs/overview-summary-RemoteContent.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    RemoteContent.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.RemoteContent class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.RemoteContentAPI to define, fetch and update content - from a remote site.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-Rss20Writer.js.html b/modules/jala/docs/overview-summary-Rss20Writer.js.html deleted file mode 100644 index 3705e4e6..00000000 --- a/modules/jala/docs/overview-summary-Rss20Writer.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    Rss20Writer.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.Rss20Writer class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.Rss20WriterClass to create, modify and render standard-compliant - RSS 2.0 feeds.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-Utilities.js.html b/modules/jala/docs/overview-summary-Utilities.js.html deleted file mode 100644 index 98b6fa71..00000000 --- a/modules/jala/docs/overview-summary-Utilities.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    Utilities.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.Utilities class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.UtilitiesThis class contains various convenience methods - which do not fit in any other class.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-XmlRpcRequest.js.html b/modules/jala/docs/overview-summary-XmlRpcRequest.js.html deleted file mode 100644 index 3287421a..00000000 --- a/modules/jala/docs/overview-summary-XmlRpcRequest.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    XmlRpcRequest.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.XmlRpcRequest class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.XmlRpcRequestInstances of this class provide the necessary functionality - for issueing XmlRpc requests to a remote service.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-XmlWriter.js.html b/modules/jala/docs/overview-summary-XmlWriter.js.html deleted file mode 100644 index f2f0e31c..00000000 --- a/modules/jala/docs/overview-summary-XmlWriter.js.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    XmlWriter.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.XmlWriter class.

    - -

    - -
    - - - - - - - - - - - - -
    - - Class Summary - -
    jala.XmlWriterThis class defines a generic interface to write - arbitrary and validating XML source code.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary-all.js.html b/modules/jala/docs/overview-summary-all.js.html deleted file mode 100644 index b45afdd9..00000000 --- a/modules/jala/docs/overview-summary-all.js.html +++ /dev/null @@ -1,151 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    all.js

    - -
    - - - - -

    Summary

    -

    - - Wrapper for automatic inclusion of all Jala modules.

    - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-summary.html b/modules/jala/docs/overview-summary.html deleted file mode 100644 index 1c059073..00000000 --- a/modules/jala/docs/overview-summary.html +++ /dev/null @@ -1,286 +0,0 @@ - - - - -Jala 1.3 Overview - - - - - - - - - - - - - - - - - - -
    - -Jala 1.3 -
    - - -
    -
    - -

    Jala 1.3

    - -
    - - -

    - This document is the API Specification for - Jala 1.3. -

    - - - -

    Summary

    -

    - - Jala is a Helma-based library and utility project initially developed to ease the work at ORF.at's software development department. - - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - File Summary - -
    all.jsWrapper for automatic inclusion of all Jala modules.
    AsyncRequest.jsFields and methods of the jala.AsyncRequest class.
    BitTorrent.jsFields and methods of the jala.BitTorrent class.
    Captcha.jsFields and methods of the jala.Captcha class.
    Database.jsFields and methods of the jala.db package.
    Date.jsFields and methods of the jala.Date class.
    DnsClient.jsFields and methods of the jala.DnsClient class.
    Form.jsThis class can be used to render forms and to validate - and store user submits.
    Global.jsFields and methods of the Global prototype.
    History.jsFields and methods of the jala.History class.
    HopObject.jsAdditional fields and methods of the HopObject class.
    HtmlDocument.jsFields and methods of the jala.HtmlDocument class.
    I18n.jsMethods and macros for internationalization - of Helma applications.
    ImageFilter.jsFields and methods of the jala.ImageFilter class.
    IndexManager.jsFields and methods of the jala.IndexManager class.
    ListRenderer.jsFields and methods of the jala.ListRenderer class.
    Mp3.jsFields and methods of the jala.audio package.
    PodcastWriter.jsFields and methods of the jala.PodcastWriter class.
    RemoteContent.jsFields and methods of the jala.RemoteContent class.
    Rss20Writer.jsFields and methods of the jala.Rss20Writer class.
    Utilities.jsFields and methods of the jala.Utilities class.
    XmlRpcRequest.jsFields and methods of the jala.XmlRpcRequest class.
    XmlWriter.jsFields and methods of the jala.XmlWriter class.
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/overview-tree.html b/modules/jala/docs/overview-tree.html deleted file mode 100644 index 52df74e1..00000000 --- a/modules/jala/docs/overview-tree.html +++ /dev/null @@ -1,316 +0,0 @@ - - - - - -Jala 1.3 Class Hierarchy - - - - - - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    -

    Class Hierarchy

    - - - -
    - - - - - - - - - - - - - -
    -Jala 1.3 -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008
    - - diff --git a/modules/jala/docs/stylesheet.css b/modules/jala/docs/stylesheet.css deleted file mode 100644 index 7a35c0c1..00000000 --- a/modules/jala/docs/stylesheet.css +++ /dev/null @@ -1,39 +0,0 @@ -/* JSDoc style sheet */ - -/* Define colors, fonts and other style attributes here to override the defaults */ - -/* Page background color */ -body { background-color: #FFFFFF } - -/* Table colors */ -.TableHeadingColor { background: #CCCCFF } /* Dark mauve */ -.TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ -.TableRowColor { background: #FFFFFF } /* White */ - -/* Font used in left-hand frame lists */ -.FrameTitleFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } -.FrameHeadingFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } -.FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } - -/* Example of smaller, sans-serif font in frames */ -/* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */ - -/* Navigation bar fonts and colors */ -.NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */ -.NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */ -.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} -.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} - -.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} -.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} - -.jsdoc_ctime { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; - text-align: right } - -/* Sourcecode view */ -.sourceview { background: #FFFFFF } -.attrib { color: #DD7777 } -.comment { color: #55AA55 } -.reserved { color: #FF5555 } -.literal { color: #5555FF } - diff --git a/modules/jala/lib/dom4j-1.6.1.jar b/modules/jala/lib/dom4j-1.6.1.jar deleted file mode 100644 index c8c4dbb9..00000000 Binary files a/modules/jala/lib/dom4j-1.6.1.jar and /dev/null differ diff --git a/modules/jala/lib/id3-1.6.0d9.jar b/modules/jala/lib/id3-1.6.0d9.jar deleted file mode 100644 index 7da41c59..00000000 Binary files a/modules/jala/lib/id3-1.6.0d9.jar and /dev/null differ diff --git a/modules/jala/lib/javadns.jar b/modules/jala/lib/javadns.jar deleted file mode 100644 index 13b2ec77..00000000 Binary files a/modules/jala/lib/javadns.jar and /dev/null differ diff --git a/modules/jala/lib/jaxen-1.1-beta-8.jar b/modules/jala/lib/jaxen-1.1-beta-8.jar deleted file mode 100644 index 6b007d97..00000000 Binary files a/modules/jala/lib/jaxen-1.1-beta-8.jar and /dev/null differ diff --git a/modules/jala/lib/jid3lib-0.5.4.jar b/modules/jala/lib/jid3lib-0.5.4.jar deleted file mode 100644 index 63e5a672..00000000 Binary files a/modules/jala/lib/jid3lib-0.5.4.jar and /dev/null differ diff --git a/modules/jala/licenses/dom4j.txt b/modules/jala/licenses/dom4j.txt deleted file mode 100644 index 7cae050c..00000000 --- a/modules/jala/licenses/dom4j.txt +++ /dev/null @@ -1,40 +0,0 @@ -Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. - -Redistribution and use of this software and associated documentation -("Software"), with or without modification, are permitted provided -that the following conditions are met: - -1. Redistributions of source code must retain copyright - statements and notices. Redistributions must also contain a - copy of this document. - -2. Redistributions in binary form must reproduce the - above copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - -3. The name "DOM4J" must not be used to endorse or promote - products derived from this Software without prior written - permission of MetaStuff, Ltd. For written permission, - please contact dom4j-info@metastuff.com. - -4. Products derived from this Software may not be called "DOM4J" - nor may "DOM4J" appear in their names without prior written - permission of MetaStuff, Ltd. DOM4J is a registered - trademark of MetaStuff, Ltd. - -5. Due credit should be given to the DOM4J Project - - http://www.dom4j.org - -THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS -``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT -NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED -OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/modules/jala/licenses/id3.txt b/modules/jala/licenses/id3.txt deleted file mode 100644 index 5ab7695a..00000000 --- a/modules/jala/licenses/id3.txt +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/modules/jala/licenses/jala.txt b/modules/jala/licenses/jala.txt deleted file mode 100644 index d6456956..00000000 --- a/modules/jala/licenses/jala.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/modules/jala/licenses/javadns.txt b/modules/jala/licenses/javadns.txt deleted file mode 100644 index 56e3f124..00000000 --- a/modules/jala/licenses/javadns.txt +++ /dev/null @@ -1,29 +0,0 @@ -Copyright (c) 2001-2004, Gregg Wonderly -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this -list of conditions and the following disclaimer. - -Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - -Neither the name of Gregg Wonderly nor the names of contributors to this -software may be used to endorse or promote products derived from this -software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/modules/jala/licenses/javamusictag.html b/modules/jala/licenses/javamusictag.html deleted file mode 100644 index 487e60aa..00000000 --- a/modules/jala/licenses/javamusictag.html +++ /dev/null @@ -1,613 +0,0 @@ - - - - GNU Lesser General Public License - GNU Project - Free Software Foundation (FSF) - - - -

    GNU Lesser General Public License

    - -

    - Version 2.1, February 1999 - -

    - -

    -

    Copyright (C) 1991, 1999 Free Software Foundation, Inc.
    -    59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    -    Everyone is permitted to copy and distribute verbatim copies
    -    of this license document, but changing it is not allowed.
    -
    -    [This is the first released version of the Lesser GPL. It also counts
    -    as the successor of the GNU Library Public License, version 2, hence
    -    the version number 2.1.]
    -
    - - -

    Preamble

    - -

    - The licenses for most software are designed to take away your - freedom to share and change it. By contrast, the GNU General Public - Licenses are intended to guarantee your freedom to share and change - free software--to make sure the software is free for all its users. -

    - -

    - This license, the Lesser General Public License, applies to some - specially designated software packages--typically libraries--of the - Free Software Foundation and other authors who decide to use it. You - can use it too, but we suggest you first think carefully about whether - this license or the ordinary General Public License is the better - strategy to use in any particular case, based on the explanations below. -

    - -

    - When we speak of free software, we are referring to freedom of use, - not price. Our General Public Licenses are designed to make sure that - you have the freedom to distribute copies of free software (and charge - for this service if you wish); that you receive source code or can get - it if you want it; that you can change the software and use pieces of - it in new free programs; and that you are informed that you can do - these things. -

    - -

    - To protect your rights, we need to make restrictions that forbid - distributors to deny you these rights or to ask you to surrender these - rights. These restrictions translate to certain responsibilities for - you if you distribute copies of the library or if you modify it. -

    - -

    - For example, if you distribute copies of the library, whether gratis - or for a fee, you must give the recipients all the rights that we gave - you. You must make sure that they, too, receive or can get the source - code. If you link other code with the library, you must provide - complete object files to the recipients, so that they can relink them - with the library after making changes to the library and recompiling - it. And you must show them these terms so they know their rights. -

    - -

    - We protect your rights with a two-step method: (1) we copyright the - library, and (2) we offer you this license, which gives you legal - permission to copy, distribute and/or modify the library. -

    - -

    - To protect each distributor, we want to make it very clear that - there is no warranty for the free library. Also, if the library is - modified by someone else and passed on, the recipients should know - that what they have is not the original version, so that the original - author's reputation will not be affected by problems that might be - introduced by others. -

    - -

    - Finally, software patents pose a constant threat to the existence of - any free program. We wish to make sure that a company cannot - effectively restrict the users of a free program by obtaining a - restrictive license from a patent holder. Therefore, we insist that - any patent license obtained for a version of the library must be - consistent with the full freedom of use specified in this license. -

    - -

    - Most GNU software, including some libraries, is covered by the - ordinary GNU General Public License. This license, the GNU Lesser - General Public License, applies to certain designated libraries, and - is quite different from the ordinary General Public License. We use - this license for certain libraries in order to permit linking those - libraries into non-free programs. -

    - -

    - When a program is linked with a library, whether statically or using - a shared library, the combination of the two is legally speaking a - combined work, a derivative of the original library. The ordinary - General Public License therefore permits such linking only if the - entire combination fits its criteria of freedom. The Lesser General - Public License permits more lax criteria for linking other code with - the library. -

    - -

    - We call this license the "Lesser" General Public License because it - does Less to protect the user's freedom than the ordinary General - Public License. It also provides other free software developers Less - of an advantage over competing non-free programs. These disadvantages - are the reason we use the ordinary General Public License for many - libraries. However, the Lesser license provides advantages in certain - special circumstances. -

    - -

    - For example, on rare occasions, there may be a special need to - encourage the widest possible use of a certain library, so that it becomes - a de-facto standard. To achieve this, non-free programs must be - allowed to use the library. A more frequent case is that a free - library does the same job as widely used non-free libraries. In this - case, there is little to gain by limiting the free library to free - software only, so we use the Lesser General Public License. -

    - -

    - In other cases, permission to use a particular library in non-free - programs enables a greater number of people to use a large body of - free software. For example, permission to use the GNU C Library in - non-free programs enables many more people to use the whole GNU - operating system, as well as its variant, the GNU/Linux operating - system. -

    - -

    - Although the Lesser General Public License is Less protective of the - users' freedom, it does ensure that the user of a program that is - linked with the Library has the freedom and the wherewithal to run - that program using a modified version of the Library. -

    - -

    - The precise terms and conditions for copying, distribution and - modification follow. Pay close attention to the difference between a - "work based on the library" and a "work that uses the library". The - former contains code derived from the library, whereas the latter must - be combined with the library in order to run. -

    - -

    - -

    - -

    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

    - - -

    - 0. - This License Agreement applies to any software library or other - program which contains a notice placed by the copyright holder or - other authorized party saying it may be distributed under the terms of - this Lesser General Public License (also called "this License"). - Each licensee is addressed as "you". -

    - -

    - A "library" means a collection of software functions and/or data - prepared so as to be conveniently linked with application programs - (which use some of those functions and data) to form executables. -

    - -

    - The "Library", below, refers to any such software library or work - which has been distributed under these terms. A "work based on the - Library" means either the Library or any derivative work under - copyright law: that is to say, a work containing the Library or a - portion of it, either verbatim or with modifications and/or translated - straightforwardly into another language. (Hereinafter, translation is - included without limitation in the term "modification".) -

    - -

    - "Source code" for a work means the preferred form of the work for - making modifications to it. For a library, complete source code means - all the source code for all modules it contains, plus any associated - interface definition files, plus the scripts used to control compilation - and installation of the library. -

    - -

    - Activities other than copying, distribution and modification are not - covered by this License; they are outside its scope. The act of - running a program using the Library is not restricted, and output from - such a program is covered only if its contents constitute a work based - on the Library (independent of the use of the Library in a tool for - writing it). Whether that is true depends on what the Library does - and what the program that uses the Library does. -

    - -

    - 1. - You may copy and distribute verbatim copies of the Library's - complete source code as you receive it, in any medium, provided that - you conspicuously and appropriately publish on each copy an - appropriate copyright notice and disclaimer of warranty; keep intact - all the notices that refer to this License and to the absence of any - warranty; and distribute a copy of this License along with the - Library. -

    - -

    - You may charge a fee for the physical act of transferring a copy, - and you may at your option offer warranty protection in exchange for a - fee. -

    - -

    - 2. - You may modify your copy or copies of the Library or any portion - of it, thus forming a work based on the Library, and copy and - distribute such modifications or work under the terms of Section 1 - above, provided that you also meet all of these conditions: -

    - -

    -

      -
    • a) - The modified work must itself be a software library. -
    • b) - You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - -
    • c) - You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - -
    • d) - If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. -

      - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) -

      - -

      - These requirements apply to the modified work as a whole. If - identifiable sections of that work are not derived from the Library, - and can be reasonably considered independent and separate works in - themselves, then this License, and its terms, do not apply to those - sections when you distribute them as separate works. But when you - distribute the same sections as part of a whole which is a work based - on the Library, the distribution of the whole must be on the terms of - this License, whose permissions for other licensees extend to the - entire whole, and thus to each and every part regardless of who wrote - it. -

      - -

      - Thus, it is not the intent of this section to claim rights or contest - your rights to work written entirely by you; rather, the intent is to - exercise the right to control the distribution of derivative or - collective works based on the Library. -

      - -

      - In addition, mere aggregation of another work not based on the Library - with the Library (or with a work based on the Library) on a volume of - a storage or distribution medium does not bring the other work under - the scope of this License. -

    - -

    - 3. - You may opt to apply the terms of the ordinary GNU General Public - License instead of this License to a given copy of the Library. To do - this, you must alter all the notices that refer to this License, so - that they refer to the ordinary GNU General Public License, version 2, - instead of to this License. (If a newer version than version 2 of the - ordinary GNU General Public License has appeared, then you can specify - that version instead if you wish.) Do not make any other change in - these notices. -

    - -

    - Once this change is made in a given copy, it is irreversible for - that copy, so the ordinary GNU General Public License applies to all - subsequent copies and derivative works made from that copy. -

    - -

    - This option is useful when you wish to copy part of the code of - the Library into a program that is not a library. -

    - -

    - 4. - You may copy and distribute the Library (or a portion or - derivative of it, under Section 2) in object code or executable form - under the terms of Sections 1 and 2 above provided that you accompany - it with the complete corresponding machine-readable source code, which - must be distributed under the terms of Sections 1 and 2 above on a - medium customarily used for software interchange. -

    - -

    - If distribution of object code is made by offering access to copy - from a designated place, then offering equivalent access to copy the - source code from the same place satisfies the requirement to - distribute the source code, even though third parties are not - compelled to copy the source along with the object code. -

    - -

    - 5. - A program that contains no derivative of any portion of the - Library, but is designed to work with the Library by being compiled or - linked with it, is called a "work that uses the Library". Such a - work, in isolation, is not a derivative work of the Library, and - therefore falls outside the scope of this License. -

    - -

    - However, linking a "work that uses the Library" with the Library - creates an executable that is a derivative of the Library (because it - contains portions of the Library), rather than a "work that uses the - library". The executable is therefore covered by this License. - Section 6 states terms for distribution of such executables. -

    - -

    - When a "work that uses the Library" uses material from a header file - that is part of the Library, the object code for the work may be a - derivative work of the Library even though the source code is not. - Whether this is true is especially significant if the work can be - linked without the Library, or if the work is itself a library. The - threshold for this to be true is not precisely defined by law. -

    - -

    - If such an object file uses only numerical parameters, data - structure layouts and accessors, and small macros and small inline - functions (ten lines or less in length), then the use of the object - file is unrestricted, regardless of whether it is legally a derivative - work. (Executables containing this object code plus portions of the - Library will still fall under Section 6.) -

    - -

    - Otherwise, if the work is a derivative of the Library, you may - distribute the object code for the work under the terms of Section 6. - Any executables containing that work also fall under Section 6, - whether or not they are linked directly with the Library itself. -

    - -

    - 6. - As an exception to the Sections above, you may also combine or - link a "work that uses the Library" with the Library to produce a - work containing portions of the Library, and distribute that work - under terms of your choice, provided that the terms permit - modification of the work for the customer's own use and reverse - engineering for debugging such modifications. -

    - -

    - You must give prominent notice with each copy of the work that the - Library is used in it and that the Library and its use are covered by - this License. You must supply a copy of this License. If the work - during execution displays copyright notices, you must include the - copyright notice for the Library among them, as well as a reference - directing the user to the copy of this License. Also, you must do one - of these things: -

    - -

    -

      -
    • a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - -
    • b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - -
    • c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - -
    • d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - -
    • e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. -
    - -

    - For an executable, the required form of the "work that uses the - Library" must include any data and utility programs needed for - reproducing the executable from it. However, as a special exception, - the materials to be distributed need not include anything that is - normally distributed (in either source or binary form) with the major - components (compiler, kernel, and so on) of the operating system on - which the executable runs, unless that component itself accompanies - the executable. -

    - -

    - It may happen that this requirement contradicts the license - restrictions of other proprietary libraries that do not normally - accompany the operating system. Such a contradiction means you cannot - use both them and the Library together in an executable that you - distribute. -

    - -

    - 7. You may place library facilities that are a work based on the - Library side-by-side in a single library together with other library - facilities not covered by this License, and distribute such a combined - library, provided that the separate distribution of the work based on - the Library and of the other library facilities is otherwise - permitted, and provided that you do these two things: -

    - -

    -

      -
    • a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - -
    • b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. -
    - -

    - 8. You may not copy, modify, sublicense, link with, or distribute - the Library except as expressly provided under this License. Any - attempt otherwise to copy, modify, sublicense, link with, or - distribute the Library is void, and will automatically terminate your - rights under this License. However, parties who have received copies, - or rights, from you under this License will not have their licenses - terminated so long as such parties remain in full compliance. -

    - -

    - 9. - You are not required to accept this License, since you have not - signed it. However, nothing else grants you permission to modify or - distribute the Library or its derivative works. These actions are - prohibited by law if you do not accept this License. Therefore, by - modifying or distributing the Library (or any work based on the - Library), you indicate your acceptance of this License to do so, and - all its terms and conditions for copying, distributing or modifying - the Library or works based on it. -

    - -

    - 10. - Each time you redistribute the Library (or any work based on the - Library), the recipient automatically receives a license from the - original licensor to copy, distribute, link with or modify the Library - subject to these terms and conditions. You may not impose any further - restrictions on the recipients' exercise of the rights granted herein. - You are not responsible for enforcing compliance by third parties with - this License. -

    - -

    - 11. - If, as a consequence of a court judgment or allegation of patent - infringement or for any other reason (not limited to patent issues), - conditions are imposed on you (whether by court order, agreement or - otherwise) that contradict the conditions of this License, they do not - excuse you from the conditions of this License. If you cannot - distribute so as to satisfy simultaneously your obligations under this - License and any other pertinent obligations, then as a consequence you - may not distribute the Library at all. For example, if a patent - license would not permit royalty-free redistribution of the Library by - all those who receive copies directly or indirectly through you, then - the only way you could satisfy both it and this License would be to - refrain entirely from distribution of the Library. -

    - -

    - If any portion of this section is held invalid or unenforceable under any - particular circumstance, the balance of the section is intended to apply, - and the section as a whole is intended to apply in other circumstances. -

    - -

    - It is not the purpose of this section to induce you to infringe any - patents or other property right claims or to contest validity of any - such claims; this section has the sole purpose of protecting the - integrity of the free software distribution system which is - implemented by public license practices. Many people have made - generous contributions to the wide range of software distributed - through that system in reliance on consistent application of that - system; it is up to the author/donor to decide if he or she is willing - to distribute software through any other system and a licensee cannot - impose that choice. -

    - -

    - This section is intended to make thoroughly clear what is believed to - be a consequence of the rest of this License. -

    - -

    - 12. - If the distribution and/or use of the Library is restricted in - certain countries either by patents or by copyrighted interfaces, the - original copyright holder who places the Library under this License may add - an explicit geographical distribution limitation excluding those countries, - so that distribution is permitted only in or among countries not thus - excluded. In such case, this License incorporates the limitation as if - written in the body of this License. -

    - -

    - 13. - The Free Software Foundation may publish revised and/or new - versions of the Lesser General Public License from time to time. - Such new versions will be similar in spirit to the present version, - but may differ in detail to address new problems or concerns. -

    - -

    - Each version is given a distinguishing version number. If the Library - specifies a version number of this License which applies to it and - "any later version", you have the option of following the terms and - conditions either of that version or of any later version published by - the Free Software Foundation. If the Library does not specify a - license version number, you may choose any version ever published by - the Free Software Foundation. -

    - -

    - 14. - If you wish to incorporate parts of the Library into other free - programs whose distribution conditions are incompatible with these, - write to the author to ask for permission. For software which is - copyrighted by the Free Software Foundation, write to the Free - Software Foundation; we sometimes make exceptions for this. Our - decision will be guided by the two goals of preserving the free status - of all derivatives of our free software and of promoting the sharing - and reuse of software generally. -

    - -

    - NO WARRANTY -

    - -

    - 15. - BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO - WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. - EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR - OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY - KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE - LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME - THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. -

    - -

    - 16. - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN - WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY - AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU - FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR - CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE - LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING - RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A - FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF - SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - DAMAGES. -

    - \ No newline at end of file diff --git a/modules/jala/tests/1meg.reference-win.torrent b/modules/jala/tests/1meg.reference-win.torrent deleted file mode 100644 index bfa6890a..00000000 --- a/modules/jala/tests/1meg.reference-win.torrent +++ /dev/null @@ -1 +0,0 @@ -d8:announce30:http://tracker.orf.at/announce13:creation datei1172497604e4:infod6:lengthi1048576e4:name4:1meg12:piece lengthi262144e6:pieces80:. WYT>Y. WYT>Y. WYT>Y. WYT>Yee \ No newline at end of file diff --git a/modules/jala/tests/1meg.reference.torrent b/modules/jala/tests/1meg.reference.torrent deleted file mode 100644 index 16454c90..00000000 Binary files a/modules/jala/tests/1meg.reference.torrent and /dev/null differ diff --git a/modules/jala/tests/AsyncRequest.js b/modules/jala/tests/AsyncRequest.js deleted file mode 100644 index c7033aa2..00000000 --- a/modules/jala/tests/AsyncRequest.js +++ /dev/null @@ -1,65 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -var result = undefined; - -/** - * A simple test of jala.AsyncRequest. It constructs a new AsyncRequest - * with a test function defined below that sets various properties - * of the global result object above. After evaluating the async request - * the current thread sleeps for a short period of time to wait for - * the other request to finish, and then does the testing of the result. - */ -var testAsyncRequest = function() { - var r = new jala.AsyncRequest(global, "testFunction"); - r.run("jala"); - // wait until the async request started above has finished - // before testing the result, but no longer than 1 second. - var elapsed = 0; - var interval = 5; - while (result === undefined && elapsed < 1000) { - elapsed += interval; - java.lang.Thread.sleep(interval); - } - assertNotUndefined(result); - assertEqual(result.name, "jala"); - assertEqual(result.request, req); - assertEqual(result.response, res); - assertFalse(r.isAlive()); - return; -}; - -/** - * A simple test function that assigns an object to the global - * property "result". - * @param {String} name A string to use as name - */ -var testFunction = function(name) { - result = { - name: name, - request: req, - response: res - }; - return; -}; diff --git a/modules/jala/tests/BitTorrent.js b/modules/jala/tests/BitTorrent.js deleted file mode 100644 index ac1e92bd..00000000 --- a/modules/jala/tests/BitTorrent.js +++ /dev/null @@ -1,59 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - -/** - * A simple test of jala.BitTorrent. - * FIXME: Needs resolution of issue #33 - */ -var testBitTorrent = function() { - var size = 1024 * 1024; // 1 meg - var file = new java.io.File(jala.Test.getTestFile("1meg")); - var fos = new java.io.FileOutputStream(file, false); - var channel = fos.getChannel(); - var iterations = 0; - while (channel.size() < size) { - channel.write(java.nio.ByteBuffer.allocate(1024)); - } - channel.close(); - fos.close(); - - var torrent = new jala.BitTorrent(file); - // Testing against file generated with BitTorrent.app (OS X) - torrent.set("announce", "http://tracker.orf.at/announce"); - // S3 defines a multitracker list with a single tracker item - //torrent.set("announce-list", [["http://tracker.amazonaws.com:6969/announce"]]); - torrent.setCreationDate(new Date(2007, 1, 26, 14, 46, 44)); - torrent.save(); - file["delete"](); - - try { - var torrentFile = torrent.getTorrentFile(); - var refFile = new helma.File(jala.Test.getTestFile("1meg.reference.torrent")); - assertEqual(torrentFile.readAll().trim(), refFile.readAll().trim()); - } catch (x) { - throw(x); - } finally { - torrentFile.remove(); - } - return; -}; diff --git a/modules/jala/tests/Database.js b/modules/jala/tests/Database.js deleted file mode 100644 index a2b95509..00000000 --- a/modules/jala/tests/Database.js +++ /dev/null @@ -1,163 +0,0 @@ -/** - * Contains the system's temporary directory - * @type helma.File - * @private - */ -var tmpDir = new helma.File(java.lang.System.getProperty("java.io.tmpdir")); - -/** - * Contains the server created in testServer method - * @private - */ -var server = null; - -/** - * Basic tests for jala.db.RamDatabase. All of these tests are - * valid for jala.db.FileDatabase too. - */ -var testRamDatabase = function() { - var db = new jala.db.RamDatabase("test"); - assertNotNull(db); - assertEqual(db.getName(), "test"); - assertEqual(db.getDatabasePath(), "mem:test"); - assertEqual(db.getUrl(), "jdbc:h2:mem:test"); - // test connection to database - var conn = db.getConnection(); - assertNotNull(conn); - assertTrue(conn instanceof helma.Database); - - // create a table - db.createTable("test", [ - { - name: "id", - type: java.sql.Types.INTEGER, - nullable: false, - unique: true - }, - { - name: "name", - type: java.sql.Types.VARCHAR, - length: 255 - } - ], "id"); - - // test if the table exists - assertTrue(db.tableExists("test")); - - // dump database - var dumpFile = new helma.File(tmpDir, "backup.test.sql"); - assertTrue(db.dump(dumpFile)); - assertTrue(dumpFile.exists()); - assertTrue(dumpFile.getLength() > 0); - // remove dump file again - dumpFile.remove(); - - // drop table - db.dropTable("test"); - assertFalse(db.tableExists("test")); - - // test db shutdown - db.shutdown(); - assertThrows(function() { - conn.query("select 1 = 1"); - }, Packages.org.h2.jdbc.JdbcSQLException); - return; -}; - -/** - * Basic tests for jala.db.FileDatabase that are different to - * jala.db.RamDatabase - */ -var testFileDatabase = function() { - var db = new jala.db.FileDatabase("test", tmpDir); - assertNotNull(db); - assertEqual(db.getName(), "test"); - assertEqual(db.getDirectory(), tmpDir); - - var dbDir = new helma.File(tmpDir, "test"); - assertEqual(db.getDatabasePath(), "file:" + dbDir.getAbsolutePath()); - assertEqual(db.getUrl(), "jdbc:h2:file:" + dbDir.getAbsolutePath()); - - // execute sql script (need to do that, otherwise the backup won't - // work because the database is empty) - var sqlFile = jala.Test.getTestFile("Database.script.sql"); - assertTrue(db.runScript(sqlFile)); - assertTrue(db.tableExists("test")); - - // test backup - var backupFile = new helma.File(tmpDir, "backup.zip"); - assertTrue(db.backup(backupFile)); - assertTrue(backupFile.exists()); - assertTrue(backupFile.getLength() > 0); - - // remove the database - db.remove(); - assertFalse((new helma.File(db.getDirectory(), db.getName() + ".data.db")).exists()); - assertFalse((new helma.File(db.getDirectory(), db.getName() + ".index.db")).exists()); - assertFalse((new helma.File(db.getDirectory(), db.getName() + ".trace.db")).exists()); - - // test restore - assertTrue(db.restore(backupFile)); - assertTrue(db.tableExists("test")); - - // remove backup file and database - backupFile.remove(); - db.remove(); - - return; -}; - -var testServer = function() { - server = new jala.db.Server(tmpDir); - // test default config - assertEqual(tmpDir, server.getDirectory()); - assertEqual(server.getPort(), 9092); - assertFalse(server.useSsl()); - assertFalse(server.isPublic()); - assertFalse(server.createOnDemand()); - - // test setting config properties - server.useSsl(true); - assertTrue(server.useSsl()); - server.isPublic(true); - assertTrue(server.isPublic()); - server.createOnDemand(true); - assertTrue(server.createOnDemand()); - - // reset back some of them - server.useSsl(false); - assertFalse(server.useSsl()); - server.isPublic(false); - assertFalse(server.isPublic()); - - // start the server - assertTrue(server.start()); - - // test connection properties (this also includes testing - // of server.getUrl()) - var props = server.getProperties("test", "test", "1111"); - assertEqual(props.getProperty("test.url"), "jdbc:h2:tcp://localhost:9092/test"); - assertEqual(props.getProperty("test.driver"), "org.h2.Driver"); - assertEqual(props.getProperty("test.user"), "test"); - assertEqual(props.getProperty("test.password"), "1111"); - - var conn = server.getConnection("test", "test", "1111"); - assertNotNull(conn); - - // stop the server - assertTrue(server.stop()); - // and remove the file database created above - var db = new jala.db.FileDatabase("test", tmpDir, "test", "1111"); - db.remove(); - return; -}; - -/** - * Stuff to do on cleanup - */ -var cleanup = function() { - if (server != null) { - server.stop(); - } - return; -}; diff --git a/modules/jala/tests/Database.script.sql b/modules/jala/tests/Database.script.sql deleted file mode 100644 index 7beab74d..00000000 --- a/modules/jala/tests/Database.script.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE test (id INTEGER NOT NULL, name VARCHAR(255), PRIMARY KEY (id)); -INSERT INTO test (id, name) VALUES (1, 'jala'); -INSERT INTO test (id, name) VALUES (2, 'Database'); -INSERT INTO test (id, name) VALUES (3, 'Test'); diff --git a/modules/jala/tests/DnsClient.js b/modules/jala/tests/DnsClient.js deleted file mode 100644 index 19ceb720..00000000 --- a/modules/jala/tests/DnsClient.js +++ /dev/null @@ -1,66 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -var dnsClient = new jala.DnsClient("68.12.16.25"); -var result; - -/** - * Testing default mode (A records) - */ -var testAQuery = function() { - result = dnsClient.query("nomatic.org"); - assertEqual(result.length, 1); - assertEqual(result[0].ipAddress, "213.129.249.34"); - return; -}; - -/** - * Testing SOA record queries - */ -var testSoaQuery = function() { - result = dnsClient.query("nomatic.org", jala.DnsClient.TYPE_SOA); - assertEqual(result.length, 1); - assertEqual(result[0].email, "hostmaster.nomatic.org"); - return; -}; - -/** - * Testing MX record queries - */ -var testMxQuery = function() { - result = dnsClient.query("nomatic.org", jala.DnsClient.TYPE_MX); - assertEqual(result.length, 1); - assertEqual(result[0].mx, "grace.nomatic.org"); - return; -}; - -/** - * Testing NS record queries - */ -var testNsQuery = function() { - result = dnsClient.query("nomatic.org", jala.DnsClient.TYPE_NS); - assertEqual(result.length, 3); - // can't test single records as their order changes unpredictably - return; -}; diff --git a/modules/jala/tests/Form.fileupload.doc b/modules/jala/tests/Form.fileupload.doc deleted file mode 100644 index 40b88854..00000000 Binary files a/modules/jala/tests/Form.fileupload.doc and /dev/null differ diff --git a/modules/jala/tests/Form.imageupload.jpg b/modules/jala/tests/Form.imageupload.jpg deleted file mode 100644 index 84a3d709..00000000 Binary files a/modules/jala/tests/Form.imageupload.jpg and /dev/null differ diff --git a/modules/jala/tests/Form.js b/modules/jala/tests/Form.js deleted file mode 100644 index 0fee8358..00000000 --- a/modules/jala/tests/Form.js +++ /dev/null @@ -1,460 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - -/** - * a global variable containing the form instance - * @type jala.Form - */ -var form; - - -/** - * Create and configure the form object - */ -var setup = function() { - form = jala.Form.create(getConfig(), new DataObject()); - // form.render(); // show the test form - return; -}; - - -/** - * Test the form rendering mechanism - */ -var testFormRender = function() { - var html = new jala.HtmlDocument(form.renderAsString()); - var list = html.getAll("*"); - - var idx = 2; - assertEqual(list[idx].name, "form"); - assertAttribute(list[idx].attributes, "id", "test"); - assertAttribute(list[idx].attributes, "class", "form"); - assertAttribute(list[idx].attributes, "name", "test"); - assertAttribute(list[idx].attributes, "enctype", "multipart/form-data"); - assertAttribute(list[idx].attributes, "method", "post"); - - - // alias / input - assertEqual(list[++idx].name, "div"); - assertAttribute(list[idx].attributes, "id", "testAlias"); - assertAttribute(list[idx].attributes, "class", "component require"); - - assertEqual(list[++idx].name, "label"); - assertAttribute(list[idx].attributes, "for", "testAliasControl"); - - assertEqual(list[++idx].name, "input"); - assertAttribute(list[idx].attributes, "id", "testAliasControl"); - assertAttribute(list[idx].attributes, "class", "input"); - assertAttribute(list[idx].attributes, "type", "text"); - assertAttribute(list[idx].attributes, "maxlength", "10"); - assertAttribute(list[idx].attributes, "name", "alias"); - assertAttribute(list[idx].attributes, "size", "20"); - - assertEqual(list[++idx].name, "div"); - assertEqual(list[idx].value, "Enter alias."); - assertAttribute(list[idx].attributes, "class", "helpText"); - - - // desc / textarea - assertEqual(list[++idx].name, "div"); - assertAttribute(list[idx].attributes, "id", "testDesc"); - assertAttribute(list[idx].attributes, "class", "component require"); - - assertEqual(list[++idx].name, "label"); - assertAttribute(list[idx].attributes, "for", "testDescControl"); - - assertEqual(list[++idx].name, "textarea"); - assertAttribute(list[idx].attributes, "id", "testDescControl"); - assertAttribute(list[idx].attributes, "class", "textarea"); - assertAttribute(list[idx].attributes, "name", "desc"); - assertAttribute(list[idx].attributes, "cols", "30"); - assertAttribute(list[idx].attributes, "rows", "3"); - - - - // pushdate / date - assertEqual(list[++idx].name, "div"); - assertAttribute(list[idx].attributes, "id", "testPushdate"); - assertAttribute(list[idx].attributes, "class", "component require"); - - assertEqual(list[++idx].name, "label"); - assertAttribute(list[idx].attributes, "for", "testPushdateControl"); - - assertEqual(list[++idx].name, "input"); - assertAttribute(list[idx].attributes, "id", "testPushdateControl"); - assertAttribute(list[idx].attributes, "class", "date"); - assertAttribute(list[idx].attributes, "type", "text"); - assertAttribute(list[idx].attributes, "name", "pushdate"); - - - // isonline / checkbox - assertEqual(list[++idx].name, "div"); - assertAttribute(list[idx].attributes, "id", "testIsonline"); - assertAttribute(list[idx].attributes, "class", "component optional"); - - assertEqual(list[++idx].name, "label"); - assertAttribute(list[idx].attributes, "for", "testIsonlineControl"); - - assertEqual(list[++idx].name, "input"); - assertAttribute(list[idx].attributes, "id", "testIsonlineControl"); - assertAttribute(list[idx].attributes, "type", "checkbox"); - assertAttribute(list[idx].attributes, "class", "checkbox"); - assertAttribute(list[idx].attributes, "name", "isonline"); - assertAttribute(list[idx].attributes, "value", "1"); - - - // category / select - assertEqual(list[++idx].name, "div"); - assertAttribute(list[idx].attributes, "id", "testCategory"); - assertAttribute(list[idx].attributes, "class", "component optional"); - - assertEqual(list[++idx].name, "label"); - assertAttribute(list[idx].attributes, "for", "testCategoryControl"); - - assertEqual(list[++idx].name, "select"); - assertAttribute(list[idx].attributes, "id", "testCategoryControl"); - assertAttribute(list[idx].attributes, "class", "select"); - assertAttribute(list[idx].attributes, "name", "category"); - assertAttribute(list[idx].attributes, "size", "1"); - - assertEqual(list[++idx].name, "option"); - assertAttribute(list[idx].attributes, "value", "cat0"); - - assertEqual(list[++idx].name, "option"); - assertAttribute(list[idx].attributes, "value", "cat1"); - - assertEqual(list[++idx].name, "option"); - assertAttribute(list[idx].attributes, "value", "cat2"); - - assertEqual(list[++idx].name, "option"); - assertAttribute(list[idx].attributes, "value", "cat3"); - - - // fieldset - assertEqual(list[++idx].name, "fieldset"); - - assertEqual(list[++idx].name, "legend"); - assertEqual(list[idx].value, "a fieldset"); - - - // fileupload - assertEqual(list[++idx].name, "div"); - assertAttribute(list[idx].attributes, "id", "testFileupload"); - assertAttribute(list[idx].attributes, "class", "component optional"); - - assertEqual(list[++idx].name, "label"); - assertAttribute(list[idx].attributes, "for", "testFileuploadControl"); - - assertEqual(list[++idx].name, "input"); - assertAttribute(list[idx].attributes, "id", "testFileuploadControl"); - assertAttribute(list[idx].attributes, "class", "file"); - assertAttribute(list[idx].attributes, "type", "file"); - assertAttribute(list[idx].attributes, "accept", "application/msword"); - assertAttribute(list[idx].attributes, "name", "fileupload"); - - - // imageupload - assertEqual(list[++idx].name, "div"); - assertAttribute(list[idx].attributes, "id", "testImageupload"); - assertAttribute(list[idx].attributes, "class", "component optional"); - - assertEqual(list[++idx].name, "label"); - assertAttribute(list[idx].attributes, "for", "testImageuploadControl"); - - assertEqual(list[++idx].name, "input"); - assertAttribute(list[idx].attributes, "id", "testImageuploadControl"); - assertAttribute(list[idx].attributes, "class", "image"); - assertAttribute(list[idx].attributes, "type", "file"); - assertAttribute(list[idx].attributes, "name", "imageupload"); - - - // submit - assertEqual(list[++idx].name, "div"); - assertAttribute(list[idx].attributes, "id", "testSubmit"); - assertAttribute(list[idx].attributes, "class", "component"); - - assertEqual(list[++idx].name, "input"); - assertAttribute(list[idx].attributes, "id", "testSubmitControl"); - assertAttribute(list[idx].attributes, "class", "submit"); - assertAttribute(list[idx].attributes, "name", "submit"); - assertAttribute(list[idx].attributes, "value", "Submit this form"); - assertAttribute(list[idx].attributes, "type", "submit"); - - - // cancel - assertEqual(list[++idx].name, "div"); - assertAttribute(list[idx].attributes, "id", "testCancel"); - assertAttribute(list[idx].attributes, "class", "component"); - - assertEqual(list[++idx].name, "input"); - assertAttribute(list[idx].attributes, "id", "testCancelControl"); - assertAttribute(list[idx].attributes, "class", "button"); - assertAttribute(list[idx].attributes, "name", "cancel"); - assertAttribute(list[idx].attributes, "value", "Cancel edit"); - assertAttribute(list[idx].attributes, "type", "button"); - - return; -} - - -/** - * Test the form validation mechanism - */ -var testFormValidate = function() { - var reqData = getRequestData(); - - // default userinput values that should validate - var tracker = form.validate(reqData); - assertFalse(tracker.hasError()); - - // now try invalid values in userinput: - reqData["alias"] = "a"; - reqData["desc"] = ""; - reqData["pushdate"] = "17.5.2007"; - reqData["category"] = "invalidOption"; - tracker = form.validate(reqData); - assertTrue(tracker.hasError()); - assertEqual(tracker.errors["alias"], "Alias is too short."); - assertEqual(tracker.errors["desc"], "Please enter text into this field."); - assertEqual(tracker.errors["pushdate"], "This date cannot be parsed."); - assertEqual(tracker.errors["category"], "Please select a valid option."); - - // reset to default userinput: - reqData = getRequestData(); - // require a smaller image: - form.components.uploadfieldset.components.imageupload.require("maxwidth", 100, "Maximum width exceeded."); - tracker = form.validate(reqData); - assertTrue(tracker.hasError()); - assertEqual(tracker.errors["imageupload"], "Maximum width exceeded."); - // undo image restriction: - form.components.uploadfieldset.components.imageupload.require("maxwidth", 200, "Maximum width exceeded."); - tracker = form.validate(reqData); - assertFalse(tracker.hasError()); - - return; -}; - - -/** - * Test the form rendering mechanism in the case of an error - */ -var testFormRenderWithError = function() { - var reqData = getRequestData(); - reqData["alias"] = "a"; - var tracker = form.validate(reqData); - - var html = new jala.HtmlDocument(form.renderAsString()); - var list = html.getAll("*"); - assertEqual(list[4].name, "div"); - assertEqual(list[4].value, "Alias is too short."); - assertAttribute(list[4].attributes, "class", "errorText"); -}; - - -/** - * Test the form save mechanism - */ -var testFormSave = function() { - var dataObj = form.getDataObject(); - - var reqData = getRequestData(); - var tracker = form.validate(reqData); - assertFalse(tracker.hasError()); - form.save(); - assertEqual(dataObj.alias, "aliasValue"); - assertEqual(dataObj.getProperty("desc"), "descriptionValue"); - assertEqual(dataObj.pushdate.toString(), new Date(2007, 4, 17, 11, 32, 0).toString()); - assertEqual(dataObj.isonline, 1); - assertEqual(dataObj.getProperty("category"), "cat2"); - - return; -} - - - -/** - * Helper function to dump an html element to the response - * @param {Object} el - */ -var debugElement = function(el) { - res.write("" + el.name + " (" + el.value + ")
    "); - if (el.attributes) { - var attrList = el.attributes; - for (var i=0; i"); - } - } -}; - - -/** - * Helper function to assert that a given attribute exists - * in an element - * @param {Array} attrList Array with attribute objects - * @param {String} name Name of attribute - * @param {String} value Value of attribute - */ -var assertAttribute = function(attrList, name, value) { - for (var i=0; iHello, World!' + - 'foo' + - '' + - 'foobar' + - ''; - -/** - * Simple test of the HtmlDocument.getLinks method. - * An instance of HtmlDocument is created from a very - * simple HTML source. The result of getLinks is then - * evaluated and tested. - */ -var testGetLinks = function() { - var html = new jala.HtmlDocument(source); - var links = html.getLinks(); - assertEqual(links.constructor, Array); - assertEqual(links.length, 3); - assertEqual(links[0].constructor, Object); - for (var i in links) { - assertNotUndefined(links[i].url); - assertNotUndefined(links[i].text); - } - assertEqual(links[0].url, "http://localhost/1"); - assertEqual(links[0].text, "foo"); - assertEqual(links[1].url, "http://localhost/2"); - assertEqual(links[1].text, "bar"); - assertEqual(links[2].url, "http://localhost/3"); - assertEqual(links[2].text, "foobar"); - return; -}; - -/** - * Simple test of the HtmlDocument.geAll method. - * An instance of HtmlDocument is created from a very - * simple HTML source. The result of getAll is then - * evaluated and tested. - */ -var testGetAll = function() { - var names = ["html", "head", "title", "body", "h1", "a", "div", "a", "a"]; - var html = new jala.HtmlDocument(source); - var list = html.getAll("*"); - for (var i in list) { - assertNotUndefined(list[i].name); - assertEqual(list[i].name, names[i]); - } - assertEqual(list[2].value, "Test"); - assertEqual(list[4].value, "Hello, World!"); - assertEqual(list[5].value, "foo"); - assertEqual(list[7].value, "bar"); - assertEqual(list[8].value, "foobar"); - assertEqual(html.getAll("h1")[0].value, "Hello, World!"); - return; -}; diff --git a/modules/jala/tests/I18n.js b/modules/jala/tests/I18n.js deleted file mode 100644 index 4305f06a..00000000 --- a/modules/jala/tests/I18n.js +++ /dev/null @@ -1,136 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * Declare which test methods should be run in which order - * @type Array - * @final - */ - -var oldMessages; - -/** - * Called before running the tests - */ -var setup = function() { - // save any currently used message bundle before - // creating the one for this test - oldMessages = jala.i18n.getMessages(); - // setup the test message bundle - var messages = {}; - messages.de_AT = { - "Hello, World!": "Hallo, Welt!", - "This is {0}.": "Das ist {0}.", - "You've got one new mail.": "Du hast eine neue E-Mail.", - "You've got {0} new mails.": "Du hast {0} neue E-Mails." - }; - // tell jala where to find the messages - jala.i18n.setMessages(messages); - // assign a method for retrieving the locale for translation - jala.i18n.setLocaleGetter(new Function("return res.meta.locale;")); - // set the locale to use by jala.i18n - res.meta.locale = new java.util.Locale("de", "AT"); - return; -}; - - -/** - * Called after tests have finished. This method will be called - * regarless whether the test succeeded or failed. - */ -var cleanup = function() { - // restore any previous message set - jala.i18n.setMessages(oldMessages); - return; -}; - -/** - * Tests for formatMessage - */ -var testFormatMessage = function() { - var msg = "Es ist jetzt {0,date,EEEE, dd. MMMM yyyy, HH:mm} Uhr."; - var args = [new Date(2007, 1, 8, 17, 58)]; - var result = jala.i18n.formatMessage(msg, args); - var expected = "Es ist jetzt Donnerstag, 08. Februar 2007, 17:58 Uhr."; - assertEqual(expected, result); - return; -}; - -/** - * Tests for gettext() - */ -var testGettext = function() { - assertEqual("Hallo, Welt!", gettext("Hello, World!")); - // test not found message key - assertEqual("Hello You!", gettext("Hello You!")); - // test gettext with additional replacement value - assertEqual("Das ist Jala I18n.", gettext("This is {0}.", "Jala I18n")); - return; -}; - -/** - * Tests for ngettext() - */ -var testNgettext = function() { - // zero - assertEqual("Du hast 0 neue E-Mails.", - ngettext("You've got one new mail.", - "You've got {0} new mails.", - 0)); - // one - assertEqual("Du hast eine neue E-Mail.", - ngettext("You've got one new mail.", - "You've got {0} new mails.", - 1)); - // more - assertEqual("Du hast 23 neue E-Mails.", - ngettext("You've got one new mail.", - "You've got {0} new mails.", - 23)); - return; -}; - -/** - * Tests for message macro - */ -var testMessageMacro = function() { - // singular - var skin = createSkin('<% message text="You\'ve got one new mail." %>'); - assertEqual("Du hast eine neue E-Mail.", renderSkinAsString(skin)); - - res.handlers.testHandler = {value: 0}; - // value replacement using testHandler - skin = createSkin('<% message text="You\'ve got {0} new mails." values="testHandler.value" %>'); - assertEqual("Du hast 0 neue E-Mails.", renderSkinAsString(skin)); - // plural including replacement using testHandler - res.handlers.testHandler.value = 23; - skin = createSkin('<% message text="You\'ve got one new mail." plural="You\'ve got {0} new mails." values="testHandler.value" %>'); - assertEqual("Du hast 23 neue E-Mails.", renderSkinAsString(skin)); - // using a value of the param object passed to the skin - // FIXME: appearently this doesn't work, but why? - /* - skin = createSkin('<% message text="You\'ve got one new mail." plural="You\'ve got {0} new mails." values="param.spam" %>'); - assertEqual("Du hast 45 neue E-Mails.", renderSkinAsString(skin, {spam: 45})); - */ -}; diff --git a/modules/jala/tests/ImageFilter.js b/modules/jala/tests/ImageFilter.js deleted file mode 100644 index cb588788..00000000 --- a/modules/jala/tests/ImageFilter.js +++ /dev/null @@ -1,100 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - -/** - * Called after tests have finished. This method will be called - * regarless whether the test succeeded or failed. - */ -var cleanup = function() { - var tempDir = new helma.File(java.lang.System.getProperty("java.io.tmpdir")); - var names = ["sharpen", "unsharpMask", "gaussianBlur"]; - var file; - for (var i=0; iSubclasses:
    -' . -# join('
    -', -# map ({"$_"} -# map ( { s/\s*(\w+)\s*/$1/; $_} @{@_->[0]}) -# ) -# ) . '

    ' -# }; -# -# $CLASS_ATTRS_MAP{with} = -# sub { -# 'This class has a \'@with\' attribute' -# }; -#}; - -# Method attributes -# eval { -# -# Uncomment this to allow the filename to be displayed for -# each function -# -# $METHOD_ATTRS_MAP{filename} = -# sub { -# '

    Filename: ' . $_[0] . '

    ' -# }; -# $CLASS_ATTRS_MAP{filename} = $METHOD_ATTRS_MAP{filename}; -# -# }; -# - diff --git a/modules/jala/util/HopKit/JSDoc/CHANGES b/modules/jala/util/HopKit/JSDoc/CHANGES deleted file mode 100644 index deae94f5..00000000 --- a/modules/jala/util/HopKit/JSDoc/CHANGES +++ /dev/null @@ -1,605 +0,0 @@ -JSDoc 1.9.9.2 -============= - -- Fixed disappearing argument list for package-style class constructors - -JSDoc 1.9.9.1 -============= - -- Fixed bug in template dir designation that caused JSDoc to crash if - run from an absolute path - -JSDoc 1.9.9 -=========== - -- Added a commandline parameter for supplying a template directory - -- Adding sorting of class names on overview-summary-$filename.js - (sf.net bug #1416564) - -- Fix for broken anchors from the overview-summary-$filename page to static - methods (SF.net bug #1416543) - -JSDoc 1.9.8.1 -============= - -- Don't touch the file source (src) when processing the file overview data - -- Pick up functions as constructors of the @class tag is used - -JSDoc 1.9.8 -=========== - -- Allow the @base tag to accept the form: @base ClassName URL (RFE 1114510) - -- Be more lenient with @param and @return types (RFE 1104728) - -- Corrected CSS error, changed "pts" to "pt" - -JSDoc 1.9.7 -=========== - -- Added "--no-lexical-privates" option to ignore locally-defined values - from within constructors - -- Fixed linking to static fields/methods - -JSDoc 1.9.6.2 -============= - -- Set correct permissions on files in packaging script - -- Fixed compile error on some versions of perl - -- Create distinct anchors for static methods and fields in HTML so that - if there is a static and instance method of the same name, the links work - correctly - -JSDoc 1.9.6.1 -============= - -- Updated unit tests for clearing of function contents - -- Removed collapsing of string literals; this was originally added for version - 1.9.5.1 to avoid segfaults, but the decision has been made that it is up - to the user to use a version of perl that doesn't segfault instead of - trying to work around it in perl code. - -- Added (experimental) @exec tag for initialization blocks that should be 'run' - -JSDoc 1.9.6 -=========== - -- Fix for incorrect return type and parameter types for static method - listing in file overview - -- Clear out unused nested functions with the preprocessor to avoid problems - -JSDoc 1.9.5.8 -============= - -- Yet another fix for __defineGetter__ and __defineSetter__ - -JSDoc 1.9.5.7 -============= - -- Fixed bug in syntax highlighting for single-line inline comments - -- Fixed bug in preprocessing of __defineGetter__ and __defineSetter__ - -JSDoc 1.9.5.6 -============= - -- Fixed incorrect listing of private classes when --private not enabled - -JSDoc 1.9.5.4 -============= - -- Corrected bug with function assignment inside constructor - -JSDoc 1.9.5.3 -============= - -- Added ability to specify different file extensions on commandline - -JSDoc 1.9.5.2 -============= - -- Fixed formatted text munging for @class description - -- Added support for @package tag to be used with XMI export - -JSDoc 1.9.5.1 -============= - -- Added collapsing of string literals during preprocessing - -JSDoc 1.9.5 -=========== - -- Added listing of global (static) methods to file overview summary, code - submitted by Jeremy Gillick - -- Allow a global variable to be defined as a class from an anonymous - function declaration - -JSDoc 1.9.4.2.1 -=============== - -- Further fix for typed parameter names starting with a dollar sign - -JSDoc 1.9.4.2 -============= - -- Added ability to handle parameter names starting with a dollar sign - -JSDoc 1.9.4.1 -============= - -- Only use the first sentence for file and class summary on the - overview pages - -- Add a non-breaking space in the overview summary tables when there is no - appropriate value to display - -JSDoc 1.9.4 -=========== - -- If there are multiple source files documented, the index page defaults - to the overview summary for the main frame - -- Made JSDoc site link open in parent frame - -- Added overview and file summary tables (similar to package overview table - in JavaDoc) - -JSDoc 1.9.3.1 -============= - -- Fixed duplicate class-tree output - -JSDoc 1.9.3 -=========== - -- Added alpha release of XML and XMI output formats - -- Upgrade a function to a class if the @base tag is used - -- Fixed issue with sub-package nested classes requiring the @addon tag - -- Added the implicit "Object" class to the inheritance tree, as well as - other classes that are referenced but not defined - -JSDoc 1.9.2.1 -============= - -- Added @addon tag, which is used when adding static methods to core classes - or classes not defined within the files being documented - -- Fix for the base class of nested classes not being properly set - -- Fix for infinite recursion when all classes are private - - -JSDoc 1.9.2 -=========== - -- Removed unecessary table from overview-summary.tmpl - -- Added the @ignore tag to allow total hiding of functions - -- Fix for incorrect marking of methods as void when the return value is - enclosed in parentheses - -- Fix so that methods with a @return tag but without a return statement - are not marked as void - -- Fixed issue with not all files being listed in the file listing - - -JSDoc 1.9.1.3 -============= - -- Fixed issue with backslashes in path - -- Fixed issue with

     tags and JavaScript code within fileoverview sections
    -
    -- Made documented versions of a method take precedence over a 
    -  non-documented version
    -
    -- Added support for prototype assignment without parentheses
    -
    -- Added new @return label {type typeLink} Description... syntax
    -
    -JSDoc 1.9.1.2
    -=============
    -
    -- Further improvements to mark_void_method
    -
    -- Improved handling of dynamically-bound methods within functions
    -
    -- Improved handling of erroneous documenting of 'this'
    -
    -- Fixed quoting on error message
    -
    -- Added a few new unit tests for testing general behaviour
    -
    -JSDoc 1.9.1.1
    -=============
    -
    -- Fix for embarrassing bug in mark_void_method
    -
    -JSDoc 1.9.1
    -===========
    -
    -- Fix for the incorrect void marking of methods that return a string literal
    -
    -- Fix to stop dynamic prototyping from adding non-dynamic classes
    -
    -- Added ability to add a link to parameter-type data, as follows:
    -    @param {TypeName http://my.link.com/} myParam Description of parameter
    -
    -JSDoc 1.9
    -=========
    -
    -- Added support for a Constant Values page like in Javadoc
    -
    -- Added support for private classes (by marking the constructor with
    -  the @private attribute)
    -
    -- Added a "File" page with links to it in the navbar. The "File" page includes
    -  the file overview if one has been supplied, as well as the source view
    -  (unless jsdoc has been invoked with the --no-sources flag)
    -
    -- Added a --no-sources commandline option to not show the sourcecode for
    -  the JavaScript files 
    -
    -- Added --package-naming commandline option, which specifies that the path 
    -  leading to each source file will be preserved. This allows for the same 
    -  filename to be used in different directories. Using the same class name
    -  in different packages is _not_ supported (yet)
    -
    -- Added JSDoc link and creation time in the footer of each page
    -
    -- Added support for @member tag to explicitly mark a method as a member of
    -  a class
    -
    -JSDoc 1.8.4
    -===========
    -
    -- Added step in prepocessing to attempt to add missing @constructor tags where
    -  the 'new' operator is used in combination with a function name elsewhere
    -  in the source.
    -
    -- Only the first @extends marking (or assignment of an instance to a sub-
    -  class's prototype) will be used in determining the base class of a class.
    -
    -- Updated test.js to show off more features of JSDoc, as well as a general 
    -  clean-up.
    -    
    -- Changed the parser to consider a method to be a class declaration if its
    -  documentation contains a @class tag (in addition to the @constructor tag)
    -
    -JSDoc 1.8.3.1
    -=============
    -
    -- Some general code cleanup and refactoring. 
    -
    -- Properly fixed marking of void/non-void methods, and at the same time
    -  re-introduced recursive regexes (this time non-dynamic, as dynamic seem
    -  to be much too unstable)
    -
    -JSDoc 1.8.3
    -===========
    -
    -- Changed the handling for __defineGetter__ and __defineSetter__
    -  to define a property instead of a method in the documentation
    -
    -- Fixed bug in parse_jsdoc_comment that didn't allow for email addresses
    -  to be entered verbatim (instead, the domain of the address was parsed
    -  as a tag)
    -
    -- Re-did the @fileoverview parsing, now other tags and inner {@link...} 
    -  tags are included. Additionally, if only one file is processed and there
    -  is no project overview file included, the file's overview (if it exists)
    -  is used as the project overview. Thanks to Robert Flaherty for input
    -  and bug reports on this issue.
    -
    -JSDoc 1.8.2.1
    -=============
    -
    -- Got rid of extra '*' with @fileoverview
    -
    -JSDoc 1.8.2
    -=============
    -
    -- Fixed bug where other @tags were included as part of the @fileoverview
    -
    -- Added support for @version in method documentation
    -
    -- Partial fix for incorrect marking of void methods
    -
    -- Made field and return @type handling more robust and flexible
    -
    -JSDoc 1.8.1
    -===========
    -
    -- Added @extends as a synonym for @base
    -
    -- Fixed doubled-up 
      tags in hierarchy tree code (thanks to Robert Flaherty) - -- Fixed bug where a class's base class would not get recorded if - there was a forward assignment of a static value to the class - (thanks to Robert Flaherty) - - -JSDoc 1.8 -========= - -- Remove the GLOBALS class if it is empty - -- Fixed case-sensitive sort in index - -- Added support for comments with long blocks of '*'s in the opening and - closing of the doc string - -- Added sourcecode view - -- Fixed bug where named anonymous functions were not recognized as methods - when assigned to prototypes - -- Allow for singletons to be declared with var - -- Allow for binding static properties to classes before they are defined - -- Added @overviewfile attribute for class documentation, inlines html or - textfiles into the documentation - -- Added beginnings of unit testing - -- Don't add 'constructor' as an instance or class property - -- Added an @overviewfile tag which can be put in an independent - jsdoc-comment block at the top of each file. This results in a project - overview page for each file with an overview, similar to JavaDoc's - package pages. - -- Added support for Mozilla's __defineGetter__ and __defineSetter__ - -- Return type for methods is now Object, and is displayed instead of the - 'function' declaration. The 'void' type is shown if no return can be - found in the function and no other type is defined. The defaulting to - Object also goes for fields, and is shown instead of the 'var' declaration - -- Allow usage of the {@link url label} construct for the @type tag - - -JSDoc 1.7.2.1 -============= - -- Fixed segfault problem in huge constructors with deconstruct_constructor - selection regex - - -JSDoc 1.7.2 -=========== - -- Added a @class tag to constructors, for providing class-specific information - -- Added handling for Singleton classes - -- Added handler for @base tag to denote inheritance - -JSDoc 1.7.1.4 -============= - -- Fixed bug introduced by refactoring of &format_link - -JSDoc 1.7.1.3 -============= - -- Added workaround in &format_link for apparent bug in some builds of - perl 5.8.0 - -- Fixed bug in handling of --recursive (was always recursive) - -JSDoc 1.7.1.2 -============= - -- Fixed problems with new preprocessor when confronted with nested classes - -JSDoc 1.7.1.1 -============= - -- Fixed bug where {@link}s inside of @params weren't processed - -JSDoc 1.7.1 -=========== - -- Added --quiet switch and message to signify ending of successful execution - -- Fixed problem with perl segfaulting on big class prototype block definitions - -- Fixed incorrectly formatted {@link}s nested in other @attributes - -- Added preprocessor for handling private methods to replace bulky - and buggy evaluate_constructor method - -JSDoc 1.7 -========= - -- Added usage of strict and warnings in JSDoc.pm - -- Added ability to set type information for method parameters - (e.g. /** @param {String} userName The name of the current user */ ) - -- Added support for class prototype initialization blocks (finally!) - -JSDoc 1.6.3.1 -============= - -- Fixed bug where static fields initialized to 0 are not picked up - -JSDoc 1.6.3 -=========== - -- Removed the constraint that a nested class constructor must be marked - with the @constructor attribute - -- Allow @constructor attribute to mark nested class constructors which would - otherwise be considered static methods - -- Allow newlines as well as semi-colon for line-endings - -- Allow a leading '$' for field names - - -JSDoc 1.6.2.1 -============= - -- Fixed splicing error for nested classes, thanks again to jdber - - -JSDoc 1.6.2 -=========== - -- Carry over overridden method description attributes even if there is - no text description to carry over - -- Improved HTML in main.tmpl - -- Fixed infinite loop and recognition for when static inner class construct is - used (thanks to jdber for the patch) - -- Added a Nested Class Summary section to the output documentation to display - inner classes - -JSDoc 1.6.1.1 -============= - -- Fixed bug in carrying over description of overridden methods - -JSDoc 1.6.1 -=========== - -- Improved the format_link function in jsdoc.pl so that {@links} will - not be made to non-existent resources, and parentheses are not placed - after a field name (as opposed to a method name) - -- Carry over method documentation for overridden methods if no new - documentation has been supplied for the method. This is in following with - javadoc functionality - -- Fixed /* functionality(whatever) bug - -- Fixed remaining problems with comments inside of parameter lists - -JSDoc 1.6 -========= - -- Big cleanup in jsdoc.pl in terms of writing templates to file - -- Fixed bug where multi-line @params don't work - -- Added filename-scoped frame, as well as the name of the filename for - each class - -- Improved the linking implementation for @link and @see to do a better job - in terms of not building broken links - -JSDoc 1.5.2 -=========== - -- Changed the name '[default context]' for non-class functions to be - GLOBALS, also made this name configurable with command-line parameters - -- Made jsdoc easily runnable from anywhere on the filesystem, without - requiring installing JSDoc.pm in the @INC - -JSDoc 1.5.1 -=========== - -- Added support for @requires in methods - -- Generic '@' attributes now work for constructors, such as @see and @throws. - Also added support for @return and @returns for constructors - -- Fixed the @link construct to allow custom labels - -- Added standard support for @author in methods as well as classes - (Thanks for Rainer Eschen for bringing me to my senses) - -- Fixed spacing for @author attributes - - -JSDoc 1.5 -=========== - -- Fixed bug that would break HTML links within documentation - -- Fixed bug in path to logo in IMG tags - -- Added support for type information for both methods and fields - -- Added suppport for @private in instance fields - -- Fixed bug where private methods would show up in the inherited methods list - in subclasses - -- Private class methods are now also supported - -- Method parameters details are displayed in the same order as the parameter - list for a method - -- Moved more info into the 'vars' member of methods, and away from the parser - -- Added @final (with synonym @const) for class and instance properties - -- Fix in parser where string literals bound to classes in a constructor were - not caught by the parser - - - -JSDoc 1.4 -========= - -- Added @attributes: @author, @deprecated, @see, @version, @requires, @throws - -- Updated pod (removed documentation for non-existant parse_jsdoc_source, -added a small example) - -- Added function to reset the parser (reset_parser) - -- Fixed bug where the same property could be bound to a class's prototype -more than once - -- Fixed bug where embedded // comments would break the parser - -- Added ability to set project name, page footer, logo and project summary -(thanks to Jeff Conrad for code and suggestions) - -- Added overview summary (thanks to Jeff Conrad for code) - -- Split up loading/parsing of sources file to prevent crashes that were caused -by overloading the regex engine - -- Added overview-tree (thanks to Jeff Conrad for the code contribution) - -- Fixed bug where some assignments of methods to instances in a constructor -would get lost - -- Fix in doc-parsing where a line with only a star and a newline would get -passed over - -- Added ability to 'hide' methods with @private - - -JSDoc 1.3 -========= - -- When a function is marked with @constructor, it will always be dealt -with as a class - -- Improved doc regex - -- Added recursive directory handling diff --git a/modules/jala/util/HopKit/JSDoc/JSDoc.pm b/modules/jala/util/HopKit/JSDoc/JSDoc.pm deleted file mode 100644 index bd7e898a..00000000 --- a/modules/jala/util/HopKit/JSDoc/JSDoc.pm +++ /dev/null @@ -1,1070 +0,0 @@ -package JSDoc; - -=head1 NAME - -JSDoc - parse JavaScript source file for JSDoc comments - -=head1 SYNOPSIS - -Create JavaScript sourcefiles commented in a manner similar to javadoc -(ie. with documentation starting with '/**' and then pass a list of references -to JavaScript source to parse_code_tree: - - /** - * This is a class for example purposes - * @param name Name for the new object - * @constructor - */ - function MyClass(name){ - this.name = name; - } - - $code_tree = parse_code_tree(@src_refs); - -A tree structure describing the code layout, inheritance and documentation -is returned - -To clear the cache of classes and functions in the parser: - - reset_parser(); - - -=head1 DESCRIPTION - -The C function requires a ref to a string holding the -souce code of a javascript object file or files. It returns a data structure -that describes the object hierarchy contained in the source file, as well -as included documentation for all fields and methods. The resulting -data structure has the following form (for each class): - - Class - | - +- classname - | - +- constructor_args - | - +- extends - | - +- constructor_detail - | - +- constructor_vars - | - +- class_methods - | | - | +- description - | | - | +- mapped_name - | | - | +- argument_list - | | - | +- vars - | - +- instance_methods - | | - | +- description - | | - | +- mapped_name - | | - | +- argument_list - | | - | +- vars - | - +- class_fields - | | - | +- field_description - | | - | +- field_name - | | - | +- field_value - | | - | +- field_vars - | - +- instance_fields - | | - | +- field_description - | | - | +- field_name - | | - | +- field_value - | | - | +- field_vars - | - +- inner_classes - | | - | +- class_name - | - +- inherits - | - +- Class - | - +- instance_fields - | - +- instance_methods - - -There is also an additional entry under the key __FILES__ that contains -keyed entries for each @tag that was defined in the first JSDoc comment -block with a @fileoverview tag. Each entry under __FILES__ is keyed by -filename, and is a hash reference. - -=head1 AUTHORS - -Gabriel Reid gab_reid@users.sourceforge.net, -Michael Mathews michael@mathews.net - -=cut - -require 5.000; -use strict; -use warnings; -use Exporter; - -# Recursion limit for recursive regexes -use constant RECURSION => 10; - -use vars qw/ @ISA @EXPORT /; - -@ISA = qw(Exporter); -@EXPORT = qw(parse_code_tree configure_parser reset_parser); - -# State -use vars qw/ %CLASSES %FUNCTIONS %CONFIG $CTX_FILE /; - -# Regexes -use vars qw/ $BAL_PAREN $BAL_BRACE $SQUOTE $DQUOTE $NONQUOTE - $FUNC_DEF $RET_FUNC_DEF $ANON_FUNCTION $LITERAL $FUNC_CALL - $JSDOC_COMMENT $MLINE_COMMENT $SLINE_COMMENT /; - -# This limits nested braces to 30 levels, but is much more -# stable than using a dynamic regex -$BAL_BRACE = qr/\{(?:[^\{\}])*\}/; -$BAL_PAREN = qr/\((?:[^()])*\)/; -for (1..RECURSION){ - $BAL_BRACE = qr/\{(?:[^\{\}]|$BAL_BRACE)*\}/; - $BAL_PAREN = qr/\((?:[^()]|$BAL_PAREN)*\)/; -} -$SQUOTE = qr{'[^'\\]*(?:\\.[^'\\]*)*'}; -$DQUOTE = qr{"[^"\\]*(?:\\.[^"\\]*)*"}; -$NONQUOTE = qr{[^"'/]}; -$FUNC_DEF = qr/function\s+\w+(?:\.\w+)*\s*$BAL_PAREN\s*$BAL_BRACE/; -$RET_FUNC_DEF = qr/function\s+(\w+(?:\.\w+)*)\s*($BAL_PAREN)\s*($BAL_BRACE)/; -$ANON_FUNCTION = qr/function\s*$BAL_PAREN\s*$BAL_BRACE/; -$LITERAL = qr/$DQUOTE|$SQUOTE|\d+/; -$FUNC_CALL = qr/(?:new\s+)?\w+(?:\.\w+)*\s*$BAL_PAREN/; -$JSDOC_COMMENT = qr{/\*\*[^*]*\*+(?:[^/*][^*]*\*+)*/}; -$MLINE_COMMENT = qr{/\*[^*]*\*+(?:[^/*][^*]*\*+)*/}; -$SLINE_COMMENT = qr{//[^\n]*}; - - -# -# Public function that returns a datastructure representing the JS classes -# and their documentation -# -sub parse_code_tree { - - &initialize_parser; - - # - # This (I mean the "<<$_>>") is pretty hacky, but I've made it this - # way to maintain backwards compatibility with anyone who's automatically - # expecting this to work when they throw an array of refs to it. If you're - # using this for your own work, please don't expect to be able to - # put the context file in like this in the future - # - for my $js_src (map { ref and ${$_} or "<<$_>>" } @_){ - if ($js_src =~ /^<<(.+)>>$/){ - $CTX_FILE = $1; - next; - } - - # perlify os line-endings - $js_src =~ s/(\r\n|\r)/\n/g; - - &parse_file_info($js_src); - $js_src = &preprocess_source($js_src); - &fetch_funcs_and_classes($js_src); - } - - &map_all_properties(); - &build_class_hierarchy(); - &set_class_constructors(); - &filter_globals; - - while (my ($classname, $class) = each %CLASSES){ - delete $class->{_class_properties}; - delete $class->{_instance_properties}; - $class->{classname} = $classname unless $classname eq '__FILES__'; - } - return \%CLASSES; -} - -# -# Parses up a a jsdoc comment into its component parts -# PARAM: The document string to be parsed -# -sub parse_jsdoc_comment { - my ($doc, $raw) = @_; - - # Remove excess '*' characters - $doc =~ s/^[*\s]*([^*].*?)[*\s]*$/$1/s; - $doc =~ s/^\s*\*//gm; - - my %parsed = (); # remember each part that is parsed - - # the first paragraph could be a summary statement - # a paragraph may follow of variable defs (variable names start with "@") - my ($summary, $variable_str) = $doc =~ - /^\s* - ( - (?:[^{@]|(?:\{[^@]))* - (?:\{\@ - (?:[^{@]|(?:\{[^@]))*)* - ) - \s* - (.*) - $/xs; - $summary =~ s/^\s*(\S.*?)\s*$/$1/s; - $parsed{summary} = $summary; - - # two types of variable def can be dealt with here: - # a @argument has a two-part value -- the arg name and a description - # all other @ only have a single value each (although there may - # be many variables with the same name) - if($variable_str) { - my %vars = (); - while ($variable_str =~ / - (?{$_} = [] for qw(instance_fields class_fields - instance_methods class_methods - inner_classes); - } - unless ($CLASSES{$class}->{extends}){ - &set_base_class($class, $1) - if $class_doc =~ /\@base\s+(\w+(?:\.\w+)*)/; - } -} - -# -# Set the base class for a given class -# -sub set_base_class { - my ($class, $base_class) = @_; - &add_class($class); - $CLASSES{$class}->{extends} = $base_class - unless $CLASSES{$class}->{extends}; -} - -# -# Add a property, either a class or instance method or field -# -sub add_property { - my ($doc, $class, $property, $value, $is_class_property) = @_; - &add_class($class); - return if $property eq 'constructor'; - my $parsed_doc = &parse_jsdoc_comment($doc); - $doc = $parsed_doc->{summary}; - my $key = $is_class_property ? '_class_properties' : '_instance_properties'; - for my $classref (@{$CLASSES{$class}->{$key}}){ - if ($classref->{property_name} eq $property){ - # Whine about rebinding functions to classes - if ($FUNCTIONS{$value}){ - warn "Already bound property '$property' to '$class'\n"; - return; - } - - # Only take on new attributes - $classref->{property_doc} ||= $doc; - $classref->{property_vars} ||= $parsed_doc->{vars}; - return; - } - } - - push @{$CLASSES{$class}->{$key}}, { - property_doc => $doc, - property_name => $property, - property_value => $value, - property_vars => $parsed_doc->{vars} - }; -} - - -# -# Add a function and its documentation to the global FUNCTION hash -# -sub add_function { - my ($doc, $function, $arg_list, $is_private) = @_; - - # clean remaining comments out of arg list - # (all others are already gone) - # Again, taken from Jeffrey Friedl's "Mastering Regular Expressions" - { - no warnings; - $arg_list =~ s/ - ($NONQUOTE+| - $DQUOTE$NONQUOTE*| - $SQUOTE$NONQUOTE*) - |$MLINE_COMMENT|$SLINE_COMMENT/$1/gx; - } - - if ($FUNCTIONS{$function}){ - warn "Function '$function' already declared\n"; - unless ($doc && !$FUNCTIONS{$function}->{documentation}->{summary}){ - return 0; - } - } - $FUNCTIONS{$function} = {}; - my $func = $FUNCTIONS{$function}; - $arg_list and $func->{argument_list} = join(" ", split("\\s+", $arg_list)) - or $func->{argument_list} = "()"; - - my $documentation = parse_jsdoc_comment($doc); - if ($documentation->{vars}->{member}){ - my ($classname) = map { s/^\s*(\S*)\s*$/$1/; $_ } - @{$documentation->{vars}->{member}}; - &add_property($doc, $classname, $function, $function, 0) - if $classname =~ /\w+/; - } - my $function_ref = $FUNCTIONS{$function}; - - $function_ref->{documentation} = $documentation; - $function_ref->{description} = $documentation->{summary}; - $function_ref->{vars} = $function_ref->{documentation}->{vars}; - $function_ref->{vars}->{filename} = $CTX_FILE; - $function_ref->{vars}->{private} = 1 if $is_private; - 1; -} - - -# -# Map all the class and instance properties to their implementation -# -sub map_all_properties { - for my $type (qw(_class_properties _instance_properties)){ - for my $class (keys %CLASSES){ - &map_single_property( - $class, - $_->{property_name}, - $_->{property_value}, - $_->{property_doc}, - $_->{property_vars}, $type eq '_class_properties') - for @{$CLASSES{$class}->{$type}} - } - } - - # Map all the unattached functions - my $classname = $CONFIG{GLOBALS_NAME} || 'GLOBALS'; - &add_class($classname); - for my $function - (grep !($FUNCTIONS{$_}->{is_mapped} || $CLASSES{$_}), keys %FUNCTIONS){ - &map_single_property( - $classname, $function, $function, '', undef, 1); - } - - # Map static inner classes - for $classname (keys %CLASSES){ - my $i = 0; - my @to_remove; - for my $cprop (@{$CLASSES{$classname}->{class_methods}}){ - my $propname = $cprop->{mapped_name}; - if ($CLASSES{"$classname.$propname"}){ - push @to_remove, $i; - push @{$CLASSES{$classname}->{inner_classes}}, - {class_name => "$classname." . $cprop->{mapped_name}}; - $FUNCTIONS{"$classname.$propname"} = - delete $FUNCTIONS{"__$classname.$propname"}; - } - $i++; - } - splice(@{$CLASSES{$classname}->{class_methods}}, $_, 1) - for reverse @to_remove; - } -} - -# -# Map a single instance or class field or method -# -sub map_single_property { - my ($class, $prop_name, $prop_val, - $description, $vars, $is_class_prop) = @_; - if (!$FUNCTIONS{$prop_val}){ - push @{$CLASSES{$class}->{$is_class_prop - ? 'class_fields' : 'instance_fields'}}, { - field_name => $prop_name, - field_description => $description, - field_value => $prop_val, - field_vars => $vars }; - return; - } - my %method; - my $function = $FUNCTIONS{$prop_val}; - $function->{is_mapped} = 1; - $method{mapped_name} = $prop_name; - - $method{$_} = $function->{$_} for - qw/ argument_list description vars /; - - push @{$CLASSES{$class}->{$is_class_prop - ? 'class_methods' - : 'instance_methods'}}, \%method; -} - - - -# -# Build up the full hierarchy of classes, including figuring out -# what methods are overridden by subclasses, etc -# PARAM: The JS source code -# -sub build_class_hierarchy { - # Find out what is inherited - for my $class (map($CLASSES{$_}, sort keys %CLASSES)){ - my $superclassname = $class->{extends}; - !$superclassname and next; - my $superclass = $CLASSES{$superclassname}; - $class->{inherits} = {}; - while ($superclass){ - $class->{inherits}->{$superclassname} = {}; - my @instance_fields; - my @instance_methods; - - &handle_instance_methods($superclass, $superclassname, - $class, \@instance_methods); - - &handle_instance_fields($superclass, $superclassname, - $class, \@instance_fields); - - $superclassname = $superclass->{extends}; - $superclass = $superclassname ? $CLASSES{$superclassname} : undef; - } - } -} - -# -# This is just a helper function for build_class_hierarchy -# because that function was getting way oversized -# -sub handle_instance_methods { - my ($superclass, $superclassname, $class, $instance_methods) = @_; - if ($superclass->{instance_methods}){ - INSTANCE_METHODS: - for my $base_method (@{$superclass->{instance_methods}}){ - for my $method (@{$class->{instance_methods}}){ - if ($$base_method{mapped_name} eq $$method{mapped_name}){ - - # Carry over the description for overridden methods with - # no description (to be javadoc compliant) - if (($base_method->{description} or $base_method->{vars}) - and not $method->{description}){ - - $method->{description} = $base_method->{description}; - for my $varkey (keys(%{$base_method->{vars}})){ - $method->{vars}->{$varkey} - = $base_method->{vars}->{$varkey} - unless $method->{vars}->{$varkey}; - } - } - next INSTANCE_METHODS; - } - } - for (keys %{$class->{inherits}}){ - my $inherited = $class->{inherits}->{$_}; - for my $method (@{$inherited->{instance_methods}}){ - next INSTANCE_METHODS - if $$base_method{mapped_name} eq $method; - } - } - push @$instance_methods, $$base_method{mapped_name}; - } - $class->{inherits}->{$superclassname}->{instance_methods} - = $instance_methods; - } -} - -# -# This is just a helper function for build_class_hierarchy -# because that function was getting way oversized -# -sub handle_instance_fields { - my ($superclass, $superclassname, $class, $instance_fields) = @_; - if ($superclass->{instance_fields}){ - INSTANCE_FIELDS: - for my $base_field (@{$superclass->{instance_fields}}){ - for my $field (@{$class->{instance_fields}}){ - next INSTANCE_FIELDS if $field eq $base_field; - } - push @$instance_fields, $base_field->{field_name}; - } - $class->{inherits}->{$superclassname}->{instance_fields} - = $instance_fields; - } -} - -# -# Set all the class constructors -# -sub set_class_constructors { - for my $classname (keys %CLASSES){ - my $constructor = $FUNCTIONS{$classname}; - $CLASSES{$classname}->{constructor_args} = - $constructor->{argument_list}; - $CLASSES{$classname}->{constructor_detail} - = $constructor->{description}; - - $CLASSES{$classname}->{constructor_vars} = $constructor->{vars} || {}; - } -} - -# -# Clear out everything from the parsed classes and functions -# -sub reset_parser { - %CLASSES = (); - %FUNCTIONS = (); -} - -# -# Set global parameters for the parser -# -sub configure_parser { - %CONFIG = @_; -} - -# -# Set the initial defaults for the parser -# -sub initialize_parser { - $CONFIG{GLOBALS_NAME} ||= 'GLOBALS'; -} - -# -# Run through the source and convert 'confusing' JavaScript constructs -# into ones that are understood by the parser, as well as stripping -# out unwanted comment blocks. -# -# For example: -# -# Foo.prototype = { -# bar: function(){ return "Eep!"; }, -# baz: "Ha!" -# } -# -# becomes -# -# Foo.prototype.bar = function(){ return "Eep!"; }; -# Foo.prototype.baz = "Ha!"; -# -sub preprocess_source { - my ($src) = @_; - - # Make all the @extends tags into @base tags - $src =~ s/\@extends\b/\@base/g; - - # This had better not break anything! - $src = &deconstruct_getset($src); - - # Convert: - # /** @constructor */ - # Foo.Bar = function(){...} - # to: - # /** @constroctor */ - # Foo.Bar = function(){} - # /** @constructor */ - # function Foo.Bar(){...} - # - # Note that we have to keep the original declaration so that Foo.Bar - # can be recognized as a nested class. Yes, I know it's bad... - $src =~ s! - ($JSDOC_COMMENT\s*) - (?:var\s*)?(\w+(?:\.\w+)*?) - \s*= - (\s*function)(?=\s*($BAL_PAREN)\s*\{) - !index($1, '@constructor') == -1 ? "$1$2 = $3" : "$1$2 = function$4 {};\n$1$3 $2"!egx; - - # remove all uninteresting comments, but only if they're not inside - # of other comments - # (adapted from Jeffrey Friedl's "Mastering Regular Expressions" - { - no warnings; - $src =~ s/ - ($NONQUOTE+| - $JSDOC_COMMENT$NONQUOTE*| - $DQUOTE$NONQUOTE*| - $SQUOTE$NONQUOTE*) - |$MLINE_COMMENT|$SLINE_COMMENT/$1/gx; - - 1 while $src =~ s/$JSDOC_COMMENT\s*($JSDOC_COMMENT)/$1/g; - } - - # Alter the prototype-initialization blocks - $src =~ s/ - (\w+(?:\.\w+)*)\.prototype - \s*=\s*($BAL_BRACE)/deconstruct_prototype($1, $2)/egx; - - # Mark all constructors based on 'new' statements - my %seen; - my @classnames = grep { not $seen{$_}++ } - $src =~ /\bnew\s+(\w+(?:\.\w+)*)\s*\(/g; - for my $cname (@classnames){ - $src =~ s/($JSDOC_COMMENT?) - (?=\s*function\s+\Q$cname\E\s*$BAL_PAREN - \s*$BAL_BRACE) - /&annotate_comment($1, '@constructor')/ex; - } - - $src =~ s/ - ($JSDOC_COMMENT?)\s* - (function\s+\w+(?:\.\w+)*\s*$BAL_PAREN\s*) - ($BAL_BRACE) - /&deconstruct_constructor($1, "$2$3")/egx; - - $src =~ s! - (?:var\s+)?(\w+(?:\.\w+)*) - \s*=\s* - new\s+ - ($ANON_FUNCTION)!&deconstruct_singleton($1, $2)!egx; - - $src = &remove_dynamic_bindings($src); - - # Mark all void methods with "@type void" - $src =~ s/($JSDOC_COMMENT?)\s* - ((?: - (?:function\s+\w+(?:\.\w+)*\s*$BAL_PAREN\s*) - | - (?:\w+(?:\.\w+)*\s*=\s*function\s*(?:\w+\s*)?$BAL_PAREN\s*) - )$BAL_BRACE) - /&mark_void_method($1, $2)/egx; - - # Clear nested functions (will save trouble later on) - $src =~ s/($JSDOC_COMMENT?)\s* - (\w+(?:\.\w+)*\s*=\s*)? - (function(?:\s+\w+(?:\.\w+)*)?\s*$BAL_PAREN\s*) - ($BAL_BRACE) - /&clear_nested($1, $2, $3, $4)/egx; - - return $src; -} - -sub clear_nested { - my ($doc, $assign_to, $declaration, $funcbody) = @_; - $assign_to ||= ''; - if ($doc =~ /^(?=.*\@constructor|\@class)(?=.*\@exec)/){ - warn "\@constructor or \@class can't be used together with \@exec\n"; - } - if ($doc !~ /\@(constructor|class|exec)/ - or $assign_to =~ /^\w+\.prototype\./) { - return "$doc\n$assign_to$declaration" . "{}\n"; - } elsif ($doc =~ /\@(constructor|class)/) { - return "$doc\n$assign_to$declaration$funcbody"; - } else { - my @visible_funcs = $funcbody =~ / - ((?:$JSDOC_COMMENT)? - (?:\w+\.\w+(?:\.\w+)*)\s*=\s* - (?: - $FUNC_DEF - | - $ANON_FUNCTION - | - $FUNC_CALL - | - \w+ - )\s*;)/gx; - return join("\n", @visible_funcs); - } -} - -# -# Remove dynamic binding. -# Change this: -# -# function MyFunc(class){ -# var x = 2; -# class.prototype.func = function(){}; -# return x; -# } -# -# to: -# -# function MyFunc(class){ -# var x = 2; -# -# return x; -# } -# -# and change this: -# -# function BindMethod(obj){ -# obj.someFunc = function(){ return null; }; -# return obj; -# } -# -# to: -# -# function BindMethod(obj){ -# -# return obj; -# } -# -sub remove_dynamic_bindings { - my ($src) = @_; - while ($src =~ /$RET_FUNC_DEF/g){ - my ($fname, $params, $definition) = ($1, $2, $3); - next unless $definition =~ /\bfunction\b|\w+\.prototype\./; - my @params = split(/\s*,\s*/, substr($params, 1, length($params) - 2)); - for my $param (@params){ - $src =~ s/\b$param\.prototype\.[^;\n]*[;\n]//g; - $src =~ s/\b$param\.\w+ = $ANON_FUNCTION//g; - } - } - $src; -} - -# -# Annotate a method as being void if no @type can be found, and there is no -# statement to return a value in the method itself. -# -sub mark_void_method { - my ($doc, $funcdef) = @_; - return "$doc\n$funcdef" if $doc =~ /\@(constructor|type|returns?)\b/; - my ($fbody) = $funcdef =~ /^[^{]*($BAL_BRACE)/; - $fbody =~ s/$FUNC_DEF/function x(){}/g; - $fbody =~ s/$ANON_FUNCTION/function (){}/g; - $doc = &annotate_comment($doc, '@type void') - if $fbody !~ /\breturn\s+(?:(?:\w+)|(?:(["']).*?\1)|$BAL_PAREN)/; - "$doc\n$funcdef"; -} - -# -# A helper to change singleton declarations like -# -# MySingleton = new function(){this.x=function(){}} -# -# into: -# -# function MySingleton(){} -# MySingleton.prototype.x = function(){}; -# -sub deconstruct_singleton { - my ($classname, $definition) = @_; - $definition =~ s/function\s*$BAL_PAREN\s*\{(.*)\}\s*$/$1/s; - $definition =~ s/\bthis\./$classname.prototype\./g; - qq# - function $classname(){} - $definition; - #; -} - -# -# A helper to preprocess_source, change prototype-initialization -# blocks into multiple prototype-property assignments -# -sub deconstruct_prototype { - my ($class, $src) = @_; - $src =~ s/^\{(.*)\}$/$1/s; - $src =~ s! - (\w+) - \s*:\s* - ( - $ANON_FUNCTION - | - $FUNC_DEF - | - $FUNC_CALL - | - $LITERAL - | - \w+ - ) - \s*,? - !$class.prototype.$1 = $2;!gsx; - - $src; -} - -# -# Unpacks a constructor into separate calls -# -sub deconstruct_constructor { - my ($doc, $func_def) = @_; - return "$doc$func_def" unless $doc =~ /\@(constructor|class)/; - my ($classname) = $func_def =~ /function\s+(\w+(?:\.\w+)*)/; - $func_def =~ s/ - (\{.*\})$ - /&deconstruct_inner_constructor($classname, $1)/esx; - "$doc$func_def"; -} - -sub deconstruct_inner_constructor { - my ($classname, $inner_src) = @_; - $inner_src = substr($inner_src, 1, -1); - my @doc_n_fnames = $inner_src =~ /($JSDOC_COMMENT?)\s*function\s+(\w+)/g; - - unless ($CONFIG{NO_LEXICAL_PRIVATES}){ - $inner_src =~ s/ - ($JSDOC_COMMENT)? - \s* - var - \s+ - (\w+)/&annotate_comment($1) . "\n$classname\.prototype\.$2"/egx; - - $inner_src =~ s/ - ($JSDOC_COMMENT)?\s* - ^\s* - function - \s+ - (\w+) - /&annotate_comment($1) . - "\n$classname\.prototype\.$2 = function"/egmx; - } - - { - no warnings; - $inner_src =~ s/ - ($JSDOC_COMMENT\s*)? - ^\s*this(?=\.) - /$1$classname.prototype/gmx; - } - - # Replace all bindings of private methods to public names - for (my $i = 0; $i < @doc_n_fnames; $i += 2) - { - my ($doc, $fname) = @doc_n_fnames[$i, $i + 1]; - $inner_src =~ s/ - ($JSDOC_COMMENT\s* - $classname\.prototype\.\w+) - \s*=\s* - $fname\s*[\n;] - /$1 = function(){}/gx; - - $inner_src =~ s/ - ($classname\.prototype\.\w+) - \s*=\s* - $fname\s*[\n;] - /$doc\n$1 = function(){}/gx; - } - "{}\n$inner_src"; -} - -# -# Deconstruct mozilla's __defineGetter__ and __defineSetter__ -# (Yes, I know this goes against my principles...) -# -sub deconstruct_getset { - my ($src) = @_; - # Crack open the assignments for define(Getter|Setter) - my $crack = sub { - my $code = shift; $code =~ s/^.(.*).$/$1/s; - my ($name) = split ",", $code; - $name = ($name =~ /.*?(['"])([^'"]+)\1/)[1]; - $name; - }; - for my $prefix ('get', 'set'){ - my $fname = "define\u${prefix}ter"; - $src =~ s/ - (\w+(?:\.\w+)* - \.prototype) - \.__${fname}__\s*($BAL_PAREN)/ - my $name = $crack->($2); - "$1.$name = null"/gex; - } - $src; -} - - -# -# Add an annotation (@tag) to a documentation block. The block is assumed to -# be a valid JSDoc documentation block ==> /^\/\*\*.*\*\/$/ -# and no checking is done to verify this -# -sub annotate_comment { - my $annotation = $_[1] || '@private'; - return "\n/** $annotation */" unless $_[0]; - substr($_[0], 0, -2) . " \n$annotation \n*/"; -} - -# -# This is here to stop perl from segfaulting from deep recursion in regexes -# The first character in the text _should_ be open_token, as everything -# before open_token will be discarded, unless there is no matching text -# at all. -# -sub find_balanced_block { - my ($open_token, $close_token, $text) = @_; - my ($count, $open, $close) = (0, 0, 0); - return ('', $text) unless $text =~ /\Q$open_token\E/; - $text =~ s/^.*?(?=\Q$open_token\E)//s; - for (split //, $text){ - $count++; - $open++ if $_ eq $open_token; - $close++ if $_ eq $close_token; - last unless ($open != $close); - } - warn "Unbalanced block\n" if ($open != $close); - (substr($text, 0, $count), substr($text, $count)); -} - -# -# Remove the $CONFIG{GLOBALS_NAME} class if it doesn't contain anything -# -sub filter_globals { - my $global = $CLASSES{$CONFIG{GLOBALS_NAME}}; - delete $CLASSES{$CONFIG{GLOBALS_NAME}} if - not (defined $global->{constructor_args} || - defined $global->{constructor_detail}) - && not (@{$global->{instance_methods}} || - @{$global->{instance_fields}} || - @{$global->{class_methods}} || - @{$global->{class_fields}}); - - # Also get rid of extra info under the '__files__' key - delete $CLASSES{__FILES__}->{$_} for qw(constructor_params constructor_args - constructor_detail class_methods - constructor_vars); -} - - -# -# Try to grab the first block comment from the file that has a @fileoverview -# tag in it, and get the file info from there -# -sub parse_file_info { - my ($src) = @_; - my %fileinfo = ( src => $src ); - while ($src =~ /($JSDOC_COMMENT)/g){ - local $_ = substr($1, 3, length($1) - 5); # Get the actual content - if (/\@fileoverview\b/){ - my $doc = parse_jsdoc_comment($_, 1); - %fileinfo = (%{$doc->{vars}}, %fileinfo); - last; - } - } - $CLASSES{__FILES__}->{$CTX_FILE} = \%fileinfo if $CTX_FILE; -} - -1; diff --git a/modules/jala/util/HopKit/JSDoc/JSDoc/XMI.pm b/modules/jala/util/HopKit/JSDoc/JSDoc/XMI.pm deleted file mode 100644 index 77b5e0af..00000000 --- a/modules/jala/util/HopKit/JSDoc/JSDoc/XMI.pm +++ /dev/null @@ -1,291 +0,0 @@ -package JSDoc::XMI; - -use strict; -use warnings; -use HTML::Template; -use Data::Dumper; - -=head1 DESCRIPTION - - @packages - - @classes - $classname - $classid - $classuuid - $classvisibility (public|protected|private) - - @specializationids - $specializationid - - $generalizationid - - @attributes - $attributeid - $attributeuuid - $attributename - $attributevisibility (public|protected|private) - $ownerscope (instance|classifier) - $classid - $typeid - - @methods - $methodid - $methoduuid - $methodname - $methodvisibility (public|protected|private) - $ownerscope (instance|classifier) - $returnid - $returnuuid - $returntypeid - - @datatypes - $datatypeid - $datatypeuuid - $datatypename - - @generalizations - $generalizationid - $generalizationuuid - $generalizationchild - $generalizationparent - -=cut - -sub new { - my ($package, $location) = @_; - bless { - location => "${location}JSDoc/", - idcounter => 2, - types => {}, - classes => {}, - generalizations => {} - }, $package; -} - -sub output { - my ($self, $classes) = @_; - - my $template = HTML::Template->new( - filename => $self->{location} . 'xmi.tmpl', - die_on_bad_params => 1); - - my @packages = $self->get_packages($classes); - my @datatypes = $self->get_datatypes; - my @generalizations = $self->get_generalizations; - - $template->param( - packages => \@packages, - datatypes => \@datatypes, - generalizations => \@generalizations ); - return $template->output; -} - -sub get_id { - 'xmi.' . shift->{idcounter}++; -} - -sub get_uuid { - my @chars = ('A'..'Z', 'a'..'z', 0..9); - my @uuid; - for (1..32){ - push @uuid, $chars[rand(@chars)]; - } - join("", @uuid); -} - -sub get_packages { - my ($self, $classes) = @_; - my %packages; - push(@{$packages{$_->{package}}}, $_) - for $self->get_classes($classes); - map { - name => $_, - classes => $packages{$_}, - packageid => $self->get_id, - packageuuid => $self->get_uuid - }, keys %packages; -} - -sub get_classes { - my ($self, $classes) = @_; - my @classes; - - # Store all the class-ids before we start on anything else - $self->add_class($_) for keys %$classes; - - for my $cname (keys %$classes){ - my $class = { - classname => $cname, - classid => $self->add_class($cname), - classuuid => $self->get_uuid, - classvisibility => - defined($classes->{$cname}->{constructor_vars}->{private}) - ? 'private' : 'public' - }; - $class->{attributes} = $self->get_attributes( - $class->{classid}, - $classes->{$cname}); - - $class->{methods} = $self->get_methods( - $class->{classid}, - $classes->{$cname}); - - $class->{generalizationid} = - $self->get_generalizationid($classes->{$cname}); - - $class->{package} = - defined($classes->{$cname}->{constructor_vars}->{package}) - ? $classes->{$cname}->{constructor_vars}->{package}->[0] : ''; - - push @classes, $class; - } - - for my $class (@classes){ - $class->{specializationids} = $self->get_specializationids($class); - } - - @classes; -} - -sub get_methods { - my ($self, $classid, $class) = @_; - my @methods; - - for my $k (qw(instance class)){ - for my $method (@{$class->{"${k}_methods"}}){ - my $type = defined($method->{vars}->{type}) - ? $method->{vars}->{type}->[0] : 'Object'; - my $meth = { - methodid => $self->get_id, - methoduuid => $self->get_uuid, - methodname => $method->{mapped_name}, - methodvisibility => - defined($method->{vars}->{private}) - ? 'private' : 'public', - ownerscope => - $k eq 'class' ? 'classifier' : 'instance', - returnid => $self->get_id, - returnuuid => $self->get_uuid, - returntypeid => $self->add_type($type) - }; - push @methods, $meth; - } - } - return \@methods; -} - -sub get_attributes { - my ($self, $classid, $class) = @_; - my @attributes; - for my $k (qw(instance class)){ - for my $field (@{$class->{"${k}_fields"}}){ - my $type = defined($field->{field_vars}->{type}) - ? $field->{field_vars}->{type}->[0] : 'Object'; - my $attr = { - attributeid => $self->get_id, - attributeuuid => $self->get_uuid, - attributename => $field->{field_name}, - attributevisibility => - defined($field->{field_vars}->{private}) - ? 'private' : 'public', - ownerscope => - $k eq 'class' ? 'classifier' : 'instance', - classid => $classid, - typeid => $self->add_type($type) - }; - push @attributes, $attr; - } - } - \@attributes; -} - -sub get_generalizationid { - my ($self, $class) = @_; - - if ($class->{extends}){ - return $self->add_generalization( - $class->{classname}, - $class->{extends}); - } - ''; -} - -sub get_specializationids { - my ($self, $class) = @_; - my $cname = $class->{classname}; - my $cid = $self->add_class($cname); - - my @specializationids; - - for my $id (keys %{$self->{generalizations}}){ - my $generalization = $self->{generalizations}->{$id}; - if ($generalization->{parent} eq $cid){ - push @specializationids, { specializationid => $id }; - } - } - \@specializationids; -} - -sub get_datatypes { - my ($self) = @_; - my @datatypes; - - while (my ($type, $id) = each(%{$self->{types}})){ - push @datatypes, { - datatypeid => $id, - datatypeuuid => $self->get_uuid, - datatypename => $type }; - } - @datatypes; -} - -sub get_generalizations { - my ($self) = @_; - my @generalizations; - - while (my ($id, $generalization) = each(%{$self->{generalizations}})){ - push @generalizations, { - generalizationid => $id, - generalizationuuid => $self->get_uuid, - generalizationchild => $generalization->{parent}, - generalizationparent => $generalization->{child}}; - } - @generalizations; -} - -sub add_type { - my ($self, $type) = @_; - $type =~ s/^\s*(\S+)\s*$/$1/; - if (defined($self->{classes}->{$type})){ - return $self->add_class($type); - } elsif (defined($self->{types}->{$type})){ - return $self->{types}->{$type}; - } - $self->{types}->{$type} = $self->get_id; -} - -sub add_class { - my ($self, $class) = @_; - $class =~ s/^\s*(\S+)\s*$/$1/; - if (defined($self->{classes}->{$class})){ - return $self->{classes}->{$class}; - } - $self->{classes}->{$class} = $self->get_id; -} - -sub add_generalization { - my ($self, $subclassname, $superclassname) = @_; - my $subclassid = $self->add_class($subclassname); - my $superclassid = $self->add_class($superclassname); - - my $generalization = { - child => $subclassid, - parent => $superclassid }; - - my $generalizationid = $self->get_id; - $self->{generalizations}->{$generalizationid} = $generalization; - $generalizationid; -} - -1; diff --git a/modules/jala/util/HopKit/JSDoc/JSDoc/XML.pm b/modules/jala/util/HopKit/JSDoc/JSDoc/XML.pm deleted file mode 100644 index aa07f307..00000000 --- a/modules/jala/util/HopKit/JSDoc/JSDoc/XML.pm +++ /dev/null @@ -1,72 +0,0 @@ -package JSDoc::XML; - -use strict; -use warnings; -use HTML::Template; - -sub new { - my ($package, $location) = @_; - bless { location => "${location}JSDoc/" }, $package; -} - -sub output { - my ($self, $classes) = @_; - my @classes = _preprocess( - grep {defined($_->{classname})} values %$classes); - my $template = HTML::Template->new( - filename => $self->{location} . 'xml.tmpl', - die_on_bad_params => 1); - - $template->param(classes => \@classes); - return $template->output; -} - -sub _preprocess { - my @classes = @_; - for (@classes){ - $_->{inherits} = _preprocess_inherits($_->{inherits}); - $_->{constructor_vars} = _preprocess_vars($_->{constructor_vars}); - for my $method (@{$_->{instance_methods}}, @{$_->{class_methods}}){ - $method->{vars} = _preprocess_vars($method->{vars}); - } - for my $field (@{$_->{instance_fields}}, @{$_->{class_fields}}){ - $field->{field_vars} = _preprocess_vars($field->{field_vars}); - } - } - @classes; -} - -sub _preprocess_inherits { - my ($inherits) = @_; - my @inherits; - for my $class (keys %$inherits){ - my $inherit = { - class => $class, - methods => [map { name => $_ }, - @{$inherits->{$class}->{instance_methods}}]}; - push @inherits, $inherit; - } - \@inherits; -} - -sub _preprocess_vars { - my ($vars) = @_; - return $vars if ref($vars) eq 'ARRAY'; - my @vars; - for my $key (keys %$vars){ - my $var; - if (ref($vars->{$key}) eq 'ARRAY'){ - $var = { - '@name' => $key, - values => [map { val => $_ }, @{$vars->{$key}}] }; - } else { - $var = { - '@name' => $key, - values => [ { val => $vars->{$key} } ] }; - } - push @vars, $var; - } - \@vars; -} - -1; diff --git a/modules/jala/util/HopKit/JSDoc/JSDoc/xmi.tmpl b/modules/jala/util/HopKit/JSDoc/JSDoc/xmi.tmpl deleted file mode 100644 index 7aa07d5f..00000000 --- a/modules/jala/util/HopKit/JSDoc/JSDoc/xmi.tmpl +++ /dev/null @@ -1,250 +0,0 @@ - - - - - JSDoc XMI Export - 0.1 - - - - - - JSDoc - - - - - - - - - - - " - xmi.uuid=""> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - return - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/modules/jala/util/HopKit/JSDoc/JSDoc/xml.tmpl b/modules/jala/util/HopKit/JSDoc/JSDoc/xml.tmpl deleted file mode 100644 index 0757ac73..00000000 --- a/modules/jala/util/HopKit/JSDoc/JSDoc/xml.tmpl +++ /dev/null @@ -1,128 +0,0 @@ - - - - - " - extends="" > - - - - - - ]]> - - - - - - ]]> - - - - - ]]> - - - - - - ]]> - - - - - - - - - - - - ]]> - ]]> - - - - - ]]> - - - - - - - - - - - - ]]> - - - - - - ]]> - - - - - - - - - - - - - - - - ]]> - ]]> - - - - - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/modules/jala/util/HopKit/JSDoc/JavaScript/Syntax/HTML.pm b/modules/jala/util/HopKit/JSDoc/JavaScript/Syntax/HTML.pm deleted file mode 100644 index 909facb7..00000000 --- a/modules/jala/util/HopKit/JSDoc/JavaScript/Syntax/HTML.pm +++ /dev/null @@ -1,95 +0,0 @@ -package JavaScript::Syntax::HTML; - -=head1 NAME - -JavaScript::Syntax::HTML - Convert JavaScript sourcecode to HTML - -=head1 SYNOPSIS - - use JavaScript::Syntax::HTML qw(to_html to_html_document); - my $html_fragment = to_html($js_src); - my $html_doc = output_html_document($js_src); - -=head1 DESCRIPTION - -JavaScript::Syntax::HTML processes JavaScript code and outputs HTML with -all reserved words marked up. - -The to_html method only outputs an HTML fragment (no or tags), -and only marks up the reserved words with CSS styles. - -The to_html_document method outputs a full HTML document, and does include -style information for the reserved words markup. - -The style classes that can be defined for use with to_html are C, -C, and C. - -=head1 AUTHOR - -Gabriel Reid gab_reid@users.sourceforge.net - -=cut - -use warnings; -use strict; -use Exporter; - -our @ISA = qw(Exporter); -our @EXPORT_OK = qw(to_html to_html_document); - -sub to_html { - local $_ = shift; - s/\&/&/g; - s//>/g; - s/ - ((?:\/\*.*?\*\/) - | - (?:\/\/[^\n]*$)) - | - ('[^']*'|"[^"]*") - | - \b(function|for|if|while|return|else|prototype|this)\b - / get_substitution($1, $2, $3) /egsxm; - $_; -} - -sub get_substitution { - my ($comment, $stringliteral, $resword) = @_; - my $content; - if ($comment){ - $comment =~ s/(\@\w+)\b/get_span('attrib', $1)/eg; - return get_span('comment', $comment); - } elsif ($stringliteral){ - return get_span('literal', $stringliteral); - } elsif ($resword){ - return get_span('reserved', $resword); - } -} - -sub get_span { - my ($class, $inner) = @_; - qq($inner); -} - -sub to_html_document { - my ($src) = @_; - $src = &to_html($src); - qq( - - - - - -
      -$src
      -	
      - -); -} diff --git a/modules/jala/util/HopKit/JSDoc/README b/modules/jala/util/HopKit/JSDoc/README deleted file mode 100644 index cb34ca75..00000000 --- a/modules/jala/util/HopKit/JSDoc/README +++ /dev/null @@ -1,30 +0,0 @@ -README for jsdoc.pl - -jsdoc.pl is a script that produces javadoc-style documentation from well-formed -JavaScript sourcefiles. At the moment, this means it supports sourcefiles where -all functions are mapped to a class using prototype-based inheritance. -Anonymous function definitions -(e.g. Circle.prototype.getRadius = function(){ ...} ) are supported. - -This application requires Perl5, as well as one non-standard addon module: - - HTML::Template, which is available from CPAN (cpan.org) - -Invocation is simple: Just run the application, giving one or more well-formed -OO JavaScript sourcefilename(s) as arguments. A sample JS sourcefile, test.js, -is given along with this application. An example of running the application is -shown below: - - $ ./jsdoc.pl test.js - -OR - perl jsdoc.pl test.js - -Further information about using JsDoc can be found at -http://jsdoc.sourceforge.net - -If there are any questions, comments, problems or anything else, please mail -the jsdoc-user mailing list; more information can be found at -http://sourceforge.net/mail/?group_id=30801. This application has been -successfully tested on Linux (Debian and Redhat), and Windows 2000 with -ActivePerl. - diff --git a/modules/jala/util/HopKit/JSDoc/TODO b/modules/jala/util/HopKit/JSDoc/TODO deleted file mode 100644 index 414e805b..00000000 --- a/modules/jala/util/HopKit/JSDoc/TODO +++ /dev/null @@ -1,46 +0,0 @@ -TODO for JSDoc - -- XML / XMI export - -- Improve the --package-naming option so that there are separate namespaces - for each package (so that you can have the same class name defined in - different packages) - -- Fix some spacing/table issues in the navbar in the templates (use a td - border in the stylesheet to debug) - -- Introduce a more generalized system for generating the navbar - -- Handle additional information (such as @see) for fields - -- Uncallable methods/functions should be marked as private, or show the scope - from which they can be called - -- Dynamic handling of assignment of prototype to a temp variable (preprocessor) - -- Add support for interfaces, but first this has to be better defined - -- Top-level var documenting (maybe add a '@global' tag to force toplevel vars - to be documented - -- Add an FAQ, more and better documentation - -- Java port (someday...) - -- Make a more polished API for using other doclets, like javadoc - -- Add a deprecated page, make deprecated support more like javadoc - -- Add support for js files without .js extension - -- Support for a time stamp - -- Some of the ->{vars} are set to undef, should always be an empty map - -- Add command line params --dump-tree, --dump-xml - -- Add command line param --stylesheet - -- Make navbar links selective so they are never broken - -- Update the help doc diff --git a/modules/jala/util/HopKit/JSDoc/TestJSDoc.pl b/modules/jala/util/HopKit/JSDoc/TestJSDoc.pl deleted file mode 100644 index aa35933f..00000000 --- a/modules/jala/util/HopKit/JSDoc/TestJSDoc.pl +++ /dev/null @@ -1,679 +0,0 @@ -#!/usr/bin/perl - -package JSDoc; -# -# Unit testing of JSDoc -# -# Run with 'perl TestJSDoc.pl' or './TestJSDoc.pl' -# - -use strict; -use warnings; - - - -use JSDoc; -use Data::Dumper; -use Test::More qw(no_plan); - -$|++; - -# parse_jsdoc_comment -diag("Testing parse_jsdoc_comment"); -is_deeply(parse_jsdoc_comment(''), {summary => ''}, - "Ensure only summary is filled in"); - -is(parse_jsdoc_comment('')->{summary}, '', 'Empty comment value'); - - -is(parse_jsdoc_comment( - '************************* test *************')->{summary}, - 'test', 'long leading and trailing stars'); - - -# annotate_comment -diag("Testing annotate_comment"); -is(annotate_comment, "\n/** \@private */", 'annotate_comment w/o arg'); -like(annotate_comment("/** This is a test */"), - qr#^/\s*\*\*\s*This is a test\s+\@private\s*\*/\s*$#, - 'annotate_comment w/ arg'); -like(annotate_comment("/** This is a test */", '@testtag value'), - qr#^/\s*\*\*\s*This is a test\s+\@testtag\svalue\s*\*/\s*$#, - 'annotate_comment w/ tag argument'); - -# find_balanced_block -diag("Testing find_balanced_block"); -my @blocks = ( - # basic simple input - ['{', '}', '{ this is in the braces } {this is after}{{', - ['{ this is in the braces }', ' {this is after}{{'] , - 'basic input'], - - # discard leading chars before opening char - ['{', '}', 'discard {inner} after', - ['{inner}', ' after'], 'discard leading chars'], - - # empty input string - ['{', '}', '', - ['', ''], 'empty input string'], - - # nothing to match at all - ['{', '}', 'there is nothing to match', - ['', 'there is nothing to match'], 'nothing to match'], - ); -for my $test (@blocks){ - my @args = @{$test}[0..2]; - my ($expect, $explain) = @{$test}[3,4]; - is_deeply([find_balanced_block(@args)], $expect, $explain); -} - -# -# Test the @member tag -# -diag('Testing the @member tag'); -reset_parser(); -my $src = q# -/** @constructor */ -function Foo(){ - this.x = function(){return null;}; -} -/** Unrelated */ -function myfunc(){return null;} -#; -my $classes = parse_code_tree(\$src); -my %method_names = map { $_->{mapped_name} => 1 } - @{$classes->{Foo}->{instance_methods}}; -ok(not(defined($method_names{myfunc})), - 'Unrelated method is not added to class without @member tag'); -reset_parser(); -$src = q# -/** @constructor */ -function Foo(){ - this.x = function(){return null;}; -} -/** - * @member Foo - */ -function myfunc(){return null;} -#; -$classes = parse_code_tree(\$src); -%method_names = map { $_->{mapped_name} => 1 } - @{$classes->{Foo}->{instance_methods}}; -ok(defined($method_names{myfunc}), - 'Add method marked with @member to class'); -reset_parser(); - -# -# preprocess_source -# - -diag("Testing preprocess_source"); - -# Make sure that: -# -# Foo.prototype = { -# bar: function(){ return "Eep!"; }, -# baz: "Ha!" -# } -# -# becomes: -# -# Foo.prototype.bar = function(){ return "Eep!"; }; -# Foo.prototype.baz = "Ha!"; - -my $before = q/ - Foo.prototype = { - bar: function(){ return "Eep!"; }, - baz: "Ha!" - } /; - -my $after_re = qr/^\s*(?:$JSDOC_COMMENT)?\s*Foo.prototype.bar - \s*=\s* - function\(\s*\)\s*\{[^\}]*}\s*;\s* - Foo\.prototype\.baz\s*=\s*"[^"]+"\s*;\s*$/x; - -like(preprocess_source($before), $after_re, - 'Unpack prototype block assignment'); - -# -# Make sure that: -# -# /** @constructor */ -# Foo.Bar = function(){this.x = 2;var y = 3;} -# becomes: -# /** @constructor */ -# Foo.Bar = function(){}; -# -# /** @constructor */ -# function Foo.Bar(){} -# -# Foo.Bar.prototype.x = 2; -# -# /** @private */ -# Foo.Bar.prototype.y = 3; -# -$before = q# - /** @constructor */ - Foo.Bar = function(){this.x = 2; var y = 3; }#; -$after_re = qr{ - ^\s*/\*\*\s*\@constructor\s*\*/\s* - Foo\.Bar\s*=\s*function\s*\(\s*\)\s*\{\s*\}\s*;\s* - /\*\*\s*\@constructor\s*\*/\s* - function\s+Foo\.Bar\s*\(\s*\)\s*\{\s*\} - \s* - Foo\.Bar\.prototype\.x\s*=\s*2\s*;\s* - /\*\*\s*\@private\s*\*/\s* - Foo\.Bar\.prototype\.y\s*=\s*3\s*;\s*$ - }x; -like(preprocess_source($before), $after_re, - 'Unpack nested class'); - -# -# Make sure that: -# MySingleton = new function(){this.x=function(){}} -# and -# var MySingleton = new function(){this.x=function(){}} -# become: -# function MySingleton(){} -# MySingleton.prototype.x = function(){}; -# -$before = q# MySingleton = new function(){this.x=function(){}} #; -$after_re = qr{ - ^\s*(?:$JSDOC_COMMENT)? - \s*function\s*MySingleton\s*\(\)\s*\{\s*\}\s* - (?:$JSDOC_COMMENT)?\s* - MySingleton\.prototype\.x\s*=\s*function\s*\(\s*\)\s*\{\s*\}\s*;\s*$}x; -like(preprocess_source($before), $after_re, - 'Unpack singleton'); - -# Same thing, but with var before the declaration -$before = q#var MySingleton = new function(){this.x=function(){}} #; -like(preprocess_source($before), $after_re, - "Unpack var'd singleton"); - - -# -# Test unpacking a constructor into a bunch of -# prototype-based declarations -# - -$before = q# - /** - * @constructor - */ - function MyClass(){ - /** Private variable 'x' */ - var x = 3; - /** - * This is my function - */ - this.myFunction = function(){ return null; }; - - /** - * This is a private function - */ - function myPrivateFunction(x){ - return null; - } - } -#; -$after_re = qr{ - /\*\*\s* - \*\s*\@constructor\s* - \*/\s* - function\s+MyClass\s*\(\s*\)\s*\{\s*\}\s* - - /\*\*\s*Private\svariable\s'x'\s* - \@private\s*\*/\s* - MyClass\.prototype\.x\s*=\s*3\s*;\s* - - /\*\*\s* - \*\s*This\sis\smy\sfunction\s*\*/\s* - MyClass\.prototype\.myFunction\s*=\s*function\s*\(\s*\)\s*\{ - [^\}]*\}\s*;\s* - - /\*\*\s* - \*\s*This\sis\sa\sprivate\sfunction\s* - \@private\s*\*/\s* - MyClass\.prototype\.myPrivateFunction\s*=\s*function\(\s*x\s*\)\s* - \{[^\}]*\}\s*$ -}x; - -like(preprocess_source($before), $after_re, - 'Testing unpacking a constructor into prototype-based assignments'); - - -# -# Test the marking of void methods -# -$before = q'function MyFunc(){}'; -$after_re = qr{/\*\*\s*\@type\s+void\s*\*/\s*function\s+MyFunc\s*\(\)\{\}}; -like(preprocess_source($before), $after_re, - "Testing basic marking of void method without a docstring"); - -$before = q' -/** Method */ -function MyFunc(){} -'; -$after_re = qr{/\*\*\s*Method\s+\@type\s+void\s*\*/\s* - function\s+MyFunc\(\)\{\}}x; -like(preprocess_source($before), $after_re, - "Testing basic marking of void methods"); - -$before = '/** Method */ - Shape.prototype.MyFunc = function(){}'; -$after_re = qr{ - /\*\*\s* - Method\s+ - \@type\s+void\s* - \*/\s*Shape\.prototype\.MyFunc\s*=\s*function\(\)\{\}}x; -like(preprocess_source($before), $after_re, - "Testing marking of void anonymous method"); - -$before = 'Shape.prototype.MyFunc = function(){return null;}'; -$after_re = qr{^\s*Shape\.prototype\.MyFunc\s*= - \s*function\(\)\{[^\}]*\}}x; -like(preprocess_source($before), $after_re, - "Testing marking of void anonymous method"); - -$before = "function x(){return null;}"; -$after_re = qr{\s*function\sx\(\)\s*\{[^\}]*\}\s*$}; -like(preprocess_source($before), $after_re, - "Leave non-void methods without docstrings alone"); - -$before = "/** My test function */\nfunction x(){return null;}"; -$after_re = qr{\s*/\*\*\s*My\stest\sfunction\s*\*/\s* - function\sx\(\)\s*\{[^\}]*\}\s*$}x; -like(preprocess_source($before), $after_re, - "Leave non-void methods with docstrings alone"); - -reset_parser(); -$src = q# -/** - * @constructor - */ -function MyClass(){ - this.af = afunc; - this.bf = bfunc; - this.cf = cfunc; - function afunc(){} - function bfunc(){} - function cfunc(){} -} -#; -$classes = parse_code_tree(\$src); -ok(eq_set( - [ map { $_->{mapped_name} } - @{$classes->{MyClass}->{instance_methods}}], - ['af', 'bf', 'cf', 'afunc', 'bfunc', 'cfunc']), - "Ensure instance methods in constructor are correctly assigned"); - - - -reset_parser(); -$src = 'function MyFunction(){ return ""; }'; -$classes = parse_code_tree(\$src); -ok(!defined($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}), - "Ensure a function returning an empty string is not marked as void"); - -reset_parser(); -$src = 'function A(){ var x = "x"; }'; -$classes = parse_code_tree(\$src); -ok($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0] eq 'void', - "Ensure a global void is void"); - -reset_parser(); -$src = 'function A(c){ c.someFunc = function(){ return 2; }; }'; -$classes = parse_code_tree(\$src); -ok($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0] eq 'void', - "Ensure inner function definitions don't affect the return type"); - -reset_parser(); -$src = 'function A(c){ c.someFunc = function(){ return 2; }; return ""; }'; -$classes = parse_code_tree(\$src); -ok(!defined($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0]), - "Ensure inner-function measures don't affect non-void functions"); - -reset_parser(); -$src = '/** @return {int} Description */function f(){}'; -$classes = parse_code_tree(\$src); -ok(!defined($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0]), - 'Methods with a @return tag but no return statement are not marked void'); - -reset_parser(); -$src = 'function f(){ return (true ? "t" : "f");}'; -$classes = parse_code_tree(\$src); -ok(!defined($classes->{GLOBALS}->{class_methods}->[0]->{vars}->{type}->[0]), - "Non-void with non-trivial return statement is not marked as void"); - -# -# Try huge constructor input -# -my @testsrc = (q# -/** - * @class This is class information - * @constructor - */ - function MyClass(){ - -#); -for (1..30){ - push @testsrc, " - /** This is a private method */ - function f$_(){ return null; } - - /** - * THis is function number $_ - * \@return Nothing - */ - this.func$_ = function(){if(true){if(false){return null;}}} ;\n"; -} -push @testsrc, "\n}\n"; -my $testsrc = join("\n", @testsrc); -# This could crash everything -preprocess_source($testsrc); -pass("Process huge constructor with preprocess_source"); - - -# -# Huge constructor with unbalanced input -# -@testsrc = (q# -/** - * @class This is class information - * @constructor - */ - function MyClass(){ - -#); -for (1..100){ - push @testsrc, " - /** - * THis is function number $_ - * \@return Nothing - */ - this.func$_ = function(){if(true){if(false){return null;}};\n"; -} -push @testsrc, "\n}\n"; -$testsrc = join("\n", @testsrc); -# This could crash everything -preprocess_source($testsrc); -pass("Process huge unbalanced constructor with preprocess_source"); - -# -# deconstruct_mozilla_getset -# -$before = 'MyClass.prototype.__defineGetter__("myProp", function(){return null;});'; -$after_re = qr{ - ^\s*MyClass\.prototype\.myProp\s*=\s*null\s*;\s*$}x; - #\s*function\s*\(\s*\)\s*\{\s*return\s+null\s*;\s*\}\s*;\s*$}x; - -like(deconstruct_getset($before), $after_re, - "Testing behaviour of __defineGetter__"); -like(preprocess_source($before), $after_re, - "Testing behaviour of __defineGetter__ in preprocess_source"); - -$before = 'MyClass.prototype.__defineSetter__("myProp", function(){return null;});'; -$after_re = qr{ - ^\s*MyClass\.prototype\.myProp\s*=\s*null\s*;\s*$}x; - -like(deconstruct_getset($before), $after_re, - "Testing behaviour of __defineSetter__"); -like(preprocess_source($before), $after_re, - "Testing behaviour of __defineSetter__ in preprocess_source"); - -reset_parser(); -$src = " - function MyFunc(theclass){ - var x = 2; - theclass.prototype.f = function(){}; - return x; - } - MyClass.prototype.f = function(){}; -"; -$classes = parse_code_tree(\$src); -ok(not(defined($classes->{theclass})), - "Ensure that dynamic prototyping doesn't add classes"); -ok(defined($classes->{MyClass}), - "Ensure that normal classes are added with static prototyping"); - -# -# miscellaneous tests -# -diag("Miscellaneous tests"); -reset_parser(); -$src = " - /** \@constructor */ - function A(){} - /** \@constructor */ - function C(){} - /** \@constructor - \@extends A - */ - function B(){} - B.prototype = new C();"; - -$classes = parse_code_tree(\$src); -is($classes->{B}->{extends}, 'A', - "Test that the first extends marking is the good one, others are ignored"); - -reset_parser(); -$src = "function A(){ this.n = function(){return 2};} - var a = new A(); "; -$classes = parse_code_tree(\$src); -ok(defined($classes->{A}), - "Functions are later used with 'new' must be treated as a constructor"); - -ok(!defined($classes->{this}), "'this' cannot be added as a class"); - - -# -# Ensure using the @base tag automatically qualifies a function as a class, -# even if the base class isn't defined -# -reset_parser(); -$src = '/** @base SomeOtherClass */ -function MyClass(){}'; -$classes = parse_code_tree(\$src); -ok(defined($classes->{MyClass}), - 'A function must be upgraded to a class if the @base tag is used'); - -# -# Allow an anonymous function to be assigned to a global variable, -# resulting in a new class -# -reset_parser(); -$src = ' -/** - * Some function - * @constructor - */ -var SomeClass = function(){ this.x = 2; } -'; -$classes = parse_code_tree(\$src); -ok(defined($classes->{SomeClass}), - "Allow anonymous function to be assigned to a global variable"); - -# -# Make sure that dynamically binding methods to a object at a later time -# do not affect the documentation -# -reset_parser(); -$src = ' -function AddCallback(obj){ - obj.callback = function(){ return null; }; -}'; -$classes = parse_code_tree(\$src); -ok(!defined($classes->{obj}), - "Don't add passed-in objects as classes when doing dynamic binding"); - -reset_parser(); -$src = ' -/** @constructor */ -function A(){} -A.prototype.setup = A_Setup; -A.prototype.tearDown = A_TearDown; -function A_Setup(){ - this.callback = function(){ return null; }; -} -function A_TearDown(){ - this.tornDown = true; -}'; -$classes = parse_code_tree(\$src); -ok(!defined($classes->{this}), - "Don't add 'this' as a class when dynamically adding methods in a method"); - -# -# Test block prototype assignment -# -diag("Test block prototype assignment"); -reset_parser(); -$src = ' -SomeClass.prototype = { - funcA: function(){ return null; }, - valA: 3, - funcB: function(){ return null; }, - valB: "just testing", - funcC: function(){} -};'; -$classes = parse_code_tree(\$src); -ok(eq_set( - [ map { $_->{mapped_name} } - @{$classes->{SomeClass}->{instance_methods}}], - ['funcA', 'funcB', 'funcC']), - "Ensure instance methods are assigned in prototype definition block"); -ok(eq_set( - [ map { $_->{field_name} } - @{$classes->{SomeClass}->{instance_fields}}], - ['valA', 'valB']), - "Ensure instance fields are assigned in prototype definition block"); - -# -# Test prototype assignment -# -diag("Test prototype assignment"); -reset_parser(); -$src = ' -function Base(){} -function Sub(){} -Sub.prototype = new Base(); -'; -$classes = parse_code_tree(\$src); -ok($classes->{Sub}->{extends} eq 'Base', - "Prototype assignment results in inheritance"); - -reset_parser(); -$src = ' -function Base(){} -function Sub(){} -Sub.prototype = new Base; -'; -$classes = parse_code_tree(\$src); -ok($classes->{Sub}->{extends} eq 'Base', - "Prototype assignment results in inheritance (2)"); - -# -# Test the handling of methods defined more than once -# -reset_parser(); -$src = ' -function f(){} -/** doc */ -function f(){} -'; -$classes = parse_code_tree(\$src); -ok($classes->{GLOBALS}->{class_methods}->[0]->{description} eq 'doc', - "In case of double function definition, the one with most info wins"); - -reset_parser(); -$src = ' -/** doc */ -function f(){} -function f(){} -'; -$classes = parse_code_tree(\$src); -ok($classes->{GLOBALS}->{class_methods}->[0]->{description} eq 'doc', - "In case of double function definition, the one with most info wins (2)"); - -# -# Make sure that extra JSDoc-style comment blocks are not viewed as source -# -reset_parser(); -$src = ' -/** @constructor */ -function x(){} - -/** more doc -function y(){} -*/ - -/** @constructor */ -function z(){} -'; -$classes = parse_code_tree(\$src); -ok(!defined($classes->{GLOBALS}->{class_methods}->[0]), - "Ignore JSDoc in extra JSDoc-comment blocks"); - - -# -# Test the behaviour of the @ignore tag -# -reset_parser(); -$src = ' -/** This method is normal */ -function Normal(){} - -/** @ignore */ -function Hidden(){} -'; -$classes = parse_code_tree(\$src); -my %fnames = map { $_->{mapped_name} => 1 } - @{$classes->{GLOBALS}->{class_methods}}; -ok(defined $fnames{Normal}, "A normal method is picked up and documented"); -ok(!defined $fnames{Hidden}, 'An @ignored method is not picked up'); - -# -# Test the behaviour of the @addon tag -# -reset_parser(); -$src = ' -/** - * Should be ignored - */ -ClassOne.funcOne = function(){}; - -/** - * Should not be ignored - * @addon - */ -ClassTwo.funcOne = function(){}; - -ClassThree.prototype = new Object(); -ClassThree.funcThree = function(){}'; -$classes = parse_code_tree(\$src); -ok(!defined($classes->{ClassOne}), - 'Extensions to undefined classes/objects without @addon are ignored'); -ok(defined($classes->{ClassTwo}), - 'Extensions to undefined classes/objects with @addon are not ignored'); -ok($classes->{ClassThree}->{class_methods}->[0]->{mapped_name} eq 'funcThree', - 'Class methods without @addon work on pre-defined classes'); - -# -# Ensure enclosing package-classes are still recognized without using @addon -# -reset_parser(); -$src = ' -/** - * @constructor - */ -package.MyClass = function MyClass(){} - -package.MyClass.prototype.foo = function foo(){} -'; -$classes = parse_code_tree(\$src); -ok(defined($classes->{package}), - 'Super-package-classes must be recognized without the @addon tag'); -ok(defined($classes->{'package.MyClass'}), - 'Sub-package-classes must be recognized without the @addon tag'); - - diff --git a/modules/jala/util/HopKit/JSDoc/jsdoc.pl b/modules/jala/util/HopKit/JSDoc/jsdoc.pl deleted file mode 100644 index 8ef004bd..00000000 --- a/modules/jala/util/HopKit/JSDoc/jsdoc.pl +++ /dev/null @@ -1,1282 +0,0 @@ -#!/usr/bin/perl -w - -# -# This program makes use of the JSDoc module to make a JavaDoc equivalent -# for JavaScript. The template that is used is based on the JavaDoc -# doclet. This program only needs to be invoked with one or more -# JS OO sourcefiles as command-line args. -# - -use strict; -use HTML::Template; -use File::Copy; -use File::Basename; -use Getopt::Long; -use File::Find; -use lib dirname($0); -use JSDoc; -use JSDoc::XML; -use JSDoc::XMI; -use JavaScript::Syntax::HTML qw(to_html); - - -use constant LOCATION => dirname($0) . '/'; -use constant MAIN_TMPL => "main.tmpl"; -use constant ALLCLASSES_TMPL => 'allclasses-frame.tmpl'; -use constant ALLCLASSES_NOFRAME_TMPL => 'allclasses-noframe.tmpl'; -use constant OVERVIEW_FRAME_TMPL => 'overview-frame.tmpl'; -use constant TREE_TMPL => 'overview-tree.tmpl'; -use constant OVERVIEW_TMPL => 'overview-summary.tmpl'; -use constant INDEX_TMPL => 'index.tmpl'; -use constant DEFAULT_DEST_DIR => 'js_docs_out/'; -use constant STYLESHEET => 'stylesheet.css'; -use constant HELP_TMPL => 'help-doc.tmpl'; -use constant INDEX_ALL_TMPL => 'index-all.tmpl'; -use constant CONSTANTS_TMPL => 'constant-values.tmpl'; - -use vars qw/ $CLASSES $DEFAULT_CLASSNAME @CLASSNAMES @INDEX %TMPL_CACHE - %CLASS_ATTRS_MAP %METHOD_ATTRS_MAP %FILE_ATTRS_MAP %OPTIONS - @FILENAMES %FILE_OVERVIEWS $TIME $CURRENT_CLASS /; - -# -# Begin main execution -# - -&parse_cmdline; -&initialize_param_maps; -$TIME = localtime(); -do '.jsdoc_config'; -warn "Error parsing config file: $@\n" if $@; - -my @sources; - -mkdir($OPTIONS{OUTPUT}) - or die "Can't create output directory $OPTIONS{OUTPUT}: $!\n" - unless (-e $OPTIONS{OUTPUT} && -d $OPTIONS{OUTPUT}); - - -if (@ARGV < 1 || $OPTIONS{HELP} || !(@sources = &load_sources())){ - warn "No sourcefiles supplied\n" if !$OPTIONS{HELP}; - &show_usage(); - exit(1); -} - -# Parse the code tree -&configure_parser( - GLOBALS_NAME => $OPTIONS{GLOBALS_NAME}, - NO_LEXICAL_PRIVATES => $OPTIONS{NO_LEXICAL_PRIVATES}); -$CLASSES = &parse_code_tree(@sources); -%FILE_OVERVIEWS = %{delete $CLASSES->{__FILES__}}; -die "Nothing to document, exiting\n" unless keys %{$CLASSES}; - -if ($OPTIONS{FORMAT} eq 'html'){ - &output_html; -} elsif ($OPTIONS{FORMAT} eq 'xml') { - &output_xml; -} elsif ($OPTIONS{FORMAT} eq 'xmi'){ - &output_xmi; -} else { - die "Unknown data format '$OPTIONS{FORMAT}'\n"; -} - -&_log('Completed generating documentation'); - -# -# End main execution -# - - -# -# Output a single template -# -sub output_template { - my ($tmplname, $outname, $params, $relaxed) = (@_); - - $OPTIONS{TEMPLATEDIR} =~ s/(\S+)\/$/$1/; - - $tmplname = $OPTIONS{TEMPLATEDIR} . "/$tmplname"; - die "Template file '$tmplname' not found" unless -e $tmplname; - - # Caching templates seems to improve performance quite a lot - if (!$TMPL_CACHE{$tmplname}){ - $TMPL_CACHE{$tmplname} = new HTML::Template( - die_on_bad_params => !$relaxed, - filename => $tmplname); - } - my $tmpl = $TMPL_CACHE{$tmplname}; - $tmpl->param($params); - $outname = sprintf('%s%s', $OPTIONS{OUTPUT}, mangle($outname)); - &print_file($outname, $tmpl->output); -} - - -# -# Output data to a file -# -sub print_file { - my ($fname, $data) = @_; - open FILE, ">$fname" - or die "Couldn't open '$fname' to write: $!\n"; - print FILE $data; - close FILE; -} - -# -# Output HTML documentation in the output directory -# -sub output_html { - &output_class_templates(); - &output_index_template(); - &output_aux_templates(); - &output_tree_template(); -} - -# -# Output XMI in the output directory -# -sub output_xmi { - my $xmi = JSDoc::XMI->new(LOCATION); - &print_file("$OPTIONS{OUTPUT}/jsdoc.xmi", $xmi->output($CLASSES)); -} - -# -# Output XML in the output directory -# -sub output_xml { - my $xml = JSDoc::XML->new(LOCATION); - &print_file("$OPTIONS{OUTPUT}/jsdoc.xml", $xml->output($CLASSES)); -} - -# -# Gather information for each class and output its template -# -sub output_class_templates { - - # Note the class name for later, including classes that aren't defined - # but are used for inheritance - my %seen; - @CLASSNAMES = sort { lc $a->{classname} cmp lc $b->{classname}} - grep { !$seen{$_->{classname}}++ } - (map {classname => $_} , - grep { not defined $CLASSES->{$_}->{constructor_vars}->{private} - or $OPTIONS{PRIVATE} } - keys %$CLASSES), - (map { classname => $_ }, grep { !defined($$CLASSES{$_}) } - map { $_->{extends} } grep { defined($_->{extends}) } - values %$CLASSES); - die "Nothing to document, exiting\n" unless @CLASSNAMES; - - @FILENAMES = map {filename => $_, mangledfilename => mangle($_)}, - sort {lc($a) cmp lc($b)} grep {length $_} keys %FILE_OVERVIEWS; - for (my $i = 0; $i < @CLASSNAMES; $i++){ - my $classname = $CLASSNAMES[$i]->{classname}; - $CURRENT_CLASS = $classname; - next unless $$CLASSES{$classname}; - - # Template Parameters - my ($class, $subclasses, $class_summary, @constructor_params, - $next_class, $prev_class, $constructor_attrs, $constructor_detail); - - $class= $$CLASSES{$classname}; - &add_to_index($class, $classname); - - # Set up the constructor and class information - &resolve_synonyms($class->{constructor_vars}); - &format_vars($class->{constructor_vars}); - @constructor_params = - &fetch_args($class->{constructor_vars}, - \$class->{constructor_args}); - $constructor_attrs = - &format_method_attributes($class->{constructor_vars}); - $constructor_detail = - &resolve_inner_links($class->{constructor_detail}); - $class_summary = &format_class_attributes($class->{constructor_vars}); - $class_summary = &resolve_inner_links($class_summary); - - # Navbar information - $next_class = $i + 1 < @CLASSNAMES - ? $CLASSNAMES[$i + 1]->{classname} - : undef; - $prev_class = $i > 0 ? $CLASSNAMES[$i - 1]->{classname} : undef; - - # Find all the direct subclasses - $subclasses = join( ',', - map qq| $_|, - @{&find_subclasses($classname)}); - - my $superclass = $class->{extends} || ''; - - if ($$CLASSES{$superclass}){ - $superclass = "$superclass" - unless (!$OPTIONS{PRIVATE} - && $$CLASSES{$superclass}->{constructor_vars}->{private}); - } - - my $file_overview = $class->{constructor_vars}->{filename} ? - sprintf('overview-summary-%s.html', - mangle($class->{constructor_vars}->{filename})) - : ''; - - &output_template(MAIN_TMPL, "$classname.html", { - next_class => $next_class, - prev_class => $prev_class, - file_overview => $file_overview, - superclass => $superclass, - constructor_args => $class->{constructor_args}, - constructor_params => \@constructor_params, - constructor_attrs => $constructor_attrs, - constructor_returns => $class->{constructor_vars}->{returns}[0], - class_summary => $class_summary, - class_attribs => $class->{constructor_vars}->{private} ? - '<private>' : '', - constructor_detail => $constructor_detail, - constructor_summary => &get_summary($constructor_detail), - classname => $classname, - subclasses => $subclasses, - class_tree => &build_class_tree($classname, $CLASSES), - fields => &map_fields($class), - methods => &map_methods($class), - method_inheritance => &map_method_inheritance($class), - field_inheritance => &map_field_inheritance($class), - inner_classes => $class->{inner_classes}, - project_name => $OPTIONS{PROJECT_NAME}, - page_footer => $OPTIONS{PAGE_FOOTER}, - ctime => $TIME - }, 1); - } -} - -# -# Handle cleaning up / resolving inner links in FILE_OVERVIEWS -# -sub process_file_overviews { - for my $filename (map{$_->{filename}} @FILENAMES){ - my $overview = $FILE_OVERVIEWS{$filename}; - my $src = $overview->{src}; - $overview->{src} = ''; - format_vars($overview); - $overview = - resolve_inner_links($FILE_OVERVIEWS{$filename}); - $overview->{src} = $src; - $FILE_OVERVIEWS{$filename} = $overview; - } -} - -# -# Output all the non-class template files -# -sub output_aux_templates(){ - - unless ($OPTIONS{LOGO} and -f $OPTIONS{LOGO} and -r $OPTIONS{LOGO}){ - $OPTIONS{LOGO} and warn "Can't read $OPTIONS{LOGO}"; - $OPTIONS{LOGO} = ''; - } - $OPTIONS{LOGO} and copy $OPTIONS{LOGO}, $OPTIONS{OUTPUT}; - - &process_file_overviews; - $DEFAULT_CLASSNAME = - (grep { - defined($$CLASSES{$_->{classname}}) } @CLASSNAMES)[0]->{classname}; - - my $summary = &get_overall_summary; - - &output_classes_frames_templates; - &output_multiple_files_templates if @FILENAMES > 1; - &output_index_and_help_templates($summary); - &output_overview_summaries($summary); - &output_const_summary(); - my $stylesheet = LOCATION . STYLESHEET; - if ($OPTIONS{TEMPLATEDIR} ne LOCATION){ - $stylesheet = $OPTIONS{TEMPLATEDIR} . '/' . STYLESHEET; - die "Stylesheet '$stylesheet' not found" unless -e $stylesheet; - } - copy ($stylesheet, $OPTIONS{OUTPUT} . STYLESHEET); -} - -sub get_overall_summary { - my $summary; - if ($OPTIONS{PROJECT_SUMMARY}){ - if (-f $OPTIONS{PROJECT_SUMMARY} and - open SUMMARY, $OPTIONS{PROJECT_SUMMARY}){ - local $/ = undef; - $summary = ; - close SUMMARY; - } else { - warn "Can't open $OPTIONS{PROJECT_SUMMARY}"; - } - } elsif (@FILENAMES == 1) { - # If we only have one file and it has an overview, use that overview - my $filename = $FILENAMES[0]->{filename}; - if ($FILE_OVERVIEWS{$filename}->{fileoverview}){ - $summary = $FILE_OVERVIEWS{$filename}->{fileoverview}[0]; - $summary .= "

      "; - - while (my ($name, $val) = each %{$FILE_OVERVIEWS{$filename}}){ - $summary .= &{$FILE_ATTRS_MAP{$name}}($val) - if $FILE_ATTRS_MAP{$name}; - } - } - } - $summary; -} - -# -# Output the main (default) page and the help template -# -sub output_index_and_help_templates { - - my ($summary) = @_; - - # Output the main index template - &output_template(INDEX_TMPL, 'index.html', { - DEFAULT_CLASSNAME => @FILENAMES > 1 - ? 'overview-summary' - : $DEFAULT_CLASSNAME, - multifile => @FILENAMES > 1 }); - - # Output the help document template - &output_template(HELP_TMPL, 'help-doc.html', { - page_footer => $OPTIONS{PAGE_FOOTER}, - ctime => $TIME, - project_name => $OPTIONS{PROJECT_NAME} }); - -} - -# -# Output the frames listing all the classes -# -sub output_classes_frames_templates { - my $classnamesref = - [ grep { defined($$CLASSES{$_->{classname}}) } @CLASSNAMES ]; - my $params = { - filename => 'All Classes', - fname_link => 'All Classes', - CLASSNAMES => $classnamesref }; - if (@FILENAMES < 2){ - $params->{project_name} = $OPTIONS{PROJECT_NAME}; - $params->{logo} = basename($OPTIONS{LOGO}); - } - &output_template(ALLCLASSES_TMPL, 'allclasses-frame.html', $params); - - &output_template(ALLCLASSES_NOFRAME_TMPL, 'allclasses-noframe.html', { - CLASSNAMES => $classnamesref, - project_name => $OPTIONS{PROJECT_NAME}, - logo => basename($OPTIONS{LOGO}) }); - -} - -# -# Output the overview summary templates -# -sub output_overview_summaries { - my ($summary) = @_; - - my @overviews = map { - name => $_, - link => &mangle("overview-summary-$_.html"), - overview => - get_summary( - $FILE_OVERVIEWS{$_}{fileoverview}[0] || ' ') - }, sort {lc($a) cmp lc($b)} keys(%FILE_OVERVIEWS); - - &output_template(OVERVIEW_TMPL, 'overview-summary.html', { - generic => 1, - project_name => $OPTIONS{PROJECT_NAME}, - project_title => $OPTIONS{PROJECT_NAME}, - page_footer => $OPTIONS{PAGE_FOOTER}, - ctime => $TIME, - project_summary => $summary, - is_file_summary => 0, - overviews => \@overviews }); - - for my $filename (keys %FILE_OVERVIEWS){ - my @classes = grep { - ($$CLASSES{$_}->{constructor_vars}->{filename} || '') eq $filename - } keys %$CLASSES; - my @class_overviews = sort { lc($a->{name}) cmp lc($b->{name}) } - map { - name => $_, - link => "$_.html", - overview => get_summary( - $CLASSES->{$_}->{constructor_vars}->{class}[0] || ' ') - }, grep { !$CLASSES->{$_}->{constructor_vars}->{private} - || $OPTIONS{PRIVATE} } @classes; - my %overview = %{$FILE_OVERVIEWS{$filename}}; - my $src = delete $overview{src}; - my $summary = $overview{fileoverview}[0] || - "No overview generated for '$filename'"; - $summary .= "

      "; - while (my ($name, $val) = each %overview){ - $summary .= &{$FILE_ATTRS_MAP{$name}}($val) - if $FILE_ATTRS_MAP{$name}; - } - my @methods = - map { - is_private => $_->{is_private}, - method_summary => $_->{method_summary}, - is_class_method => $_->{is_class_method}, - method_anchor => - sprintf('%s%s', $_->{is_class_method} ? '!s!' : '', - $_->{method_name}), - method_arguments=> $_->{method_arguments}, - method_name => $_->{method_name}, - type => $_->{type}, - file_link => $OPTIONS{GLOBALS_NAME} . ".html" - }, @{&map_methods($$CLASSES{$OPTIONS{GLOBALS_NAME}}, $filename)}; - - &output_template(OVERVIEW_TMPL, "overview-summary-$filename.html", { - generic => 0, - sourcecode => $OPTIONS{NO_SRC} ? '' : &to_html($src), - project_name => $OPTIONS{PROJECT_NAME}, - project_title => $filename, - page_footer => $OPTIONS{PAGE_FOOTER}, - ctime => $TIME, - project_summary => $summary, - is_file_summary => 1, - methods => \@methods, - overviews => \@class_overviews }); - } - -} - -# -# Output a summary page about the 'static constant' field values for all -# classes -# -sub output_const_summary { - my @static_params; - for my $classname (sort { uc($a) cmp uc($b) } keys %$CLASSES){ - my $class = $CLASSES->{$classname}; - my @statics = grep { $_->{field_value} =~ /^(?:\d+)|(?:(['"]).*\1)$/} - grep { $_->{field_vars}->{final}} @{$class->{class_fields}}; - if (@statics){ - push @static_params, { - classname => $classname, - static_values => [map { - name => $_->{field_name}, - value => $_->{field_value}, - classname => $classname}, @statics] }; - } - } - &output_template(CONSTANTS_TMPL, 'constant-values.html', { - project_name => $OPTIONS{PROJECT_NAME}, - page_footer => $OPTIONS{PAGE_FOOTER}, - ctime => $TIME, - classnames => [map {name => $_->{classname}}, @static_params], - static_finals => \@static_params - } - ) if @static_params; -} - -# -# Method to handle outputting file overview template if -# more than one sourcefile is being processed -# -sub output_multiple_files_templates { - &output_template(OVERVIEW_FRAME_TMPL, 'overview-frame.html', { - logo => basename($OPTIONS{LOGO}), - project_name => $OPTIONS{PROJECT_NAME}, - filenames => \@FILENAMES }); - - for my $fname (map { $_->{filename}} @FILENAMES){ - my @classes = grep { - ($$CLASSES{$_}->{constructor_vars}->{filename} || '') eq $fname - } keys %$CLASSES; - - #methods under GLOBAL (detached) class - my @methods; - for (my $i = 0; $i < @CLASSNAMES; $i++){ - if($CLASSNAMES[$i]->{classname} eq $OPTIONS{GLOBALS_NAME}){ - my $class = $$CLASSES{$CLASSNAMES[$i]->{classname}}; - for my $method ( - sort {lc $a->{mapped_name} cmp lc $b->{mapped_name} } - @{$class->{class_methods}}){ - if(defined($fname) - && $fname eq $method->{vars}->{filename}){ - $method->{filename} = $fname; - push(@methods, $method); - } - } - last; - } - } - - &output_template(ALLCLASSES_TMPL, - sprintf('overview-%s.html', $fname), { - filename => $fname, - fname_link => $FILE_OVERVIEWS{$fname} - ? sprintf('%s', - mangle($fname), $fname) - : $fname, - CLASSNAMES => [map {classname => $_}, - grep { !$$CLASSES{$_}->{constructor_vars}->{private} - || $OPTIONS{PRIVATE} } sort @classes] }); - } -} - -# -# Mangle a file path so that it can be used as a filename -# -sub mangle { - local $_ = shift; - tr{/\\}{_}; - $_; -} - -# -# Build the tree representation of the inheritance -# PARAM: Name of the class -# -sub build_class_tree { - my $classname = shift; - my $class = $$CLASSES{$classname}; - my $tree = ""; - my @family; - push @family, $classname; - while ($class->{extends} and $class->{extends} ne ""){ - my $base = $class->{extends}; - if ($$CLASSES{$base}){ - $base = "$base" - unless (!$OPTIONS{PRIVATE} - && $$CLASSES{$base}->{constructor_vars}->{private}); - } elsif ($class->{constructor_vars}->{base}){ - if (my ($bcname, $url) = - $class->{constructor_vars}->{base}->[0] - =~ /^(\S+)\s(\S.*)$/){ - $base = "$base"; - } - } - push @family, $base; - $class = $$CLASSES{$class->{extends}}; - } - push @family, "Object"; - my $indent = 3; - $tree = (pop @family) . "\n"; - my $name = $_; - while ($name = pop (@family)){ - my $instr = " " x $indent; - $tree .= sprintf "%s|\n%s+--%s%s%s\n", $instr, $instr, - $name eq $classname ? "" : "", $name, - $name eq $classname ? "" : ""; - $indent += 6; - } - $tree; -} - -# -# Shown if no commandline args are given -# -sub show_usage(){ - print qq{Usage: jsdoc [OPTIONS] + - - -h | --help Show this message and exit - -r | --recursive Recurse through given directories - -p | --private Show private methods and fields - -d | --directory Specify output directory (defaults to js_docs_out) - -q | --quiet Suppress normal output - - --page-footer Specify (html) footer string that will be added to - all docs - --project-name Specify project name for that will be added to docs - --logo Specify a path to a logo to be used in the docs - --project-summary Specify a path to a text file that contains an - overview summary of the project - - --no-sources Don't include the source code view - - --extensions Provide a comma-separated list of file extensions - to be considered as JavaScript source files - - --package-naming Use package-style naming (i.e. keep directory names - in the file path). This is useful if you have multiple - files with the same name, but in different directories. - This option is only useful if --recursive is also used. - - --globals-name Specify a 'class name' under which all unattached - methods will be classified. The defaults to GLOBALS - - --format Set the output format. The options are html, xml - and xmi, defaulting to html. The others are currently - alpha software. - - --template-dir Provide another directory containing HTML templates - - --no-lexical-privates Ignore "private" variables and functions that are - lexically defined within constructors - - \n}; - -} - -# -# Take all the command line args as filenames and add them to @SOURCESFILES -# -sub load_sources(){ - my (@filenames, @sources); - my $ext_re = sprintf('%s', - join '|', split /\s*,\s*/, $OPTIONS{EXTENSIONS}); - for my $arg (@ARGV){ - if (-d $arg) { - $arg =~ s/(.*[^\/])$/$1\//; - find( { - wanted => sub { - push @filenames, { - name => $_, - relname => $OPTIONS{PACKAGENAMING} - ? substr($_, length($arg)) - : (fileparse($_))[0] - } if ((-f and -r and /.+\.$ext_re$/oi) && - (/^\Q$arg\E[^\/]+$/ || $OPTIONS{RECURSIVE})) - }, - no_chdir => 1 }, $arg); - } elsif (-f $arg){ - my $relname = (fileparse($arg))[0]; - push @filenames, { name => $arg, relname => $relname }; - } - } - for (@filenames){ - &_log(sprintf 'Loading sources from %s', $_->{name}); - open SRC, '<', $_->{name} - or (warn sprintf("Can't open %s, skipping: $!\n", $_->{name}) - and next); - local $/ = undef; - push @sources, $_->{relname}; - push @sources, \; - close SRC; - } - @sources; -} - -# -# Once all sources have been parsed, finds all subclasses -# of $classname -# -sub find_subclasses(){ - my ($classname) = @_; - my @subclasses; - for my $class (keys %$CLASSES){ - my $subclassname = $$CLASSES{$class}->{extends}; - if ($$CLASSES{$class}->{extends} and - $$CLASSES{$class}->{extends} eq $classname){ - push @subclasses, $class; - } - } - \@subclasses; -} - -# -# Make a summary of a description, cutting it off either at the first -# double newline or the first period followed by whitespace. -# PARAM: $description -# -sub get_summary { - my ($description) = @_; - my $summary; - if ($description){ - ($summary) = $description =~ /^(.*?(?:[?!.](?=\s)|\n\n)).*$/gs - or $summary = $description; - } else { - $summary = ""; - } - $summary; -} - - -# -# Set up all the instance and class methods for one template -# PARAM: A reference to a class -# PARAM: Optional filename, only maps methods for that file (used for GLOBAL) -# -sub map_methods{ - my ($class, $fname) = @_; - my @methods; - for my $mtype (qw(instance_methods class_methods)){ - next unless $class->{$mtype}; - - for my $method ( - sort {lc $a->{mapped_name} cmp lc $b->{mapped_name} } - @{$class->{$mtype}}){ - next if $fname && $fname ne $method->{vars}->{filename}; - &resolve_synonyms($method->{vars}); - next if (!$OPTIONS{PRIVATE} && $method->{vars}->{private}); - - $method->{vars}->{returns}[0] = - $method->{vars}->{returns}[0] || $method->{vars}->{return}; - - my @args = &fetch_args($method->{vars}, \$method->{argument_list}); - @args = map { &format_vars($_); $_ } @args; - - &format_vars($method->{vars}); - my $desc = &resolve_inner_links($method->{description}); - my $type = &map_return_type($method); - my $ret = $method->{vars}->{returns}[0]; - my $attrs = &format_method_attributes($method->{vars}); - - push @methods, { - method_description => $desc, - method_summary => &get_summary($desc), - method_name => $method->{mapped_name}, - method_arguments => $method->{argument_list}, - method_params => \@args, - method_returns => $ret, - is_class_method => $mtype eq 'class_methods', - is_private => defined($method->{vars}->{private}), - attributes => $attrs, - type => $type }; - } - } - \@methods; -} - -# -# Map a function return type -# -sub map_return_type { - my ($method) = @_; - #return 'Object' unless $method->{vars}->{type}[0]; - my $name = 'Object'; - my $link = ''; - if (defined($method->{vars}->{type})){ - $name = $method->{vars}->{type}[0]; - } elsif (defined($method->{vars}->{returns}[0])){ - if ($method->{vars}->{returns}[0] =~ s/\s*\{(\S+)(?:\s+([^}]+))?\}//){ - $name = $1; - $link = $2; - } - $method->{vars}->{type} = [$name]; - } - $name =~ s/^\s*(\S.*?)\s*$/$1/; - if ($$CLASSES{$name} || $link){ - $link ||= "$name.html"; - return qq|$name|; - } - $name; -} - -# -# Set up all the instance and class methods for one template -# PARAM: A reference to a class -# -sub map_fields { - my $class = shift; - my @fields; - # Set up the instance fields - for my $type (qw(instance_fields class_fields)){ - next unless $class->{$type}; - for (sort {lc $a->{field_name} cmp lc $b->{field_name} } - @{$class->{$type}}){ - - &resolve_synonyms($_->{field_vars}); - next if (!$OPTIONS{PRIVATE} && $_->{field_vars}->{private}); - my $description = &resolve_inner_links($_->{field_description}); - my $const_link = ($_->{field_vars}->{final} && - ($_->{field_value} =~ /^\-?\d+(\.\d+)?$/ - || $_->{field_value} =~ /^(["']).*\1$/)) - ? $class->{classname} : ''; - push @fields, { - field_name => $_->{field_name}, - field_description => $description, - field_summary => &get_summary($description), - is_final => defined($_->{field_vars}->{final}), - is_private => defined($_->{field_vars}->{private}), - is_class_field => $type eq 'class_fields', - type => &map_field_type($_), - const_link => $const_link}; - } - } - \@fields; -} - -# -# Map a field type -# -sub map_field_type { - my ($field) = @_; - return 'Object' unless $field->{field_vars}->{type}[0]; - my $name = $field->{field_vars}->{type}[0]; - $name =~ s/^\s*(\S.*?)\s*$/$1/; - return qq|$name| if $$CLASSES{$name}; - $name; -} - -# -# Map all the inherited methods to a template parameter -# PARAM: A reference to a class -# -sub map_method_inheritance { - my $class = shift; - my @method_inheritance; - # Set up the inherited methods - if ($class->{inherits}){ - my $superclassname = $class->{extends}; - my $superclass = $$CLASSES{$superclassname}; - while ($superclass){ - if (!$superclass->{constructor_vars}->{private} - || $OPTIONS{PRIVATE}){ - my $methods = - $class->{inherits}->{$superclassname}->{instance_methods}; - push @method_inheritance, { - superclass_name => $superclassname, - inherited_methods => join(', ', - map(qq|$_|, - &filter_private_methods( - $methods, $superclassname)))} - if ($methods and @$methods); - } - $superclassname = $superclass->{extends}; - $superclass = $superclassname ? $$CLASSES{$superclassname} : undef; - } - } - \@method_inheritance; -} - -# -# Map all the inherited fields to a template parameter -# PARAM: A reference to a class -# -sub map_field_inheritance { - my $class = shift; - my @field_inheritance; - # Set up the inherited fields - if ($class->{inherits}){ - my $superclassname = $class->{extends}; - my $superclass = $$CLASSES{$superclassname}; - while ($superclass){ - if (!$superclass->{constructor_vars}->{private} - || $OPTIONS{PRIVATE}){ - my $fields = - $class->{inherits}->{$superclassname}->{instance_fields}; - push @field_inheritance, { - superclass_name => $superclassname, - inherited_fields => join(', ', - map(qq|$_|, - &filter_private_fields($fields, $superclassname)))} - if ($fields and @$fields); - } - $superclassname = $superclass->{extends}; - $superclass = $superclassname ? $$CLASSES{$superclassname} : undef; - } - } - \@field_inheritance; -} - -# -# Filter out private inherited methods -# -sub filter_private_methods { - my ($methods, $superclassname) = @_; - my @visible_methods; - for my $method(@$methods){ - for my $super_method - (@{$$CLASSES{$superclassname}->{instance_methods}}){ - push @visible_methods, $method - if $method eq $super_method->{mapped_name} and - (!$super_method->{vars}->{private} || $OPTIONS{PRIVATE}); - } - } - @visible_methods; -} - -# -# Filter out private inherited fields -# -sub filter_private_fields { - my ($fields, $superclassname) = @_; - my @visible_fields; - for my $field (@$fields){ - for my $super_field(@{$$CLASSES{$superclassname}->{instance_fields}}){ - push @visible_fields, $field - if $field eq $super_field->{field_name} and - (!$super_field->{field_vars}->{private} - || $OPTIONS{PRIVATE}); - } - } - @visible_fields; -} - -# -# Adds a class's information to the global INDEX list -# -sub add_to_index { - my ($class, $classname) = @_; - push @INDEX, { - name => $classname, - class => $classname, - type => '', linkname => '' - }; - - if (!$class->{constructor_args}){ - $class->{constructor_args} = ''; - } else { - push @INDEX, { - name => "$classname$class->{constructor_args}", - class => $classname, - type => 'Constructor in ', - linkname => 'constructor_detail' }; - } - for my $mtype (qw(class_methods instance_methods)){ - my $type = sprintf('%s method in ', - $mtype eq 'class_methods' ? 'Class' : 'Instance'); - push @INDEX, { - name => "$_->{mapped_name}$_->{argument_list}", - class => $classname, - type => $type, - linkname => $_->{mapped_name}} - for grep { - not($_->{vars}->{private} and not $OPTIONS{PRIVATE}) - } @{$class->{$mtype}}; - - } - for my $ftype (qw(class_fields instance_fields)){ - my $type = sprintf('%s field in ', - $ftype eq 'class_fields' ? 'Class' : 'Instance'); - push @INDEX, { - name => $_->{field_name}, - class => $classname, - type => $type, - linkname => $_->{field_name}} - for grep { - not($_->{field_vars}->{private} and not $OPTIONS{PRIVATE}) - } @{$class->{$ftype}}; - } -} - -# -# Outputs the index page -# -sub output_index_template { - @INDEX = sort {lc $a->{name} cmp lc $b->{name}} @INDEX; - my %letters; - for my $item (@INDEX){ - my $letter = uc(substr($item->{name}, 0, 1)); - $letter = uc(substr($item->{class}, 0, 1)) if $letter eq ''; - push @{$letters{$letter}}, $item; - } - - my $letter_list = [map {letter_name => $_}, - sort {lc $a cmp lc $b} keys %letters]; - &output_template(INDEX_ALL_TMPL, 'index-all.html', { - letters => $letter_list, - project_name => $OPTIONS{PROJECT_NAME}, - page_footer => $OPTIONS{PAGE_FOOTER}, - ctime => $TIME, - index_list => [map { - letter => $_->{letter_name}, - value => $letters{$_->{letter_name}} - }, @{$letter_list}] }); -} - -# -# Recursively builds up the overview tree -# -sub build_tree { - my $parentclassname = shift || ''; - my $ret = ""; - for my $cname (map {$_->{classname}} @CLASSNAMES) { - next if $cname eq $OPTIONS{GLOBALS_NAME}; - my $class = $$CLASSES{$cname}; - my $parent = $class->{extends} || '-'; - if ((!$parentclassname && $parent eq '-') - or ($parent eq $parentclassname)) { - $ret .= $$CLASSES{$cname} ? qq{ -
    • - - $cname
    • - } : qq{ -
    • - $cname
    • - }; - my $childrentree .= &build_tree($cname); - $ret = "$ret$childrentree" if $childrentree; - } - } - $ret = "
        $ret
      " unless not $ret; - if ($parentclassname eq ''){ - $ret = qq{
      • Object
      • $ret
      }; - } - $ret; -} - -# -# Outputs the overview tree -# -sub output_tree_template { - my $tree = &build_tree(); - &output_template(TREE_TMPL, 'overview-tree.html', { - classtrees => $tree, - project_name => $OPTIONS{PROJECT_NAME}, - page_footer => $OPTIONS{PAGE_FOOTER}, - ctime => $TIME }, 1); -} - -# -# Formats additional non-standard attributes for methods according to user -# configuration -# -sub format_method_attributes { - my ($attrs) = shift; - my $attributes = ''; - while (my ($name, $val) = each %{$attrs}) { - $attributes .= &{$METHOD_ATTRS_MAP{$name}}($val) - if $METHOD_ATTRS_MAP{$name}; - } - $attributes; -} - -# -# Formats additional non-standard attributes for classes according to user -# configuration -# -sub format_class_attributes { - my ($attrs) = shift; - my $attributes; - if ($attrs->{class} && @{ $attrs->{class} }){ - $attributes = sprintf('
      %s
      ', $attrs->{class}[0] || '') - } - while (my ($name, $val) = each %{$attrs}) { - $attributes .= &{$CLASS_ATTRS_MAP{$name}}($val) - if $CLASS_ATTRS_MAP{$name}; - } - $attributes; -} - -# -# Parses the command line options -# -sub parse_cmdline { - $OPTIONS{OUTPUT} = DEFAULT_DEST_DIR; - $OPTIONS{PROJECT_NAME} = ''; - $OPTIONS{COPYRIGHT} = ''; - $OPTIONS{PROJECT_SUMMARY} = ''; - $OPTIONS{LOGO} = ''; - $OPTIONS{GLOBALS_NAME} = 'GLOBALS'; - $OPTIONS{FORMAT} = 'html'; - $OPTIONS{EXTENSIONS} = 'js'; - $OPTIONS{TEMPLATEDIR} = LOCATION; - GetOptions( - 'private|p' => \$OPTIONS{PRIVATE}, - 'directory|d=s' => \$OPTIONS{OUTPUT}, - 'help|h' => \$OPTIONS{HELP}, - 'recursive|r' => \$OPTIONS{RECURSIVE}, - 'page-footer=s' => \$OPTIONS{PAGE_FOOTER}, - 'project-name=s' => \$OPTIONS{PROJECT_NAME}, - 'project-summary=s' => \$OPTIONS{PROJECT_SUMMARY}, - 'logo=s' => \$OPTIONS{LOGO}, - 'globals-name=s' => \$OPTIONS{GLOBALS_NAME}, - 'quiet|q' => \$OPTIONS{QUIET}, - 'no-sources' => \$OPTIONS{NO_SRC}, - 'package-naming' => \$OPTIONS{PACKAGENAMING}, - 'format=s' => \$OPTIONS{FORMAT}, - 'extensions=s' => \$OPTIONS{EXTENSIONS}, - 'no-lexical-privates' => \$OPTIONS{NO_LEXICAL_PRIVATES}, - 'template-dir=s' => \$OPTIONS{TEMPLATEDIR}); - $OPTIONS{OUTPUT} =~ s/([^\/])$/$1\//; -} - -# -# Resolves links for {@link } items -# -sub resolve_inner_links { - my $doc = shift; - $doc =~ s{\{\@link\s+([^\}]+)\}}{&format_link($1)}eg if $doc; - return $doc; -} - - -# -# Formats a {@link } item -# -sub format_link { - my ($link) = shift; - die unless $CURRENT_CLASS; - $link =~ s/^\s*(.*?)\s*$/$1/; - $link =~ s/<[^>]*>//g; - my ($class, $method, $label, $url); - my $class_re = qr/\w+(?:\.\w+)*/; - unless ((($class, $method, $label) = - $link =~ /^($class_re)?#($class_re)\s*(.*)$/) - or (($class, $label) = $link =~ /^($class_re)(?:\s+(.*))?$/)){ - if (($url, $label) = $link =~ /^(https?:\/\/\S+)\s+(.*?)\s*$/){ - return "$label"; - } else { - return $link; - } - } - if ($class){ - unless ($$CLASSES{$class}){ - warn "\@link can't find reference $class\n"; - return $link; - } - } - if (!$method){ - $label = $class unless $label; - qq{$label}; - } else { - my $clss = $CLASSES->{$class || $CURRENT_CLASS}; - my @methods = (@{$clss->{instance_methods}}, - @{$clss->{class_methods}}); - my @fields = (@{$clss->{instance_fields}}, @{$clss->{class_fields}}); - my @statics = (@{$clss->{class_methods}}, @{$clss->{class_fields}}); - my $ismethod = grep { $_->{mapped_name} eq $method } @methods; - my $isfield = grep { $_->{field_name} eq $method } @fields - unless $ismethod; - my $isstatic = grep { - ($_->{field_name} || $_->{mapped_name}) eq $method } @statics; - if ($class){ - $label = "$class.$method" . ($ismethod ? '()' : '') unless $label; - if ($ismethod or $isfield){ - $method = ($isstatic ? "!s!" : "") . $method; - qq{$label}; - } else { - warn "\@link can't find reference $method in $class\n"; - $link; - } - } else { - $label = $method . ($ismethod ? "()" : "") unless $label; - $method = ($isstatic ? "!s!" : "") . $method; - qq{$label}; - } - } -} - - -# -# Initializes the customizable maps for @attributes -# -sub initialize_param_maps { - %CLASS_ATTRS_MAP = ( - author => - sub { - 'Author: ' . - join(', ', @{$_[0]}) . "
      " - }, - deprecated => - sub { - 'Deprecated ' . ($_[0] ? $_[0]->[0] : '') . - "

      "; - }, - see => - sub { - 'See:
        - ' . - join('
        - ', map {&format_link($_)} @{$_[0]}) . "
      " - }, - version => - sub { - 'Version: ' . - join(', ', @{$_[0]}) . '

      ' - }, - requires => - sub { - 'Requires:
        - ' . - join('
        - ', map {&format_link($_)} @{$_[0]}) . "
      " - }, - filename => - sub { - sprintf 'Defined in %s

      ', - sprintf("%s", - mangle($_[0]), $_[0]); - }, - overviewfile => - sub { - my ($content, $fh) = ""; - my $fname = $_[0][0] or return ''; - unless(open $fh, "$fname"){ - warn "Can't open overview file '$fname' : $!\n"; - return ''; - } - { local $/ = undef; $content .= <$fh> } - close $fh or warn "Couldn't close overview file '$fname'\n"; - # Crude manner to strip out extra HTML - $content =~ s/(.*)<\/body>/$1/si; - "$content
      "; - } - ); - - %METHOD_ATTRS_MAP = ( - throws => - sub { - "Throws:
        - " . - join("
        - ", @{$_[0]}) . "
      " - }, - ); - $METHOD_ATTRS_MAP{exception} = $METHOD_ATTRS_MAP{throws}; - $METHOD_ATTRS_MAP{$_} = $CLASS_ATTRS_MAP{$_} for qw(author version - deprecated see requires); - $FILE_ATTRS_MAP{$_} = $CLASS_ATTRS_MAP{$_} for qw(author version - see requires); -} - -# -# Parse the @param or @argument values into name/value pairs and -# return the list of them -# -sub fetch_args { - my ($vars, $arg_list_ref) = @_; - return unless $vars and $$arg_list_ref; - my (@args, %used); - for my $arg (split /\W+(?{param}}){ - my ($type, $link, $name, $value) = - /(?: - \{\s* - (\S+) # type name - (?:\s+(\S+)\s*)? # optional link - \})? - \s* - (\$?\w+) # parameter name - (.*) # description - /x; - next unless $name eq $arg; - $used{$name} = 1; - $type ||= ''; - if ($$CLASSES{$type} || $link){ - $link ||= "$type.html"; - $type = qq|$type| ; - } - my $type_regex = qr{\Q$arg\E\b}; - $$arg_list_ref =~ s/(? $name, vardescrip => $value}; - } - } - for (@{$vars->{param}}){ - my ($type, $link, $name, $value) - = /(?:\{\s*(\S+)(?:\s+(\S+)\s*)?\})?\s*(\$?\w+)(.*)/; - next if $used{$name}; - push @args, { varname => $name, vardescrip => $value }; - } - @args; -} - -sub resolve_synonyms { - my ($item) = @_; - $item->{param} = $item->{param} || $item->{argument}; - $item->{returns} = $item->{return} || $item->{returns}; - $item->{final} = $item->{final} || $item->{const}; -} - -# -# Log a message to STDOUT if the --quiet switch is not used -# -sub _log { - print $_[0], "\n" unless $OPTIONS{QUIET}; -} - -# -# Takes a vars hash and resolves {@link}s within it -# -sub format_vars { - my ($vars) = @_; - for my $key (keys %$vars){ - if (ref($vars->{$key}) eq 'ARRAY'){ - for (0..$#{$vars->{$key}}){ - $vars->{$key}->[$_] = &resolve_inner_links($vars->{$key}->[$_]); - } - } else { - $vars->{$key} = &resolve_inner_links($vars->{$key}); - } - } -} - diff --git a/modules/jala/util/HopKit/JSDoc/templates/allclasses-frame.tmpl b/modules/jala/util/HopKit/JSDoc/templates/allclasses-frame.tmpl deleted file mode 100644 index e2a4ce31..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/allclasses-frame.tmpl +++ /dev/null @@ -1,37 +0,0 @@ - - - - - -<TMPL_VAR NAME="project_name"> <TMPL_VAR NAME="filename"> - - - - - - - "/> - -

      - - -
      - - - - - - - - -
      .html" TARGET="classFrame"> -
      -
      - - - diff --git a/modules/jala/util/HopKit/JSDoc/templates/allclasses-noframe.tmpl b/modules/jala/util/HopKit/JSDoc/templates/allclasses-noframe.tmpl deleted file mode 100644 index 6da363c1..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/allclasses-noframe.tmpl +++ /dev/null @@ -1,36 +0,0 @@ - - - - -<TMPL_VAR NAME="project_name"> All Classes - - - - - - - "/> - -

      - -All Classes -
      - - - - - - - - -
      .html" > -
      -
      - - - diff --git a/modules/jala/util/HopKit/JSDoc/templates/constant-values.tmpl b/modules/jala/util/HopKit/JSDoc/templates/constant-values.tmpl deleted file mode 100644 index fb4307c4..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/constant-values.tmpl +++ /dev/null @@ -1,151 +0,0 @@ - - - - -<TMPL_VAR NAME="project_name"> Constant Values - - - - - - - - - - - - - - - - - - -
      - - -
      - - -
      -

      Constant Field Values

      -
      -
        - -
      • ">
      • -
        -
      - -
      - - - "> - - - - - - - - - - - -
      - .html"> -
      .html#">
      -

      - -

      - - -


      - - - - - - - - - - - - - -
      - - -
      - - -
      - - - -
      Documentation generated by JSDoc on
      - - diff --git a/modules/jala/util/HopKit/JSDoc/templates/help-doc.tmpl b/modules/jala/util/HopKit/JSDoc/templates/help-doc.tmpl deleted file mode 100644 index 5f70ef3c..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/help-doc.tmpl +++ /dev/null @@ -1,160 +0,0 @@ - - - - -<TMPL_VAR NAME="project_name"> API Help - - - - - - - - - - - - - - - - - - -
      - - -
      - - -
      -
      -

      -How This API Document Is Organized

      -
      -This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

      -Class

      -
      - -

      -Each class has its own separate page. Each of these pages has three sections consisting of a class description, summary tables, and detailed member descriptions:

        -
      • Class inheritance diagram
      • Direct Subclasses
      • Class declaration
      • Class description -

        -

      • Field Summary
      • Constructor Summary
      • Method Summary -

        -

      • Field Detail
      • Constructor Detail
      • Method Detail
      -Each summary entry contains the first sentence from the detailed description for that item.
      - - -

      -Index

      -
      -The Index contains an alphabetic list of all classes, constructors, methods, and fields.
      -

      -Prev/Next

      -These links take you to the next or previous class, interface, package, or related page.

      -Frames/No Frames

      -These links show and hide the HTML frames. All pages are available with or without frames. -

      - - -This help file applies to API documentation generated using the standard doclet. - -
      -


      - - - - - - - - - - - - - -
      - - -
      - - -
      - - - -
      Documentation generated by JSDoc on
      - - diff --git a/modules/jala/util/HopKit/JSDoc/templates/index-all.tmpl b/modules/jala/util/HopKit/JSDoc/templates/index-all.tmpl deleted file mode 100644 index 262a1e22..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/index-all.tmpl +++ /dev/null @@ -1,142 +0,0 @@ - - - - - -Index () - - - - - - - - - - - - - - - - - - -
      - - -
      - - - - __"> -
      - - -__">

      -

      - -
      -
      .html#"> - - class .html"> -
        -
      -
      -
      -
      - - __"> - -
      - - - - - - - - - - - - -
      - - -
      - - -
      - - - -
      Documentation generated by JSDoc on
      - - diff --git a/modules/jala/util/HopKit/JSDoc/templates/index.tmpl b/modules/jala/util/HopKit/JSDoc/templates/index.tmpl deleted file mode 100644 index 1899a483..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/index.tmpl +++ /dev/null @@ -1,27 +0,0 @@ - - - - -Generated Javascript Documentation - - - - - - - - - - - -.html" name="classFrame"> - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to <A HREF="allclasses-frame.html">Non-frame version.</A> - diff --git a/modules/jala/util/HopKit/JSDoc/templates/main.tmpl b/modules/jala/util/HopKit/JSDoc/templates/main.tmpl deleted file mode 100644 index b89866e3..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/main.tmpl +++ /dev/null @@ -1,448 +0,0 @@ - - - - - -<TMPL_VAR name="classname"> - - - - - - - - - - - - - - - - - - - - - -
      - - -
      - -
      - - -

      Class

      -
      - -
      -
      - Direct Known Subclasses: -
      - -
      -
      -
      - -
      -
      - -
       class - - -
      extends - - -
      - -

      - -

      -
      -
      - - - - - - - - - - - - - - -
      -Nested Class Summary
      - <static class>.html">
      -  -
      - - - - - - - - - - - - - - - - - - - -
      - Field Summary
      - <private> <static>  <final> !s!"> -
      -           
      -   -
      - - - -   - - - - - - - -
      Fields inherited from class .html">
      - -
      -  -
      -
      - - - - - - - - - - - - - - -
      -Constructor Summary
      - - - .html#()"> - - - -
      -             - -
      -
      - - -  - - - - - - - - - - - - - - - - -
      -Method Summary
      - - <static> <private>   - - - - - !s!"> - -
      -            - -
      -
      - - - - - - - - - -
      Methods inherited from class .html">
      - - -
      -  -
      -

      - - - - - - - - - - -
      Field Detail
      - - - !s!
      "> -

      -
      <private> <static> <final>  
      - -
      -
      - - - - - - - - - - - -
      - Constructor Detail -
      - -()">

      -

      -
      - - -
        - -
      -
      - - -
        - Parameters: - -
          - -
        -
        - -
      -
      - - - -
        - Returns: -
          - -
        -
      -
      - - - - -
        - -
      -
      -
      - - - - - - - - - - - - -
      - Method Detail -
      - - - - !s!
      "> -

      -
      <static>  <private>  
      - -
      -
      - - - -
        - Parameters: - -
          - -
        -
        -
      -
      - - - -
        - Returns: -
          - -
        -
      -
      - - - -
        - -
      -
      - -
      - -
      - - - - - - - - - - - - - - - - - - - - -
      - - -
      - - - -
      - - - -
      Documentation generated by JSDoc on
      - - diff --git a/modules/jala/util/HopKit/JSDoc/templates/overview-frame.tmpl b/modules/jala/util/HopKit/JSDoc/templates/overview-frame.tmpl deleted file mode 100644 index 5097ca4c..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/overview-frame.tmpl +++ /dev/null @@ -1,43 +0,0 @@ - - - - -Overview () - - - - - - - "/> - -

      - - - - -
      - - - - - -
      All Classes -

      - -Files -
      - -.html" TARGET="packageFrame">
      -
      -

      - -

      -  - - diff --git a/modules/jala/util/HopKit/JSDoc/templates/overview-summary.tmpl b/modules/jala/util/HopKit/JSDoc/templates/overview-summary.tmpl deleted file mode 100644 index 504c1f76..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/overview-summary.tmpl +++ /dev/null @@ -1,222 +0,0 @@ - - - - -<tmpl_var name="project_name"> Overview - - - - - - - - - - - - - - - - - - -
      - - -
      - - -


      -
      - -

      - -

      JSDoc Documentation

      -
      -
      - - -

      - This document is the API Specification for - . -

      -
      -
      - -

      Summary

      -

      - - - - No summary generated for these documents. - -

      - -
      - - - - - - - - - - - - -
      - - Class Summary - - File Summary - -
      ">
      -
      -
      - - - - - - - - - - - - - - - - -
      - - Method Summary - -
      - - static private   - - - - - #"> - -
      -            - -
      -

      - - - - -

      -
      -
      - - - - - - - - - - - - - - -
      - -
      - - -
      - - - -
      Documentation generated by JSDoc on
      - - diff --git a/modules/jala/util/HopKit/JSDoc/templates/overview-tree.tmpl b/modules/jala/util/HopKit/JSDoc/templates/overview-tree.tmpl deleted file mode 100644 index 47968010..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/overview-tree.tmpl +++ /dev/null @@ -1,121 +0,0 @@ - - - - - -<TMPL_VAR name="project_name"> Class Hierarchy - - - - - - - - - - - - - - - - - - -
      - -
      - - -
      -

      Class Hierarchy

      - - - -
      - - - - - - - - - - - - - -
      - -
      - - -
      - - - -
      Documentation generated by JSDoc on
      - - diff --git a/modules/jala/util/HopKit/JSDoc/templates/stylesheet.css b/modules/jala/util/HopKit/JSDoc/templates/stylesheet.css deleted file mode 100644 index 7a35c0c1..00000000 --- a/modules/jala/util/HopKit/JSDoc/templates/stylesheet.css +++ /dev/null @@ -1,39 +0,0 @@ -/* JSDoc style sheet */ - -/* Define colors, fonts and other style attributes here to override the defaults */ - -/* Page background color */ -body { background-color: #FFFFFF } - -/* Table colors */ -.TableHeadingColor { background: #CCCCFF } /* Dark mauve */ -.TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ -.TableRowColor { background: #FFFFFF } /* White */ - -/* Font used in left-hand frame lists */ -.FrameTitleFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } -.FrameHeadingFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } -.FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } - -/* Example of smaller, sans-serif font in frames */ -/* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */ - -/* Navigation bar fonts and colors */ -.NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */ -.NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */ -.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} -.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} - -.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} -.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} - -.jsdoc_ctime { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; - text-align: right } - -/* Sourcecode view */ -.sourceview { background: #FFFFFF } -.attrib { color: #DD7777 } -.comment { color: #55AA55 } -.reserved { color: #FF5555 } -.literal { color: #5555FF } - diff --git a/modules/jala/util/HopKit/JSDoc/test.js b/modules/jala/util/HopKit/JSDoc/test.js deleted file mode 100644 index 72e3fde5..00000000 --- a/modules/jala/util/HopKit/JSDoc/test.js +++ /dev/null @@ -1,505 +0,0 @@ -/** - * @fileoverview This file is to be used for testing the JSDoc parser - * It is not intended to be an example of good JavaScript OO-programming, - * nor is it intended to fulfill any specific purpose apart from - * demonstrating the functionality of the - * {@link http://sourceforge.net/projects/jsdoc JSDoc} parser - * - * @author Gabriel Reid gab_reid@users.sourceforge.net - * @version 0.1 - */ - - -/** - * Construct a new Shape object. - * @class This is the basic Shape class. - * It can be considered an abstract class, even though no such thing - * really existing in JavaScript - * @constructor - * @throws MemoryException if there is no more memory - * @throws GeneralShapeException rarely (if ever) - * @return A new shape - */ -function Shape(){ - - /** - * This is an example of a function that is not given as a property - * of a prototype, but instead it is assigned within a constructor. - * For inner functions like this to be picked up by the parser, the - * function that acts as a constructor must be denoted with - * the @constructor tag in its comment. - * @type String - */ - this.getClassName = function(){ - return "Shape"; - } - - /** - * This is a private method, just used here as an example - */ - function addReference(){ - // Do nothing... - } - -} - -/** - * Create a new Hexagon instance. - * @extends Shape - * @class Hexagon is a class that is a logical sublcass of - * {@link Shape} (thanks to the @extends tag), but in - * reality it is completely unrelated to Shape. - * @param {int} sideLength The length of one side for the new Hexagon - */ -function Hexagon(sideLength) { -} - - -/** - * This is an unattached (static) function that adds two integers together. - * @param {int} One The first number to add - * @param {int http://jsdoc.sourceforge.net/} Two The second number to add - * @author Gabriel Reid - * @deprecated So you shouldn't use it anymore! - */ -function Add(One, Two){ - return One + Two; -} - - -/** - * The color of this shape - * @type Color - */ -Shape.prototype.color = null; - -/** - * The border of this shape. - * @type int - */ -Shape.prototype.border = null; - -/* - * The assignment of function implementations for Shape, documentation will - * be taken over from the method declaration. - */ - -Shape.prototype.getCoords = Shape_GetCoords; - -Shape.prototype.getColor = Shape_GetColor; - -Shape.prototype.setCoords = Shape_SetCoords; - -Shape.prototype.setColor = Shape_SetColor; - -/* - * These are all the instance method implementations for Shape - */ - -/** - * Get the coordinates of this shape. It is assumed that we're always talking - * about shapes in a 2D location here. - * @requires Shape The shape class - * @returns A Coordinate object representing the location of this Shape - * @type Coordinate - */ -function Shape_GetCoords(){ - return this.coords; -} - -/** - * Get the color of this shape. - * @see #setColor - * @type Color - */ -function Shape_GetColor(){ - return this.color; -} - -/** - * Set the coordinates for this Shape - * @param {Coordinate} coordinates The coordinates to set for this Shape - */ -function Shape_SetCoords(coordinates){ - this.coords = coordinates; -} - -/** - * Set the color for this Shape - * @param {Color} color The color to set for this Shape - * @param other There is no other param, but it can still be documented if - * optional parameters are used - * @throws NonExistantColorException (no, not really!) - * @see #getColor - */ -function Shape_SetColor(color){ - this.color = color; -} - -/** - * Clone this shape - * @returns A copy of this shape - * @type Shape - * @author Gabriel Reid - */ -Shape.prototype.clone = function(){ - return new Shape(); -} - -/** - * Create a new Rectangle instance. - * @class A basic rectangle class, inherits from Shape. - * This class could be considered a concrete implementation class - * @constructor - * @param {int} width The optional width for this Rectangle - * @param {int} height Thie optional height for this Rectangle - * @author Gabriel Reid - * @see Shape Shape is the base class for this - */ -function Rectangle(width, // This is the width - height // This is the height - ){ - if (width){ - this.width = width; - if (height){ - this.height = height; - } - } -} - - -/* Inherit from Shape */ -Rectangle.prototype = new Shape(); - -/** - * Value to represent the width of the Rectangle. - *
      Text in bold and italic and a - * link to SourceForge - * @private - * @type int - */ -Rectangle.prototype.width = 0; - -/** - * Value to represent the height of the Rectangle - * @private - * @type int - */ -Rectangle.prototype.height = 0; - -/** - * Get the type of this object. - * @type String - */ -Rectangle.prototype.getClassName= function(){ - return "Rectangle"; -} - -/* - * These are all the instance method implementations for Rectangle - */ - -Rectangle.prototype.getWidth = Rectangle_GetWidth; - -Rectangle.prototype.getHeight = Rectangle_GetHeight; - -Rectangle.prototype.setWidth = Rectangle_SetWidth; - -Rectangle.prototype.setHeight = Rectangle_SetHeight; - -Rectangle.prototype.getArea = Rectangle_GetArea; - - -/** - * Get the value of the width for the Rectangle - * @type int - * @see #setWidth - */ -function Rectangle_GetWidth(){ - return this.width; -} - -/** - * Get the value of the height for the Rectangle. - * Another getter is the {@link Shape#getColor} method in the - * {@link Shape base Shape class}. - * @return The height of this Rectangle - * @type int - * @see #setHeight - */ -function Rectangle_GetHeight(){ - return this.height; -} - -/** - * Set the width value for this Rectangle. - * @param {int} width The width value to be set - * @see #getWidth - */ -function Rectangle_SetWidth(width){ - this.width = width; -} - -/** - * Set the height value for this Rectangle. - * @param {int} height The height value to be set - * @see #getHeight - */ -function Rectangle_SetHeight(height){ - this.height = height; -} - -/** - * Get the value for the total area of this Rectangle - * @return total area of this Rectangle - * @type int - */ -function Rectangle_GetArea(){ - return width * height; -} - - -/** - * Create a new Square instance. - * @class A Square is a subclass of {@link Rectangle} - * @param {int} width The optional width for this Rectangle - * @param {int} height The optional height for this Rectangle - */ -function Square(width, height){ - if (width){ - this.width = width; - if (height){ - this.height = height; - } - } - -} - -/* Square is a subclass of Rectangle */ -Square.prototype = new Rectangle(); - - -/* - * The assignment of function implementation for Shape. - */ -Square.prototype.setWidth = Square_SetWidth; - -Square.prototype.setHeight = Square_SetHeight; - - - -/** - * Set the width value for this Square. - * @param {int} width The width value to be set - * @see #getWidth - */ -function Square_SetWidth(width){ - this.width = this.height = width; -} - -/** - * Set the height value for this Square - * Sets the {@link Rectangle#height height} attribute in the Rectangle. - * @param {int} height The height value to be set - */ -function Square_SetHeight(height){ - this.height = this.width = height; -} - - -/** - * Create a new Circle instance based on a radius. - * @class Circle class is another subclass of Shape - * @param {int} radius The optional radius of this Circle - */ -function Circle(radius){ - if (radius){ - this.radius = radius; - } -} - -/* Circle inherits from Shape */ -Circle.prototype = new Shape(); - -/** - * The radius value for this Circle - * @private - * @type int - */ -Circle.prototype.radius = 0; - -/** - * A very simple class (static) field that is also a constant - * @final - * @type float - */ -Circle.PI = 3.14; - -Circle.createCircle = Circle_CreateCircle; - -Circle.prototype.getRadius = Circle_GetRadius; - -Circle.prototype.setRadius = Circle_SetRadius; - -/** - * Get the radius value for this Circle - * @type int - * @see #setRadius - */ -function Circle_GetRadius(){ - return this.radius; -} - -/** - * Set the radius value for this Circle - * @param {int} radius The radius value to set - * @see #getRadius - */ -function Circle_SetRadius(radius){ - this.radius = radius; -} - -/** - * An example of a class (static) method that acts as a factory for Circle - * objects. Given a radius value, this method creates a new Circle. - * @param {int} radius The radius value to use for the new Circle. - * @type Circle - */ -function Circle_CreateCircle(radius){ - return new Circle(radius); -} - - -/** - * Create a new Coordinate instance based on x and y grid data. - * @class Coordinate is a class that can encapsulate location information. - * @param {int} x The optional x portion of the Coordinate - * @param {int} y The optinal y portion of the Coordinate - */ -function Coordinate(x, y){ - if (x){ - this.x = x; - if (y){ - this.y = y; - } - } -} - -/** - * The x portion of the Coordinate - * @type int - * @see #getX - * @see #setX - */ -Coordinate.prototype.x = 0; - -/** - * The y portion of the Coordinate - * @type int - * @see #getY - * @see #setY - */ -Coordinate.prototype.y = 0; - -Coordinate.prototype.getX = Coordinate_GetX; -Coordinate.prototype.getY = Coordinate_GetY; -Coordinate.prototype.setX = Coordinate_SetX; -Coordinate.prototype.setY = Coordinate_SetY; - -/** - * Gets the x portion of the Coordinate. - * @type int - * @see #setX - */ -function Coordinate_GetX(){ - return this.x; -} - -/** - * Get the y portion of the Coordinate. - * @type int - * @see #setY - */ -function Coordinate_GetY(){ - return this.y; -} - -/** - * Sets the x portion of the Coordinate. - * @param {int} x The x value to set - * @see #getX - */ -function Coordinate_SetX(x){ - this.x = x; -} - -/** - * Sets the y portion of the Coordinate. - * @param {int} y The y value to set - * @see #getY - */ -function Coordinate_SetY(y){ - this.y = y; -} - -/** - * @class This class exists to demonstrate the assignment of a class prototype - * as an anonymous block. - */ -function ShapeFactory(){ -} - -ShapeFactory.prototype = { - /** - * Creates a new {@link Shape} instance. - * @return A new {@link Shape} - * @type Shape - */ - createShape: function(){ - return new Shape(); - } -} - -/** - * An example of a singleton class - */ -MySingletonShapeFactory = new function(){ - - /** - * Get the next {@link Shape} - * @type Shape - * @return A new {@link Shape} - */ - this.getShape = function(){ - return null; - } - -} - - -/** - * Create a new Foo instance. - * @class This is the Foo class. It exists to demonstrate 'nested' classes. - * @constructor - * @see Foo.Bar - */ -function Foo(){} - -/** - * Creates a new instance of Bar. - * @class This class exists to demonstrate 'nested' classes. - * @constructor - * @see Foo.Bar - */ -function Bar(){} - -/** - * Nested class - * @constructor - */ -Foo.Bar = function(){this.x = 2;} - -Foo.Bar.prototype = new Bar(); - -Foo.Bar.prototype.y = '3'; - diff --git a/modules/jala/util/HopKit/build.bat b/modules/jala/util/HopKit/build.bat deleted file mode 100755 index 886c2ba2..00000000 --- a/modules/jala/util/HopKit/build.bat +++ /dev/null @@ -1,69 +0,0 @@ -:: -:: Jala Project [http://opensvn.csie.org/traccgi/jala] -:: -:: Copyright 2004 ORF Online und Teletext GmbH -:: -:: Licensed under the Apache License, Version 2.0 (the ``License''); -:: you may not use this file except in compliance with the License. -:: You may obtain a copy of the License at -:: -:: http://www.apache.org/licenses/LICENSE-2.0 -:: -:: Unless required by applicable law or agreed to in writing, software -:: distributed under the License is distributed on an ``AS IS'' BASIS, -:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -:: See the License for the specific language governing permissions and -:: limitations under the License. -:: -:: $Revision$ -:: $LastChangedBy$ -:: $LastChangedDate$ -:: $HeadURL$ -:: - - -@echo off - -rem This is build.bat for Ant 1.7 - -rem Define the path to the ANT binary directory -rem (traling slash is mandatory!) -rem set ANT_HOME=%PROGRAMFILES%\Apache Group\apache-ant-1.7.0\bin\ - -rem Set this to the directory of your Helma installation if necessary -set HELMA_HOME="" - -rem ========================================================================== -rem No need to edit anything past here - -rem store path of this script as BUILD_HOME -set BUILD_HOME=%~dp0 - -rem Set this to the directory of your Helma installation -if "%HELMA_HOME%"=="""" set HELMA_HOME="%BUILD_HOME%/../../../.." - -rem Slurp the command line arguments. This loop allows for an unlimited number -rem of arguments (up to the command line limit, anyway). -set ANT_CMD_LINE_ARGS=%1 -if ""%1""=="""" goto runAnt -shift -:setupArgs -if ""%1""=="""" goto runAnt -if ""%1""==""-noclasspath"" goto runAnt -set ANT_CMD_LINE_ARGS=%ANT_CMD_LINE_ARGS% %1 -shift -goto setupArgs - -:runAnt - -rem ---- if there is no build.xml in the working directory, use the library -rem ---- in this directory -if not exist ".\build.xml" ( - set ANT_CMD_LINE_ARGS=-file "%BUILD_HOME%lib.xml" %ANT_CMD_LINE_ARGS% -) - -echo BUILD_HOME: %BUILD_HOME% - -ant -Dant.home=. -Dbasedir=. -lib "%BUILD_HOME%\lib;%HELMA_HOME%\lib" -propertyfile "%CD%\build.properties" %ANT_CMD_LINE_ARGS% - -:end diff --git a/modules/jala/util/HopKit/build.gradle b/modules/jala/util/HopKit/build.gradle deleted file mode 100644 index f8c9778e..00000000 --- a/modules/jala/util/HopKit/build.gradle +++ /dev/null @@ -1,16 +0,0 @@ -dependencies { - // FIXME: Seems to be not used, anymore…? - runtimeOnly 'bsf:bsf:2.4.0' -} - -jar.enabled = false -compileJava.enabled = false -compileTestJava.enabled = false -processResources.enabled = false -processTestResources.enabled = false -test.enabled = false - -tasks.register('deps', Copy) { - from sourceSets.main.runtimeClasspath - into 'lib' -} diff --git a/modules/jala/util/HopKit/build.sh b/modules/jala/util/HopKit/build.sh deleted file mode 100755 index 691439c6..00000000 --- a/modules/jala/util/HopKit/build.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/sh - -## -## Jala Project [http://opensvn.csie.org/traccgi/jala] -## -## Copyright 2004 ORF Online und Teletext GmbH -## -## Licensed under the Apache License, Version 2.0 (the ``License''); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an ``AS IS'' BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## $Revision: 3 $ -## $LastChangedBy: tobi $ -## $LastChangedDate: 2007-01-19 14:33:08 +0100 (Fri, 19 Jan 2007) $ -## $HeadURL: https://robert@opensvn.csie.org/jala/trunk/util/HopKit/build.bat $ -## - -# Uncomment and set this to the directory of your Helma installation -# if you installed jala in a different subdirectory than "modules/jala" -# HELMA_HOME="path/to/helma/installation" - -#-------------------------------------------- -# No need to change anything below -# buildfile for ant 1.7.0 -#-------------------------------------------- -if test -z "${ANT_HOME}" ; then - echo "ERROR: ANT_HOME not found in your environment." - echo "Please, set the ANT_HOME variable in your environment to match the" - echo "location of the Apache Ant installation you want to use." - exit -fi - -#---- store path of this script as BUILD_HOME -BUILD_HOME=$(dirname $0) -if [ "${BUILD_HOME:0:1}" != "/" ] ; then - # convert to absolute path - BUILD_HOME=${PWD}/${BUILD_HOME} -fi -export BUILD_HOME - -#---- store HELMA_HOME if not defined above -if [ -z "$HELMA_HOME" ] ; then - HELMA_HOME=$BUILD_HOME/../../../.. -fi - -#---- Slurp the command line arguments. -while [ $# -ne 0 ] -do - ANT_CMD_LINE_ARGS="${ANT_CMD_LINE_ARGS} $1" - shift -done - -#---- if there is no build.xml in the working directory, use the lib.xml -#---- in this directory -if test ! -f ${PWD}/build.xml ; then - BUILD_XML="${BUILD_HOME}/lib.xml" -else - BUILD_XML="${PWD}/build.xml" -fi - -${ANT_HOME}/bin/ant -Dant.home="${BUILD_HOME}" -Dbasedir="${PWD}" -lib "${BUILD_HOME}/lib:${HELMA_HOME}/lib" -propertyfile "${PWD}/build.properties" -file $BUILD_XML ${ANT_CMD_LINE_ARGS} - -exit diff --git a/modules/jala/util/HopKit/js.bat b/modules/jala/util/HopKit/js.bat deleted file mode 100755 index b9c5fa64..00000000 --- a/modules/jala/util/HopKit/js.bat +++ /dev/null @@ -1,107 +0,0 @@ -:: -:: Jala Project [http://opensvn.csie.org/traccgi/jala] -:: -:: Copyright 2004 ORF Online und Teletext GmbH -:: -:: Licensed under the Apache License, Version 2.0 (the ``License''); -:: you may not use this file except in compliance with the License. -:: You may obtain a copy of the License at -:: -:: http://www.apache.org/licenses/LICENSE-2.0 -:: -:: Unless required by applicable law or agreed to in writing, software -:: distributed under the License is distributed on an ``AS IS'' BASIS, -:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -:: See the License for the specific language governing permissions and -:: limitations under the License. -:: -:: $Revision$ -:: $LastChangedBy$ -:: $LastChangedDate$ -:: $HeadURL$ -:: - - -@echo off - -set HOPKIT=%~dp0 - -set JAVA=java -set JSJAR="%HOPKIT%\lib\js.jar" -set JSTOOLS=org.mozilla.javascript.tools - -goto %1 - - -rem -- S H E L L -- -:shell - -if "%2"=="" ( - %JAVA% -cp "%JSJAR%" "%JSTOOLS%.shell.Main" -) else ( - %JAVA% -cp "%JSJAR%" "%JSTOOLS%.shell.Main" "%2" -) - -goto end - - -rem -- T E S T -- -:test - - -rem -- C O M P I L E -- -:compile - -%JAVA% -cp "%JSJAR%" "%JSTOOLS%.jsc.Main" -nosource "%2" - -goto end - - -rem -- L I N T -- -:lint - -%JAVA% -cp "%JSJAR%" "%JSTOOLS%.shell.Main jslint.js" "%2" - -goto end - - -rem -- D O C S -- -:docs - -if "%3"=="" ( - set DOCDIR=docs -) else ( - set DOCDIR=%3 -) - -"%HOPKIT%\JSDoc\jsdoc.pl" -q -r -d "%DOCDIR%" --template-dir "%HOPKIT%/JSDoc/templates" --package-naming --globals-name Global --project-name "%2" --project-summary "./.jsdoc/summary.html" . - -goto end - - -rem -- M I N I F Y -- -:minify - -"%HOPKIT%\jsmin" "%2" - - -rem -- P A C K -- -:pack - - -rem -- H E L P -- -:help - -echo Currently the following build targets are supported: -echo docs - Create JSDoc API documentation. -echo help - Output this information. -echo compile - Compile a JavaScript file as Java class. -echo lint - Apply JavaScript Lint to a file. -echo minify - Minify JavaScript source files. -rem echo pack - Pack and obsfucate JavaScript source files. -echo shell - Start Rhino's interactive JavaScript shell. -echo test - Apply unit tests to JavaScript code. - - -rem -- E N D -- -:end diff --git a/modules/jala/util/HopKit/lib.xml b/modules/jala/util/HopKit/lib.xml deleted file mode 100644 index 99a166af..00000000 --- a/modules/jala/util/HopKit/lib.xml +++ /dev/null @@ -1,433 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - validate failed: error(s) in javascript code. - - - - diff --git a/modules/jala/util/HopKit/lib/bsf-2.4.0.jar b/modules/jala/util/HopKit/lib/bsf-2.4.0.jar deleted file mode 100644 index 2288c36e..00000000 Binary files a/modules/jala/util/HopKit/lib/bsf-2.4.0.jar and /dev/null differ diff --git a/modules/jala/util/HopKit/scripts/MessageParser.js b/modules/jala/util/HopKit/scripts/MessageParser.js deleted file mode 100644 index 06e1a34c..00000000 --- a/modules/jala/util/HopKit/scripts/MessageParser.js +++ /dev/null @@ -1,478 +0,0 @@ -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH. -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview - * MessageParser script that extracts all gettext message macros - * out of skin files and all calls of gettext functions - * (that is "gettext", "ngettext" and "_") out of function - * files and directly generates a .pot file from it. - * If an argument "-o" is given and it is followed by - * a path to a file, the output is written to this file. - * Any other argument is interpreted as directory or file - * that should be parsed. - */ - - -/** - * @constructor - */ -var Message = function(id, pluralId) { - this.id = id && String(id); - this.pluralId = pluralId && String(pluralId); - this.locations = []; - return this; -}; - -/** - * Static method that constructs a message key by - * which a message can be identified in the messages map. - * @param {String} id The message Id - * @param {String} pluralId The plural message Id - * @returns The generated message key - * @type String - */ -Message.getKey = function(id, pluralId) { - if (id && pluralId) { - return id + pluralId; - } else { - return id; - } -}; - -/** - * Encloses the string passed as argument in quotes - * and wraps the string if it is longer than 80 characters. - * @param {String} str The string to format - * @param {Boolean} wrap If true the message string will be splitted in - * parts where each one is max. 80 characters long - * @returns The formatted string. - * @type String - */ -Message.formatId = function(str, wrap) { - var escapeQuotes = function(s) { - return s.replace(/(^|[^\\])"/g, '$1\\"'); - }; - - var len = 80; - var buf = new java.lang.StringBuffer(); - if (wrap == true && str.length > len) { - buf.append('""\n'); - var offset = 0; - while (offset < str.length) { - buf.append('"'); - buf.append(escapeQuotes(str.substring(offset, offset += len))); - buf.append('"'); - buf.append("\n"); - } - return buf.toString(); - } else { - buf.append('"'); - buf.append(escapeQuotes(str)); - buf.append('"\n'); - } - return buf.toString(); -}; - -/** - * Adds a new location to this Message instance. - * @param {String} filePath The path to the file this message - * is located in. - * @param {Number} lineNum The line number at which this message - * was found at - */ -Message.prototype.addLocation = function(filePath, lineNum) { - const basePath = java.nio.file.Paths.get(java.io.File(app.dir).getCanonicalPath()); - const locationPath = java.nio.file.Paths.get(filePath); - const relativePath = basePath.relativize(locationPath); - this.locations.push(relativePath + ":" + lineNum); -}; - -/** - * Writes this Message instance as .po compatible string to - * the StringBuffer passed as argument. - * @param {java.lang.StringBuffer} buf The StringBuffer instance - * to write into - */ -Message.prototype.write = function(buf) { - for (var i=0;i -1 - || (this.pluralId != null && this.pluralId.indexOf("{") > -1)) { - buf.append("#, java-format\n"); - } - buf.append('msgid '); - buf.append(Message.formatId(this.id)); - if (this.pluralId != null) { - buf.append('msgid_plural '); - buf.append(Message.formatId(this.pluralId)); - buf.append('msgstr[0] ""\nmsgstr[1] ""\n') - } else { - buf.append('msgstr ""\n') - } - buf.append("\n"); - return; -}; - -/** - * @constructor - */ -var MessageParser = function() { - this.messages = {}; - return this; -}; - -/** - * Object containing the accepted function names, currently - * supported are "gettext", "ngettext" and "_". This is used - * as a lookup map during function file parsing. - * @type Object - */ -MessageParser.FUNCTION_NAMES = { - "_": true, - "gettext": true, - "ngettext": true, - "markgettext": true, - "cgettext": true -}; - -/** - * The name of the gettext macro - * @type String - */ -MessageParser.MACRO_NAME = "message"; - -/** - * The name of the macro attribute that will be interpreted - * as gettext attribute. - * @type String - */ -MessageParser.ATTRIBUTE_NAME = MessageParser.MACRO_NAME; - -/** - * A regular expression for parsing macros in a skin. The result - * of this regular expression contains: - * result[1] = macro handler name (can be empty for global macros) - * result[2] = macro name - * result[3] = the macro's attributes - * @type RegExp - */ -MessageParser.REGEX_MACRO = /<%\s*(?:([\w]+)\.)?([\w]+)\s+([^%]+?)\s*%>/gm; - -/** - * A regular expression for parsing the attributes of a macro. The result - * of this regular expression contains: - * result[1] = attribute name - * result[2] = attribute value - * @type RegExp - */ -MessageParser.REGEX_PARAM = /([\w]*)\s*=\s*["'](.*?)["']\s*(?=\w+=|$)/gm; - -/** - * Calculates the line number in the string passed as argument - * at which the specified index position is located. - * @param {String} str The source string - * @param {Number} idx The index position to get the line number for. - * @returns The line number of the index position in the source string. - * @type Number - */ -MessageParser.getLineNum = function(str, idx) { - return str.substring(0, idx).split(/.*(?:\r\n|\n\r|\r|\n)/).length; -}; - -/** - * Parses the file passed as argument. If the file - * is a directory, this method recurses down the directory - * tree and parses all skin and function files. - * @param {java.io.File} file The file or directory to start at. - * @param {String} encoding The encoding to use - */ -MessageParser.prototype.parse = function(file, encoding) { - if (file.isDirectory()) { - var list = file.list(); - for (var i=0;i -1) { - switch (String(fName.substring(dotIdx+1))) { - case "skin": - print("Parsing skin file " + file.getCanonicalPath() + "..."); - this.parseSkinFile(file, encoding); - break; - case "hac": - case "js": - print("Parsing function file " + file.getCanonicalPath() + "..."); - this.parseFunctionFile(file, encoding); - break; - default: - break; - } - } - } - return; -}; - -/** @ignore */ -MessageParser.prototype.toString = function() { - return "[Jala Message Parser]"; -}; - -/** - * Parses a .js file and creates Message instances for all - * calls of "gettext", "ngettext", "markgettext" and "_". - * @param {java.io.File} file The function file to parse - * @param {String} encoding The encoding to use - */ -MessageParser.prototype.parseFunctionFile = function(file, encoding) { - var fis = new java.io.FileInputStream(file); - var isr = new java.io.InputStreamReader(fis, encoding || "UTF-8"); - var reader = new java.io.BufferedReader(isr); - var tokenizer = new java.io.StreamTokenizer(reader); - var messages = [], stack = []; - var c; - while ((c = tokenizer.nextToken()) != java.io.StreamTokenizer.TT_EOF) { - switch (c) { - case java.io.StreamTokenizer.TT_WORD: - if (MessageParser.FUNCTION_NAMES[tokenizer.sval] == true) { - stack.push({name: tokenizer.sval, lineNr: tokenizer.lineno()}); - } else if (stack.length > 0) { - // it's something else than a string argument inside a gettext method call - // so finalize the argument parsing here as we aren't interested in that - messages.push(stack.pop()); - } - break; - case java.io.StreamTokenizer.TT_NUMBER: - break; - default: - if (stack.length > 0) { - if ("\u0028".charCodeAt(0) == c) { - // start of arguments (an opening bracket) - stack[stack.length-1].args = []; - } else if ("\u0029".charCodeAt(0) == c) { - // end of arguments (a closing bracket) - messages.push(stack.pop()); - } else if ("\u0022".charCodeAt(0) == c || "\u0027".charCodeAt(0) == c) { - // a quoted string argument - stack[stack.length-1].args.push(tokenizer.sval); - } - } - break; - } - } - if (messages.length > 0) { - var msgParam, key, msg; - for (var i=0;i 0) { - if (msgParam.name === "cgettext" || msgParam.name === "markgettext") { - msgParam.args[0] = cgettext.getKey(msgParam.args[0], msgParam.args[1]); - delete msgParam.args[1]; - } - key = Message.getKey(msgParam.args[0]); - if (!(msg = this.messages[key])) { - this.messages[key] = msg = new Message(msgParam.args[0], msgParam.args[1]); - } - if (!msg.pluralId && msgParam.args.length > 1) { - msg.pluralId = msgParam.args[1]; - } - msg.addLocation(file.getCanonicalPath(), msgParam.lineNr); - } - } - } - fis.close(); - isr.close(); - reader.close(); - return; -}; - -/** - * Parses a skin file and creates Message instances for - * all macros which name is either "message" or - * that have attributes named "message" and optional - * "plural" - * @param {java.io.File} file The skin file to parse - * @param {String} encoding The encoding to use - */ -MessageParser.prototype.parseSkinFile = function(file, encoding) { - var self = this; - var source = readFile(file.getAbsolutePath(), encoding || "UTF-8"); - - var checkNestedMacros = function(iterator) { - var macros = []; - while (iterator.hasNext()) { - macro = iterator.next(); - if (macro && macro.constructor !== String) { - macros.push(macro); - } - } - processMacros(macros); - } - - var processMacros = function(macros) { - var re = gettext_macro.REGEX; - var id, pluralId, name, args, param, key, msg; - for (let macro of macros) { - id = pluralId = null; - name = macro.getName(); - param = macro.getNamedParams(); - if (param) { - checkNestedMacros(param.values().iterator()); - if (name === MessageParser.MACRO_NAME) { - id = param.get("text"); - pluralId = param.get("plural"); - } else if (param.containsKey("message") === MessageParser.ATTRIBUTE_NAME) { - id = param.get("message"); - pluralId = param.get("plural"); - } - } - args = macro.getPositionalParams(); - if (args) { - checkNestedMacros(args.iterator()); - if (name === "gettext" || name === "markgettext") { - id = cgettext.getKey(args.get(0), param && param.get("context")); - } else if (name === "ngettext") { - id = args.get(0); - pluralId = args.get(1); - } - } - if (id != null) { - if (id.constructor !== String) { - continue; - } - // create new Message instance or update the existing one - id = id.replace(re, String.SPACE); - pluralId && (pluralId = pluralId.replace(re, String.SPACE)); - key = Message.getKey(id); - if (!(msg = self.messages[key])) { - self.messages[key] = msg = new Message(id, pluralId, file.getCanonicalPath()); - } - msg.addLocation(file.getCanonicalPath(), MessageParser.getLineNum(source, macro.start)); - } - } - } - - var skin = createSkin(source); - if (skin.hasMainskin()) { - processMacros(skin.getMacros()); - } - for (let name of skin.getSubskinNames()) { - var subskin = skin.getSubskin(name); - processMacros(subskin.getMacros()); - } - return; -} - -/** - * Prints a standard Header of a .po file - * FIXME: Allow custom header (template?) - * FIXME: why the hell is Plural-Forms ignored in poEdit? - * @see http://drupal.org/node/17564 - */ -MessageParser.prototype.getPotString = function() { - var date = new Date; - var buf = new java.lang.StringBuffer(); - buf.append('#\n'); - buf.append('# The Antville Project\n'); - buf.append('# http://code.google.com/p/antville\n'); - buf.append('#\n'); - buf.append('# Copyright 2001-' + date.getFullYear() + ' by the Workers of Antville.\n'); - buf.append('#\n'); - buf.append("# Licensed under the Apache License, Version 2.0 (the ``License''\n"); - buf.append('# you may not use this file except in compliance with the License.\n'); - buf.append('# You may obtain a copy of the License at\n'); - buf.append('#\n'); - buf.append('# http://www.apache.org/licenses/LICENSE-2.0\n'); - buf.append('#\n'); - buf.append('# Unless required by applicable law or agreed to in writing, software\n'); - buf.append("# distributed under the License is distributed on an ``AS IS'' BASIS,\n"); - buf.append('# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'); - buf.append('# See the License for the specific language governing permissions and\n'); - buf.append('# limitations under the License.\n'); - buf.append('#\n\n'); - buf.append('#, fuzzy\n'); - buf.append('msgid ""\n'); - buf.append('msgstr ""\n'); - buf.append('"Project-Id-Version: Antville-' + Root.VERSION + '\\n"\n'); - buf.append('"Report-Msgid-Bugs-To: mail@antville.org\\n"\n'); - var sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mmZ"); - buf.append('"POT-Creation-Date: ' + sdf.format(new java.util.Date()) + '\\n"\n'); - buf.append('"PO-Revision-Date: ' + sdf.format(new java.util.Date()) + '\\n"\n'); - //buf.append('"Last-Translator: FULL NAME \\n"\n'); - buf.append('"Language-Team: The Antville People \\n"\n'); - buf.append('"MIME-Version: 1.0\\n"\n'); - buf.append('"Content-Type: text/plain; charset=utf-8\\n"\n'); - buf.append('"Content-Transfer-Encoding: 8bit\\n"\n'); - buf.append('"Plural-Forms: nplurals=2; plural=(n != 1);\\n"\n'); - buf.append('\n'); - - // sort all messages by their singular key - var keys = []; - for (var i in this.messages) { - keys[keys.length] = this.messages[i].id; - } - keys.sort(); - // add all the messages - for (var i=0;ijava -cp rhino.jar org.mozilla.javascript.tools.shell.Main PoParser.js [namespace] - * - * The accepted arguments are: - *
        - *
      • input: Either a single .po file or a directory containing multiple files
      • - *
      • output: The directory where to put the generated message files
      • - *
      • namespace: An optional namespace in which the generated message object will reside - * (eg. if the namespace is called "jala", the messages will be stored in global.jala.messages)
      • - *
      - */ - - -/** - * Constructs a new PoParser instance. - * @class Instances of this class can generate JavaScript message files out - * of GNU Gettext .po files for use with jala.I18n (and possibly other internationalization - * environments too). - * @param {String} handler An optional namespace where the parsed messages should be stored - * @returns A newly created instance of PoParser - * @constructor - */ -var PoParser = function(namespace) { - /** - * An array containing the parsed messages - * @type Array - */ - this.messages = []; - - /** - * The locale key string (eg. "de_AT") of the .po file - * @type String - */ - this.localeKey = null; - - /** - * The namespace (optional) where to store the generated messages - * @type String - */ - this.namespace = namespace; - return this; -}; - -/** - * A regular expression for splitting the contents of a .po file into - * single lines - * @type RegExp - */ -PoParser.REGEX_LINES = /\r\n|\r|\n|\u0085|\u2028|\u2029/; - -/** - * A regular expression for parsing singular message keys - * @type RegExp - */ -PoParser.REGEX_MSGID = /^\s*msgid(?!_plural)\s+\"(.*)\"\s*$/; - -/** - * A regular expression for parsing plural message keys - * @type RegExp - */ -PoParser.REGEX_MSGID_PLURAL = /^\s*msgid_plural\s+\"(.*)\"\s*$/; - -/** - * A regular expression for parsing message key continuations - * @type RegExp - */ -PoParser.REGEX_MSG_CONT = /^\s*\"(.*)\"\s*$/; - -/** - * A regular expression for parsing a message translation - * @type RegExp - */ -PoParser.REGEX_MSGSTR = /^\s*msgstr(?:\[(\d)\])?\s+\"(.*)\"\s*$/; - -/** - * A regular expression used to detect lines other than whitespace - * and comments - * @type RegExp - */ -PoParser.REGEX_DATA = /^\s*msg/; - -PoParser.isData = function(str) { - return PoParser.REGEX_DATA.test(str); -}; - -/** - * Reads the file passed as argument, assuming that it is UTF-8 encoded - * @param {java.io.File} file The file to read - * @returns The contents of the file - * @type java.lang.String - */ -PoParser.readFile = function(file) { - var inStream = new java.io.InputStreamReader(new java.io.FileInputStream(file), "UTF-8"); - var buffer = new java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 2048); - var read = 0; - var r = 0; - while ((r = inStream.read(buffer, read, buffer.length - read)) > -1) { - read += r; - if (read == buffer.length) { - // grow input buffer - var newBuffer = new java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, buffer.length * 2); - java.lang.System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); - buffer = newBuffer; - } - } - inStream.close(); - return new java.lang.String(buffer, 0, read); -} - -/** - * Parses the PO file passed as argument into the messages array - * of this PoParser instance. - * @param {java.io.File} file The .po file to parse - */ -PoParser.prototype.parse = function(file) { - // parse the locale key out of the file name - var fileName = file.getName(); - if (!(this.localeKey = fileName.substring(0, fileName.indexOf(".")))) { - throw "Invalid PO file name: " + fileName; - } - - // read the PO file content and parse it into messages - var content = PoParser.readFile(file); - var start = new Date(); - var lines = content.split(PoParser.REGEX_LINES); - var idx = -1; - var line = null; - var m, value, nr; - var msg; - - var hasMoreLines = function() { - return idx < lines.length - 1; - }; - - var nextLine = function() { - return (line = lines[idx += 1]) != null; - }; - - var getContinuation = function(str) { - var nLine; - while ((nLine = lines[idx + 1]) != null) { - if ((m = nLine.match(PoParser.REGEX_MSG_CONT)) != null) { - str += m[1]; - nextLine(); - } else { - break; - } - } - return str; - } - - while (nextLine()) { - if ((m = line.match(PoParser.REGEX_MSGID)) != null) { - value = getContinuation(m[1]); - if (value) { - msg = this.messages[this.messages.length] = new Message(value); - } - } else if ((m = line.match(PoParser.REGEX_MSGID_PLURAL)) != null) { - value = getContinuation(m[1]); - if (value && msg != null) { - msg.pluralKey = value; - } - } else if ((m = line.match(PoParser.REGEX_MSGSTR)) != null) { - nr = m[1]; - value = getContinuation(m[2]); - if (value && msg != null) { - nr = parseInt(nr, 10); - msg.translations[nr || 0] = value; - } - } - } - return; -}; - -/** - * Converts the array containing the parsed messages into a message - * catalog script file and saves it on disk. - * @param {java.io.File} outputDir The directory where the message - * file should be saved - */ -PoParser.prototype.writeToFile = function(output) { - var buf = new java.lang.StringBuffer(); - // write header - buf.append('/**\n'); - buf.append(' * Instantiate the messages namespace if it\'s not already existing\n'); - buf.append(' */\n'); - var objPath = ""; - if (this.namespace) { - objPath += this.namespace; - buf.append('if (!global.' + objPath + ') {\n'); - buf.append(' global.' + objPath + ' = {};\n'); - buf.append('}\n'); - objPath += "."; - } - objPath += "messages"; - buf.append('if (!global.' + objPath + ') {\n'); - buf.append(' global.' + objPath + ' = {};\n'); - buf.append('}\n\n'); - - buf.append('/**\n'); - buf.append(' * Messages for locale "' + this.localeKey + '"\n'); - buf.append(' */\n'); - var fname = objPath + "." + this.localeKey + ".js"; - objPath += "['" + this.localeKey + "']"; - buf.append('global.' + objPath + ' = {\n'); - // write messages - for (var i=0;i [namespace]"); - print(": Either a single .po file or a directory containing .po files"); - print(": The directory where the generated messages files should be stored"); - print("[namespace]: An optional global namespace where the messages should be"); - print(" stored (eg. a namespace like 'jala' will lead to messages"); - print(" stored in global.jala.messages by their locale."); - quit(); -} - -var input = new java.io.File(arguments[0]); -var output = new java.io.File(arguments[1]); -var namespace = arguments[2]; - -// check if the output destination is a directory -if (output.isFile()) { - print("Invalid arguments: the output destination must be a directory."); - quit(); -} - -if (namespace && namespace.indexOf(".") != -1) { - print("Invalid arguments: Please don't specify complex object paths, as this"); - print("would corrupt the messages file."); - quit(); -} - -// parse the PO file(s) and create the message catalog files -var parser; -if (input.isDirectory()) { - var files = input.listFiles(); - var file; - for (var i=0;i. - - var myReport = JSLINT.report(option); - - If the option is true, then the report will be limited to only errors. -*/ - -String.prototype.entityify = function () { - return this. - replace(/&/g, '&'). - replace(//g, '>'); -}; - -String.prototype.isAlpha = function () { - return (this >= 'a' && this <= 'z\uffff') || - (this >= 'A' && this <= 'Z\uffff'); -}; - - -String.prototype.isDigit = function () { - return (this >= '0' && this <= '9'); -}; - - -// We build the application inside a function so that we produce only a single -// global variable. The function will be invoked, its return value is the JSLINT -// function itself. - -var JSLINT; -JSLINT = function () { - - var anonname, - -// browser contains a set of global names which are commonly provided by a -// web browser environment. - - browser = { - alert: true, - blur: true, - clearInterval: true, - clearTimeout: true, - close: true, - closed: true, - confirm: true, - defaultStatus: true, - document: true, - event: true, - focus: true, - frames: true, - history: true, - Image: true, - length: true, - location: true, - moveBy: true, - moveTo: true, - name: true, - navigator: true, - onblur: true, - onerror: true, - onfocus: true, - onload: true, - onresize: true, - onunload: true, - open: true, - opener: true, - parent: true, - print: true, - prompt: true, - resizeBy: true, - resizeTo: true, - screen: true, - scroll: true, - scrollBy: true, - scrollTo: true, - self: true, - setInterval: true, - setTimeout: true, - status: true, - top: true, - window: true, - XMLHttpRequest: true - }, - funlab, funstack, functions, globals, - -// konfab contains the global names which are provided to a Konfabulator widget. - - konfab = { - alert: true, - animator: true, - appleScript: true, - beep: true, - bytesToUIString: true, - chooseColor: true, - chooseFile: true, - chooseFolder: true, - convertPathToHFS: true, - convertPathToPlatform: true, - closeWidget: true, - CustomAnimation: true, - escape: true, - FadeAnimation: true, - focusWidget: true, - form: true, - include: true, - isApplicationRunning: true, - iTunes: true, - konfabulatorVersion: true, - log: true, - MoveAnimation: true, - openURL: true, - play: true, - popupMenu: true, - print: true, - prompt: true, - reloadWidget: true, - resolvePath: true, - resumeUpdates: true, - RotateAnimation: true, - runCommand: true, - runCommandInBg: true, - saveAs: true, - savePreferences: true, - showWidgetPreferences: true, - sleep: true, - speak: true, - suppressUpdates: true, - tellWidget: true, - unescape: true, - updateNow: true, - yahooCheckLogin: true, - yahooLogin: true, - yahooLogout: true, - COM: true, - filesystem: true, - preferenceGroups: true, - preferences: true, - screen: true, - system: true, - URL: true, - XMLDOM: true, - XMLHttpRequest: true - }, - lines, lookahead, member, noreach, option, prevtoken, stack, - -// standard contains the global names that are provided by standard JavaScript. - - standard = { - Array: true, - Boolean: true, - Date: true, - decodeURI: true, - decodeURIComponent: true, - encodeURI: true, - encodeURIComponent: true, - Error: true, - escape: true, - 'eval': true, - EvalError: true, - Function: true, - isFinite: true, - isNaN: true, - Math: true, - Number: true, - Object: true, - parseInt: true, - parseFloat: true, - RangeError: true, - ReferenceError: true, - RegExp: true, - String: true, - SyntaxError: true, - TypeError: true, - unescape: true, - URIError: true - }, - syntax = {}, token, verb, -/* - xmode is used to adapt to the exceptions in XML parsing. It can have these - states: - false .js script file - " A " attribute - ' A ' attribute - content The content of a script tag - CDATA A CDATA block -*/ - xmode, -/* - xtype identifies the type of document being analyzed. It can have these - states: - false .js script file - html .html file - widget .kon Konfabulator file -*/ - xtype, -// token - tx = /^([(){}[.,:;'"~]|\](\]>)?|\?>?|==?=?|\/(\*(global|extern)*|=|)|\*[\/=]?|\+[+=]?|-[-=]?|%[=>]?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=%\?]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+-]?[0-9]+)?)/, -// string ending in single quote - sx = /^((\\[^\x00-\x1f]|[^\x00-\x1f'\\])*)'/, - sxx = /^(([^\x00-\x1f'])*)'/, -// string ending in double quote - qx = /^((\\[^\x00-\x1f]|[^\x00-\x1f"\\])*)"/, - qxx = /^(([^\x00-\x1f"])*)"/, -// regular expression - rx = /^(\\[^\x00-\x1f]|\[(\\[^\x00-\x1f]|[^\x00-\x1f\\\/])*\]|[^\x00-\x1f\\\/\[])+\/[gim]*/, -// star slash - lx = /\*\/|\/\*/, -// global identifier - gx = /^([a-zA-Z_$][a-zA-Z0-9_$]*)/, -// identifier - ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*$)/, -// global separators - hx = /^[\x00-\x20,]*(\*\/)?/, -// whitespace - wx = /^\s*(\/\/.*\r*$)?/; - -// Make a new object that inherits from an existing object. - - function object(o) { - function F() {} - F.prototype = o; - return new F(); - } - -// Produce an error warning. - - function warning(m, x, y) { - var l, c, t = typeof x === 'object' ? x : token; - if (typeof x === 'number') { - l = x; - c = y || 0; - } else { - if (t.id === '(end)') { - t = prevtoken; - } - l = t.line || 0; - c = t.from || 0; - } - JSLINT.errors.push({ - id: '(error)', - reason: m, - evidence: lines[l] || '', - line: l, - character: c - }); - if (option.passfail) { - JSLINT.errors.push(null); - throw null; - } - } - - function error(m, x, y) { - warning(m, x, y); - JSLINT.errors.push(null); - throw null; - } - - -// lexical analysis - - var lex = function () { - var character, from, line, s; - -// Private lex methods - - function nextLine() { - line += 1; - if (line >= lines.length) { - return false; - } - character = 0; - s = lines[line]; - return true; - } - -// Produce a token object. The token inherits from a syntax symbol. - - function it(type, value) { - var t; - if (type === '(punctuator)') { - t = syntax[value]; - } else if (type === '(identifier)') { - t = syntax[value]; - if (!t || typeof t != 'object') { - t = syntax[type]; - } - } else { - t = syntax[type]; - } - if (!t || typeof t != 'object') { - error("Unrecognized symbol: '" + value + "' " + type); - } - t = object(t); - if (value || type === '(string)') { - t.value = value; - } - t.line = line; - t.character = character; - t.from = from; - return t; - } - -// Public lex methods - - return { - init: function (source) { - if (typeof source === 'string') { - lines = source.split('\n'); - if (lines.length == 1) { - lines = lines[0].split('\r'); - } - } else { - lines = source; - } - line = 0; - character = 0; - from = 0; - s = lines[0]; - }, - -// token -- this is called by advance to get the next token. - - token: function () { - var c, i, l, r, t; - - function string(x) { - var a, j; - r = x.exec(s); - if (r) { - t = r[1]; - l = r[0].length; - s = s.substr(l); - character += l; - if (xmode == 'script') { - if (t.indexOf('<\/') >= 0) { - warning( - 'Expected "...<\\/..." and instead saw "...<\/...".', token); - } - } - return it('(string)', r[1]); - } else { - for (j = 0; j < s.length; j += 1) { - a = s.charAt(j); - if (a < ' ') { - if (a === '\n' || a === '\r') { - break; - } - error("Control character in string: " + - s.substring(0, j), line, character + j); - } - } - error("Unclosed string: " + s, line, character); - } - } - - for (;;) { - if (!s) { - return it(nextLine() ? '(endline)' : '(end)', ''); - } - r = wx.exec(s); - if (!r || !r[0]) { - break; - } - l = r[0].length; - s = s.substr(l); - character += l; - if (s) { - break; - } - } - from = character; - r = tx.exec(s); - if (r) { - t = r[0]; - l = t.length; - s = s.substr(l); - character += l; - c = t.substr(0, 1); - -// identifier - - if (c.isAlpha() || c === '_' || c === '$') { - return it('(identifier)', t); - } - -// number - - if (c.isDigit()) { - if (token.id === '.') { - warning( - "A decimal fraction should have a zero before the decimal point.", - token); - } - if (!isFinite(Number(t))) { - warning("Bad number: '" + t + "'.", - line, character); - } - if (s.substr(0, 1).isAlpha()) { - error("Space is required after a number: '" + - t + "'.", line, character); - } - if (c === '0' && t.substr(1,1).isDigit()) { - warning("Don't use extra leading zeros: '" + - t + "'.", line, character); - } - if (t.substr(t.length - 1) === '.') { - warning( - "A trailing decimal point can be confused with a dot: '" + t + "'.", - line, character); - } - return it('(number)', t); - } - -// string - - if (t === '"') { - return (xmode === '"' || xmode === 'string') ? - it('(punctuator)', t) : - string(xmode === 'xml' ? qxx : qx); - } - if (t === "'") { - return (xmode === "'" || xmode === 'string') ? - it('(punctuator)', t) : - string(xmode === 'xml' ? sxx : sx); - } - -// unbegun comment - - if (t === '/*') { - for (;;) { - i = s.search(lx); - if (i >= 0) { - break; - } - if (!nextLine()) { - error("Unclosed comment.", token); - } - } - character += i + 2; - if (s.substr(i, 1) === '/') { - error("Nested comment."); - } - s = s.substr(i + 2); - return this.token(); - } - -// /*extern - - if (t === '/*extern' || t === '/*global') { - for (;;) { - r = hx.exec(s); - if (r) { - l = r[0].length; - s = s.substr(l); - character += l; - if (r[1] === '*/') { - return this.token(); - } - } - if (s) { - r = gx.exec(s); - if (r) { - l = r[0].length; - s = s.substr(l); - character += l; - globals[r[1]] = true; - } else { - error("Bad extern identifier: '" + - s + "'.", line, character); - } - } else if (!nextLine()) { - error("Unclosed comment."); - } - } - } - -// punctuator - - return it('(punctuator)', t); - } - error("Unexpected token: " + (t || s.substr(0, 1)), - line, character); - }, - -// skip -- skip past the next occurrence of a particular string. -// If the argument is empty, skip to just before the next '<' character. -// This is used to ignore HTML content. Return false if it isn't found. - - skip: function (to) { - if (token.id) { - if (!to) { - to = ''; - if (token.id.substr(0, 1) === '<') { - lookahead.push(token); - return true; - } - } else if (token.id.indexOf(to) >= 0) { - return true; - } - } - prevtoken = token; - token = syntax['(error)']; - for (;;) { - var i = s.indexOf(to || '<'); - if (i >= 0) { - character += i + to.length; - s = s.substr(i + to.length); - return true; - } - if (!nextLine()) { - break; - } - } - return false; - }, - -// regex -- this is called by parse when it sees '/' being used as a prefix. - - regex: function () { - var l, r = rx.exec(s), x; - if (r) { - l = r[0].length; - character += l; - s = s.substr(l); - x = r[1]; - return it('(regex)', x); - } - error("Bad regular expression: " + s); - } - }; - }(); - - function builtin(name) { - return standard[name] === true || - globals[name] === true || - ((xtype === 'widget' || option.widget) && konfab[name] === true) || - ((xtype === 'html' || option.browser) && browser[name] === true); - } - - function addlabel(t, type) { - if (t) { - if (typeof funlab[t] === 'string') { - switch (funlab[t]) { - case 'var': - case 'var*': - if (type === 'global') { - funlab[t] = 'var*'; - return; - } - break; - case 'global': - if (type === 'var') { - warning('Var ' + t + - ' was used before it was declared.', prevtoken); - return; - } - if (type === 'var*' || type === 'global') { - return; - } - break; - case 'function': - case 'parameter': - if (type === 'global') { - return; - } - break; - } - warning("Identifier '" + t + "' already declared as " + - funlab[t], prevtoken); - } - funlab[t] = type; - } - } - - -// We need a peek function. If it has an argument, it peeks that much farther -// ahead. It is used to distinguish -// for ( var i in ... -// from -// for ( var i = ... - - function peek(i) { - var j = 0, t; - if (token == syntax['(error)']) { - return token; - } - if (typeof i === 'undefined') { - i = 0; - } - while (j <= i) { - t = lookahead[j]; - if (!t) { - t = lookahead[j] = lex.token(); - } - j += 1; - } - return t; - } - - - var badbreak = {')': true, ']': true, '++': true, '--': true}; - -// Produce the next token. It looks for programming errors. - - function advance(id, t) { - var l; - switch (prevtoken.id) { - case '(number)': - if (token.id === '.') { - warning( -"A dot following a number can be confused with a decimal point.", prevtoken); - } - break; - case '-': - if (token.id === '-' || token.id === '--') { - warning("Confusing minusses."); - } - break; - case '+': - if (token.id === '+' || token.id === '++') { - warning("Confusing plusses."); - } - break; - } - if (prevtoken.type === '(string)' || prevtoken.identifier) { - anonname = prevtoken.value; - } - - if (id && token.value != id) { - if (t) { - if (token.id === '(end)') { - warning("Unmatched '" + t.id + "'.", t); - } else { - warning("Expected '" + id + "' to match '" + - t.id + "' from line " + (t.line + 1) + - " and instead saw '" + token.value + "'."); - } - } else { - warning("Expected '" + id + "' and instead saw '" + - token.value + "'."); - } - } - prevtoken = token; - for (;;) { - token = lookahead.shift() || lex.token(); - if (token.id === ''); - } else { - error("Unexpected token '') { - if (xmode === 'CDATA') { - xmode = 'script'; - } else { - error("Unexpected token ']]>"); - } - } else if (token.id !== '(endline)') { - break; - } - if (xmode === '"' || xmode === "'") { - error("Missing '" + xmode + "'.", prevtoken); - } - l = !xmode && !option.laxLineEnd && - (prevtoken.type == '(string)' || prevtoken.type == '(number)' || - prevtoken.type == '(identifier)' || badbreak[prevtoken.id]); - } - if (l && token.id != '{' && token.id != '}' && token.id != ']') { - warning( - "Line breaking error: '" + - prevtoken.value + "'.", prevtoken); - } - if (xtype === 'widget' && xmode === 'script' && token.id) { - l = token.id.charAt(0); - if (l === '<' || l === '&') { - token.nud = token.led = null; - token.lbp = 0; - token.reach = true; - } - } - } - - - function advanceregex() { - token = lex.regex(); - } - - - function beginfunction(i) { - var f = {'(name)': i, '(line)': token.line + 1, '(context)': funlab}; - funstack.push(funlab); - funlab = f; - functions.push(funlab); - } - - - function endfunction() { - funlab = funstack.pop(); - } - - -// This is the heart of JSLINT, the Pratt parser. In addition to parsing, it -// is looking for ad hoc lint patterns. We add to Pratt's model .fud, which is -// like nud except that it is only used on the first token of a statement. -// Having .fud makes it much easier to define JavaScript. I retained Pratt's -// nomenclature, even though it isn't very descriptive. - -// .nud Null denotation -// .fud First null denotation -// .led Left denotation -// lbp Left binding power -// rbp Right binding power - -// They are key to the parsing method called Top Down Operator Precedence. - - function parse(rbp, initial) { - var l, left, o; - if (token.id && token.id === '/') { - if (prevtoken.id != '(' && prevtoken.id != '=' && - prevtoken.id != ':' && prevtoken.id != ',' && - prevtoken.id != '=') { - warning( -"Expected to see a '(' or '=' or ':' or ',' preceding a regular expression literal, and instead saw '" + - prevtoken.value + "'.", prevtoken); - } - advanceregex(); - } - if (token.id === '(end)') { - warning("Unexpected early end of program", prevtoken); - } - advance(); - if (initial) { - anonname = 'anonymous'; - verb = prevtoken.value; - } - if (initial && prevtoken.fud) { - prevtoken.fud(); - } else { - if (prevtoken.nud) { - o = prevtoken.exps; - left = prevtoken.nud(); - } else { - if (token.type === '(number)' && prevtoken.id === '.') { - warning( -"A leading decimal point can be confused with a dot: ." + token.value, - prevtoken); - } - error("Expected an identifier and instead saw '" + - prevtoken.id + "'.", prevtoken); - } - while (rbp < token.lbp) { - o = token.exps; - advance(); - if (prevtoken.led) { - left = prevtoken.led(left); - } else { - error("Expected an operator and instead saw '" + - prevtoken.id + "'."); - } - } - if (initial && !o) { - warning( -"Expected an assignment or function call and instead saw an expression.", - prevtoken); - } - } - if (l) { - funlab[l] = 'label'; - } - if (left && left.id === 'eval') { - warning("evalError", left); - } - return left; - } - - -// Parasitic constructors for making the symbols that will be inherited by -// tokens. - - function symbol(s, p) { - return syntax[s] || (syntax[s] = {id: s, lbp: p, value: s}); - } - - - function delim(s) { - return symbol(s, 0); - } - - - function stmt(s, f) { - var x = delim(s); - x.identifier = x.reserved = true; - x.fud = f; - return x; - } - - - function blockstmt(s, f) { - var x = stmt(s, f); - x.block = true; - return x; - } - - - function prefix(s, f) { - var x = symbol(s, 150); - x.nud = (typeof f === 'function') ? f : function () { - parse(150); - return this; - }; - return x; - } - - - function prefixname(s, f) { - var x = prefix(s, f); - x.identifier = x.reserved = true; - return x; - } - - - function type(s, f) { - var x = delim(s); - x.type = s; - x.nud = f; - return x; - } - - - function reserve(s, f) { - var x = type(s, f); - x.identifier = x.reserved = true; - return x; - } - - - function reservevar(s) { - return reserve(s, function () { - return this; - }); - } - - - function infix(s, f, p) { - var x = symbol(s, p); - x.led = (typeof f === 'function') ? f : function (left) { - return [f, left, parse(p)]; - }; - return x; - } - - - function assignop(s, f) { - symbol(s, 20).exps = true; - return infix(s, function (left) { - if (left) { - if (left.id === '.' || left.id === '[' || - (left.identifier && !left.reserved)) { - parse(19); - return left; - } - if (left == syntax['function']) { - if (option.jscript) { - parse(19); - return left; - } else { - warning( -"Expected an identifier in an assignment, and instead saw a function invocation.", - prevtoken); - } - } - } - error("Bad assignment.", this); - }, 20); - } - - - function suffix(s, f) { - var x = symbol(s, 150); - x.led = function (left) { - if (option.plusplus) { - warning(this.id + " is considered harmful.", this); - } - return [f, left]; - }; - return x; - } - - - function optionalidentifier() { - if (token.reserved) { - warning("Expected an identifier and instead saw '" + - token.id + "' (a reserved word)."); - } - if (token.identifier) { - advance(); - return prevtoken.value; - } - } - - - function identifier() { - var i = optionalidentifier(); - if (i) { - return i; - } - if (prevtoken.id === 'function' && token.id === '(') { - warning("Missing name in function statement."); - } else { - error("Expected an identifier and instead saw '" + - token.value + "'.", token); - } - } - - - function reachable(s) { - var i = 0, t; - if (token.id != ';' || noreach) { - return; - } - for (;;) { - t = peek(i); - if (t.reach) { - return; - } - if (t.id != '(endline)') { - if (t.id === 'function') { - warning( -"Inner functions should be listed at the top of the outer function.", t); - break; - } - warning("Unreachable '" + t.value + "' after '" + s + - "'.", t); - break; - } - i += 1; - } - } - - - function statement() { - var t = token; - while (t.id === ';') { - warning("Unnecessary semicolon", t); - advance(';'); - t = token; - if (t.id === '}') { - return; - } - } - if (t.identifier && !t.reserved && peek().id === ':') { - advance(); - advance(':'); - addlabel(t.value, 'live*'); - if (!token.labelled) { - warning("Label '" + t.value + - "' on unlabelable statement '" + token.value + "'.", - token); - } - if (t.value.toLowerCase() == 'javascript') { - warning("Label '" + t.value + - "' looks like a javascript url.", - token); - } - token.label = t.value; - t = token; - } - parse(0, true); - if (!t.block) { - if (token.id != ';') { - warning("Missing ';'", prevtoken.line, - prevtoken.from + prevtoken.value.length); - } else { - advance(';'); - } - } - } - - - function statements() { - while (!token.reach) { - statement(); - } - } - - - function block() { - var t = token; - if (token.id === '{') { - advance('{'); - statements(); - advance('}', t); - } else { - warning("Missing '{' before '" + token.value + "'."); - noreach = true; - statement(); - noreach = false; - } - verb = null; - } - - -// An identity function, used by string and number tokens. - - function idValue() { - return this; - } - - - function countMember(m) { - if (typeof member[m] === 'number') { - member[m] += 1; - } else { - member[m] = 1; - } - } - - -// Common HTML attributes that carry scripts. - - var scriptstring = { - onblur: true, - onchange: true, - onclick: true, - ondblclick: true, - onfocus: true, - onkeydown: true, - onkeypress: true, - onkeyup: true, - onload: true, - onmousedown: true, - onmousemove: true, - onmouseout: true, - onmouseover: true, - onmouseup: true, - onreset: true, - onselect: true, - onsubmit: true, - onunload: true - }; - - -// XML types. Currently we support html and widget. - - var xmltype = { - HTML: { - doBegin: function (n) { - if (!option.cap) { - warning("HTML case error."); - } - xmltype.html.doBegin(); - } - }, - html: { - doBegin: function (n) { - xtype = 'html'; - xmltype.html.script = false; - }, - doTagName: function (n, p) { - var i, t = xmltype.html.tag[n], x; - if (!t) { - error('Unrecognized tag: <' + n + '>. ' + - (n === n.toLowerCase() ? - 'Did you mean <' + n.toLowerCase() + '>?' : '')); - } - x = t.parent; - if (x) { - if (x.indexOf(' ' + p + ' ') < 0) { - error('A <' + n + '> must be within <' + x + '>', - prevtoken); - } - } else { - i = stack.length; - do { - if (i <= 0) { - error('A <' + n + '> must be within the body', - prevtoken); - } - i -= 1; - } while (stack[i].name !== 'body'); - } - xmltype.html.script = n === 'script'; - return t.simple; - }, - doAttribute: function (n, a) { - if (n === 'script') { - if (a === 'src') { - xmltype.html.script = false; - return 'string'; - } else if (a === 'language') { - warning("The 'language' attribute is deprecated", - prevtoken); - return false; - } - } - return scriptstring[a] && 'script'; - }, - doIt: function (n) { - return xmltype.html.script ? 'script' : - n !== 'html' && xmltype.html.tag[n].special && 'special'; - }, - tag: { - a: {}, - abbr: {}, - acronym: {}, - address: {}, - applet: {}, - area: {simple: true, parent: ' map '}, - b: {}, - base: {simple: true, parent: ' head '}, - bdo: {}, - big: {}, - blockquote: {}, - body: {parent: ' html noframes '}, - br: {simple: true}, - button: {}, - caption: {parent: ' table '}, - center: {}, - cite: {}, - code: {}, - col: {simple: true, parent: ' table colgroup '}, - colgroup: {parent: ' table '}, - dd: {parent: ' dl '}, - del: {}, - dfn: {}, - dir: {}, - div: {}, - dl: {}, - dt: {parent: ' dl '}, - em: {}, - embed: {}, - fieldset: {}, - font: {}, - form: {}, - frame: {simple: true, parent: ' frameset '}, - frameset: {parent: ' html frameset '}, - h1: {}, - h2: {}, - h3: {}, - h4: {}, - h5: {}, - h6: {}, - head: {parent: ' html '}, - html: {}, - hr: {simple: true}, - i: {}, - iframe: {}, - img: {simple: true}, - input: {simple: true}, - ins: {}, - kbd: {}, - label: {}, - legend: {parent: ' fieldset '}, - li: {parent: ' dir menu ol ul '}, - link: {simple: true, parent: ' head '}, - map: {}, - menu: {}, - meta: {simple: true, parent: ' head noscript '}, - noframes: {parent: ' html body '}, - noscript: {parent: ' html head body frameset '}, - object: {}, - ol: {}, - optgroup: {parent: ' select '}, - option: {parent: ' optgroup select '}, - p: {}, - param: {simple: true, parent: ' applet object '}, - pre: {}, - q: {}, - samp: {}, - script: {parent: -' head body p div span abbr acronym address bdo blockquote cite code del dfn em ins kbd pre samp strong th td var '}, - select: {}, - small: {}, - span: {}, - strong: {}, - style: {parent: ' head ', special: true}, - sub: {}, - sup: {}, - table: {}, - tbody: {parent: ' table '}, - td: {parent: ' tr '}, - textarea: {}, - tfoot: {parent: ' table '}, - th: {parent: ' tr '}, - thead: {parent: ' table '}, - title: {parent: ' head '}, - tr: {parent: ' table tbody thead tfoot '}, - tt: {}, - u: {}, - ul: {}, - 'var': {} - } - }, - widget: { - doBegin: function (n) { - xtype = 'widget'; - }, - doTagName: function (n, p) { - var t = xmltype.widget.tag[n]; - if (!t) { - error('Unrecognized tag: <' + n + '>. '); - } - var x = t.parent; - if (x.indexOf(' ' + p + ' ') < 0) { - error('A <' + n + '> must be within <' + x + '>', prevtoken); - } - }, - doAttribute: function (n, a) { - var t = xmltype.widget.tag[a]; - if (!t) { - error('Unrecognized attribute: <' + n + ' ' + a + '>. '); - } - var x = t.parent; - if (x.indexOf(' ' + n + ' ') < 0) { - error('Attribute ' + a + ' does not belong in <' + - n + '>'); - } - return t.script ? 'script' : a === 'name' ? 'define' : 'string'; - }, - doIt: function (n) { - var x = xmltype.widget.tag[n]; - return x && x.script && 'script'; - }, - tag: { - "about-box": {parent: ' widget '}, - "about-image": {parent: ' about-box '}, - "about-text": {parent: ' about-box '}, - "about-version": {parent: ' about-box '}, - action: {parent: ' widget ', script: true}, - alignment: {parent: ' image text textarea window '}, - author: {parent: ' widget '}, - autoHide: {parent: ' scrollbar '}, - bgColor: {parent: ' text textarea '}, - bgOpacity: {parent: ' text textarea '}, - checked: {parent: ' image '}, - clipRect: {parent: ' image '}, - color: {parent: ' about-text about-version shadow text textarea '}, - contextMenuItems: {parent: ' frame image text textarea window '}, - colorize: {parent: ' image '}, - columns: {parent: ' textarea '}, - company: {parent: ' widget '}, - copyright: {parent: ' widget '}, - data: {parent: ' about-text about-version text textarea '}, - debug: {parent: ' widget '}, - defaultValue: {parent: ' preference '}, - defaultTracking: {parent: ' widget '}, - description: {parent: ' preference '}, - directory: {parent: ' preference '}, - editable: {parent: ' textarea '}, - enabled: {parent: ' menuItem '}, - extension: {parent: ' preference '}, - file: {parent: ' action preference '}, - fillMode: {parent: ' image '}, - font: {parent: ' about-text about-version text textarea '}, - frame: {parent: ' frame window '}, - group: {parent: ' preference '}, - hAlign: {parent: ' frame image scrollbar text textarea '}, - height: {parent: ' frame image scrollbar text textarea window '}, - hidden: {parent: ' preference '}, - hLineSize: {parent: ' frame '}, - hOffset: {parent: ' about-text about-version frame image scrollbar shadow text textarea window '}, - hotkey: {parent: ' widget '}, - hRegistrationPoint: {parent: ' image '}, - hslAdjustment: {parent: ' image '}, - hslTinting: {parent: ' image '}, - hScrollBar: {parent: ' frame '}, - icon: {parent: ' preferenceGroup '}, - image: {parent: ' about-box frame window widget '}, - interval: {parent: ' action timer '}, - key: {parent: ' hotkey '}, - kind: {parent: ' preference '}, - level: {parent: ' window '}, - lines: {parent: ' textarea '}, - loadingSrc: {parent: ' image '}, - max: {parent: ' scrollbar '}, - maxLength: {parent: ' preference '}, - menuItem: {parent: ' contextMenuItems '}, - min: {parent: ' scrollbar '}, - minimumVersion: {parent: ' widget '}, - minLength: {parent: ' preference '}, - missingSrc: {parent: ' image '}, - modifier: {parent: ' hotkey '}, - name: {parent: ' hotkey image preference preferenceGroup text textarea timer window '}, - notSaved: {parent: ' preference '}, - onContextMenu: {parent: ' frame image text textarea window ', script: true}, - onDragDrop: {parent: ' frame image text textarea ', script: true}, - onDragEnter: {parent: ' frame image text textarea ', script: true}, - onDragExit: {parent: ' frame image text textarea ', script: true}, - onFirstDisplay: {parent: ' window ', script: true}, - onGainFocus: {parent: ' textarea window ', script: true}, - onKeyDown: {parent: ' hotkey text textarea ', script: true}, - onKeyPress: {parent: ' textarea ', script: true}, - onKeyUp: {parent: ' hotkey text textarea ', script: true}, - onImageLoaded: {parent: ' image ', script: true}, - onLoseFocus: {parent: ' textarea window ', script: true}, - onMouseDown: {parent: ' frame image text textarea ', script: true}, - onMouseEnter: {parent: ' frame image text textarea ', script: true}, - onMouseExit: {parent: ' frame image text textarea ', script: true}, - onMouseMove: {parent: ' frame image text ', script: true}, - onMouseUp: {parent: ' frame image text textarea ', script: true}, - onMouseWheel: {parent: ' frame ', script: true}, - onMultiClick: {parent: ' frame image text textarea window ', script: true}, - onSelect: {parent: ' menuItem ', script: true}, - onTimerFired: {parent: ' timer ', script: true}, - onValueChanged: {parent: ' scrollbar ', script: true}, - opacity: {parent: ' frame image scrollbar shadow text textarea window '}, - option: {parent: ' preference widget '}, - optionValue: {parent: ' preference '}, - order: {parent: ' preferenceGroup '}, - orientation: {parent: ' scrollbar '}, - pageSize: {parent: ' scrollbar '}, - preference: {parent: ' widget '}, - preferenceGroup: {parent: ' widget '}, - remoteAsync: {parent: ' image '}, - requiredPlatform: {parent: ' widget '}, - rotation: {parent: ' image '}, - scrollX: {parent: ' frame '}, - scrollY: {parent: ' frame '}, - secure: {parent: ' preference textarea '}, - scrollbar: {parent: ' text textarea '}, - shadow: {parent: ' about-text text window '}, - size: {parent: ' about-text about-version text textarea '}, - spellcheck: {parent: ' textarea '}, - src: {parent: ' image '}, - srcHeight: {parent: ' image '}, - srcWidth: {parent: ' image '}, - style: {parent: ' about-text about-version preference text textarea '}, - text: {parent: ' frame window '}, - textarea: {parent: ' frame window '}, - timer: {parent: ' widget '}, - thumbColor: {parent: ' scrollbar '}, - ticking: {parent: ' timer '}, - ticks: {parent: ' preference '}, - tickLabel: {parent: ' preference '}, - tileOrigin: {parent: ' image '}, - title: {parent: ' menuItem preference preferenceGroup window '}, - tooltip: {parent: ' image text textarea '}, - tracking: {parent: ' image '}, - trigger: {parent: ' action '}, - truncation: {parent: ' text '}, - type: {parent: ' preference '}, - useFileIcon: {parent: ' image '}, - vAlign: {parent: ' frame image scrollbar text textarea '}, - value: {parent: ' preference scrollbar '}, - version: {parent: ' widget '}, - visible: {parent: ' frame image scrollbar text textarea window '}, - vLineSize: {parent: ' frame '}, - vOffset: {parent: ' about-text about-version frame image scrollbar shadow text textarea window '}, - vRegistrationPoint: {parent: ' image '}, - vScrollBar: {parent: ' frame '}, - width: {parent: ' frame image scrollbar text textarea window '}, - window: {parent: ' widget '}, - zOrder: {parent: ' frame image scrollbar text textarea '} - } - } - }; - - function xmlword(tag) { - var w = token.value; - if (!token.identifier) { - if (token.id === '<') { - error(tag ? "Expected < and saw '<'" : "Missing '>'", - prevtoken); - } else { - warning("Missing quotes", prevtoken); - } - } - advance(); - while (token.id === '-' || token.id === ':') { - w += token.id; - advance(); - if (!token.identifier) { - error('Bad name: ' + w + token.value); - } - w += token.value; - advance(); - } - return w; - } - - function xml() { - var a, e, n, q, t; - xmode = 'xml'; - stack = []; - for (;;) { - switch (token.value) { - case '<': - advance('<'); - t = token; - n = xmlword(true); - t.name = n; - if (!xtype) { - if (xmltype[n]) { - xmltype[n].doBegin(); - n = xtype; - e = false; - } else { - error("Unrecognized <" + n + ">"); - } - } else { - if (option.cap && xtype === 'html') { - n = n.toLowerCase(); - } - e = xmltype[xtype].doTagName(n, stack[stack.length - 1].type); - } - t.type = n; - for (;;) { - if (token.id === '/') { - advance('/'); - e = true; - break; - } - if (token.id && token.id.substr(0, 1) === '>') { - break; - } - a = xmlword(); - switch (xmltype[xtype].doAttribute(n, a)) { - case 'script': - xmode = 'string'; - advance('='); - q = token.id; - if (q !== '"' && q !== "'") { - error('Missing quote.'); - } - xmode = q; - advance(q); - statements(); - if (token.id !== q) { - error( - 'Missing close quote on script attribute'); - } - xmode = 'xml'; - advance(q); - break; - case 'value': - advance('='); - if (!token.identifier && - token.type != '(string)' && - token.type != '(number)') { - error('Bad value: ' + token.value); - } - advance(); - break; - case 'string': - advance('='); - if (token.type !== '(string)') { - error('Bad value: ' + token.value); - } - advance(); - break; - case 'define': - advance('='); - if (token.type !== '(string)') { - error('Bad value: ' + token.value); - } - addlabel(token.value, 'global'); - advance(); - break; - default: - if (token.id === '=') { - advance('='); - if (!token.identifier && - token.type != '(string)' && - token.type != '(number)') { - } - advance(); - } - } - } - switch (xmltype[xtype].doIt(n)) { - case 'script': - xmode = 'script'; - advance('>'); - statements(); - xmode = 'xml'; - break; - case 'special': - e = true; - n = ''; - if (!lex.skip(n)) { - error("Missing " + n, t); - } - break; - default: - lex.skip('>'); - } - if (!e) { - stack.push(t); - } - break; - case ''); - } - if (t.name != n) { - error('Expected and instead saw '); - } - if (token.id !== '>') { - error("Expected '>'"); - } - lex.skip('>'); - break; - case '') { - break; - } - if (token.id === '<' || token.id === '(end)') { - error("Missing '>'.", prevtoken); - } - } - lex.skip('>'); - break; - case ''); - break; - case '<%': - lex.skip('%>'); - break; - case '') { - break; - } - if (token.id === '' || token.id === '(end)') { - error("Missing '?>'.", prevtoken); - } - } - lex.skip('?>'); - break; - case '<=': - case '<<': - case '<<=': - error("Expected '<'."); - break; - case '(end)': - return; - } - if (!lex.skip('')) { - if (stack.length) { - t = stack.pop(); - error('Missing ', t); - } - return; - } - advance(); - } - } - - -// Build the syntax table by declaring the syntactic elements of the language. - - type('(number)', idValue); - type('(string)', idValue); - - syntax['(identifier)'] = { - type: '(identifier)', - lbp: 0, - identifier: true, - nud: function () { - if (option.undef && !builtin(this.value) && - xmode !== '"' && xmode !== "'") { - var c = funlab; - while (!c[this.value]) { - c = c['(context)']; - if (!c) { - warning("Undefined variable: " + this.value, - prevtoken); - break; - } - } - } - addlabel(this.value, 'global'); - return this; - }, - led: function () { - error("Expected an operator and instead saw '" + - token.value + "'."); - } - }; - - type('(regex)', function () { - return [this.id, this.value, this.flags]; - }); - - delim('(endline)'); - delim('(begin)'); - delim('(end)').reach = true; - delim(''); - delim('?>'); - delim('(error)').reach = true; - delim('}').reach = true; - delim(')'); - delim(']'); - delim(']]>').reach = true; - delim('"').reach = true; - delim("'").reach = true; - delim(';'); - delim(':').reach = true; - delim(','); - reservevar('eval'); - reserve('else'); - reserve('case').reach = true; - reserve('default').reach = true; - reserve('catch'); - reserve('finally'); - reservevar('arguments'); - reservevar('false'); - reservevar('Infinity'); - reservevar('NaN'); - reservevar('null'); - reservevar('this'); - reservevar('true'); - reservevar('undefined'); - assignop('=', 'assign', 20); - assignop('+=', 'assignadd', 20); - assignop('-=', 'assignsub', 20); - assignop('*=', 'assignmult', 20); - assignop('/=', 'assigndiv', 20).nud = function () { - warning( - "A regular expression literal can be confused with '/='."); - }; - assignop('%=', 'assignmod', 20); - assignop('&=', 'assignbitand', 20); - assignop('|=', 'assignbitor', 20); - assignop('^=', 'assignbitxor', 20); - assignop('<<=', 'assignshiftleft', 20); - assignop('>>=', 'assignshiftright', 20); - assignop('>>>=', 'assignshiftrightunsigned', 20); - infix('?', function (left) { - parse(10); - advance(':'); - parse(10); - }, 30); - - infix('||', 'or', 40); - infix('&&', 'and', 50); - infix('|', 'bitor', 70); - infix('^', 'bitxor', 80); - infix('&', 'bitand', 90); - infix('==', function (left) { - var t = token; - if ( (t.type === '(number)' && !+t.value) || - (t.type === '(string)' && !t.value) || - t.type === 'true' || t.type === 'false' || - t.type === 'undefined' || t.type === 'null') { - warning("Use '===' to compare with '" + t.value + "'.", t); - } - return ['==', left, parse(100)]; - }, 100); - infix('===', 'equalexact', 100); - infix('!=', function (left) { - var t = token; - if ( (t.type === '(number)' && !+t.value) || - (t.type === '(string)' && !t.value) || - t.type === 'true' || t.type === 'false' || - t.type === 'undefined' || t.type === 'null') { - warning("Use '!==' to compare with '" + t.value + "'.", t); - } - return ['!=', left, parse(100)]; - }, 100); - infix('!==', 'notequalexact', 100); - infix('<', 'less', 110); - infix('>', 'greater', 110); - infix('<=', 'lessequal', 110); - infix('>=', 'greaterequal', 110); - infix('<<', 'shiftleft', 120); - infix('>>', 'shiftright', 120); - infix('>>>', 'shiftrightunsigned', 120); - infix('in', 'in', 120); - infix('instanceof', 'instanceof', 120); - infix('+', 'addconcat', 130); - prefix('+', 'num'); - infix('-', 'sub', 130); - prefix('-', 'neg'); - infix('*', 'mult', 140); - infix('/', 'div', 140); - infix('%', 'mod', 140); - - suffix('++', 'postinc'); - prefix('++', 'preinc'); - syntax['++'].exps = true; - - suffix('--', 'postdec'); - prefix('--', 'predec'); - syntax['--'].exps = true; - prefixname('delete', function () { - parse(0); - }).exps = true; - - - prefix('~', 'bitnot'); - prefix('!', 'not'); - prefixname('typeof', 'typeof'); - prefixname('new', function () { - var c = parse(155), - i; - if (c) { - if (c.identifier) { - c['new'] = true; - switch (c.value) { - case 'Object': - warning('Use the object literal notation {}.', prevtoken); - break; - case 'Array': - warning('Use the array literal notation [].', prevtoken); - break; - case 'Number': - case 'String': - case 'Boolean': - warning("Do not use the " + c.value + - " function as a constructor.", prevtoken); - break; - case 'Function': - if (!option.evil) { - warning('The Function constructor is eval.'); - } - break; - default: - i = c.value.substr(0, 1); - if (i < 'A' || i > 'Z') { - warning( - 'A constructor name should start with an uppercase letter.', c); - } - } - } else { - if (c.id !== '.' && c.id !== '[' && c.id !== '(') { - warning('Bad constructor', prevtoken); - } - } - } else { - warning('Weird construction.', this); - } - if (token.id === '(') { - advance('('); - if (token.id !== ')') { - for (;;) { - parse(10); - if (token.id !== ',') { - break; - } - advance(','); - } - } - advance(')'); - } else { - warning("Missing '()' invoking a constructor."); - } - return syntax['function']; - }); - syntax['new'].exps = true; - - infix('.', function (left) { - var m = identifier(); - if (typeof m === 'string') { - countMember(m); - } - if (!option.evil && left && left.value === 'document' && - (m === 'write' || m === 'writeln')) { - warning("document.write can be a form of eval.", left); - } - this.left = left; - this.right = m; - return this; - }, 160); - - infix('(', function (left) { - var n = 0, p = []; - if (left && left.type === '(identifier)') { - if (left.value.match(/^[A-Z](.*[a-z].*)?$/)) { - if (left.value !== 'Number' && left.value !== 'String') { - warning("Missing 'new' prefix when invoking a constructor", - left); - } - } - } - if (token.id !== ')') { - for (;;) { - p[p.length] = parse(10); - n += 1; - if (token.id !== ',') { - break; - } - advance(','); - } - } - advance(')'); - if (typeof left === 'object') { - if (left.value == 'parseInt' && n == 1) { - warning("Missing radix parameter", left); - } - if (!option.evil) { - if (left.value == 'eval' || left.value == 'Function') { - warning("eval is evil", left); - } else if (p[0] && p[0].id === '(string)' && - (left.value === 'setTimeout' || - left.value === 'setInterval')) { - warning( - "Implied eval is evil. Use a function argument instead of a string", left); - } - } - if (!left.identifier && left.id !== '.' && - left.id !== '[' && left.id !== '(') { - warning('Bad invocation.', left); - } - - } - return syntax['function']; - }, 155).exps = true; - - prefix('(', function () { - parse(0); - advance(')', this); - }); - - infix('[', function (left) { - var e = parse(0); - if (e && e.type === '(string)') { - countMember(e.value); - if (ix.test(e.value)) { - var s = syntax[e.value]; - if (!s || !s.reserved) { - warning("This is better written in dot notation.", e); - } - } - } - advance(']', this); - this.left = left; - this.right = e; - return this; - }, 160); - - prefix('[', function () { - if (token.id === ']') { - advance(']'); - return; - } - for (;;) { - parse(10); - if (token.id === ',') { - advance(','); - if (token.id === ']' || token.id === ',') { - warning('Extra comma.', prevtoken); - } - } else { - advance(']', this); - return; - } - } - }, 160); - - (function (x) { - x.nud = function () { - var i; - if (token.id === '}') { - advance('}'); - return; - } - for (;;) { - i = optionalidentifier(true); - if (!i && (token.id === '(string)' || token.id === '(number)')) { - i = token.id; - advance(); - } - if (!i) { - error("Expected an identifier and instead saw '" + - token.value + "'."); - } - if (typeof i.value === 'string') { - countMember(i.value); - } - advance(':'); - parse(10); - if (token.id === ',') { - advance(','); - if (token.id === ',' || token.id === '}') { - warning("Extra comma."); - } - } else { - advance('}', this); - return; - } - } - }; - x.fud = function () { - error( - "Expected to see a statement and instead saw a block."); - }; - })(delim('{')); - - - function varstatement() { - var i, n; - for (;;) { - n = identifier(); - if (!option.redef) { - for (i = funstack.length - 1; i >= 0; i -= 1) { - if (funstack[i][n]) { - warning("Redefinition of '" + n + "'.", prevtoken); - break; - } - } - } - addlabel(n, 'var'); - if (token.id === '=') { - advance('='); - parse(20); - } - if (token.id === ',') { - advance(','); - } else { - return; - } - } - } - - - stmt('var', varstatement); - - stmt('new', function () { - error("'new' should not be used as a statement"); - }); - - - function functionparams() { - var t = token; - advance('('); - if (token.id === ')') { - advance(')'); - return; - } - for (;;) { - addlabel(identifier(), 'parameter'); - if (token.id === ',') { - advance(','); - } else { - advance(')', t); - return; - } - } - } - - - blockstmt('function', function () { - var i = identifier(); - addlabel(i, 'var*'); - beginfunction(i); - addlabel(i, 'function'); - functionparams(); - block(); - endfunction(); - }); - - prefixname('function', function () { - var i = optionalidentifier() || ('"' + anonname + '"'); - beginfunction(i); - addlabel(i, 'function'); - functionparams(); - block(); - endfunction(); - }); - - blockstmt('if', function () { - var t = token; - advance('('); - parse(20); - advance(')', t); - block(); - if (token.id === 'else') { - advance('else'); - if (token.id === 'if' || token.id === 'switch') { - statement(); - } else { - block(); - } - } - }); - - blockstmt('try', function () { - var b; - block(); - if (token.id === 'catch') { - advance('catch'); - beginfunction('"catch"'); - functionparams(); - block(); - endfunction(); - b = true; - } - if (token.id === 'finally') { - advance('finally'); - beginfunction('"finally"'); - block(); - endfunction(); - return; - } else if (!b) { - error("Expected 'catch' or 'finally' and instead saw '" + - token.value + "'."); - } - }); - - blockstmt('while', function () { - var t= token; - advance('('); - parse(20); - advance(')', t); - block(); - }).labelled = true; - - reserve('with'); - - blockstmt('switch', function () { - var t = token; - advance('('); - var g = false; - parse(20); - advance(')', t); - t = token; - advance('{'); - for (;;) { - switch (token.id) { - case 'case': - switch (verb) { - case 'break': - case 'case': - case 'continue': - case 'return': - case 'switch': - case 'throw': - break; - default: - warning( - "Expected a 'break' statement before 'case'.", - prevtoken); - } - advance('case'); - parse(20); - g = true; - advance(':'); - verb = 'case'; - break; - case 'default': - switch (verb) { - case 'break': - case 'continue': - case 'return': - case 'throw': - break; - default: - warning( - "Expected a 'break' statement before 'default'.", - prevtoken); - } - advance('default'); - g = true; - advance(':'); - break; - case '}': - advance('}', t); - return; - case '(end)': - error("Missing '}'."); - return; - default: - if (prevtoken.id !== ':') { - error("Missing ':' on a case clause", prevtoken); - } - if (g) { - statements(); - } else { - error("Expected to see 'case' and instead saw '" + - token.value + "'."); - } - } - } - }).labelled = true; - - stmt('debugger', function () { - if (!option.debug) { - warning("All debugger statements should be removed."); - } - }); - - stmt('do', function () { - block(); - advance('while'); - var t = token; - advance('('); - parse(20); - advance(')', t); - }).labelled = true; - - blockstmt('for', function () { - var t = token; - advance('('); - if (peek(token.id === 'var' ? 1 : 0).id === 'in') { - if (token.id === 'var') { - advance('var'); - addlabel(identifier(), 'var'); - } else { - advance(); - } - advance('in'); - parse(20); - advance(')', t); - block(); - return; - } else { - if (token.id != ';') { - if (token.id === 'var') { - advance('var'); - varstatement(); - } else { - for (;;) { - parse(0); - if (token.id !== ',') { - break; - } - advance(','); - } - } - } - advance(';'); - if (token.id != ';') { - parse(20); - } - advance(';'); - if (token.id === ';') { - error("Expected to see ')' and instead saw ';'"); - } - if (token.id != ')') { - for (;;) { - parse(0); - if (token.id !== ',') { - break; - } - advance(','); - } - } - advance(')', t); - block(); - } - }).labelled = true; - - - function nolinebreak(t) { - if (t.line !== token.line) { - warning("Statement broken badly.", t); - } - } - - - stmt('break', function () { - nolinebreak(this); - if (funlab[token.value] === 'live*') { - advance(); - } - reachable('break'); - }); - - - stmt('continue', function () { - nolinebreak(this); - if (funlab[token.id] === 'live*') { - advance(); - } - reachable('continue'); - }); - - - stmt('return', function () { - nolinebreak(this); - if (token.id != ';' && !token.reach) { - parse(20); - } - reachable('return'); - }); - - - stmt('throw', function () { - nolinebreak(this); - parse(20); - reachable('throw'); - }); - - -// Superfluous reserved words - - reserve('abstract'); - reserve('boolean'); - reserve('byte'); - reserve('char'); - reserve('class'); - reserve('const'); - reserve('double'); - reserve('enum'); - reserve('export'); - reserve('extends'); - reserve('final'); - reserve('float'); - reserve('goto'); - reserve('implements'); - reserve('import'); - reserve('int'); - reserve('interface'); - reserve('long'); - reserve('native'); - reserve('package'); - reserve('private'); - reserve('protected'); - reserve('public'); - reserve('short'); - reserve('static'); - reserve('super'); - reserve('synchronized'); - reserve('throws'); - reserve('transient'); - reserve('void'); - reserve('volatile'); - - -// The actual JSLINT function itself. - - var j = function (s, o) { - option = o; - if (!o) { - option = {}; - } - JSLINT.errors = []; - globals = {}; - functions = []; - xmode = false; - xtype = ''; - stack = null; - funlab = {}; - member = {}; - funstack = []; - lookahead = []; - lex.init(s); - - prevtoken = token = syntax['(begin)']; - try { - advance(); - if (token.value.charAt(0) === '<') { - xml(); - } else { - statements(); - advance('(end)'); - } - } catch (e) { - if (e) { - JSLINT.errors.push({ - reason: "JSLint error: " + e.description, - line: token.line, - character: token.from, - evidence: token.value - }); - } - } - return JSLINT.errors.length === 0; - }; - - -// Report generator. - - j.report = function (option) { - var a = [], c, cc, f, i, k, o = [], s; - - function detail(h) { - if (s.length) { - o.push('
      ' + h + ':  ' + s.sort().join(', ') + - '
      '); - } - } - - k = JSLINT.errors.length; - if (k) { - o.push( - '
      Error:
      '); - for (i = 0; i < k; i += 1) { - c = JSLINT.errors[i]; - if (c) { - o.push('

      Problem at line ' + (c.line + 1) + - ' character ' + (c.character + 1) + - ': ' + c.reason.entityify() + - '

      ' + c.evidence.entityify() + - '

      '); - } - } - o.push('
      '); - if (!c) { - return o.join(''); - } - } - - if (!option) { - for (k in member) { - a.push(k); - } - if (a.length) { - a = a.sort(); - o.push( - ''); - for (i = 0; i < a.length; i += 1) { - o.push(''); - } - o.push('
      MembersOccurrences
      ', a[i], '', member[a[i]], - '
      '); - } - for (i = 0; i < functions.length; ++i) { - f = functions[i]; - for (k in f) { - if (f[k] === 'global') { - c = f['(context)']; - for (;;) { - cc = c['(context)']; - if (!cc) { - if ((!funlab[k] || funlab[k] === 'var?') && - !builtin(k)) { - funlab[k] = 'var?'; - f[k] = 'global?'; - } - break; - } - if (c[k] === 'parameter!' || c[k] === 'var!') { - f[k] = 'var.'; - break; - } - if (c[k] === 'var' || c[k] === 'var*' || - c[k] === 'var!') { - f[k] = 'var.'; - c[k] = 'var!'; - break; - } - if (c[k] === 'parameter') { - f[k] = 'var.'; - c[k] = 'parameter!'; - break; - } - c = cc; - } - } - } - } - s = []; - for (k in funlab) { - c = funlab[k]; - if (typeof c === 'string' && c.substr(0, 3) === 'var') { - if (c === 'var?') { - s.push('' + k + ' (?)'); - } else { - s.push('' + k + ''); - } - } - } - detail('Global'); - if (functions.length) { - o.push('
      Function:
        '); - } - for (i = 0; i < functions.length; i += 1) { - f = functions[i]; - o.push('
      1. ' + (f['(name)'] || '') + ''); - s = []; - for (k in f) { - if (k.charAt(0) != '(') { - switch (f[k]) { - case 'parameter': - s.push('' + k + ''); - break; - case 'parameter!': - s.push('' + k + - ' (closure)'); - break; - } - } - } - detail('Parameter'); - s = []; - for (k in f) { - if (k.charAt(0) != '(') { - switch(f[k]) { - case 'var': - s.push('' + k + - ' (unused)'); - break; - case 'var*': - s.push('' + k + ''); - break; - case 'var!': - s.push('' + k + - ' (closure)'); - break; - case 'var.': - s.push('' + k + - ' (outer)'); - break; - } - } - } - detail('Var'); - s = []; - c = f['(context)']; - for (k in f) { - if (k.charAt(0) != '(' && f[k].substr(0, 6) === 'global') { - if (f[k] === 'global?') { - s.push('' + k + ' (?)'); - } else { - s.push('' + k + ''); - } - } - } - detail('Global'); - s = []; - for (k in f) { - if (k.charAt(0) != '(' && f[k] === 'label') { - s.push(k); - } - } - detail('Label'); - o.push('
      2. '); - } - if (functions.length) { - o.push('
      '); - } - } - return o.join(''); - }; - - return j; - -}(); \ No newline at end of file diff --git a/modules/jala/util/HopKit/scripts/jsmin.js b/modules/jala/util/HopKit/scripts/jsmin.js deleted file mode 100644 index 1ef29cf1..00000000 --- a/modules/jala/util/HopKit/scripts/jsmin.js +++ /dev/null @@ -1,316 +0,0 @@ -/* jsmin.js - 2006-08-31 -Author: Franck Marcia -This work is an adaptation of jsminc.c published by Douglas Crockford. -Permission is hereby granted to use the Javascript version under the same -conditions as the jsmin.c on which it is based. - -jsmin.c -2006-05-04 - -Copyright (c) 2002 Douglas Crockford (www.crockford.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -Update: - add level: - 1: minimal, keep linefeeds if single - 2: normal, the standard algorithm - 3: agressive, remove any linefeed and doesn't take care of potential - missing semicolons (can be regressive) - store stats - jsmin.oldSize - jsmin.newSize -*/ - -String.prototype.has = function(c) { - return this.indexOf(c) > -1; -}; - -function jsmin(comment, input, level) { - - if (input === undefined) { - input = comment; - comment = ''; - level = 2; - } else if (level === undefined || level < 1 || level > 3) { - level = 2; - } - - if (comment.length > 0) { - comment += '\n'; - } - - var a = '', - b = '', - EOF = -1, - LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', - DIGITS = '0123456789', - ALNUM = LETTERS + DIGITS + '_$\\', - theLookahead = EOF; - - - /* isAlphanum -- return true if the character is a letter, digit, underscore, - dollar sign, or non-ASCII character. - */ - - function isAlphanum(c) { - return c != EOF && (ALNUM.has(c) || c.charCodeAt(0) > 126); - } - - - /* get -- return the next character. Watch out for lookahead. If the - character is a control character, translate it to a space or - linefeed. - */ - - function get() { - - var c = theLookahead; - if (get.i == get.l) { - return EOF; - } - theLookahead = EOF; - if (c == EOF) { - c = input.charAt(get.i); - ++get.i; - } - if (c >= ' ' || c == '\n') { - return c; - } - if (c == '\r') { - return '\n'; - } - return ' '; - } - - get.i = 0; - get.l = input.length; - - - /* peek -- get the next character without getting it. - */ - - function peek() { - theLookahead = get(); - return theLookahead; - } - - - /* next -- get the next character, excluding comments. peek() is used to see - if a '/' is followed by a '/' or '*'. - */ - - function next() { - - var c = get(); - if (c == '/') { - switch (peek()) { - case '/': - for (;;) { - c = get(); - if (c <= '\n') { - return c; - } - } - break; - case '*': - get(); - for (;;) { - switch (get()) { - case '*': - if (peek() == '/') { - get(); - return ' '; - } - break; - case EOF: - throw 'Error: Unterminated comment.'; - } - } - break; - default: - return c; - } - } - return c; - } - - - /* action -- do something! What you do is determined by the argument: - 1 Output A. Copy B to A. Get the next B. - 2 Copy B to A. Get the next B. (Delete A). - 3 Get the next B. (Delete B). - action treats a string as a single character. Wow! - action recognizes a regular expression if it is preceded by ( or , or =. - */ - - function action(d) { - - var r = []; - - if (d == 1) { - r.push(a); - } - - if (d < 3) { - a = b; - if (a == '\'' || a == '"') { - for (;;) { - r.push(a); - a = get(); - if (a == b) { - break; - } - if (a <= '\n') { - throw 'Error: unterminated string literal: ' + a; - } - if (a == '\\') { - r.push(a); - a = get(); - } - } - } - } - - b = next(); - - if (b == '/' && '(,=:[!&|'.has(a)) { - r.push(a); - r.push(b); - for (;;) { - a = get(); - if (a == '/') { - break; - } else if (a =='\\') { - r.push(a); - a = get(); - } else if (a <= '\n') { - throw 'Error: unterminated Regular Expression literal'; - } - r.push(a); - } - b = next(); - } - - return r.join(''); - } - - - /* m -- Copy the input to the output, deleting the characters which are - insignificant to JavaScript. Comments will be removed. Tabs will be - replaced with spaces. Carriage returns will be replaced with - linefeeds. - Most spaces and linefeeds will be removed. - */ - - function m() { - - var r = []; - a = '\n'; - - r.push(action(3)); - - while (a != EOF) { - switch (a) { - case ' ': - if (isAlphanum(b)) { - r.push(action(1)); - } else { - r.push(action(2)); - } - break; - case '\n': - switch (b) { - case '{': - case '[': - case '(': - case '+': - case '-': - r.push(action(1)); - break; - case ' ': - r.push(action(3)); - break; - default: - if (isAlphanum(b)) { - r.push(action(1)); - } else { - if (level == 1 && b != '\n') { - r.push(action(1)); - } else { - r.push(action(2)); - } - } - } - break; - default: - switch (b) { - case ' ': - if (isAlphanum(a)) { - r.push(action(1)); - break; - } - r.push(action(3)); - break; - case '\n': - if (level == 1 && a != '\n') { - r.push(action(1)); - } else { - switch (a) { - case '}': - case ']': - case ')': - case '+': - case '-': - case '"': - case '\'': - if (level == 3) { - r.push(action(3)); - } else { - r.push(action(1)); - } - break; - default: - if (isAlphanum(a)) { - r.push(action(1)); - } else { - r.push(action(3)); - } - } - } - break; - default: - r.push(action(1)); - break; - } - } - } - - return r.join(''); - } - - jsmin.oldSize = input.length; - ret = m(input); - jsmin.newSize = ret.length; - - return comment + ret; - -} diff --git a/modules/jala/util/Test/build.gradle b/modules/jala/util/Test/build.gradle deleted file mode 100644 index 7e596efa..00000000 --- a/modules/jala/util/Test/build.gradle +++ /dev/null @@ -1,16 +0,0 @@ -dependencies { - runtimeOnly 'org.subethamail:subethasmtp-smtp:1.2' - runtimeOnly 'org.subethamail:subethasmtp-wiser:1.2' -} - -jar.enabled = false -compileJava.enabled = false -compileTestJava.enabled = false -processResources.enabled = false -processTestResources.enabled = false -test.enabled = false - -tasks.register('deps', Copy) { - from sourceSets.main.runtimeClasspath - into 'code' -} diff --git a/modules/jala/util/Test/code/Global/Root.js b/modules/jala/util/Test/code/Global/Root.js deleted file mode 100644 index 86713cc7..00000000 --- a/modules/jala/util/Test/code/Global/Root.js +++ /dev/null @@ -1,53 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * Module dependencies - */ -app.addRepository("modules/core/HopObject.js"); -app.addRepository("modules/core/Array.js"); -app.addRepository("modules/helma/File.js"); - -/** - * Test runner - */ -Root.prototype.jala_test_action = function() { - res.handlers.test = new jala.Test(); - if (req.isGet() && req.data.test) { - res.handlers.test.execute(req.data.test); - } else if (req.isPost() && (req.data.test_array || req.data.test)) { - res.handlers.test.execute(req.data.test_array || req.data.test); - } - renderSkin("jala.Test"); - return; -}; - -/** - * External stylesheet for test runner - */ -Root.prototype.jala_test_css_action = function() { - res.contentType = "text/css"; - renderSkin("jala.Test#stylesheet"); - return; -}; diff --git a/modules/jala/util/Test/code/Global/jala.Test.js b/modules/jala/util/Test/code/Global/jala.Test.js deleted file mode 100644 index f171da68..00000000 --- a/modules/jala/util/Test/code/Global/jala.Test.js +++ /dev/null @@ -1,1598 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * @fileoverview Fields and methods of the jala.Test class. - */ - - -// Define the global namespace for Jala modules -if (!global.jala) { - global.jala = {}; -} - -/** - * HelmaLib dependencies - */ -app.addRepository("modules/core/String.js"); -app.addRepository("modules/helma/Http.js"); - -/** - * Jala dependencies - */ -app.addRepository(getProperty("jala.dir", "modules/jala") + - "/code/Database.js"); - -/** - * Constructs a new Test instance. - * @class Provides various methods for automated tests. - * This is essentially a port of JSUnit (http://www.edwardh.com/jsunit/) - * suitable for testing Helma applications. - * @param {Number} capacity The capacity of the cache - * @constructor - */ -jala.Test = function() { - - /** - * Contains the number of tests that were executed - * @type Number - */ - this.testsRun = 0; - - /** - * Contains the number of tests that failed - * @type Boolean - */ - this.testsFailed = 0; - - /** - * Contains the number of test functions that passed - * @type Number - */ - this.functionsPassed = 0; - - /** - * Contains the number of test functions that failed - * @type Number - */ - this.functionsFailed = 0; - - /** - * An Array containing the results of this Test instance. - * @type Array - */ - this.results = []; - - return this; -}; - - - -/************************************************************* - ***** S T A T I C F I E L D S A N D M E T H O D S ***** - *************************************************************/ - - -/** - * Constant indicating "passed" status - * @type String - * @final - */ -jala.Test.PASSED = "passed"; - -/** - * Constant indicating "failed" status - * @type String - * @final - */ -jala.Test.FAILED = "failed"; - -/** - * Helper method useable for displaying a value - * @param {Object} The value to render - * @returns The value rendered as string - * @type String - */ -jala.Test.valueToString = function(val) { - res.push(); - if (val === null) { - res.write("null"); - } else if (val === undefined) { - res.write("undefined"); - } else { - if (typeof(val) == "function") { - // functions can be either JS methods or Java classes - // the latter throws an exception when trying to access a property - try { - res.write(val.name || val); - } catch (e) { - res.write(val); - } - } else { - if (val.constructor && val.constructor == String) { - res.write('"' + encode(val.head(200)) + '"'); - } else { - res.write(val.toString()); - } - res.write(" ("); - if (val.constructor && val.constructor.name != null) { - res.write(val.constructor.name); - } else { - res.write(typeof(val)); - } - res.write(")"); - } - } - return res.pop(); -}; - -/** - * Returns the directory containing the test files. - * The location of the directory is either defined by the - * application property "jala.testDir" or expected to be one level - * above the application directory (and named "tests") - * @returns The directory containing the test files - * @type helma.File - */ -jala.Test.getTestsDirectory = function() { - var dir; - if (getProperty("jala.testDir") != null) { - dir = new helma.File(getProperty("jala.testDir")); - } - if (!dir || !dir.exists()) { - var appDir = new helma.File(app.dir); - dir = new helma.File(appDir.getParent(), "tests"); - if (!dir.exists()) - return null; - } - return dir; -}; - -/** - * Returns an array containing the test files located - * in the directory. - * @returns An array containing the names of all test files - * @type Array - */ -jala.Test.getTestFiles = function() { - var dir; - if ((dir = jala.Test.getTestsDirectory()) != null) { - return dir.list(/.*\.js$/).sort(); - } - return null; -}; - -/** - * Returns the testfile with the given name - * @param {String} fileName The name of the test file - * @returns The test file - * @type helma.File - */ -jala.Test.getTestFile = function(fileName) { - var dir = jala.Test.getTestsDirectory(); - if (dir != null) { - return new helma.File(dir, fileName); - } - return null; -}; - -/** - * @param {Number} nr The number of arguments to be expected - * @param {Object} args The arguments array. - * @returns True in case the number of arguments matches - * the expected amount, false otherwise. - * @type Boolean - */ -jala.Test.evalArguments = function(args, argsExpected) { - if (!(args.length == argsExpected || - (args.length == argsExpected + 1 && typeof(args[0]) == "string"))) { - throw new jala.Test.ArgumentsException("Insufficient arguments passed to assertion function"); - } - return; -}; - -/** - * Returns true if the arguments array passed as argument - * contains an additional comment. - * @param {Array} args The arguments array to check for an existing comment. - * @param {Number} argsExpected The number of arguments expected by the - * assertion function. - * @returns True if the arguments contain a comment, false otherwise. - * @type Boolean - */ -jala.Test.argsContainComment = function(args, argsExpected) { - return !(args.length <= argsExpected - || (args.length == argsExpected + 1 && typeof(args[0]) != "string")) -}; - -/** - * Cuts out the comment from the arguments array passed - * as argument and returns it. CAUTION: this actually modifies - * the arguments array! - * @param {Array} args The arguments array. - * @returns The comment, if existing. Null otherwise. - * @type String - */ -jala.Test.getComment = function(args, argsExpected) { - if (jala.Test.argsContainComment(args, argsExpected)) - return args[0]; - return null; -}; - -/** - * Returns the argument on the index position in the array - * passed as arguments. This method respects an optional comment - * at the beginning of the arguments array. - * @param {Array} args The arguments to retrieve the non-comment - * value from. - * @param {Number} idx The index position on which the value to - * retrieve is to be expected if no comment is existing. - * @returns The non-comment value, or null. - * @type Object - */ -jala.Test.getValue = function(args, argsExpected, idx) { - return jala.Test.argsContainComment(args, argsExpected) ? args[idx+1] : args[idx]; -}; - - -/** - * Creates a stack trace and parses it for display. - * @param {java.lang.StackTraceElement} trace The trace to parse. If not given - * a stacktrace will be generated - * @returns The parsed stack trace - * @type String - */ -jala.Test.getStackTrace = function(trace) { - /** - * Private method for filtering out only JS parts of the stack trace - * @param {Object} name - */ - var accept = function(name) { - return name.endsWith(".js") || name.endsWith(".hac") || - name.endsWith(".hsp"); - }; - - // create exception and fill in stack trace - if (!trace) { - var ex = new Packages.org.mozilla.javascript.EvaluatorException(""); - ex.fillInStackTrace(); - trace = ex.getStackTrace(); - } - var stack = []; - var el, fileName, lineNumber; - // parse the stack trace and keep only the js elements - var inTrace = false; - for (var i=trace.length; i>0; i--) { - el = trace[i-1]; - fileName = el.getFileName(); - lineNumber = el.getLineNumber(); - if (fileName != null && lineNumber > -1 && accept(fileName)) { - if (fileName.endsWith(res.meta.currentTest)) { - inTrace = true; - } - if (inTrace == true) { - // ignore all trace lines that refer to jala.Test - if (fileName.endsWith("jala.Test.js")) { - break; - } - stack.push("at " + fileName + ":" + lineNumber); - } - } - } - return stack.reverse().join("\n"); -}; - -/** - * Adds all assertion methods, the http client, test database manager and - * smpt server to the per-thread global object. - * @private - */ -jala.Test.prepareTestScope = function() { - // define global assertion functions - for (var i in jala.Test.prototype) { - if (i.indexOf("assert") == 0) { - global[i] = jala.Test.prototype[i]; - } - } - // add global include method - global.include = function(file) { - jala.Test.include(global, file); - return; - }; - // instantiate a global HttpClient - global.httpClient = new jala.Test.HttpClient(); - // instantiate the test database manager - global.testDatabases = new jala.Test.DatabaseMgr(); - // instantiate the smtp server - global.smtpServer = new jala.Test.SmtpServer(); - return; -}; - -/** - * Evaluates a javascript file in the global test scope. This method can be used - * to include generic testing code in test files. This method is available as - * global method "include" for all test methods - * @param {Object} scope The scope in which the file should be evaluated - * @param {String} fileName The name of the file to include, including the path - */ -jala.Test.include = function(scope, file) { - var file = new helma.File(file); - var fileName = file.getName(); - if (file.canRead() && file.exists()) { - var cx = Packages.org.mozilla.javascript.Context.enter(); - var code = new java.lang.String(file.readAll() || ""); - cx.evaluateString(scope, code, fileName, 1, null); - } - return; -}; - - - -/******************************* - ***** E X C E P T I O N S ***** - *******************************/ - - -/** - * Creates a new Exception instance - * @class Base exception class - * @returns A newly created Exception instance - * @constructor - */ -jala.Test.Exception = function Exception() { - return this; -}; - -/** @ignore */ -jala.Test.Exception.prototype.toString = function() { - return "[jala.Test.Exception: " + this.message + "]"; -}; - -/** - * Creates a new TestException instance - * @class Instances of this exception are thrown whenever an - * assertion function fails - * @param {String} comment An optional comment - * @param {String} message The failure message - * @returns A newly created TestException instance - * @constructor - */ -jala.Test.TestException = function TestException(comment, message) { - this.functionName = null; - this.comment = comment; - this.message = message; - this.stackTrace = jala.Test.getStackTrace(); - return this; -}; -jala.Test.TestException.prototype = new jala.Test.Exception(); - -/** @ignore */ -jala.Test.TestException.prototype.toString = function() { - return "[jala.Test.TestException in " + this.functionName + - ": " + this.message + "]"; -}; - -/** - * Creates a new ArgumentsException instance - * @class Instances of this exception are thrown whenever an assertion - * function is called with incorrect or insufficient arguments - * @param {String} message The failure message - * @returns A newly created ArgumentsException instance - * @constructor - */ -jala.Test.ArgumentsException = function ArgumentsException(message) { - this.functionName = null; - this.message = message; - this.stackTrace = jala.Test.getStackTrace(); - return this; -}; -jala.Test.ArgumentsException.prototype = new jala.Test.Exception(); - -/** @ignore */ -jala.Test.ArgumentsException.prototype.toString = function() { - return "[jala.Test.ArgumentsException in " + this.functionName + - ": " + this.message + "]"; -}; - -/** - * Creates a new EvaluatorException instance - * @class Instances of this exception are thrown when attempt - * to evaluate the test code fails. - * @param {String} message The failure message, or an Error previously - * thrown. - * @param {String} exception An optional nested Error - * @returns A newly created EvaluatorException instance - * @constructor - */ -jala.Test.EvaluatorException = function EvaluatorException(message, exception) { - this.functionName = null; - this.message = null; - this.stackTrace = null; - this.fileName = null; - this.lineNumber = null; - - if (arguments.length == 1 && arguments[0] instanceof Error) { - this.message = ""; - exception = arguments[0]; - } else { - this.message = message; - } - - if (exception != null) { - this.name = exception.name; - if (exception.rhinoException != null) { - var e = exception.rhinoException; - this.message += e.details(); - this.stackTrace = jala.Test.getStackTrace(e.getStackTrace()); - } else if (exception instanceof Error) { - this.message = exception.message; - } - if (!this.stackTrace) { - // got no stack trace, so add at least filename and line number - this.fileName = exception.fileName || null; - this.lineNumber = exception.lineNumber || null; - } - } - - return this; -}; -jala.Test.EvaluatorException.prototype = new jala.Test.Exception(); - -/** @ignore */ -jala.Test.EvaluatorException.prototype.toString = function() { - return "[jala.Test.EvaluatorException: " + this.message + "]"; -}; - - - -/************************************************* - ***** R E S U L T C O N S T R U C T O R S ***** - *************************************************/ - - -/** - * Constructs a new TestResult instance - * @class Instances of this class represent the result of the execution - * of a single test file - * @param {String} testFileName The name of the excecuted test file - * @returns A new TestResult instance - * @constructor - */ -jala.Test.TestResult = function(testFileName) { - this.name = testFileName; - this.elapsed = 0; - this.status = jala.Test.PASSED; - this.log = []; - return this; -}; - -/** - * Constructs a new TestFunctionResult instance - * @class Instances of this class represent the result of the successful - * execution of a single test function (failed executions will be represented - * as Exceptions in the log of a test result). - * @param {String} functionName The name of the excecuted test function - * @param {Date} startTime A Date instance marking the begin of the test - * @returns A new TestFunctionResult instance - * @constructor - */ -jala.Test.TestFunctionResult = function(functionName, startTime) { - this.functionName = functionName; - this.elapsed = (new Date()) - startTime; - return this; -}; - - - -/************************************************* - ***** P R O T O T Y P E F U N C T I O N S ***** - *************************************************/ - - -/** - * Executes a single test file - * @param {helma.File} testFile The file containing the test to run - */ -jala.Test.prototype.executeTest = function(testFile) { - var testFileName = testFile.getName(); - // store the name of the current test in res.meta.currentTest - // as this is needed in getStackTrace - res.meta.currentTest = testFileName; - - var cx = Packages.org.mozilla.javascript.Context.enter(); - var code = new java.lang.String(testFile.readAll() || ""); - var testResult = new jala.Test.TestResult(testFileName); - global.testFunctionIdents = []; - try { - // prepare the test scope - jala.Test.prepareTestScope(); - // evaluate the test file in the per-thread which is garbage - // collected at the end of the test run - cx.evaluateString(global, code, testFileName, 1, null); - for (var ident in global) { - if (ident.startsWith("test") && (global[ident] instanceof Function)) { - testFunctionIdents.push(ident); - } - } - var start = new Date(); - // run all test methods defined in the array "tests" - var functionName; - for (var i=0;i 0) { - for (var i=0;i 0) { - var fileName, skinParam; - for (var i=0;i= 301 && result.code <= 303 && result.location != null) { - // received a redirect location, so follow it - result = this.executeRequest("GET", result.location); - } - return result; -}; - -/** - * Convenience method for requesting the url passed as argument - * using method GET - * @param {String} url The url to request - * @param {Object} param A parameter object to use with this request - * @return An object containing response values - * @see helma.Http.prototype.getUrl - */ -jala.Test.HttpClient.prototype.getUrl = function(url, param) { - return this.executeRequest("GET", url, param); -}; - -/** - * Convenience method for submitting a form. - * @param {String} url The url to request - * @param {Object} param A parameter object to use with this request - * @return An object containing response values - * @see helma.Http.prototype.getUrl - */ -jala.Test.HttpClient.prototype.submitForm = function(url, param) { - return this.executeRequest("POST", url, param); -}; - -/** @ignore */ -jala.Test.HttpClient.prototype.toString = function() { - return "[jala.Test.HttpClient]"; -}; - - - - -/***************************************************** - ***** T E S T D A T A B A S E M A N A G E R ***** - *****************************************************/ - - -/** - * Returns a newly created DatabaseMgr instance - * @class Instances of this class allow managing test databases - * and switching a running application to an in-memory test - * database to use within a unit test. - * @returns A newly created instance of DatabaseMgr - * @constructor - */ -jala.Test.DatabaseMgr = function() { - /** - * Map containing all test databases - */ - this.databases = {}; - - /** - * Map containing the original datasource - * properties that were temporarily deactivated - * by activating a test database - */ - this.dbSourceProperties = {}; - - return this; -}; - -jala.Test.DatabaseMgr.prototype.toString = function() { - return "[jala.Test DatabaseMgr]"; -}; - -/** - * Returns a newly initialized in-memory test database with the given name - * @param {String} name The name of the test database - * @returns The newly initialized test database - * @type jala.db.RamDatabase - */ -jala.Test.DatabaseMgr.prototype.initDatabase = function(name) { - return new jala.db.RamDatabase(name); -}; - -/** - * Switches the application to the test database passed as argument. - * In addition this method clears the application cache and invalidates - * the root object. - * @param {jala.db.RamDatabase} testDb The test database to switch to. - * @param {String} dbSourceName Optional name of the application's database - * source that will be replaced by the test database. - */ -jala.Test.DatabaseMgr.prototype.switchToDatabase = function(testDb, dbSourceName) { - var dbName = dbSourceName || testDb.getName(); - // switch the datasource to the test database - var dbSource = app.getDbSource(dbName); - var oldProps = dbSource.switchProperties(testDb.getProperties()); - // store the old db properties in this manager for use in stopAll() - this.databases[dbName] = testDb; - this.dbSourceProperties[dbName] = oldProps; - // clear the application cache and invalidate root - app.clearCache(); - root.invalidate(); - return; -}; - -/** - * Switches the application datasource with the given name - * to a newly created in-memory database. In addition this method - * also clears the application cache and invalidates the root - * object to ensure that everything is re-retrieved from the - * test database. - * This method can be called with a second boolean argument indicating - * that tables used by the application should be created in the in-memory - * database (excluding any data). - * @param {String} dbSourceName The name of the application database - * source as defined in db.properties - * @param {Boolean} copyTables If true this method also copies all - * tables in the source database to the test database (excluding - * indexes). - * @param {Array} tables An optional array containing table names that - * should be created in the test database. If not specified this method - * collects all tables that are mapped in the application. - * @returns The test database - * @type jala.db.RamDatabase - */ -jala.Test.DatabaseMgr.prototype.startDatabase = function(dbSourceName, copyTables, tables) { - try { - var testDb = this.initDatabase(dbSourceName); - // switch the datasource to the test database - var dbSource = app.getDbSource(dbSourceName); - if (copyTables === true) { - if (tables === null || tables === undefined) { - // collect the table names of all relational prototypes - tables = []; - var protos = app.getPrototypes(); - for (let proto of protos) { - var dbMap = proto.getDbMapping(); - if (dbMap.isRelational()) { - tables.push(dbMap.getTableName()); - } - } - } - testDb.copyTables(dbSource, tables); - } - this.switchToDatabase(testDb); - return testDb; - } catch (e) { - throw new jala.Test.EvaluatorException("Unable to switch to test database because of ", e); - } -}; - -/** - * Stops all registered test databases and and reverts the application - * to its original datasource(s) as defined in db.properties file. - * In addition this method rolls back all pending changes within the request, - * clears the application cache and invalidates the root object - * to ensure no traces of the test database are left behind. - */ -jala.Test.DatabaseMgr.prototype.stopAll = function() { - // throw away all pending transactions - res.rollback(); - try { - // loop over all registered databases and revert the appropriate - // datasource back to the original database - var testDb, dbSource; - for (var dbSourceName in this.databases) { - testDb = this.databases[dbSourceName]; - dbSource = app.getDbSource(dbSourceName); - dbSource.switchProperties(this.dbSourceProperties[dbSourceName]); - testDb.shutdown(); - } - // clear the application cache and invalidate root - app.clearCache(); - root.invalidate(); - } catch (e) { - throw new jala.Test.EvaluatorException("Unable to stop test databases because of ", e); - } - return; -}; - - - -/********************************* - ***** S M T P S E R V E R ***** - *********************************/ - - -/** - * Creates a new SmtpServer instance - * @class Instances of this class represent an SMTP server listening on - * localhost. By default jala.Test will create a global variable called - * "smtpServer" that contains an instance of this class. To use the server call - * {@link #start} in a test method (eg. in the basic setup method) and - * {@link #stop} in the cleanup method. - * @param {Number} port Optional port to listen on (defaults to 25) - * @returns A newly created SmtpServer instance - * @constructor - */ -jala.Test.SmtpServer = function(port) { - var server = null; - - var oldSmtpServer = null; - - /** - * Starts the SMTP server. Note that this method switches the SMTP server as - * defined in app.properties of the tested application or server.properties - * to "localhost" to ensure that all mails sent during tests are received - * by this server. The SMTP server definition is switched back to the - * original when {@link #stop} is called. - */ - this.start = function() { - server = new Packages.org.subethamail.wiser.Wiser() - // listen only on localhost - server.setHostname("localhost"); - if (port != null && !isNaN(port)) { - server.setPort(port); - } - // switch smtp property of tested application - oldSmtpServer = getProperty("smtp"); - app.__app__.getProperties().put("smtp", "localhost"); - server.start(); - return; - }; - - /** - * Stops the SMTP server and switches the "smtp" property of the tested - * application back to the value defined in app or server.properties - */ - this.stop = function() { - server.stop(); - server = null; - // switch back to original SMTP server address - var props = app.__app__.getProperties(); - if (oldSmtpServer != null) { - props.put("smtp", oldSmtpServer); - } else { - props.remove("smtp"); - } - return; - }; - - /** - * Returns an array containing all mails received by the server, - * where each one is an instance of {@link jala.Test.SmtpServer.Message} - * @returns An array with all messages - * @type Array - */ - this.getMessages = function() { - var it = server.getMessages().listIterator(); - var result = []; - while (it.hasNext()) { - result.push(new jala.Test.SmtpServer.Message(it.next())); - } - return result; - }; - - return this; -}; - -/** @ignore */ -jala.Test.SmtpServer.prototype.toString = function() { - return "[Jala Test SmtpServer]"; -}; - -/** - * Creates a new Mail instance - * @class Instances of this class represent a mail message received - * by the SMTP server - * @param {org.subethamail.wiser.WiserMessage} message The message - * as received by the SMTP server - * @returns A newly created Mail instance - * @constructor - */ -jala.Test.SmtpServer.Message = function(message) { - /** - * The wrapped message as MimeMessage instance - * @type javax.mail.internet.MimeMessage - * @private - */ - var mimeMessage = message.getMimeMessage(); - - /** - * Returns the wrapped message - * @type org.subethamail.wiser.WiserMessage - */ - this.getMessage = function() { - return message; - }; - - /** - * Returns the wrapped message as MimeMessage - * @type javax.mail.internet.MimeMessage - */ - this.getMimeMessage = function() { - return mimeMessage; - }; - - return this; -}; - -/** @ignore */ -jala.Test.SmtpServer.Message.prototype.toString = function() { - return "[Jala Test Mail]"; -}; - -/** - * Returns an array containing all senders of this mail - * @returns An array with all senders of this mail - * @type Array - */ -jala.Test.SmtpServer.Message.prototype.getFrom = function() { - var result = []; - this.getMimeMessage().getFrom().forEach(function(addr) { - result.push(addr.toString()) - }); - return result; -}; - -/** - * Returns an array containing all recipients of this mail - * @returns An array with all recipients of this mail - * @type Array - */ -jala.Test.SmtpServer.Message.prototype.getTo = function() { - var type = Packages.javax.mail.internet.MimeMessage.RecipientType.TO; - var result = []; - this.getMimeMessage().getRecipients(type).forEach(function(addr) { - result.push(addr.toString()) - }); - return result; -}; - -/** - * Returns an array containing all CC recipients of this mail - * @returns An array with all CC recipients of this mail - * @type Array - */ -jala.Test.SmtpServer.Message.prototype.getCc = function() { - var type = Packages.javax.mail.internet.MimeMessage.RecipientType.CC; - var result = []; - this.getMimeMessage().getRecipients(type).forEach(function(addr) { - result.push(addr.toString()) - }); - return result; -}; - -/** - * Returns an array with all reply-to addresses of this mail - * @returns An array with all reply-to addresses of this mail - * @type Array - */ -jala.Test.SmtpServer.Message.prototype.getReplyTo = function() { - var result = []; - this.getMimeMessage().getReplyTo().forEach(function(addr) { - result.push(addr.toString()) - }); - return result; -}; - -/** - * Returns the encoding of this mail as defined in the "Content-Transfer-Encoding" - * header field - * @returns The encoding of this mail - * @type String - */ -jala.Test.SmtpServer.Message.prototype.getEncoding = function() { - return this.getMimeMessage().getEncoding(); -}; - -/** - * Returns the subject of this mail - * @returns The subject of this mail - * @type String - */ -jala.Test.SmtpServer.Message.prototype.getSubject = function() { - return this.getMimeMessage().getSubject(); -}; - -/** - * Returns the content of this mail - * @returns The content of this mail - */ -jala.Test.SmtpServer.Message.prototype.getContent = function() { - return this.getMimeMessage().getContent(); -}; - -/** - * Returns the content type of this mail as defined in the "Content-Type" - * header field - * @returns The content type of this mail - * @type String - */ -jala.Test.SmtpServer.Message.prototype.getContentType = function() { - return this.getMimeMessage().getContentType(); -}; diff --git a/modules/jala/util/Test/code/Global/jala.Test.skin b/modules/jala/util/Test/code/Global/jala.Test.skin deleted file mode 100644 index e03b8647..00000000 --- a/modules/jala/util/Test/code/Global/jala.Test.skin +++ /dev/null @@ -1,294 +0,0 @@ -<% -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// -%> - - - -Jala Unit Test Runner -" /> - - - -
      -
      Jala Unit Test Runner
      -
      <% test.directory prefix="Tests: " %>
      -
      -
      -
      -
      "> - <% test.list prefix='

      Available Tests

      ' %> -
      -
      -
      - - - - - - - - - - - - - -
      TestsFunctions
      <% test.testsRun %> run<% test.functionsPassed %> passed
      <% test.testsFailed %> failed<% test.functionsFailed %> failed
      - <% test.results %> -
      -
      - - - - - -<% #result ------------------------------------------------------------------ %> - -

      Results of '<% param.name %>':

      -<% param.log prefix="
      " suffix="
      " %> - - - -<% #item -------------------------------------------------------------------- %> - -
    • - /><% param.name %> -
    • - - - -<% #logFailed --------------------------------------------------------------- %> - -
      Error
      -
      - <% param.functionName prefix='' suffix='()' %> -
      <% param.name suffix=": " %><% param.message %>
      -
      <% param.comment %>
      -
      <% param.fileName prefix="at " %><% param.lineNumber prefix=":" %>
      -
      <% param.stackTrace encoding="html" %>
      -
      - - - -<% #logPassed --------------------------------------------------------------- %> - -
      Passed
      -
      <% param.functionName %>()(in <% param.elapsed %> ms)
      - - - -<% #stylesheet -------------------------------------------------------------- %> - -body { - font-family: Verdana, Arial, Helvetica; - font-size: 0.85em; - margin: 0; - padding: 0; -} - -a { - text-decoration: none; - color: #333; -} - -a:hover { - text-decoration: underline; -} - -div.header { - background-color: #aaa; - border-bottom: 1px solid #333; - font-size: 18px; - font-weight: bold; - color: #ddd; - padding: 10px 20px; -} - -div.header div.title { - float: left; - font-size: 18px; - font-weight: bold; - color: #ddd; -} - -div.header div.directory { - text-align: right; - font-size: 11px; - font-weight: normal; - color: #eee; - padding: 5px; -} - -div.main { - margin: 20px; -} - -div.footer { - margin-top: 400px; - padding: 10px 0 10px 20px; - clear: both; - background-color: #eee; - font-size: 0.7em; - color: #999; -} - -div.list { - float: left; - width: 200px; - padding-right: 30px; - border-right: 1px solid #ccc; -} - -div.list h4 { - margin: 0; - padding: 0 0 10px 0; - font-size: 1em; -} - -div.list form { - margin: 0; - padding: 0; -} - -div.list ul { - list-style-type: none; - margin: 0; - padding: 0; -} - -div.list ul li { - padding: 0; - margin-top:1px; - font-size: 0.95em; -} - -div.list .submit { - margin: 15px 0 0 0; - padding: 0 10px; - border: 1px solid gray; -} - -div.result { - margin-left: 250px; - padding-left: 20px; -} - -/** statistics **/ - -table.statistics { - xborder: 1px solid black; - border-collapse: collapse; -} - -table.statistics th { - text-align: left; - font-size: 0.9em; -} - -table.statistics td { - padding-right: 15px; - color: #666; -} - -table.statistics span.passed { - color: #009900; - font-weight: bold; -} - -table.statistics span.failed { - color: #cc0000; - font-weight: bold; -} - -/** result formattings **/ - -div.result h4 { - font-size: 1em; - font-weight: bold; - border-top: 1px solid #ccc; - padding-top: 20px; -} - -dt { - float: left; -} - -dt.test { - width: 70px; - padding: 2px 10px; -} - -dt.passed { - background-color:#33cc33; - font-size: 0.9em; -} - -dt.error { - background-color:#cc0000; - color: #efefef; - font-size: 0.9em; -} - -dd { - font-size: 0.95em; - margin: 0 0 10px 100px; - padding: 2px; -} - - -span.title, span.function { - width: 200px; - padding-right:10px; -} - -span.function { - font-style: italic; -} - -span.elapsed { - font-size: 0.9em; -} diff --git a/modules/jala/util/Test/code/subethasmtp-smtp-1.2.jar b/modules/jala/util/Test/code/subethasmtp-smtp-1.2.jar deleted file mode 100644 index 3af4aa44..00000000 Binary files a/modules/jala/util/Test/code/subethasmtp-smtp-1.2.jar and /dev/null differ diff --git a/modules/jala/util/Test/code/subethasmtp-wiser-1.2.jar b/modules/jala/util/Test/code/subethasmtp-wiser-1.2.jar deleted file mode 100644 index 200cf39e..00000000 Binary files a/modules/jala/util/Test/code/subethasmtp-wiser-1.2.jar and /dev/null differ diff --git a/modules/jala/util/Test/code/subethasmtp.license.txt b/modules/jala/util/Test/code/subethasmtp.license.txt deleted file mode 100644 index 8b3eb3ad..00000000 --- a/modules/jala/util/Test/code/subethasmtp.license.txt +++ /dev/null @@ -1,204 +0,0 @@ -SubEthaSMTP - A SMTP mail server -Copyright (C) 2006-2007 SubEthaMail.org - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/modules/jala/util/Test/docs/Root.html b/modules/jala/util/Test/docs/Root.html deleted file mode 100644 index 22ffee06..00000000 --- a/modules/jala/util/Test/docs/Root.html +++ /dev/null @@ -1,302 +0,0 @@ - - - - - -Root - - - - - - - - - - - - - - - - - - - - - -
      -Jala Test - -
      - -
      - - -

      Class Root

      -
      Object
      -   |
      -   +--Root
      -
      - - -
      -
      - -
      class - Root - - -
      - -
      - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - -
      -Method Summary
      - -  void - - - - - jala_test_action() - -
      -            - Test runner -
      - -  void - - - - - jala_test_css_action() - -
      -            - External stylesheet for test runner -
      - - - -

      - - - - - - - - - - - - - - - - - -


      - - - - - - - - - - - - -
      - Method Detail -
      - - - - -

      jala_test_action

      -
      void jala_test_action()
      - -
        Test runner
      - - - - - - - - - - - -
      - - -

      jala_test_css_action

      -
      void jala_test_css_action()
      - -
        External stylesheet for test runner
      - - - - - - - - - - - -
      - - - - - - - - - - - - - - - - - - - - - - -
      -Jala Test - -
      - - - -
      - - - -
      Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
      - - diff --git a/modules/jala/util/Test/docs/allclasses-frame.html b/modules/jala/util/Test/docs/allclasses-frame.html deleted file mode 100644 index 277e728e..00000000 --- a/modules/jala/util/Test/docs/allclasses-frame.html +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - All Classes - - - - - - -

      - -All Classes -
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      jala -
      -
      jala.Test -
      -
      jala.Test.ArgumentsException -
      -
      jala.Test.DatabaseMgr -
      -
      jala.Test.EvaluatorException -
      -
      jala.Test.Exception -
      -
      jala.Test.HttpClient -
      -
      jala.Test.SmtpServer -
      -
      jala.Test.SmtpServer.Message -
      -
      jala.Test.TestException -
      -
      jala.Test.TestFunctionResult -
      -
      jala.Test.TestResult -
      -
      Root -
      -
      - - - diff --git a/modules/jala/util/Test/docs/allclasses-noframe.html b/modules/jala/util/Test/docs/allclasses-noframe.html deleted file mode 100644 index 7c79845a..00000000 --- a/modules/jala/util/Test/docs/allclasses-noframe.html +++ /dev/null @@ -1,106 +0,0 @@ - - - - -Jala Test All Classes - - - - - - -

      Jala Test

      - -All Classes -
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      jala -
      -
      jala.Test -
      -
      jala.Test.ArgumentsException -
      -
      jala.Test.DatabaseMgr -
      -
      jala.Test.EvaluatorException -
      -
      jala.Test.Exception -
      -
      jala.Test.HttpClient -
      -
      jala.Test.SmtpServer -
      -
      jala.Test.SmtpServer.Message -
      -
      jala.Test.TestException -
      -
      jala.Test.TestFunctionResult -
      -
      jala.Test.TestResult -
      -
      Root -
      -
      - - - diff --git a/modules/jala/util/Test/docs/constant-values.html b/modules/jala/util/Test/docs/constant-values.html deleted file mode 100644 index 519a296e..00000000 --- a/modules/jala/util/Test/docs/constant-values.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - -Jala Test Constant Values - - - - - - - - - - - - - - - - - - -
      -Jala Test - -
      - - -
      -

      Constant Field Values

      -
      - - -
      - - - - - - - - - - - - - - - - - - - -
      - jala.Test -
      PASSED"passed"
      FAILED"failed"
      -

      - -

      - - -


      - - - - - - - - - - - - - -
      -Jala Test - -
      - - -
      - - - -
      Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
      - - diff --git a/modules/jala/util/Test/docs/help-doc.html b/modules/jala/util/Test/docs/help-doc.html deleted file mode 100644 index 8ecda993..00000000 --- a/modules/jala/util/Test/docs/help-doc.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - -Jala Test API Help - - - - - - - - - - - - - - - - - - -
      -Jala Test - -
      - - -
      -
      -

      -How This API Document Is Organized

      -
      -This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

      -Class

      -
      - -

      -Each class has its own separate page. Each of these pages has three sections consisting of a class description, summary tables, and detailed member descriptions:

        -
      • Class inheritance diagram
      • Direct Subclasses
      • Class declaration
      • Class description -

        -

      • Field Summary
      • Constructor Summary
      • Method Summary -

        -

      • Field Detail
      • Constructor Detail
      • Method Detail
      -Each summary entry contains the first sentence from the detailed description for that item.
      - - -

      -Index

      -
      -The Index contains an alphabetic list of all classes, constructors, methods, and fields.
      -

      -Prev/Next

      -These links take you to the next or previous class, interface, package, or related page.

      -Frames/No Frames

      -These links show and hide the HTML frames. All pages are available with or without frames. -

      - - -This help file applies to API documentation generated using the standard doclet. - -
      -


      - - - - - - - - - - - - - -
      -Jala Test - -
      - - -
      - - - -
      Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
      - - diff --git a/modules/jala/util/Test/docs/index-all.html b/modules/jala/util/Test/docs/index-all.html deleted file mode 100644 index 96b11df9..00000000 --- a/modules/jala/util/Test/docs/index-all.html +++ /dev/null @@ -1,771 +0,0 @@ - - - - - -Index () - - - - - - - - - - - - - - - - - - -
      -Jala Test - -
      - - -A D E F G I J L N P R S T V -
      - - -

      -A

      - -
      -
      argsContainComment(args, argsExpected) - -Class method in class jala.Test -
        -
      - -
      -
      assertEqual(val1, val2) - -Instance method in class jala.Test -
        -
      - -
      -
      assertEqualFile(val, file) - -Instance method in class jala.Test -
        -
      - -
      -
      assertFalse(val) - -Instance method in class jala.Test -
        -
      - -
      -
      assertMatch(val, rxp) - -Instance method in class jala.Test -
        -
      - -
      -
      assertNaN(val) - -Instance method in class jala.Test -
        -
      - -
      -
      assertNotEqual(val1, val2) - -Instance method in class jala.Test -
        -
      - -
      -
      assertNotNaN(val) - -Instance method in class jala.Test -
        -
      - -
      -
      assertNotNull(val) - -Instance method in class jala.Test -
        -
      - -
      -
      assertNotUndefined(val) - -Instance method in class jala.Test -
        -
      - -
      -
      assertNull(val) - -Instance method in class jala.Test -
        -
      - -
      -
      assertStringContains(val, str) - -Instance method in class jala.Test -
        -
      - -
      -
      assertThrows(func, exception) - -Instance method in class jala.Test -
        -
      - -
      -
      assertTrue(val) - -Instance method in class jala.Test -
        -
      - -
      -
      assertUndefined(val) - -Instance method in class jala.Test -
        -
      - -
      - -

      -D

      - -
      -
      databases - -Instance field in class jala.Test.DatabaseMgr -
        -
      - -
      -
      dbSourceProperties - -Instance field in class jala.Test.DatabaseMgr -
        -
      - -
      -
      directory_macro() - -Instance method in class jala.Test -
        -
      - -
      - -

      -E

      - -
      -
      elapsed - -Instance field in class jala.Test.TestFunctionResult -
        -
      - -
      -
      elapsed - -Instance field in class jala.Test.TestResult -
        -
      - -
      -
      evalArguments(args, argsExpected) - -Class method in class jala.Test -
        -
      - -
      -
      execute(what) - -Instance method in class jala.Test -
        -
      - -
      -
      executeRequest(method, url, param) - -Instance method in class jala.Test.HttpClient -
        -
      - -
      -
      executeTest(testFile) - -Instance method in class jala.Test -
        -
      - -
      -
      executeTestFunction(functionName, scope) - -Instance method in class jala.Test -
        -
      - -
      - -

      -F

      - -
      -
      FAILED - -Class field in class jala.Test -
        -
      - -
      -
      functionName - -Instance field in class jala.Test.TestFunctionResult -
        -
      - -
      -
      functionsFailed - -Instance field in class jala.Test -
        -
      - -
      -
      functionsPassed - -Instance field in class jala.Test -
        -
      - -
      - -

      -G

      - -
      -
      getCc() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getClient() - -Instance method in class jala.Test.HttpClient -
        -
      - -
      -
      getComment(args, argsExpected) - -Class method in class jala.Test -
        -
      - -
      -
      getContent() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getContentType() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getCookies() - -Instance method in class jala.Test.HttpClient -
        -
      - -
      -
      getEncoding() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getFrom() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getMessage() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getMessages() - -Instance method in class jala.Test.SmtpServer -
        -
      - -
      -
      getMimeMessage() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getReplyTo() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getStackTrace(trace) - -Class method in class jala.Test -
        -
      - -
      -
      getSubject() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getTestFile(fileName) - -Class method in class jala.Test -
        -
      - -
      -
      getTestFiles() - -Class method in class jala.Test -
        -
      - -
      -
      getTestsDirectory() - -Class method in class jala.Test -
        -
      - -
      -
      getTo() - -Instance method in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      getUrl(url, param) - -Instance method in class jala.Test.HttpClient -
        -
      - -
      -
      getValue(args, argsExpected, idx) - -Class method in class jala.Test -
        -
      - -
      - -

      -I

      - -
      -
      include(scope, file) - -Class method in class jala.Test -
        -
      - -
      - -

      -J

      - -
      -
      jala - - class jala -
        -
      - -
      -
      jala.Test - - class jala.Test -
        -
      - -
      -
      jala.Test() - -Constructor in class jala.Test -
        -
      - -
      -
      jala.Test.ArgumentsException - - class jala.Test.ArgumentsException -
        -
      - -
      -
      jala.Test.ArgumentsException(message) - -Constructor in class jala.Test.ArgumentsException -
        -
      - -
      -
      jala.Test.DatabaseMgr - - class jala.Test.DatabaseMgr -
        -
      - -
      -
      jala.Test.DatabaseMgr() - -Constructor in class jala.Test.DatabaseMgr -
        -
      - -
      -
      jala.Test.EvaluatorException - - class jala.Test.EvaluatorException -
        -
      - -
      -
      jala.Test.EvaluatorException(message, exception) - -Constructor in class jala.Test.EvaluatorException -
        -
      - -
      -
      jala.Test.Exception - - class jala.Test.Exception -
        -
      - -
      -
      jala.Test.Exception() - -Constructor in class jala.Test.Exception -
        -
      - -
      -
      jala.Test.HttpClient - - class jala.Test.HttpClient -
        -
      - -
      -
      jala.Test.HttpClient() - -Constructor in class jala.Test.HttpClient -
        -
      - -
      -
      jala.Test.SmtpServer - - class jala.Test.SmtpServer -
        -
      - -
      -
      jala.Test.SmtpServer(port) - -Constructor in class jala.Test.SmtpServer -
        -
      - -
      -
      jala.Test.SmtpServer.Message - - class jala.Test.SmtpServer.Message -
        -
      - -
      -
      jala.Test.SmtpServer.Message(message) - -Constructor in class jala.Test.SmtpServer.Message -
        -
      - -
      -
      jala.Test.TestException - - class jala.Test.TestException -
        -
      - -
      -
      jala.Test.TestException(comment, message) - -Constructor in class jala.Test.TestException -
        -
      - -
      -
      jala.Test.TestFunctionResult - - class jala.Test.TestFunctionResult -
        -
      - -
      -
      jala.Test.TestFunctionResult(functionName, startTime) - -Constructor in class jala.Test.TestFunctionResult -
        -
      - -
      -
      jala.Test.TestResult - - class jala.Test.TestResult -
        -
      - -
      -
      jala.Test.TestResult(testFileName) - -Constructor in class jala.Test.TestResult -
        -
      - -
      -
      jala_test_action() - -Instance method in class Root -
        -
      - -
      -
      jala_test_css_action() - -Instance method in class Root -
        -
      - -
      - -

      -L

      - -
      -
      list_macro() - -Instance method in class jala.Test -
        -
      - -
      -
      log - -Instance field in class jala.Test.TestResult -
        -
      - -
      - -

      -N

      - -
      -
      name - -Instance field in class jala.Test.TestResult -
        -
      - -
      - -

      -P

      - -
      -
      PASSED - -Class field in class jala.Test -
        -
      - -
      - -

      -R

      - -
      -
      renderResult(result) - -Instance method in class jala.Test -
        -
      - -
      -
      renderResults() - -Instance method in class jala.Test -
        -
      - -
      -
      results - -Instance field in class jala.Test -
        -
      - -
      -
      results_macro() - -Instance method in class jala.Test -
        -
      - -
      -
      Root - - class Root -
        -
      - -
      - -

      -S

      - -
      -
      setCookies(arr) - -Instance method in class jala.Test.HttpClient -
        -
      - -
      -
      start() - -Instance method in class jala.Test.SmtpServer -
        -
      - -
      -
      startDatabase(dbSourceName, copyTables, tables) - -Instance method in class jala.Test.DatabaseMgr -
        -
      - -
      -
      status - -Instance field in class jala.Test.TestResult -
        -
      - -
      -
      stop() - -Instance method in class jala.Test.SmtpServer -
        -
      - -
      -
      stopAll() - -Instance method in class jala.Test.DatabaseMgr -
        -
      - -
      -
      submitForm(url, param) - -Instance method in class jala.Test.HttpClient -
        -
      - -
      - -

      -T

      - -
      -
      testsFailed - -Instance field in class jala.Test -
        -
      - -
      -
      testsRun - -Instance field in class jala.Test -
        -
      - -
      -
      toString() - -Instance method in class jala.Test.DatabaseMgr -
        -
      - -
      - -

      -V

      - -
      -
      valueToString(val) - -Class method in class jala.Test -
        -
      - -
      - -A D E F G I J L N P R S T V - - - - - - - - - - - - - - -
      -Jala Test - -
      - - -
      - - - -
      Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
      - - diff --git a/modules/jala/util/Test/docs/index.html b/modules/jala/util/Test/docs/index.html deleted file mode 100644 index 8a7b7ade..00000000 --- a/modules/jala/util/Test/docs/index.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - -Generated Javascript Documentation - - - - - - - - - - - - - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to <A HREF="allclasses-frame.html">Non-frame version.</A> - diff --git a/modules/jala/util/Test/docs/jala.Test.ArgumentsException.html b/modules/jala/util/Test/docs/jala.Test.ArgumentsException.html deleted file mode 100644 index a0393e46..00000000 --- a/modules/jala/util/Test/docs/jala.Test.ArgumentsException.html +++ /dev/null @@ -1,276 +0,0 @@ - - - - - -jala.Test.ArgumentsException - - - - - - - - - - - - - - - - - - - - - -
      -Jala Test - -
      - -
      - - -

      Class jala.Test.ArgumentsException

      -
      Object
      -   |
      -   +--jala.Test.Exception
      -         |
      -         +--jala.Test.ArgumentsException
      -
      - - -
      -
      - -
      class - jala.Test.ArgumentsException - -
      extends jala.Test.Exception - - -
      - -

      -
      Instances of this exception are thrown whenever an assertion - function is called with incorrect or insufficient arguments -
      Defined in Global/jala.Test.js

      -

      - -
      - - - - - - - - - - - - - - - - - - - - - - - - -
      -Constructor Summary
      - - - jala.Test.ArgumentsException - - (<String> message) - -
      -             - Creates a new ArgumentsException instance -
      - - - -  - - - - - -

      - - - - - - - - - - - - - - - -
      - Constructor Detail -
      - -

      -jala.Test.ArgumentsException

      -
      jala.Test.ArgumentsException(<String> message)
      - - -
        - Creates a new ArgumentsException instance -
      - - - -
        - Parameters: - -
          message - The failure message -
        - - -
      - - - - -
        - Returns: -
          - A newly created ArgumentsException instance -
        -
      - - - - - -
      - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      -Jala Test - -
      - - - -
      - - - -
      Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
      - - diff --git a/modules/jala/util/Test/docs/jala.Test.DatabaseMgr.html b/modules/jala/util/Test/docs/jala.Test.DatabaseMgr.html deleted file mode 100644 index ee77071e..00000000 --- a/modules/jala/util/Test/docs/jala.Test.DatabaseMgr.html +++ /dev/null @@ -1,486 +0,0 @@ - - - - - -jala.Test.DatabaseMgr - - - - - - - - - - - - - - - - - - - - - -
      -Jala Test - -
      - -
      - - -

      Class jala.Test.DatabaseMgr

      -
      Object
      -   |
      -   +--jala.Test.DatabaseMgr
      -
      - - -
      -
      - -
      class - jala.Test.DatabaseMgr - - -
      - -

      -
      Instances of this class allow managing test databases - and switching a running application to an in-memory test - database to use within a unit test. -
      Defined in Global/jala.Test.js

      -

      - -
      - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      - Field Summary
      -  Objectdatabases -
      -           Map containing all test databases
      -  ObjectdbSourceProperties -
      -           Map containing the original datasource - properties that were temporarily deactivated - by activating a test database
      -   - - - - - - - - - - - - - - - - - -
      -Constructor Summary
      - - - jala.Test.DatabaseMgr - - () - -
      -             - Returns a newly created DatabaseMgr instance -
      - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -
      -Method Summary
      - -  jala.db.RamDatabase - - - - - startDatabase(<String> dbSourceName, <Boolean> copyTables, <Array> tables) - -
      -            - Switches the application datasource with the given name - to a newly created in-memory database. -
      - -  void - - - - - stopAll() - -
      -            - Stops all registered test databases and and reverts the application - to its original datasource(s) as defined in db.properties file. -
      - -  Object - - - - - toString() - -
      -            - -
      - - - -

      - - - - - - - - - - -
      Field Detail
      - - - -

      databases

      -
      Object databases
      -
        - Map containing all test databases - -
      -
      - - -

      dbSourceProperties

      -
      Object dbSourceProperties
      -
        - Map containing the original datasource - properties that were temporarily deactivated - by activating a test database - -
      -
      - - - - - - - - - - - - -
      - Constructor Detail -
      - -

      -jala.Test.DatabaseMgr

      -
      jala.Test.DatabaseMgr()
      - - -
        - Returns a newly created DatabaseMgr instance -
      - - - -
    - - - - -
      - Returns: -
        - A newly created instance of DatabaseMgr -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    startDatabase

    -
    jala.db.RamDatabase startDatabase(<String> dbSourceName, <Boolean> copyTables, <Array> tables)
    - -
      Switches the application datasource with the given name - to a newly created in-memory database. In addition this method - also clears the application cache and invalidates the root - object to ensure that everything is re-retrieved from the - test database. - This method can be called with a second boolean argument indicating - that tables used by the application should be created in the in-memory - database (excluding any data).
    - - - - -
      - Parameters: - -
        dbSourceName - The name of the application database source as defined in db.properties -
      - -
        copyTables - If true this method also copies all tables in the source database to the test database (excluding indexes). -
      - -
        tables - An optional array containing table names that should be created in the test database. If not specified this method collects all tables that are mapped in the application. -
      - -
    - - - - -
      - Returns: -
        - The test database -
      -
    - - - - - -
    - - -

    stopAll

    -
    void stopAll()
    - -
      Stops all registered test databases and and reverts the application - to its original datasource(s) as defined in db.properties file. - In addition this method commits all pending changes within the request, - cleares the application cache and invalidates the root object - to ensure no traces of the test database are left behind.
    - - - - - - - - - - - -
    - - -

    toString

    -
    Object toString()
    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.Test.EvaluatorException.html b/modules/jala/util/Test/docs/jala.Test.EvaluatorException.html deleted file mode 100644 index d6b8fbb1..00000000 --- a/modules/jala/util/Test/docs/jala.Test.EvaluatorException.html +++ /dev/null @@ -1,279 +0,0 @@ - - - - - -jala.Test.EvaluatorException - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala.Test.EvaluatorException

    -
    Object
    -   |
    -   +--jala.Test.Exception
    -         |
    -         +--jala.Test.EvaluatorException
    -
    - - -
    -
    - -
    class - jala.Test.EvaluatorException - -
    extends jala.Test.Exception - - -
    - -

    -
    Instances of this exception are thrown when attempt - to evaluate the test code fails. -
    Defined in Global/jala.Test.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Test.EvaluatorException - - (<String> message, <String> exception) - -
    -             - Creates a new EvaluatorException instance -
    - - - -  - - - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Test.EvaluatorException

    -
    jala.Test.EvaluatorException(<String> message, <String> exception)
    - - -
      - Creates a new EvaluatorException instance -
    - - - -
      - Parameters: - -
        message - The failure message, or an Error previously thrown. -
      - -
        exception - An optional nested Error -
      - - -
    - - - - -
      - Returns: -
        - A newly created EvaluatorException instance -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.Test.Exception.html b/modules/jala/util/Test/docs/jala.Test.Exception.html deleted file mode 100644 index 8145120c..00000000 --- a/modules/jala/util/Test/docs/jala.Test.Exception.html +++ /dev/null @@ -1,272 +0,0 @@ - - - - - -jala.Test.Exception - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala.Test.Exception

    -
    Object
    -   |
    -   +--jala.Test.Exception
    -
    - -
    -
    - Direct Known Subclasses: -
    - jala.Test.EvaluatorException, jala.Test.ArgumentsException, jala.Test.TestException -
    -
    - - -
    -
    - -
    class - jala.Test.Exception - - -
    - -

    -
    Base exception class -
    Defined in Global/jala.Test.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Test.Exception - - () - -
    -             - Creates a new Exception instance -
    - - - -  - - - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Test.Exception

    -
    jala.Test.Exception()
    - - -
      - Creates a new Exception instance -
    - - - - - - - - -
      - Returns: -
        - A newly created Exception instance -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.Test.HttpClient.html b/modules/jala/util/Test/docs/jala.Test.HttpClient.html deleted file mode 100644 index cbdc5838..00000000 --- a/modules/jala/util/Test/docs/jala.Test.HttpClient.html +++ /dev/null @@ -1,593 +0,0 @@ - - - - - -jala.Test.HttpClient - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala.Test.HttpClient

    -
    Object
    -   |
    -   +--jala.Test.HttpClient
    -
    - - -
    -
    - -
    class - jala.Test.HttpClient - - -
    - -

    -
    Instances of this class represent a http client useable for - testing, as any session cookies received by the tested application - are stored and used for subsequent requests, allowing simple "walkthrough" - tests. -
    Defined in Global/jala.Test.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Test.HttpClient - - () - -
    -             - Constructs a new HttpClient instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Object - - - - - executeRequest(<String> method, <String> url, <Object> param) - -
    -            - Sends a HTTP request to the Url passed as argument -
    - -  helma.Http - - - - - getClient() - -
    -            - Returns the http client used -
    - -  Array - - - - - getCookies() - -
    -            - Returns the cookies set for this http client -
    - -  Object - - - - - getUrl(<String> url, <Object> param) - -
    -            - Convenience method for requesting the url passed as argument - using method GET -
    - -  void - - - - - setCookies(<Array> arr) - -
    -            - Sets the cookie to use for subsequent requests using this client -
    - -  Object - - - - - submitForm(<String> url, <Object> param) - -
    -            - Convenience method for submitting a form. -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Test.HttpClient

    -
    jala.Test.HttpClient()
    - - -
      - Constructs a new HttpClient instance -
    - - - - - - - - -
      - Returns: -
        - A newly constructed HttpClient -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    executeRequest

    -
    Object executeRequest(<String> method, <String> url, <Object> param)
    - -
      Sends a HTTP request to the Url passed as argument
    - - - - -
      - Parameters: - -
        method - The HTTP method to use -
      - -
        url - The url to request -
      - -
        param - A parameter object to use with this request -
      - -
    - - - - -
      - Returns: -
        - An object containing response values -
      -
    - - - - -
      - See:
        - helma.Http.prototype.getUrl
      -
    - - -
    - - -

    getClient

    -
    helma.Http getClient()
    - -
      Returns the http client used
    - - - - - - - -
      - Returns: -
        - The http client used -
      -
    - - - - - -
    - - -

    getCookies

    -
    Array getCookies()
    - -
      Returns the cookies set for this http client
    - - - - - - - -
      - Returns: -
        - The cookies to use for subsequent requests -
      -
    - - - - - -
    - - -

    getUrl

    -
    Object getUrl(<String> url, <Object> param)
    - -
      Convenience method for requesting the url passed as argument - using method GET
    - - - - -
      - Parameters: - -
        url - The url to request -
      - -
        param - A parameter object to use with this request -
      - -
    - - - - -
      - Returns: -
        - An object containing response values -
      -
    - - - - -
      - See:
        - helma.Http.prototype.getUrl
      -
    - - -
    - - -

    setCookies

    -
    void setCookies(<Array> arr)
    - -
      Sets the cookie to use for subsequent requests using this client
    - - - - -
      - Parameters: - -
        arr - The cookie object as received from helma.Http.getUrl -
      - -
    - - - - - - - - -
    - - -

    submitForm

    -
    Object submitForm(<String> url, <Object> param)
    - -
      Convenience method for submitting a form.
    - - - - -
      - Parameters: - -
        url - The url to request -
      - -
        param - A parameter object to use with this request -
      - -
    - - - - -
      - Returns: -
        - An object containing response values -
      -
    - - - - -
      - See:
        - helma.Http.prototype.getUrl
      -
    - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.Test.SmtpServer.Message.html b/modules/jala/util/Test/docs/jala.Test.SmtpServer.Message.html deleted file mode 100644 index 1093292f..00000000 --- a/modules/jala/util/Test/docs/jala.Test.SmtpServer.Message.html +++ /dev/null @@ -1,705 +0,0 @@ - - - - - -jala.Test.SmtpServer.Message - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala.Test.SmtpServer.Message

    -
    Object
    -   |
    -   +--jala.Test.SmtpServer.Message
    -
    - - -
    -
    - -
    class - jala.Test.SmtpServer.Message - - -
    - -

    -
    Instances of this class represent a mail message received - by the SMTP server -
    Defined in Global/jala.Test.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Test.SmtpServer.Message - - (<org.subethamail.wiser.WiserMessage> message) - -
    -             - Creates a new Mail instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Array - - - - - getCc() - -
    -            - Returns an array containing all CC recipients of this mail -
    - -  Object - - - - - getContent() - -
    -            - Returns the content of this mail -
    - -  String - - - - - getContentType() - -
    -            - Returns the content type of this mail as defined in the "Content-Type" - header field -
    - -  String - - - - - getEncoding() - -
    -            - Returns the encoding of this mail as defined in the "Content-Transfer-Encoding" - header field -
    - -  Array - - - - - getFrom() - -
    -            - Returns an array containing all senders of this mail -
    - -  org.subethamail.wiser.WiserMessage - - - - - getMessage() - -
    -            - Returns the wrapped message -
    - -  javax.mail.internet.MimeMessage - - - - - getMimeMessage() - -
    -            - Returns the wrapped message as MimeMessage -
    - -  Array - - - - - getReplyTo() - -
    -            - Returns an array with all reply-to addresses of this mail -
    - -  String - - - - - getSubject() - -
    -            - Returns the subject of this mail -
    - -  Array - - - - - getTo() - -
    -            - Returns an array containing all recipients of this mail -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Test.SmtpServer.Message

    -
    jala.Test.SmtpServer.Message(<org.subethamail.wiser.WiserMessage> message)
    - - -
      - Creates a new Mail instance -
    - - - -
      - Parameters: - -
        message - The message as received by the SMTP server -
      - - -
    - - - - -
      - Returns: -
        - A newly created Mail instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    getCc

    -
    Array getCc()
    - -
      Returns an array containing all CC recipients of this mail
    - - - - - - - -
      - Returns: -
        - An array with all CC recipients of this mail -
      -
    - - - - - -
    - - -

    getContent

    -
    Object getContent()
    - -
      Returns the content of this mail
    - - - - - - - -
      - Returns: -
        - The content of this mail -
      -
    - - - - - -
    - - -

    getContentType

    -
    String getContentType()
    - -
      Returns the content type of this mail as defined in the "Content-Type" - header field
    - - - - - - - -
      - Returns: -
        - The content type of this mail -
      -
    - - - - - -
    - - -

    getEncoding

    -
    String getEncoding()
    - -
      Returns the encoding of this mail as defined in the "Content-Transfer-Encoding" - header field
    - - - - - - - -
      - Returns: -
        - The encoding of this mail -
      -
    - - - - - -
    - - -

    getFrom

    -
    Array getFrom()
    - -
      Returns an array containing all senders of this mail
    - - - - - - - -
      - Returns: -
        - An array with all senders of this mail -
      -
    - - - - - -
    - - -

    getMessage

    -
    org.subethamail.wiser.WiserMessage getMessage()
    - -
      Returns the wrapped message
    - - - - - - - - - - - -
    - - -

    getMimeMessage

    -
    javax.mail.internet.MimeMessage getMimeMessage()
    - -
      Returns the wrapped message as MimeMessage
    - - - - - - - - - - - -
    - - -

    getReplyTo

    -
    Array getReplyTo()
    - -
      Returns an array with all reply-to addresses of this mail
    - - - - - - - -
      - Returns: -
        - An array with all reply-to addresses of this mail -
      -
    - - - - - -
    - - -

    getSubject

    -
    String getSubject()
    - -
      Returns the subject of this mail
    - - - - - - - -
      - Returns: -
        - The subject of this mail -
      -
    - - - - - -
    - - -

    getTo

    -
    Array getTo()
    - -
      Returns an array containing all recipients of this mail
    - - - - - - - -
      - Returns: -
        - An array with all recipients of this mail -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.Test.SmtpServer.html b/modules/jala/util/Test/docs/jala.Test.SmtpServer.html deleted file mode 100644 index c8d06ecc..00000000 --- a/modules/jala/util/Test/docs/jala.Test.SmtpServer.html +++ /dev/null @@ -1,434 +0,0 @@ - - - - - -jala.Test.SmtpServer - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala.Test.SmtpServer

    -
    Object
    -   |
    -   +--jala.Test.SmtpServer
    -
    - - -
    -
    - -
    class - jala.Test.SmtpServer - - -
    - -

    -
    Instances of this class represent an SMTP server listening on - localhost. By default jala.Test will create a global variable called - "smtpServer" that contains an instance of this class. To use the server call - start() in a test method (eg. in the basic setup method) and - stop() in the cleanup method. -
    Defined in Global/jala.Test.js

    -

    - -
    - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.Test.SmtpServer.Message
    -  - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Test.SmtpServer - - (<Number> port) - -
    -             - Creates a new SmtpServer instance -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  Array - - - - - getMessages() - -
    -            - Returns an array containing all mails received by the server, - where each one is an instance of jala.Test.SmtpServer.Message -
    - -  void - - - - - start() - -
    -            - Starts the SMTP server. -
    - -  void - - - - - stop() - -
    -            - Stops the SMTP server and switches the "smtp" property of the tested - application back to the value defined in app or server.properties -
    - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Test.SmtpServer

    -
    jala.Test.SmtpServer(<Number> port)
    - - -
      - Creates a new SmtpServer instance -
    - - - -
      - Parameters: - -
        port - Optional port to listen on (defaults to 25) -
      - - -
    - - - - -
      - Returns: -
        - A newly created SmtpServer instance -
      -
    - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    getMessages

    -
    Array getMessages()
    - - - - - - - - - -
      - Returns: -
        - An array with all messages -
      -
    - - - - - -
    - - -

    start

    -
    void start()
    - -
      Starts the SMTP server. Note that this method switches the SMTP server as - defined in app.properties of the tested application or server.properties - to "localhost" to ensure that all mails sent during tests are received - by this server. The SMTP server definition is switched back to the - original when stop() is called.
    - - - - - - - - - - - -
    - - -

    stop

    -
    void stop()
    - -
      Stops the SMTP server and switches the "smtp" property of the tested - application back to the value defined in app or server.properties
    - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.Test.TestException.html b/modules/jala/util/Test/docs/jala.Test.TestException.html deleted file mode 100644 index 98f158fe..00000000 --- a/modules/jala/util/Test/docs/jala.Test.TestException.html +++ /dev/null @@ -1,279 +0,0 @@ - - - - - -jala.Test.TestException - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala.Test.TestException

    -
    Object
    -   |
    -   +--jala.Test.Exception
    -         |
    -         +--jala.Test.TestException
    -
    - - -
    -
    - -
    class - jala.Test.TestException - -
    extends jala.Test.Exception - - -
    - -

    -
    Instances of this exception are thrown whenever an - assertion function fails -
    Defined in Global/jala.Test.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Test.TestException - - (<String> comment, <String> message) - -
    -             - Creates a new TestException instance -
    - - - -  - - - - - -

    - - - - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Test.TestException

    -
    jala.Test.TestException(<String> comment, <String> message)
    - - -
      - Creates a new TestException instance -
    - - - -
      - Parameters: - -
        comment - An optional comment -
      - -
        message - The failure message -
      - - -
    - - - - -
      - Returns: -
        - A newly created TestException instance -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.Test.TestFunctionResult.html b/modules/jala/util/Test/docs/jala.Test.TestFunctionResult.html deleted file mode 100644 index 44590e95..00000000 --- a/modules/jala/util/Test/docs/jala.Test.TestFunctionResult.html +++ /dev/null @@ -1,332 +0,0 @@ - - - - - -jala.Test.TestFunctionResult - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala.Test.TestFunctionResult

    -
    Object
    -   |
    -   +--jala.Test.TestFunctionResult
    -
    - - -
    -
    - -
    class - jala.Test.TestFunctionResult - - -
    - -

    -
    Instances of this class represent the result of the successful - execution of a single test function (failed executions will be represented - as Exceptions in the log of a test result). -
    Defined in Global/jala.Test.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  Objectelapsed -
    -           
    -  ObjectfunctionName -
    -           
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Test.TestFunctionResult - - (<String> functionName, <Date> startTime) - -
    -             - Constructs a new TestFunctionResult instance -
    - - - -  - - - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    elapsed

    -
    Object elapsed
    -
      - - -
    -
    - - -

    functionName

    -
    Object functionName
    -
      - - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Test.TestFunctionResult

    -
    jala.Test.TestFunctionResult(<String> functionName, <Date> startTime)
    - - -
      - Constructs a new TestFunctionResult instance -
    - - - -
      - Parameters: - -
        functionName - The name of the excecuted test function -
      - -
        startTime - A Date instance marking the begin of the test -
      - - -
    - - - - -
      - Returns: -
        - A new TestFunctionResult instance -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.Test.TestResult.html b/modules/jala/util/Test/docs/jala.Test.TestResult.html deleted file mode 100644 index 9b631c3b..00000000 --- a/modules/jala/util/Test/docs/jala.Test.TestResult.html +++ /dev/null @@ -1,362 +0,0 @@ - - - - - -jala.Test.TestResult - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala.Test.TestResult

    -
    Object
    -   |
    -   +--jala.Test.TestResult
    -
    - - -
    -
    - -
    class - jala.Test.TestResult - - -
    - -

    -
    Instances of this class represent the result of the execution - of a single test file -
    Defined in Global/jala.Test.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  Objectelapsed -
    -           
    -  Objectlog -
    -           
    -  Objectname -
    -           
    -  Objectstatus -
    -           
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Test.TestResult - - (<String> testFileName) - -
    -             - Constructs a new TestResult instance -
    - - - -  - - - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    elapsed

    -
    Object elapsed
    -
      - - -
    -
    - - -

    log

    -
    Object log
    -
      - - -
    -
    - - -

    name

    -
    Object name
    -
      - - -
    -
    - - -

    status

    -
    Object status
    -
      - - -
    -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Test.TestResult

    -
    jala.Test.TestResult(<String> testFileName)
    - - -
      - Constructs a new TestResult instance -
    - - - -
      - Parameters: - -
        testFileName - The name of the excecuted test file -
      - - -
    - - - - -
      - Returns: -
        - A new TestResult instance -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.Test.html b/modules/jala/util/Test/docs/jala.Test.html deleted file mode 100644 index 73a857e7..00000000 --- a/modules/jala/util/Test/docs/jala.Test.html +++ /dev/null @@ -1,2008 +0,0 @@ - - - - - -jala.Test - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala.Test

    -
    Object
    -   |
    -   +--jala.Test
    -
    - - -
    -
    - -
    class - jala.Test - - -
    - -

    -
    Provides various methods for automated tests. - This is essentially a port of JSUnit (http://www.edwardh.com/jsunit/) - suitable for testing Helma applications. -
    Defined in Global/jala.Test.js

    -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.Test.Exception
    - <static class>jala.Test.TestException
    - <static class>jala.Test.ArgumentsException
    - <static class>jala.Test.EvaluatorException
    - <static class>jala.Test.TestResult
    - <static class>jala.Test.TestFunctionResult
    - <static class>jala.Test.HttpClient
    - <static class>jala.Test.DatabaseMgr
    - <static class>jala.Test.SmtpServer
    -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - Field Summary
    -  NumberfunctionsFailed -
    -           Contains the number of test functions that failed
    -  NumberfunctionsPassed -
    -           Contains the number of test functions that passed
    -  Arrayresults -
    -           An Array containing the results of this Test instance.
    -  BooleantestsFailed -
    -           Contains the number of tests that failed
    -  NumbertestsRun -
    -           Contains the number of tests that were executed
    - <static>  <final> StringFAILED -
    -           Constant indicating "failed" status
    - <static>  <final> StringPASSED -
    -           Constant indicating "passed" status
    -   - - - - - - - - - - - - - - - - - -
    -Constructor Summary
    - - - jala.Test - - () - -
    -             - Constructs a new Test instance. -
    - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - -  void - - - - - assertEqual(<Object> val1, <Object> val2) - -
    -            - Checks if the values passed as arguments are equal. -
    - -  void - - - - - assertEqualFile(<Object> val, <String|helma.File> file) - -
    -            - Checks if the value passed as argument equals the content of a file on disk. -
    - -  void - - - - - assertFalse(<Object> val) - -
    -            - Checks if the value passed as argument is boolean false. -
    - -  void - - - - - assertMatch(<String> val, <RegExp> rxp) - -
    -            - Checks if the regular expression matches the string. -
    - -  void - - - - - assertNaN(<Object> val) - -
    -            - Checks if the value passed as argument is NaN. -
    - -  void - - - - - assertNotEqual(<Object> val1, <Object> val2) - -
    -            - Checks if the values passed as arguments are not equal. -
    - -  void - - - - - assertNotNaN(<Object> val) - -
    -            - Checks if the value passed as argument is not NaN. -
    - -  void - - - - - assertNotNull(<Object> val) - -
    -            - Checks if the value passed as argument is not null. -
    - -  void - - - - - assertNotUndefined(<Object> val) - -
    -            - Checks if the value passed as argument is not undefined. -
    - -  void - - - - - assertNull(<Object> val) - -
    -            - Checks if the value passed as argument is null. -
    - -  void - - - - - assertStringContains(<String> val, <String> str) - -
    -            - Checks if the value passed as argument contains the pattern specified. -
    - -  void - - - - - assertThrows(<Object> func, <Object> exception) - -
    -            - Checks if the function passed as argument throws a defined exception. -
    - -  void - - - - - assertTrue(<Object> val) - -
    -            - Checks if the value passed as argument is boolean true. -
    - -  void - - - - - assertUndefined(<Object> val) - -
    -            - Checks if the value passed as argument is undefined. -
    - -  String - - - - - directory_macro() - -
    -            - Returns the absolute path to the directory containing the tests -
    - -  void - - - - - execute(<String|Array> what) - -
    -            - Main test execution function -
    - -  void - - - - - executeTest(<helma.File> testFile) - -
    -            - Executes a single test file -
    - -  Object - - - - - executeTestFunction(<String> functionName, <helma.scripting.rhino.GlobalObject> scope) - -
    -            - Executes a single test function -
    - -  void - - - - - list_macro() - -
    -            - Renders the list of available tests -
    - -  void - - - - - renderResult(result) - -
    -            - Renders the result of a single test -
    - -  void - - - - - renderResults() - -
    -            - Renders the results of all tests done by this test instance - to response. -
    - -  void - - - - - results_macro() - -
    -            - Renders the test results -
    - - <static> Boolean - - - - - argsContainComment(<Array> args, <Number> argsExpected) - -
    -            - Returns true if the arguments array passed as argument - contains an additional comment. -
    - - <static> Boolean - - - - - evalArguments(<Object> args, argsExpected) - -
    -            - -
    - - <static> String - - - - - getComment(<Array> args, argsExpected) - -
    -            - Cuts out the comment from the arguments array passed - as argument and returns it. -
    - - <static> String - - - - - getStackTrace(<java.lang.StackTraceElement> trace) - -
    -            - Creates a stack trace and parses it for display. -
    - - <static> helma.File - - - - - getTestFile(<String> fileName) - -
    -            - Returns the testfile with the given name -
    - - <static> Array - - - - - getTestFiles() - -
    -            - Returns an array containing the test files located - in the directory. -
    - - <static> helma.File - - - - - getTestsDirectory() - -
    -            - Returns the directory containing the test files. -
    - - <static> Object - - - - - getValue(<Array> args, argsExpected, <Number> idx) - -
    -            - Returns the argument on the index position in the array - passed as arguments. -
    - - <static> void - - - - - include(<Object> scope, file) - -
    -            - Evaluates a javascript file in the global test scope. -
    - - <static> String - - - - - valueToString(val) - -
    -            - Helper method useable for displaying a value -
    - - - -

    - - - - - - - - - - -
    Field Detail
    - - - -

    functionsFailed

    -
    Number functionsFailed
    -
      - Contains the number of test functions that failed - -
    -
    - - -

    functionsPassed

    -
    Number functionsPassed
    -
      - Contains the number of test functions that passed - -
    -
    - - -

    results

    -
    Array results
    -
      - An Array containing the results of this Test instance. - -
    -
    - - -

    testsFailed

    -
    Boolean testsFailed
    -
      - Contains the number of tests that failed - -
    -
    - - -

    testsRun

    -
    Number testsRun
    -
      - Contains the number of tests that were executed - -
    -
    - - -

    FAILED

    -
    <static> <final> String FAILED
    - -
    - - -

    PASSED

    -
    <static> <final> String PASSED
    - -
    - - - - - - - - - - - - -
    - Constructor Detail -
    - -

    -jala.Test

    -
    jala.Test()
    - - -
      - Constructs a new Test instance. -
    - - - -
      - Parameters: - -
        capacity - The capacity of the cache -
      - - -
    - - - - - - - - -
    - - - - - - - - - - - - -
    - Method Detail -
    - - - - -

    assertEqual

    -
    void assertEqual(<Object> val1, <Object> val2)
    - -
      Checks if the values passed as arguments are equal.
    - - - - -
      - Parameters: - -
        val1 - The value that should be compared to the second argument. -
      - -
        val2 - The value that should be compared to the first argument. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertEqualFile

    -
    void assertEqualFile(<Object> val, <String|helma.File> file)
    - -
      Checks if the value passed as argument equals the content of a file on disk.
    - - - - -
      - Parameters: - -
        val - The value that should be compared with the content of the file on disk. -
      - -
        file - Either a file name (including a path), or an instance of helma.File representing the file to use for comparison. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertFalse

    -
    void assertFalse(<Object> val)
    - -
      Checks if the value passed as argument is boolean false.
    - - - - -
      - Parameters: - -
        val - The value that should be boolean false. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertMatch

    -
    void assertMatch(<String> val, <RegExp> rxp)
    - -
      Checks if the regular expression matches the string.
    - - - - -
      - Parameters: - -
        val - The string that should contain the regular expression pattern -
      - -
        rxp - The regular expression that should match the value -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertNaN

    -
    void assertNaN(<Object> val)
    - -
      Checks if the value passed as argument is NaN.
    - - - - -
      - Parameters: - -
        val - The value that should be NaN. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertNotEqual

    -
    void assertNotEqual(<Object> val1, <Object> val2)
    - -
      Checks if the values passed as arguments are not equal.
    - - - - -
      - Parameters: - -
        val1 - The value that should be compared to the second argument. -
      - -
        val2 - The value that should be compared to the first argument. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertNotNaN

    -
    void assertNotNaN(<Object> val)
    - -
      Checks if the value passed as argument is not NaN.
    - - - - -
      - Parameters: - -
        val - The value that should be not NaN. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertNotNull

    -
    void assertNotNull(<Object> val)
    - -
      Checks if the value passed as argument is not null.
    - - - - -
      - Parameters: - -
        val - The value that should be not null. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertNotUndefined

    -
    void assertNotUndefined(<Object> val)
    - -
      Checks if the value passed as argument is not undefined.
    - - - - -
      - Parameters: - -
        val - The value that should be not undefined. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertNull

    -
    void assertNull(<Object> val)
    - -
      Checks if the value passed as argument is null.
    - - - - -
      - Parameters: - -
        val - The value that should be null. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertStringContains

    -
    void assertStringContains(<String> val, <String> str)
    - -
      Checks if the value passed as argument contains the pattern specified.
    - - - - -
      - Parameters: - -
        val - The string that should contain the pattern -
      - -
        str - The string that should be contained -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertThrows

    -
    void assertThrows(<Object> func, <Object> exception)
    - -
      Checks if the function passed as argument throws a defined exception.
    - - - - -
      - Parameters: - -
        func - The function to call -
      - -
        exception - Optional object expected to be thrown when executing the function -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertTrue

    -
    void assertTrue(<Object> val)
    - -
      Checks if the value passed as argument is boolean true.
    - - - - -
      - Parameters: - -
        val - The value that should be boolean true. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    assertUndefined

    -
    void assertUndefined(<Object> val)
    - -
      Checks if the value passed as argument is undefined.
    - - - - -
      - Parameters: - -
        val - The value that should be undefined. -
      - -
    - - - - - - - -
      - Throws:
        - jala.Test.ArgumentsException
        - jala.Test.TestException
      -
    - - -
    - - -

    directory_macro

    -
    String directory_macro()
    - -
      Returns the absolute path to the directory containing the tests
    - - - - - - - -
      - Returns: -
        - The path to the tests directory -
      -
    - - - - - -
    - - -

    execute

    -
    void execute(<String|Array> what)
    - -
      Main test execution function
    - - - - -
      - Parameters: - -
        what - Either the name of a single test file or an array containing the names of several function files that should be executed. -
      - -
    - - - - - - - - -
    - - -

    executeTest

    -
    void executeTest(<helma.File> testFile)
    - -
      Executes a single test file
    - - - - -
      - Parameters: - -
        testFile - The file containing the test to run -
      - -
    - - - - - - - - -
    - - -

    executeTestFunction

    -
    Object executeTestFunction(<String> functionName, <helma.scripting.rhino.GlobalObject> scope)
    - -
      Executes a single test function
    - - - - -
      - Parameters: - -
        functionName - The name of the test function to execute -
      - -
        scope - The scope to execute the test method in -
      - -
    - - - - - - - - -
    - - -

    list_macro

    -
    void list_macro()
    - -
      Renders the list of available tests
    - - - - - - - - - - - -
    - - -

    renderResult

    -
    void renderResult(result)
    - -
      Renders the result of a single test
    - - - - -
      - Parameters: - -
        The - result to render -
      - -
    - - - - - - - - -
    - - -

    renderResults

    -
    void renderResults()
    - -
      Renders the results of all tests done by this test instance - to response.
    - - - - - - - - - - - -
    - - -

    results_macro

    -
    void results_macro()
    - -
      Renders the test results
    - - - - - - - - - - - -
    - - -

    argsContainComment

    -
    <static> Boolean argsContainComment(<Array> args, <Number> argsExpected)
    - -
      Returns true if the arguments array passed as argument - contains an additional comment.
    - - - - -
      - Parameters: - -
        args - The arguments array to check for an existing comment. -
      - -
        argsExpected - The number of arguments expected by the assertion function. -
      - -
    - - - - -
      - Returns: -
        - True if the arguments contain a comment, false otherwise. -
      -
    - - - - - -
    - - -

    evalArguments

    -
    <static> Boolean evalArguments(<Object> args, argsExpected)
    - - - - -
      - Parameters: - -
        args - The arguments array. -
      - -
        nr - The number of arguments to be expected -
      - -
    - - - - -
      - Returns: -
        - True in case the number of arguments matches the expected amount, false otherwise. -
      -
    - - - - - -
    - - -

    getComment

    -
    <static> String getComment(<Array> args, argsExpected)
    - -
      Cuts out the comment from the arguments array passed - as argument and returns it. CAUTION: this actually modifies - the arguments array!
    - - - - -
      - Parameters: - -
        args - The arguments array. -
      - -
    - - - - -
      - Returns: -
        - The comment, if existing. Null otherwise. -
      -
    - - - - - -
    - - -

    getStackTrace

    -
    <static> String getStackTrace(<java.lang.StackTraceElement> trace)
    - -
      Creates a stack trace and parses it for display.
    - - - - -
      - Parameters: - -
        trace - The trace to parse. If not given a stacktrace will be generated -
      - -
    - - - - -
      - Returns: -
        - The parsed stack trace -
      -
    - - - - - -
    - - -

    getTestFile

    -
    <static> helma.File getTestFile(<String> fileName)
    - -
      Returns the testfile with the given name
    - - - - -
      - Parameters: - -
        fileName - The name of the test file -
      - -
    - - - - -
      - Returns: -
        - The test file -
      -
    - - - - - -
    - - -

    getTestFiles

    -
    <static> Array getTestFiles()
    - -
      Returns an array containing the test files located - in the directory.
    - - - - - - - -
      - Returns: -
        - An array containing the names of all test files -
      -
    - - - - - -
    - - -

    getTestsDirectory

    -
    <static> helma.File getTestsDirectory()
    - -
      Returns the directory containing the test files. - The location of the directory is either defined by the - application property "jala.testDir" or expected to be one level - above the application directory (and named "tests")
    - - - - - - - -
      - Returns: -
        - The directory containing the test files -
      -
    - - - - - -
    - - -

    getValue

    -
    <static> Object getValue(<Array> args, argsExpected, <Number> idx)
    - -
      Returns the argument on the index position in the array - passed as arguments. This method respects an optional comment - at the beginning of the arguments array.
    - - - - -
      - Parameters: - -
        args - The arguments to retrieve the non-comment value from. -
      - -
        idx - The index position on which the value to retrieve is to be expected if no comment is existing. -
      - -
    - - - - -
      - Returns: -
        - The non-comment value, or null. -
      -
    - - - - - -
    - - -

    include

    -
    <static> void include(<Object> scope, file)
    - -
      Evaluates a javascript file in the global test scope. This method can be used - to include generic testing code in test files. This method is available as - global method "include" for all test methods
    - - - - -
      - Parameters: - -
        scope - The scope in which the file should be evaluated -
      - -
        fileName - The name of the file to include, including the path -
      - -
    - - - - - - - - -
    - - -

    valueToString

    -
    <static> String valueToString(val)
    - -
      Helper method useable for displaying a value
    - - - - -
      - Parameters: - -
        The - value to render -
      - -
    - - - - -
      - Returns: -
        - The value rendered as string -
      -
    - - - - - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/jala.html b/modules/jala/util/Test/docs/jala.html deleted file mode 100644 index 05de1f60..00000000 --- a/modules/jala/util/Test/docs/jala.html +++ /dev/null @@ -1,225 +0,0 @@ - - - - - -jala - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - -
    - - -

    Class jala

    -
    Object
    -   |
    -   +--jala
    -
    - - -
    -
    - -
    class - jala - - -
    - -
    - - - - - - - - - - - - - - -
    -Nested Class Summary
    - <static class>jala.Test
    -  - - - - - - - - - - - - - - - - -  - - - - - -

    - - - - - - - - - - - - - - - - - -


    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test - -
    - - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/overview-Global_Global.js.html b/modules/jala/util/Test/docs/overview-Global_Global.js.html deleted file mode 100644 index f002fa10..00000000 --- a/modules/jala/util/Test/docs/overview-Global_Global.js.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - Global/Global.js - - - - - - -

    - -Global/Global.js -
    - - - - -
    - - - diff --git a/modules/jala/util/Test/docs/overview-Global_Root.js.html b/modules/jala/util/Test/docs/overview-Global_Root.js.html deleted file mode 100644 index 3edefc66..00000000 --- a/modules/jala/util/Test/docs/overview-Global_Root.js.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - Global/Root.js - - - - - - -

    - -Global/Root.js -
    - - - - -
    - - - diff --git a/modules/jala/util/Test/docs/overview-Global_jala.Test.js.html b/modules/jala/util/Test/docs/overview-Global_jala.Test.js.html deleted file mode 100644 index 2a6b7249..00000000 --- a/modules/jala/util/Test/docs/overview-Global_jala.Test.js.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - Global/jala.Test.js - - - - - - -

    - -Global/jala.Test.js -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    jala.Test -
    -
    jala.Test.ArgumentsException -
    -
    jala.Test.DatabaseMgr -
    -
    jala.Test.EvaluatorException -
    -
    jala.Test.Exception -
    -
    jala.Test.HttpClient -
    -
    jala.Test.SmtpServer -
    -
    jala.Test.SmtpServer.Message -
    -
    jala.Test.TestException -
    -
    jala.Test.TestFunctionResult -
    -
    jala.Test.TestResult -
    -
    - - - diff --git a/modules/jala/util/Test/docs/overview-frame.html b/modules/jala/util/Test/docs/overview-frame.html deleted file mode 100644 index fef01bd7..00000000 --- a/modules/jala/util/Test/docs/overview-frame.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - -Overview () - - - - - - -

    Jala Test

    - - - - -
    - - - - - -
    All Classes -

    - -Files -
    - -Global/jala.Test.js
    - -Global/Root.js
    - -

    - -

    -  - - diff --git a/modules/jala/util/Test/docs/overview-summary-Global_Global.js.html b/modules/jala/util/Test/docs/overview-summary-Global_Global.js.html deleted file mode 100644 index 3eaeafd8..00000000 --- a/modules/jala/util/Test/docs/overview-summary-Global_Global.js.html +++ /dev/null @@ -1,206 +0,0 @@ - - - - -jala.Test Overview - - - - - - - - - - - - - - - - - - -
    - -jala.Test -
    - - -


    -
    - -

    Global/Global.js

    - -
    - - - - -

    Summary

    -

    - - No overview generated for 'Global/Global.js'

    - -

    - -
    - - - - - - - - -
    //
    -// Jala Project [http://opensvn.csie.org/traccgi/jala]
    -//
    -// Copyright 2004 ORF Online und Teletext GmbH
    -//
    -// Licensed under the Apache License, Version 2.0 (the ``License'');
    -// you may not use this file except in compliance with the License.
    -// You may obtain a copy of the License at
    -//
    -//    http://www.apache.org/licenses/LICENSE-2.0
    -//
    -// Unless required by applicable law or agreed to in writing, software
    -// distributed under the License is distributed on an ``AS IS'' BASIS,
    -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    -// See the License for the specific language governing permissions and
    -// limitations under the License.
    -//
    -// $Revision$
    -// $LastChangedBy$
    -// $LastChangedDate$
    -// $HeadURL$
    -//
    -
    -
    -/**
    - * Module dependencies
    - */
    -app.addRepository("modules/core/HopObject.js");
    -app.addRepository("modules/helma/File.js");
    -
    -/**
    - * Test runner
    - */
    -Root.prototype.runner_action = function() {
    -   res.handlers.test = new jala.Test();
    -   if (req.isGet() && req.data.test) {
    -      res.handlers.test.execute(req.data.test);
    -   } else if (req.isPost() && (req.data.test_array || req.data.test)) {
    -      res.handlers.test.execute(req.data.test_array || req.data.test);
    -   }
    -   renderSkin("jala.Test.main");
    -   return;
    -};
    -
    -/**
    - * External stylesheet for test runner
    - */
    -Root.prototype.jala_Test_stylesheet_action = function() {
    -   res.contentType = "text/css";
    -   renderSkin("jala.Test.stylesheet");
    -   return;
    -};
    -
    -
    - - - - - - - - - - - - - - - -
    -jala.Test -
    - - -
    - - - -
    Documentation generated by JSDoc on Mon Feb 12 14:40:38 2007
    - - diff --git a/modules/jala/util/Test/docs/overview-summary-Global_Root.js.html b/modules/jala/util/Test/docs/overview-summary-Global_Root.js.html deleted file mode 100644 index fbee4bcd..00000000 --- a/modules/jala/util/Test/docs/overview-summary-Global_Root.js.html +++ /dev/null @@ -1,151 +0,0 @@ - - - - -Jala Test Overview - - - - - - - - - - - - - - - - - - -
    - -Jala Test -
    - - -
    -
    - -

    Global/Root.js

    - -
    - - - - -

    Summary

    -

    - - No overview generated for 'Global/Root.js'

    - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/overview-summary-Global_jala.Test.js.html b/modules/jala/util/Test/docs/overview-summary-Global_jala.Test.js.html deleted file mode 100644 index 8e23ecac..00000000 --- a/modules/jala/util/Test/docs/overview-summary-Global_jala.Test.js.html +++ /dev/null @@ -1,236 +0,0 @@ - - - - -Jala Test Overview - - - - - - - - - - - - - - - - - - -
    - -Jala Test -
    - - -
    -
    - -

    Global/jala.Test.js

    - -
    - - - - -

    Summary

    -

    - - Fields and methods of the jala.Test class.

    - -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - Class Summary - -
    jala.TestProvides various methods for automated tests.
    jala.Test.ArgumentsExceptionInstances of this exception are thrown whenever an assertion - function is called with incorrect or insufficient arguments -
    jala.Test.DatabaseMgrInstances of this class allow managing test databases - and switching a running application to an in-memory test - database to use within a unit test.
    jala.Test.EvaluatorExceptionInstances of this exception are thrown when attempt - to evaluate the test code fails.
    jala.Test.ExceptionBase exception class -
    jala.Test.HttpClientInstances of this class represent a http client useable for - testing, as any session cookies received by the tested application - are stored and used for subsequent requests, allowing simple "walkthrough" - tests.
    jala.Test.SmtpServerInstances of this class represent an SMTP server listening on - localhost.
    jala.Test.SmtpServer.MessageInstances of this class represent a mail message received - by the SMTP server -
    jala.Test.TestExceptionInstances of this exception are thrown whenever an - assertion function fails -
    jala.Test.TestFunctionResultInstances of this class represent the result of the successful - execution of a single test function (failed executions will be represented - as Exceptions in the log of a test result).
    jala.Test.TestResultInstances of this class represent the result of the execution - of a single test file -
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/overview-summary.html b/modules/jala/util/Test/docs/overview-summary.html deleted file mode 100644 index cd3cb6cb..00000000 --- a/modules/jala/util/Test/docs/overview-summary.html +++ /dev/null @@ -1,178 +0,0 @@ - - - - -Jala Test Overview - - - - - - - - - - - - - - - - - - -
    - -Jala Test -
    - - -
    -
    - -

    Jala Test

    - -
    - - -

    - This document is the API Specification for - Jala Test. -

    - - - -

    Summary

    -

    - - No summary generated for these documents. - -

    - -
    - - - - - - - - - - - - - - - - - -
    - - File Summary - -
    Global/jala.Test.jsFields and methods of the jala.Test class.
    Global/Root.js 
    -
    - - - - - - - - - - - - - - - - - - - - - -
    -Jala Test -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/overview-tree.html b/modules/jala/util/Test/docs/overview-tree.html deleted file mode 100644 index 22e0d0fd..00000000 --- a/modules/jala/util/Test/docs/overview-tree.html +++ /dev/null @@ -1,173 +0,0 @@ - - - - - -Jala Test Class Hierarchy - - - - - - - - - - - - - - - - - - -
    -Jala Test -
    - - -
    -

    Class Hierarchy

    - - - -
    - - - - - - - - - - - - - -
    -Jala Test -
    - - -
    - - - -
    Documentation generated by JSDoc on Tue Jan 8 15:50:17 2008
    - - diff --git a/modules/jala/util/Test/docs/stylesheet.css b/modules/jala/util/Test/docs/stylesheet.css deleted file mode 100644 index 7a35c0c1..00000000 --- a/modules/jala/util/Test/docs/stylesheet.css +++ /dev/null @@ -1,39 +0,0 @@ -/* JSDoc style sheet */ - -/* Define colors, fonts and other style attributes here to override the defaults */ - -/* Page background color */ -body { background-color: #FFFFFF } - -/* Table colors */ -.TableHeadingColor { background: #CCCCFF } /* Dark mauve */ -.TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ -.TableRowColor { background: #FFFFFF } /* White */ - -/* Font used in left-hand frame lists */ -.FrameTitleFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } -.FrameHeadingFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } -.FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, san-serif } - -/* Example of smaller, sans-serif font in frames */ -/* .FrameItemFont { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */ - -/* Navigation bar fonts and colors */ -.NavBarCell1 { background-color:#EEEEFF;}/* Light mauve */ -.NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */ -.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} -.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} - -.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} -.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} - -.jsdoc_ctime { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; - text-align: right } - -/* Sourcecode view */ -.sourceview { background: #FFFFFF } -.attrib { color: #DD7777 } -.comment { color: #55AA55 } -.reserved { color: #FF5555 } -.literal { color: #5555FF } - diff --git a/modules/jala/util/Test/tests/selftest.js b/modules/jala/util/Test/tests/selftest.js deleted file mode 100644 index 5e175b6e..00000000 --- a/modules/jala/util/Test/tests/selftest.js +++ /dev/null @@ -1,169 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * Declare which test methods should be run in which order - * @type Array - * @final - */ - -/** - * Test for jala.Test.evalArguments - */ -var testEvalArguments = function testEvalArguments() { - var args; - // test arguments without a comment - args = [true, false, 1, "one", new Date()]; - jala.Test.evalArguments(args, 5); - // test arguments with a comment - args = ["a comment", true, false, 1, "one", new Date()]; - jala.Test.evalArguments(args, 5); - return; -}; - -/** - * Test for jala.Test.containsComment - */ -var testArgsContainComment = function testArgsContainComment() { - var args = ["a comment", true]; - if (jala.Test.argsContainComment(args, 1) !== true) { - throw new jala.Test.TestException(null, - "Argument array is supposed to contain a comment, but doesn't"); - } - return; -}; - -/** - * Test for jala.Test.getComment - */ -var testGetComment = function testGetComment() { - var args = ["a comment", true]; - if (jala.Test.getComment(args, 1) !== args[0]) { - throw new jala.Test.TestException(null, "Couldn't get comment"); - } - return; -}; - -/** - * Test for jala.Test.getValue - */ -var testGetValue = function testGetValue() { - var args = ["a comment", 1, 2, 3]; - if (jala.Test.getValue(args, 3, 1) !== args[2]) { - throw new jala.Test.TestException("Couldn't get correct argument value"); - } - return; -}; - -/** - * Testing assertion functions - */ -var testBasicAssertionFunctions = function testAssertionFunctions() { - assertTrue("just a comment", true); - assertFalse("just a comment", false); - assertEqual(1, 1); - assertEqualArrays("asserting arrays", [1,2,3], [1,2,3]); - assertEqualArrays(["1","2"], ["1","2"]); - assertNotEqual(1, 2); - assertNull(null); - assertNotNull(true); - assertUndefined(undefined); - assertNotUndefined(true); - assertNaN("one"); - assertNotNaN(1); - assertStringContains("just a self test", "self"); - assertMatch("just a self test", /^just/); - return; -}; - -/** - * Testing assertThrows - */ -var testAssertThrows = function testAssertThrows() { - // throw undefined (yes, you can do that...) - assertThrows(function() { - throw undefined; - }, undefined); - // throw custom javascript object - assertThrows(function() { - throw new jala.Test.TestException("", "message"); - }, jala.Test.TestException); - // throw string - assertThrows(function() { - throw "my message"; - }, "my message"); - // throw java exception - assertThrows(function() { - var x = new java.util.Vector(0); - res.debug(x.get(1)); - }, java.lang.ArrayIndexOutOfBoundsException); - // throw anything, but don't check further - assertThrows(function() { - throw new Date(); - }); - // don't throw an expected exception - assertThrows(function() { - assertThrows(function() { - return; - }, "oy"); - }, jala.Test.TestException); - return; -}; - -var testInclude = function() { - var dir = java.lang.System.getProperty("java.io.tmpdir"); - var content = "var INCLUDED = true;"; - // create include file with the above content - var file = new helma.File(dir, "testInclude." + (new Date()).getTime()); - file.open(); - file.write(content); - file.close(); - include(file); - // now include the file and test if everything works - assertTrue(global["INCLUDED"]); - // finally remove the include file again - file.remove(); - return; -}; - -/** - * Testing testAssertEqualFile - */ -var testAssertEqualFile = function testAssertEqualFile() { - var str = "This is just a simple test\r\n"; - var dir = java.lang.System.getProperty("java.io.tmpdir"); - // create test file and write the string into the file - var testFile = new helma.File(dir, "testAssertEqualFile." + (new Date()).getTime()); - testFile.open(); - testFile.write(str); - testFile.close(); - // test string comparison - assertEqualFile(str, testFile); - // test byte array comparison - var arr = new java.lang.String(str).getBytes(); - assertEqualFile(arr, testFile); - // finally, remove testFile again - testFile.remove(); - return; -}; diff --git a/modules/jala/util/Test/tests/skeleton.js b/modules/jala/util/Test/tests/skeleton.js deleted file mode 100644 index 8cd7cf58..00000000 --- a/modules/jala/util/Test/tests/skeleton.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Prefix all test-functions with "test" - */ - -/** - * Called before running the tests - */ -var setup = function() { - return; -}; - -/** - * Called after all tests have finished - */ -var cleanup = function() { - return; -}; diff --git a/modules/jala/util/XmlRpcClient/Global/Feedback.js b/modules/jala/util/XmlRpcClient/Global/Feedback.js deleted file mode 100644 index 98c0a36e..00000000 --- a/modules/jala/util/XmlRpcClient/Global/Feedback.js +++ /dev/null @@ -1,85 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * Error- and Confirmation message container - * @class Instances of this class can contain numerous error- and confirm messages - * and function as a macro handler object. - * @constructor - * @returns A newly created Feedback instance - * @type Feedback - */ -var Feedback = function() { - this.errors = {}; - this.messages = {}; - this.isError = false; - return this; -}; - -/** - * Adds the message with the given name to the list of errors and - * sets the isError flag to true. - * @param {String} name The name of the message - * @param {msg} msg The message to use - */ -Feedback.prototype.setError = function(name, msg) { - this.errors[name] = msg; - this.isError = true; - return; -}; - -/** - * Adds the message with the given name to the list of confirmation messages - * and sets the isError flag to true. - * @param {String} name The name of the message - * @param {msg} msg The message to use - */ -Feedback.prototype.setMessage = function(name, msg) { - this.messages[name] = msg; - return; -}; - -/** - * Returns the message with the given name - * @returns The message with the given name - * @type String - */ -Feedback.prototype.message_macro = function(param) { - if (param.name != null) { - return this.messages[param.name]; - } - return; -}; - -/** - * Returns the error message with the given name - * @returns The error message with the given name - * @type String - */ -Feedback.prototype.error_macro = function(param) { - if (param.name != null) { - return this.errors[param.name]; - } - return; -}; diff --git a/modules/jala/util/XmlRpcClient/Global/Global.js b/modules/jala/util/XmlRpcClient/Global/Global.js deleted file mode 100644 index 1f8c3b3f..00000000 --- a/modules/jala/util/XmlRpcClient/Global/Global.js +++ /dev/null @@ -1,362 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * Dependencies - */ -app.addRepository("modules/core/String.js"); -app.addRepository(getProperty("jala.dir", "modules/jala") + - "/code/XmlRpcRequest.js"); - -/** - * A safe eval method that uses a standard Javascript scope - * without any Helma specifics for evaluation. This method - * does a double evaluation: first it evaluates the code - * in a separate javascript scope without any Helma specifics, and only - * if that doesn't throw an exception it evaluates the expression in the - * application scope, so that objects constructed during evaluation - * belong to the correct scope (and eg. testing with instanceof returns - * the expected result). Keep in mind that due to the double - * evaluation using this method is quite costly. - * @param {String} code The code to evaluate - * @returns The result of the evaluated code - */ -var safeEval = function(code) { - var context = new Packages.org.mozilla.javascript.Context(); - try { - context.enter(); - // first evaluation in separate scope - context.evaluateString(safeEval.SCOPE, code, null, 0, null); - return eval(code); - } finally { - context.exit(); - } -}; -safeEval.SCOPE = Packages.org.mozilla.javascript.Context.getCurrentContext().initStandardObjects(); - -/** - * Returns true if the value passed as argument is a string. Since - * this value might be constructed using the safeEval's scope - * this method tests both the application's scope and the safe one. - * @param {Object} val The value to test - * @returns True if the value is a string, false otherwise - */ -var isString = function(val) { - return typeof(val) == "string" || - val instanceof java.lang.String || - val instanceof String; -}; - -/** - * Returns true if the value passed as argument is a boolean. Since - * this value might be constructed using the safeEval's scope - * this method tests both the application's scope and the safe one. - * @param {Object} val The value to test - * @returns True if the value is a boolean, false otherwise - */ -var isBoolean = function(val) { - return typeof(val) == "boolean" || - val instanceof Boolean; -}; - -/** - * Returns true if the value passed as argument is a number. Since - * this value might be constructed using the safeEval's scope - * this method tests both the application's scope and the safe one. - * @param {Object} val The value to test - * @returns True if the value is a number, false otherwise - */ -var isNumber = function(val) { - return typeof(val) == "number" || - val instanceof java.lang.Integer || - val instanceof Number; -}; - -/** - * Returns true if the value passed as argument is null. - * @param {Object} val The value to test - * @returns True if the value is null, false otherwise - */ -var isNull = function(val) { - return val === null; -}; - -/** - * Returns true if the value passed as argument is undefined. - * @param {Object} val The value to test - * @returns True if the value is undefined, false otherwise - */ -var isUndefined = function(val) { - return val === undefined; -}; - -/** - * Returns true if the value passed as argument is an array. Since - * this value might be constructed using the safeEval's scope - * this method tests both the application's scope and the safe one. - * @param {Object} val The value to test - * @returns True if the value is an array, false otherwise - */ -var isArray = function(val) { - return val instanceof Array; -}; - -/** - * Returns true if the value passed as argument is a date. Since - * this value might be constructed using the safeEval's scope - * this method tests both the application's scope and the safe one. - * @param {Object} val The value to test - * @returns True if the value is a date, false otherwise - */ -var isDate = function(val) { - return val instanceof Date || - val instanceof java.util.Date; -}; - -/** - * Returns true if the value passed as argument is an object. Since - * this value might be constructed using the safeEval's scope - * this method tests both the application's scope and the safe one. - * @param {Object} val The value to test - * @returns True if the value is an object, false otherwise - */ -var isObject = function(val) { - return val instanceof Object || - val instanceof java.lang.Object; -}; - -/** - * Parses the argument string passed into an array containing - * evaluated arguments. The string can contain object and array literals, - * strings, numbers and dates (using standard Javascript syntax). - * @param {String} str The string to parse - * @returns The parsed arguments - * @type Array - */ -var parseArguments = function(str) { - var result = []; - var c, literalLevel = 0; - var buf = new java.lang.StringBuffer(); - for (var i=0;i 0) { - result.push(evalArgument(buf.toString())); - } - return result; -}; - -/** - * Parses a single argument string using the safeEval's method - * eval(). This way users can't do any harm since all they have is - * a plain Javascript environment without any Helma specifics. - * @param {String} str The string to evaluate - * @returns The evaluated argument - */ -var evalArgument = function(str) { - if (str) { - str = str.trim(); - return safeEval("(" + str + ")"); - } - return null; -}; - -/** - * Returns the object passed as argument as formatted JSOn compatible - * string. - * @param {Object} obj The object to format as string - * @returns The formatted string - */ -var prettyPrint = function(obj) { - - var pad = function(str) { - return " ".repeat((lvl) * 6) + str; - }; - - var printString = function(str) { - return '"' + encode(str) + '"'; - }; - - var printInteger = function(nr) { - return nr.toString(); - }; - - var printBoolean = function(bool) { - return bool.toString(); - }; - - var printUndefined = function() { - return "undefined"; - }; - - var printNull = function() { - return "null"; - }; - - var printDate = function(date) { - return date.toString(); - }; - - var printArray = function(arr) { - var buf = new java.lang.StringBuffer(); - buf.append("["); - lvl += 1; - for (var i=0;i 0) { - buf.append(","); - } - buf.append("\n"); - buf.append(pad(printValue(arr[i]))); - } - lvl -= 1; - buf.append("\n"); - buf.append(pad("]")); - return buf.toString(); - }; - - var printObject = function(obj) { - var buf = new java.lang.StringBuffer(); - buf.append("{"); - lvl += 1; - var first = true; - for (var i in obj) { - if (first) { - first = !first; - } else { - buf.append(","); - } - buf.append("\n"); - buf.append(pad(printString(i) + ": ")); - buf.append(printValue(obj[i])); - } - lvl -= 1; - buf.append("\n"); - buf.append(pad("}")); - return buf.toString(); - }; - - var printValue = function(val) { - if (isArray(val)) { - return printArray(val); - } else if (isDate(val)) { - return printDate(val); - } else if (isString(val)) { - return printString(val); - } else if (isNumber(val)) { - return printInteger(val); - } else if (isBoolean(val)) { - return printBoolean(val); - } else if (isNull(val)) { - return printNull(); - } else if (isUndefined(val)) { - return printUndefined(); - } else if (isObject(val)) { - return printObject(val); - } else if (val.toString != null) { - return val.toString(); - } - return; - }; - - var lvl = 0; - return printValue(obj); -}; - -/** - * Returns the xml source passed as argument as readable string - * with appropriate linefeeds and indents. This method uses a - * regular expression instead of converting the xml source into - * a DOM tree to be able to format invalid xml which might be useful - * for debugging. - * @param {String} xmlSource The XML source for format - * @returns The formatted source - */ -var prettyPrintXml = function(xmlSource) { - var pad = function(str) { - res.write(" ".repeat((lvl) * 6) + encode(str)); - }; - - // remove all linefeeds and carriage returns - var xml = xmlSource.replace(/\r\n|\n\r|\n|\r/g, ""); - var re = /<(\/?)([^>]+)[^<]+(?=<|$)/gm; - var lvl = 0; - var match; - var tag, prevTag; - res.push(); - while (match = re.exec(xml)) { - tag = match[2]; - if (!match[1]) { - // opening or contentless tag - if (match.index > 0) { - res.write("\n"); - lvl += 1; - } - pad(match[0]); - if (tag.indexOf("/") > -1) { - lvl -= 1; - } - } else { - // closing tag - if (tag == prevTag) { - lvl -= 1; - res.encode(match[0]); - } else { - res.write("\n"); - pad(match[0]); - lvl -= 1; - } - } - prevTag = tag; - } - return res.pop(); -}; - -/** - * Basic selection macro useable for checkboxes - * and select dropdowns. This macro checks if - * req.data[param.name] equals param.value, and if - * true it writes the specified param.attribute in - * the form 'attribute="attribute"' to response. - */ -var selection_macro = function(param) { - if (req.data[param.name] == param.value) { - res.write(" "); - res.write(param.attribute); - res.write('="'); - res.write(param.attribute); - res.write('"'); - } - return; -}; diff --git a/modules/jala/util/XmlRpcClient/Global/XmlRpcCall.js b/modules/jala/util/XmlRpcClient/Global/XmlRpcCall.js deleted file mode 100644 index 0a216921..00000000 --- a/modules/jala/util/XmlRpcClient/Global/XmlRpcCall.js +++ /dev/null @@ -1,146 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * Wrapper for making XmlRpc calls to remote servers. - * @class Instances of this class can make calls to remote - * XmlRpc servers, plus function as macro handlers for displaying - * results, errors etc. - * @param {String} url The url of the entry-point - * @param {String} methodName The name of the method to call (eg. "xmlrpcclient.echo") - * @param {Array} args An array containing arguments to pass to the remote function - * @returns A newly created XmlRpcCall instance - * @type XmlRpcCall - */ -var XmlRpcCall = function(url, methodName) { - this.request = new jala.XmlRpcRequest(url, methodName); - this.result = null; - return this; -}; - -/** - * Executes the XmlRpc call - */ -XmlRpcCall.prototype.execute = function() { - this.args = arguments; - this.response = jala.XmlRpcRequest.prototype.execute.apply(this.request, arguments); - return; -}; - -/** @ignore */ -XmlRpcCall.prototype.toString = function() { - return "[XmlRpcCall]"; -}; - -/** - * Returns the Url of this XmlRpcCall instance. - * @returns The url of this call - * @type String - */ -XmlRpcCall.prototype.url_macro = function() { - return this.url; -}; - -/** - * Returns the method name of this XmlRpcCall instance. - * @returns The method name of this call - * @type String - */ -XmlRpcCall.prototype.method_macro = function() { - return this.methodName; -}; - -/** - * Displays the arguments of this XmlRpcCall instance. - */ -XmlRpcCall.prototype.arguments_macro = function() { - var arg; - for (var i=0;i'); - res.write('
    ' + i + " "); - if (isArray(arg)) { - res.write("(Array)"); - } else if (isDate(arg)) { - res.write("(Date)"); - } else if (isString(arg)) { - res.write("(String)"); - } else if (isNumber(arg)) { - res.write("(Integer)"); - } else if (isBoolean(arg)) { - res.write("(Boolean)"); - } else if (isNull(arg)) { - res.write("(null)"); - } else if (isUndefined(arg)) { - res.write("(undefined)"); - } else if (isObject(arg)) { - res.write("(Object)"); - } else { - res.write("(unknown type)"); - } - res.write('
    \n
    ');
    -      res.write(prettyPrint(arg));
    -      res.write("
    "); - } - return; -}; - -/** - * Returns the result of this XmlRpcCall instance. - * @returns The result as human readable string - * @type String - */ -XmlRpcCall.prototype.result_macro = function() { - if (this.response.result != null) { - return prettyPrint(this.response.result); - } - return; -}; - -/** - * Returns the error of this XmlRpcCall instance, if any. - * @returns The error string - * @type String - */ -XmlRpcCall.prototype.error_macro = function() { - if (this.response.error != null) { - return this.response.error; - } - return; -}; - -/** - * Displays the xml source of either request or response - * @param {Object} param A parameter object containing the - * macro attributes - */ -XmlRpcCall.prototype.xml_macro = function(param) { - var xml = this.response[param.of + "Xml"]; - if (xml != null) { - res.write("
    ");
    -      res.write(prettyPrintXml(xml));
    -      res.write("
    "); - } - return; -}; diff --git a/modules/jala/util/XmlRpcClient/README b/modules/jala/util/XmlRpcClient/README deleted file mode 100644 index 31fae511..00000000 --- a/modules/jala/util/XmlRpcClient/README +++ /dev/null @@ -1,59 +0,0 @@ -This is the README file for the XmlRpcClient application as part of -version 1.0 of the Jala Javascript Library. - - -About XmlRpcClient ------------------- - -The XmlRpcClient is a small Helma application useful to test and debug XmlRpc -requests. - - -Installation ------------- - -To install the application add the following to the apps.properties file in -your Helma installation directory: - -xmlrpcclient -xmlrpcclient.repository.0 = ./modules/jala/util/XmlRpcClient - - -Usage Instructions ------------------- - -To access the XmlRpcClient point your browser to the URL - -http://your.server.domain[:port]/xmlrpcclient - -(replace "your.server.domain" with the domain of your server, and the ":port" -section with the port number if not 80). Then fill out the form with at least -the URL of the XmlRpc service and the method name (both are required). - -Optionally you can pass various arguments to the remote method using standard -Javascript literal notation, eg.: - -String: "a string" -Number: 1 -Boolean: true|false -Objec: {name: "jala"} -Array: [1, 2, "three", 4] -Date: new Date(2007, 0, 22, 15, 10) - -By default the XmlRpc client uses UTF-8 as encoding for request and response, -which you can change to ISO-8859-1 if necessary. If you select the "Show Xml" -checkbox the result shown will also contain the Xml source of the request and -response, which is useful for debugging. - -At last you can tell the client to use a specific HTTP proxy for the requests, -which you must define in the form "fqdn:port", eg. "my.proxy.com:3128". - - -Contact, Bugs and Feedback --------------------------- - -The Jala Project is currently hosted at https://OpenSVN.csie.org/traccgi/jala/ -providing all necessary information about Subversion access, Ticketing, Releases -etc. - -For immediate contact you can reach the developers via jaladev AT gmail.com. diff --git a/modules/jala/util/XmlRpcClient/Root/Root.js b/modules/jala/util/XmlRpcClient/Root/Root.js deleted file mode 100644 index 11b2eea6..00000000 --- a/modules/jala/util/XmlRpcClient/Root/Root.js +++ /dev/null @@ -1,84 +0,0 @@ -// -// Jala Project [http://opensvn.csie.org/traccgi/jala] -// -// Copyright 2004 ORF Online und Teletext GmbH -// -// Licensed under the Apache License, Version 2.0 (the ``License''); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an ``AS IS'' BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// $Revision$ -// $LastChangedBy$ -// $LastChangedDate$ -// $HeadURL$ -// - - -/** - * Main action - */ -Root.prototype.main_action = function() { - res.handlers.xmlrpc = {}; - res.handlers.feedback = new Feedback(); - if (req.isPost()) { - if (!req.data.url) { - res.handlers.feedback.setError("url", "Please enter the URL of the XmlRpc entry point"); - } - if (!req.data.method) { - res.handlers.feedback.setError("method", "Please specify the method to call"); - } - try { - var args = parseArguments(req.data.args); - } catch (e) { - res.handlers.feedback.setError("arguments", "The method arguments are invalid"); - } - if (!res.handlers.feedback.isError) { - var xmlRpcCall = new XmlRpcCall(req.data.url, req.data.method); - xmlRpcCall.request.setEncoding(req.data.encoding); - xmlRpcCall.request.setProxy(req.data.proxy); - xmlRpcCall.request.setDebug(req.data.debug == 1); - if (app.properties.username != null && app.properties.password != null) { - xmlRpcCall.request.setCredentials(app.properties.username, app.properties.password); - } - XmlRpcCall.prototype.execute.apply(xmlRpcCall, args); - res.handlers.xmlrpc = xmlRpcCall; - } - } - this.renderSkin("main"); - return; -}; - -/** - * Main XmlRpc action. The only supported method name is "echo". - * If no additional arguments are given this action - * returns "echo" to the client. A single additional argument is returned - * as-is, multiple additional arguments are returned as array. - */ -Root.prototype.main_action_xmlrpc = function(methodName) { - switch (methodName) { - case "echo": - if (arguments.length == 1) { - return "echo"; - } else if (arguments.length == 2) { - return arguments[1]; - } else { - var result = []; - for (var i=1;i - - -Jala XmlRpc Client - - - - -
    Jala XmlRpc Client
    -
    -
    -
    <% feedback.error name="url" prefix='
    ' suffix="
    " %>" />
    - Example: http://localhost:8080/xmlrpcclient/
    -
    <% feedback.error name="method" prefix='
    ' suffix="
    " %>" />
    - Example: echo
    -
    <% feedback.error name="arguments" prefix='
    ' suffix="
    " %>" />
    - Example: "eins", 123, true, new Date(), {test: {me: "please"}}, ["a", ["b", "c"]]
    -
    -
    />
    -

    - Example: my.proxy.com:3128
    -

    (* = required)
    - - <% xmlrpc.arguments prefix="
    Arguments" suffix="
    " %> - - <% xmlrpc.error prefix='
    Error' suffix="
    " %> - - <% xmlrpc.result prefix='
    Result
    ' suffix="
    " %> - - <% xmlrpc.xml of="request" prefix="
    Request XML" suffix="
    " %> - - <% xmlrpc.xml of="response" prefix="
    Response XML" suffix="
    " %> - -
    -
    - - \ No newline at end of file diff --git a/modules/tools/Global/helma.Inspector.js b/modules/tools/Global/helma.Inspector.js deleted file mode 100644 index 03a46e2b..00000000 --- a/modules/tools/Global/helma.Inspector.js +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2005 Helma Software. All Rights Reserved. - * - * $RCSfile: helma.Inspector.js,v $ - * $Author: czv $ - * $Revision: 1.5 $ - * $Date: 2006/04/24 11:12:40 $ - */ - -// take care of any dependencies -app.addRepository('modules/core/String.js'); -app.addRepository('modules/core/Number.js'); -app.addRepository('modules/helma/Html.js'); - -if (!global.helma) { - global.helma = {}; -} - -helma.Inspector = function(hopObj) { - if (!hopObj) - hopObj == root; - - var version = "4.0"; - var children = []; - var properties = []; - var collections = []; - - var html = new helma.Html(); - var keySorter = new String.Sorter("key"); - var idSorter = new Number.Sorter("id"); - - var skins = { - child: createSkin(helma.Inspector.child_skin), - collection: createSkin(helma.Inspector.collection_skin), - date: createSkin(helma.Inspector.date_skin), - editor: createSkin(helma.Inspector.editor_skin), - property: createSkin(helma.Inspector.property_skin) - }; - - var genOptions = function(start, end, selected) { - res.push(); - for (var i=start; i<=end; i+=1) { - res.write(""); - if (i < 10) - res.write("0"); - res.write(i); - res.write("\n"); - } - return res.pop(); - }; - - this.render = function() { - for (var i in hopObj) { - var obj = { - key: i, - value: hopObj[i] - }; - if (hopObj[i]) { - if (obj.value._prototype && - obj.value._prototype == "HopObject") - collections.push(obj); - else - properties.push(obj); - } - } - properties.sort(keySorter); - collections.sort(keySorter); - - var n = hopObj.size(); - for (var i=0; i cols="40" rows="1"><% param.value encoding="form" %>
    \ -\ -\ -\ -\ -\ -\ -\ -'; - -HopObject.prototype[ (app.properties['inspectorAction'] || 'inspector') +'_action' ] = function() { - if (!helma.auth('inspector')) - res.abort(); - if (typeof helma == "undefined" || !helma.Inspector) { - res.write("Could not create instance of helma.Inspector "); - res.write("(probably due to missing helmaLib v4.0+)"); - return; - } - var inspector = new helma.Inspector(this); - inspector.action(); - return; -}; - -helma.lib = "Inspector"; -helma.dontEnum(helma.lib); -for (var i in helma[helma.lib]) - helma[helma.lib].dontEnum(i); -for (var i in helma[helma.lib].prototype) - helma[helma.lib].prototype.dontEnum(i); -delete helma.lib; diff --git a/modules/tools/Global/helma.Inspector.main.skin b/modules/tools/Global/helma.Inspector.main.skin deleted file mode 100644 index da240f2c..00000000 --- a/modules/tools/Global/helma.Inspector.main.skin +++ /dev/null @@ -1,157 +0,0 @@ - - - - - -helma.Inspector v<% inspector.version %> - - - - - - -

    <% inspector.title %>

    -
    <% inspector.path %><% inspector.title %>

    - - - - - - - - - - - -
    - - - - -<% inspector.children default='' %> -
    <% inspector.childProto default="child" %> objects
    none
    -
    - - - - -<% inspector.properties %> -
    properties
    -
    - - - - -<% inspector.collections default='' %> -
    collections
    none
    -
    - - - diff --git a/modules/tools/Global/helma.Markup.js b/modules/tools/Global/helma.Markup.js deleted file mode 100644 index 1bad0279..00000000 --- a/modules/tools/Global/helma.Markup.js +++ /dev/null @@ -1,807 +0,0 @@ -/* -* Copyright (C) 2004 Hannes Wallnoefer -*/ - -//////////////////////////////////////////////////////////////////////// -// Html element functions -//////////////////////////////////////////////////////////////////////// - -if (!global.helma) { - global.helma = {}; -} - -helma.Markup = {}; - -helma.Markup.element = function(name, attributes, content) { - if (!name) { - throw "helma.Markup.element called without element name"; - } - // open tag - res.write("<"); - res.write(name); - if (attributes) { - for (var i in attributes) { - if (typeof(attributes[i]) == "undefined") - continue; - res.write(" "); - res.write(i); - res.write("=\""); - res.write(encodeForm(attributes[i])); - res.write("\""); - } - } - // if no child objects create empty element and return - if (typeof(content) == "undefined") { - res.write(" />"); - return; - } - res.write(">"); - - // write content - res.write(content); - - // close tag - res.write(""); -} - -helma.Markup.Element = function(name, attributes, children) { - return new MarkupElement(name, attributes, children); -} - -helma.Markup.form = function(attributes, content) { - this.element("form", attributes, content); -} - -helma.Markup.Form = function(attributes, children) { - return new MarkupElement("form", attributes, children); -} - -helma.Markup.textarea = function(attributes, content) { - this.element("textarea", attributes, encodeForm(content)); -} - -helma.Markup.Textarea = function(attributes, children) { - return new HtmlTextarea(attributes, children); -} - -helma.Markup.input = function(attributes, content) { - this.element("input", attributes, content); -} - -helma.Markup.Input = function(attributes, children) { - return new MarkupElement("input", attributes, children); -} - -helma.Markup.button = function(attributes, content) { - if (!attributes) - attributes = {}; - attributes.type = "button"; - this.element("input", attributes, content); -} - -helma.Markup.Button = function(attributes, children) { - if (!attributes) - attributes = {}; - attributes.type = "button"; - return new MarkupElement("input", attributes, children); -} - -helma.Markup.submit = function(attributes, content) { - if (!attributes) - attributes = {}; - attributes.type = "submit"; - this.element("input", attributes, content); -} - -helma.Markup.Submit = function(attributes, children) { - if (!attributes) - attributes = {}; - attributes.type = "submit"; - return new MarkupElement("input", attributes, children); -} - -helma.Markup.hidden = function(attributes, content) { - if (!attributes) - attributes = {}; - attributes.type = "hidden"; - this.element("input", attributes, content); -} - -helma.Markup.Hidden = function(attributes, children) { - if (!attributes) - attributes = {}; - attributes.type = "hidden"; - return new MarkupElement("input", attributes, children); -} - -helma.Markup.file = function(attributes, content) { - if (!attributes) - attributes = {}; - attributes.type = "file"; - this.element("input", attributes, content); -} - -helma.Markup.File = function(attributes, children) { - if (!attributes) - attributes = {}; - attributes.type = "file"; - return new MarkupElement("input", attributes, children); -} - -helma.Markup.password = function(attributes, content) { - if (!attributes) - attributes = {}; - attributes.type = "password"; - this.element("input", attributes, content); -} - -helma.Markup.Password = function(attributes, children) { - if (!attributes) - attributes = {}; - attributes.type = "password"; - return new MarkupElement("input", attributes, children); -} - -helma.Markup.checkbox = function(attributes, content) { - if (!attributes) - attributes = {}; - attributes.type = "checkbox"; - if (!attributes.checked) - delete(attributes.checked); - this.element("input", attributes, content); -} - -helma.Markup.Checkbox = function(attributes, children) { - if (!attributes) - attributes = {}; - attributes.type = "checkbox"; - if (!attributes.checked) - delete(attributes.checked); - return new MarkupElement("input", attributes, children); -} - -helma.Markup.select = function(attributes, children, selected, firstLine) { - res.write(new HtmlSelect(attributes, children, selected, firstLine)); -} - -helma.Markup.Select = function(attributes, children, selected, firstLine) { - return new HtmlSelect(attributes, children, selected, firstLine); -} - -helma.Markup.head = function(attributes, content) { - this.element("head", attributes, content); -} - -helma.Markup.Head = function(attributes, children) { - return new MarkupElement("head", attributes, children); -} - -helma.Markup.title = function(attributes, content) { - this.element("title", attributes, content); -} - -helma.Markup.Title = function(attributes, children) { - return new MarkupElement("title", attributes, children); -} - -helma.Markup.body = function(attributes, content) { - this.element("body", attributes, content); -} - -helma.Markup.Body = function(attributes, children) { - return new MarkupElement("body", attributes, children); -} - -helma.Markup.div = function(attributes, content) { - this.element("div", attributes, content); -} - -helma.Markup.Div = function(attributes, children) { - return new MarkupElement("div", attributes, children); -} - -helma.Markup.p = function(attributes, content) { - this.element("p", attributes, content); -} - -helma.Markup.P = function(attributes, children) { - return new MarkupElement("p", attributes, children); -} - -helma.Markup.b = function(attributes, content) { - this.element("b", attributes, content); -} - -helma.Markup.B = function(attributes, children) { - return new MarkupElement("b", attributes, children); -} - -helma.Markup.span = function(attributes, content) { - this.element("span", attributes, content); -} - -helma.Markup.Span = function(attributes, children) { - return new MarkupElement("span", attributes, children); -} - -helma.Markup.img = function(attributes) { - this.element("img", attributes); -} - -helma.Markup.Img = function(attributes) { - return new MarkupElement("img", attributes); -} - -helma.Markup.script = function(attributes, content) { - this.element("script", attributes, content); -} - -helma.Markup.Script = function(attributes, children) { - return new MarkupElement("script", attributes, children); -} - -helma.Markup.ul = function(attributes, content) { - this.element("ul", attributes, content); -} - -helma.Markup.Ul = function(attributes, children) { - return new MarkupElement("ul", attributes, children); -} - -helma.Markup.ol = function(attributes, content) { - this.element("ol", attributes, content); -} - -helma.Markup.Ol = function(attributes, children) { - return new MarkupElement("ol", attributes, children); -} - -helma.Markup.li = function(attributes, content) { - this.element("li", attributes, content); -} - -helma.Markup.Li = function(attributes, children) { - return new MarkupElement("li", attributes, children); -} - - -helma.Markup.a = function(attributes, content) { - this.element("a", attributes, content); -} - -helma.Markup.link = helma.Markup.a; - -helma.Markup.A = function(attributes, children) { - return new MarkupElement("a", attributes, children); -} - -helma.Markup.table = function(attributes, content) { - this.element("table", attributes, content); -} - -helma.Markup.Table = function(attributes, children) { - return new MarkupElement("table", attributes, children); -} - -helma.Markup.Colgroup = function(attributes, children) { - return new MarkupElement("colgroup", attributes, children); -} - -helma.Markup.colgroup = function(attributes, content) { - this.element("colgroup", attributes, content); -} - -helma.Markup.Col = function(attributes, children) { - return new MarkupElement("col", attributes, children); -} - -helma.Markup.col = function(attributes, content) { - this.element("col", attributes, content); -} - -helma.Markup.tr = function(attributes, content) { - this.element("tr", attributes, content); -} - -helma.Markup.Tr = function(attributes, children) { - return new MarkupElement("tr", attributes, children); -} - -helma.Markup.th = function(attributes, content) { - this.element("th", attributes, content); -} - -helma.Markup.Th = function(attributes, children) { - return new MarkupElement("th", attributes, children); -} - -helma.Markup.td = function(attributes, content) { - this.element("td", attributes, content); -} - -helma.Markup.Td = function(attributes, children) { - return new MarkupElement("td", attributes, children); -} - -helma.Markup.h1 = function(attributes, content) { - this.element("h1", attributes, content); -} - -helma.Markup.H1 = function(attributes, children) { - return new MarkupElement("h1", attributes, children); -} - -helma.Markup.h2 = function(attributes, content) { - this.element("h2", attributes, content); -} - -helma.Markup.H2 = function(attributes, children) { - return new MarkupElement("h2", attributes, children); -} - -helma.Markup.h3 = function(attributes, content) { - this.element("h3", attributes, content); -} - -helma.Markup.H3 = function(attributes, children) { - return new MarkupElement("h3", attributes, children); -} - -helma.Markup.h4 = function(attributes, content) { - this.element("h4", attributes, content); -} - -helma.Markup.H4 = function(attributes, children) { - return new MarkupElement("h4", attributes, children); -} - -helma.Markup.h5 = function(attributes, content) { - this.element("h5", attributes, content); -} - -helma.Markup.H5 = function(attributes, children) { - return new MarkupElement("h5", attributes, children); -} - -helma.Markup.h6 = function(attributes, content) { - this.element("h6", attributes, content); -} - -helma.Markup.H6 = function(attributes, children) { - return new MarkupElement("h6", attributes, children); -} - -helma.Markup.pre = function(attributes, content) { - this.element("pre", attributes, content); -} - -helma.Markup.Pre = function(attributes, children) { - return new MarkupElement("pre", attributes, children); -} - -helma.Markup.br = function(attributes) { - this.element("br", attributes); -} - -helma.Markup.Br = function(attributes, children) { - return new MarkupElement("br", attributes, children); -} - -helma.Markup.openTag = function(name, attributes) { - if (!name) { - throw "helma.Markup.openTag called without element name"; - } - res.write("<"); - res.write(name); - if (attributes) { - for (var i in attributes) { - if (typeof(attributes[i]) == "undefined") - continue; - res.write(" "); - res.write(i); - res.write("=\""); - res.write(encodeForm(attributes[i])); - res.write("\""); - } - } - res.write(">"); -} - -helma.Markup.closeTag = function(name) { - res.write(""); -} - - -/** - * utility object to provide an easy way - * for programmatically creating an x/html table. - * @param Number the number of columns in the table - * @param Object the table's, its rows' and cells' attributes - * @return Object an instance of TableWriter - */ -helma.Markup.TableWriter = function(numberOfColumns, attr) { - this.ncols = numberOfColumns; - if (isNaN(this.ncols)) - throw "Illegal argument in TableWriter(): first argument must be a number"; - if (this.ncols < 1) - throw "Illegal argument in TableWriter(): first argument must be > 1"; - this.written = 0; - // if no attributes object given, create an empty one - if (!attr) - attr = {}; - if (!attr.trEven) attr.trEven = attr.tr; - if (!attr.trOdd) attr.trOdd = attr.tr; - if (!attr.trHead) attr.trHead = attr.trEven; - if (!attr.tdEven) attr.tdEven = attr.td; - if (!attr.tdOdd) attr.tdOdd = attr.td; - if (!attr.thEven) attr.thEven = attr.th; - if (!attr.thOdd) attr.thOdd = attr.th; - this.attr = attr; - - // write header row? set to true to use "th" tags for first row - this.writeHeader = false; - // write to string buffer rather than response? - this.writeString = false; - - /** - * Write a table cell. - * @param String the table cell content as text - * @param attr an optional attributes holder for the td tag - */ - this.write = function(text, attr) { - // set up some variables - var isHeaderRow = (this.writeHeader && this.written < this.ncols); - var isNewRow = (this.written % this.ncols == 0); - var isEvenRow = ((this.written / this.ncols) % 2 == 0); - var isEvenCol = ((this.written % this.ncols) % 2 == 0); - // write out table and table row tags - if (this.written == 0) { - if (this.writeString) - res.push(); - helma.Markup.openTag("table", this.attr.table); - helma.Markup.openTag("tr", this.attr.trHead); - } else if (isNewRow) { - helma.Markup.closeTag("tr"); - if (isEvenRow) - helma.Markup.openTag("tr", this.attr.trEven); - else - helma.Markup.openTag("tr", this.attr.trOdd); - } - // get the attribute object for the table cell - if (!attr) { - // no explicit attribute given - if (isEvenCol) - attr = isHeaderRow ? this.attr.thEven : this.attr.tdEven; - else - attr = isHeaderRow ? this.attr.thOdd : this.attr.tdOdd; - } - // write out table cell tag - helma.Markup.openTag(isHeaderRow ? "th" : "td", attr); - // write out table cell contents - if (text) - res.write(text); - // close table cell - helma.Markup.closeTag(isHeaderRow ? "th" : "td"); - if (attr && !isNaN(attr.colspan)) - this.written += attr.colspan; - else - this.written += 1; - return; - }; - - /** - * Close all open table tags. - */ - this.close = function() { - if (this.written > 0) { - while (this.written++ % this.ncols != 0) - res.write(""); - res.write(""); - this.written = 0; - } - if (this.writeString) - return res.pop(); - return; - }; - return this; -} - - -//////////////////////////////////////////////////////////////////////// -// MarkupElement is the base class for all elements -//////////////////////////////////////////////////////////////////////// - -/** - * Element constructor. Takes a name, - * a map of attributes and an array of child - * elements as arguments. - */ -function MarkupElement(name, attributes, children) { - if (!attributes) - attributes = {}; - this.attr = attributes; - // if (name && !this._elementName) { - this._elementName = name; - // } else { - if (attributes && attributes.name) { - this.name = attributes.name; - // this.attr.name = name; - } - - this.map = {}; - - this.add(children); - - this.initValueProperty(); -} - -/** - * Add a new child element - */ -MarkupElement.prototype.add = function(child) { - if (typeof(child) == "undefined") { - return; - } - // initialize child array if necessary - if (!this.children) { - this.children = []; - } - if (child instanceof Array) { - for (var i in child) { - this.add(child[i]); - } - return; - } - // add new child - this.children.push(child); - // register child if it has a name property - if (child) { - if (child.name && !this.map[child.name]) { - this.map[child.name] = child; - } - // register grandchilds unless the name slot is already taken - for (var i in child.map) { - var c = child.map[i]; - if (c && c.name && !this.map[c.name]) { - this.map[c.name] = c; - } - } - // set parent property in child - child.parent = this; - } -} - -MarkupElement.prototype.firstChild = function() { - return this.children ? this.children[0] : undefined; -} - -MarkupElement.prototype.lastChild = function() { - return this.children ? this.children[this.children.length - 1] : undefined; -} - - -/** - * Render the element to the response buffer. - */ -MarkupElement.prototype.render = function(writer) { - if (!writer) - writer = res; - - this.processValueProperty(); - // open tag - if (this._elementName) { - writer.write("<"); - writer.write(this._elementName); - for (var i in this.attr) { - if (typeof(this.attr[i]) == "undefined") - continue; - writer.write(" "); - writer.write(i); - writer.write("=\""); - writer.write(encodeForm(this.attr[i])); - writer.write("\""); - } - // render type attribute if set - if (this._type) { - writer.write(" type=\""); - writer.write(this._type); - writer.write("\""); - } - // if no child objects create empty element and return - if (typeof(this.children) == "undefined") { - writer.write(" />"); - return; - } - writer.write(">"); - } - - // write child elements - if (typeof(this.children) != "undefined") { - if (this.children instanceof Array) { - for (var i in this.children) { - if (typeof(this.children[i]) instanceof MarkupElement) { - this.children[i].render(); - } else if (this.children[i]) { - writer.write(this.children[i]); - } - } - } else { - writer.write(this.children); - } - } - - // close tag - if (this._elementName) { - writer.write(""); - } -} - -/** - * Return an object containing the rendered child elements - * of this element keyed by element name. This is suitable - * for rendering the elements of a markup object through - * a skin, using the object returned by this function as macro - * handler. - */ -MarkupElement.prototype.renderMap = function() { - var map = {}; - if (this.children && typeof(this.children) == "object") { - for (var i in this.children) { - if (typeof(this.children[i]) == "object") { - var comp = this.children[i]; - map[comp.name] = comp.toString(); - } - } - } - return map; -} - -/** - * Return an array containing the rendered child elements - * of this element keyed index position. This is suitable - * for those cases where we want to print out a markup - * object's elements programmatically. - */ -MarkupElement.prototype.renderArray = function() { - var list = []; - if (this.children && typeof(this.children) == "object") { - for (var i in this.children) { - if (typeof(this.children[i]) == "object") { - var comp = this.children[i]; - list.push(comp.toString()); - } - } - } - return list; -} - -/** - * Render the element to a string. - */ -MarkupElement.prototype.toString = function() { - res.push(); - this.render(res); - return res.pop(); -} - -/** - * Recursively populate this object and its child objects, - * reading values from the argument object. - */ -MarkupElement.prototype.populate = function(obj) { - // if no object passed populate from req.data - if (!obj) - obj = req.data; - - // set value - if (this.name && this._type != "submit") - this.value = obj[this.name]; - - // populate named child elements - for (var i in this.map) { - if (typeof(this.map[i]) == "object" && this.map[i].populate) { - this.map[i].populate(obj); - } - } -} - -/** - * Recursively validate this element and its child elements. - */ -MarkupElement.prototype.validate = function() { - // apply constraints - if (this.constraints) { - for (var i in this.constraints) { - this.contstraints[i].apply(this); - } - } - - // validate child elements - for (var i in this.map) { - if (typeof(this.map[i]) == "object" && this.map[i].validate) { - this.map[i].validate(); - } - } -} - -/** - * Set up this Element's value property. - */ -MarkupElement.prototype.initValueProperty = function() { - this.value = this.attr.value; -} - -/** - * Process this Element's value property. - */ -MarkupElement.prototype.processValueProperty = function() { - this.attr.value = this.value; -} - -//////////////////////////////////////////////////////////////////////// -// MarkupElement subclasses for Html form elements. -//////////////////////////////////////////////////////////////////////// - - -/** - * Html textarea - */ -function HtmlTextarea(attributes, children) { - this.constructor("textarea", attributes, children); -} -HtmlTextarea.prototype = new MarkupElement("textarea"); - -/** - * Set up this Textarea's value property. - */ -HtmlTextarea.prototype.initValueProperty = function() { - if (typeof(this.attr.value) != "undefined") - this.value = this.attr.value; - else if (this.children && this.children.length > 0) - this.value = this.children[0]; -} - -/** - * Process this Textarea's value property. - */ -HtmlTextarea.prototype.processValueProperty = function() { - this.children = [encodeForm(this.value)]; -} - -/** - * Select list - */ -function HtmlSelect(attributes, children, selectedValue, firstLine) { - var options = []; - if (firstLine) - options.push(new MarkupElement("option", {value: ""}, "")); - if (children instanceof Array) { - for (var i in children) { - var child = children[i]; - var value, display; - if (child instanceof Array && child.length == 2) { - value = child[0]; - display = child[1]; - } else if (child.value != null && child.display != null) { - value = child.value; - display = child.display; - } else { - display = child; - value = i; - } - var attr = {value: value}; - if (value == selectedValue) - attr.selected = "selected"; - options.push(new MarkupElement("option", attr, display)); - } - } - this.constructor("select", attributes, options); -} -HtmlSelect.prototype = new MarkupElement("select"); - diff --git a/modules/tools/Global/helma.auth.js b/modules/tools/Global/helma.auth.js deleted file mode 100644 index 9e2abc50..00000000 --- a/modules/tools/Global/helma.auth.js +++ /dev/null @@ -1,91 +0,0 @@ -if (!global.helma) { - global.helma = {}; -} - -/** - * Performs basic admin level access checking for the specifed realm - * @param String realm for which access should be checked and bootstrapped - * @return true if access id verified, otherwise renders login form with bootstrapping instructions - */ -helma.auth = function(realm) { - - // helper function, checks if the client host matches an allowed host pattern, - // hostnames are converted, wildcards are only allowed in ip-addresses - var hostIsAllowed = function() { - if (!getProperty(realm+'AccessAllowed')) - return true; - else if (getProperty(realm+'AccessAllowed') == 'false') - return false; - var filter = new Packages.helma.util.InetAddressFilter(); - var str = getProperty(realm+'AccessAllowed'); - if (str != null && str != "") { - var arr = str.split(","); - for (var i in arr) { - str = new java.lang.String(arr[i]); - try { - filter.addAddress(str.trim()); - } catch (a) { - try { - str = java.net.InetAddress.getByName(str.trim()).getHostAddress(); - filter.addAddress(str); - } catch (b) { - app.log("error using address " + arr[i] + ": " + b); - } - } - } - } - return filter.matches(java.net.InetAddress.getByName(req.data.http_remotehost)); - } - - // Check if current session is authenticated for this realm - if (session.data[realm+'Authenticated'] && hostIsAllowed()) - return true; - - // Otherwise, guide to properly configure access authentication for this realm - res.data.fontface = 'Trebuchet MS, Verdana, sans-serif'; - res.data.href = path[path.length-1].href(req.action); - var pw = getProperty('adminAccess'); - var param = {}; - var accessAllowed = true; - if (req.data.username && req.data.password) { - if (pw && hostIsAllowed()) { - if (pw == Packages.org.apache.commons.codec.digest.DigestUtils.md5Hex(req.data.username + "-" + req.data.password)) { - session.data[realm+'Authenticated'] = true; - res.redirect(res.data.href); - } else { - param.message = 'Sorry, wrong password!'; - } - } else { - param.message = 'Currently, '+ realm + ' access is not allowed!
    '; - if (!pw) param.message += '\ - The adminAccess property is not set.
    \ - Before proceeding, add the following line to your app.properties or server.properties file:\ -

    adminAccess=' - + Packages.org.apache.commons.codec.digest.DigestUtils.md5Hex(req.data.username + "-" + req.data.password); - else param.message += 'The '+ realm +'AccessAllowed property does not match your host.
    \ - Before proceeding, remove this property from your app.properties or server.properties file \ - or include your host as follows:

    ' - + realm +'AccessAllowed=' + req.data.http_remotehost; - } - } - res.data.header = 'Authentication for '+ realm +' access'; - renderSkin('helma.auth.login', param); - return false; -} -helma.dontEnum('auth'); - -/** - * Invalidates a previously authenticated realm - * @param String realm for which an authentication should be invalidated - * @return true if an authenticated realm was invalidated, otherwise false - */ -helma.invalidate = function(realm) { - if (session.data[realm+'Authenticated']) { - delete session.data[realm+'Authenticated']; - return true; - } - else { - return false; - } -} -helma.dontEnum('invalidate'); diff --git a/modules/tools/Global/helma.auth.login.skin b/modules/tools/Global/helma.auth.login.skin deleted file mode 100644 index 0e519599..00000000 --- a/modules/tools/Global/helma.auth.login.skin +++ /dev/null @@ -1,23 +0,0 @@ - - - -<% response.title %> - - - -<% response.header prefix="

    " suffix="

    " %> -<% param.message prefix="

    " suffix="

    " %> -
    -

    Please enter the administrators username and password to proceed:

    -

    Username:

    -

    Password:

    - -
    - - diff --git a/modules/tools/Global/helma.shell.js b/modules/tools/Global/helma.shell.js deleted file mode 100644 index df1252ea..00000000 --- a/modules/tools/Global/helma.shell.js +++ /dev/null @@ -1,60 +0,0 @@ -if (!global.helma) { - global.helma = {}; -} - -/** - * Checks shell access, renders the shell skin and evaluates submitted shell commands and scripts - */ -helma.shell = function(realm) { - if (req.data.done) { - helma.invalidate('shell'); - helma.invalidate('sqlshell'); - helma.invalidate('inspector'); - res.redirect(this.href()); - } - if (!helma.auth('shell')) - res.abort(); - res.data.fontface = 'Trebuchet MS, Verdana, sans-serif'; - res.data.href = this.href(); - res.data.commands = encodeForm(req.data.commands); - var evalcode = req.data.command || req.data.commands; - if (!evalcode && helma.Inspector) { - if (!session.data.inspectorAuthenticated) - session.data.inspectorAuthenticated = true; - evalcode = '(new helma.Inspector(this)).action();"
    ";'; - } - if (evalcode) { - try { - var startTime = new Date(); - var evalResult = eval(evalcode); - var stopTime = new Date(); - res.write(evalResult); - if (req.data.commands) { - res.write('

    ') - res.write('') - res.write('Script evaluated in ' + (stopTime.getTime() - startTime.getTime()) +' milliseconds.'); - res.write('
    '); - } else if (!req.data.command) { - res.write('
    '); - } - } catch ( e ) { - res.write(''); - if ( e.javaException ) { - var s = new java.io.StringWriter(); - e.javaException.printStackTrace( new java.io.PrintWriter( s ) ); - res.write( s.toString() ); - } else { - res.write( format( e + '
    ' + e.fileName + ', lineNumber = ' + e.lineNumber ) ); - } - res.write('
    '); - if (req.data.commands) res.write('
    '); - } - } - if (!req.data.command) renderSkin('helma.shell'); -} -helma.dontEnum('shell'); - -/** - * Checks shell access, renders the shell skin and evaluates submitted shell commands and scripts - */ -HopObject.prototype[ (app.properties['shellAction'] || 'shell') +'_action' ] = helma.shell; diff --git a/modules/tools/Global/helma.shell.skin b/modules/tools/Global/helma.shell.skin deleted file mode 100644 index 5b436bd7..00000000 --- a/modules/tools/Global/helma.shell.skin +++ /dev/null @@ -1,124 +0,0 @@ - - -
    -
    - - -
    - -
    -
    - -
    - - -
    diff --git a/modules/tools/Global/helma.sqlshell.js b/modules/tools/Global/helma.sqlshell.js deleted file mode 100644 index d2808832..00000000 --- a/modules/tools/Global/helma.sqlshell.js +++ /dev/null @@ -1,753 +0,0 @@ -if (!global.helma) { - global.helma = {}; -} - -helma.sqlshell = {}; - -/** -* Get the helma datasource with the given name -*/ -helma.sqlshell.getDatasource = function(name) { - return app.getDbSource(name); -} - -/** - * Get an array of names of all defined data sources suitable for use - * in html.select macro. - */ -helma.sqlshell.getDatasources = function() { - var dbmap = app.getDbProperties(); - var sources = []; - for (var i in dbmap) { - var dot = i.indexOf("."); - if (dot > -1 && i.lastIndexOf(".url") == i.length-4) { - var source = i.substring(0, dot); - sources.push([source, source]); - } - } - return sources; -} - -helma.sqlshell.getRepositories = function() { - var rep = []; - var repos = app.getRepositories(); - for (var i in repos) { - if (repos[i].getClass() == Packages.helma.framework.repository.FileRepository) - rep.push([i, repos[i].name]); - } - return rep; -} - -helma.sqlshell.getProtoRepositories = function(protoName) { - var rep = []; - var proto = app.getPrototype(protoName); - if (proto) { - var repos = proto.getRepositories(); - for (var i in repos) { - if (repos[i].getClass() == Packages.helma.framework.repository.FileRepository) - rep.push([i, repos[i].name]); - } - } - return rep; -} - -/** -* Main action to set the Helma Dbsource, display forms, perform queries. -*/ -helma.sqlshell.main = function() { - // If done, end sqlshell session - if (req.data.done) { - helma.invalidate('sqlshell'); - if (session.data.sqlShellReturnUrl) { - var targetUrl = session.data.sqlShellReturnUrl; - delete session.data.sqlShellReturnUrl; - } else { - var targetUrl = path.href(); - } - res.redirect(targetUrl); - } - - // Check if sqlshell is called from the shell tool - if (req.data.introFrom) { - session.data.sqlShellReturnUrl = req.data.introFrom; - if (session.data.shellAuthenticated) - session.data.sqlshellAuthenticated = true; - } - - // Check authentication - if (!helma.auth('sqlshell')) - res.abort(); - - // Handle authenticated requests - res.handlers.html = helma.sqlshell.html; - var param = {}; - param.datasource = req.data.datasource; - res.data.fontface = 'Verdana, sans-serif'; - /* if (req.data.schema) - session.data.sqlshellSchema = req.data.schema; - if (req.data.datasource) - session.data.sqlshellDatasource = req.data.datasource; */ - var dsource = req.data.datasource ? - helma.sqlshell.getDatasource(req.data.datasource) : null; - if (dsource) { - (new helma.sqlshell.Datasource(dsource)).main(); - } else { - if (req.data.datasource && req.isPost()) { - param.message = "Sorry, data source " + req.data.datasource + - " is not defined for this application."; - } - res.data.header = "Choose data source"; - res.data.datasources = helma.sqlshell.getDatasources(); - res.data.body = renderSkinAsString("helma.sqlshell.selectdb", param); - renderSkin("helma.sqlshell.page"); - } -} - -helma.sqlshell.Datasource = function(datasource) { - this.datasource = datasource; - this.name = datasource.name; - return this; -} - -/** -* Get an array of schema names defined in the current database. -*/ -helma.sqlshell.Datasource.prototype.getSchemas = function(meta) { - // get available schemas and set up an array for the drop down box: - var schemas = []; - var t = meta.getSchemas(); - while (t.next()) { - var s = t.getString(1); - schemas.push([s, s]); - } - return schemas; -} - -/** - * Get table names and set up an array for the drop down box - */ -helma.sqlshell.Datasource.prototype.getTables = function(meta, schema) { - var tables = [["", ""]]; - var t = meta.getTables (null, schema, "%", null); - while (t.next()) { - var table = t.getString (3); - tables.push([table, table]); - } - return tables; -} - -helma.sqlshell.Datasource.prototype.getColumns = function(meta, schema, table) { - var columns = []; - var t = meta.getColumns(null, schema, table, "%"); - while (t.next()) { - columns.push(t.getString(4)); - } - return columns; -} - -helma.sqlshell.Datasource.prototype.getPrototypes = function() { - var protos = [["", ""]]; - var protomap = app.getPrototypes(); - for (var i in protomap) { - if (protomap[i].lowerCaseName != "global") { - protos.push([protomap[i].name, protomap[i].name]); - } - } - return protos.sort(function(a, b) {return a < b ? -1 : 1;}); -} - -helma.sqlshell.Datasource.prototype.href = function(name) { - var href = path.href(req.action) + "?datasource="; - href += encode(req.data.datasource); - href += "&schema="; - href += encode(req.data.schema); - href += "&tab="; - href += req.data.tab; - return href; -} - -helma.sqlshell.Datasource.prototype.href_macro = function(param) { - return this.href(param.name); -} - -helma.sqlshell.colors = { - explore: "#bd9", query: "#db9", map: "#9bd" -} - -helma.sqlshell.Datasource.prototype.main = function() { - res.handlers.datasource = this; - if (!req.data.tab) { - req.data.tab = "explore"; - } - res.data.tabcolor = helma.sqlshell.colors[req.data.tab]; - - var param = new Object(); - param.action = this.href(); - - // get connection - var con = this.datasource.getConnection(); - - // get database meta data - var meta = con.getMetaData(); - - res.data.datasources = helma.sqlshell.getDatasources(); - res.data.schemas = this.getSchemas(meta); - var schema = req.data.schema; - res.data.tables = this.getTables(meta, schema); - - if (req.data.action) { - app.data.repositories = helma.sqlshell.getRepositories(); - if (req.data.action == "createproto" ) { - var repos = app.repositories[req.data.repository]; - var file = new File(repos.directory.toString(), req.data.protoname); - if (file.mkdir()) { - - renderSkin(this.getSkin("closePopup"), { - parentUrl: this.href() + "&prototype=" + req.data.protoname, - message: "

    Created directory " + file + "

    " + - "

    Please wait for prototypes to be updated...

    " - } ); - return; - } else { - res.debug("Couldn't create directory: " + file); - res.data.body = renderSkinAsString(this.getSkin("newproto")); - } - } else if (req.data.action == "extras") { - var p = {}; - var t = app.getPrototype(req.data.target); - var target = t && t.dbMapping ? t.dbMapping.tableName : null; - p.targetColumns = this.getColumns(meta, schema, target).toSource(); - p.localColumns = this.getColumns(meta, schema, req.data.__sqlshell_table__).toSource(); - res.data.body = renderSkinAsString(this.getSkin(req.data.action), p); - } else if (req.data.action == "generate") { - if (req.data.create) { - renderSkin(this.getSkin("closePopup"), { - parentUrl: this.href() + "&prototype=" + req.data.__sqlshell_prototype__, - message: "

    Created type mapping " + file + "

    " + - "

    Please wait for prototypes to be updated...

    " - } ); - } else { - var fields = {}; - var s = new java.lang.StringBuffer(); - for (var i in req.data) { - if (i.indexOf("maptype_") == 0) { - fields[i.substring(8)] = req.data[i]; - } - s.append(""); - } - if (req.data.__sqlshell_create__) { - // res.data.body = renderSkinAsString(this.getSkin("generate"), p); - var repos = app.getPrototype(req.data.__sqlshell_prototype__).repositories; - var resName = "type.properties"; - for (var i in repos) { - var resource = repos[i].getResource(resName); - if (resource && resource.exists()) { - if (resource.getClass() == Packages.helma.framework.repository.FileResource) { - var file = new File(resource.getName()); - var backup = new File(resource.getName() + ".bak"); - if (backup.exists()) { - var n = 1; - do { - backup = new File(resource.getName() + ".bak." + n++) - } while (backup.exists()); - } - if (!file.renameTo(backup)) { - res.debug("ERROR: Couldn't create backup for " + resource); - } - } else { - res.debug("WARNING: Couldn't move " + resource); - } - } - } - var file = new File(repos[req.data.__sqlshell_repository__].getResource(resName).getName()); - file.open(); - file.writeln("# Created by Helma SqlShell at " + new Date()); - if (req.data.__sqlshell_extends__) - file.writeln("_extends = " + req.data.__sqlshell_extends__); - if (req.data.__sqlshell_primaryKey__) - file.writeln("_id = " + req.data.__sqlshell_primaryKey__); - if (req.data.__sqlshell_protoColumn__) - file.writeln("_prototype = " + req.data.__sqlshell_protoColumn__); - if (req.data.__sqlshell_nameColumn__) - file.writeln("_name = " + req.data.__sqlshell_nameColumn__); - file.writeln(""); - for (var i in fields) { - var propType = parseInt(fields[i]); - var propName = req.data[i]; - if (!propName) continue; - file.write(propName); - file.write(" = "); - switch (propType) { - case 0: - file.writeln(req.data[i]); - break; - case 1: - file.writeln("object(" + req.data["target_" + i] + ")"); - break; - case 2: - file.writeln("collection(" + req.data["target_" + i] + ")"); - break; - case 3: - file.writeln("mountpoint(" + req.data["target_" + i] + ")"); - break; - default: - res.debug(i + ": " + fields[i]); - } - for (var m in this.mappingOptions) { - if (this.mappingOptions[m] <= propType && req.data[i + "_" + m]) { - file.write(propName); - file.write("."); - file.write(m.replace("_", ".")); - file.write(" = "); - file.writeln(req.data[i + "_" + m]); - } - } - file.writeln(""); - } - file.close(); - res.data.body = "Successfully created mapping in " + file; - } else { - var p = {}; - p.data = s.toString(); - res.data.repositories = helma.sqlshell.getProtoRepositories(req.data.__sqlshell_prototype__); - res.data.body = renderSkinAsString(this.getSkin("generate"), p); - } - } - } else { - res.data.body = renderSkinAsString(this.getSkin(req.data.action)); - } - } else { - // should we display type info on some table? - if (req.data.tab == "explore") { - param.body = this.explore(meta, schema, param); - } else if (req.data.tab == "query") { - param.body = this.query(con, param); - } else if (req.data.tab == "map") { - param.body = this.map(meta, schema, con, param); - } - // render the inner page skin and then the whole page - res.data.body = renderSkinAsString("helma.sqlshell.main", param); - } - - renderSkin("helma.sqlshell.page"); -} - -helma.sqlshell.Datasource.prototype.explore = function(meta, schema, param) { - res.push(); - renderSkin(this.getSkin("explore"), param); - if (req.data.__sqlshell_table__) { - var tableStyle = { table: { "class": "explore" }, td: { "class": "explore" } }; - var t = meta.getColumns(null, schema, req.data.__sqlshell_table__, "%"); - var writer = new helma.Markup.TableWriter(6, tableStyle); - writer.writeHeader = true; - var columnNames = ["Column Name", "Column Type", "Column Size", - "Nullable", "Default Value", "Extras"]; - for (var c in columnNames) { - writer.write(columnNames[c]); - } - while (t.next()) { - writer.write(t.getString(4)); - writer.write(t.getString(6)); - writer.write(t.getString(7)); - writer.write(t.getString(18)); - writer.write(t.getString(13)); - writer.write(t.getString(12)); - } - writer.close(); - } - return res.pop(); -} - -helma.sqlshell.Datasource.prototype.query = function(con, param) { - // some SQL has been submitted - evaluate it - if (req.data.sql) { - var query = req.data.sql.trim(); - - con.setReadOnly(false); - var stmt = con.createStatement(); - var value; - try { - value = stmt.execute(query); - if (!value) { - param.updated = stmt.getUpdateCount(); - } else { - var rs = stmt.getResultSet(); - var rsmeta = rs.getMetaData(); - var ncol = rsmeta.getColumnCount(); - - res.push(); - var tableStyle = { table: { "class": "query" }, td: { "class": "query" } }; - var writer = new helma.Markup.TableWriter(ncol, tableStyle); - writer.writeHeader = true; - for (var i=1; i<=ncol; i++) { - writer.write(rsmeta.getColumnName(i)); - } - - while (rs.next()) { - for (var i=1; i<=ncol; i++) { - writer.write(encode(rs.getString(i))); - } - } - - writer.close(); - param.resultset = res.pop(); - } - } catch (error) { - param.message = "Error: " + error; - } - } - return renderSkinAsString(this.getSkin("query"), param); -} - -helma.sqlshell.Datasource.prototype.map = function(meta, schema, con, param) { - // for (var i in req.data) res.debug(i); - res.push(); - res.data.prototypes = this.getPrototypes(); - var proto = app.getPrototype(req.data.__sqlshell_prototype__); - if (proto) { - var tableStyle = { table: { "class": "map" }, td: { "class": "map" } }; - var dbmap = proto.getDbMapping(); - if (!req.data.__sqlshell_table__ || - req.data.__sqlshell_prototype__ != req.data.previousProto) { - req.data.__sqlshell_table__ = dbmap.tableName; - } - param.tableSelect = renderSkinAsString(createSkin('Map to table \ - <% html.select name="__sqlshell_table__" options="response.tables" \ - onchange="document.forms.tab.submit();"%>')); - } - renderSkin(this.getSkin("map"), param); - if (proto) { - var maptypes = ["Primitive", "Reference", "Collection", "Mountpoint"]; - var tableStyle = { table: { "class": "map" }, td: { "class": "map" } }; - if (req.data.__sqlshell_table__) { - var primKey = ""; - try { - var k = meta.getPrimaryKeys(null, schema, req.data.__sqlshell_table__); - if (k.next()) { - primKey = k.getString(4); - } - if (k.next()) { - helma.Markup.p({"class": "error"}, "Table has composed primary key!"); - } - } catch (error) { - helma.Markup.p({"class": "error"}, "Error retrieving primary key: " + error); - } - var t = meta.getColumns(null, schema, req.data.__sqlshell_table__, "%"); - var columns = []; - res.data.columns = [["", ""]]; - while (t.next()) { - var colname = t.getString(4); - columns.push(colname); - res.data.columns.push([colname, colname]); - } - var writer = new helma.Markup.TableWriter(2, tableStyle); - writer.write("Extends "); - var ext = dbmap.getExtends() || app.getPrototype("hopobject").name; - writer.write(helma.Markup.Select({name: "__sqlshell_extends__"}, res.data.prototypes, ext)); - writer.write("Primary key column "); - writer.write(helma.Markup.Select({name: "__sqlshell_primaryKey__"}, res.data.columns, primKey)); - writer.write("Prototype column "); - writer.write(helma.Markup.Select({name: "__sqlshell_protoColumn__"}, res.data.columns, dbmap.prototypeField)); - writer.write("Name column "); - writer.write(helma.Markup.Select({name: "__sqlshell_nameColumn__"}, res.data.columns, dbmap.nameField)); - writer.close(); - tableStyle = { table: { "class": "map", id: "maptable" }, td: { "class": "map" } }; - writer = new helma.Markup.TableWriter(5, tableStyle); - writer.writeHeader = true; - var headers = ["Column Name", "Property Name", "Mapping", - "Target Prototype", "Extras"]; - for (var c in headers) { - writer.write(headers[c]); - } - for (var col in columns) { - var colname = columns[col]; - // if (colname == primKey) continue; - var rel = dbmap.columnNameToRelation(colname); - var value = rel && rel.propName ? rel.propName : this.toCamelCase(colname); - var type = rel ? rel.refType : 0; - var targetDisplay = type > 0 ? '': ' style="display: none;"'; - var target = rel && rel.targetType ? rel.targetType.typeName : ""; - writer.write(colname); - writer.write(''); - writer.write(helma.Markup.Select({name: "maptype_" + colname, - onchange: "toggleEditor(this)"}, maptypes, type)); - writer.write('
    ' + - helma.Markup.Select({name: "target_" + colname}, res.data.prototypes, target) + '
    '); - var buffer = new java.lang.StringBuffer(); - var config = rel ? wrapJavaMap(rel.config) : {}; - for (var i in this.mappingOptions) { - // var name = i.replace('_', '.'); - var name = colname + "_" + i; - buffer.append(helma.Markup.Hidden({id: name, name: name, value: config[i] }).toString()); - } - buffer.append(helma.Markup.A({href: this.href() + "&action=extras&col=" + colname, - id:"extralink_" + colname, style: type > 0 ? '': 'display: none;', - onclick: "openExtraEditor(this.href, '" + colname + "'); return false;"}, - "edit").toString()); - writer.write(buffer); - /* writer.write(helma.Markup.A({href: this.href() + "&action=extras&col=" + colname, - id:"extralink_" + colname, style: type > 0 ? '': 'display: none;', - onclick: "openPopup(this.href, 'extras'); return false;"}, - "edit")); */ - } - var props = dbmap.getPropertyNames(); - var collectionCount = 0; - for (var p in props) { - var rel = dbmap.propertyToRelation(props[p]); - if (rel.refType < 1 || (rel.dbField && rel.dbField != primKey)) { - continue; - } - var propName = rel.propName; - var target = rel.targetType ? rel.targetType.typeName : ""; - var type = rel.refType; - if (type == 2 && !rel.dbField) { - // helma does not separate between collections and mountpoints internally - type = 3; - } - var colname = "collection_" + (collectionCount++); - writer.write(""); - writer.write(''); - writer.write(helma.Markup.Select({name: "maptype_" + colname, - onchange: "toggleEditor(this)"}, maptypes, type)); - writer.write('
    ' + - helma.Markup.Select({name: "target_" + colname}, res.data.prototypes, target) + '
    '); - var buffer = new java.lang.StringBuffer(); - var config = wrapJavaMap(rel.config); - for (var i in this.mappingOptions) { - // var name = i.replace('_', '.'); - var name = colname + "_" + i; - buffer.append(helma.Markup.Hidden({id: name, name: name, value: config[i] }).toString()); - } - buffer.append(helma.Markup.A({href: this.href() + "&action=extras&col=" + colname, - id:"extralink_" + colname, - onclick: "openExtraEditor(this.href, '" + colname + "'); return false;"}, - "edit").toString()); - writer.write(buffer); - } - writer.close(); - // FIXME: MAJOR HACK ********************************** - res.writeln(''); - // END OF MAJOR HACK ********************************** - helma.Markup.a({href: "#", onclick:'return appendTableRow("maptable");'}, "Add Collection"); - res.write(" "); - helma.Markup.submit({name: "generateMapping", - onclick:"submitFormToPopup(document.forms.tab, '" + this.href() + "&action=generate', 'generate',500,350); return false;", - value: "Generate Mapping"}); - - } - } - return res.pop(); -} - -helma.sqlshell.Datasource.prototype.mappingOptions = { - local: 1, - foreign: 1, - order: 2, - accessname: 2, - group: 2, - group_order: 2, - group_prototype: 2, - filter: 2, - filter_additionalTables: 2, - loadmode: 1, - cachemode: 2, - maxsize: 2, - hints: 2, - logicalOperator: 2, - readonly: 2, - "private": 2 -} - -helma.sqlshell.Datasource.prototype.toCamelCase = function(str) { - var s = str.toLowerCase().split(/[-_]/); - str = s[0]; - for (var i=1; iSQL:
    \ -
    \ - \ - \ - <% param.message prefix="

    " suffix="

    " %>\ - <% param.updated prefix="

    "\ - prefix="Statement executed, "\ - suffix=" row(s) affected

    " %>\ - <% param.resultset %>'); - - case "explore": return createSkin('
    Describe Table \ - <% html.select name="__sqlshell_table__" options="response.tables" \ - onchange="document.forms.tab.submit();" %>\ -
    \ - <% param.tableheader prefix="

    " suffix="

    " %>\ - <% param.tableinfo %>'); - - case "map": return createSkin('
    Prototype \ - <% html.select name="__sqlshell_prototype__" options="response.prototypes" \ - onchange="document.forms.tab.submit();" %>\ - [new]\ - <% param.tableSelect %> \ - \ - \ - \ -
    '); - - case "newproto": return createSkin('
    \ - Prototype Name:

    \ - Create in Repository:
    <% html.select name="repository" options="app.repositories" %>

    \ - \ -
    '); - - case "extras": return createSkin('
    \ -

    Extra parameters for ' + req.data.col + '

    \ - \ - \ -
    \ - \ -
    '); - - case "generate": return createSkin('
    \ - Create type.properties in Repository:
    <% html.select name="__sqlshell_repository__"\ - options="response.repositories" %>

    \ - \ - <% param.data %>\ -
    '); - - case "closePopup": return createSkin('\ - \ - \ - \ - closing window\ - \ - \ - \ - <% param.message %>\ - \ - '); - - default: return createSkin("No skin defined for " + name); - } -} - -helma.sqlshell.Datasource.href = - -HopObject.prototype[ (app.properties['sqlshellAction'] || 'sqlshell') +'_action' ] = helma.sqlshell.main; - - -helma.dontEnum('sqlshell'); - - - - -//////////////////////////////////////////////////////////////////////// -// Macro handler for Html tags -//////////////////////////////////////////////////////////////////////// - -helma.sqlshell.html = { - - tablink_macro: function(param) { - var href = req.action + "?datasource="; - href += encode(req.data.datasource); - href += "&schema="; - href += encode(req.data.schema); - href += "&tab="; - href += param.name; - var attr = { href: href, "class": "tab" }; - if (req.data.tab == param.name) { - attr["class"] += " activetab"; - } else { - attr["class"] += " passivetab"; - } - helma.Markup.element("a", attr, param.name); - }, - - select_macro: function(param) { - if (!param.name) { - throw "dropDown macro requires name attribute"; - } - if (!param.options) { - throw "dropDown macro requires options attribute"; - } - var opts = param.options.split("."); - if (opts.length != 2) { - throw "options attribute must be of the form 'handler.options'"; - } - var handler = this.getHandler(opts[0]); - if (!handler) { - throw "handler '"+opts[0]+" not found - " + - "valid options are (response|request|session|app)"; - } - var options = handler[opts[1]]; - if (!options) { - throw param.options+" is not defined "; - } - if (options.length == 0) { - return; - } - var attr = {}; - for (var i in param) { - if (i != "options" && i != "prefix" && i != "suffix") { - attr[i] = param[i]; - } - } - helma.Markup.select(attr, options, req.data[param.name], param.firstoption); - }, - - getHandler: function (handlerName) { - switch (handlerName) { - case "response": - return res.data; - case "request": - return req.data; - case "session": - return session.data; - case "app": - return app.data; - } - return null; - } -} diff --git a/modules/tools/Global/helma.sqlshell.main.skin b/modules/tools/Global/helma.sqlshell.main.skin deleted file mode 100644 index 4c33095d..00000000 --- a/modules/tools/Global/helma.sqlshell.main.skin +++ /dev/null @@ -1,30 +0,0 @@ -

    Helma Sql Shell

    - -
    -
    - - <% html.select name="datasource" options="response.datasources" - prefix="Data Source: " onchange="document.forms.datasource.submit(); %> -    - <% html.select name="schema" options="response.schemas" - prefix="Schema: " onchange="document.forms.datasource.submit(); %> -
    -
    - -
    - -
    -<% html.tablink name="explore" %> -<% html.tablink name="query" %> -<% html.tablink name="map" %> -
    - - - - - -<% param.body %> - -

    - -
    diff --git a/modules/tools/Global/helma.sqlshell.page.skin b/modules/tools/Global/helma.sqlshell.page.skin deleted file mode 100644 index a6718273..00000000 --- a/modules/tools/Global/helma.sqlshell.page.skin +++ /dev/null @@ -1,207 +0,0 @@ - - - - -Helma SqlShell <% response.title %> - - - - - - - -<% response.header prefix="

    " suffix="

    " %> - -<% response.body %> - - diff --git a/modules/tools/Global/helma.sqlshell.selectdb.skin b/modules/tools/Global/helma.sqlshell.selectdb.skin deleted file mode 100644 index 27eb9977..00000000 --- a/modules/tools/Global/helma.sqlshell.selectdb.skin +++ /dev/null @@ -1,10 +0,0 @@ -

    Data sources are defined in db.properties files either at server or application level.

    - -<% param.message prefix="

    " suffix="

    " %> - -
    -Please enter a valid data source name: - <% html.select name="datasource" options="response.datasources" %> -    - -
    \ No newline at end of file diff --git a/renovate.json b/renovate.json deleted file mode 100644 index fd76f22d..00000000 --- a/renovate.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - - "extends": [ - "config:recommended", - "mergeConfidence:all-badges", - "npm:unpublishSafe", - ":disableRateLimiting", - ":pinVersions", - ":semanticCommitsDisabled" - ], - - "osvVulnerabilityAlerts": true, - - "vulnerabilityAlerts": { - "labels": ["security", "urgent"], - "automerge": true - }, - - "labels": ["dependency"], - - "packageRules": [ - { - "description": "Label Helma core packages", - "matchFiles": ["build.gradle"], - "addLabels": ["core"] - }, - { - "description": "Label major version bumps", - "matchUpdateTypes": ["major"], - "addLabels": ["major"] - }, - { - "description": "Label packages required at runtime", - "matchDepTypes": ["dependencies"], - "addLabels": ["runtime"] - }, - { - "description": "Group Jetty packages", - "matchPackagePrefixes": ["org.eclipse.jetty"], - "groupName": "Jetty packages" - }, - { - "description": "Group Lucene packages", - "matchPackagePrefixes": ["org.apache.lucene"], - "groupName": "Lucene packages" - } - ] -} - diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 5fd2dc60..00000000 --- a/settings.gradle +++ /dev/null @@ -1,21 +0,0 @@ -rootProject.name = 'helma' - -// Copy task ignores multiple files per default -// See https://github.com/gradle/gradle/issues/11176 -org.apache.tools.ant.DirectoryScanner.removeDefaultExclude('**/.git') -org.apache.tools.ant.DirectoryScanner.removeDefaultExclude('**/.git/**') -org.apache.tools.ant.DirectoryScanner.removeDefaultExclude('**/.gitignore') - -include 'launcher' -include 'modules' -include 'jala' -include 'hopKit' -include 'test' - -project(':modules').projectDir = file('modules/helma') -project(':jala').projectDir = file('modules/jala') -project(':hopKit').projectDir = file('modules/jala/util/HopKit') -project(':test').projectDir = file('modules/jala/util/Test') - -// Rename this project to prevent redundancy and renaming of main project (VSC does not care, though) -project(':modules').name = 'modules' diff --git a/src/dist/apps.properties b/src/dist/apps.properties deleted file mode 100644 index 76672bf1..00000000 --- a/src/dist/apps.properties +++ /dev/null @@ -1,23 +0,0 @@ -# List of applications to start. -# More information about this file is available at -# http://helma.org/Documentation/Properties+Files/apps.properties/ - - -# Administrative application to manage all other apps on this server, -# accessible via its default mountpoint at http://:/manage -# and using its default repository at apps/manage - -manage - - -# More complex example of an application with custom configuration: - -welcome -welcome.mountpoint = / -welcome.repository.0 = apps/welcome/code/ -welcome.repository.1 = modules/tools -welcome.static = apps/welcome/static -welcome.staticMountpoint = /static -welcome.staticHome = index.html,default.html -welcome.staticIndex = true -welcome.uploadLimit = 2048 diff --git a/src/dist/apps/manage/Application/actions.js b/src/dist/apps/manage/Application/actions.js deleted file mode 100644 index ddbedc75..00000000 --- a/src/dist/apps/manage/Application/actions.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* renders AppManager -*/ -function main_action() { - if (checkAddress() == false) - return; - if (checkAuth(this) == false) - return; - - res.data.body = this.renderSkinAsString("main"); - renderSkin("global"); -} - - -/** -* prints session- and thread-stats for mrtg-tool -* doesn't check username or password, so that we don't have -* to write them cleartext in a mrtg-configfile but checks the -* remote address. -*/ -function mrtg_action() { - if (checkAddress() == false) - return; - - if (this.isActive() == false) { - res.write("0\n0\n0\n0\n"); - return; - } - - if (req.data.action == "sessions") { - - res.write(this.sessions.size()); - res.write("\n0\n0\n0\n"); - - } else if (req.data.action == "threads") { - - res.write(this.countActiveEvaluators() + "\n"); - res.write(this.countEvaluators() + "\n"); - res.write("0\n0\n"); - - } else if (req.data.action == "cache") { - - res.write(this.getCacheUsage() + "\n"); - res.write(this.getProperty("cachesize", "1000") + "\n"); - res.write("0\n0\n"); - - } else if (req.data.action == "requests") { - - // res.write ( - - } else { - res.write("0\n0\n0\n0\n"); - } - -} - -/** -* performs a redirect to the public site -* (workaround, we can't access application object from docapplication for some reason) -* @see application.url_macro -*/ -function redirectpublic_action() { - if (checkAddress() == false) return; - if (checkAuth(this) == false) return; - - res.redirect(this.url_macro()); -} diff --git a/src/dist/apps/manage/Application/functions.js b/src/dist/apps/manage/Application/functions.js deleted file mode 100644 index 248fb68a..00000000 --- a/src/dist/apps/manage/Application/functions.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * construct an application object so that we can use - * skins for non-active applications too - * @arg name - */ -function constructor(name) { - this.name = name; -} - -/** - * return true/false to determine if application is running - */ -function isActive() { - if (root.getApplication(this.name) == null) - return false; - else - return true; -} - -/** - * Method used by Helma for URL composition. - */ -function href(action) { - var base = root.href() + this.name + "/"; - return action ? base + action : base; -} - -/** - * Method used by Helma for URL composition. - */ -function getParentElement() { - return root; -} - -/** - * Method used by Helma request path resolution. - */ -function getChildElement(name) { - if (name == "api") - return this.getDoc(); - return null; -} diff --git a/src/dist/apps/manage/Application/head.skin b/src/dist/apps/manage/Application/head.skin deleted file mode 100644 index 539aac0e..00000000 --- a/src/dist/apps/manage/Application/head.skin +++ /dev/null @@ -1,11 +0,0 @@ -

    AppManager <% this.title %> -<% this.description prefix="
    " %> -
    - -> - /read">showAPI | - /render">renderAPI | - public | - ?app=<% this.title %>&action=flush">flush | - ?app=<% this.title %>&action=restart">restart | - ?app=<% this.title %>&action=stop">stop -

    diff --git a/src/dist/apps/manage/Application/macros.js b/src/dist/apps/manage/Application/macros.js deleted file mode 100644 index 22c32903..00000000 --- a/src/dist/apps/manage/Application/macros.js +++ /dev/null @@ -1,210 +0,0 @@ -/** - * macro rendering a skin - * @param name name of skin - */ -function skin_macro(par) { - if (par && par.name) { - this.renderSkin(par.name); - } -} - - -/** - * macro-wrapper for href-function - * @param action name of action to call on this prototype, default main - */ -function href_macro(par) { - return this.href((par && par.action) ? par.action : "main"); -} - - -/** - * Macro returning the URL of an application. - * using absoluteURI if set in app.properties, otherwise we go for the href calculated by - * the application (which is using baseURI if set) - */ -function url_macro() { - var str = this.getProperty("absoluteuri"); - if (str != null && str != "") { - return str; - } else { - return this.getRootHref(); - } -} - - -/** - * Macro returning the title of an application - */ -function title_macro() { - var title = this.name; - return(title); -} - - -/** - * Macro rendering a description of an application from a - * file called description.txt or doc.html located in the - * app's root. Limits description to 200 chars. - * @param Object Macro parameter object - */ -function description_macro(param) { - var str = ""; - var appHome = this.getAppDir(); - var f = new File(this.getAppDir().toString(), "description.txt"); - if (!f.exists()) - f = new File(this.getAppDir().toString(), "doc.html"); - if (f.exists()) { - str = f.readAll(); - if (str.length > 200) - str = str.substring(0, 200) + "..."; - } - return(str); -} - - -/** - * Macro returning the server's uptime nicely formatted - */ -function uptime_macro() { - return formatAge((java.lang.System.currentTimeMillis() - this.starttime) / 1000); -} - - -/** - * Macro returning the number of active sessions. - * parameter used by global.formatCount - * @see global.formatCount - */ -function countSessions_macro(par) { - if (this.isActive() == true) - return this.sessions.size() + formatCount(this.sessions.size(), par); - else - return 0; -} - - -/** - * Macro returning the number of logged-in users or the list - * of logged-in users if http-parameter showusers is set to true. - * Makes use of this.countUsers_macro and this.listUsers_macro - * @see application.countUsers_macro - * @see application.listUsers_macro - */ -function users_macro(par) { - if (req.data.showusers == "true") { - this.listUsers_macro(par); - } else { - this.countUsers_macro(par); - } -} - - -/** - * Macro returning the number of logged-in users if application - * is active - * parameter used by global.formatCount - * @see global.formatCount - */ -function countUsers_macro(par) { - if (this.isActive() == true) - return this.activeUsers.size() + formatCount(this.activeUsers.size(), par); - else - return 0; -} - - -/** - * Macro rendering the list of logged-in users if application is active - * @param separator html-code written between elements - */ -function listUsers_macro(par) { - var separator = (par && par.separator) ? par.separator : ", "; - if (this.activeUsers.size() == 0) - return ""; - var users = this.activeUsers.iterator(); - while (users.hasNext()) { - res.write(users.next().__name__); - if (users.hasNext()) { - res.write(separator); - } - } -} - - -/** - * Macro returning the number of active evaluators (=threads) - */ -function countActiveEvaluators_macro() { - return this.countActiveEvaluators(); -} - - -/** - * Macro returning the number of free evaluators (=threads) - */ -function countFreeEvaluators_macro() { - return this.countFreeEvaluators(); -} - - -/** - * Macro returning the current number of objects in the cache - */ -function cacheusage_macro(param) { - return this.getCacheUsage(); -} - - -/** - * Macro returning the number of objects allowed in the cache - */ -function cachesize_macro(param) { - return this.getProperty("cachesize", "1000"); -} - - -/** - * Macro formatting the number of requests in the last 5 minutes - */ -function requestCount_macro(par) { - if (app.data.stat == null || app.data.stat[this.name] == null) - return "not available"; - if (this.isActive()) { - var obj = app.data.stat[this.name]; - return obj.requestCount + formatCount(obj.requestCount, par); - } else { - return 0 + formatCount(0, par); - } -} - - -/** - * Macro formatting the number of errors in the last 5 minutes - */ -function errorCount_macro(par) { - if (app.data.stat == null || app.data.stat[this.name] == null) - return "not available"; - if (this.isActive()) { - var obj = app.data.stat[this.name]; - return obj.errorCount + formatCount(obj.errorCount, par); - } else { - return 0 + formatCount(0, par); - } -} - - -/** -* Macro formatting app.properties -*/ -function properties_macro(par) { - formatProperties(this.getProperties(), par); -} - - -function repositories_macro(param) { - var repos = this.getRepositories().iterator(); - while (repos.hasNext()) - res.writeln(repos.next().getName()); -} - diff --git a/src/dist/apps/manage/Application/main.skin b/src/dist/apps/manage/Application/main.skin deleted file mode 100644 index 455e77d2..00000000 --- a/src/dist/apps/manage/Application/main.skin +++ /dev/null @@ -1,62 +0,0 @@ -<% this.skin name="head" %> - - - - -
    application
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    active sessions <% this.countSessions %>
    ?showusers=true">logged-in users <% this.users %> 
    active evaluators <% this.countActiveEvaluators %>
    free evaluators <% this.countFreeEvaluators %>
    requests / 5 min <% this.requestCount %>
    errors / 5 min <% this.errorCount %>
    cache usage <% this.cacheusage %> objects of <% this.cachesize %>
    uptime <% this.uptime %>
    repositories <% this.repositories %>
    - - - - - -<% this.properties itemprefix='' %> -
    app.properties
    ' separator=' ' itemsuffix='
    - diff --git a/src/dist/apps/manage/Application/navig_active.skin b/src/dist/apps/manage/Application/navig_active.skin deleted file mode 100644 index 3c24b3bf..00000000 --- a/src/dist/apps/manage/Application/navig_active.skin +++ /dev/null @@ -1,18 +0,0 @@ -
    - "><% this.title %>
    - <% this.countSessions singular=" Session" plural=" Sessions" %>, - <% this.requestCount singular=" Request" plural=" Requests" %>/5min - -
    diff --git a/src/dist/apps/manage/Application/navig_disabled.skin b/src/dist/apps/manage/Application/navig_disabled.skin deleted file mode 100644 index c49223d1..00000000 --- a/src/dist/apps/manage/Application/navig_disabled.skin +++ /dev/null @@ -1,10 +0,0 @@ -
    - - - - -
    - ?app=<% this.title %>&action=start">start -
    - <% this.title %> -
    diff --git a/src/dist/apps/manage/DocApplication/actions.js b/src/dist/apps/manage/DocApplication/actions.js deleted file mode 100644 index 7c1efcfa..00000000 --- a/src/dist/apps/manage/DocApplication/actions.js +++ /dev/null @@ -1,59 +0,0 @@ -function read_action() { - this.readApplication(); - res.redirect(this.href("main")); -} - -function main_action() { - if (checkAddress() == false) - return; - if (checkAuth(this.getParentElement()) == false) - return; - this.renderSkin("frameset"); -} - - -function prototypes_action() { - if (checkAddress() == false) - return; - if (checkAuth(this.getParentElement()) == false) - return; - res.data.body = this.renderSkinAsString("prototypes"); - renderSkin("api"); -} - - -function summary_action() { - if (checkAddress() == false) - return; - if (checkAuth(this.getParentElement()) == false) - return; - res.data.body = this.renderSkinAsString("summary"); - renderSkin("api"); -} - - -function functionindex_action() { - if (checkAddress() == false) - return; - if (checkAuth(this.getParentElement()) == false) - return; - res.data.body = this.renderSkinAsString("functionindex"); - renderSkin("api"); -} - - -function render_action() { - // set res.data.rendering, this will suppress the link back to the manage - // console in the apidocs actions - res.data.rendering = true; - if (checkAddress() == false) - return; - if (checkAuth(this.getParentElement()) == false) - return; - var ct = this.renderApi(); - res.data.body = 'rendering API ...
    wrote ' + ct + ' files

    '; - res.data.body += 'back to manage console'; - res.data.title = "rendering helma api"; - res.data.head = renderSkinAsString("head"); - renderSkin("basic"); -} diff --git a/src/dist/apps/manage/DocApplication/frameset.skin b/src/dist/apps/manage/DocApplication/frameset.skin deleted file mode 100644 index 7b43c942..00000000 --- a/src/dist/apps/manage/DocApplication/frameset.skin +++ /dev/null @@ -1,31 +0,0 @@ - - - helma api / <% this.name %> - - - - - -" name="prototypes"> -" name="functions"> - -" name="main"> - - -<h2> -Frame Alert</h2> - -<p> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. - - - - diff --git a/src/dist/apps/manage/DocApplication/functionindex.skin b/src/dist/apps/manage/DocApplication/functionindex.skin deleted file mode 100644 index fbc6e3d0..00000000 --- a/src/dist/apps/manage/DocApplication/functionindex.skin +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - -
    - Application <% this.headline %>
    -
    - -">SUMMARY | -">INDEX | -A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z| - - - <% this.functions skin="asIndexItem" - separator="" - %> -
    - -">SUMMARY | -">INDEX | -A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z| - diff --git a/src/dist/apps/manage/DocApplication/functions.js b/src/dist/apps/manage/DocApplication/functions.js deleted file mode 100644 index dec28856..00000000 --- a/src/dist/apps/manage/DocApplication/functions.js +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Get the prototype of any doc-object (either a prototype, a function or a tag) - */ -function getDocPrototype(obj) { - var tmp = obj; - while (tmp != null && tmp.getType() != this.PROTOTYPE) { - tmp = tmp.getParentElement(); - } - return tmp; -} - - -/** - * Get a prototype of this docapplication, ie get on of the children of this object - */ -function getPrototype(name) { - return this.getChildElement("prototype_" + name); -} - -/** - * Method used by Helma for URL composition. - */ -function href(action) { - var base = this.getParentElement().href() + "api/"; - return action ? base + action : base; -} - -function getDir(dir, obj) { - dir.mkdir(); - if (obj.getType() == this.APPLICATION) { - return dir; - } else { - var protoObj = this.getDocPrototype(obj); - var dir = new File (dir, protoObj.getElementName()); - dir.mkdir(); - return dir; - } -} - -function renderApi() { - var prefix = this.href(""); - this.storePage(this, "main", "", "index.html"); - this.storePage(this, "prototypes"); - this.storePage(this, "summary"); - this.storePage(this, "functionindex"); - var ct = 4; - var arr = this.listChildren(); - for (var i = 0; i < arr.length; i++) { - this.storePage(arr[i], "list", "../"); - this.storePage(arr[i], "main", "../"); - ct += 2; - var subarr = arr[i].listChildren(); - for (var j = 0; j < subarr.length; j++) { - this.storePage(subarr[j], "main", "../", subarr[j].getElementName() + ".html"); - ct += 1; - } - } - return ct; -} - - -function storePage(obj, action, backPath, filename) { - if (filename == null) - var filename = action + ".html"; - var str = this.getPage(obj, action, backPath); - var appObj = this.getParentElement(); - var dir = new File (appObj.getAppDir().getAbsolutePath(), ".docs"); - dir = this.getDir(dir, obj); - var f = new File (dir, filename); - f.remove(); - f.open(); - f.write(str); - f.close(); - app.log("wrote file " + f.getAbsolutePath()); -} - - -function getPage(obj, action, backPath) { - backPath = (backPath == null) ? "" : backPath; - res.pushStringBuffer(); - eval("obj." + action + "_action ();"); - var str = res.popStringBuffer(); - // get the baseURI out of the url and replace - // it with the given relative prefix - // (keep anchors in regex!) - var reg = new RegExp ("href=\"" + this.href("") + "([^\"#]+)([^\"]*)\"", "gim"); - str = str.replace(reg, "href=\"" + backPath + "$1.html$2\""); - var reg = new RegExp ("src=\"" + this.href("") + "([^\"#]+)([^\"]*)\"", "gim"); - str = str.replace(reg, "src=\"" + backPath + "$1.html$2\""); - // shorten links, so that function files can move up one directory - // in the hierarchy - var reg = new RegExp ("(prototype_[^/]+/[^/]+)/main.html", "gim"); - str = str.replace(reg, "$1.html"); - return str; -} - - diff --git a/src/dist/apps/manage/DocApplication/indexSeparator.skin b/src/dist/apps/manage/DocApplication/indexSeparator.skin deleted file mode 100644 index beb8ee73..00000000 --- a/src/dist/apps/manage/DocApplication/indexSeparator.skin +++ /dev/null @@ -1,3 +0,0 @@ - -<% param.letter %> - \ No newline at end of file diff --git a/src/dist/apps/manage/DocApplication/macros.js b/src/dist/apps/manage/DocApplication/macros.js deleted file mode 100644 index 945419bf..00000000 --- a/src/dist/apps/manage/DocApplication/macros.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* macro rendering a skin -* @param name name of skin -*/ -function skin_macro(par) { - if (par && par.name) { - this.renderSkin(par.name); - } -} - -/** - * macro-wrapper for href-function - * @param action name of action to call on this prototype, default main - */ -function href_macro(param) { - return this.href((param && param.action) ? param.action : "main"); -} - -function comment_macro(param) { - return renderComment(this, param); -} - -function content_macro(param) { - return this.getContent(); -} - -function tags_macro(param) { - return renderTags(this, param); -} - -function location_macro(param) { - return renderLocation(this, param); -} - -function link_macro(param) { - return renderLink(this, param); -} - -//// END OF COPIED FUNCTIONS - - -function linkToManage_macro(param) { - if (res.data.rendering != true) { - return ('back to manage console'); - } -} - -function headline_macro(param) { - res.write(this.getName()); -} - - -function hrefRoot_macro(param) { - var obj = this.getChildElement("prototype_root"); - if (obj == null) { - var obj = this.getChildElement("prototype_Root"); - } - if (obj != null) { - var action = (param.action) ? param.action : "main"; - return obj.href(action); - } -} - - -/** - * list all prototypes of this application - * @param skin name of skin to render on prototype - * @param separator - */ -function prototypes_macro(param) { - var skin = (param.skin) ? param.skin : "asPrototypeList"; - var separator = (param.separator) ? param.separator : ""; - var arr = this.listChildren(); - for (var i = 0; i < arr.length; i++) { - arr[i].renderSkin(skin); - if (i < arr.length - 1) - res.write(separator); - } -} - - -/** - * list all methods of all prototypes, sort them alphabetically - * @param skin name of skin to render on each method - * @param skinSeparator name of skin to render as separator between each letters - */ -function functions_macro(param) { - var skinname = (param.skin) ? param.skin : "asListItem"; - var skinIndexSeparator = (param.indexSeparator) ? param.indexSeparator : "indexSeparator"; - var separator = (param.separator) ? param.separator : ""; - var arr = this.listFunctions(); - var lastLetter = ""; - for (var i = 0; i < arr.length; i++) { - if (arr[i].getName().substring(0, 1) != lastLetter) { - lastLetter = arr[i].getName().substring(0, 1); - var tmp = new Object (); - tmp.letter = lastLetter.toUpperCase(); - this.renderSkin(skinIndexSeparator, tmp); - } - arr[i].renderSkin(skinname); - if (i < arr.length - 1) - res.write(separator); - } -} - - diff --git a/src/dist/apps/manage/DocApplication/prototypes.skin b/src/dist/apps/manage/DocApplication/prototypes.skin deleted file mode 100644 index 2ff758fb..00000000 --- a/src/dist/apps/manage/DocApplication/prototypes.skin +++ /dev/null @@ -1,10 +0,0 @@ -<% this.linkToManage suffix="

    " %> - -Application " target="main"><% this.name %>

    - -<% this.prototypes %> - - - - - diff --git a/src/dist/apps/manage/DocApplication/summary.skin b/src/dist/apps/manage/DocApplication/summary.skin deleted file mode 100644 index 816380b7..00000000 --- a/src/dist/apps/manage/DocApplication/summary.skin +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - -
    - Application <% this.headline %>
    -
    - -">SUMMARY | -">INDEX | - - - -<% this.comment encoding="html" %> - -
    - - - <% this.prototypes skin="asSummary" - separator="" - %> -
    - - -">SUMMARY | -">INDEX | - diff --git a/src/dist/apps/manage/DocFunction/actions.js b/src/dist/apps/manage/DocFunction/actions.js deleted file mode 100644 index 6bbf0bea..00000000 --- a/src/dist/apps/manage/DocFunction/actions.js +++ /dev/null @@ -1,11 +0,0 @@ -function main_action() { - if (checkAddress() == false) - return; - if (checkAuth() == false) - return; - res.data.body = this.renderSkinAsString("main"); - renderSkin("api"); -} - - - diff --git a/src/dist/apps/manage/DocFunction/asIndexItem.skin b/src/dist/apps/manage/DocFunction/asIndexItem.skin deleted file mode 100644 index 95a998ea..00000000 --- a/src/dist/apps/manage/DocFunction/asIndexItem.skin +++ /dev/null @@ -1,7 +0,0 @@ - -<% this.link handler="false" %> -- <% this.type %> in <% docprototype.name %> -
    -<% this.comment length="200" %> - - diff --git a/src/dist/apps/manage/DocFunction/asLargeListItem.skin b/src/dist/apps/manage/DocFunction/asLargeListItem.skin deleted file mode 100644 index e11013b3..00000000 --- a/src/dist/apps/manage/DocFunction/asLargeListItem.skin +++ /dev/null @@ -1,5 +0,0 @@ - -" target="main"><% this.link %>
    -<% this.comment length="200" %> - - diff --git a/src/dist/apps/manage/DocFunction/asLargeListItemSkin.skin b/src/dist/apps/manage/DocFunction/asLargeListItemSkin.skin deleted file mode 100644 index c659c611..00000000 --- a/src/dist/apps/manage/DocFunction/asLargeListItemSkin.skin +++ /dev/null @@ -1,8 +0,0 @@ - -" target="main"><% this.link %>
    -<% this.comment length="200" %> -<% this.skinparameters separator=", "%> - - - - diff --git a/src/dist/apps/manage/DocFunction/asListItem.skin b/src/dist/apps/manage/DocFunction/asListItem.skin deleted file mode 100644 index 30df0ea1..00000000 --- a/src/dist/apps/manage/DocFunction/asListItem.skin +++ /dev/null @@ -1,2 +0,0 @@ -<% this.link %>
    - diff --git a/src/dist/apps/manage/DocFunction/asParentListItem.skin b/src/dist/apps/manage/DocFunction/asParentListItem.skin deleted file mode 100644 index 0822c4cc..00000000 --- a/src/dist/apps/manage/DocFunction/asParentListItem.skin +++ /dev/null @@ -1 +0,0 @@ -<% this.link %> \ No newline at end of file diff --git a/src/dist/apps/manage/DocFunction/functions.js b/src/dist/apps/manage/DocFunction/functions.js deleted file mode 100644 index eafd288c..00000000 --- a/src/dist/apps/manage/DocFunction/functions.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Method used by Helma for URL composition. - */ -function href(action) { - var base = this.getParentElement().href() - + this.getElementName() + "/"; - return action ? base + action : base; -} - - diff --git a/src/dist/apps/manage/DocFunction/macros.js b/src/dist/apps/manage/DocFunction/macros.js deleted file mode 100644 index 9443f0eb..00000000 --- a/src/dist/apps/manage/DocFunction/macros.js +++ /dev/null @@ -1,150 +0,0 @@ -/** -* macro rendering a skin -* @param name name of skin -*/ -function skin_macro(par) { - if (par && par.name) { - this.renderSkin(par.name); - } -} - -/** - * macro-wrapper for href-function - * @param action name of action to call on this prototype, default main - */ -function href_macro(param) { - return this.href((param && param.action) ? param.action : "main"); -} - -function comment_macro(param) { - return renderComment(this, param); -} -function content_macro(param) { - return this.getContent(); -} -function tags_macro(param) { - return renderTags(this, param); -} -function location_macro(param) { - return renderLocation(this, param); -} -function link_macro(param) { - return renderLink(this, param); -} - -//// END OF COPIED FUNCTIONS - - -function headline_macro(param) { - var p = this.getParentElement(); - var handler = (p != null) ? p.getName() : ""; - if (this.getType() == this.ACTION) { - res.write("/" + this.getName()); - } else if (this.getType() == this.FUNCTION) { - if (handler != "" && handler != "global") - res.write(handler + "."); - res.write(this.getName() + " ("); - var arr = this.listParameters(); - for (var i = 0; i < arr.length; i++) { - res.write(arr[i]); - if (i < arr.length - 1) { - res.write(", "); - } - } - res.write(")"); - } else if (this.getType() == this.MACRO) { - res.write("<% "); - if (handler != "" && handler != "global") - res.write(handler + "."); - var name = this.getName(); - if (name.indexOf("_macro") > -1) - name = name.substring(0, name.length - 6); - res.write(name); - res.write(" %>"); - } else if (this.getType() == this.SKIN) { - if (handler != "" && handler != "global") - res.write(handler + "/"); - res.write(this.getName()); - res.write(".skin"); - } else if (this.getType() == this.PROPERTIES) { - res.write(this.getName()); - } -} - - -function skinparameters_macro(param) { - if (this.getType() == this.SKIN) { - this.parameters_macro(param); - } -} - - -function parameters_macro(param) { - var separator = (param.separator) ? param.separator : ", "; - var arr = this.listParameters(); - for (var i = 0; i < arr.length; i++) { - res.write(arr[i]); - if (i < arr.length - 1) - res.write(separator); - } -} - - -function type_macro(param) { - return this.getTypeName(); -} - - -/** - * macro returning nicely formatted sourcecode of this method. - * code is encoded, >% %<-tags are colorcoded, line numbers are added - */ -function source_macro(param) { - var sourcecode = this.getContent(); - if (param.as == "highlighted") { - - sourcecode = encode(sourcecode); - - // highlight macro tags - r = new RegExp("<%", "gim"); - sourcecode = sourcecode.replace(r, '<%'); - - r = new RegExp("%>", "gim"); - sourcecode = sourcecode.replace(r, '%>'); - - // highlight js-comments - r = new RegExp("^([ \\t]*//.*)", "gm"); - sourcecode = sourcecode.replace(r, '$1'); - - // highlight quotation marks, but not for skins - if (this.getTypeName() != "Skin") { - r = new RegExp("(".*?")", "gm"); - sourcecode = sourcecode.replace(r, '$1'); - r = new RegExp("(\'[\']*\')", "gm"); - sourcecode = sourcecode.replace(r, '$1'); - } - - // remove all CR and LF, just
    remains - var r = new RegExp("[\\r\\n]", "gm"); - sourcecode = sourcecode.replace(r, ""); - - var arr = sourcecode.split("
    "); - var line = this.getStartLine ? this.getStartLine() : 1; - for (var i = 0; i < arr.length; i++) { - res.write('' + (line++) + ': '); - if (i < 99) { - res.write(' '); - } - if (i < 9) { - res.write(' '); - } - res.write(arr[i] + "\n"); - } - - } else { - res.write(sourcecode); - } -} - - - diff --git a/src/dist/apps/manage/DocFunction/main.skin b/src/dist/apps/manage/DocFunction/main.skin deleted file mode 100644 index da43ed06..00000000 --- a/src/dist/apps/manage/DocFunction/main.skin +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - -
    - <% this.headline %>
    -
    - <% this.comment suffix="

    " %> - <% this.skinparameters prefix="general parameters used in this skin:
    • " separator="
    • " suffix="

    " %> -
      - <% this.tags type="param" skin="parameter" %> - <% this.tags type="return" skin="return" %> - <% this.tags type="author" skin="author" %> - <% this.tags type="see" skin="see" %> - <% this.tags type="deprecated" skin="deprecated" %> - <% this.tags type="overrides" skin="overrides" %> -
    -
    - - - - - - -
    Sourcecode in <% this.location %>: -
    <% this.source as="highlighted" %>
    -
    - - - diff --git a/src/dist/apps/manage/DocPrototype/actions.js b/src/dist/apps/manage/DocPrototype/actions.js deleted file mode 100644 index a9b9c873..00000000 --- a/src/dist/apps/manage/DocPrototype/actions.js +++ /dev/null @@ -1,18 +0,0 @@ -function list_action() { - if (checkAddress() == false) - return; - if (checkAuth() == false) - return; - res.data.body = this.renderSkinAsString("list"); - renderSkin("api"); -} - -function main_action() { - if (checkAddress() == false) - return; - if (checkAuth() == false) - return; - res.data.body = this.renderSkinAsString("main"); - renderSkin("api"); -} - diff --git a/src/dist/apps/manage/DocPrototype/asInheritanceLink.skin b/src/dist/apps/manage/DocPrototype/asInheritanceLink.skin deleted file mode 100644 index 42449c89..00000000 --- a/src/dist/apps/manage/DocPrototype/asInheritanceLink.skin +++ /dev/null @@ -1 +0,0 @@ -extends Prototype "><% this.name %> \ No newline at end of file diff --git a/src/dist/apps/manage/DocPrototype/asParentList.skin b/src/dist/apps/manage/DocPrototype/asParentList.skin deleted file mode 100644 index 34208c8a..00000000 --- a/src/dist/apps/manage/DocPrototype/asParentList.skin +++ /dev/null @@ -1,16 +0,0 @@ - -Inherited from prototype <% this.link %>:
    - - - -<% this.methods separator=", " filter="actions" skin="asParentListItem" prefix="Actions: " suffix="
    " %> -<% this.methods separator=", " filter="functions" skin="asParentListItem" prefix="Functions: " suffix="
    " %> -<% this.methods separator=", " filter="macros" skin="asParentListItem" prefix="Macros: " suffix="
    " %> -<% this.methods separator=", " filter="skins" skin="asParentListItem" prefix="Skins: " suffix="
    " %> - - - - - - - diff --git a/src/dist/apps/manage/DocPrototype/asPrototypeList.skin b/src/dist/apps/manage/DocPrototype/asPrototypeList.skin deleted file mode 100644 index 0f3762aa..00000000 --- a/src/dist/apps/manage/DocPrototype/asPrototypeList.skin +++ /dev/null @@ -1,10 +0,0 @@ - -" onClick="parent.changePrototypeList(this);" target="main"><% this.name %> - -<% - this.inheritance action="main" target="main" - onClick="parent.changePrototypeList(this);" hopobject="false" - prefix=" (extends " suffix=")" -%> - -
    diff --git a/src/dist/apps/manage/DocPrototype/asSummary.skin b/src/dist/apps/manage/DocPrototype/asSummary.skin deleted file mode 100644 index 5ce50bd5..00000000 --- a/src/dist/apps/manage/DocPrototype/asSummary.skin +++ /dev/null @@ -1,4 +0,0 @@ - -"><% this.name %>
    -<% this.comment length="200" %> - diff --git a/src/dist/apps/manage/DocPrototype/functions.js b/src/dist/apps/manage/DocPrototype/functions.js deleted file mode 100644 index ad9ef068..00000000 --- a/src/dist/apps/manage/DocPrototype/functions.js +++ /dev/null @@ -1,30 +0,0 @@ -function translateType(filter) { - if (filter == "actions") - return Packages.helma.doc.DocElement.ACTION; - else if (filter == "functions") - return Packages.helma.doc.DocElement.FUNCTION; - else if (filter == "macros") - return Packages.helma.doc.DocElement.MACRO; - else if (filter == "skins") - return Packages.helma.doc.DocElement.SKIN; - else if (filter == "properties") - return Packages.helma.doc.DocElement.PROPERTIES; - else - return -1; -} - -/** - * Get the application we're part of. - */ -function getApplication() { - return this.getParentElement(); -} - -/** - * Method used by Helma for URL composition. - */ -function href(action) { - var base = this.getParentElement().href() - + this.getElementName() + "/"; - return action ? base + action : base; -} diff --git a/src/dist/apps/manage/DocPrototype/list.skin b/src/dist/apps/manage/DocPrototype/list.skin deleted file mode 100644 index 0225a667..00000000 --- a/src/dist/apps/manage/DocPrototype/list.skin +++ /dev/null @@ -1,10 +0,0 @@ -Prototype " target="main"><% this.name %>
    -<% this.inheritance action="list" %> -<% this.inheritance deep="true" hopobject="true" action="main" target="main" onClick="parent.changePrototypeList(this);" separator=", " prefix="extends: " suffix="
    " %>
    - - -<% this.methods filter="actions" skin="asListItem" prefix="

    Actions:
    " suffix="

    " %> -<% this.methods filter="functions" skin="asListItem" prefix="

    Functions:
    " suffix="

    " %> -<% this.methods filter="macros" skin="asListItem" prefix="

    Macros:
    " suffix="

    " %> -<% this.methods filter="skins" skin="asListItem" prefix="

    Skins:
    " suffix="

    " %> - diff --git a/src/dist/apps/manage/DocPrototype/macros.js b/src/dist/apps/manage/DocPrototype/macros.js deleted file mode 100644 index 7b2915e1..00000000 --- a/src/dist/apps/manage/DocPrototype/macros.js +++ /dev/null @@ -1,165 +0,0 @@ -/** -* macro rendering a skin -* @param name name of skin -*/ -function skin_macro(par) { - if (par && par.name) { - this.renderSkin(par.name); - } -} - -/** - * macro-wrapper for href-function - * @param action name of action to call on this prototype, default main - */ -function href_macro(param) { - return this.href((param && param.action) ? param.action : "main"); -} - -function comment_macro(param) { - return renderComment(this, param); -} - -function content_macro(param) { - return this.getContent(); -} - -function tags_macro(param) { - return renderTags(this, param); -} - -function location_macro(param) { - return renderLocation(this, param); -} - -function link_macro(param) { - return renderLink(this, param); -} - -//// END OF COPIED FUNCTIONS - - -function headline_macro(param) { - res.write(this.getName()); -} - -/** - * macro formatting list of methods of this prototype - * @param filter actions | functions | macros | skins - * @param skin skin to apply to the docfunction object - * @param separator - * @param desc Description that is passed on to the called skin - */ -function methods_macro(param) { - var skinname = (param.skin) ? param.skin : "list"; - var separator = (param.separator) ? param.separator : ""; - var arr = this.listChildren(); - var type = this.translateType(param.filter); - var sb = new java.lang.StringBuffer (); - for (var i = 0; i < arr.length; i++) { - if (arr[i].getType() == type) { - sb.append(arr[i].renderSkinAsString(skinname, param)); - sb.append(separator); - } - } - var str = sb.toString(); - if (str.length > 0) - return str.substring(0, str.length - separator.length); - else - return str; -} - - -function inheritance_macro(param) { - var action = param.action ? param.action : "main"; - var target = param.target ? ('target="' + param.target + '" ') : ''; - var obj = this.getParentPrototype(); - if (obj != null) { - obj = this.inheritanceUtil(obj, param); - } - if (param.deep == "true") { - while (obj != null) { - obj = this.inheritanceUtil(obj, param); - } - } -} - -function inheritanceUtil(obj, param) { - if (obj.getName() == "hopobject" && param.hopobject != "true") - return null; - var tmp = new Object (); - for (var i in param) - tmp[i] = param[i]; - tmp.href = obj.href((param.action) ? param.action : "main"); - delete tmp.hopobject; - delete tmp.action; - delete tmp.deep; - delete tmp.separator; - res.write(renderLinkTag(tmp)); - res.write(obj.getName() + ""); - if (obj.getParentPrototype()) - res.write(param.separator); - return obj.getParentPrototype(); -} - - -/** - * loops through the parent prototypes and renders a skin on each - * if it has got any functions. - * @param skin - */ -function parentPrototype_macro(param) { - var skinname = (param.skin) ? param.skin : "asParentList"; - var obj = this.getParentPrototype(); - while (obj != null) { - if (obj.listChildren().length > 0) { - obj.renderSkin(skinname); - } - obj = obj.getParentPrototype(); - } -} - -/** - * macro rendering a skin depending on wheter this prototype has got - * type-properties or not. - * @param skin - */ -function typeProperties_macro(param) { - var props = this.getTypeProperties(); - var iter = props.getResources(); - while (iter.hasNext()) { - var tmp = this.renderTypePropertiesResource(iter.next(), props); - var skinname = (param.skinname) ? param.skinname : "typeproperties"; - this.renderSkin(skinname, tmp); - } -} - -function renderTypePropertiesResource(res, props) { - if (res.getContent() != "") { - var sb = new java.lang.StringBuffer (); - // map of all mappings.... - var mappings = props.getMappings(); - // parse type.properties linewise: - var arr = res.getContent().split("\n"); - for (var i = 0; i < arr.length; i++) { - arr [i] = arr[i].trim(); - // look up in mappings table if line matches: - for (var e = mappings.keys(); e.hasMoreElements();) { - var key = e.nextElement(); - var reg = new RegExp ('^' + key + '\\s'); - if (arr[i].match(reg)) { - // it matched, wrap line in a link to that prototype: - var docProtoObj = this.getApplication().getPrototype(mappings.getProperty(key)); - if (docProtoObj != null) { - arr[i] = '' + arr[i] + ''; - } - } - } - sb.append(arr[i] + "\n"); - } - var tmp = new Object (); - tmp.content = sb.toString(); - tmp.source = res.getName(); - return tmp; - } -} diff --git a/src/dist/apps/manage/DocPrototype/main.skin b/src/dist/apps/manage/DocPrototype/main.skin deleted file mode 100644 index 0542d1d2..00000000 --- a/src/dist/apps/manage/DocPrototype/main.skin +++ /dev/null @@ -1,81 +0,0 @@ - - - - -
    - Prototype <% this.headline %>
    - <% this.inheritance deep="true" hopobject="true" action="main" target="main" onClick="parent.changePrototypeList(this);" separator=", " prefix="extends: " suffix="
    " %> -
    - -ACTIONS | -FUNCTIONS | -MACROS | -SKINS | -TYPE.PROPERTIES - -

    - - - - - - -
    - <% this.comment suffix="

    " %> -
      - <% this.tags type="author" skin="author" %> - <% this.tags type="see" skin="see" %> - <% this.tags type="deprecated" skin="deprecated" %> - <% this.tags type="overrides" skin="overrides" %> -
    -
    - - - - <% this.methods separator="" - filter="actions" - skin="asLargeListItem" - prefix="" - suffix="" - %> - - <% this.methods separator="" - filter="functions" - skin="asLargeListItem" - prefix="" - suffix="" - %> - - <% this.methods separator="" - filter="macros" - skin="asLargeListItem" - prefix="" - suffix="" - %> - - <% this.methods separator="" - filter="skins" - skin="asLargeListItemSkin" - prefix="" - suffix="" - %> - - <% this.methods separator="" - filter="properties" - skin="asLargeListItemSkin" - prefix="" - suffix="" - %> - - <% this.parentPrototype skin="asParentList" %> -
    Actions
     
    Functions
     
    Macros
     
    Skins
     
    type.properties
     
    - -

    - - - - - - - - diff --git a/src/dist/apps/manage/DocPrototype/typeproperties.skin b/src/dist/apps/manage/DocPrototype/typeproperties.skin deleted file mode 100644 index e1975b32..00000000 --- a/src/dist/apps/manage/DocPrototype/typeproperties.skin +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - -
    type.properties in <% param.source %>
    <% param.content %>
    - diff --git a/src/dist/apps/manage/DocTag/author.skin b/src/dist/apps/manage/DocTag/author.skin deleted file mode 100644 index c319829d..00000000 --- a/src/dist/apps/manage/DocTag/author.skin +++ /dev/null @@ -1,2 +0,0 @@ -
  • Author
    -<% this.text %> \ No newline at end of file diff --git a/src/dist/apps/manage/DocTag/deprecated.skin b/src/dist/apps/manage/DocTag/deprecated.skin deleted file mode 100644 index 57cb4d4e..00000000 --- a/src/dist/apps/manage/DocTag/deprecated.skin +++ /dev/null @@ -1,2 +0,0 @@ -
  • Deprecated
    -<% this.text %> diff --git a/src/dist/apps/manage/DocTag/main.skin b/src/dist/apps/manage/DocTag/main.skin deleted file mode 100644 index dca81089..00000000 --- a/src/dist/apps/manage/DocTag/main.skin +++ /dev/null @@ -1 +0,0 @@ -
  • <% this.text %> \ No newline at end of file diff --git a/src/dist/apps/manage/DocTag/overrides.skin b/src/dist/apps/manage/DocTag/overrides.skin deleted file mode 100644 index 4616af7f..00000000 --- a/src/dist/apps/manage/DocTag/overrides.skin +++ /dev/null @@ -1,3 +0,0 @@ -
  • Overrides
    -<% param.link %> - diff --git a/src/dist/apps/manage/DocTag/parameter.skin b/src/dist/apps/manage/DocTag/parameter.skin deleted file mode 100644 index deeed157..00000000 --- a/src/dist/apps/manage/DocTag/parameter.skin +++ /dev/null @@ -1,2 +0,0 @@ -
  • Parameter <% this.name %>:
    -<% this.text %> \ No newline at end of file diff --git a/src/dist/apps/manage/DocTag/return.skin b/src/dist/apps/manage/DocTag/return.skin deleted file mode 100644 index a421d33c..00000000 --- a/src/dist/apps/manage/DocTag/return.skin +++ /dev/null @@ -1,2 +0,0 @@ -
  • Returns
    -<% this.text %> diff --git a/src/dist/apps/manage/DocTag/see.skin b/src/dist/apps/manage/DocTag/see.skin deleted file mode 100644 index 5e66957d..00000000 --- a/src/dist/apps/manage/DocTag/see.skin +++ /dev/null @@ -1,2 +0,0 @@ -
  • See also
    -<% param.link %> diff --git a/src/dist/apps/manage/Global/api.skin b/src/dist/apps/manage/Global/api.skin deleted file mode 100644 index 9fb798d9..00000000 --- a/src/dist/apps/manage/Global/api.skin +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - -<% response.body %> - - - diff --git a/src/dist/apps/manage/Global/basic.skin b/src/dist/apps/manage/Global/basic.skin deleted file mode 100644 index 8b300a8a..00000000 --- a/src/dist/apps/manage/Global/basic.skin +++ /dev/null @@ -1,5 +0,0 @@ - - -<% response.head %> -<% response.body %> - diff --git a/src/dist/apps/manage/Global/functions.js b/src/dist/apps/manage/Global/functions.js deleted file mode 100644 index 98b840a0..00000000 --- a/src/dist/apps/manage/Global/functions.js +++ /dev/null @@ -1,262 +0,0 @@ -/** -* scheduler function, runs global.appStat every minute -*/ -function scheduler() { - appStat(); - return 60000; -} - - -/** - * initializes app.data.stat storage on startup, - * creates app.data.addressFilter - */ -function onStart() { - app.data.addressFilter = createAddressFilter(); - app.data.addressString = root.getProperty("allowadmin"); -} - -/** - * initializes addressFilter from app.properties, - * hostnames are converted, wildcards are only allowed in ip-addresses - * (so, no network-names, sorry) - */ -function createAddressFilter() { - var filter = new Packages.helma.util.InetAddressFilter(); - var str = root.getProperty("allowadmin"); - if (str != null && str != "") { - var arr = str.split(","); - for (var i in arr) { - str = new java.lang.String(arr[i]); - try { - filter.addAddress(str.trim()); - } catch (a) { - try { - str = java.net.InetAddress.getByName(str.trim()).getHostAddress(); - filter.addAddress(str); - } catch (b) { - app.log("error using address " + arr[i] + ": " + b); - } - } - } - } else { - app.log("no addresses allowed for app manage, all access will be denied"); - } - return filter; -} - - -/** - * updates the stats in app.data.stat every 5 minutes - */ -function appStat() { - if (app.data.stat == null) - app.data.stat = new HopObject (); - if ((new Date() - 300000) < app.data.stat.lastRun) - return; - var arr = root.getApplications(); - for (var i = 0; i < arr.length; i++) { - var tmp = app.data.stat[arr[i].getName()]; - if (tmp == null) { - tmp = new HopObject(); - tmp.lastTotalRequestCount = 0; - tmp.lastTotalErrorCount = 0; - } - tmp.requestCount = arr[i].getRequestCount() - tmp.lastTotalRequestCount; - tmp.lastTotalRequestCount = arr[i].getRequestCount(); - tmp.errorCount = arr[i].getErrorCount() - tmp.lastTotalErrorCount; - tmp.lastTotalErrorCount = arr[i].getErrorCount(); - app.data.stat[arr[i].getName()] = tmp; - } - app.data.stat.lastRun = new Date(); -} - - -/** - * utility function to sort object-arrays by name - */ -function sortByName(a, b) { - if (a.name > b.name) - return 1; - else if (a.name == b.name) - return 0; - else - return -1; -} - - -/** - * utility function to sort property-arrays by key - */ -function sortProps(a, b) { - if (a > b) - return 1; - else if (a == b) - return 0; - else - return -1; -} - -/** - * check access to an application or the whole server, authenticate against md5-encrypted - * properties of base-app or the particular application. if username or password aren't set - * go into stealth-mode and return a 404. if username|password are wrong, prepare response- - * object for http-auth and return false. - * @arg appObj application object to check against (if adminUsername etc are set in app.properties) - */ -function checkAuth(appObj) { - if (res && res.data.noWeb == true) { - return true; - } - var ok = false; - - // check against root - var adminAccess = root.getProperty("adminAccess"); - - if (adminAccess == null || adminAccess == "") { - res.redirect(root.href("makekey")); - } - - var uname = req.username; - var pwd = req.password; - - if (uname == null || uname == "" || pwd == null || pwd == "") - return forceAuth(); - - var md5key = Packages.org.apache.commons.codec.digest.DigestUtils.md5Hex(uname + "-" + pwd); - - if (md5key == adminAccess) - return true; - - if (appObj != null && appObj.isActive()) { - // check against application - adminAccess = appObj.getProperty("adminAccess"); - if (md5key == adminAccess) - return true; - } - return forceAuth(); -} - - -/** - * check access to the manage-app by ip-addresses - */ -function checkAddress() { - if (res && res.data.noWeb == true) { - return true; - } - // if allowadmin value in server.properties has changed, - // re-construct the addressFilter - if (app.data.addressString != root.getProperty("allowadmin")) { - app.data.addressFilter = createAddressFilter(); - app.data.addressString = root.getProperty("allowadmin"); - } - if (!app.data.addressFilter.matches(java.net.InetAddress.getByName(req.data.http_remotehost))) { - app.log("denied request from " + req.data.http_remotehost); - // forceStealth seems a bit like overkill here. - // display a message that the ip address must be added to server.properties - res.write("Access from address " + req.data.http_remotehost + " denied."); - return false; - } else { - return true; - } -} - - -/** - * response is reset to 401 / authorization required - * @arg realm realm for http-auth - */ -function forceAuth(realm) { - res.reset(); - res.status = 401; - res.realm = (realm != null) ? realm : "helma"; - res.write("Authorization Required. The server could not verify that you are authorized to access the requested page."); - return false; -} - - -/** -* macro-utility: formatting property lists -*/ -function formatProperties(props, par) { - if (props.size() == 0) - return ""; - var e = props.keys(); - var arr = new Array(); - while (e.hasMoreElements()) { - arr[arr.length] = e.nextElement(); - } - arr.sort(sortProps); - for (var i in arr) { - // don't print the admin-password - if (arr[i].toLowerCase() == "adminusername" || arr[i].toLowerCase() == "adminpassword") continue; - res.write(par.itemprefix + arr[i] + par.separator + props.getProperty(arr[i]) + par.itemsuffix); - } -} - - -/** - * macro-utility: formatting an integer value as human readable bytes - */ -function formatBytes(bytes) { - if (bytes > Math.pow(2, 30)) { - res.write(Math.round(100 * bytes / Math.pow(2, 30)) / 100 + "gb"); - } else if (bytes > Math.pow(2, 20)) { - res.write(Math.round(100 * bytes / Math.pow(2, 20)) / 100 + "mb"); - } else { - res.write(Math.round(100 * bytes / Math.pow(2, 10)) / 100 + "kb"); - } -} - - -/** - * macro-utility: formatting time in millis as human readable age - */ -function formatAge(age) { - var str = ""; - var days = Math.floor(age / 86400); - age = age - days * 86400; - var hours = Math.floor(age / 3600); - age = age - hours * 3600; - var minutes = Math.floor(age / 60); - var seconds = Math.floor(age - minutes * 60); - if (days > 0) - str += (days + " days, "); - if (hours > 0) - str += (hours + "h, "); - str += (minutes + "min"); - if (days == 0) str += (", " + seconds + "sec"); - return(str); -} - - -/** - * macro-utility: formatting a number-suffix by choosing between singular and plural - * @arg value number to be formatted - * @arg param-object object to get fields - * @param singular string used for value==1 - * @param plural string used for value!=1 - */ -function formatCount(ct, par) { - if (!par || !par.singular || !par.plural) { - return ""; - } - if (ct == 1) - return par.singular; - else - return par.plural; -} - - -/** - * tries to make out if this server is running linux from java's system properties - */ -function isLinux() { - var str = java.lang.System.getProperty("os.name"); - return (str != null && str.toLowerCase().indexOf("linux") != -1); -} - - - - diff --git a/src/dist/apps/manage/Global/global.skin b/src/dist/apps/manage/Global/global.skin deleted file mode 100644 index a80b0da1..00000000 --- a/src/dist/apps/manage/Global/global.skin +++ /dev/null @@ -1,14 +0,0 @@ - - -<% skin name="head" %> - - - - - - - -
    <% skin name="navig" %><% response.body %>
    - - - diff --git a/src/dist/apps/manage/Global/head.skin b/src/dist/apps/manage/Global/head.skin deleted file mode 100644 index 45680b8e..00000000 --- a/src/dist/apps/manage/Global/head.skin +++ /dev/null @@ -1,59 +0,0 @@ - - <% response.title %> - - \ No newline at end of file diff --git a/src/dist/apps/manage/Global/macros.js b/src/dist/apps/manage/Global/macros.js deleted file mode 100644 index ee3fe97a..00000000 --- a/src/dist/apps/manage/Global/macros.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * macro rendering a skin - * @param name name of skin - */ -function skin_macro(par) { - if (par && par.name) { - renderSkin(par.name); - } -} - - -/** - * Macro returning the actual date and time. - */ -function now_macro() { - var date = new Date(); - return(date.format("dd.MM.yyyy, HH:mm'h' zzz")); -} diff --git a/src/dist/apps/manage/Global/navig.skin b/src/dist/apps/manage/Global/navig.skin deleted file mode 100644 index b7d93776..00000000 --- a/src/dist/apps/manage/Global/navig.skin +++ /dev/null @@ -1,30 +0,0 @@ - -

    ">" title="helma" border="0" width="174" height="35" align="baseline" style="border-width:3px;border-color:white;"> -

    - -
    - <% root.appCount filter="active" singular=" app" plural=" apps"%> on - "><% root.hostname %> (<% root.hostaddress %>) -
    - -<% root.appList filter="active" %> - -

    -
    - disabled apps: -
    - -<% root.appList filter="disabled" skin="navig_disabled" %> - -

    -

    - Information on helma.org:
    -

  • reference
    -
  • mailinglist
    -
  • svn
    -
  • download
    -

    - -

    -

  • ">generate server password -

    diff --git a/src/dist/apps/manage/Global/pwdfeedback.skin b/src/dist/apps/manage/Global/pwdfeedback.skin deleted file mode 100644 index f5003a67..00000000 --- a/src/dist/apps/manage/Global/pwdfeedback.skin +++ /dev/null @@ -1,20 +0,0 @@ - - - - - -
    - -Generated username and password for helma's manager:
    - -

    Please copy/paste this line into the server.properties file of your -helma installation.

    - -
    <% param.propsString %>
    - -

    After that proceed to ">the manage console, -enter your credentials and you should be allowed in.

    - -
    - - diff --git a/src/dist/apps/manage/Global/pwdform.skin b/src/dist/apps/manage/Global/pwdform.skin deleted file mode 100644 index 79b7c602..00000000 --- a/src/dist/apps/manage/Global/pwdform.skin +++ /dev/null @@ -1,28 +0,0 @@ - - - - - -
    - -Username and password for helma's manager:
    - -

    Please choose an username and password combination to access the -manage application of this server. They will be printed md5-encoded -in a format that you've got to copy/paste into the server.properties -file.

    - -<% param.msg %> -
    - (username)
    - (password)
    -
    -
    - -

    Warning: The used http-authorization transmits username and password -in an unsafe cleartext way. Therefore you're strongly discouraged to -use any given combination that is normally protected through SSH.

    - -
    - - diff --git a/src/dist/apps/manage/Global/renderFunctions.js b/src/dist/apps/manage/Global/renderFunctions.js deleted file mode 100644 index 280c5168..00000000 --- a/src/dist/apps/manage/Global/renderFunctions.js +++ /dev/null @@ -1,153 +0,0 @@ -function renderLink(docEl, param) { - var text = ""; - if (docEl.getType() == docEl.APPLICATION || docEl.getType() == docEl.PROTOTYPE) { - text = docEl.getName(); - } else if (docEl.getType() == docEl.SKIN) { - text = docEl.getName() + ".skin"; - } else if (docEl.getType() == docEl.MACRO) { - if (param.handler != "false" && docEl.getParentElement() && docEl.getParentElement().getName() != "global") { - text = docEl.getParentElement().getName() + "."; - } - var str = docEl.getName(); - if (str.indexOf("_macro")) { - text += str.substring(0, str.length - 6); - } - } else if (docEl.getType() == docEl.FUNCTION) { - text = docEl.getName() + "("; - var arr = docEl.listParameters(); - for (var i = 0; i < arr.length; i++) { - text += arr[i]; - if (i < arr.length - 1) - text += ", "; - } - text += ")"; - } else { - text = docEl.getName(); - } - param.href = docEl.href("main"); - if (!param.target) { - param.target = "main"; - } - return renderLinkTag(param) + text + ''; -} - - -function renderLinkTag(param) { - var sb = new java.lang.StringBuffer (); - sb.append(''); - return sb.toString(); -} - -/** - * renders the name of the location of a doc element. - */ -function renderLocation (docEl, param) { - return docEl.toString(); -} - -/** -* renders tag list. -* @param param.skin skin to render on found DocTags -* @param param.separator String printed between tags -* @param param.type type string (param|return|author|version|see) to filter tags. -*/ -function renderTags(docEl, param) { - var skinname = (param.skin) ? param.skin : "main"; - var type = param.type; - if (type == "params") - type = "param"; - else if (type == "returns") - type = "return"; - else if (type == "arg") - type = "param"; - var str = ""; - var arr = docEl.listTags(); - for (var i = 0; i < arr.length; i++) { - if (arr[i].getType() == type) { - if (type == "see" || type == "overrides") { - param.link = renderReference(arr[i], docEl); - } - str += arr[i].renderSkinAsString(skinname, param); - str += (param.separator) ? param.separator : ""; - } - } - return str; -} - - -/** - * renders a reference to functions in other prototypes, masks - * urls in a see tag - * (see- and overrides-tags) - * @param docTagObj - * @param docEl needed to be able to walk up to application object - */ -function renderReference(docTagObj, docEl) { - // prepare the text: - var text = docTagObj.getText(); - text = new java.lang.String (text); - text = text.trim(); - if (text.indexOf("http://") == 0) { - // an url is a simple job - return '' + text + ''; - } else { - // make sure we only use the first item in the text so that unlinked comments - // can follow, store & split the that - var tok = new java.util.StringTokenizer (text); - var tmp = tok.nextToken(); - text = " " + text.substring(tmp.length + 1); - var parts = tmp.split("."); - // try to find the application object - var obj = docEl; - while (obj != null) { - if (obj.getType() == Packages.helma.doc.DocElement.APPLICATION) { - var appObj = obj; - break; - } - obj = obj.getParentElement(); - } - var protoObj = appObj.getChildElement("prototype_" + parts[0]); - if (protoObj == null) { - // prototype wasn't found, return the unlinked tag - return tmp + text; - } - if (parts.length == 1) { - // no function specified, return the linked prototype - return '' + format(tmp) + '' + text; - } - // try to find a function object: - var arr = protoObj.listChildren(); - for (var i = 0; i < arr.length; i++) { - if (arr[i].getName() == parts [1]) { - return '' + format(tmp) + '' + text; - } - } - // function not found: - return tmp + text; - } -} - - -/** -* function rendering a comment. -* @param param.length comment is shortened to the given length. -* @returns string -*/ -function renderComment(docEl, param) { - var str = docEl.getComment(); - if (param.length) { - if (param.length < str.length) { - return str.substring(0, param.length) + " ..."; - } - } - return str; -} - diff --git a/src/dist/apps/manage/README.md b/src/dist/apps/manage/README.md deleted file mode 100644 index 81d4eaa6..00000000 --- a/src/dist/apps/manage/README.md +++ /dev/null @@ -1,26 +0,0 @@ -To get the manage application to work you need to - -- add it to the `apps.properties` file with the following line: - -``` -manage -```` - -- use a Helma distribution version 1.5 or higher. - -- add the following properties to the `server.properties` file: - -``` -allowAdmin = [comma-separated list of hosts or ip-addresses that - are allowed to access this application. wildcards - are only allowed in addresses, not in hostnames!] -adminAccess = -``` - -Creating the credentials can be done after you've got the application -up and running at this address: - -``` -http:///manage/makekey -``` - diff --git a/src/dist/apps/manage/Root/actions.js b/src/dist/apps/manage/Root/actions.js deleted file mode 100644 index 4c7c68a8..00000000 --- a/src/dist/apps/manage/Root/actions.js +++ /dev/null @@ -1,130 +0,0 @@ -/** - * main action, show server-stats - * perform start, stop, restart and flush-action - * - */ -function main_action() { - - if (checkAddress() == false) return; - - if (req.data.app != null && req.data.app != "" && req.data.action != null && req.data.action != "") { - - var appObj = root.getApp(req.data.app); - // check access for application. md5-encoded uname/pwd can also be put in - // app.properties to limit access to a single app - if (checkAuth(appObj) == false) return; - - if (req.data.action == "start") { - this.startApplication(req.data.app); - res.redirect(appObj.href("main")); - - } else if (req.data.action == "stop") { - if (checkAuth() == false) return; - this.stopApplication(req.data.app); - res.redirect(root.href("main")); - - } else if (req.data.action == "restart") { - this.stopApplication(req.data.app); - this.startApplication(req.data.app); - res.redirect(appObj.href("main")); - - } else if (req.data.action == "flush") { - appObj.clearCache(); - res.redirect(appObj.href("main")); - - } - - } - - // output only to root - if (checkAuth() == false) return; - - res.data.title = "Helma Object Publisher - Serverinfo"; - res.data.body = this.renderSkinAsString("main"); - renderSkin("global"); -} - -/** -* return the helma object publisher logo, built into hop core -* to be independent of static html-paths -*/ -function image_action() { - if (checkAddress() == false) return; - - res.contentType = "image/gif"; - res.writeBinary(Packages.helma.util.Logo.hop); -} - -function makekey_action() { - - if (checkAddress() == false) - return; - - var obj = new Object(); - obj.msg = ""; - if (req.data.username != null && req.data.password != null) { - - // we have input from webform - if (req.data.username == "") - obj.msg += "username can't be left empty!
    "; - if (req.data.password == "") - obj.msg += "password can't be left empty!
    "; - if (obj.msg != "") { - obj.username = req.data.username; - res.reset(); - res.data.body = renderSkinAsString("pwdform", obj); - } else { - // render the md5-string: - obj.propsString = "adminAccess=" + Packages.org.apache.commons.codec.digest.DigestUtils.md5Hex(req.data.username + "-" + req.data.password) + "
    \n"; - res.data.body = renderSkinAsString("pwdfeedback", obj); - } - - } else { - - // no input from webform, so print it - res.data.body = renderSkinAsString("pwdform", obj); - - } - - res.data.title = "username & password on " + root.hostname_macro(); - res.data.head = renderSkinAsString("head"); - renderSkin("basic"); -} - -/** -* prints server-stats for mrtg-tool. -* doesn't check username or password, so that we don't have -* to write them cleartext in a mrtg-configfile but checks the -* remote address. -*/ -function mrtg_action() { - - if (checkAddress() == false) - return; - - - if (req.data.action == "memory") { - - res.write(this.jvmTotalMemory_macro() + "\n"); - res.write(this.jvmFreeMemory_macro() + "\n"); - res.write("0\n0\n"); - - } else if (req.data.action == "netstat" && isLinux()) { - - var str = (new File("/proc/net/tcp")).readAll(); - var arr = str.split("\n"); - res.write(arr.length - 2 + "\n"); - res.write("0\n0\n0\n"); - - } else if (req.data.action == "loadavg" && isLinux()) { - - // load average of last 5 minutes: - var str = (new File("/proc/loadavg")).readAll(); - var arr = str.split(" "); - res.write(arr[1] * 100 + "\n"); - res.write("0\n0\n0\n"); - - } else { - res.write("0\n0\n0\n0\n"); - } -} diff --git a/src/dist/apps/manage/Root/functions.js b/src/dist/apps/manage/Root/functions.js deleted file mode 100644 index 9e8ead34..00000000 --- a/src/dist/apps/manage/Root/functions.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* renders the api of a given application. used from commandline. -*/ -function renderApi(appName) { - - // supress security checks when accessing actions - res.data.noWeb = true; - - // start the application - this.startApplication(appName); - var appObj = this.getApp(appName); - var docApp = appObj.getChildElement("api"); - - // now render the api - var ct = docApp.renderApi(); - writeln("rendered " + ct + " files"); - - // cleanup - this.stopApplication(appName); -} - - -/** - * lists all applications in appdir. - * for active apps use this.getApplications() = helma.main.Server.getApplications() - */ -function getAllApplications() { - var appsDir = this.getAppsHome(); - var dir = appsDir.listFiles(); - var arr = new Array(); - var seen = {}; - // first check apps directory for apps directories - if (dir) { - for (var i = 0; i < dir.length; i++) { - if (dir[i].isDirectory() && dir[i].name.toLowerCase() != "cvs") { - arr[arr.length] = this.getApp(dir[i].name); - seen[dir[i].name] = true; - } - } - } - // then check entries in apps.properties for apps not currently running - var props = wrapJavaMap(root.getAppsProperties(null)); - for (var i in props) { - if (i.indexOf(".") < 0 && !seen[i] && !root.getApplication(i)) { - arr[arr.length] = this.getApp(i); - } - } - return arr; -} - - -/** - * get application by name, constructs an hopobject of the prototype application - * if the app is not running (and therefore can't be access through - * helma.main.ApplicationManager). - * ATTENTION: javascript should not overwrite helma.main.Server.getApplication() which - * retrieves active applications. - * @arg name of application - */ -function getApp(name) { - if (name == null || name == "") - return null; - var appObj = this.getApplication(name); - if (appObj == null) - appObj = new Application(name); - return appObj; -} - -/** - * Method used by Helma path resolution. - */ -function getChildElement(name) { - return this.getApp(name); -} - - diff --git a/src/dist/apps/manage/Root/macros.js b/src/dist/apps/manage/Root/macros.js deleted file mode 100644 index 9fc795e0..00000000 --- a/src/dist/apps/manage/Root/macros.js +++ /dev/null @@ -1,284 +0,0 @@ -/** - * macro rendering a skin - * @param name name of skin - */ -function skin_macro(par) { - if (par && par.name) { - this.renderSkin(par.name); - } -} - - -/** - * macro-wrapper for href-function - * @param action name of action to call on this prototype, default main - */ -function href_macro(par) { - return this.href((par && par.action)?par.action:"main"); -} - - -/** - * macro returning the total number of sessions on this server - * @see global.formatCount - */ -function countSessions_macro(par) { - var arr = this.getApplications(); - var sum = 0; - for (var i = 0; i < arr.length; i++) { - if (arr[i].getName() != app.__app__.getName()) { - sum += arr[i].sessions.size(); - } - } - return sum + formatCount(sum, par); -} - - -/** - * macro returning the number of requests during the last 5 minutes - * @see global.formatCount - */ -function requestCount_macro(par) { - if (app.data.stat == null) { - return; - } - var arr = this.getApplications(); - var sum = 0; - for (var i = 0; i < arr.length; i++) { - if (arr[i].getName() != app.__app__.getName()) { // don't include manage app - var obj = app.data.stat[arr[i].name]; - if (obj != null) { - sum += obj.requestCount; - } - } - } - return sum + formatCount(sum, par); -} - - -/** - * macro returning the number of errors during the last 5 minutes - * @see global.formatCount - */ -function errorCount_macro(par) { - if (app.data.stat == null) { - return; - } - var arr = this.getApplications(); - var sum = 0; - for (var i = 0; i < arr.length; i++) { - if (arr[i].getName() != app.__app__.getName()) { // don't include manage app - var obj = app.data.stat[arr[i].name]; - if (obj != null) { - sum += obj.errorCount; - } - } - } - return sum + formatCount(sum, par); -} - - -function extensions_macro(par) { - var vec = this.getExtensions(); - var str = ""; - for (var i = 0; i < vec.size(); i++) { - str += vec.elementAt(i).getClass().getName(); - if (i != (vec.size() - 1)) { - str += (par && par.separator) ? par.separator : ", "; - } - } - return (str == "") ? null : str; -} - -/** - * Macro returning hostname of this machine - */ -function hostname_macro(par) { - return java.net.InetAddress.getLocalHost().getHostName() -} - - -/** - * Macro returning address of this machine - */ -function hostaddress_macro(par) { - return java.net.InetAddress.getLocalHost().getHostAddress() -} - - -/** - * Macro returning the number of running applications, - * the manage application being excluded. - */ -function appCount_macro(par) { - if (par && par.filter == "active") { - var ct = root.getApplications().length - 1; - } else if (par && par.filter == "disabled") { - var ct = root.getAllApplications().length - root.getApplications().length; - } else { - var ct = root.getAllApplications().length - 1; - } - return ct + formatCount(ct, par); -} - - -/** - * Macro that lists all running applications, - * the manage application being excluded (-1). - * @param skin skin of application that will be used. - */ -function appList_macro(par) { - var skin = (par && par.skin) ? par.skin : "navig_active"; - var apps = new Array(); - if (par && par.filter == "active") { - var arr = root.getApplications(); - for (var i = 0; i < arr.length; i++) { - apps[apps.length] = arr[i]; - } - } else if (par && par.filter == "disabled") { - var arr = root.getAllApplications(); - for (var i in arr) { - if (arr[i].isActive() == false) { - apps[apps.length] = arr[i]; - } - } - } else { - var apps = root.getAllApplications(); - } - apps = apps.sort(sortByName); - var html = ""; - var param = new Object(); - for (var n in apps) { - var a = apps[n]; - if (apps[n].name == app.__app__.getName()) - continue; - var item = a.renderSkinAsString(skin); - html += item; - } - return(html); -} - - -/** - * Macro that returns the server's uptime nicely formatted - */ -function uptime_macro() { - return formatAge((java.lang.System.currentTimeMillis() - this.starttime) / 1000); -} - - -/** - * Macro that returns the server's version string - */ -function version_macro() { - return this.version; -} - - -/** - * Macro that returns the home directory of the hop installation - */ -function home_macro() { - return this.getHopHome().toString(); -} - - -/** - * Macro that returns the free memory in the java virtual machine - * @param format if "hr", value will be printed human readable - */ -function jvmFreeMemory_macro(param) { - var m = java.lang.Runtime.getRuntime().freeMemory(); - return (param && param.hr) ? formatBytes(m) : m; -} - - -/** - * Macro that returns the total memory available to the java virtual machine - * @param format if "hr", value will be printed human readable - */ -function jvmTotalMemory_macro(param) { - var m = java.lang.Runtime.getRuntime().totalMemory(); - return (param && param.hr) ? formatBytes(m) : m; -} - - -/** - * Macro that returns the used memory in the java virtual machine - * @param format if "hr", value will be printed human readable - */ -function jvmUsedMemory_macro(param) { - var m = java.lang.Runtime.getRuntime().totalMemory() - java.lang.Runtime.getRuntime().freeMemory(); - return (param && param.hr) ? formatBytes(m) : m; -} - - -/** - * Macro that returns the version and type of the java virtual machine - */ -function jvm_macro() { - return java.lang.System.getProperty("java.version") + " " + java.lang.System.getProperty("java.vendor"); -} - - -/** - * Macro that returns the home directory of the java virtual machine - */ -function jvmHome_macro() { - return java.lang.System.getProperty("java.home"); -} - - -/** - * Macro that greps all jar-files from the class path variable and lists them. - * @param separator string that is printed between the items - */ -function jvmJars_macro(par) { - var separator = (par && par.separator ) ? par.separator : ", "; - var str = java.lang.System.getProperty("java.class.path"); - var arr = str.split(".jar"); - for (var i in arr) { - var str = arr[i]; - var pos = ( str.lastIndexOf('\\') > str.lastIndexOf('/') ) ? str.lastIndexOf('\\') : str.lastIndexOf('/'); - res.write(arr[i].substring(pos + 1) + ".jar"); - if (i < arr.length - 1) res.write(separator); - } -} - - -/** - * Macro that returns the name and version of the server's os - */ -function os_macro() { - return java.lang.System.getProperty("os.name") + " " + java.lang.System.getProperty("os.arch") + " " + java.lang.System.getProperty("os.version"); -} - - -/** - * Macro that returns anything from server.properties - */ -function property_macro(par) { - if (par && par.key) { - return this.getProperty(key); - } else { - return ""; - } -} - - -/** - * Macro formatting server.properties - */ -function properties_macro(par) { - formatProperties(this.getProperties(), par); -} - - -/** - * Macro that returns the timezone of this server - */ -function timezone_macro(par) { - return java.util.TimeZone.getDefault().getDisplayName(false, java.util.TimeZone.LONG) + " (" + java.util.TimeZone.getDefault().getID() + ")"; -} - - diff --git a/src/dist/apps/manage/Root/main.skin b/src/dist/apps/manage/Root/main.skin deleted file mode 100644 index 2bcebc29..00000000 --- a/src/dist/apps/manage/Root/main.skin +++ /dev/null @@ -1,111 +0,0 @@ -<% this.hostname %> (<% this.hostaddress %>)

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<% this.properties itemprefix='' %> -
    helma
    uptime: <% this.uptime %>
    version: <% this.version %>
    homedir: <% this.home %>
    total active sessions: <% this.countSessions default=" " %>
    total requests / 5 min: <% this.requestCount default=" " %>
    total errors / 5 min: <% this.errorCount default=" " %>
    loaded extensions: <% this.extensions default=" " %>
    jre
    free memory: <% this.jvmFreeMemory hr="true" %>
    used memory: <% this.jvmUsedMemory hr="true" %>
    total memory: <% this.jvmTotalMemory hr="true" %>
    java: <% this.jvm %>
    javahome: <% this.jvmHome %>
    os: <% this.os %>
    localtime: <% now %>
    timezone: <% this.timezone %>
    loaded Jars: <% this.jvmJars %>
    server.properties
    ' separator=' ' itemsuffix='
    - - - - diff --git a/src/dist/apps/manage/app.properties b/src/dist/apps/manage/app.properties deleted file mode 100644 index 83e08c43..00000000 --- a/src/dist/apps/manage/app.properties +++ /dev/null @@ -1,12 +0,0 @@ -# Set baseURI for application generated URLs, if necessary. -# baseURI = /manage - -# A short description of what this application is about: -_description = Helma's server management console. Start applications, introspection etc. - -# use higher request timeout because rendering the apidocs -# might take more than one minute on a slow computer -requestTimeout = 300 - -# run scheduler function each minute -cron.scheduler.function = scheduler diff --git a/src/dist/apps/manage/class.properties b/src/dist/apps/manage/class.properties deleted file mode 100644 index 4f48d3cc..00000000 --- a/src/dist/apps/manage/class.properties +++ /dev/null @@ -1,27 +0,0 @@ -# -# define the root class of this application -# -root = helma.main.Server - -# -# root.factory is used to retrieve the root class of the application -# when the instance has already been created when the application comes up. -# this is true for the helma server that is scripted here. -# -root.factory.class = helma.main.Server -root.factory.method = getServer - -# -# Map Java classes to the prototype used to script them -# and, yes, map the root class again. -# - -helma.main.Server = Root -helma.framework.core.Application = Application -helma.doc.DocApplication = DocApplication -helma.doc.DocPrototype = DocPrototype -helma.doc.DocFunction = DocFunction -helma.doc.DocProperties = DocFunction -helma.doc.DocSkin = DocFunction -helma.doc.DocTag = DocTag - diff --git a/src/dist/apps/test/README.md b/src/dist/apps/test/README.md deleted file mode 100644 index 2e554f6e..00000000 --- a/src/dist/apps/test/README.md +++ /dev/null @@ -1,10 +0,0 @@ -To run the tests, add something like this to your apps.properties file: - -test -test.appdir = apps/test/code -test.repository.0 = apps/test/code -test.repository.1 = modules/jala/util/Test/code - -And you need to have a JDBC driver for your database in lib/ext, -as well as create the database schema provided in one of the -db-.sql files. diff --git a/src/dist/apps/test/code/Global/global.js b/src/dist/apps/test/code/Global/global.js deleted file mode 100644 index b162d4d9..00000000 --- a/src/dist/apps/test/code/Global/global.js +++ /dev/null @@ -1,33 +0,0 @@ -function onStart() { - root.date = new Date(); - root.string = "root"; -} - -function hello_macro(param) { - return "hello"; -} - -function echo_macro(param, arg) { - return arg || param.what; -} - -function isDate_filter(arg) { - return arg instanceof Date; -} - -function isRootDate_filter(arg) { - return (arg instanceof Date) && - arg.getTime() == root.date.getTime(); -} - -function isResponseDate_filter(arg) { - return (arg instanceof Date) && arg == res.data.date; -} - -function makeLongString() { - var b = new java.lang.StringBuffer(); - for (var i = 1; i <= 10000; i++) { - b.append(i.toString()).append(" "); - } - return b.toString(); -} diff --git a/src/dist/apps/test/code/Global/subskins.skin b/src/dist/apps/test/code/Global/subskins.skin deleted file mode 100644 index 379245b9..00000000 --- a/src/dist/apps/test/code/Global/subskins.skin +++ /dev/null @@ -1 +0,0 @@ -mainskin<% #subskin1 %>subskin1<% #subskin2 %>subskin2<% #end %> diff --git a/src/dist/apps/test/code/Organisation/type.properties b/src/dist/apps/test/code/Organisation/type.properties deleted file mode 100644 index e5bbfbf2..00000000 --- a/src/dist/apps/test/code/Organisation/type.properties +++ /dev/null @@ -1,40 +0,0 @@ - -_db = dbcTest -_table = tb_organisation - -_id = org_id -_parent = root.organisations - -persons = collection(Person) -persons.local = org_id -persons.foreign = person_org_id -persons.accessname = person_name -persons.order = person_name - -range = collection(Person) -range.local = org_id -range.foreign = person_org_id -range.accessname = person_name -range.order = person_name -range.offset = 100 -range.maxsize = 100 - -generic = collection(Person) -generic.local.1 = $prototype -generic.foreign.1 = person_generic_prototype -generic.local.2 = $id -generic.foreign.2 = person_generic_id -generic.order = person_name - -groupedGeneric = collection(Person) -groupedGeneric.local.1 = $prototype -groupedGeneric.foreign.1 = person_generic_prototype -groupedGeneric.local.2 = $id -groupedGeneric.foreign.2 = person_generic_id -groupedGeneric.group = person_name -groupedGeneric.group.order = person_name - -name = org_name -country = org_country - -someMountpoint = mountpoint(SomeMountpoint) diff --git a/src/dist/apps/test/code/Person/type.properties b/src/dist/apps/test/code/Person/type.properties deleted file mode 100644 index c10baede..00000000 --- a/src/dist/apps/test/code/Person/type.properties +++ /dev/null @@ -1,17 +0,0 @@ - -_db = dbcTest -_table = tb_person - -_id = person_id -_parent = organisation.persons, root.persons - -name = person_name -height = person_height -dateOfBirth = person_dateofbirth - -organisation = object(Organisation) -organisation.local = person_org_id -organisation.foreign = org_id - -genericPrototype = person_generic_prototype -genericId = person_generic_id \ No newline at end of file diff --git a/src/dist/apps/test/code/Root/root.js b/src/dist/apps/test/code/Root/root.js deleted file mode 100644 index 4fe3c512..00000000 --- a/src/dist/apps/test/code/Root/root.js +++ /dev/null @@ -1,35 +0,0 @@ -function main_action() { - res.redirect(root.href("jala.test")); -} - -function hello_action() { - res.contentType = "text/plain"; - res.write("Hello"); -} - -function throwerror_action() { - throw Error(); -} - -function notfound_action() { - res.write("Not found"); -} - -function redirect_action() { - res.redirect(this.href("hello")); -} - -function error_action() { - res.write("Error"); -} - -function long_action() { - res.write(makeLongString()); -} - -function macro_macro(param) { - // change suffix - if (param.suffix) param.suffix = "."; - return this.string; -} - diff --git a/src/dist/apps/test/code/Root/type.properties b/src/dist/apps/test/code/Root/type.properties deleted file mode 100644 index 05a31029..00000000 --- a/src/dist/apps/test/code/Root/type.properties +++ /dev/null @@ -1,16 +0,0 @@ -date = date -string = string - - -organisations = collection(Organisation) -organisations.accessname = org_name - -organisationsByCountry = collection(Organisation) -organisationsByCountry.group = org_country -organisationsByCountry.group.prototype = Country -organisationsByCountry.group.order = org_country desc -organisationsByCountry.order = org_name desc - -persons = collection(Person) - -someMountpoint = mountpoint(SomeMountpoint) diff --git a/src/dist/apps/test/code/app.properties b/src/dist/apps/test/code/app.properties deleted file mode 100644 index 1d18bda0..00000000 --- a/src/dist/apps/test/code/app.properties +++ /dev/null @@ -1,3 +0,0 @@ -baseUri = http://localhost:8080/test/ -# hard-code cache size to default value to make sure there's some cache rotation -cacheSize = 500 diff --git a/src/dist/apps/test/code/db.properties b/src/dist/apps/test/code/db.properties deleted file mode 100644 index ebceb1a3..00000000 --- a/src/dist/apps/test/code/db.properties +++ /dev/null @@ -1,15 +0,0 @@ - -#MySQL -dbcTest.url = jdbc:mysql://localhost/helmaTest -dbcTest.driver = com.mysql.jdbc.Driver -dbcTest.user = helma -dbcTest.password = secret - -# Oracle -# dbcTest.url = jdbc:oracle:thin:@localhost:1521:XE -# dbcTest.driver = oracle.jdbc.driver.OracleDriver - -# PostgreSQL -# dbcTest.url = jdbc:postgresql:helmaTest -# dbcTest.driver = org.postgresql.Driver - diff --git a/src/dist/apps/test/db-mysql.sql b/src/dist/apps/test/db-mysql.sql deleted file mode 100644 index b5559d90..00000000 --- a/src/dist/apps/test/db-mysql.sql +++ /dev/null @@ -1,26 +0,0 @@ - -CREATE DATABASE IF NOT EXISTS helmaTest; -USE helmaTest; - -GRANT ALL ON helmaTest.* TO helma@localhost IDENTIFIED BY 'secret'; - -DROP TABLE IF EXISTS tb_person; -DROP TABLE IF EXISTS tb_organisation; - -CREATE TABLE tb_person ( - person_id MEDIUMINT(10) NOT NULL, - person_name TINYTEXT, - person_height TINYINT unsigned, - person_dateofbirth DATETIME, - person_org_id MEDIUMINT(10) unsigned, - person_generic_prototype VARCHAR(30), - person_generic_id MEDIUMINT(10) unsigned, - PRIMARY KEY (person_id) -); - -CREATE TABLE tb_organisation ( - org_id MEDIUMINT(10) unsigned NOT NULL, - org_name TINYTEXT, - org_country TINYTEXT, - PRIMARY KEY (org_id) -); diff --git a/src/dist/apps/test/db-oracle.sql b/src/dist/apps/test/db-oracle.sql deleted file mode 100644 index 817396e3..00000000 --- a/src/dist/apps/test/db-oracle.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE tb_person ( - person_id NUMBER(10) NOT NULL, - person_name VARCHAR2(255), - person_height NUMBER(10), - person_dateofbirth DATE, - person_org_id NUMBER(10), - PRIMARY KEY (person_id) -); - -CREATE TABLE tb_organisation ( - org_id NUMBER(10) NOT NULL, - org_name VARCHAR2(255), - org_country VARCHAR2(255), - PRIMARY KEY (org_id) -); diff --git a/src/dist/apps/test/db-postgresql.sql b/src/dist/apps/test/db-postgresql.sql deleted file mode 100644 index d93e9b41..00000000 --- a/src/dist/apps/test/db-postgresql.sql +++ /dev/null @@ -1,20 +0,0 @@ - -CREATE TABLE tb_person ( - person_id INTEGER NOT NULL, - person_name VARCHAR(100), - person_height INTEGER, - person_dateofbirth TIMESTAMP, - person_org_id INTEGER, - PRIMARY KEY (person_id) -); - -CREATE TABLE tb_organisation ( - org_id INTEGER NOT NULL, - org_name VARCHAR(100), - org_country VARCHAR(100), - PRIMARY KEY (org_id) -); - -CREATE USER helma WITH PASSWORD 'secret'; -GRANT insert, delete, select, update ON tb_person, tb_organisation TO helma; - diff --git a/src/dist/apps/test/tests/HopObjectBasicMapping.js b/src/dist/apps/test/tests/HopObjectBasicMapping.js deleted file mode 100644 index c8164682..00000000 --- a/src/dist/apps/test/tests/HopObjectBasicMapping.js +++ /dev/null @@ -1,148 +0,0 @@ -tests = [ - "testEquality", - "testSimpleMapping", - "testSimpleCollection", - "testObjectReference", - "testCollectionForReference" -]; - -function setup() { -} - -function testEquality() { - var person = new Person(); - root.persons.add(person); - res.commit(); - var id = person._id; - app.clearCache(); - var person2 = root.persons.get(id); - assertNotNull(person2); - assertTrue(person !== person2); - assertTrue(person._id === person2._id); - assertTrue(person == person2); - person.remove(); -} - -function testSimpleMapping() { - - var data = { - name: "Oliver Stone", - dateOfBirth: new Date(1946, 8, 15, 6, 0, 0), - height: 182 - }; - var person = new Person(); - person.name = data.name; - person.dateOfBirth = data.dateOfBirth; - person.height = data.height; - root.persons.add(person); - var personId = person._id; - - res.commit(); // Commit Transaction - app.clearCache(); // Clear cache so that object is refetched - - var person = Person.getById(personId); - assertNotNull(person); - assertEqual(person._prototype, "Person"); - assertEqual(person._id, personId); - assertEqual(person.name, data.name); - assertEqual(person.height, data.height); - assertEqual(person.dateOfBirth.valueOf(), data.dateOfBirth.valueOf()); - res.commit(); - - person.remove(); -} - -function testSimpleCollection() { - - var data = { - name: "Helma" - }; - var orgCount = root.organisations.count(); - var org = new Organisation(); - org.name = data.name; - root.organisations.add(org); - var orgId = org._id; - - assertEqual(orgCount + 1, root.organisations.count()); - assertNotEqual(root.organisations.indexOf(org), -1); - - // fetch Object via position - assertEqual(root.organisations.get(root.organisations.indexOf(org)), org); - - // fetch Object via accessname - assertEqual(root.organisations.get(data.name), org); - - // fetch Object via id - assertEqual(root.organisations.getById(orgId), org); - - // test list - assertEqual(root.organisations.count(), root.organisations.list().length); - - org.remove(); - - assertEqual(orgCount, root.organisations.count()); - assertEqual(root.organisations.indexOf(org), -1); - assertNull(root.organisations.get(data.name)); - assertNull(root.organisations.getById(orgId)); - -} - - -function testObjectReference() { - - var org = new Organisation(); - org.name = "Helma"; - root.organisations.add(org); - var orgId = org._id; - - var person = new Person(); - person.name = "Hannes"; - person.organisation = org; - root.persons.add(person); - var personId = person._id; - - res.commit(); // Commit Transaction - app.clearCache(); // Clear cache so that object is refetched - - var org = Organisation.getById(orgId); - var person = Person.getById(personId); - assertEqual(person.organisation, org); - - org.remove(); - res.commit(); // Commit Transaction - - assertNull(person.organisation); - - person.remove(); -} - - -function testCollectionForReference() { - - var org = new Organisation(); - org.name = "Helma"; - root.organisations.add(org); - var orgId = org._id; - var personCount = org.persons.count(); - - var person = new Person(); - person.name = "Hannes"; - person.organisation = org; - root.persons.add(person); - org.persons.add(person); - - assertEqual(personCount + 1, org.persons.count()); - assertNotEqual(org.persons.indexOf(person), -1); - - org.persons.removeChild(person); - person.remove(); - - assertEqual(personCount, org.persons.count()); - assertEqual(org.persons.indexOf(person), -1); - - org.remove(); -} - - -function cleanup() { -} diff --git a/src/dist/apps/test/tests/HopObjectCollection.js b/src/dist/apps/test/tests/HopObjectCollection.js deleted file mode 100644 index 7971114d..00000000 --- a/src/dist/apps/test/tests/HopObjectCollection.js +++ /dev/null @@ -1,183 +0,0 @@ -tests = [ - "testSize", - "testMaxSize", - "testAddSmall", - "testAddLarge", - "testRemoveSmall", - "testRemoveLarge", - "testUpdateSmall", - "testUpdateLarge", - "testListSmall", - "testListLarge", - "testOrderLarge", - "testOrderSmall" -]; - -var helma, ikea; -var small = 3, large = 1234; - -function setup() { - ikea = makeOrg('Ikea', large); - helma = makeOrg('Helma', small); -} - -function testSize() { - assertEqual(ikea.persons.size(), large); - assertEqual(helma.persons.size(), small); -} - -function testMaxSize() { - assertEqual(ikea.range.size(), 100); - assertEqual(helma.range.size(), 0); - var person = ikea.range.get("Person Ikea 0150"); - assertNotNull(person); - assertEqual(person, ikea.range.get(50)); - assertEqual(person, ikea.persons.get(150)); - assertEqual(50, ikea.range.indexOf(person)); - assertEqual(150, ikea.persons.indexOf(person)); -} - -function testAddSmall() { - testAdd(helma, small); -} - -function testAddLarge() { - testAdd(ikea, large); -} - -// test directly adding to a collection -function testAdd(org, size) { - var person = new Person(); - person.name = "TestPerson"; - org.persons.add(person); - assertEqual(org.persons.size(), size + 1); - assertEqual(org.persons.indexOf(person), size); - assertEqual(org.persons.contains(person), size); - assertEqual(person.href(), org.persons.href() + "TestPerson/"); - // make sure the add has set the back-reference on the person object. - // note that === comparison will return false if the - // collection size exceeds the cache size. - assertTrue(person.organisation == org); -} - -function testRemoveSmall() { - testRemove(helma, small); -} - -function testRemoveLarge() { - testRemove(ikea, large); -} - -// test directly removing from a collection -function testRemove(org, size) { - var person = org.persons.get(org.persons.size() - 1); - person.remove(); - assertEqual(org.persons.size(), size); - assertEqual(org.persons.indexOf(person), -1); - assertEqual(org.persons.contains(person), -1); -} - -function testUpdateSmall() { - testUpdate(helma, small); -} - -function testUpdateLarge() { - testUpdate(ikea, large); -} - -// test indirectly adding to and removing form a collection -function testUpdate(org, size) { - var person = new Person(); - person.name = "TestPerson"; - person.organisation = org; - person.persist(); - res.commit(); - assertEqual(org.persons.size(), size + 1); - org.persons.prefetchChildren(); - assertEqual(org.persons.indexOf(person), size); - assertEqual(org.persons.contains(person), size); - assertEqual(person.href(), org.persons.href() + "TestPerson/"); - person.remove(); - res.commit(); - assertEqual(org.persons.size(), size); - assertEqual(org.persons.indexOf(person), -1); - assertEqual(org.persons.contains(person), -1); -} - -function testListSmall() { - testList(helma, small); -} - -function testListLarge() { - testList(ikea, large); -} - -function testList(org, size) { - function iterate(list, start, length) { - assertEqual(list.length, length); - for (var i = 0; i < length; i++) { - assertEqual(list[i].name, "Person " + org.name + (start + i).format(" 0000")); - } - } - iterate(org.persons.list(), 0, size); - org.persons.invalidate(); - iterate(org.persons.list(), 0, size); - org.persons.invalidate(); - iterate(org.persons.list(1, size - 2), 1, size - 2); -} - -function testOrderLarge() { - testOrder(ikea, ikea.persons.size() - 2); - testOrder(ikea, Math.floor(ikea.persons.size() / 2)); - testOrder(ikea, 2); -} - -function testOrderSmall() { - testOrder(helma, helma.persons.size() - 1); - testOrder(helma, 1); - testOrder(helma, 0); -} - -function testOrder(org, pos) { - var person = new Person(); - person.name = "Person " + org.name + pos.format(" 0000") + "B"; - person.organisation = org; - root.persons.add(person); - res.commit(); - assertEqual(pos + 1, org.persons.indexOf(person)); -} - -function cleanup() { - var persons = root.persons.list(); - for (let person of persons) { - person.remove(); - } - ikea.remove(); - helma.remove(); -} - -function makeOrg(name, size) { - var org = new Organisation(); - org.name = name; - root.organisations.add(org); - - for (var i = 0; i < size; i++) { - var person = new Person(); - person.name = "Person " + name + i.format(" 0000"); - person.organisation = org; - root.persons.add(person); - } - res.commit(); - return org; -} - -// debugging helpers -function dumpDataChange(message) { - res.debug(message + ": "); - dumpDataChangeFor("Person"); - dumpDataChangeFor("Organisation"); -} - -function dumpDataChangeFor(name) { - res.debug(name + ": " + app.__app__.getDbMapping(name).getLastDataChange()); -} diff --git a/src/dist/apps/test/tests/HopObjectGeneric.js b/src/dist/apps/test/tests/HopObjectGeneric.js deleted file mode 100644 index 37d4eb99..00000000 --- a/src/dist/apps/test/tests/HopObjectGeneric.js +++ /dev/null @@ -1,93 +0,0 @@ -tests = [ - 'testSize', - 'testContent', - 'testGroupContent', - 'testRemove', - 'testAdd' -]; - -var org; -var size = 16; - -function setup() { - org = new Organisation(); - org.name = "GenericOrg"; - var i = 0, person; - - function addPerson(collection) { - person = new Person(); - person.name = "GenericPerson " + i.format("00"); - collection.add(person); - i++; - } - - // add first half to both collections of transient parent ... - while (i < 4) - addPerson(org.generic); - while (i < 8) - addPerson(org.groupedGeneric); - root.organisations.add(org); - // ... second half to both collections of persistent parent. - while (i < 12) - addPerson(org.generic); - while (i < size) - addPerson(org.groupedGeneric); - - res.commit(); -} - -function testSize() { - assertEqual(org.generic.size(), size); - org.invalidate(); - assertEqual(org.generic.size(), size); -} - -function testContent() { - var list = org.generic.list(); - assertEqual(list.length, size); - for (var i = 0; i < list.length; i++) { - assertEqual(list[i].name, "GenericPerson " + i.format("00")); - } -} - -function testGroupContent() { - var list = org.groupedGeneric.list(); - assertEqual(list.length, size); - for (var i = 0; i < list.length; i++) { - assertEqual(list[i].groupname, "GenericPerson " + i.format("00")); - assertEqual(list[i].size(), 1); - assertEqual(list[i].get(0).name, "GenericPerson " + i.format("00")); - } -} - -function testRemove() { - var person = org.generic.get(size/2); - org.generic.removeChild(person); - assertEqual(org.generic.size(), size - 1); - res.rollback(); - // note: removeChild does not remove the node, nor does it - // unset the constraints between parent and child, so after a rollback - // the object is back in place. While this behaviour is disputable, - // until this is so we test for it. - assertEqual(org.generic.size(), size); -} - -function testAdd() { - var person = new Person(); - org.generic.add(person); - assertEqual(org.generic.size(), size + 1); - assertEqual(org.groupedGeneric.size(), size); - res.commit(); - // note: even after commit the grouped collection must not grow - // since we added a person without a name - assertEqual(org.generic.size(), size + 1); - assertEqual(org.groupedGeneric.size(), size); -} - -function cleanup() { - var persons = org.generic.list(); - for (let person of persons) { - person.remove(); - } - org.remove(); -} diff --git a/src/dist/apps/test/tests/HopObjectGroupBy.js b/src/dist/apps/test/tests/HopObjectGroupBy.js deleted file mode 100644 index 88a02818..00000000 --- a/src/dist/apps/test/tests/HopObjectGroupBy.js +++ /dev/null @@ -1,149 +0,0 @@ -tests = [ - "testGroupByAddRemoveCommit", - "testGroupByAddRemoveNoCommit", - "testGroupOrder", - "testGroupTransient" -]; - -// todo: run with different sizes -var size = 1234; - -function setup() { - for (var i = 0; i < size; i++) { - var org = new Organisation(); - org.name = "Organisation " + i; - org.country = "CH" + i.format("0000"); - // add to different collections - if (i % 2 == 0) - root.organisations.add(org); - else - root.organisationsByCountry.add(org); - } - res.commit(); -} - -function testGroupByAddRemoveCommit() { - var countryCount = root.organisationsByCountry.count(); - var org = new Organisation(); - org.country = "AT" + Math.random(); - org.name = "Helma" + Math.random(); - root.organisations.add(org); - res.commit(); // Commit Transaction - - var country = root.organisationsByCountry.get(org.country); - assertEqual(countryCount + 1, root.organisationsByCountry.count()); - assertNotNull(country); - assertEqual(country._prototype, "Country"); - assertEqual(country._id, org.country); - - org.remove(); - res.commit(); // Commit Transaction - - assertNull(root.organisationsByCountry.get(org.country)); - assertEqual(countryCount, root.organisationsByCountry.count()); -} - -function testGroupByAddRemoveNoCommit() { - - var countryCount = root.organisationsByCountry.count(); - var org = new Organisation(); - org.country = "AT" + Math.random(); - org.name = "Helma" + Math.random(); - root.organisations.add(org); - root.organisationsByCountry.add(org); - - // FIXME HELMABUG: count does not get incremented immediately - assertEqual(countryCount + 1, root.organisationsByCountry.count()); - - var country = root.organisationsByCountry.get(org.country); - assertNotNull(country); - assertEqual(country._prototype, "Country"); - assertEqual(country._id, org.country); - assertEqual(country.count(), 1); - assertEqual(country.get(0), org); - - root.organisationsByCountry.removeChild(org); - org.remove(); - - // FIXME HELMABUG: country is still accessible at this point - // similar to http://helma.org/bugs/show_bug.cgi?id=551 - assertNull(root.organisationsByCountry.get(org.country)); - - assertEqual(countryCount, root.organisationsByCountry.count()); -} - -function testGroupOrder() { - - var org1 = new Organisation(); - org1.country = "AT"; - org1.name = "Helma" + Math.random(); - root.organisations.add(org1); - - var org2 = new Organisation(); - org2.country = "CH01"; // pre-populated items have countries CH0000..C1234 - org2.name = "Helma" + Math.random(); - root.organisations.add(org2); - - var org3 = new Organisation(); - org3.country = "DE"; - org3.name = "Helma" + Math.random(); - root.organisations.add(org3); - - var org4 = new Organisation(); - org4.country = org3.country; - org4.name = "Helma" + Math.random(); - root.organisations.add(org4); - - res.commit(); - - // make sure that countries and organisations are sorted in decreasing order (as specified in type.properties) - var countries = root.organisationsByCountry.list(); - assertEqual(countries.length, size + 3); - for (var i = 0; i < countries.length; i++) { - if (i>0) { - assertTrue(root.organisationsByCountry.get(i-1).groupname >= root.organisationsByCountry.get(i).groupname); - } - for (var j = 0; j < root.organisationsByCountry.get(i); j++) { - if (j > 0) { - assertTrue(root.organisationsByCountry.get(i).get(j-1).groupname >= root.organisationsByCountry.get(i).get(j).groupname); - } - } - } - - org1.remove(); - org2.remove(); - org3.remove(); - org4.remove(); -} - -function testGroupTransient() { - - var temp = new Root(); - var countryCount = temp.organisationsByCountry.count(); - var org = new Organisation(); - org.country = "AT" + Math.random(); - org.name = "Helma" + Math.random(); - temp.organisationsByCountry.add(org); - - var country = temp.organisationsByCountry.get(org.country); - assertEqual(countryCount + 1, temp.organisationsByCountry.count()); - assertNotNull(country); - assertEqual(country._prototype, "Country"); - assertEqual(country.groupname, org.country); - - // These don't work as org uses the parent from type.properties - // which is root.organisations. Not sure if this is a bug or not. - // assertEqual(country, org._parent); - // org.remove(); - country.removeChild(org); - - assertNull(root.organisationsByCountry.get(org.country)); - assertEqual(countryCount, temp.organisationsByCountry.count()); -} - -function cleanup() { - var orgs = root.organisations.list(); - for (let org of orgs) { - org.remove(); - } -} diff --git a/src/dist/apps/test/tests/HopObjectHref.js b/src/dist/apps/test/tests/HopObjectHref.js deleted file mode 100644 index 9515b3b5..00000000 --- a/src/dist/apps/test/tests/HopObjectHref.js +++ /dev/null @@ -1,56 +0,0 @@ -tests = [ - "testSimpleParent", - "testFallbackParent", - "testMountpoints" -]; - - -var org; -var person1; -var person2; - -function setup() { - org = new Organisation(); - org.name = "Helma"; - root.organisations.add(org); - - person1 = new Person(); - person1.name = "Hannes"; - person1.organisation = org; - root.persons.add(person1); - - person2 = new Person(); - person2.name = "Michi"; - root.persons.add(person2); -} - -function testSimpleParent() { - assertEqual(org.href(), root.organisations.href() + org.name + "/"); - assertEqual(root.organisations, org._parent); - assertEqual(root, org._parent._parent); -} - -function testFallbackParent() { - assertEqual(person1.href(), person1.organisation.persons.href() + person1.name + "/"); - assertEqual(person1.organisation.persons, person1._parent); - - assertEqual(person2.href(), root.persons.href() + person2._id + "/"); - assertEqual(root.persons, person2._parent); -} - -function testMountpoints() { - assertEqual(root.someMountpoint._prototype, "SomeMountpoint"); - assertEqual(root.someMountpoint._parent, root); - assertEqual(root.someMountpoint.href(), root.href() + "someMountpoint/"); - - assertEqual(org.someMountpoint._prototype, "SomeMountpoint"); - assertEqual(org.someMountpoint._parent, org); - // FIXME: Helma-Bug ? mountpoints are converted to lower case ? - assertEqual(org.someMountpoint.href(), org.href() + "someMountpoint/"); -} - -function cleanup() { - org.remove(); - person1.remove(); - person2.remove(); -} diff --git a/src/dist/apps/test/tests/HopObjectReference.js b/src/dist/apps/test/tests/HopObjectReference.js deleted file mode 100644 index e97f8700..00000000 --- a/src/dist/apps/test/tests/HopObjectReference.js +++ /dev/null @@ -1,40 +0,0 @@ -tests = [ - "testForward", - "testBackward", -]; - -function setup() { - var org = new Organisation(); - var person = new Person(); - org.name = "Acme Hovercraft"; - person.name = "Murray Feather"; - person.organisation = org; - org.person = person; - person.persist(); - res.commit(); -} - -function testForward() { - app.clearCache(); - person = root.persons.get(0); - org = root.organisations.get(0); - assertEqual(person.organisation, org); - assertEqual(person.organisation.name, org.name); - assertEqual("Acme Hovercraft", org.name); -} - -function testBackward() { - app.clearCache(); - var person = root.persons.get(0); - var org = root.organisations.get(0); - assertEqual(org.person, person); - assertEqual(org.person.name, person.name); - assertEqual("Murray Feather", person.name); -} - -function cleanup() { - var person = root.persons.get(0); - var org = root.organisations.get(0); - org.remove(); - person.remove(); -} diff --git a/src/dist/apps/test/tests/Skin.js b/src/dist/apps/test/tests/Skin.js deleted file mode 100644 index e8f5c3c3..00000000 --- a/src/dist/apps/test/tests/Skin.js +++ /dev/null @@ -1,319 +0,0 @@ -var tests = [ - "testCommentMacro", - "testDeepResolve", - "testDeepUnhandled", - "testDeep", - "testDeepFail", - "testDeepFailSilent", - "testJavaProp", - "testJavaMissing", - "testJavaMissingSilent", - "testJavaMissingVerbose", - "testUndefinedHandler", - "testJSProp", - "testJSMacro", - "testJSFunction", - "testJSMissing", - "testJSMissingSilent", - "testJSMissingVerbose", - "testDateFilter", - "testNestedRootMacro", - "testNestedParamMacro", - "testNestedResponseMacro", - "testNestedPrefixSuffix", - "testResponseProp", - "testResponseMacro", - "testResponseFunction", - "testResponseMissing", - "testResponseMissingSilent", - "testResponseMissingVerbose", - "testRootProp", - "testRootMacro", - "testRootMissing", - "testRootMissingSilent", - "testRootMissingVerbose", - "testSessionProp", - "testSessionMacro", - "testSessionFunction", - "testSessionMissing", - "testSessionMissingDefault", - "testSessionMissingSilent", - "testSessionMissingVerbose", - "testSessionDeepMissing", - "testSubskins" -]; - -var setup = function() { - res.handlers.color = new java.awt.Color["(int,int,int)"](0, 255, 0); - res.handlers.file = new java.io.File["(java.lang.String,java.lang.String)"](null, "file"); - res.handlers.jsobject = { - banana: "yellow", - kiwi_macro: function() { return this.kiwiColor }, - apple: function() {}, - kiwiColor: "green" - }; - res.data.date = new Date(); - res.data.banana = "yellow"; - res.data.kiwi_macro = function() { return "green" }; - res.data.apple = function() {}; - session.data.banana = "yellow"; - session.data.kiwi_macro = function() { return "green" }; - session.data.apple = function() {}; -}; - -var testCommentMacro = function() { - var skin = createSkin("<% // this.foo bar=<% this.foobar %> FIXME %>ok"); - var result = renderSkinAsString(skin); - assertEqual(result, "ok"); -} - -var testDeepResolve = function() { - res.handlers.deep = { - getMacroHandler: function(name) { - if (name != "foo") return null; - return { - bar_macro: function() { - return "ok"; - } - } - } - } - var result = renderSkinAsString(createSkin("<% deep.foo.bar %>")); - assertEqual(result, "ok"); -}; - -var testDeepUnhandled = function() { - res.handlers.deep = { - getMacroHandler: function(name) { - if (name != "foo") return null; - return { - onUnhandledMacro: function(name) { - if (name == "bar") return "ok"; - } - } - } - } - var result = renderSkinAsString(createSkin("<% deep.foo.bar %>")); - assertEqual(result, "ok"); -}; - -var testDeep = function() { - res.handlers.deep = { - foo: { - bar: "ok" - } - } - var result = renderSkinAsString(createSkin("<% deep.foo.bar %>")); - assertEqual(result, "ok"); -}; - -var testDeepFail = function() { - var result = renderSkinAsString(createSkin("<% root.foo.bar %>")); - assertStringContains(result, "Unhandled"); - var result = renderSkinAsString(createSkin("<% root.foo.bar failmode=silent %>")); - assertEqual(result, ""); -}; - -var testDeepFailSilent = function() { - res.handlers.deep = { - foo: {} - }; - var result = renderSkinAsString(createSkin("<% deep.foo.bar %>")); - assertEqual(result, ""); - var result = renderSkinAsString(createSkin("<% deep.foo.bar failmode=verbose %>")); - assertStringContains(result, "Unhandled"); -}; - - -var testJavaProp = function() { - var result = renderSkinAsString(createSkin("<% color.green %>")); - assertEqual(result, "255"); - result = renderSkinAsString(createSkin("<% color.red %>")); - assertEqual(result, "0"); -}; - -var testJavaMissing = function() { - var result = renderSkinAsString(createSkin("<% colo.foo %>")); - assertStringContains(result, "Unhandled"); -}; - -var testJavaMissingSilent = function() { - var result = renderSkinAsString(createSkin("<% color.foo failmode=silent default=ok %>")); - assertEqual(result, "ok"); -}; - -var testJavaMissingVerbose = function() { - var result = renderSkinAsString(createSkin("<% color.foo failmode=verbose %>")); - assertStringContains(result, "Unhandled"); -} - -var testUndefinedHandler = function() { - var result = renderSkinAsString(createSkin("<% file.parentFile %>")); - assertEqual(result, ""); -}; - -var testJSProp = function() { - var result = renderSkinAsString(createSkin("<% jsobject.banana %>")); - assertEqual(result, "yellow"); -}; - -var testJSMacro = function() { - var result = renderSkinAsString(createSkin("<% jsobject.kiwi %>")); - assertEqual(result, "green"); -}; - -var testJSFunction = function() { - var result = renderSkinAsString(createSkin("<% jsobject.apple failmode=silent %>")); - assertEqual(result, ""); -}; - -var testJSMissing = function() { - var result = renderSkinAsString(createSkin("<% jsobject.papaya %>")); - assertEqual(result, ""); -}; - -var testJSMissingSilent = function() { - var result = renderSkinAsString(createSkin("<% jsobject.papaya failmode=silent %>")); - assertEqual(result, ""); -}; - -var testJSMissingVerbose = function() { - var result = renderSkinAsString(createSkin("<% jsobject.papaya failmode=verbose %>")); - assertStringContains(result, "Unhandled"); -}; - -var testDateFilter = function() { - var result = renderSkinAsString(createSkin("<% root.date | isDate %>")); - assertEqual(result, "true"); -}; - -var testNestedRootMacro = function() { - var skin = "<% echo <% root.date %> | isRootDate %>"; - var result = renderSkinAsString(createSkin(skin)); - assertEqual(result, "true"); -} - -var testNestedParamMacro = function() { - var skin = "<% echo <% param.date %> | isDate %>"; - var result = renderSkinAsString(createSkin(skin), { date: new Date() }); - assertEqual(result, "true"); -} - - -var testNestedResponseMacro = function() { - var skin = "<% echo what=<% response.date %> | isResponseDate %>"; - var result = renderSkinAsString(createSkin(skin)); - assertEqual(result, "true"); -}; - -var testNestedPrefixSuffix = function() { - var skin = "<% root.macro prefix=<% root.string %> suffix=<% root.macro %> %>"; - var result = renderSkinAsString(createSkin(skin)); - // root.macro changes suffix to "." - assertEqual(result, "rootroot."); -} - -var testResponseProp = function() { - var result = renderSkinAsString(createSkin("<% response.banana %>")); - assertEqual(result, "yellow"); -}; - -var testResponseMacro = function() { - var result = renderSkinAsString(createSkin("<% response.kiwi %>")); - assertEqual(result, "green"); -}; - -var testResponseFunction = function() { - var result = renderSkinAsString(createSkin("<% response.apple failmode=silent %>")); - assertEqual(result, ""); -}; - -var testResponseMissing = function() { - var result = renderSkinAsString(createSkin("<% response.papaya %>")); - assertEqual(result, ""); -}; - -var testResponseMissingSilent = function() { - var result = renderSkinAsString(createSkin("<% response.papaya failmode=silent %>")); - assertEqual(result, ""); -}; - -var testResponseMissingVerbose = function() { - var result = renderSkinAsString(createSkin("<% response.papaya failmode=verbose %>")); - assertStringContains(result, "Unhandled"); -}; - -var testRootProp = function() { - var result = renderSkinAsString(createSkin("<% root.string %>")); - assertEqual(result, "root"); -}; - -var testRootMacro = function() { - var result = renderSkinAsString(createSkin("<% root.macro %>")); - assertEqual(result, "root"); -}; - -var testRootMissing = function() { - var result = renderSkinAsString(createSkin("<% root.undefinedmacro %>")); - assertStringContains(result, "Unhandled"); -}; - -var testRootMissingSilent = function() { - var result = renderSkinAsString(createSkin("<% root.undefinedmacro failmode=silent %>")); - assertEqual(result, ""); -}; - -var testRootMissingVerbose = function() { - var result = renderSkinAsString(createSkin("<% root.undefinedmacro failmode=verbose %>")); - assertStringContains(result, "Unhandled"); -}; - -var testSessionProp = function() { - var result = renderSkinAsString(createSkin("<% session.banana %>")); - assertEqual(result, "yellow"); -}; - -var testSessionMacro = function() { - var result = renderSkinAsString(createSkin("<% session.kiwi %>")); - assertEqual(result, "green"); -}; - -var testSessionFunction = function() { - var result = renderSkinAsString(createSkin("<% session.apple failmode=silent %>")); - assertEqual(result, ""); -}; - -var testSessionMissingDefault = function() { - var result = renderSkinAsString(createSkin("<% session.papaya default=nope %>")); - assertEqual(result, "nope"); -}; - -var testSessionMissing = function() { - var result = renderSkinAsString(createSkin("<% session.papaya %>")); - assertEqual(result, ""); -}; - -var testSessionMissingSilent = function() { - var result = renderSkinAsString(createSkin("<% session.papaya failmode=silent %>")); - assertEqual(result, ""); -}; - -var testSessionMissingVerbose = function() { - var result = renderSkinAsString(createSkin("<% session.papaya failmode=verbose %>")); - assertStringContains(result, "Unhandled"); -}; - -var testSessionDeepMissing = function() { - var result = renderSkinAsString(createSkin("<% session.user.name %>")); - assertStringContains(result, "Unhandled"); - // assertEqual(result, ""); -}; - -var testSubskins = function() { - var result = renderSkinAsString("subskins"); - assertEqual(result, "mainskin"); - result = renderSkinAsString("subskins#subskin1"); - assertEqual(result, "subskin1"); - result = renderSkinAsString("subskins#subskin2"); - assertEqual(result, "subskin2"); -}; diff --git a/src/dist/apps/test/tests/helma.Http.js b/src/dist/apps/test/tests/helma.Http.js deleted file mode 100644 index 3cd51cf8..00000000 --- a/src/dist/apps/test/tests/helma.Http.js +++ /dev/null @@ -1,68 +0,0 @@ -var tests = [ - "testSimple", - "testError", - "testNotFound", - "testRedirect", - "testRedirectNoFollow", - "testMaxResponseSize", - "testLongResponse" -]; - -app.addRepository("modules/helma/Http.js"); - -var http = new helma.Http(); - -var testSimple = function() { - var result = http.getUrl(root.href("hello")); - assertEqual(result.content, "Hello"); - assertEqual(result.code, 200); -}; - -var testError = function() { - var result = http.getUrl(root.href("throwerror")); - assertEqual(result.content, "Error"); - assertEqual(result.code, 500); -}; - -var testNotFound = function() { - var result = http.getUrl(root.href("nonExistingAction")); - assertEqual(result.content, "Not found"); - assertEqual(result.code, 404); -}; - -var testRedirect = function() { - var result = http.getUrl(root.href("redirect")); - assertEqual(result.content, "Hello"); - assertEqual(result.code, 200); -}; - -var testRedirectNoFollow = function() { - http.setFollowRedirects(false); - var result = null; - try { - result = http.getUrl(root.href("redirect")); - } finally { - http.setFollowRedirects(true); - } - assertEqual(result.content, ""); - // response codes 302 and 303 are both ok - assertTrue(result.code == 302 || result.code == 303); -}; - -var testMaxResponseSize = function() { - http.setMaxResponseSize(3); - var error = null; - try { - http.getUrl(root.href("hello")); - } catch (err) { - error = err; - } finally { - http.setMaxResponseSize(null); - } - assertNotNull(error); -}; - -var testLongResponse = function() { - var result = http.getUrl(root.href("long")); - assertEqual(result.content, makeLongString()); -}; diff --git a/src/dist/apps/test/tests/helma.Search.js b/src/dist/apps/test/tests/helma.Search.js deleted file mode 100644 index f70a68d7..00000000 --- a/src/dist/apps/test/tests/helma.Search.js +++ /dev/null @@ -1,347 +0,0 @@ -var tests = [ - "testConstructor", - "testGetDirectory", - "testGetRAMDirectory", - "testCreateIndex", - "testGetReaderWriter", - "testIndexLock", - "testDocument", - "testAddDocuments", - "testSearch" -]; - -app.addRepository("modules/helma/Search.js"); - -var indexName = "testindex"; -var basePath = java.lang.System.getProperty("java.io.tmpdir"); -var index; - -/** - * Test preliminaries - */ -var setup = function() { - // check if there is a (leftover) directory with the same name - // in the system's temporary directory - if so throw an exception and stop - var dir = new helma.File(basePath, indexName); - if (dir.exists()) { - throw "There is already a directory '" + dir.getAbsolutePath() + - "', please remove it before trying to run test again"; - } - return; -}; - -/** - * Test the helma.Search constructor to make sure Lucene is loaded - */ -var testConstructor = function() { - // should not throw an exception - var s = new helma.Search(); - return; -}; - -/** - * Test getDirectory method - */ -var testGetDirectory = function() { - var search = new helma.Search(); - assertThrows(function() { - search.getDirectory(); - }); - var dirs = [ - new helma.File(basePath, indexName), - new File(basePath, indexName), - new java.io.File(basePath, indexName), - basePath + "/" + indexName - ]; - var dir, fsDir, dirPath; - for (var i in dirs) { - dir = dirs[i]; - if (dir.constructor != String) { - dirPath = dir.getAbsolutePath(); - } else { - dirPath = dir; - } - fsDir = search.getDirectory(dir); - assertNotNull(fsDir); - assertEqual(fsDir.getFile().getAbsolutePath(), dirPath); - } - return; -}; - -/** - * Test getRAMDirectory method - */ -var testGetRAMDirectory = function() { - var search = new helma.Search(); - assertThrows(function() { - search.getDirectory(); - }); - var dirs = [ - new helma.File(basePath, indexName), - new File(basePath, indexName), - new java.io.File(basePath, indexName), - basePath + "/" + indexName - ]; - var dir, ramDir; - for (var i in dirs) { - dir = dirs[i]; - ramDir = search.getRAMDirectory(dir); - assertNotNull(ramDir); - } - return; -}; - -/** - * Test index creation - this method creates a RAMDirectory based - * index for testing and stores it in the global variable "index" - */ -var testCreateIndex = function() { - var search = new helma.Search(); - // test creating a file based index - var fsDir = search.getDirectory(new helma.File(basePath, indexName)); - index = search.createIndex(fsDir); - assertNotNull(index); - // explicitly test index.create(true) - assertTrue(index.create(true)); - - // test creating a ram based index - var ramDir = search.getRAMDirectory(); - index = search.createIndex(ramDir); - assertNotNull(index); - // explicitly test index.create(true) - assertTrue(index.create(true)); - assertEqual(index.constructor, helma.Search.Index); - assertEqual(index.size(), 0); - return; -}; - -/** - * Test getting index reader, writer and modifier - */ -var testGetReaderWriter = function() { - // test getReader - var reader = index.getReader(); - assertNotNull(reader); - reader.close(); - // test getWriter - var writer = index.getWriter(); - assertNotNull(writer); - writer.close(); - return; -}; - -/** - * Test index locking - */ -var testIndexLock = function() { - // test if the index is correctly locked when opening a writer - var writer = index.getWriter(); - assertTrue(index.isLocked()); - // test if getWriter() throws an exception when trying to open a second writer - assertThrows(function() { - index.getWriter(); - }); - writer.close(); - assertFalse(index.isLocked()); - return; -}; - -/** - * Test document constructor and methods - */ -var testDocument = function() { - var doc = new helma.Search.Document(); - var f; - - // test type conversion - f = new helma.Search.Document.Field("id", 1); - assertEqual(f.value.constructor, String); - assertEqual(f.value, "1"); - var now = new Date(); - f = new helma.Search.Document.Field("createtime", now); - assertEqual(f.dateValue.constructor, Date); - assertEqual(f.dateValue.getTime(), now.getTime() - (now.getTime() % 60000)); - - // test adding field with default store and index options - doc.addField(new helma.Search.Document.Field("id", 1)); - f = doc.getField("id"); - assertNotNull(f); - assertTrue(f.isStored()); - assertTrue(f.isIndexed()); - assertTrue(f.isTokenized()); - - // test adding date field with changed field options - f = new helma.Search.Document.Field("createtime", new Date(), { - store: "no", - index: "tokenized" - }); - doc.addField(f); - f = doc.getField("createtime"); - assertNotNull(f); - assertFalse(f.isStored()); - assertTrue(f.isIndexed()); - assertTrue(f.isTokenized()); - - // test deprecated way of calling addField() - doc.addField("title", "Just a test", { - "store": false, - "index": true, - "tokenize": false - }); - f = doc.getField("title"); - assertNotNull(f); - assertFalse(f.isStored()); - assertTrue(f.isIndexed()); - assertFalse(f.isTokenized()); - - // test getFields() - var fields = doc.getFields(); - assertEqual(fields.length, 3); - assertEqual(fields[0].name, "id"); - assertEqual(fields[1].name, "createtime"); - assertEqual(fields[2].name, "title"); - return; -}; - -/** - * Test adding documents - */ -var testAddDocuments = function() { - // test addDocument() - var doc = new helma.Search.Document(); - doc.addField(new helma.Search.Document.Field("id", 1)); - index.addDocument(doc); - assertEqual(index.size(), 1); - - // test removeDocument() - index.removeDocument("id", 1); - assertEqual(index.size(), 0); - - // test addDocuments() and removeDocuments() with an array - doc = new helma.Search.Document(); - doc.addField(new helma.Search.Document.Field("id", 2)); - index.addDocuments([doc]); - assertEqual(index.size(), 1); - index.removeDocuments("id", [2]); - assertEqual(index.size(), 0); - - // test addDocuments() and removeDocuments() with a Hashtable as argument - var ht = new java.util.Hashtable(); - ht.put("doc", doc); - index.addDocuments(ht); - ht = new java.util.Hashtable(); - ht.put("id", 1); - ht.put("id", 2); - index.removeDocuments("id", ht); - assertEqual(index.size(), 0); - - // test addDocuments() and removeDocuments() with a Vector as argument - var v = new java.util.Vector(); - v.add(doc); - index.addDocuments(v); - v = new java.util.Vector(); - v.add(1); - v.add(2); - index.removeDocuments("id", v); - assertEqual(index.size(), 0); - - // test updateDocument - index.addDocument(doc); - doc = new helma.Search.Document(); - doc.addField("id", 2); - index.updateDocument(doc, "id"); - assertEqual(index.size(), 1); - - // test count() - doc = new helma.Search.Document(); - doc.addField("id", 3); - index.addDocument(doc); - assertEqual(index.count("id", 3), 1); - - return; -}; - -/** - * Test searching the index - */ -var testSearch = function() { - // clear the index - index.create(); - assertEqual(index.size(), 0); - - // populate the index with test content - var names = [ - "foo", - "bar", - "baz" - ]; - - var now = new Date(); - var doc; - names.forEach(function(name, idx) { - doc = new helma.Search.Document(); - doc.addField("id", idx + 1); - doc.addField("parent", idx % 2); - doc.addField("name", name); - doc.addField("timestamp", new Date(now.getTime() - (idx * 1e6))); - index.addDocument(doc); - }); - assertEqual(index.size(), 3); - - var searcher = index.getSearcher(); - assertNotNull(searcher); - assertNull(searcher.sortFields); - assertNotNull(searcher.getSearcher()); - assertTrue(searcher.getSearcher() instanceof Packages.org.apache.lucene.search.IndexSearcher); - - // test basic search - var q = new helma.Search.TermQuery("id", 1); - assertEqual(searcher.search(q), 1); - assertNotNull(searcher.hits); - assertEqual(searcher.hits.constructor, helma.Search.HitCollection); - assertEqual(searcher.hits.size(), 1); - var hit = searcher.hits.get(0); - assertNotNull(hit); - assertEqual(hit.constructor, helma.Search.Document); - assertEqual(hit.getField("name").constructor, helma.Search.Document.Field); - assertEqual(hit.getField("name").value, "foo"); - // test date value conversion - assertEqual(hit.getField("timestamp").value.constructor, String); - assertEqual(hit.getField("timestamp").dateValue.constructor, Date); - - // test query filter - var qf = new helma.Search.QueryFilter(new helma.Search.TermQuery("parent", 0)); - q = new helma.Search.WildcardQuery("name", "ba*"); - assertEqual(searcher.search(q, qf), 1); - assertEqual(searcher.hits.get(0).getField("name").value, names[2]); - - // test sorting of hits - searcher.sortBy("id", true); - assertEqual(searcher.search(q), 2); - assertEqual(searcher.hits.get(0).getField("name").value, names[2]); - assertEqual(searcher.hits.get(1).getField("name").value, names[1]); - - // test boolean query - q = new helma.Search.BooleanQuery(); - q.addTerm("parent", "0"); - assertEqual(q.toString(), "[(parent:0)]"); - q = new helma.Search.BooleanQuery(); - q.addTerm("parent", "0", "and"); - assertEqual(q.toString(), "[+(parent:0)]"); - q = new helma.Search.BooleanQuery(); - q.addTerm("parent", "0", "not"); - assertEqual(q.toString(), "[-(parent:0)]"); - - searcher.close(); - return; -}; - -/** - * Cleanup - */ -var cleanup = function() { - // remove the directory containing the test index - var dir = new helma.File(basePath, indexName); - dir.removeDirectory(); - return; -} \ No newline at end of file diff --git a/src/dist/apps/welcome/code/Global/init.js b/src/dist/apps/welcome/code/Global/init.js deleted file mode 100644 index ae6d095b..00000000 --- a/src/dist/apps/welcome/code/Global/init.js +++ /dev/null @@ -1,11 +0,0 @@ -function onStart(name) { - if (!root.get('first')) { - root.name = 'root'; - var firstNode = new HopObject(); - firstNode.name = 'first'; - root.add(firstNode) - var secondNode = new HopObject(); - secondNode.name = 'second'; - firstNode.add(secondNode) - } -} diff --git a/src/dist/apps/welcome/code/Guide/handler.js b/src/dist/apps/welcome/code/Guide/handler.js deleted file mode 100644 index e4bf7500..00000000 --- a/src/dist/apps/welcome/code/Guide/handler.js +++ /dev/null @@ -1,8 +0,0 @@ -function getChildElement(name) { - if (this.get(name)) - return this.get(name); - var page = new Guide(); - page.name = name; - page.parent = this; - return page; -} diff --git a/src/dist/apps/welcome/code/Guide/intro.actions.skin b/src/dist/apps/welcome/code/Guide/intro.actions.skin deleted file mode 100644 index dd6f14de..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.actions.skin +++ /dev/null @@ -1,40 +0,0 @@ -

    actions

    - -

    Every request a Helma application receives is handled by an "action" - associated with the requested URL. For example, a request to - - http://<% request.http_host %>/example will be handled by the - "example" action, defined at ./apps/welcome/code/Root/example.hac

    - -
    -res.write('Hello, this is the action defined \
    -    at ./apps/welcome/code/Root/example.hac');
    -
    - -

    The file example.hac contains the Javascript code that Helma will - evaluate when handling that request. In this example, the code inside - the example.hac file automatically becomes a prototype method with an - "_action" suffix. By leveraging such conventions, Helma allows you to - structure your code in clean and uncluttered ways. Alternatively, you - can also define actions in generic Javascript files, an examples of - which can be found in ./apps/welcome/code/Root/example.js and tested via - the URL - http://<% request.http_host %>/anotherexample

    - -
    -function anotherexample_action() {
    -    res.write('Hello again, this is the action \
    -        defined in ./apps/welcome/Root/example.js');
    -}
    -
    - -

    Requests that do not specify a particular action are handled by the - "main" action. For example, a request to - http://<% request.http_host %>/ - will be handled by the "main" action, defined at - ./apps/welcome/code/Guide/main.hac

    - -

    More information about the way Helma handles requests and maps them to - actions, and how Helma maps directories and filename extensions to - objects in the Javascript environment: -
    /docs/Request-Response-Cycle/

    diff --git a/src/dist/apps/welcome/code/Guide/intro.applications.skin b/src/dist/apps/welcome/code/Guide/intro.applications.skin deleted file mode 100644 index 440a016c..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.applications.skin +++ /dev/null @@ -1,48 +0,0 @@ -

    applications

    - -

    Helma can serve multiple independent applications, each accessible - through a different mountpoint, using Javascript environments - running in their own global scope, and configurable to use separate - code repositories.

    - -

    A Helma default installation, for example, is serving the applications - "manage" and "welcome" and makes them accessible through the - - http://<% request.http_host %>/manage/ and - http://<% request.http_host %>/ - URLs respectively. The list of active applications is defined by the file - ./apps.properties in Helma's home directory.

    - -
    -# Administrative application to manage all 
    -# other apps on this server, accessible via its 
    -# default mountpoint at http://host:port/manage 
    -# and using its default repository at apps/manage
    -
    -manage
    -
    -
    -# More complex example of an application with 
    -# custom configuration:
    -
    -welcome
    -welcome.mountpoint = /
    -welcome.repository.0 = apps/welcome/code/
    -welcome.repository.1 = modules/helmaTools.zip
    -welcome.static = apps/welcome/static
    -welcome.staticMountpoint = /static
    -welcome.staticHome = index.html,default.html
    -welcome.staticIndex = true
    -welcome.uploadLimit = 2048
    -
    - -

    Further application specific configurations can be defined in an app.properties - file inside an application's code repository. Examples of such a file you will - find in the "manage" app's default repository directory at - ./apps/manage/app.properties and in the "welcome" application's repository at - ./apps/welcome/code/app.properties.

    - -

    More information about these files: -
    /docs/Properties+Files/apps.properties/ -
    /docs/Properties+Files/app.properties/ -

    diff --git a/src/dist/apps/welcome/code/Guide/intro.dbmapping.skin b/src/dist/apps/welcome/code/Guide/intro.dbmapping.skin deleted file mode 100644 index 7f200895..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.dbmapping.skin +++ /dev/null @@ -1,56 +0,0 @@ -

    database mapping

    - -

    Helma allows you to map your HopObjects to relational database tables - instead of persisting them in the application's embedded XML database.

    - -

    The list of available database connections is defined inside the file - ./db.properties in Helma's home directory or for application specific - configurations in a db.properties file inside an application's code - repository.

    - -
    -myDataSource.url = jdbc:mysql://db.domain.com/space
    -myDataSource.driver = org.gjt.mm.mysql.Driver
    -myDataSource.user = username
    -myDataSource.password = xyz
    -
    - -

    In order to add the specified JDBC driver to the classpath, place it in - the ./lib/ext/ directory. Depending on the database system you are using, - you may want to - download an appropriate JDBC driver, for example a - driver for - MySQL.

    - -

    Using the SQLshell from within your application, - you may at any time explore your database and issue SQL statements. - The SQLshell also allows you to map your database tables to properties - of your application's prototypes as desired. A simple configuration for - your object/relational mappings might look as follows:

    - -
    -_db         = myDataSource
    -_table      = PERSON
    -_id         = ID
    -
    -firstname   = FIRSTNAME
    -lastname    = LASTNAME
    -email       = EMAIL
    -createtime  = CREATETIME
    -modifytime  = MODIFYTIME
    -
    - -

    These configurations would be placed in a type.properties file - inside the corresponding prototype directory, for example in - ./apps/addressbook/Person/type.properties, when following the - "addressbook" tutorial.

    - -

    To learn how Helma's relational database mapping is put to work and - how it relates and integrates with the other central aspects of the - framework, follow the - tutorial and build the full "addressbook" application.

    - -

    More information about the object/relational mapping of HopObject properties: -
    /docs/Properties+Files/db.properties/ -
    /docs/Object-Relational+Mapping/ -

    diff --git a/src/dist/apps/welcome/code/Guide/intro.hopobjects.skin b/src/dist/apps/welcome/code/Guide/intro.hopobjects.skin deleted file mode 100644 index fc6835fa..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.hopobjects.skin +++ /dev/null @@ -1,37 +0,0 @@ -

    hopobjects

    - -

    HopObjects extend the standard Javascript object with Helma-specific - properties and functions. They are the central building blocks that allow - you to leverage the application framework Helma provides.

    - -

    The main HopObject of every application is the "root" object. Every - HopObject can have a collection of attached additional HopObjects. - Each requested URL is resolved to a particular HopObject according - to these collections.

    - -

    In the "welcome" application for example, a request to - - http://<% request.http_host %>/first/second/ will be resolved by - checking the "root" object's collection for a HopObject named "first" - and the "first" object's collection for a HopObject named "second".

    - -

    While this path resolution is by default performed based on the ID of - the attached HopObjects, collections can be custom configured to use - another property as access name. In this example, the HopObject prototype - is configured at ./apps/welcome/code/HopObject/type.properties to use the - "name" property for this purpose.

    - -
    -_children = collection(HopObject)
    -_children.accessname = name
    -name
    -
    - -

    When a new HopObject is added to such a collection, it is automatically - stored in Helma's embedded XML database. To see a detailed example of - how this works, go to - http://<% request.http_host %>/first/ and add additional HopObjects.

    - -

    Documentation of HopObject functions and built-in properties: -
    /reference/HopObject.html -

    diff --git a/src/dist/apps/welcome/code/Guide/intro.javapackages.skin b/src/dist/apps/welcome/code/Guide/intro.javapackages.skin deleted file mode 100644 index ca17589e..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.javapackages.skin +++ /dev/null @@ -1,33 +0,0 @@ -

    java packages

    - -

    Helma puts the whole wealth of Java libraries at your fingertips. - The "Packages" object in Helma's Javascript environment serves as - the doorway to leverage any Java packages in the CLASSPATH. You can - add any Java packages to the - CLASSPATH simply by putting the jar files in the ./lib/ext/ directory.

    - -

    Any public methods that these Java classes define become callable from - your application's Javascript environment and you can create and work - with Java objects just like you do with Javascript objects. For example, - you could create a Java StringBuffer object and then append data to it - as follows:

    - -
    -var buffer = new Packages.java.lang.StringBuffer();
    -buffer.append('hello');
    -
    - -

    If your application makes extensive use of a Java class, it might be a - good idea to wrap that class in a Javascript prototype. That way, the - objects your applications works with become true Javascript objects, you - can control exactly which class methods are exposed to your application - and you can abstract the implementation, allowing you to change the Java - classes you use without requiring modifications to your application.

    - -

    Various examples of such wrappers around Java classes can be found in the - helmaLib, which makes Mail, File, Ftp, Image, Search, SSH and Zip - functionality available in this way.

    - -

    More information on how Helma makes Java scriptable: -
    /rhino/ScriptingJava -

    diff --git a/src/dist/apps/welcome/code/Guide/intro.macros.skin b/src/dist/apps/welcome/code/Guide/intro.macros.skin deleted file mode 100644 index e6c4e913..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.macros.skin +++ /dev/null @@ -1,52 +0,0 @@ -

    macros

    - -

    Macros are methods of application logic that can be called through - custom macro tags contained in skins. Macros allow skins to pull - data from application logic, while other macro tags only push - pre-determined data to the skins.

    - -

    You will find an example for such a skin in the "welcome" application - at ./apps/welcome/code/Root/example_using_macro.skin

    - -
    -<p>This is an example of a skin calling a macro.</p>
    -<p>You will find this skin at 
    -    ./apps/welcome/code/Root/example_using_macro.skin</p>
    -<p>This skin is rendered by the action defined at 
    -    ./apps/welcome/code/Root/example_using_macro.hac</p>
    -<p>The macro this skin calls is defined in 
    -    ./apps/welcome/code/Root/example.js</p>
    -<p>You can test it via the URL 
    -    <a href="<% this.pullLink part="url" %>">
    -        <% this.pullLink part="text" %>
    -    </a>
    -</p>
    -
    - -

    In this example, the skin calls a "pullLink" macro twice, using a different - "part" parameter. Macro methods are defined using a corresponding function - name with a "_macro" suffix. The pullLink macro used in this example, you - will find defined in ./apps/welcome/code/Root/example.js

    - -
    -function pullLink_macro(params) {
    -    switch (params.part) {
    -        case 'text' : 
    -            return '/example_using_macro';
    -        case 'url'  : 
    -            return this.href('example_using_macro');;
    -    }
    -}
    -
    - -

    You can test this macro and see the skin rendered via the URL - - http://<% request.http_host %>/example_using_macro

    - -

    Note that macros can again make use of skins, which may again contain - macro calls. This combination of skins and macros allows actions to - delegate the response generation through multiple tiers of "control" - and "presentation".

    - -

    More information about macro tags and ways in which you can use custom defined macros: -
    /docs/Request-Response-Cycle/

    diff --git a/src/dist/apps/welcome/code/Guide/intro.prototypes.skin b/src/dist/apps/welcome/code/Guide/intro.prototypes.skin deleted file mode 100644 index d00742ce..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.prototypes.skin +++ /dev/null @@ -1,41 +0,0 @@ -

    prototypes

    - -

    Helma's coding conventions revolve around the prototype based object - inheritance of Javascript. While Helma does not force you to leverage - these coding conventions, doing so will increase productivity and you - will achieve better maintainability due to a clean and well organized - code structure.

    - -

    The HopObject prototype is the core prototype of every Helma application. - By default, other prototypes that you create will inherit from the - HopObject prototype. Every directory that you create inside your - application's code repository becomes automatically a prototype by that - name and will inherit the methods, actions, macros and skins that the - HopObject prototype provides.

    - -

    In the "welcome" application's code repository at ./apps/welcome/code/ - for example, you will find directories for the HopObject, Root and Guide - prototypes. Both the Root and Guide prototypes inherit automatically any - code from the HopObject prototype. Additionally, the Root prototype also - inherits from the Guide prototype, due to the "_extends" property that is - configured in ./apps/welcome/code/Root/type.properties

    - -
    -_extends = Guide
    -
    - -

    "Root" is the prototype of the application's root object. The root object - of the "welcome" application therefore uses the combined code from these - three prototypes, with code in "Root" overriding code from "Guide", which - in turn overrides code from "HopObject".

    - -

    When Helma receives a request to - http://<% request.http_host %>/ it will look for a "main" action to - handle the request. Since it will not find one in "Root", it will use the - one defined at ./apps/welcome/code/Guide/main.hac. Requests pointing to a - generic HopObject such as - http://<% request.http_host %>/first/ on the other hand, will use the - main action defined at ./apps/welcome/code/HopObject/main.hac.

    - -

    More information on how Helma puts prototypes to work: -
    /docs/Request-Response-Cycle/

    diff --git a/src/dist/apps/welcome/code/Guide/intro.skin b/src/dist/apps/welcome/code/Guide/intro.skin deleted file mode 100644 index 5328fd0a..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.skin +++ /dev/null @@ -1,14 +0,0 @@ -
    -

    Explore the introductions below and discover what you
    - can do with Helma and Javascript on the server-side.

    -
    - - -

    introductions

    - <% response.listintro %> - - - - - <% response.content %> - diff --git a/src/dist/apps/welcome/code/Guide/intro.skins.skin b/src/dist/apps/welcome/code/Guide/intro.skins.skin deleted file mode 100644 index f2709074..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.skins.skin +++ /dev/null @@ -1,44 +0,0 @@ -

    skins

    - -

    Helma allows you to cleanly separate presentation from application logic - through the use of skins. The skins are segments of HTML markup that can - contain macro tags, which are replaced with dynamic content when the - skin is rendered.

    - -

    You will find an example for such a skin in the "welcome" application at - ./apps/welcome/code/Root/example.skin

    - -
    -<p>This is an example of a simple skin.</p>
    -<p>You will find this skin at 
    -    ./apps/welcome/code/Root/example.skin</p>
    -<p>This skin is rendered by the action defined at 
    -    ./apps/welcome/code/Root/example_using_skin.hac</p>
    -<p>You can test it via the URL 
    -    <a href="<% response.pushLink %>">
    -        <% response.pushLinkText %>
    -    </a>
    -</p>
    -
    - -

    The rendering of skins is controlled by an application's actions. In the - case of the "welcome" application, you will find an example of such an - action at ./apps/welcome/code/Root/example_using_skin.hac

    - -
    -res.data.pushLink = this.href('example_using_skin');
    -res.data.pushLinkText = '/example_using_skin';
    -this.renderSkin('example');
    -
    - -

    You can test this action and see the skin rendered via the URL - - http://<% request.http_host %>/example_using_skin - -

    Skins can contain various kinds of "macro tags" such as <% response.pushLink %> - used in this example skin, where the value of a dynamic URL is determined by the - action and made available to the skin by setting the req.data.pushLink property.

    - -

    More information about the way in which Helma defines and renders skins, and the - various kinds of available Macro Tags: -
    /docs/Request-Response-Cycle/

    diff --git a/src/dist/apps/welcome/code/Guide/intro.staticfiles.skin b/src/dist/apps/welcome/code/Guide/intro.staticfiles.skin deleted file mode 100644 index 2a957599..00000000 --- a/src/dist/apps/welcome/code/Guide/intro.staticfiles.skin +++ /dev/null @@ -1,31 +0,0 @@ -

    static files

    - -

    The default mountpoint of a Helma application is always a code repository, - which means that requests will be handled by the application's Javascript - environment and will not reference specific server pages. Static files on - the other hand are served from separate "static" mountpoints.

    - -

    In Helma's default installation, the "welcome" application is serving - static files from its "static" directory at ./apps/welcome/static/ - and makes them accessible through URLs starting with - - http://<% request.http_host %>/static/

    - -

    For example, you should be able to access the file named "test.txt" inside - the ./apps/welcome/static/ directory via the URL - - http://<% request.http_host %>/static/test.txt

    - -

    Inside the ./apps.properties file, you will find the following settings, - which control the related behavior:

    - -
    -welcome.static = apps/welcome/static
    -welcome.staticMountpoint = /static
    -welcome.staticHome = index.html,default.html
    -welcome.staticIndex = true
    -
    - -

    More information about these and additional settings related to serving static files: -
    /docs/Properties+Files/apps.properties/ -

    diff --git a/src/dist/apps/welcome/code/Guide/list.intro.skin b/src/dist/apps/welcome/code/Guide/list.intro.skin deleted file mode 100644 index 56993d9f..00000000 --- a/src/dist/apps/welcome/code/Guide/list.intro.skin +++ /dev/null @@ -1,11 +0,0 @@ - diff --git a/src/dist/apps/welcome/code/Guide/list.tools.skin b/src/dist/apps/welcome/code/Guide/list.tools.skin deleted file mode 100644 index d65ec132..00000000 --- a/src/dist/apps/welcome/code/Guide/list.tools.skin +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/src/dist/apps/welcome/code/Guide/list.website.skin b/src/dist/apps/welcome/code/Guide/list.website.skin deleted file mode 100644 index 5ececdd2..00000000 --- a/src/dist/apps/welcome/code/Guide/list.website.skin +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/src/dist/apps/welcome/code/Guide/main.hac b/src/dist/apps/welcome/code/Guide/main.hac deleted file mode 100644 index e156957b..00000000 --- a/src/dist/apps/welcome/code/Guide/main.hac +++ /dev/null @@ -1,18 +0,0 @@ -// Prepare some response values used by the skins -res.data.href = this.href(); -res.data.root = root.href(); - -// Render three nested skins -res.data.listtools = this.renderSkinAsString('list.tools'); -res.data.listintro = this.renderSkinAsString('list.intro'); -res.data.listwebsite = this.renderSkinAsString('list.website'); -if (this.parent && this.parent.name) { - res.data.title = 'Welcome to Helma - '+ this.parent.name +' - '+ this.name; - res.data.content = this.renderSkinAsString( this.parent.name +'.'+ this.name ); - res.data.body = this.renderSkinAsString( this.parent.name ); -} -if (!res.data.body) { - res.data.title = 'Welcome to Helma - Overview'; - res.data.body = this.renderSkinAsString('overview'); -} -this.renderSkin('page'); diff --git a/src/dist/apps/welcome/code/Guide/overview.skin b/src/dist/apps/welcome/code/Guide/overview.skin deleted file mode 100644 index 3e3d3df8..00000000 --- a/src/dist/apps/welcome/code/Guide/overview.skin +++ /dev/null @@ -1,19 +0,0 @@ -
    -

    Welcome to Helma! Explore the tools, introductions and resources below and - discover what you can do with Helma and Javascript on the server-side.

    -
    - - -

    tools

    - <% response.listtools %> - - - -

    introductions

    - <% response.listintro %> - - - -

    helma.org

    - <% response.listwebsite %> - diff --git a/src/dist/apps/welcome/code/Guide/tools.about_inspector.skin b/src/dist/apps/welcome/code/Guide/tools.about_inspector.skin deleted file mode 100644 index 8322d30c..00000000 --- a/src/dist/apps/welcome/code/Guide/tools.about_inspector.skin +++ /dev/null @@ -1,21 +0,0 @@ -

    inspector

    - -

    The Inspector allows you to inspect and modify the properties of - HopObjects and to browse the HopObject tree. For example, you - can invoke the Inspector on the HopObject named "first" by - accessing the "inspector" action at - - http://<% request.http_host %>/first/inspector

    - - - -

    Note that access to the Inspector is restricted for obvious security - reasons. If you have not yet done so, you will be directed on how - to configure administrative access when you attempt to use - this tool.

    - -

    In order to be able to use the Inspector inside your own application, - you will need to add the helmaTools code repository to that - application. For example by adding modules/helmaTools.zip to the - list of its repositories in the - ./apps.properties file. diff --git a/src/dist/apps/welcome/code/Guide/tools.about_manage.skin b/src/dist/apps/welcome/code/Guide/tools.about_manage.skin deleted file mode 100644 index 40442bb2..00000000 --- a/src/dist/apps/welcome/code/Guide/tools.about_manage.skin +++ /dev/null @@ -1,18 +0,0 @@ -

    manage

    - -

    The Manage application allows you to start and stop applications and - makes a variety of status information available. It also provides access - to the automatically generated API documentation of the application's - code repositories and libraries.

    - -

    In Helma's default installation, the Manage application can be accessed - using the - http://<% request.http_host %>/manage mountpoint.

    - - - -

    Note that access to the Manage application is restricted for obvious - security reasons. You will first need to edit the ./server.properties - file and set adminAccess to your IP address. You then will be - directed on how to configure administrative access when you attempt to - use this tool.

    diff --git a/src/dist/apps/welcome/code/Guide/tools.about_shell.skin b/src/dist/apps/welcome/code/Guide/tools.about_shell.skin deleted file mode 100644 index fb4c9c76..00000000 --- a/src/dist/apps/welcome/code/Guide/tools.about_shell.skin +++ /dev/null @@ -1,31 +0,0 @@ -

    shell

    - -

    The Shell allows you to run commands and evaluate scripts within - your running application. This may be useful for administrative - and maintenance tasks for which you may not want to build a GUI - or pre-defined scripts. Certainly, the Shell can become very - useful during development and debugging.

    - -

    By running commands you can inspect and manage data structures - beyond the capabilities of the Inspector. By running scripts you - can easily test and modify small portions of your application or - invoke actions, simulating specific circumstances and measuring - their performance.

    - -

    For example, you can invoke the Shell on the HopObject - named "second" by accessing the "shell" action at - - http://<% request.http_host %>/first/second/shell

    - - - -

    Note that access to the Shell is restricted for obvious security - reasons. If you have not yet done so, you will be directed on how - to configure administrative access when you attempt to use - this tool.

    - -

    In order to be able to use the Shell inside your own application, - you will need to add the helmaTools code repository to that - application. For example by adding modules/helmaTools.zip to the - list of its repositories in the - ./apps.properties file. diff --git a/src/dist/apps/welcome/code/Guide/tools.about_sqlshell.skin b/src/dist/apps/welcome/code/Guide/tools.about_sqlshell.skin deleted file mode 100644 index 7f1eeb29..00000000 --- a/src/dist/apps/welcome/code/Guide/tools.about_sqlshell.skin +++ /dev/null @@ -1,43 +0,0 @@ -

    sqlshell

    - -

    The SQLshell allows you to query relational databases, explore - their schema, send SQL statements and create object/relational - mappings for your HopObject prototypes.

    - -

    In order to be able to use the SQLshell, you need to define at least - one datasource inside the ./db.properties file in Helma's home - directory or for application specific configurations in a db.properties - file inside the application's code repository. An example of such a - file can be found inside the welcome application at - ./apps/welcome/code/db.properties

    - -
    -myDataSource.url = jdbc:mysql://db.domain.com/space
    -myDataSource.driver = org.gjt.mm.mysql.Driver
    -myDataSource.user = username
    -myDataSource.password = xyz
    -
    - -

    In order to add the specified JDBC driver to the CLASSPATH, place it in - the ./lib/ext/ directory. Depending on the database system you are using, - you may want to - download an appropriate JDBC driver, for example a - driver for - MySQL.

    - -

    Now you should be able to use the SQLshell by accessing any URL - pointing to a HopObject with the added "sqlshell" action, such as - /sqlshell.

    - - - -

    Note that access to the SQLshell is restricted for obvious security - reasons. If you have not yet done so, you will be directed on how - to configure your administrative access when you attempt to use - this tool.

    - -

    In order to be able to use the SQLshell inside your own application, - you will need to add the helmaTools code repository to that - application. For example by adding modules/helmaTools.zip to the - list of its repositories in the - ./apps.properties file. diff --git a/src/dist/apps/welcome/code/Guide/tools.debugger.skin b/src/dist/apps/welcome/code/Guide/tools.debugger.skin deleted file mode 100644 index 844b5701..00000000 --- a/src/dist/apps/welcome/code/Guide/tools.debugger.skin +++ /dev/null @@ -1,33 +0,0 @@ -

    debugger

    - -

    The debugger can help you debug Helma applications, providing - facilities to set and clear breakpoints, control execution, view - variables, and evaluate arbitrary Javascript code in the current - scope, for example that of a request that is being processed.

    - -

    To enable the debugger, set the rhino.debug property in the - application's app.properties file as follows:

    - -
    -rhino.debug = true
    -
    - -

    If this property is set when an application is started, the debugger - will open in a separate window. Since this window will open on the - server the application is running on, using the debugger is only - suitable for local development.

    - - - -

    The "welcome" application comes with the debugger disabled. To enable - it and cause the debugger window to automatically open when Helma is - started, uncomment the corresponding property by removing the leading - hash in the ./apps/welcome/code/app.properties file:

    - -
    -#rhino.debug = true
    -
    - -

    More information on the functionality the debugger offers: -
    /rhino/debugger -

    diff --git a/src/dist/apps/welcome/code/Guide/tools.skin b/src/dist/apps/welcome/code/Guide/tools.skin deleted file mode 100644 index d5e4e20e..00000000 --- a/src/dist/apps/welcome/code/Guide/tools.skin +++ /dev/null @@ -1,14 +0,0 @@ -
    -

    Explore the tools below and discover what you
    - can do with Helma and Javascript on the server-side.

    -
    - - -

    tools

    - <% response.listtools %> - - - - - <% response.content %> - diff --git a/src/dist/apps/welcome/code/HopObject/add.hac b/src/dist/apps/welcome/code/HopObject/add.hac deleted file mode 100644 index ddea9b58..00000000 --- a/src/dist/apps/welcome/code/HopObject/add.hac +++ /dev/null @@ -1,19 +0,0 @@ -if (req.data.add && req.data.name) { - var obj = new HopObject(); - obj.name = req.data.name; - this.add(obj); - res.redirect(obj.href()) -} -res.data.root = root.href(); -res.data.parenthref = this._parent.href(); -res.data.parentname = this._parent.name; -res.data.href = this.href(); -res.data.title = this.name; -res.data.list = '\ - '; -res.data.content = this.renderSkinAsString('add'); -res.data.body = this.renderSkinAsString('main'); - -this.renderSkin('page'); diff --git a/src/dist/apps/welcome/code/HopObject/add.skin b/src/dist/apps/welcome/code/HopObject/add.skin deleted file mode 100644 index fd99e447..00000000 --- a/src/dist/apps/welcome/code/HopObject/add.skin +++ /dev/null @@ -1,6 +0,0 @@ -
    -

    In order to attach a new HopObject to "<% response.title %>", -
    please specify its name below.

    -

    Name: -

    -
    diff --git a/src/dist/apps/welcome/code/HopObject/hop.skin b/src/dist/apps/welcome/code/HopObject/hop.skin deleted file mode 100644 index 566e1a0a..00000000 --- a/src/dist/apps/welcome/code/HopObject/hop.skin +++ /dev/null @@ -1,24 +0,0 @@ -

    This HopObject is named "<% response.title %>" and has the ID "<% response.id %>".

    - -

    It is attached to the HopObject - "<% response.parentname %>".

    - -
    -

    The access counter for - this Hop Object is at - <% response.counter %> - -

    -
    - -

    This HopObject is automatically persisted in Helma's - embedded XML database at ./db/welcome/<% response.id %>.xml

    - -

    To explore this HopObject and its properties in more detail you - may utilize the web-based shell. - In addition to the inspection of this HopObject, you will be able to - evaluate server-side Javascript in its scope.

    - -

    In case you are curious: This request has been handled by the action - defined at ./apps/welcome/code/HopObject/main.hac and this text was - rendered from the skin ./apps/welcome/code/HopObject/hop.skin

    diff --git a/src/dist/apps/welcome/code/HopObject/hoplist.js b/src/dist/apps/welcome/code/HopObject/hoplist.js deleted file mode 100644 index 8f919d3d..00000000 --- a/src/dist/apps/welcome/code/HopObject/hoplist.js +++ /dev/null @@ -1,8 +0,0 @@ -function hoplist(){ - var list = ''; - for (var subnode in this.list()) { - list += '
  • '+ this.list()[subnode].name +'
  • '; - } - return '
      '+ list +'
    '; -} diff --git a/src/dist/apps/welcome/code/HopObject/main.hac b/src/dist/apps/welcome/code/HopObject/main.hac deleted file mode 100644 index b726ae18..00000000 --- a/src/dist/apps/welcome/code/HopObject/main.hac +++ /dev/null @@ -1,24 +0,0 @@ -// Prepare some response values used by the skins -res.data.root = root.href(); -res.data.parenthref = this._parent.href(); -res.data.parentname = this._parent.name; -res.data.href = this.href(); -res.data.title = this.name; -res.data.id = this._id; -if (req.data.counter) - this.counter = 0; -else - this.counter = !this.counter ? 1 : this.counter + 1; -res.data.counter = this.counter; -res.data.list = this.hoplist(); -res.data.add = '\ -
    \ -
    \ - \ -
    \ -
    '; - -// Render three nested skins -res.data.content = this.renderSkinAsString('hop'); -res.data.body = this.renderSkinAsString('main'); -this.renderSkin('page'); diff --git a/src/dist/apps/welcome/code/HopObject/main.skin b/src/dist/apps/welcome/code/HopObject/main.skin deleted file mode 100644 index 256fe4b3..00000000 --- a/src/dist/apps/welcome/code/HopObject/main.skin +++ /dev/null @@ -1,16 +0,0 @@ -
    -

    HopObject - the central building blocks of your Helma applications.

    -
    - - - -

    <% response.title %>

    - <% response.list %> - <% response.add %> - - - - <% response.content %> - diff --git a/src/dist/apps/welcome/code/HopObject/page.skin b/src/dist/apps/welcome/code/HopObject/page.skin deleted file mode 100644 index 797ef03c..00000000 --- a/src/dist/apps/welcome/code/HopObject/page.skin +++ /dev/null @@ -1,23 +0,0 @@ - - - - -<% response.title %> - - - - - - - - -
    -
    - <% response.body %> -
    -


    - - - diff --git a/src/dist/apps/welcome/code/HopObject/scripts_js.hac b/src/dist/apps/welcome/code/HopObject/scripts_js.hac deleted file mode 100644 index 8f543488..00000000 --- a/src/dist/apps/welcome/code/HopObject/scripts_js.hac +++ /dev/null @@ -1,2 +0,0 @@ -res.contentType="application/javascript"; -this.renderSkin('scripts_js'); diff --git a/src/dist/apps/welcome/code/HopObject/scripts_js.skin b/src/dist/apps/welcome/code/HopObject/scripts_js.skin deleted file mode 100644 index cd63cebd..00000000 --- a/src/dist/apps/welcome/code/HopObject/scripts_js.skin +++ /dev/null @@ -1,22 +0,0 @@ -function openbox(kind) { - document.write('\ -
    \ - \ - \ - '); - if (kind != 'content') document.write('\ -
    \ - '); - else document.write('\ -
    \ - '); -} - -function closebox(kind) { - document.write('\ -
    \ - \ - \ -
    \ - '); -} diff --git a/src/dist/apps/welcome/code/HopObject/styles_css.hac b/src/dist/apps/welcome/code/HopObject/styles_css.hac deleted file mode 100644 index 9412e83c..00000000 --- a/src/dist/apps/welcome/code/HopObject/styles_css.hac +++ /dev/null @@ -1,2 +0,0 @@ -res.contentType="text/css"; -this.renderSkin('styles_css'); diff --git a/src/dist/apps/welcome/code/HopObject/styles_css.skin b/src/dist/apps/welcome/code/HopObject/styles_css.skin deleted file mode 100644 index e07911bd..00000000 --- a/src/dist/apps/welcome/code/HopObject/styles_css.skin +++ /dev/null @@ -1,112 +0,0 @@ -body { - background-color: #fff; - margin-top: 0px; - margin-left: 0px; -} - -a {text-decoration: none;} -a:link {color: #00f;} -a:visited {color: #00b;} -a:active {color: #f66;} -a:hover {color: #c33;} - -pre { - background: #ffe; - line-height:150%; - padding: 8px; -} - -h3 { - font-family: "Trebuchet MS", sans-serif; - font-size: 16px; - margin-left: 15px; -} - -ul { - font-family: "Trebuchet MS", sans-serif; - font-size: 13px; - color: #333; - // margin-left: 40px; -} - -.overview { - width: 755px; - heigth: 92px; -} -.tools { - float:left; - margin-left: 15px; - width: 222px; -} -.intro { - float:left; - margin-left: 27px; - margin-right: 27px; - width: 222px; -} -.website { - float:left; - width: 222px; -} -.pagetools, .pageintro, .pagewebsite { - float:left; - margin-left: 15px; - width: 195px; -} - -.frame { - width: 755px; - margin-top: 0px; - margin-right: auto; - margin-left: auto; - margin-bottom: 30px; -} -.lead { - font-family: "Trebuchet MS", sans-serif; - font-size: 16px; - color: #666; - margin-top: 20px; - margin-right: 45px; - margin-left: 125px; - margin-bottom: 25px; -} -.columnheight { - height: 300px; -} -.content { - font-family: "Trebuchet MS", sans-serif; - font-size: 13px; - line-height:135%; - float:left; - spacing: 10px; - margin-left: 25px; - width: 505px; -} -.contentmargin { - margin-left: 20px; - margin-right: 15px; -} - -.tools, .tools b.rtop b, .tools b.rbottom b, -.pagetools, .pagetools b.rtop b, .pagetools b.rbottom b - {background: #bf7} - -.intro, .intro b.rtop b, .intro b.rbottom b, -.pageintro, .pageintro b.rtop b, .pageintro b.rbottom b - {background: #fd6} - -.website, .website b.rtop b, .website b.rbottom b, -.pagewebsite, .pagewebsite b.rtop b, .pagewebsite b.rbottom b - {background: #7cf} - -.content, .content b.rtop b, .content b.rbottom b - {background: #eee} - -b.rtop, b.rbottom{display:block;background: #fff} -b.rtop b, b.rbottom b{display:block;height: 1px; - overflow: hidden;} -b.r1{margin: 0 5px} -b.r2{margin: 0 3px} -b.r3{margin: 0 2px} -b.r4{margin: 0 1px;height: 2px} -b.rtop b.r4, b.rbottom b.r4{margin: 0 1px;height: 2px} diff --git a/src/dist/apps/welcome/code/HopObject/type.properties b/src/dist/apps/welcome/code/HopObject/type.properties deleted file mode 100644 index 176ce08c..00000000 --- a/src/dist/apps/welcome/code/HopObject/type.properties +++ /dev/null @@ -1,3 +0,0 @@ -_children = collection(HopObject) -_children.accessname = name -name diff --git a/src/dist/apps/welcome/code/Root/example.hac b/src/dist/apps/welcome/code/Root/example.hac deleted file mode 100644 index 76e98e56..00000000 --- a/src/dist/apps/welcome/code/Root/example.hac +++ /dev/null @@ -1,2 +0,0 @@ -res.write('Hello, this is the action defined \ - at ./apps/welcome/code/Root/example.hac'); diff --git a/src/dist/apps/welcome/code/Root/example.js b/src/dist/apps/welcome/code/Root/example.js deleted file mode 100644 index b4d7b301..00000000 --- a/src/dist/apps/welcome/code/Root/example.js +++ /dev/null @@ -1,11 +0,0 @@ -function anotherexample_action() { - res.write('Hello again, this is the action \ - defined in ./apps/welcome/code/Root/example.js'); -} - -function pullLink_macro(params) { - switch (params.part) { - case 'text' : return '/example_using_macro'; - case 'url' : return this.href('example_using_macro');; - } -} diff --git a/src/dist/apps/welcome/code/Root/example.skin b/src/dist/apps/welcome/code/Root/example.skin deleted file mode 100644 index c3fb292c..00000000 --- a/src/dist/apps/welcome/code/Root/example.skin +++ /dev/null @@ -1,10 +0,0 @@ -

    This is an example of a simple skin.

    -

    You will find this skin at - ./apps/welcome/code/Root/example.skin

    -

    This skin is rendered by the action defined at - ./apps/welcome/code/Root/example_using_skin.hac

    -

    You can test it via the URL - - <% response.pushLinkText %> - -

    diff --git a/src/dist/apps/welcome/code/Root/example_using_macro.hac b/src/dist/apps/welcome/code/Root/example_using_macro.hac deleted file mode 100644 index cdcb86d7..00000000 --- a/src/dist/apps/welcome/code/Root/example_using_macro.hac +++ /dev/null @@ -1 +0,0 @@ -this.renderSkin('example_using_macro'); diff --git a/src/dist/apps/welcome/code/Root/example_using_macro.skin b/src/dist/apps/welcome/code/Root/example_using_macro.skin deleted file mode 100644 index 08023455..00000000 --- a/src/dist/apps/welcome/code/Root/example_using_macro.skin +++ /dev/null @@ -1,12 +0,0 @@ -

    This is an example of a skin that calls a macro.

    -

    You will find this skin at - ./apps/welcome/code/Root/example_using_macro.skin

    -

    This skin is rendered by the action defined at - ./apps/welcome/code/Root/example_using_macro.hac

    -

    The macro this skin calls is defined in - ./apps/welcome/code/Root/example.js

    -

    You can test it via the URL - "> - <% this.pullLink part="text" %> - -

    diff --git a/src/dist/apps/welcome/code/Root/example_using_skin.hac b/src/dist/apps/welcome/code/Root/example_using_skin.hac deleted file mode 100644 index ec38ce97..00000000 --- a/src/dist/apps/welcome/code/Root/example_using_skin.hac +++ /dev/null @@ -1,3 +0,0 @@ -res.data.pushLinkUrl = this.href('example_using_skin'); -res.data.pushLinkText = 'example_using_skin'; -this.renderSkin('example'); diff --git a/src/dist/apps/welcome/code/Root/type.properties b/src/dist/apps/welcome/code/Root/type.properties deleted file mode 100644 index 188d64d6..00000000 --- a/src/dist/apps/welcome/code/Root/type.properties +++ /dev/null @@ -1,4 +0,0 @@ -_extends = Guide -_children = collection(HopObject) -_children.accessname = name -name diff --git a/src/dist/apps/welcome/code/app.properties b/src/dist/apps/welcome/code/app.properties deleted file mode 100644 index 96715c17..00000000 --- a/src/dist/apps/welcome/code/app.properties +++ /dev/null @@ -1 +0,0 @@ -#rhino.debug = true diff --git a/src/dist/apps/welcome/static/guide/debugger.png b/src/dist/apps/welcome/static/guide/debugger.png deleted file mode 100644 index c8cc3c06..00000000 Binary files a/src/dist/apps/welcome/static/guide/debugger.png and /dev/null differ diff --git a/src/dist/apps/welcome/static/guide/inspector.png b/src/dist/apps/welcome/static/guide/inspector.png deleted file mode 100644 index b4d12339..00000000 Binary files a/src/dist/apps/welcome/static/guide/inspector.png and /dev/null differ diff --git a/src/dist/apps/welcome/static/guide/manage.png b/src/dist/apps/welcome/static/guide/manage.png deleted file mode 100644 index 2d5e21ef..00000000 Binary files a/src/dist/apps/welcome/static/guide/manage.png and /dev/null differ diff --git a/src/dist/apps/welcome/static/guide/shell.png b/src/dist/apps/welcome/static/guide/shell.png deleted file mode 100644 index 15ff2bb5..00000000 Binary files a/src/dist/apps/welcome/static/guide/shell.png and /dev/null differ diff --git a/src/dist/apps/welcome/static/guide/sqlshell.png b/src/dist/apps/welcome/static/guide/sqlshell.png deleted file mode 100644 index d3c92b50..00000000 Binary files a/src/dist/apps/welcome/static/guide/sqlshell.png and /dev/null differ diff --git a/src/dist/apps/welcome/static/helmaheader.png b/src/dist/apps/welcome/static/helmaheader.png deleted file mode 100644 index 9d45c048..00000000 Binary files a/src/dist/apps/welcome/static/helmaheader.png and /dev/null differ diff --git a/src/dist/apps/welcome/static/test.txt b/src/dist/apps/welcome/static/test.txt deleted file mode 100644 index f4311c2f..00000000 --- a/src/dist/apps/welcome/static/test.txt +++ /dev/null @@ -1,4 +0,0 @@ - - This file should appear at http://:/static/test.txt - if you use the embedded Web server (-w option on commandline). - diff --git a/src/dist/db.properties b/src/dist/db.properties deleted file mode 100644 index 7530ed26..00000000 --- a/src/dist/db.properties +++ /dev/null @@ -1,18 +0,0 @@ -# This is where you specify relational data sources to -# map Helma types to relational databases. -# -# If you want to define a data source just for one -# application, simply copy the db.properties file to -# the application directory. -# -# The actual mapping of types is done in the -# type.properties file in the prototype directories. -# -# More information about this file is available at -# http://helma.org/docs/guide/properties/db.properties/ - -# Properties of JDBC data sources -#myDataSource.url = jdbc:mysql://db.domain.com/space -#myDataSource.driver = org.gjt.mm.mysql.Driver -#myDataSource.user = username -#myDataSource.password = xyz diff --git a/src/dist/db/manage/helma.xsl b/src/dist/db/manage/helma.xsl deleted file mode 100644 index e69de29b..00000000 diff --git a/src/dist/db/welcome/helma.xsl b/src/dist/db/welcome/helma.xsl deleted file mode 100644 index e69de29b..00000000 diff --git a/src/dist/extras/deploy.sh b/src/dist/extras/deploy.sh deleted file mode 100755 index 869cf945..00000000 --- a/src/dist/extras/deploy.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -# Use this script as forced command of an authorized SSH key: -# command="/home/helma/extras/deploy.sh" ssh-ed25519 AAAAC3NzaC… - -case "$SSH_ORIGINAL_COMMAND" in - ping) - echo pong - ;; - - restart) - printf 'Restarting Helma… ' - sudo /bin/systemctl restart helma - printf '%s\n' 'done.' - ;; - - *) - # Allow any rsync command but restrict it to the installation directory - rrsync -wo /home/helma - ;; -esac diff --git a/src/dist/extras/dpkg/README.Debian b/src/dist/extras/dpkg/README.Debian deleted file mode 100644 index 22eb5743..00000000 --- a/src/dist/extras/dpkg/README.Debian +++ /dev/null @@ -1,6 +0,0 @@ -Helma for Debian ----------------- - - - - -- Hannes Wallnoefer Mon, 15 Dec 2008 11:04:41 +0100 diff --git a/src/dist/extras/dpkg/changelog b/src/dist/extras/dpkg/changelog deleted file mode 100644 index 562b13b9..00000000 --- a/src/dist/extras/dpkg/changelog +++ /dev/null @@ -1,34 +0,0 @@ -helma1 (1.7.0-1) intrepid; urgency=low - - * Update to final 1.7.0 release - - -- Hannes Wallnoefer Tue, 29 Sep 2009 10:12:35 +0200 - -helma1 (1.7.0-rc3-2) intrepid; urgency=low - - * Update build number to please launchpad build bots - - -- Hannes Wallnoefer Fri, 11 Sep 2009 16:15:46 +0200 - -helma1 (1.7.0-rc3-1) intrepid; urgency=low - - * Update to 1.7.0 release candidate 3 - * Add package for HelmaSwarm - - -- Hannes Wallnoefer Thu, 10 Sep 2009 16:43:12 +0200 - -helma1 (1.7+r9436-1) intrepid; urgency=low - - * Change java dependencies to include more options - * Move properties files to /etc/helma1/ so they are not overwritten - on updates. (Still have to figure out how to prompt the user for - how to handle modified files.) - - -- Hannes Wallnoefer Wed, 17 Dec 2008 11:00:00 +0100 - -helma1 (1.7+r9436) intrepid; urgency=low - - * Initial release - - -- Hannes Wallnoefer Tue, 16 Dec 2008 11:00:00 +0100 - diff --git a/src/dist/extras/dpkg/compat b/src/dist/extras/dpkg/compat deleted file mode 100644 index 7f8f011e..00000000 --- a/src/dist/extras/dpkg/compat +++ /dev/null @@ -1 +0,0 @@ -7 diff --git a/src/dist/extras/dpkg/control b/src/dist/extras/dpkg/control deleted file mode 100644 index 62b4b020..00000000 --- a/src/dist/extras/dpkg/control +++ /dev/null @@ -1,46 +0,0 @@ -Source: helma1 -Section: web -Priority: optional -Maintainer: Hannes Wallnoefer -Build-Depends: debhelper (>= 7), default-jdk, cdbs -Build-Depends-Indep: ant -Standards-Version: 3.7.3 -Homepage: http://www.helma.org/ - -Package: helma1 -Architecture: all -Depends: default-jre-headless | java2-runtime-headless | - java5-runtime-headless | sun-java5-jre | system-java, - jsvc, adduser, lsb-base (>= 3) -Description: A server-side JavaScript web application framework. - . - Helma is an open-source JavaScript framework written in Java. - It uses the Mozilla Rhino JavaScript engine to provide - a comprehensive framework for web application development. - -Package: helma1-swarm -Section: web -Architecture: all -Depends: helma1 (>= ${source:Version}) -Description: A cluster extension for the Helma web framework. - . - Helma is an open-source JavaScript framework written in Java. - It uses the Mozilla Rhino JavaScript engine to provide - a comprehensive framework for web application development. - . - This package contains HelmaSwarm, a cluster extension based - on JGroups. - -Package: helma1-docs -Section: doc -Architecture: all -Depends: helma1 (>= ${source:Version}) -Description: Online documentation for the Helma web framework. - . - Helma is an open-source JavaScript framework written in Java. - It uses the Mozilla Rhino JavaScript engine to provide - a comprehensive framework for web application development. - . - This package contains the online documentation, including Java - and JavaScript API documentation. - diff --git a/src/dist/extras/dpkg/copyright b/src/dist/extras/dpkg/copyright deleted file mode 100644 index 6dd9115c..00000000 --- a/src/dist/extras/dpkg/copyright +++ /dev/null @@ -1,62 +0,0 @@ -This package was debianized by Hannes Wallnoefer on -Mon, 15 Dec 2008 11:04:41 +0100. - -It was downloaded from http://www.helma.org/ - -Upstream Authors: - - Hannes Wallnoefer - Robert Gaggl - Daniel Rutharth - Stefan Pollach - Tobias Schaefer - Manfred Andres - Juerg Lehni - -Copyright: 1999-2008 Helma Project. All rights reserved. - -License: - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - 3. Products derived from this software may not be called "Helma" - or "Hop", nor may "Helma" or "Hop" appear in their name, without - prior written permission of the Helma Project Group. For written - permission, please contact helma@helma.org. - - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE HELMA PROJECT OR ITS - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - OF THE POSSIBILITY OF SUCH DAMAGE. - - -Helma includes third party software released under different specific -license terms. See the licenses directory in the Helma distribution -for a list of these licenses. - -The Debian packaging is (C) 2008, Hannes Wallnoefer and -is licensed under the GPL, see `/usr/share/common-licenses/GPL'. - -Parts of Helma come with different licenses, see /usr/share/helma/licenses -for details. - - diff --git a/src/dist/extras/dpkg/dirs b/src/dist/extras/dpkg/dirs deleted file mode 100644 index ca882bbb..00000000 --- a/src/dist/extras/dpkg/dirs +++ /dev/null @@ -1,2 +0,0 @@ -usr/bin -usr/sbin diff --git a/src/dist/extras/dpkg/helma1-docs.install b/src/dist/extras/dpkg/helma1-docs.install deleted file mode 100644 index e457a75c..00000000 --- a/src/dist/extras/dpkg/helma1-docs.install +++ /dev/null @@ -1,3 +0,0 @@ -docs/api/ /usr/share/doc/helma1/api/ -docs/framework/ /usr/share/doc/helma1/framework/ - diff --git a/src/dist/extras/dpkg/helma1-swarm.docs b/src/dist/extras/dpkg/helma1-swarm.docs deleted file mode 100644 index bacb12c8..00000000 --- a/src/dist/extras/dpkg/helma1-swarm.docs +++ /dev/null @@ -1 +0,0 @@ -helmaswarm/README.txt diff --git a/src/dist/extras/dpkg/helma1-swarm.install b/src/dist/extras/dpkg/helma1-swarm.install deleted file mode 100644 index 75388ca3..00000000 --- a/src/dist/extras/dpkg/helma1-swarm.install +++ /dev/null @@ -1,3 +0,0 @@ -helmaswarm/lib/*.jar /usr/share/helma1/lib/ext/ -helmaswarm/swarm.conf /etc/helma1/ - diff --git a/src/dist/extras/dpkg/helma1.default b/src/dist/extras/dpkg/helma1.default deleted file mode 100644 index e8c98f8b..00000000 --- a/src/dist/extras/dpkg/helma1.default +++ /dev/null @@ -1,18 +0,0 @@ -# Run Helma as this user ID. Not setting this or leaving it blank will use the -# default of helma1. -#HELMA_USER=helma1 - -# The home directory of the Java development kit (JDK). You need at least -# JDK version 1.5. If JAVA_HOME is not set, some common directories for -# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried. -#JAVA_HOME=/usr/lib/jvm/java-6-openjdk - -# Directory for per-instance configuration files and webapps. It contains the -# directories conf, logs, webapps, work and temp. See RUNNING.txt for details. -# Default: /var/lib/helma1 -#HELMA_BASE=/var/lib/helma1 - -# Arguments to pass to the Java virtual machine (JVM). -#JAVA_OPTS="-Djava.awt.headless=true -Xmx128M" - - diff --git a/src/dist/extras/dpkg/helma1.dirs b/src/dist/extras/dpkg/helma1.dirs deleted file mode 100644 index 96eaf2f6..00000000 --- a/src/dist/extras/dpkg/helma1.dirs +++ /dev/null @@ -1,5 +0,0 @@ -var/log/helma1 -var/lib/helma1/apps -var/lib/helma1/db -etc/helma1 - diff --git a/src/dist/extras/dpkg/helma1.docs b/src/dist/extras/dpkg/helma1.docs deleted file mode 100644 index c9f7a63d..00000000 --- a/src/dist/extras/dpkg/helma1.docs +++ /dev/null @@ -1,2 +0,0 @@ -license.txt -README.txt diff --git a/src/dist/extras/dpkg/helma1.init b/src/dist/extras/dpkg/helma1.init deleted file mode 100644 index f3f569a6..00000000 --- a/src/dist/extras/dpkg/helma1.init +++ /dev/null @@ -1,191 +0,0 @@ -#!/bin/sh -# -# /etc/init.d/helma1 -- startup script for the Helma web framework -# -# Written by Miquel van Smoorenburg . -# Modified for Debian GNU/Linux by Ian Murdock . -# Modified for Tomcat by Stefan Gybas . -# Modified for Tomcat6 by Thierry Carrez . -# Modified for Helma by Hannes Wallnoefer . -# -### BEGIN INIT INFO -# Provides: helma1 -# Required-Start: $local_fs $remote_fs $network -# Required-Stop: $local_fs $remote_fs $network -# Should-Start: $named -# Should-Stop: $named -# Default-Start: 2 3 4 5 -# Default-Stop: 1 -# Short-Description: Start Helma web application framework. -# Description: Start Helma web application framework. -### END INIT INFO - -set -e - -PATH=/bin:/usr/bin:/sbin:/usr/sbin -NAME=helma1 -DESC="Helma web application framework" -DAEMON=/usr/bin/jsvc -HELMA_HOME=/usr/share/$NAME -DEFAULT=/etc/default/$NAME - -if [ `id -u` -ne 0 ]; then - echo "You need root privileges to run this script" - exit 1 -fi - -# Make sure helma is started with system locale -if [ -r /etc/default/locale ]; then - . /etc/default/locale - export LANG -fi - -. /lib/lsb/init-functions -. /etc/default/rcS - - -# The following variables can be overwritten in $DEFAULT - -# Run Helma as this user ID -HELMA_USER=helma1 - -# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not -# defined in $DEFAULT) -JDK_DIRS="/usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm" - -# Look for the right JVM to use -for jdir in $JDK_DIRS; do - if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then - JAVA_HOME="$jdir" - fi -done -export JAVA_HOME - -# Directory for per-instance configuration files and webapps -HELMA_BASE=/var/lib/$NAME - -# Default Java options -# Set java.awt.headless=true if JAVA_OPTS is not set so the -# Xalan XSL transformer can work without X11 display on JDK 1.4+ -# It also looks like the default heap size of 64M is not enough for most cases -# so the maximum heap size is set to 128M -if [ -z "$JAVA_OPTS" ]; then - JAVA_OPTS="-Djava.awt.headless=true -Xmx128M" -fi - -# End of variables that can be overwritten in $DEFAULT - -# overwrite settings from default file -if [ -f "$DEFAULT" ]; then - . "$DEFAULT" -fi - -if [ ! -f "$HELMA_HOME/launcher.jar" ]; then - log_failure_msg "$NAME is not installed" - exit 1 -fi - -if [ ! -f "$DAEMON" ]; then - log_failure_msg "missing $DAEMON" - exit 1 -fi - -# Set juli LogManager if logging.properties is provided -if [ -r "$HELMA_BASE"/logging.properties ]; then - JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" "-Djava.util.logging.config.file="$HELMA_BASE/logging.properties" -fi - -# Define other required variables -HELMA_PID="/var/run/$NAME.pid" -BOOTSTRAP_CLASS=helma.main.launcher.Main -JSVC_CLASSPATH="/usr/share/java/commons-daemon.jar:$HELMA_HOME/launcher.jar" - -case "$1" in - start) - if [ -z "$JAVA_HOME" ]; then - log_failure_msg "no JDK found - please set JAVA_HOME" - exit 1 - fi - - if [ ! -d "$HELMA_BASE" ]; then - log_failure_msg "invalid HELMA_BASE: $HELMA_BASE" - exit 1 - fi - - log_daemon_msg "Starting $DESC" "$NAME" - if start-stop-daemon --test --start --pidfile "$HELMA_PID" \ - --user $HELMA_USER --startas "$JAVA_HOME/bin/java" \ - >/dev/null; then - - cd "$HELMA_BASE" - - $DAEMON -user "$HELMA_USER" -cp "$JSVC_CLASSPATH" \ - -outfile SYSLOG -errfile SYSLOG \ - -pidfile "$HELMA_PID" $JAVA_OPTS "$BOOTSTRAP_CLASS" \ - -h "$HELMA_BASE" - - sleep 1 - if start-stop-daemon --test --start --pidfile "$HELMA_PID" \ - --user $HELMA_USER --startas "$JAVA_HOME/bin/java" \ - >/dev/null; then - log_end_msg 1 - else - log_end_msg 0 - fi - else - log_progress_msg "(already running)" - log_end_msg 0 - fi - ;; - stop) - log_daemon_msg "Stopping $DESC" "$NAME" - if start-stop-daemon --test --start --pidfile "$HELMA_PID" \ - --user "$HELMA_USER" --startas "$JAVA_HOME/bin/java" \ - >/dev/null; then - log_progress_msg "(not running)" - else - $DAEMON -cp "$JSVC_CLASSPATH" -pidfile "$HELMA_PID" \ - -stop "$BOOTSTRAP_CLASS" - fi - log_end_msg 0 - ;; - status) - if start-stop-daemon --test --start --pidfile "$HELMA_PID" \ - --user $HELMA_USER --startas "$JAVA_HOME/bin/java" \ - >/dev/null; then - - if [ -f "$HELMA_PID" ]; then - log_success_msg "$DESC is not running, but pid file exists." - exit 1 - else - log_success_msg "$DESC is not running." - exit 3 - fi - else - log_success_msg "$DESC is running with pid `cat $HELMA_PID`" - fi - ;; - restart|force-reload) - if start-stop-daemon --test --stop --pidfile "$HELMA_PID" \ - --user $HELMA_USER --startas "$JAVA_HOME/bin/java" \ - >/dev/null; then - $0 stop - sleep 1 - fi - $0 start - ;; - try-restart) - if start-stop-daemon --test --start --pidfile "$HELMA_PID" \ - --user $HELMA_USER --startas "$JAVA_HOME/bin/java" \ - >/dev/null; then - $0 start - fi - ;; - *) - log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}" - exit 1 - ;; -esac - -exit 0 - diff --git a/src/dist/extras/dpkg/helma1.install b/src/dist/extras/dpkg/helma1.install deleted file mode 100644 index 3f18c600..00000000 --- a/src/dist/extras/dpkg/helma1.install +++ /dev/null @@ -1,7 +0,0 @@ -launcher.jar /usr/share/helma1/ -lib/*.jar /usr/share/helma1/lib/ -licenses/ /usr/share/helma1/licenses/ -build/main/*.properties /etc/helma1/ -build/externals/modules/ /var/lib/helma1/ -build/externals/welcome/ /var/lib/helma1/apps/ -build/externals/manage/ /var/lib/helma1/apps/ diff --git a/src/dist/extras/dpkg/helma1.links b/src/dist/extras/dpkg/helma1.links deleted file mode 100644 index fead9bc4..00000000 --- a/src/dist/extras/dpkg/helma1.links +++ /dev/null @@ -1,5 +0,0 @@ -/var/log/helma1 /var/lib/helma1/log -/etc/helma1/apps.properties /var/lib/helma1/apps.properties -/etc/helma1/server.properties /var/lib/helma1/server.properties -/etc/helma1/db.properties /var/lib/helma1/db.properties - diff --git a/src/dist/extras/dpkg/helma1.postinst b/src/dist/extras/dpkg/helma1.postinst deleted file mode 100644 index 7e03482a..00000000 --- a/src/dist/extras/dpkg/helma1.postinst +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# postinst script for helma1 -# -# see: dh_installdeb(1) - -set -e - -# summary of how this script can be called: -# * `configure' -# * `abort-upgrade' -# * `abort-remove' `in-favour' -# -# * `abort-remove' -# * `abort-deconfigure' `in-favour' -# `removing' -# -# for details, see http://www.debian.org/doc/debian-policy/ or -# the debian-policy package - - -case "$1" in - configure) - if ! id helma1 > /dev/null 2>&1 ; then - adduser --system --home /usr/share/helma1 --no-create-home \ - --group --disabled-password --shell /bin/false \ - helma1 - fi - chown -R helma1:adm /var/lib/helma1 - chown -R helma1:adm /var/log/helma1 - chmod 750 /var/log/helma1 - ;; - - abort-upgrade|abort-remove|abort-deconfigure) - ;; - - *) - echo "postinst called with unknown argument \`$1'" >&2 - exit 1 - ;; -esac - -# dh_installdeb will replace this with shell code automatically -# generated by other debhelper scripts. - -#DEBHELPER# - -exit 0 - - diff --git a/src/dist/extras/dpkg/patches/01_build_helmaswarm.diff b/src/dist/extras/dpkg/patches/01_build_helmaswarm.diff deleted file mode 100644 index 744ac0f0..00000000 --- a/src/dist/extras/dpkg/patches/01_build_helmaswarm.diff +++ /dev/null @@ -1,24 +0,0 @@ ---- helma-clean/build.xml 2009-09-11 14:50:36.000000000 +0200 -+++ helma/build.xml 2009-09-11 15:00:23.000000000 +0200 -@@ -481,4 +481,14 @@ - - - -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - ---- helma-clean/helmaswarm/build.properties 2009-09-11 19:47:13.000000000 +0200 -+++ helma/helmaswarm/build.properties 2009-09-11 19:50:29.000000000 +0200 -@@ -1,3 +1,3 @@ - # build properties for helmaswarm - --helma.install.dir=../helma -+helma.install.dir=../ diff --git a/src/dist/extras/dpkg/rules b/src/dist/extras/dpkg/rules deleted file mode 100755 index e9b4a722..00000000 --- a/src/dist/extras/dpkg/rules +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/make -f -# debian/rules for helma1 (uses CDBS) - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -include /usr/share/cdbs/1/rules/debhelper.mk -include /usr/share/cdbs/1/class/ant.mk -#include /usr/share/cdbs/1/rules/dpatch.mk -include /usr/share/cdbs/1/rules/simple-patchsys.mk - -JAVA_HOME := /usr/lib/jvm/default-java -DEB_ANT_BUILD_TARGET := jar javadocs jsdocs package-apps swarm-jar -DEB_ANT_CLEAN_TARGET := clean swarm-clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - -binary-indep: build install - dh_testdir - dh_testroot - dh_installinit --error-handler=true -- start 90 2 3 4 5 . stop 10 1 . - dh_install --exclude=.bat - dh_installdocs - dh_installdebconf - dh_link - dh_compress - dh_fixperms - dh_installdeb - dh_gencontrol - dh_md5sums - dh_builddeb - -binary-arch: build install - -binary: binary-indep binary-arch - diff --git a/src/dist/extras/helma.service b/src/dist/extras/helma.service deleted file mode 100644 index 7d42310b..00000000 --- a/src/dist/extras/helma.service +++ /dev/null @@ -1,25 +0,0 @@ -[Unit] -Description = Helma Object Publisher -After = syslog.target network.target -StartLimitIntervalSec = 0 - -[Service] -Type = simple -Restart = always -RestartSec = 1 -SuccessExitStatus = 143 -User = helma -WorkingDirectory = /home/helma - -ExecStart = /usr/bin/java -server \ - -Dfile.encoding=utf8 \ - -Djava.awt.headless=true \ - -Xms1024m -Xmx2048m \ - -jar launcher.jar \ - -w 8080 -x 8081 - -ExecReload = /bin/sh -c 'touch apps.properties && touch server.properties' -ExecStop = /bin/kill -15 $MAINPID - -[Install] -WantedBy = multi-user.target diff --git a/src/dist/extras/upstart/README.md b/src/dist/extras/upstart/README.md deleted file mode 100644 index 34648d47..00000000 --- a/src/dist/extras/upstart/README.md +++ /dev/null @@ -1,15 +0,0 @@ -This is a startup script for Helma written by Andreas Bolka. It allows -you to automatically run Helma as a service on Linux and Unix hosts. -It was originally written for Debian GNU/Linux, but was successfully -tested on SuSE Linux and should work for most Linux and Unix platforms. - -If you are looking for a way to run Helma as Service on a Windows -machine, have a look at HelmaService: - -http://adele.helma.org/download/helma/contrib/hannes/helmaservice - -If you experience any problems running Helma as service on Linux, -Windows or Unix box, please drop us a note on the Helma User Mailing -List: - -http://helma.org/development/mailinglists diff --git a/src/dist/extras/upstart/helma b/src/dist/extras/upstart/helma deleted file mode 100755 index 46bbf66c..00000000 --- a/src/dist/extras/upstart/helma +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash -# -# helma init script (written for debian, but should be rather generic) -# needs helma.conf, preferrably in /etc/helma.conf -# -# andreas bolka, 2003-11-30 -# - -### BEGIN INIT INFO -# Provides: helma -# Required-Start: postgresql apache2 -# Required-Stop: -# Default-Start: 2 3 4 5 -# Default-STop: 0 1 6 -# Short-Description: Helma Application Server -### END INIT INFO - -HELMA_CONFIG=/etc/helma.conf - -### - -# Check for existence of needed config file and source it -if [ -r $HELMA_CONFIG ]; then - source $HELMA_CONFIG -else - echo "Can't read config file $HELMA_CONFIG" - exit 6 -fi - -# Check for missing files and directories - -if [ ! -x $JAVA_BIN ]; then - echo "Config error: JAVA_BIN $JAVA_BIN not found or not executable" - exit 5 -fi - -if [ ! -r $HELMA_INSTALL/launcher.jar ]; then - echo "Config error: $HELMA_INSTALL/launcher.jar not found or not readable" - exit 5 -fi - -if [ ! -d $HELMA_HOME ]; then - echo "Config error: HELMA_HOME $HELMA_HOME not found" - exit 5 -fi - -RUN_CMD="su - $HELMA_USER" -RUN_ARGS="-c $JAVA_BIN $JAVA_OPTS -jar $HELMA_INSTALL/launcher.jar -h $HELMA_HOME $HELMA_ARGS" - -case "$1" in - start) - echo -n "Starting $HELMA_SERVICE: " - - if [ -f $HELMA_PID ]; then - echo "$HELMA_SERVICE (pid `cat $HELMA_PID`) already running" - exit 1 - fi - - cd $HELMA_HOME - nohup $RUN_CMD "$RUN_ARGS" > $HELMA_LOG 2>&1 & - echo $! > $HELMA_PID - echo "$HELMA_SERVICE (pid `cat $HELMA_PID`) started." - ;; - - stop) - echo -n "Shutting down $HELMA_SERVICE: " - if [ ! -f $HELMA_PID ]; then - echo "$HELMA_SERVICE not running" - exit 1 - fi - - PID=`cat $HELMA_PID 2>/dev/null` - echo -n "$HELMA_SERVICE (pid $PID) " - kill $PID 2>/dev/null; sleep 2; kill -9 $PID 2>/dev/null - rm -f $HELMA_PID - echo "stopped." - ;; - - restart) - $0 stop && $0 start - ;; - - reload) - echo -n "Reloading $HELMA_SERVICE: $HELMA_SERVICE" - touch $HELMA_HOME/server.properties - touch $HELMA_HOME/apps.properties - echo "." - ;; - - *) - echo "Usage: /etc/init.d/helma start|stop|restart|reload" - exit 1 - ;; -esac - -exit 0 diff --git a/src/dist/extras/upstart/helma.conf b/src/dist/extras/upstart/helma.conf deleted file mode 100644 index 521320c2..00000000 --- a/src/dist/extras/upstart/helma.conf +++ /dev/null @@ -1,44 +0,0 @@ -# -# Helma Object Publisher configuration file -# -# Authors: -# Hannes Wallnoefer , -# Andreas Bolka -# -# This file should be placed in /etc/helma.conf. -# It is read by the Helma service control script, -# usually /etc/init.d/helma. -# - -# Full path to Java executable -JAVA_HOME=/usr/lib/jvm/default-java -JAVA_BIN=$JAVA_HOME/bin/java - -# Options passed to the Java runtime -JAVA_OPTS="-server -Djava.awt.headless=true -Dfile.encoding=utf-8 -Djsse.enableSNIExtension=false" - -# The name of this Helma server/service and the pid file to be used -HELMA_SERVICE=helma -HELMA_PID=/var/run/helma.pid - -# Helma install directory. This is where we look for the Helma jar files -# (launcher.jar, lib/* and lib/ext/*) -HELMA_INSTALL=/home/helma - -# Helma home directory, in case it is different from the Helma install dir. -# This is where Helma will look for properties files and applications. -HELMA_HOME=$HELMA_INSTALL - -# The user Helma should be running as -HELMA_USER=helma - -# File to which standard and error output from Helma is redirected -HELMA_LOG=$HELMA_HOME/log/helma-out.log - -# Helma options. Possible options are: -# -f file - Location of server.properties file -# -p port - RMI port -# -w port - Web server port -# -x port - XML-RPC port -# -jk port - AJP13 port -HELMA_ARGS="-w 8080" diff --git a/src/dist/server.properties b/src/dist/server.properties deleted file mode 100644 index 2b219de3..00000000 --- a/src/dist/server.properties +++ /dev/null @@ -1,32 +0,0 @@ -# Helma server configuration file. -# More information about this file is available at -# http://helma.org/docs/guide/properties/server.properties/ - -# HTTP server port -webPort = 8080 - -# XML-RPC server port -xmlRpcPort = 8081 - -# Comma-separated list of ip addresses which are allowed to access -# admin applications. Default is localhost for IPv4 and IPv6. -allowAdmin = 127.0.0.1, ::1 - -# Credentials for using administrative apps like manage, shell and inspector -adminAccess = 2e7e46fdfc6174e1330359be2e75e766 - -# The SMTP server to use for sending mails. Set and uncomment the -# following line before trying to send mails from Helma applications. -#smtp = mail.yourdomain.com - -# During development, you may want to uncomment the following line, which -# will cause errors to be logged directly to the console instead of writing -# to the log files inside the default ./log directory. -#logDir = console - -# Server-wide locale settings -# (please refer to http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html -# for country codes, resp. http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt -# for language codes). -#country = AT -#language = de diff --git a/src/dist/static/helma.gif b/src/dist/static/helma.gif deleted file mode 100644 index 6af2476b..00000000 Binary files a/src/dist/static/helma.gif and /dev/null differ diff --git a/src/dist/static/helma2.gif b/src/dist/static/helma2.gif deleted file mode 100644 index 8bbb844b..00000000 Binary files a/src/dist/static/helma2.gif and /dev/null differ diff --git a/src/dist/static/test.txt b/src/dist/static/test.txt deleted file mode 100644 index 594b3ff3..00000000 --- a/src/dist/static/test.txt +++ /dev/null @@ -1,3 +0,0 @@ - - This file should appear at http://:/static/test.txt - if you use the embedded Web server (-w option). diff --git a/src/main/java/helma/extensions/ConfigurationException.java b/src/main/java/helma/extensions/ConfigurationException.java deleted file mode 100644 index 3a79dfaa..00000000 --- a/src/main/java/helma/extensions/ConfigurationException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.extensions; - -/** - * - */ -public class ConfigurationException extends RuntimeException { - private static final long serialVersionUID = 6428439427909728917L; - - /** - * Creates a new ConfigurationException object. - * - * @param msg ... - */ - public ConfigurationException(String msg) { - super(msg); - } -} diff --git a/src/main/java/helma/extensions/HelmaExtension.java b/src/main/java/helma/extensions/HelmaExtension.java deleted file mode 100644 index 7bb0fa26..00000000 --- a/src/main/java/helma/extensions/HelmaExtension.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.extensions; - -import helma.framework.core.Application; -import helma.main.Server; -import helma.scripting.ScriptingEngine; -import java.util.HashMap; - -/** - * Helma extensions have to subclass this. The extensions to be loaded are - * defined in server.properties by setting extensions = - * packagename.classname, packagename.classname. - */ -public abstract class HelmaExtension { - /** - * called by the Server at startup time. should check wheter the needed classes - * are present and throw a ConfigurationException if not. - */ - public abstract void init(Server server) throws ConfigurationException; - - /** - * called when an Application is started. This should be synchronized when - * any self-initialization is performed. - */ - public abstract void applicationStarted(Application app) - throws ConfigurationException; - - /** - * called when an Application is stopped. - * This should be synchronized when any self-destruction is performed. - */ - public abstract void applicationStopped(Application app); - - /** - * called when an Application's properties are have been updated. - * note that this will be called at startup once *before* applicationStarted(). - */ - public abstract void applicationUpdated(Application app); - - /** - * called by the ScriptingEngine when it is initizalized. Throws a ConfigurationException - * when this type of ScriptingEngine is not supported. New methods and prototypes can be - * added to the scripting environment. New global vars should be returned in a HashMap - * with pairs of varname and ESObjects. This method should be synchronized, if it - * performs any other self-initialization outside the scripting environment. - */ - public abstract HashMap initScripting(Application app, ScriptingEngine engine) - throws ConfigurationException; - - /** - * - * - * @return ... - */ - public abstract String getName(); -} diff --git a/src/main/java/helma/extensions/demo/DemoExtension.java b/src/main/java/helma/extensions/demo/DemoExtension.java deleted file mode 100644 index dbc35cae..00000000 --- a/src/main/java/helma/extensions/demo/DemoExtension.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.extensions.demo; - - -import helma.extensions.ConfigurationException; -import helma.extensions.HelmaExtension; -import helma.framework.core.Application; -import helma.main.Server; -import helma.scripting.ScriptingEngine; -import helma.scripting.rhino.RhinoEngine; -import java.util.HashMap; - -/** - * a demo extension implementation, to activate this add extensions = - * helma.extensions.demo.DemoExtensions to your server.properties. - * a new global object demo that wraps helma.main.Server - * will be added to the scripting environment. - */ -public class DemoExtension extends HelmaExtension { - /** - * - * - * @param server ... - * - * @throws ConfigurationException ... - */ - public void init(Server server) throws ConfigurationException { - try { - // just a demo with the server class itself (which is always there, obviously) - Class check = Class.forName("helma.main.Server"); - } catch (ClassNotFoundException e) { - throw new ConfigurationException("helma-library not present in classpath. make sure helma.jar is included. get it from http://www.helma.org/"); - } - } - - /** - * - * - * @param app ... - * - * @throws ConfigurationException ... - */ - public void applicationStarted(Application app) throws ConfigurationException { - app.logEvent("DemoExtension init with app " + app.getName()); - } - - /** - * - * - * @param app ... - */ - public void applicationStopped(Application app) { - app.logEvent("DemoExtension stopped on app " + app.getName()); - } - - /** - * - * - * @param app ... - */ - public void applicationUpdated(Application app) { - app.logEvent("DemoExtension updated on app " + app.getName()); - } - - /** - * - * - * @param app ... - * @param engine ... - * - * @return ... - * - * @throws ConfigurationException ... - */ - public HashMap initScripting(Application app, ScriptingEngine engine) - throws ConfigurationException { - if (!(engine instanceof RhinoEngine)) { - throw new ConfigurationException("scripting engine " + engine.toString() + - " not supported in DemoExtension"); - } - - app.logEvent("initScripting DemoExtension with " + app.getName() + " and " + - engine.toString()); - - // initialize prototypes and global vars here - HashMap globals = new HashMap(); - - globals.put("demo", Server.getServer()); - - return globals; - } - - /** - * - * - * @return ... - */ - public String getName() { - return "DemoExtension"; - } -} diff --git a/src/main/java/helma/framework/AbortException.java b/src/main/java/helma/framework/AbortException.java deleted file mode 100644 index 395ee04e..00000000 --- a/src/main/java/helma/framework/AbortException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - -/** - * AbortException is thrown internally when a response is aborted. - * Although this is not an Error, it subclasses java.lang.Error - * because it's not meant to be caught by application code (similar to - * java.lang.ThreadDeath). - */ -public class AbortException extends Error { - - private static final long serialVersionUID = -7536693051844908815L; - -} diff --git a/src/main/java/helma/framework/ApplicationStoppedException.java b/src/main/java/helma/framework/ApplicationStoppedException.java deleted file mode 100644 index 76364b6d..00000000 --- a/src/main/java/helma/framework/ApplicationStoppedException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - - -/** - * This is thrown when a request is made to a stopped - * application - */ -public class ApplicationStoppedException extends RuntimeException { - private static final long serialVersionUID = 7125229844095452333L; - - /** - * Creates a new ApplicationStoppedException object. - */ - public ApplicationStoppedException() { - super("The application has been stopped"); - } -} diff --git a/src/main/java/helma/framework/CookieTrans.java b/src/main/java/helma/framework/CookieTrans.java deleted file mode 100644 index 5293b843..00000000 --- a/src/main/java/helma/framework/CookieTrans.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - -import java.io.Serializable; -import jakarta.servlet.http.Cookie; - -/** - * Cookie Transmitter. A simple, serializable representation - * of an HTTP cookie. - */ -public final class CookieTrans implements Serializable { - private String name; - private String value; - private String path; - private String domain; - private boolean isHttpOnly = true; - private boolean isSecure = false; - private int days = -1; - - CookieTrans(String name, String value) { - this.name = name; - this.value = value; - } - - void setValue(String value) { - this.value = value; - } - - void setDays(int days) { - this.days = days; - } - - void setPath(String path) { - this.path = path; - } - - void setDomain(String domain) { - this.domain = domain; - } - - void setHttpOnly(boolean isHttpOnly) { - this.isHttpOnly = isHttpOnly; - } - - void setSecure(boolean isSecure) { - this.isSecure = isSecure; - } - - /** - * @return ... - */ - public String getName() { - return name; - } - - /** - * @return ... - */ - public String getValue() { - return value; - } - - /** - * @return ... - */ - public int getDays() { - return days; - } - - /** - * @return ... - */ - public String getPath() { - return path; - } - - /** - * @return ... - */ - public String getDomain() { - return domain; - } - - /** - * @return ... - */ - public boolean getHttpOnly() { - return isHttpOnly; - } - - /** - * @return ... - */ - public boolean getSecure() { - return isSecure; - } - - /** - * - * - * @param defaultPath ... - * @param defaultDomain ... - * - * @return ... - */ - public Cookie getCookie(String defaultPath, String defaultDomain) { - Cookie c = new Cookie(name, value); - - // NOTE: If cookie version is set to 1, cookie values will be quoted. - // c.setVersion(1); - - if (days > -1) { - // Cookie time to live, days -> seconds - c.setMaxAge(days * 60 * 60 * 24); - } - - if (path != null) { - c.setPath(path); - } else if (defaultPath != null) { - c.setPath(defaultPath); - } - - if (domain != null) { - c.setDomain(domain); - } else if (defaultDomain != null) { - c.setDomain(defaultDomain); - } - - c.setHttpOnly(isHttpOnly); - c.setSecure(isSecure); - - return c; - } -} diff --git a/src/main/java/helma/framework/FrameworkException.java b/src/main/java/helma/framework/FrameworkException.java deleted file mode 100644 index 0f52b858..00000000 --- a/src/main/java/helma/framework/FrameworkException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - - -/** - * The basic exception class used to tell when certain things go - * wrong in evaluation of requests. - */ -public class FrameworkException extends RuntimeException { - private static final long serialVersionUID = -8477797850472128617L; - - /** - * Creates a new FrameworkException object. - * - * @param msg ... - */ - public FrameworkException(String msg) { - super(msg); - } -} diff --git a/src/main/java/helma/framework/FutureResult.java b/src/main/java/helma/framework/FutureResult.java deleted file mode 100644 index 6dbb85e4..00000000 --- a/src/main/java/helma/framework/FutureResult.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - -/** - * A handle for an asynchronous request execution. This allows to wait for - * request termination, get the result or the exception of the execution. - */ -public interface FutureResult { - /** - * Get the result of the execution. If the execution is still active, - * or if the invocation threw an exception, this method immediately returns null. - * @return the result, or null - */ - Object getResult(); - - /** - * Get the exception of the execution, if one was thrown. If the execution - * is still active, or if no exception was thrown, this method immediately returns null. - * @return the exception, or null - */ - Exception getException(); - - /** - * Returns true if the execution is still active, and false if not. - * @return true if the execution is still active - */ - boolean getRunning(); - - /** - * Wait for execution to terminat, returning the execution result, if one is available. - * @return the execution result, or null - * @throws InterruptedException if we were interrupted by some other thread - */ - Object waitForResult() throws InterruptedException; - - /** - * Wait for a specific ammount of thime for the execution to terminate, returning - * the execution result, if one is available. - * @param timeout the number of milliseconds to wait - * @return the execution result, or null - * @throws InterruptedException if we were interrupted by some other thread - */ - Object waitForResult(long timeout) throws InterruptedException; -} diff --git a/src/main/java/helma/framework/IPathElement.java b/src/main/java/helma/framework/IPathElement.java deleted file mode 100644 index b56289e5..00000000 --- a/src/main/java/helma/framework/IPathElement.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - - -/** - * Interface that objects need to implement to build a Helma URL tree. Apart from methods - * to retrieve the identifier and its child and parent elements, this interface defines a method - * that determines which prototype to use to add scripts and skins to an object.

    - * - * Please note that this interface is still work in progress. You should expect it to get some - * additional methods that allow for looping through child elements, for example, or retrieving the - * parent element.

    - * - */ -public interface IPathElement { - /** - * Return the name to be used to get this element from its parent - */ - public String getElementName(); - - /** - * Retrieve a child element of this object by name. - */ - public IPathElement getChildElement(String name); - - /** - * Return the parent element of this object. - */ - public IPathElement getParentElement(); - - /** - * Get the name of the prototype to be used for this object. This will - * determine which scripts, actions and skins can be called on it - * within the Helma scripting and rendering framework. - */ - public String getPrototype(); -} diff --git a/src/main/java/helma/framework/IRemoteApp.java b/src/main/java/helma/framework/IRemoteApp.java deleted file mode 100644 index a9423f99..00000000 --- a/src/main/java/helma/framework/IRemoteApp.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - -import java.rmi.*; - -/** - * RMI interface for an application. Currently only execute is used and supported. - */ -public interface IRemoteApp extends Remote { - /** - * - * - * @param param ... - * - * @return ... - * - * @throws RemoteException ... - */ - public ResponseTrans execute(RequestTrans param) throws RemoteException; - - /** - * - * - * @throws RemoteException ... - */ - public void ping() throws RemoteException; -} diff --git a/src/main/java/helma/framework/NotFoundException.java b/src/main/java/helma/framework/NotFoundException.java deleted file mode 100644 index 5104e795..00000000 --- a/src/main/java/helma/framework/NotFoundException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - - -/** - * The basic exception class used to tell when certain things go - * wrong in evaluation of requests. - */ -public class NotFoundException extends RuntimeException { - private static final long serialVersionUID = -715022974097617658L; - - /** - * Creates a new NotFoundException object. - * - * @param message ... - */ - public NotFoundException(String message) { - super(message); - } - - /** - * Creates a new NotFoundException object with a cause. - * - * @param message the message - * @param cause the cause - */ - public NotFoundException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/src/main/java/helma/framework/RedirectException.java b/src/main/java/helma/framework/RedirectException.java deleted file mode 100644 index a75e910a..00000000 --- a/src/main/java/helma/framework/RedirectException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - - -/** - * RedirectException is thrown internally when a response is redirected to a - * new URL. Although this is not an Error, it subclasses java.lang.Error - * because it's not meant to be caught by application code (similar to - * java.lang.ThreadDeath). - */ -public class RedirectException extends Error { - private static final long serialVersionUID = 2362170037476457592L; - - String url; - - /** - * Creates a new RedirectException object. - * - * @param url the URL - */ - public RedirectException(String url) { - super("Redirection Request to " + url); - this.url = url; - } - - /** - * Return the URL to redirect to. - * @return the URL - */ - public String getUrl() { - return url; - } - -} diff --git a/src/main/java/helma/framework/RequestBean.java b/src/main/java/helma/framework/RequestBean.java deleted file mode 100644 index bf377a63..00000000 --- a/src/main/java/helma/framework/RequestBean.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - -import jakarta.servlet.http.HttpServletRequest; -import java.io.Serializable; -import java.util.Map; - -/** - * - */ -public class RequestBean implements Serializable { - private static final long serialVersionUID = -6826881712426326687L; - - RequestTrans req; - - /** - * Creates a new RequestBean object. - * - * @param req ... - */ - public RequestBean(RequestTrans req) { - this.req = req; - } - - /** - * - * - * @param name ... - * - * @return ... - */ - public Object get(String name) { - return req.get(name); - } - - - /** - * Return the method of the request. This may either be a HTTP method or - * one of the Helma pseudo methods defined in RequestTrans. - */ - public String getMethod() { - return req.getMethod(); - } - - /** - * - * - * @return ... - */ - public boolean isGet() { - return req.isGet(); - } - - /** - * - * - * @return ... - */ - public boolean isPost() { - return req.isPost(); - } - - /** - * Returns the Servlet request represented by this RequestTrans instance. - * Returns null for internal and XML-RPC requests. - */ - public HttpServletRequest getServletRequest() { - return req.getServletRequest(); - } - - /** - * Proxy to HttpServletRequest.getHeader(). - * @param name the header name - * @return the header value, or null - */ - public String getHeader(String name) { - return req.getHeader(name); - } - - /** - * Proxy to HttpServletRequest.getHeaders(), returns header values as string array. - * @param name the header name - * @return the header values as string array - */ - public String[] getHeaders(String name) { - return req.getHeaders(name); - } - - /** - * Proxy to HttpServletRequest.getIntHeader(), fails silently by returning -1. - * @param name the header name - * @return the header parsed as integer or -1 - */ - public int getIntHeader(String name) { - return req.getIntHeader(name); - } - - /** - * Proxy to HttpServletRequest.getDateHeader(), fails silently by returning -1. - * @param name the header name - * @return the date in milliseconds, or -1 - */ - public long getDateHeader(String name) { - return req.getDateHeader(name); - } - - /** - * @return A string representation of this request - */ - public String toString() { - return "[Request]"; - } - - /** - * @return the invoked action - */ - public String getAction() { - return req.getAction(); - } - - /** - * @return The req.data map containing request parameters, cookies and - * assorted HTTP headers - */ - public Map getData() { - return req.getRequestData(); - } - - /** - * @return the req.params map containing combined query and post parameters - */ - public Map getParams() { - return req.getParams(); - } - - /** - * @return the req.queryParams map containing parameters parsed from the query string - */ - public Map getQueryParams() { - return req.getQueryParams(); - } - - /** - * @return the req.postParams map containing params parsed from post data - */ - public Map getPostParams() { - return req.getPostParams(); - } - - /** - * @return the req.cookies map containing request cookies - */ - public Map getCookies() { - return req.getCookies(); - } - - /** - * @return the time this request has been running, in milliseconds - */ - public long getRuntime() { - return (System.currentTimeMillis() - req.getStartTime()); - } - - /** - * @return the password if using HTTP basic authentication - */ - public String getPassword() { - return req.getPassword(); - } - - /** - * @return the request path - */ - public String getPath() { - return req.getPath(); - } - - /** - * @return the request URI - */ - public String getUri() { - return req.getUri(); - } - - /** - * @return the username if using HTTP basic authentication - */ - public String getUsername() { - return req.getUsername(); - } - - /** - * The action handler allows the onRequest() method to set the function object - * to be invoked for processing the request, overriding the action resolved - * from the request path. - * @return the action handler - */ - public Object getActionHandler() { - return req.getActionHandler(); - } - - /** - * The action handler allows the onRequest() method to set the function object - * to be invoked for processing the request, overriding the action resolved - * from the request path. - * @param handler the action handler - */ - public void setActionHandler(Object handler) { - req.setActionHandler(handler); - } -} diff --git a/src/main/java/helma/framework/RequestTrans.java b/src/main/java/helma/framework/RequestTrans.java deleted file mode 100644 index ec8218fe..00000000 --- a/src/main/java/helma/framework/RequestTrans.java +++ /dev/null @@ -1,781 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - -import helma.util.SystemMap; -import helma.util.StringUtils; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.http.Cookie; - -import org.apache.commons.codec.binary.Base64; - -import java.io.*; -import java.util.*; -import java.util.regex.Pattern; -import java.util.regex.Matcher; - -/** - * A Transmitter for a request from the servlet client. Objects of this - * class are directly exposed to JavaScript as global property req. - */ -public class RequestTrans implements Serializable { - - static final long serialVersionUID = 5398880083482000580L; - - // HTTP methods - public final static String GET = "GET"; - public final static String POST = "POST"; - public final static String DELETE = "DELETE"; - public final static String HEAD = "HEAD"; - public final static String OPTIONS = "OPTIONS"; - public final static String PUT = "PUT"; - public final static String TRACE = "TRACE"; - // Helma pseudo-methods - public final static String XMLRPC = "XMLRPC"; - public final static String EXTERNAL = "EXTERNAL"; - public final static String INTERNAL = "INTERNAL"; - - // the servlet request and response, may be null - final HttpServletRequest request; - final HttpServletResponse response; - - // the path info of the request - private final String path; - - // the uri of the request - private final String uri; - - // the request's session id - private String session; - - // the map of form and cookie data - private final Map values = new DataComboMap(); - - private ParamComboMap params; - private ParameterMap queryParams, postParams, cookies; - - // the HTTP request method - private String method; - - // timestamp of client-cached version, if present in request - private long ifModifiedSince = -1; - - // set of ETags the client sent with If-None-Match header - private final Set etags = new HashSet(); - - // when was execution started on this request? - private final long startTime; - - // the name of the action being invoked - private String action; - private Object actionHandler = null; - private String httpUsername; - private String httpPassword; - - static private final Pattern paramPattern = Pattern.compile("\\[(.+?)\\]"); - - /** - * Create a new Request transmitter with an empty data map. - */ - public RequestTrans(String method, String path) { - this.method = method; - this.path = path; - this.uri = null; - this.request = null; - this.response = null; - startTime = System.currentTimeMillis(); - } - - /** - * Create a new request transmitter with the given data map. - */ - public RequestTrans(HttpServletRequest request, - HttpServletResponse response, String path) { - this.method = request.getMethod(); - this.request = request; - this.response = response; - this.path = path; - this.uri = request.getRequestURI(); - startTime = System.currentTimeMillis(); - - // do standard HTTP variables - String header = request.getHeader("Host"); - if (header != null) { - values.put("http_host", header.toLowerCase()); - } - - header = request.getHeader("Referer"); - if (header != null) { - values.put("http_referer", header); - } - - try { - long ifModifiedSince = request.getDateHeader("If-Modified-Since"); - if (ifModifiedSince > -1) { - setIfModifiedSince(ifModifiedSince); - } - } catch (IllegalArgumentException ignore) { - // not a date header - } - - header = request.getHeader("If-None-Match"); - if (header != null) { - setETags(header); - } - - header = request.getRemoteAddr(); - if (header != null) { - values.put("http_remotehost", header); - } - - header = request.getHeader("User-Agent"); - if (header != null) { - values.put("http_browser", header); - } - - header = request.getHeader("Accept-Language"); - if (header != null) { - values.put("http_language", header); - } - - header = request.getHeader("authorization"); - if (header != null) { - values.put("authorization", header); - } - } - - /** - * Return true if we should try to handle this as XML-RPC request. - * - * @return true if this might be an XML-RPC request. - */ - public synchronized boolean checkXmlRpc() { - if ("POST".equalsIgnoreCase(method)) { - String contentType = request.getContentType(); - if (contentType == null) { - return false; - } - int semi = contentType.indexOf(";"); - if (semi > -1) { - contentType = contentType.substring(0, semi); - } - return "text/xml".equalsIgnoreCase(contentType.trim()); - } - return false; - } - - /** - * Return true if this request is in fact handled as XML-RPC request. - * This implies that {@link #checkXmlRpc()} returns true and a matching - * XML-RPC action was found. - * - * @return true if this request is handled as XML-RPC request. - */ - public synchronized boolean isXmlRpc() { - return XMLRPC.equals(method); - } - - /** - * Set a cookie - * @param name the cookie name - * @param cookie the cookie - */ - public void setCookie(String name, Cookie cookie) { - if (cookies == null) { - cookies = new ParameterMap(); - } - cookies.put(name, cookie); - } - - /** - * @return a map containing the cookies sent with this request - */ - public Map getCookies() { - if (cookies == null) { - cookies = new ParameterMap(); - } - return cookies; - } - - /** - * @return the combined query and post parameters for this request - */ - public Map getParams() { - if (params == null) { - params = new ParamComboMap(); - } - return params; - } - - /** - * @return get the query parameters for this request - */ - public Map getQueryParams() { - if (queryParams == null) { - queryParams = new ParameterMap(); - } - return queryParams; - } - - /** - * @return get the post parameters for this request - */ - public Map getPostParams() { - if (postParams == null) { - postParams = new ParameterMap(); - } - return postParams; - } - - /** - * set the request parameters - */ - public void setParameters(Map parameters, boolean isPost) { - if (isPost) { - postParams = new ParameterMap(parameters); - } else { - queryParams = new ParameterMap(parameters); - } - } - - /** - * Add a post parameter to the request - * @param name the parameter name - * @param value the parameter value - */ - public void addPostParam(String name, Object value) { - if (postParams == null) { - postParams = new ParameterMap(); - } - Object previous = postParams.getRaw(name); - if (previous instanceof Object[]) { - Object[] array = (Object[]) previous; - Object[] values = new Object[array.length + 1]; - System.arraycopy(array, 0, values, 0, array.length); - values[array.length] = value; - postParams.put(name, values); - } else if (previous == null) { - postParams.put(name, new Object[] {value}); - } - } - - /** - * Set a parameter value in this request transmitter. This - * parses foo[bar][baz] as nested objects/maps. - */ - public void set(String name, Object value) { - values.put(name, value); - } - - /** - * Get a value from the requests map by key. - */ - public Object get(String name) { - try { - return values.get(name); - } catch (Exception x) { - return null; - } - } - - /** - * Get the data map for this request transmitter. - */ - public Map getRequestData() { - return values; - } - - /** - * Returns the Servlet request represented by this RequestTrans instance. - * Returns null for internal and XML-RPC requests. - */ - public HttpServletRequest getServletRequest() { - return request; - } - - /** - * Proxy to HttpServletRequest.getHeader(). - * @param name the header name - * @return the header value, or null - */ - public String getHeader(String name) { - return request == null ? null : request.getHeader(name); - } - - /** - * Proxy to HttpServletRequest.getHeaders(), returns header values as string array. - * @param name the header name - * @return the header values as string array - */ - public String[] getHeaders(String name) { - return request == null ? - null : StringUtils.collect(request.getHeaders(name)); - } - - /** - * Proxy to HttpServletRequest.getIntHeader(), fails silently by returning -1. - * @param name the header name - * @return the header parsed as integer or -1 - */ - public int getIntHeader(String name) { - try { - return request == null ? -1 : getIntHeader(name); - } catch (NumberFormatException nfe) { - return -1; - } - } - - /** - * Proxy to HttpServletRequest.getDateHeader(), fails silently by returning -1. - * @param name the header name - * @return the date in milliseconds, or -1 - */ - public long getDateHeader(String name) { - try { - return request == null ? -1 : getDateHeader(name); - } catch (NumberFormatException nfe) { - return -1; - } - } - - /** - * Returns the Servlet response for this request. - * Returns null for internal and XML-RPC requests. - */ - public HttpServletResponse getServletResponse() { - return response; - } - - /** - * The hash code is computed from the session id if available. This is used to - * detect multiple identic requests. - */ - public int hashCode() { - if (session == null || path == null) { - return super.hashCode(); - } else { - return 17 + (37 * session.hashCode()) + - (37 * path.hashCode()); - } - } - - /** - * A request is considered equal to another one if it has the same method, - * path, session, request data, and conditional get data. This is used to - * evaluate multiple simultanous identical requests only once. - */ - public boolean equals(Object what) { - if (what instanceof RequestTrans) { - if (session == null || path == null) { - return super.equals(what); - } else { - RequestTrans other = (RequestTrans) what; - return (session.equals(other.session) - && path.equalsIgnoreCase(other.path) - && values.equals(other.values) - && ifModifiedSince == other.ifModifiedSince - && etags.equals(other.etags)); - } - } - return false; - } - - /** - * Return the method of the request. This may either be a HTTP method or - * one of the Helma pseudo methods defined in this class. - */ - public synchronized String getMethod() { - return method; - } - - /** - * Set the method of this request. - * - * @param method the method. - */ - public synchronized void setMethod(String method) { - this.method = method; - } - - /** - * Return true if this object represents a HTTP GET Request. - */ - public boolean isGet() { - return GET.equalsIgnoreCase(method); - } - - /** - * Return true if this object represents a HTTP GET Request. - */ - public boolean isPost() { - return POST.equalsIgnoreCase(method); - } - - /** - * Get the request's session id - */ - public String getSession() { - return session; - } - - /** - * Set the request's session id - */ - public void setSession(String session) { - this.session = session; - } - - /** - * Get the request's path - */ - public String getPath() { - return path; - } - - /** - * Get the request's path - */ - public String getUri() { - return uri; - } - - /** - * Get the request's action. - */ - public String getAction() { - return action; - } - - /** - * Set the request's action. - */ - public void setAction(String action) { - int suffix = action.lastIndexOf("_action"); - this.action = suffix > -1 ? action.substring(0, suffix) : action; - } - - /** - * Get the request's action handler. The action handler allows the - * onRequest() method to set the function object to be invoked for processing - * the request, overriding the action resolved from the request path. - * @return the action handler function - */ - public Object getActionHandler() { - return actionHandler; - } - - /** - * Set the request's action handler. The action handler allows the - * onRequest() method to set the function object to be invoked for processing - * the request, overriding the action resolved from the request path. - * @param handler the action handler - */ - public void setActionHandler(Object handler) { - this.actionHandler = handler; - } - - /** - * Get the time the request was created. - */ - public long getStartTime() { - return startTime; - } - - /** - * - * - * @param since ... - */ - public void setIfModifiedSince(long since) { - ifModifiedSince = since; - } - - /** - * - * - * @return ... - */ - public long getIfModifiedSince() { - return ifModifiedSince; - } - - /** - * - * - * @param etagHeader ... - */ - public void setETags(String etagHeader) { - if (etagHeader.indexOf(",") > -1) { - StringTokenizer st = new StringTokenizer(etagHeader, ", \r\n"); - while (st.hasMoreTokens()) - etags.add(st.nextToken()); - } else { - etags.add(etagHeader); - } - } - - /** - * - * - * @return ... - */ - public Set getETags() { - return etags; - } - - /** - * - * - * @param etag ... - * - * @return ... - */ - public boolean hasETag(String etag) { - if ((etags == null) || (etag == null)) { - return false; - } - - return etags.contains(etag); - } - - /** - * - * - * @return ... - */ - public String getUsername() { - if (httpUsername != null) { - return httpUsername; - } - - String auth = (String) get("authorization"); - - if ((auth == null) || "".equals(auth)) { - return null; - } - - decodeHttpAuth(auth); - - return httpUsername; - } - - /** - * - * - * @return ... - */ - public String getPassword() { - if (httpPassword != null) { - return httpPassword; - } - - String auth = (String) get("authorization"); - - if ((auth == null) || "".equals(auth)) { - return null; - } - - decodeHttpAuth(auth); - - return httpPassword; - } - - private void decodeHttpAuth(String auth) { - if (auth == null) { - return; - } - - StringTokenizer tok; - - if (auth.startsWith("Basic ")) { //$NON-NLS-1$ - tok = new StringTokenizer(new String(Base64.decodeBase64(auth.substring(6))), - ":"); //$NON-NLS-1$ - } else { - tok = new StringTokenizer(new String(Base64.decodeBase64(auth)), ":"); //$NON-NLS-1$ - } - - try { - httpUsername = tok.nextToken(); - } catch (NoSuchElementException e) { - httpUsername = null; - } - - try { - StringBuffer buf = new StringBuffer(tok.nextToken()); - while (tok.hasMoreTokens()) { - buf.append(":"); - buf.append(tok.nextToken()); - } - httpPassword = buf.toString(); - } catch (NoSuchElementException e) { - httpPassword = null; - } - } - - public String toString() { - return method + ":" + path; - } - - class ParameterMap extends SystemMap { - - private static final long serialVersionUID = 7632860503639617076L; - - public ParameterMap() { - super(); - } - - public ParameterMap(Map map) { - super((int) (map.size() / 0.75f) + 1); - for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) { - Map.Entry e = (Map.Entry) i.next(); - put(e.getKey(), e.getValue()); - } - } - - public Object put(Object key, Object value) { - if (key instanceof String) { - String name = (String) key; - int bracket = name.indexOf('['); - if (bracket > -1 && name.endsWith("]")) { - Matcher matcher = paramPattern.matcher(name); - String partName = name.substring(0, bracket); - return putInternal(partName, matcher, value); - } - } - Object previous = super.get(key); - if (previous != null && (previous instanceof Map || value instanceof Map)) - throw new RuntimeException("Conflicting HTTP Parameters for '" + key + "'"); - return super.put(key, value); - } - - private Object putInternal(String name, Matcher matcher, Object value) { - Object previous = super.get(name); - if (matcher.find()) { - ParameterMap map = null; - if (previous instanceof ParameterMap) { - map = (ParameterMap) previous; - } else if (previous == null) { - map = new ParameterMap(); - super.put(name, map); - } else { - throw new RuntimeException("Conflicting HTTP Parameters for '" + name + "'"); - } - String partName = matcher.group(1); - return map.putInternal(partName, matcher, value); - } - if (previous != null && (previous instanceof Map || value instanceof Map)) - throw new RuntimeException("Conflicting HTTP Parameters for '" + name + "'"); - return super.put(name, value); - } - - public Object get(Object key) { - if (key instanceof String) { - Object value = super.get(key); - String name = (String) key; - if (name.endsWith("_array") && value == null) { - value = super.get(name.substring(0, name.length() - 6)); - return value instanceof Object[] ? value : null; - } else if (name.endsWith("_cookie") && value == null) { - value = super.get(name.substring(0, name.length() - 7)); - return value instanceof Cookie ? value : null; - } else if (value instanceof Object[]) { - Object[] values = ((Object[]) value); - return values.length > 0 ? values[0] : null; - } else if (value instanceof Cookie) { - Cookie cookie = (Cookie) value; - return cookie.getValue(); - } - } - return super.get(key); - } - - protected Object getRaw(Object key) { - return super.get(key); - } - } - - class DataComboMap extends SystemMap { - - private static final long serialVersionUID = 5737810055554406299L; - - public Object get(Object key) { - Object value = super.get(key); - if (value != null) - return value; - if (postParams != null && (value = postParams.get(key)) != null) - return value; - if (queryParams != null && (value = queryParams.get(key)) != null) - return value; - if (cookies != null && (value = cookies.get(key)) != null) - return value; - return null; - } - - public boolean containsKey(Object key) { - return get(key) != null; - } - - public Set entrySet() { - Set entries = new HashSet(super.entrySet()); - if (postParams != null) entries.addAll(postParams.entrySet()); - if (queryParams != null) entries.addAll(queryParams.entrySet()); - if (cookies != null) entries.addAll(cookies.entrySet()); - return entries; - } - - public Set keySet() { - Set keys = new HashSet(super.keySet()); - if (postParams != null) keys.addAll(postParams.keySet()); - if (queryParams != null) keys.addAll(queryParams.keySet()); - if (cookies != null) keys.addAll(cookies.keySet()); - return keys; - } - } - - class ParamComboMap extends SystemMap { - private static final long serialVersionUID = -9177176570950359431L; - - public Object get(Object key) { - Object value; - if (postParams != null && (value = postParams.get(key)) != null) - return value; - if (queryParams != null && (value = queryParams.get(key)) != null) - return value; - return null; - } - - public boolean containsKey(Object key) { - return get(key) != null; - } - - public Set entrySet() { - Set entries = new HashSet(); - if (postParams != null) entries.addAll(postParams.entrySet()); - if (queryParams != null) entries.addAll(queryParams.entrySet()); - return entries; - } - - public Set keySet() { - Set keys = new HashSet(); - if (postParams != null) keys.addAll(postParams.keySet()); - if (queryParams != null) keys.addAll(queryParams.keySet()); - return keys; - } - } -} diff --git a/src/main/java/helma/framework/ResponseBean.java b/src/main/java/helma/framework/ResponseBean.java deleted file mode 100644 index 061ecb54..00000000 --- a/src/main/java/helma/framework/ResponseBean.java +++ /dev/null @@ -1,716 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - -import helma.objectmodel.db.Transactor; -import helma.scripting.ScriptingException; - -import jakarta.servlet.http.HttpServletResponse; -import java.io.Serializable; -import java.io.StringWriter; -import java.io.PrintWriter; -import java.util.Date; -import java.util.Map; - -/** - * - */ -public class ResponseBean implements Serializable { - private static final long serialVersionUID = -6807623667477109800L; - - ResponseTrans res; - - /** - * Creates a new ResponseBean object. - * - * @param res the wrapped ResponseTrans - */ - public ResponseBean(ResponseTrans res) { - this.res = res; - } - - /** - * Write an object to the response buffer by converting it to a string - * and then HTML-encoding it. - * - * @param obj the object to write to the response buffer - */ - public void encode(Object obj) { - res.encode(obj); - } - - /** - * Write an object to the response buffer by converting it to a string - * and then XML-encoding it. - * - * @param obj the object to write to the response buffer - */ - public void encodeXml(Object obj) { - res.encodeXml(obj); - } - - /** - * Write an object to the response buffer by converting it to a string - * and then encoding it for form/text area content use. - * - * @param obj the object to write to the response buffer - */ - public void encodeForm(Object obj) { - res.encodeForm(obj); - } - - /** - * Write an object to the response buffer by converting it to a string - * and then HTML-formatting it. - * - * @param obj the object to write to the response buffer - */ - public void format(Object obj) { - res.format(obj); - } - - /** - * Redirect the request to a different URL - * - * @param url the URL to redirect to - * @throws RedirectException to immediately terminate the request - */ - public void redirect(String url) throws RedirectException { - res.redirect(url); - } - - /** - * Internally forward the request to a different URL - * - * @param url the URL to forward to - * @throws RedirectException to immediately terminate the request - */ - public void forward(String url) throws RedirectException { - res.forward(url); - } - - /** - * Immediately stop processing the current request - * - * @throws RedirectException to immediately terminate the request - */ - public void stop() throws RedirectException { - res.redirect(null); - } - - /** - * Reset the response object, clearing all content previously written to it - */ - public void reset() { - res.reset(); - } - - /** - * Reset the response buffer, clearing all content previously written to it - */ - public void resetBuffer() { - res.resetBuffer(); - } - - /** - * Returns the ServletResponse instance for this Response. - * Returns null for internal and XML-RPC requests. - * @return the servlet response - */ - public HttpServletResponse getServletResponse() { - return res.getServletResponse(); - } - - /** - * Set a HTTP cookie with the name and value that is discarded when the - * HTTP client is closed - * - * @param key the cookie name - * @param value the cookie value - */ - public void setCookie(String key, String value) { - res.setCookie(key, value, -1, null, null, true, false); - } - - /** - * Set a HTTP cookie with the name and value that is stored by the - * HTTP client for the given number of days. A days value of 0 means the - * cookie should be immediately discarded. - * - * @param key the cookie name - * @param value the cookie value - * @param days number of days the cookie should be stored - */ - public void setCookie(String key, String value, int days) { - res.setCookie(key, value, days, null, null, true, false); - } - - /** - * Set a HTTP cookie with the name and value that is only applied to - * the URLs matching the given path and is stored by the - * HTTP client for the given number of days. A days value of 0 means the - * cookie should be immediately discarded. - * - * @param key the cookie name - * @param value the cookie value - * @param days number of days the cookie should be stored - * @param path the URL path to apply the cookie to - */ - public void setCookie(String key, String value, int days, String path) { - res.setCookie(key, value, days, path, null, true, false); - } - - /** - * Set a HTTP cookie with the name and value that is only applied to - * the URLs matching the given path and is stored by the - * HTTP client for the given number of days. A days value of 0 means the - * cookie should be immediately discarded. - * - * @param key the cookie name - * @param value the cookie value - * @param days number of days the cookie should be stored - * @param path the URL path to apply the cookie to - * @param domain domain - * @param isHttpOnly marks the cookie as HttpOnly - */ - public void setCookie(String key, String value, int days, String path, String domain, boolean isHttpOnly) { - res.setCookie(key, value, days, path, domain, isHttpOnly, false); - } - - /** - * Set a HTTP cookie with the name and value that is only applied to - * the URLs matching the given path and is stored by the - * HTTP client for the given number of days. A days value of 0 means the - * cookie should be immediately discarded. - * - * @param key the cookie name - * @param value the cookie value - * @param days number of days the cookie should be stored - * @param path the URL path to apply the cookie to - * @param domain domain - * @param isHttpOnly marks the cookie as HttpOnly - * @param isSecure limits the cookie to secure protocols - */ - public void setCookie(String key, String value, int days, String path, String domain, boolean isHttpOnly, boolean isSecure) { - res.setCookie(key, value, days, path, domain, isHttpOnly, isSecure); - } - - /** - * Set a HTTP cookie with the name and value that is only applied to - * the URLs matching the given path and is stored by the - * HTTP client for the given number of days. A days value of 0 means the - * cookie should be immediately discarded. - * - * @param key the cookie name - * @param value the cookie value - * @param days number of days the cookie should be stored - * @param path the URL path to apply the cookie to - * @param domain domain - */ - public void setCookie(String key, String value, int days, String path, String domain) { - res.setCookie(key, value, days, path, domain, true, false); - } - - /** - * Unset a previously set HTTP cookie, causing it to be discarded immedialtely by the - * HTTP client. - * - * @param key the name of the cookie to be discarded - */ - public void unsetCookie(String key) { - res.setCookie(key, "", 0, null, null, true, false); - } - - /** - * Directly write a string to the response buffer without any transformation. - * - * @param str the string to write to the response buffer - */ - public void write(String... str) { - if (str == null) return; - - for (String s : str) { - res.write(s + ""); - } - } - - /** - * Write string to response buffer and append a platform dependent newline sequence. - * - * @param str the string to write to the response buffer - */ - public void writeln(String... str) { - if (str == null) return; - - for (String s : str) { - res.write(s + ""); - } - - res.writeln(); - } - - /** - * Write a platform dependent newline sequence to response buffer. - */ - public void writeln() { - res.writeln(); - } - - /** - * Directly write a byte array to the response buffer without any transformation. - * - * @param bytes the string to write to the response buffer - */ - public void writeBinary(byte[] bytes) { - res.writeBinary(bytes); - } - - /** - * add HTML formatted debug messages to the end of the page. - * - * @param messages the list of messages - */ - public void debug(String... messages) { - if (messages == null) { - messages = new String[]{null}; - } - - for (String message : messages) { - res.debug(message + " "); - } - } - - /** - * Return a string representation for this object - * - * @return string representation - */ - public String toString() { - return "[Response]"; - } - - // property-related methods - - /** - * Return the current cachability setting for this response - * - * @return true if the response may be cached by the HTTP client, false otherwise - */ - public boolean getCache() { - return res.isCacheable(); - } - - /** - * Set true cachability setting for this response - * - * @param cache true if the response may be cached by the HTTP client, false otherwise - */ - public void setCache(boolean cache) { - res.setCacheable(cache); - } - - /** - * Get the current charset/encoding name for the response - * - * @return The charset name - */ - public String getCharset() { - return res.getCharset(); - } - - /** - * Set the charset/encoding name for the response - * - * @param charset The charset name - */ - public void setCharset(String charset) { - res.setCharset(charset); - } - - /** - * Get the current content type name for the response - * - * @return the content type - */ - public String getContentType() { - return res.getContentType(); - } - - /** - * Set the content type for the response - * - * @param contentType The charset name - */ - public void setContentType(String contentType) { - res.setContentType(contentType); - } - - /** - * Proxy to HttpServletResponse.addHeader() - * @param name the header name - * @param value the header value - */ - public void addHeader(String name, String value) { - res.addHeader(name, value); - } - - /** - * Proxy to HttpServletResponse.addDateHeader() - * @param name the header name - * @param value the header value - */ - public void addDateHeader(String name, Date value) { - res.addDateHeader(name, value); - } - - /** - * Proxy to HttpServletResponse.setHeader() - * @param name the header name - * @param value the header value - */ - public void setHeader(String name, String value) { - res.setHeader(name, value); - } - - /** - * Proxy to HttpServletResponse.setDateHeader() - * @param name the header name - * @param value the header value - */ - public void setDateHeader(String name, Date value) { - res.setDateHeader(name, value); - } - - - /** - * Get the data map for the response - * - * @return the data object - */ - public Map getData() { - return res.getResponseData(); - } - - /** - * Get the macro handlers map for the response - * - * @return the macro handlers map - */ - public Map getHandlers() { - return res.getMacroHandlers(); - } - - /** - * Get the meta map for the response - * - * @return the meta map - */ - public Map getMeta() { - return res.getMetaData(); - } - - /** - * Get the current error message for the response, if any - * - * @return the error message - */ - public String getError() { - return res.getErrorMessage(); - } - - /** - * Get the uncaught exception for the response, if any - * @return the uncaught exception - */ - public Throwable getException() { - return res.getError(); - } - - /** - * Return the Javascript stack trace of an uncought exception. - * @return the script stack trace of any uncaught exception or null. - */ - public String getScriptStack() { - Throwable t = res.getError(); - if (t instanceof ScriptingException) - return ((ScriptingException) t).getScriptStackTrace(); - return null; - } - - /** - * Get the Java stack trace of an uncaught exception. - * @return the java stack trace of an uncaught exception or null. - */ - public String getJavaStack() { - Throwable t = res.getError(); - if (t == null) - return null; - else if (t instanceof ScriptingException) - return ((ScriptingException) t).getJavaStackTrace(); - StringWriter w = new StringWriter(); - t.printStackTrace(new PrintWriter(w)); - return w.toString(); - } - - /** - * Get the current message for the response, if set - * - * @return the message - */ - public String getMessage() { - return res.getMessage(); - } - - /** - * Set the message property for the response - * - * @param message the message property - */ - public void setMessage(String message) { - res.setMessage(message); - } - - /** - * Get the HTTP authentication realm for the response - * - * @return the HTTP authentication realm - */ - public String getRealm() { - return res.getRealm(); - } - - /** - * Set the HTTP authentication realm for the response - * - * @param realm the HTTP authentication realm - */ - public void setRealm(String realm) { - res.setRealm(realm); - } - - /** - * Set the skin search path for the response - * - * @param arr an array containing files or nodes containing skins - */ - public void setSkinpath(Object[] arr) { - res.setSkinpath(arr); - } - - /** - * Get the skin search path for the response - * - * @return The array of files or nodes used to search for skins - */ - public Object[] getSkinpath() { - return res.getSkinpath(); - } - - /** - * Get the HTTP status code for this response - * - * @return the HTTP status code - */ - public int getStatus() { - return res.getStatus(); - } - - /** - * Set the HTTP status code for this response - * - * @param status the HTTP status code - */ - public void setStatus(int status) { - res.setStatus(status); - } - - /** - * Get the last modified date for this response - * - * @return the last modified date - */ - public Date getLastModified() { - long modified = res.getLastModified(); - - if (modified > -1) { - return new Date(modified); - } else { - return null; - } - } - - /** - * Set the last modified date for this response - * - * @param date the last modified date - */ - public void setLastModified(Date date) { - if (date == null) { - res.setLastModified(-1); - } else { - res.setLastModified(date.getTime()); - } - } - - /** - * Get the ETag for this response - * - * @return the HTTP etag - */ - public String getETag() { - return res.getETag(); - } - - /** - * Set the HTTP Etag for this response - * - * @param etag the HTTP ETag - */ - public void setETag(String etag) { - res.setETag(etag); - } - - /** - * Add an item to this response's dependencies. If no dependency has changed between - * requests, an HTTP not-modified response will be generated. - * - * @param what a string item this response depends on - */ - public void dependsOn(String what) { - res.dependsOn(what); - } - - /** - * Digest this response's dependencies to conditionally create a HTTP not-modified response - */ - public void digest() { - res.digestDependencies(); - } - - /** - * Push a string buffer on the response object. All further - * writes will be redirected to this buffer. - */ - public void push() { - res.pushBuffer(null); - } - - /** - * Pop a string buffer from the response object containing - * all the writes since the last pushBuffer - * - * @return ... - */ - public String pop() { - return res.popString(); - } - - /** - * Old version for push() kept for compatibility - * @deprecated - */ - @Deprecated - public void pushStringBuffer() { - res.pushBuffer(null); - } - - /** - * Old version for pop() kept for compatibility - * @deprecated - * @return ... - */ - @Deprecated - public String popStringBuffer() { - return res.popString(); - } - - /** - * Push a string buffer on the response object. All further - * writes will be redirected to this buffer. - * @param buffer the string buffer - * @return the new stringBuffer - */ - public StringBuffer pushBuffer(StringBuffer buffer) { - return res.pushBuffer(buffer); - } - - /** - * Push a string buffer on the response object. All further - * writes will be redirected to this buffer. - * @return the new stringBuffer - */ - public StringBuffer pushBuffer() { - return res.pushBuffer(null); - } - - /** - * Pops the current response buffer without converting it to a string - * @return the stringBuffer - */ - public StringBuffer popBuffer() { - return res.popBuffer(); - } - - /** - * Returns the current response buffer as string. - * - * @return the response buffer as string - */ - public String getBuffer() { - return res.getBuffer().toString(); - } - - /** - * Commit changes made during the course of the current transaction - * and start a new one - * - * @throws Exception thrown if commit fails - */ - public void commit() throws Exception { - Transactor tx = Transactor.getInstance(); - if (tx != null) { - String tname = tx.getTransactionName(); - tx.commit(); - tx.begin(tname); - } - } - - /** - * Rollback the current transaction and start a new one. - * - * @throws Exception thrown if rollback fails - */ - public void rollback() throws Exception { - Transactor tx = Transactor.getInstance(); - if (tx != null) { - String tname = tx.getTransactionName(); - tx.abort(); - tx.begin(tname); - } - } - - /** - * Rollback the current database transaction and abort execution. - * This has the same effect as calling rollback() and then stop(). - * - * @throws AbortException thrown to exit the the current execution - */ - public void abort() throws AbortException { - throw new AbortException(); - } - -} diff --git a/src/main/java/helma/framework/ResponseTrans.java b/src/main/java/helma/framework/ResponseTrans.java deleted file mode 100644 index 239487d7..00000000 --- a/src/main/java/helma/framework/ResponseTrans.java +++ /dev/null @@ -1,1177 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - -import helma.framework.core.Skin; -import helma.framework.core.Application; -import helma.util.*; -import helma.scripting.ScriptingException; - -import jakarta.servlet.http.HttpServletResponse; -import java.io.*; -import java.security.*; -import java.util.*; - -import org.apache.commons.codec.binary.Base64; -import org.apache.xmlrpc.XmlRpcResponseProcessor; - -/** - * A Transmitter for a response to the servlet client. Objects of this - * class are directly exposed to JavaScript as global property res. - */ -public final class ResponseTrans extends Writer implements Serializable { - - static final long serialVersionUID = -8627370766119740844L; - static final int INITIAL_BUFFER_SIZE = 2048; - - static final String newLine = System.getProperty("line.separator"); - - // MIME content type of the response. - private String contentType = "text/html"; - - // Charset (encoding) to use for the response. - private String charset; - - // Used to allow or disable client side caching - private boolean cacheable = true; - - // HTTP response code, defaults to 200 (OK). - private int status = 200; - - // HTTP authentication realm - private String realm; - - // the actual response - private byte[] response = null; - - // contains the redirect URL - private String redir = null; - - // the forward (internal redirect) URL - private String forward = null; - - // the last-modified date, if it should be set in the response - private long lastModified = -1; - - // flag to signal that resource has not been modified - private boolean notModified = false; - - // Entity Tag for this response, used for conditional GETs - private String etag = null; - - // cookies - Map cookies; - - // the buffer used to build the response - private transient StringBuffer buffer = null; - - // an idle StringBuffer waiting to be reused - private transient StringBuffer cachedBuffer = null; - - // these are used to implement the _as_string variants for Hop templates. - private transient Stack buffers; - - // the path used to tell where to look for skins - private transient Object[] skinpath = null; - - // hashmap for skin caching - private transient HashMap skincache; - - // buffer for debug messages - will be automatically appended to response - private transient StringBuffer debugBuffer; - - // field for generic message to be displayed - private transient String message; - - // field for error - private transient Throwable error; - - // the res.data map of form and cookie data - private transient Map values = new SystemMap(); - - // the res.handlers map of macro handlers - private transient Map handlers = new SystemMap(); - - // the res.meta map for meta response data - private transient Map meta = new SystemMap(); - - // the request trans for this response - private transient RequestTrans reqtrans; - - // the message digest used to generate composed digests for ETag headers - private transient MessageDigest digest; - - // the skin current or last rendered skin - private transient volatile Skin activeSkin; - - // the application - Application app; - - - /** - * Creates a new ResponseTrans object. - * - * @param req the RequestTrans for this response - */ - public ResponseTrans(Application app, RequestTrans req) { - this.app = app; - reqtrans = req; - } - - /** - * Get a value from the responses map by key. - */ - public Object get(String name) { - try { - return values.get(name); - } catch (Exception x) { - return null; - } - } - - /** - * Get the data map for this response transmitter. - */ - public Map getResponseData() { - return values; - } - - /** - * Get the macro handlers map for this response transmitter. - */ - public Map getMacroHandlers() { - return handlers; - } - - /** - * Get the meta info map for this response transmitter. - */ - public Map getMetaData() { - return meta; - } - - /** - * Returns the ServletResponse instance for this ResponseTrans. - * Returns null for internal and XML-RPC requests. - */ - public HttpServletResponse getServletResponse() { - return reqtrans.getServletResponse(); - } - - /** - * Reset the current response buffer. - */ - public synchronized void resetBuffer() { - if (buffer != null) { - buffer.setLength(0); - } - } - - /** - * Reset the response object to its initial empty state. - */ - public synchronized void reset() { - if (buffer != null) { - buffer.setLength(0); - } - - buffers = null; - response = null; - cacheable = true; - redir = forward = message = null; - error = null; - etag = realm = charset = null; - contentType = "text/html"; - values.clear(); - handlers.clear(); - meta.clear(); - lastModified = -1; - notModified = false; - skinpath = null; - skincache = null; - cookies = null; - - if (digest != null) { - digest.reset(); - } - } - - /** - * This is called before a skin is rendered as string - * (renderSkinAsString) to redirect the output to a new - * string buffer. - * @param buf the StringBuffer to use, or null - * @return the new StringBuffer instance - */ - public synchronized StringBuffer pushBuffer(StringBuffer buf) { - if (buffers == null) { - buffers = new Stack(); - } - - if (buffer != null) { - buffers.push(buffer); - } - - if (buf != null) { - buffer = buf; - } else if (cachedBuffer != null) { - buffer = cachedBuffer; - cachedBuffer = null; - } else { - buffer = new StringBuffer(64); - } - return buffer; - } - - /** - * Returns the content of the current string buffer and switches back to the previos one. - */ - public synchronized String popString() { - StringBuffer buf = popBuffer(); - String str = buf.toString(); - // store stringbuffer for later reuse - buf.setLength(0); - cachedBuffer = buf; - return str; - } - - public synchronized StringBuffer popBuffer() { - if (buffer == null) { - throw new RuntimeException("Can't pop string buffer: buffer is null"); - } else if (buffers == null) { - throw new RuntimeException("Can't pop string buffer: buffer stack is empty"); - } - // get local reference - StringBuffer buf = buffer; - // restore the previous buffer, which may be null - buffer = buffers.empty() ? null : (StringBuffer) buffers.pop(); - return buf; - } - - /** - * Get the response buffer, creating it if it doesn't exist - */ - public synchronized StringBuffer getBuffer() { - if (buffer == null) { - buffer = new StringBuffer(INITIAL_BUFFER_SIZE); - } - - return buffer; - } - - /** - * Append a string to the response unchanged. - */ - public synchronized void write(String str) { - if (str != null) { - if (buffer == null) { - buffer = new StringBuffer(Math.max(str.length() + 100, INITIAL_BUFFER_SIZE)); - } - buffer.append(str); - } - } - - /** - * Appends a objct to the response unchanged. - * The object is first converted to a string. - */ - public void write(Object what) { - if (what != null) { - write(what.toString()); - } - } - - /** - * Appends a part from a char array to the response buffer. - * - * @param chars - * @param offset - * @param length - */ - public synchronized void write(char[] chars, int offset, int length) { - if (buffer == null) { - buffer = new StringBuffer(Math.max(length + 100, INITIAL_BUFFER_SIZE)); - } - buffer.append(chars, offset, length); - } - - /** - * Appends a char array to the response buffer. - * - * @param chars - */ - public void write(char chars[]) { - write(chars, 0, chars.length); - } - - - /** - * Appends a signle character to the response buffer. - * @param c - */ - public synchronized void write(int c) { - if (buffer == null) { - buffer = new StringBuffer(INITIAL_BUFFER_SIZE); - } - buffer.append((char) c); - } - - /** - * Appends a part from a string to the response buffer. - * @param str - * @param offset - * @param length - */ - public void write(String str, int offset, int length) { - char cbuf[] = new char[length]; - str.getChars(offset, (offset + length), cbuf, 0); - write(cbuf, 0, length); - } - - /** - * Write object to response buffer and append a platform dependent newline sequence. - */ - public synchronized void writeln(Object what) { - if (what != null) { - write(what.toString()); - } else if (buffer == null) { - // if what is null, buffer may still be uninitialized - buffer = new StringBuffer(INITIAL_BUFFER_SIZE); - } - buffer.append(newLine); - } - - /** - * Writes a platform dependent newline sequence to response buffer. - */ - public synchronized void writeln() { - // buffer may still be uninitialized - if (buffer == null) { - buffer = new StringBuffer(INITIAL_BUFFER_SIZE); - } - buffer.append(newLine); - } - - /** - * Insert string somewhere in the response buffer. Caller has to make sure - * that buffer exists and its length is larger than offset. str may be null, in which - * case nothing happens. - */ - public void debug(Object message) { - if (debugBuffer == null) { - debugBuffer = new StringBuffer(); - } - - String str = (message == null) ? "null" : message.toString(); - - debugBuffer.append("

    "); - debugBuffer.append(str); - debugBuffer.append("
    "); - } - - /** - * Replace special characters with entities, including {@code <}, {@code >} and {@code "}, thus allowing - * no HTML tags. - */ - public synchronized void encode(Object what) { - if (what != null) { - String str = what.toString(); - - if (buffer == null) { - buffer = new StringBuffer(Math.max(str.length() + 100, INITIAL_BUFFER_SIZE)); - } - - HtmlEncoder.encodeAll(str, buffer); - } - } - - /** - * Replace special characters with entities but pass through HTML tags - */ - public synchronized void format(Object what) { - if (what != null) { - String str = what.toString(); - - if (buffer == null) { - buffer = new StringBuffer(Math.max(str.length() + 100, INITIAL_BUFFER_SIZE)); - } - - HtmlEncoder.encode(str, buffer); - } - } - - /** - * Replace special characters with entities, including {@code <}, {@code >} and {@code "}, thus allowing - * no HTML tags. - */ - public synchronized void encodeXml(Object what) { - if (what != null) { - String str = what.toString(); - - if (buffer == null) { - buffer = new StringBuffer(Math.max(str.length() + 100, INITIAL_BUFFER_SIZE)); - } - - HtmlEncoder.encodeXml(str, buffer); - } - } - - /** - * Encode HTML entities, but leave newlines alone. This is for the content of textarea forms. - */ - public synchronized void encodeForm(Object what) { - if (what != null) { - String str = what.toString(); - - if (buffer == null) { - buffer = new StringBuffer(Math.max(str.length() + 100, INITIAL_BUFFER_SIZE)); - } - - HtmlEncoder.encodeAll(str, buffer, false); - } - } - - /** - * - * - * @param url ... - * - * @throws RedirectException ... - */ - public void redirect(String url) throws RedirectException { - // remove newline chars to prevent response splitting attack - redir = url == null ? - null : url.replaceAll("[\r\n]", ""); - throw new RedirectException(redir); - } - - /** - * - * - * @return ... - */ - public String getRedirect() { - return redir; - } - - /** - * - * - * @param url ... - * - * @throws RedirectException ... - */ - public void forward(String url) throws RedirectException { - // remove newline chars to prevent response splitting attack - forward = url == null ? - null : url.replaceAll("[\r\n]", ""); - throw new RedirectException(forward); - } - - /** - * - * - * @return ... - */ - public String getForward() { - return forward; - } - - /** - * Allow to directly set the byte array for the response. Calling this more than once will - * overwrite the previous output. - * @param bytes an arbitrary byte array - */ - public void writeBinary(byte[] bytes) { - response = bytes; - } - - /** - * Proxy to HttpServletResponse.addHeader() - * @param name the header name - * @param value the header value - */ - public void addHeader(String name, String value) { - HttpServletResponse res = getServletResponse(); - if (res != null) - res.addHeader(name, value); - } - - /** - * Proxy to HttpServletResponse.addDateHeader() - * @param name the header name - * @param value the header value - */ - public void addDateHeader(String name, Date value) { - HttpServletResponse res = getServletResponse(); - if (res != null) - res.addDateHeader(name, value.getTime()); - } - - /** - * Proxy to HttpServletResponse.setHeader() - * @param name the header name - * @param value the header value - */ - public void setHeader(String name, String value) { - HttpServletResponse res = getServletResponse(); - if (res != null) - res.setHeader(name, value); - } - - /** - * Proxy to HttpServletResponse.setDateHeader() - * @param name the header name - * @param value the header value - */ - public void setDateHeader(String name, Date value) { - HttpServletResponse res = getServletResponse(); - if (res != null) - res.setDateHeader(name, value.getTime()); - } - - /** - * Write a vanilla error report. Callers should make sure the ResponeTrans is - * new or has been reset. - * - * @param throwable the error - */ - public void reportError(Throwable throwable) { - if (throwable == null) { - // just to be safe - reportError("Unspecified error"); - return; - } - if (reqtrans.isXmlRpc()) { - writeXmlRpcError(new RuntimeException(throwable)); - } else { - status = 500; - if (!"true".equalsIgnoreCase(app.getProperty("suppressErrorPage"))) { - write(""); - write("

    Error in application " + app.getName() + "

    "); - encode(getErrorMessage(throwable)); - writeln("

    "); - if (app.debug()) { - if (throwable instanceof ScriptingException) { - ScriptingException scriptx = (ScriptingException) throwable; - writeln("

    Script Stack

    "); - writeln("
    " + scriptx.getScriptStackTrace() + "
    "); - writeln("

    Java Stack

    "); - writeln("
    " + scriptx.getJavaStackTrace() + "
    "); - } else { - writeln("

    Java Stack

    "); - writeln("
    ");
    -                        throwable.printStackTrace(new PrintWriter(this));
    -                        writeln("
    "); - } - } - writeln(""); - } - } - } - - /** - * Write a vanilla error report. Callers should make sure the ResponeTrans is - * new or has been reset. - * @param errorMessage the error message - */ - public void reportError(String errorMessage) { - if (reqtrans.isXmlRpc()) { - writeXmlRpcError(new RuntimeException(errorMessage)); - } else { - status = 500; - if (!"true".equalsIgnoreCase(app.getProperty("suppressErrorPage"))) { - write("

    "); - write("Error in application "); - write(app.getName()); - write("

    "); - encode(errorMessage); - writeln("

    "); - } - } - } - - public void writeXmlRpcResponse(Object result) { - try { - reset(); - contentType = "text/xml"; - if (charset == null) { - charset = "UTF-8"; - } - XmlRpcResponseProcessor xresproc = new XmlRpcResponseProcessor(); - writeBinary(xresproc.encodeResponse(result, charset)); - } catch (Exception x) { - writeXmlRpcError(x); - } - } - - public void writeXmlRpcError(Exception x) { - contentType = "text/xml"; - if (charset == null) { - charset = "UTF-8"; - } - XmlRpcResponseProcessor xresproc = new XmlRpcResponseProcessor(); - writeBinary(xresproc.encodeException(x, charset)); - } - - public void flush() { - // does nothing! - } - - /** - * This has to be called after writing to this response has finished and before it is shipped back to the - * web server. Transforms the string buffer into a byte array for transmission. - */ - public void close() throws UnsupportedEncodingException { - close(null); - } - - /** - * This has to be called after writing to this response has finished and before it is shipped back to the - * web server. Transforms the string buffer into a byte array for transmission. - * @param defaultCharset the charset to use if no explicit charset has been set on the response - * @throws UnsupportedEncodingException if the charset is not a valid encoding name - */ - public synchronized void close(String defaultCharset) throws UnsupportedEncodingException { - // if the response was already written and committed by the application - // there's no point in closing the response buffer - HttpServletResponse res = reqtrans.getServletResponse(); - if (res != null && res.isCommitted()) { - // response was committed using HttpServletResponse directly. We need - // set response to null and notify waiters in order to let attached - // requests know they can't reuse this response. - response = null; - notifyAll(); - return; - } - - boolean encodingError = false; - - // only close if the response hasn't been closed yet, and if no - // response was generated using writeBinary(). - if (response == null) { - // only use default charset if not explicitly set for this response. - if (charset == null) { - charset = defaultCharset; - } - // if charset is not set, use western encoding - if (charset == null) { - charset = "UTF-8"; - } - - // if debug buffer exists, append it to main buffer - if (contentType != null && - contentType.startsWith("text/html") && - debugBuffer != null) { - debugBuffer.append("
    "); - if (buffer == null) { - buffer = debugBuffer; - } else { - buffer.append(debugBuffer); - } - } - - // get the buffer's bytes in the specified encoding - if (buffer != null) { - try { - response = buffer.toString().getBytes(charset); - } catch (UnsupportedEncodingException uee) { - encodingError = true; - response = buffer.toString().getBytes(); - } - - // make sure this is done only once, even with more requsts attached - buffer = null; - } else { - response = new byte[0]; - } - } - - boolean autoETags = "true".equals(app.getProperty("autoETags", "true")); - // if etag is not set, calc MD5 digest and check it, but only if - // not a redirect or error - if (autoETags && - etag == null && - lastModified == -1 && - status == 200 && - redir == null) { - try { - digest = MessageDigest.getInstance("MD5"); - // if (contentType != null) - // digest.update (contentType.getBytes()); - byte[] b = this.digest.digest(this.response); - this.etag = "\"" + new String(Base64.encodeBase64(b)) + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - // only set response to 304 not modified if no cookies were set - if (reqtrans.hasETag(etag) && countCookies() == 0) { - response = new byte[0]; - notModified = true; - } - } catch (Exception e) { - // Etag creation failed for some reason. - app.logError("Error creating ETag: " + e); - } - } - - notifyAll(); - - // if there was a problem with the encoding, let the app know - if (encodingError) { - throw new UnsupportedEncodingException(charset); - } - } - - /** - * If we just attached to evaluation we call this instead of close because only the primary thread - * is responsible for closing the result - */ - public synchronized void waitForClose() { - try { - if (response == null) { - wait(10000L); - } - } catch (InterruptedException ix) { - // Ignore - } - } - - /** - * Get the body content for this response as byte array, encoded using the - * response's charset. - * - * @return the response body - */ - public byte[] getContent() { - return response; - } - - /** - * Get the number of bytes of the response body. - * - * @return the length of the response body - */ - public int getContentLength() { - if (response != null) { - return response.length; - } - - return 0; - } - - /** - * Get the response's MIME content type - * - * @return the MIME type for this response - */ - public String getContentType() { - if (charset != null) { - return contentType + "; charset=" + charset; - } - - return contentType; - } - - - /** - * Set the response's MIME content type - * - * @param contentType MIME type for this response - */ - public void setContentType(String contentType) { - this.contentType = contentType; - } - - /** - * Set the Last-Modified header for this response - * - * @param modified the Last-Modified header in milliseconds - */ - public void setLastModified(long modified) { - // date headers don't do milliseconds, round to seconds - lastModified = (modified / 1000) * 1000; - if (reqtrans.getIfModifiedSince() == lastModified) { - notModified = true; - throw new RedirectException(null); - } - } - - /** - * Get the value of the Last-Modified header for this response. - * - * @return the Last-Modified header in milliseconds - */ - public long getLastModified() { - return lastModified; - } - - /** - * Set the ETag header value for this response. - * - * @param value the ETag header value - */ - public void setETag(String value) { - etag = (value == null) ? null : ("\"" + value + "\""); - if (etag != null && reqtrans.hasETag(etag)) { - notModified = true; - throw new RedirectException(null); - } - } - - /** - * Get the ETag header value for this response. - * - * @return the ETag header value - */ - public String getETag() { - return etag; - } - - /** - * Check if this response should generate a Not-Modified response. - * - * @return true if the the response wasn't modified since the client last saw it. - */ - public boolean getNotModified() { - return notModified; - } - - /** - * Add a dependency to this response. - * - * @param what an item this response's output depends on. - */ - public void dependsOn(Object what) { - if (digest == null) { - try { - digest = MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException nsa) { - // MD5 should always be available - } - } - - if (what == null) { - digest.update(new byte[0]); - } else if (what instanceof Date) { - digest.update(Long.toBinaryString(((Date) what).getTime()).getBytes()); - } else if (what instanceof byte[]) { - digest.update((byte[]) what); - } else { - String str = what.toString(); - - if (str != null) { - digest.update(str.getBytes()); - } else { - digest.update(new byte[0]); - } - } - } - - /** - * Digest all dependencies to a checksum to see if the response has changed. - */ - public void digestDependencies() { - if (digest == null) { - return; - } - - // add the application checksum as dependency to make ETag - // generation sensitive to changes in the app - byte[] b = digest.digest(Long.toBinaryString((this.app.getChecksum())).getBytes()); - - setETag(new String(Base64.encodeBase64(b))); - } - - /** - * Set the path in which to look for skins. This may contain file locations and - * HopObjects. - * - * @param arr the skin path - */ - public void setSkinpath(Object[] arr) { - this.skinpath = arr; - skincache = null; - } - - /** - * Get the path in which to look for skins. This may contain file locations and - * HopObjects. - * - * @return the skin path - */ - public Object[] getSkinpath() { - if (skinpath == null) { - skinpath = new Object[0]; - } - - return skinpath; - } - - /** - * Look up a cached skin. - * - * @param id the skin key - * @return the skin, or null if no skin is cached for the given key - */ - public Skin getCachedSkin(Object id) { - if (skincache == null) { - return null; - } - - return (Skin) skincache.get(id); - } - - /** - * Cache a skin for the length of this response. - * - * @param id the skin key - * @param skin the skin to cache - */ - public void cacheSkin(Object id, Skin skin) { - if (skincache == null) { - skincache = new HashMap(); - } - - skincache.put(id, skin); - } - - /** - * Set the skin currently being rendered, returning the previously active skin. - * @param skin the new active skin - * @return the previously active skin - */ - public Skin switchActiveSkin(Skin skin) { - Skin previousSkin = activeSkin; - activeSkin = skin; - return previousSkin; - } - - /** - * Return the skin currently being rendered, or none. - * @return the currently active skin - */ - public Skin getActiveSkin() { - return activeSkin; - } - - /** - * Set a cookie. - * - * @param key the cookie key - * @param value the cookie value - * @param days the cookie's lifespan in days - * @param path the URL path to apply the cookie to - * @param domain the domain to apply the cookie to - * @param isHttpOnly marks the cookie as HttpOnly - * @param isSecure limits the cookie for use with secure protocols - */ - public void setCookie(String key, String value, int days, String path, String domain, boolean isHttpOnly, boolean isSecure) { - CookieTrans c = null; - - if (cookies == null) { - cookies = new HashMap(); - } else { - c = (CookieTrans) cookies.get(key); - } - - // remove newline chars to prevent response splitting attack - if (value != null) { - value = value.replaceAll("[\r\n]", ""); - } - - if (c == null) { - c = new CookieTrans(key, value); - cookies.put(key, c); - } else { - c.setValue(value); - } - - c.setDays(days); - c.setPath(path); - c.setDomain(domain); - - if (!"false".equalsIgnoreCase(app.getProperty("cookies.httpOnly"))) { - c.setHttpOnly(true); - } - - if ("true".equalsIgnoreCase(app.getProperty("cookies.secure"))) { - c.setSecure(true); - } - } - - /** - * Reset all previously set cookies. - */ - public void resetCookies() { - if (cookies != null) { - cookies.clear(); - } - } - - /** - * Get the number of cookies set in this response. - * - * @return the number of cookies - */ - public int countCookies() { - if (cookies != null) { - return cookies.size(); - } - - return 0; - } - - /** - * Get the cookies set in this response. - * - * @return the cookies - */ - public CookieTrans[] getCookies() { - if (cookies == null) { - return new CookieTrans[0]; - } - - CookieTrans[] c = new CookieTrans[cookies.size()]; - cookies.values().toArray(c); - return c; - } - - /** - * Get the message to display to the user, if any. - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * Set a message to display to the user. - * @param message the message - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * Get the error message to display to the user, if any. - * @return the error message - */ - public Throwable getError() { - return error; - } - - /** - * Set a message to display to the user. - * @param error the error message - */ - public void setError(Throwable error) { - this.error = error; - } - - public String getErrorMessage() { - if (error == null) - return null; - return getErrorMessage(error); - } - - private static String getErrorMessage(Throwable t) { - String msg = t.getMessage(); - if (msg == null || msg.length() == 0) - msg = t.toString(); - if (msg == null || msg.length() == 0) - return "Unspecified Error: " + t.getClass().getName(); - return msg; - } - - /** - * Get debug messages to append to the response, if any. - * @return the response's debug buffer - */ - public StringBuffer getDebugBuffer() { - return debugBuffer; - } - - /** - * Set debug messages to append to the response. - * @param debugBuffer the response's debug buffer - */ - public void setDebugBuffer(StringBuffer debugBuffer) { - this.debugBuffer = debugBuffer; - } - - /** - * Get the charset/encoding for this response - * @return the charset name - */ - public String getCharset() { - return charset; - } - - /** - * Set the charset/encoding for this response - * @param charset the charset name - */ - public void setCharset(String charset) { - this.charset = charset; - } - - /** - * Returns true if this response may be cached by the client - * @return true if the response may be cached - */ - public boolean isCacheable() { - return cacheable; - } - - /** - * Set the cacheability of this response - * @param cache true if the response may be cached - */ - public void setCacheable(boolean cache) { - this.cacheable = cache; - } - - /** - * Get the HTTP response status code - * @return the HTTP response code - */ - public int getStatus() { - return status; - } - - /** - * Set the HTTP response status code - * @param status the HTTP response code - */ - public void setStatus(int status) { - this.status = status; - } - - /** - * Get the HTTP authentication realm - * @return the name of the authentication realm - */ - public String getRealm() { - return realm; - } - - /** - * Set the HTTP authentication realm - * @param realm the name of the authentication realm - */ - public void setRealm(String realm) { - this.realm = realm; - } -} diff --git a/src/main/java/helma/framework/TimeoutException.java b/src/main/java/helma/framework/TimeoutException.java deleted file mode 100644 index 6e1f53ab..00000000 --- a/src/main/java/helma/framework/TimeoutException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - - -/** - * TimeoutException is thrown by the request evaluator when a request could - * not be serviced within the timeout period specified for an application. - */ -public class TimeoutException extends RuntimeException { - private static final long serialVersionUID = 3853135482278393735L; - - /** - * Creates a new TimeoutException object. - */ - public TimeoutException() { - super("Request timed out"); - } -} diff --git a/src/main/java/helma/framework/UploadStatus.java b/src/main/java/helma/framework/UploadStatus.java deleted file mode 100644 index 31d0a02c..00000000 --- a/src/main/java/helma/framework/UploadStatus.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 2007 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework; - -import java.io.Serializable; - -public class UploadStatus implements Serializable { - - private static final long serialVersionUID = 8335579045959177198L; - - long current = 0; - long total = 0; - int itemsRead = 0; - String error = null; - long lastModified; - - public UploadStatus() { - lastModified = System.currentTimeMillis(); - } - - public void update(long bytesRead, long contentLength, int itemsRead) { - this.current = bytesRead; - this.total = contentLength; - this.itemsRead = itemsRead; - lastModified = System.currentTimeMillis(); - } - - public void setError(String error) { - this.error = error; - lastModified = System.currentTimeMillis(); - } - - public String getError() { - return error; - } - - public long getCurrent() { - return current; - } - - public long getTotal() { - return total; - } - - public int getItemsRead() { - return itemsRead; - } - - public boolean isDisposable() { - // Make upload status disposable if it hasn't been modified for the last - // 10 minutes, regardless of whether the upload has finished or not - return System.currentTimeMillis() - lastModified > 60000; - } - - public String toString() { - StringBuffer buffer = new StringBuffer("{current: ").append(current) - .append(", total: ").append(total) - .append(", itemsRead: ").append(itemsRead) - .append(", error: "); - if (error == null) { - buffer.append("null"); - } else { - buffer.append("\""); - buffer.append(error.replaceAll("\"", "\\\\\"")); - buffer.append("\""); - } - return buffer.append("}").toString(); - } - -} diff --git a/src/main/java/helma/framework/core/AppClassLoader.java b/src/main/java/helma/framework/core/AppClassLoader.java deleted file mode 100644 index 1a2f28a6..00000000 --- a/src/main/java/helma/framework/core/AppClassLoader.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.core; - -import java.net.URL; -import java.net.URLClassLoader; - -/** - * ClassLoader subclass with package accessible addURL method. - */ -public class AppClassLoader extends URLClassLoader { - private final String appname; - - /** - * Create a HelmaClassLoader with the given application name and the given URLs - */ - public AppClassLoader(String appname, URL[] urls) { - super(urls, AppClassLoader.class.getClassLoader()); - this.appname = appname; - } - - protected void addURL(URL url) { - super.addURL(url); - } - - /** - * - * - * @return ... - */ - public String getAppName() { - return appname; - } - - public String toString() { - return "helma.framework.core.AppClassLoader[" + appname + "]"; - } -} diff --git a/src/main/java/helma/framework/core/Application.java b/src/main/java/helma/framework/core/Application.java deleted file mode 100644 index be41d21a..00000000 --- a/src/main/java/helma/framework/core/Application.java +++ /dev/null @@ -1,2202 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.core; - -import helma.extensions.ConfigurationException; -import helma.extensions.HelmaExtension; -import helma.framework.*; -import helma.framework.repository.*; -import helma.main.Server; -import helma.objectmodel.*; -import helma.objectmodel.db.*; -import helma.util.*; -import helma.scripting.ScriptingEngine; -import helma.scripting.ScriptingException; - -import java.io.*; -import java.lang.reflect.*; -import java.rmi.*; -import java.util.*; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import java.util.ArrayList; - - -/** - * The central class of a Helma application. This class keeps a pool of - * request evaluators (threads with JavaScript interpreters), waits for - * requests from the Web server or XML-RPC port and dispatches them to - * the evaluators. - */ -public final class Application implements Runnable { - // the name of this application - private String name; - - // application sources - ArrayList repositories; - - // properties and db-properties - ResourceProperties props; - - // properties and db-properties - ResourceProperties dbProps; - - // This application's main directory - File appDir; - - // Helma server hopHome directory - File hopHome; - - // embedded db directory - File dbDir; - - // false if hopobjects are case sensitive (default) - public boolean caseInsensitive; - - // this application's node manager - protected NodeManager nmgr; - - // the root of the website, if a custom root object is defined. - // otherwise this is managed by the NodeManager and not cached here. - Object rootObject = null; - String rootObjectClass; - // if defined this will cause us to get the root object straight - // from the scripting engine, circumventing all hopobject db fluff - String rootObjectPropertyName; - String rootObjectFunctionName; - - // The session manager - SessionManager sessionMgr; - - /** - * The type manager checks if anything in the application's prototype definitions - * has been updated prior to each evaluation. - */ - public TypeManager typemgr; - - /** - * The skin manager for this application - */ - protected SkinManager skinmgr; - - /** - * Collections for evaluator thread pooling - */ - protected Stack freeThreads; - protected Vector allThreads; - boolean running = false; - boolean debug; - long starttime; - Hashtable dbSources; - - // map of app modules reflected at app.modules - Map modules; - - // internal worker thread for scheduler, session cleanup etc. - Thread worker; - // request timeout defaults to 60 seconds - long requestTimeout = 60000; - ThreadGroup threadgroup; - - // threadlocal variable for the current RequestEvaluator - ThreadLocal currentEvaluator = new ThreadLocal(); - - // Map of requesttrans -> active requestevaluators - Hashtable activeRequests; - - String logDir; - - // Two logs for each application - Log eventLog; - Log accessLog; - - // Symbolic names for each log - String eventLogName; - String accessLogName; - - // A transient node that is shared among all evaluators - protected INode cachenode; - - // some fields for statistics - protected volatile long requestCount = 0; - protected volatile long xmlrpcCount = 0; - protected volatile long errorCount = 0; - - // the URL-prefix to use for links into this application - private String baseURI; - // the name of the root prototype as far as href() is concerned - private String hrefRootPrototype; - - // the id of the object to use as root object - String rootId = "0"; - - // Db mappings for some standard prototypes - private DbMapping rootMapping; - private DbMapping userRootMapping; - private DbMapping userMapping; - - // name of response encoding - String charset; - - // password file to use for authenticate() function - private CryptResource pwfile; - - // Map of java class names to object prototypes - ResourceProperties classMapping; - - // Map of extensions allowed for public skins - Properties skinExtensions; - - // time we last read the properties file - private long lastPropertyRead = -1L; - - // the set of prototype/function pairs which are allowed to be called via XML-RPC - private HashSet xmlrpcAccess; - - // the name under which this app serves XML-RPC requests. Defaults to the app name - private String xmlrpcHandlerName; - - // the list of currently active cron jobs - Hashtable activeCronJobs = null; - // the list of custom cron jobs - Hashtable customCronJobs = null; - - private ResourceComparator resourceComparator; - private Resource currentCodeResource; - - // Field to cache unmapped java classes - private final static String CLASS_NOT_MAPPED = "(unmapped)"; - - /** - * Namespace search path for global macros - */ - String[] globalMacroPath = null; - - /** - * Simple constructor for dead application instances. - */ - public Application(String name) { - this.name = name; - } - - /** - * Build an application with the given name with the given sources. No - * Server-wide properties are created or used. - */ - public Application(String name, Repository[] repositories, File dbDir) - throws RemoteException, IllegalArgumentException { - this(name, null, repositories, null, dbDir); - } - - /** - * Build an application with the given name and server instance. The - * app directories will be created if they don't exist already. - */ - public Application(String name, Server server) - throws RemoteException, IllegalArgumentException { - this(name, server, new Repository[0], null, null); - } - - /** - * Build an application with the given name, server instance, sources and - * db directory. - */ - public Application(String name, Server server, Repository[] repositories, - File customAppDir, File customDbDir) - throws RemoteException, IllegalArgumentException { - if ((name == null) || (name.trim().length() == 0)) { - throw new IllegalArgumentException("Invalid application name: " + name); - } - - if (repositories.length == 0) { - throw new java.lang.IllegalArgumentException("No sources defined for application: " + name); - } - - this.name = name; - - this.caseInsensitive = "true".equalsIgnoreCase(server.getAppsProperties(name).getProperty("caseInsensitive")); - - this.repositories = new ArrayList(); - this.repositories.addAll(Arrays.asList(repositories)); - resourceComparator = new ResourceComparator(this); - - appDir = customAppDir; - dbDir = customDbDir; - - // system-wide properties, default to null - ResourceProperties sysProps; - - // system-wide properties, default to null - ResourceProperties sysDbProps; - - sysProps = sysDbProps = null; - hopHome = null; - - if (server != null) { - hopHome = server.getHopHome(); - - if (dbDir == null) { - dbDir = new File(server.getDbHome(), name); - } - - // get system-wide properties - sysProps = server.getProperties(); - sysDbProps = server.getDbProperties(); - } - - if (!dbDir.exists()) { - dbDir.mkdirs(); - } - - if (appDir == null) { - for (int i=repositories.length-1; i>=0; i--) { - if (repositories[i] instanceof FileRepository) { - appDir = new File(repositories[i].getName()); - break; - } - } - } - - // give the Helma Thread group a name so the threads can be recognized - threadgroup = new ThreadGroup("TX-" + name); - - // create app-level properties - props = new ResourceProperties(this, "app.properties", sysProps); - - // get log names - accessLogName = props.getProperty("accessLog", - new StringBuffer("helma.").append(name).append(".access").toString()); - eventLogName = props.getProperty("eventLog", - new StringBuffer("helma.").append(name).append(".event").toString()); - - // create app-level db sources - dbProps = new ResourceProperties(this, "db.properties", sysDbProps, false); - - // the passwd file, to be used with the authenticate() function - CryptResource parentpwfile = null; - - if (hopHome != null) { - parentpwfile = new CryptResource(new FileResource(new File(hopHome, "passwd")), null); - } - - pwfile = new CryptResource(repositories[0].getResource("passwd"), parentpwfile); - - // the properties that map java class names to prototype names - classMapping = new ResourceProperties(this, "class.properties"); - classMapping.setIgnoreCase(false); - - // get class name of root object if defined. Otherwise native Helma objectmodel will be used. - rootObjectClass = classMapping.getProperty("root"); - - updateProperties(); - - dbSources = new Hashtable(); - modules = new SystemMap(); - } - - /** - * Get the application ready to run, initializing the evaluators and type manager. - */ - public void init() - throws DatabaseException, IllegalAccessException, InstantiationException, - ClassNotFoundException, InterruptedException { - init(null); - } - - /** - * Get the application ready to run, initializing the evaluators and type manager. - * - * @param ignoreDirs comma separated list of directory names to ignore - */ - public void init(final String ignoreDirs) - throws DatabaseException, IllegalAccessException, InstantiationException, - ClassNotFoundException, InterruptedException { - - Initializer i = new Initializer(ignoreDirs); - i.start(); - i.join(); - if (i.exception != null) { - if (i.exception instanceof DatabaseException) - throw (DatabaseException) i.exception; - if (i.exception instanceof IllegalAccessException) - throw (IllegalAccessException) i.exception; - if (i.exception instanceof InstantiationException) - throw (InstantiationException) i.exception; - if (i.exception instanceof ClassNotFoundException) - throw (ClassNotFoundException) i.exception; - throw new RuntimeException(i.exception); - } - } - - // We need to call initialize in a fresh thread because the calling thread could - // already be associated with a rhino context, for example when starting from the - // manage application. - class Initializer extends Thread { - Exception exception = null; - String ignoreDirs; - - Initializer(String dirs) { - super(name + "-init"); - ignoreDirs = dirs; - } - - public void run() { - try { - synchronized (Application.this) { - initInternal(); - } - } catch (Exception x) { - exception = x; - } - } - - private void initInternal() - throws DatabaseException, IllegalAccessException, - InstantiationException, ClassNotFoundException { - running = true; - // create and init type mananger - typemgr = new TypeManager(Application.this, ignoreDirs); - // set the context classloader. Note that this must be done before - // using the logging framework so that a new LogFactory gets created - // for this app. - Thread.currentThread().setContextClassLoader(typemgr.getClassLoader()); - try { - typemgr.createPrototypes(); - } catch (Exception x) { - logError("Error creating prototypes", x); - } - - if (Server.getServer() != null) { - Vector extensions = Server.getServer().getExtensions(); - - for (int i = 0; i < extensions.size(); i++) { - HelmaExtension ext = (HelmaExtension) extensions.get(i); - - try { - ext.applicationStarted(Application.this); - } catch (ConfigurationException e) { - logEvent("couldn't init extension " + ext.getName() + ": " + - e.toString()); - } - } - } - - // create and init evaluator/thread lists - freeThreads = new Stack(); - allThreads = new Vector(); - - activeRequests = new Hashtable(); - activeCronJobs = new Hashtable(); - customCronJobs = new Hashtable(); - - // create the skin manager - skinmgr = new SkinManager(Application.this); - - // read in root id, root prototype, user prototype - rootId = props.getProperty("rootid", "0"); - String rootPrototype = props.getProperty("rootprototype", "root"); - String userPrototype = props.getProperty("userprototype", "user"); - - rootMapping = getDbMapping(rootPrototype); - if (rootMapping == null) - throw new RuntimeException("rootPrototype does not exist: " + rootPrototype); - userMapping = getDbMapping(userPrototype); - if (userMapping == null) - throw new RuntimeException("userPrototype does not exist: " + userPrototype); - - // The whole user/userroot handling is basically old - // ugly obsolete crap. Don't bother. - ResourceProperties p = new ResourceProperties(); - String usernameField = (userMapping != null) ? userMapping.getNameField() : null; - - if (usernameField == null) { - usernameField = "name"; - } - - p.put("_children", "collection(" + userPrototype + ")"); - p.put("_children.accessname", usernameField); - userRootMapping = new DbMapping(Application.this, "__userroot__", p); - userRootMapping.update(); - - // create the node manager - nmgr = new NodeManager(Application.this); - nmgr.init(dbDir.getAbsoluteFile(), props); - - // create the app cache node exposed as app.data - cachenode = new TransientNode(Application.this, "app"); - - // create and init session manager - String sessionMgrImpl = props.getProperty("sessionManagerImpl", - "helma.framework.core.SessionManager"); - sessionMgr = (SessionManager) Class.forName(sessionMgrImpl).newInstance(); - logEvent("Using session manager class " + sessionMgrImpl); - sessionMgr.init(Application.this); - - // read the sessions if wanted - if ("true".equalsIgnoreCase(getProperty("persistentSessions"))) { - RequestEvaluator ev = getEvaluator(); - try { - ev.initScriptingEngine(); - sessionMgr.loadSessionData(null, ev.scriptingEngine); - } finally { - releaseEvaluator(ev); - } - } - - // preallocate minThreads request evaluators - int minThreads = 0; - - try { - minThreads = Integer.parseInt(props.getProperty("minThreads")); - } catch (Exception ignore) { - // not parsable as number, keep 0 - } - - if (minThreads > 0) { - logEvent("Starting "+minThreads+" evaluator(s) for " + name); - } - - for (int i = 0; i < minThreads; i++) { - RequestEvaluator ev = new RequestEvaluator(Application.this); - - if (i == 0) { - ev.initScriptingEngine(); - } - freeThreads.push(ev); - allThreads.addElement(ev); - } - } - } - - - /** - * Create and start scheduler and cleanup thread - */ - public synchronized void start() { - starttime = System.currentTimeMillis(); - - // as first thing, invoke global onStart() function - RequestEvaluator eval = null; - try { - eval = getEvaluator(); - eval.invokeInternal(null, "onStart", RequestEvaluator.EMPTY_ARGS); - } catch (Exception xcept) { - logError("Error in " + name + ".onStart()", xcept); - } finally { - releaseEvaluator(eval); - } - - worker = new Thread(this, name + "-worker"); - worker.setPriority(Thread.NORM_PRIORITY + 1); - worker.start(); - } - - /** - * This is called to shut down a running application. - */ - public synchronized void stop() { - // invoke global onStop() function - RequestEvaluator eval = null; - try { - eval = getEvaluator(); - eval.invokeInternal(null, "onStop", RequestEvaluator.EMPTY_ARGS); - } catch (Exception x) { - logError("Error in " + name + ".onStop()", x); - } - - // mark app as stopped - running = false; - - // stop all threads, this app is going down - if (worker != null) { - worker.interrupt(); - } - - worker = null; - - // stop evaluators - if (allThreads != null) { - for (Enumeration e = allThreads.elements(); e.hasMoreElements();) { - RequestEvaluator ev = (RequestEvaluator) e.nextElement(); - ev.stopTransactor(); - ev.shutdown(); - } - } - - // remove evaluators - allThreads.removeAllElements(); - freeThreads.clear(); - - // shut down node manager and embedded db - try { - nmgr.shutdown(); - } catch (DatabaseException dbx) { - System.err.println("Error shutting down embedded db: " + dbx); - } - - // tell the extensions that we're stopped. - if (Server.getServer() != null) { - Vector extensions = Server.getServer().getExtensions(); - - for (int i = 0; i < extensions.size(); i++) { - HelmaExtension ext = (HelmaExtension) extensions.get(i); - - ext.applicationStopped(this); - } - } - - // store the sessions if wanted - if ("true".equalsIgnoreCase(getProperty("persistentSessions"))) { - // sessionMgr.storeSessionData(null); - sessionMgr.storeSessionData(null, eval.scriptingEngine); - } - sessionMgr.shutdown(); - } - - /** - * Returns true if this app is currently running - * - * @return true if the app is running - */ - public boolean isRunning() { - return running; - } - - /** - * Get the application directory. - * - * @return the application directory, or first file based repository - */ - public File getAppDir() { - return appDir; - } - - /** - * Get a comparator for comparing Resources according to the order of - * repositories they're contained in. - * - * @return a comparator that sorts resources according to their repositories - */ - public ResourceComparator getResourceComparator() { - return resourceComparator; - } - - /** - * Returns a free evaluator to handle a request. - */ - public RequestEvaluator getEvaluator() { - if (!running) { - throw new ApplicationStoppedException(); - } - - // first try - try { - return (RequestEvaluator) freeThreads.pop(); - } catch (EmptyStackException nothreads) { - int maxThreads = 50; - - String maxThreadsProp = props.getProperty("maxThreads"); - if (maxThreadsProp != null) { - try { - maxThreads = Integer.parseInt(maxThreadsProp); - } catch (Exception ignore) { - logEvent("Couldn't parse maxThreads property: " + maxThreadsProp); - } - } - - synchronized (this) { - // allocate a new evaluator - if (allThreads.size() < maxThreads) { - logEvent("Starting engine " + (allThreads.size() + 1) + - " for " + name); - - RequestEvaluator ev = new RequestEvaluator(this); - - allThreads.addElement(ev); - - return (ev); - } - } - } - - // we can't create a new evaluator, so we wait if one becomes available. - // give it 3 more tries, waiting 3 seconds each time. - for (int i = 0; i < 4; i++) { - try { - Thread.sleep(3000); - - return (RequestEvaluator) freeThreads.pop(); - } catch (EmptyStackException nothreads) { - // do nothing - } catch (InterruptedException inter) { - throw new RuntimeException("Thread interrupted."); - } - } - - // no luck, give up. - throw new RuntimeException("Maximum Thread count reached."); - } - - /** - * Returns an evaluator back to the pool when the work is done. - */ - public void releaseEvaluator(RequestEvaluator ev) { - if (ev != null) { - ev.recycle(); - freeThreads.push(ev); - } - } - - /** - * This can be used to set the maximum number of evaluators which will be allocated. - * If evaluators are required beyound this number, an error will be thrown. - */ - public boolean setNumberOfEvaluators(int n) { - if ((n < 2) || (n > 511)) { - return false; - } - - int current = allThreads.size(); - - synchronized (allThreads) { - if (n > current) { - int toBeCreated = n - current; - - for (int i = 0; i < toBeCreated; i++) { - RequestEvaluator ev = new RequestEvaluator(this); - - freeThreads.push(ev); - allThreads.addElement(ev); - } - } else if (n < current) { - int toBeDestroyed = current - n; - - for (int i = 0; i < toBeDestroyed; i++) { - try { - RequestEvaluator re = (RequestEvaluator) freeThreads.pop(); - allThreads.removeElement(re); - re.stopTransactor(); - } catch (EmptyStackException empty) { - return false; - } - } - } - } - - return true; - } - - /** - * Return the number of currently active threads - */ - public int getActiveThreads() { - return 0; - } - - /** - * Execute a request coming in from a web client. - */ - public ResponseTrans execute(RequestTrans req) { - requestCount += 1; - - // get user for this request's session - Session session = createSession(req.getSession()); - session.touch(); - - ResponseTrans res = null; - RequestEvaluator ev = null; - - // are we responsible for releasing the evaluator and closing the result? - boolean primaryRequest = false; - - try { - // first look if a request with same user/path/data is already being executed. - // if so, attach the request to its output instead of starting a new evaluation - // this helps to cleanly solve "doubleclick" kind of users - ev = (RequestEvaluator) activeRequests.get(req); - - if (ev != null) { - res = ev.attachHttpRequest(req); - if (res != null) { - // we can only use the existing response object if the response - // wasn't written to the HttpServletResponse directly. - res.waitForClose(); - if (res.getContent() == null) { - res = null; - } - } - } - - if (res == null) { - primaryRequest = true; - - // if attachHttpRequest returns null this means we came too late - // and the other request was finished in the meantime - // check if the properties file has been updated - updateProperties(); - - // get evaluator and invoke - ev = getEvaluator(); - res = ev.invokeHttp(req, session); - } - } catch (ApplicationStoppedException stopped) { - // let the servlet know that this application has gone to heaven - throw stopped; - } catch (Exception x) { - errorCount += 1; - res = new ResponseTrans(this, req); - res.reportError(x); - } finally { - if (primaryRequest) { - activeRequests.remove(req); - releaseEvaluator(ev); - - // response needs to be closed/encoded before sending it back - try { - res.close(charset); - } catch (UnsupportedEncodingException uee) { - logError("Unsupported response encoding", uee); - } - } - } - - return res; - } - - /** - * Called to execute a method via XML-RPC, usally by helma.main.ApplicationManager - * which acts as default handler/request dispatcher. - */ - public Object executeXmlRpc(String method, Vector args) - throws Exception { - xmlrpcCount += 1; - - Object retval = null; - RequestEvaluator ev = null; - - try { - // check if the properties file has been updated - updateProperties(); - - // get evaluator and invoke - ev = getEvaluator(); - retval = ev.invokeXmlRpc(method, args.toArray()); - } finally { - releaseEvaluator(ev); - } - - return retval; - } - - - public Object executeExternal(String method, Vector args) - throws Exception { - Object retval = null; - RequestEvaluator ev = null; - try { - // check if the properties file has been updated - updateProperties(); - // get evaluator and invoke - ev = getEvaluator(); - retval = ev.invokeExternal(method, args.toArray()); - } finally { - releaseEvaluator(ev); - } - return retval; - } - - /** - * Reset the application's object cache, causing all objects to be refetched from - * the database. - */ - public void clearCache() { - nmgr.clearCache(); - } - - /** - * Returns the number of elements in the NodeManager's cache - */ - public int getCacheUsage() { - return nmgr.countCacheEntries(); - } - - /** - * Returns a map of cache statistics - */ - public Map getCacheStatistics() { - return nmgr.getCacheStatistics(); - } - - /** - * Set the application's root element to an arbitrary object. After this is called - * with a non-null object, the helma node manager will be bypassed. This function - * can be used to script and publish any Java object structure with Helma. - */ - public void setDataRoot(Object root) { - this.rootObject = root; - } - - /** - * This method returns the root object of this application's object tree. - */ - public Object getDataRoot() throws Exception { - return getDataRoot(null); - } - - /** - * This method returns the root object of this application's object tree. - */ - protected Object getDataRoot(ScriptingEngine engine) throws Exception { - if (rootObject != null) { - return rootObject; - } - // check if we have a custom root object class - if (rootObjectClass != null) { - // create custom root element. - try { - if (classMapping.containsKey("root.factory.class") && - classMapping.containsKey("root.factory.method")) { - String rootFactory = classMapping.getProperty("root.factory.class"); - Class c = typemgr.getClassLoader().loadClass(rootFactory); - Method m = c.getMethod( - classMapping.getProperty("root.factory.method"), - (Class[]) null); - rootObject = m.invoke(c, (Object[]) null); - } else { - String rootClass = classMapping.getProperty("root"); - Class c = typemgr.getClassLoader().loadClass(rootClass); - rootObject = c.newInstance(); - } - } catch (Exception e) { - throw new RuntimeException("Error creating root object: " + - e.toString()); - } - return rootObject; - } else if (rootObjectPropertyName != null || rootObjectFunctionName != null) { - // get root object from a global scripting engine property or function - if (engine == null) { - RequestEvaluator reval = getEvaluator(); - try { - return getDataRootFromEngine(reval.getScriptingEngine()); - } finally { - releaseEvaluator(reval); - } - } else { - return getDataRootFromEngine(engine); - } - } else { - // no custom root object is defined - use standard helma objectmodel - return nmgr.getRootNode(); - } - } - - private Object getDataRootFromEngine(ScriptingEngine engine) - throws ScriptingException { - return rootObjectPropertyName != null ? - engine.getGlobalProperty(rootObjectPropertyName) : - engine.invoke(null, rootObjectFunctionName, - RequestEvaluator.EMPTY_ARGS, - ScriptingEngine.ARGS_WRAP_DEFAULT, true); - } - - /** - * Return the prototype of the object to be used as this application's root object - */ - public DbMapping getRootMapping() { - return rootMapping; - } - - /** - * Return the id of the object to be used as this application's root object - */ - public String getRootId() { - return rootId; - } - - /** - * Returns the Object which contains registered users of this application. - */ - public INode getUserRoot() { - INode users = nmgr.safe.getNode("1", userRootMapping); - - users.setDbMapping(userRootMapping); - - return users; - } - - /** - * Returns the node manager for this application. The node manager is - * the gateway to the helma.objectmodel packages, which perform the mapping - * of objects to relational database tables or the embedded database. - */ - public NodeManager getNodeManager() { - return nmgr; - } - - /** - * Returns a wrapper containing the node manager for this application. The node manager is - * the gateway to the helma.objectmodel packages, which perform the mapping of objects to - * relational database tables or the embedded database. - */ - public WrappedNodeManager getWrappedNodeManager() { - return nmgr.safe; - } - - /** - * Return the application's session manager - * @return the SessionManager instance used by this app - */ - public SessionManager getSessionManager() { - return sessionMgr; - } - - /** - * Return a transient node that is shared by all evaluators of this application ("app node") - */ - public INode getCacheNode() { - return cachenode; - } - - /** - * Returns a Node representing a registered user of this application by his or her user name. - */ - public INode getUserNode(String uid) { - try { - INode users = getUserRoot(); - - return (INode) users.getChildElement(uid); - } catch (Exception x) { - return null; - } - } - - /** - * Return a prototype for a given node. If the node doesn't specify a prototype, - * return the generic hopobject prototype. - */ - public Prototype getPrototype(Object obj) { - String protoname = getPrototypeName(obj); - - if (protoname == null) { - return typemgr.getPrototype("hopobject"); - } - - Prototype p = typemgr.getPrototype(protoname); - - if (p == null) { - p = typemgr.getPrototype("hopobject"); - } - - return p; - } - - /** - * Return the prototype with the given name, if it exists - */ - public Prototype getPrototypeByName(String name) { - return typemgr.getPrototype(name); - } - - /** - * Return a collection containing all prototypes defined for this application - */ - public Collection getPrototypes() { - return typemgr.getPrototypes(); - } - - /** - * Programmatically define a new prototype. If a prototype with this name already exists return - * the existing prototype. - * @param name the prototype name - * @param typeProps custom type properties map - * @return the new prototype - */ - public Prototype definePrototype(String name, Map typeProps) { - Prototype proto = typemgr.getPrototype(name); - if (proto == null) { - proto = typemgr.createPrototype(name, null, typeProps); - } else { - proto.setTypeProperties(typeProps); - } - return proto; - } - - /** - * Return a skin for a given object. The skin is found by determining the prototype - * to use for the object, then looking up the skin for the prototype. - */ - public Skin getSkin(String protoname, String skinname, Object[] skinpath) throws IOException { - Prototype proto = getPrototypeByName(protoname); - - if (proto == null) { - return null; - } - - return skinmgr.getSkin(proto, skinname, skinpath); - } - - /** - * Return the session currently associated with a given Hop session ID. - * Create a new session if necessary. - */ - public Session createSession(String sessionId) { - return sessionMgr.createSession(sessionId); - } - - /** - * Return a list of Helma nodes (HopObjects - the database object representing the user, - * not the session object) representing currently logged in users. - */ - public List getActiveUsers() { - return sessionMgr.getActiveUsers(); - } - - /** - * Return a list of Helma nodes (HopObjects - the database object representing the user, - * not the session object) representing registered users of this application. - */ - public List getRegisteredUsers() { - ArrayList list = new ArrayList(); - INode users = getUserRoot(); - - // add all child nodes to the list - for (Enumeration e = users.getSubnodes(); e.hasMoreElements();) { - list.add(e.nextElement()); - } - - // if none, try to get them from properties (internal db) - if (list.size() == 0) { - for (Enumeration e = users.properties(); e.hasMoreElements();) { - list.add(users.getNode((String) e.nextElement())); - } - } - - return list; - } - - /** - * Return an array of SessionBean objects currently associated - * with a given Helma user. - */ - public List getSessionsForUsername(String username) { - return sessionMgr.getSessionsForUsername(username); - } - - /** - * Return the session currently associated with a given Hop session ID. - */ - public Session getSession(String sessionId) { - return sessionMgr.getSession(sessionId); - } - - /** - * Return the whole session map. - */ - public Map getSessions() { - return sessionMgr.getSessions(); - } - - /** - * Returns the number of currenty active sessions. - */ - public int countSessions() { - return sessionMgr.countSessions(); - } - - /** - * Register a user with the given user name and password. - */ - public INode registerUser(String uname, String password) { - if (uname == null) { - return null; - } - - uname = uname.toLowerCase().trim(); - - if ("".equals(uname)) { - return null; - } - - INode unode; - - try { - INode users = getUserRoot(); - - // check if a user with this name is already registered - unode = (INode) users.getChildElement(uname); - if (unode != null) { - return null; - } - - unode = new Node(uname, "user", nmgr.safe); - - String usernameField = (userMapping != null) ? userMapping.getNameField() : null; - String usernameProp = null; - - if (usernameField != null) { - usernameProp = userMapping.columnNameToProperty(usernameField); - } - - if (usernameProp == null) { - usernameProp = "name"; - } - - unode.setName(uname); - unode.setString(usernameProp, uname); - unode.setString("password", password); - - return users.addNode(unode); - - } catch (Exception x) { - logEvent("Error registering User: " + x); - - return null; - } - } - - /** - * Log in a user given his or her user name and password. - */ - public boolean loginSession(String uname, String password, Session session) { - // Check the name/password of a user and log it in to the current session - if (uname == null) { - return false; - } - - uname = uname.toLowerCase().trim(); - - if ("".equals(uname)) { - return false; - } - - try { - INode users = getUserRoot(); - Node unode = (Node) users.getChildElement(uname); - if (unode == null) - return false; - - String pw = unode.getString("password"); - - if ((pw != null) && pw.equals(password)) { - // let the old user-object forget about this session - session.logout(); - session.login(unode); - - return true; - } - } catch (Exception x) { - return false; - } - - return false; - } - - /** - * Log out a session from this application. - */ - public void logoutSession(Session session) { - session.logout(); - } - - /** - * In contrast to login, this works outside the Hop user object framework. Instead, the user is - * authenticated against a passwd file in the application directory. This is to have some sort of - * authentication available *before* the application is up and running, i.e. for application setup tasks. - */ - public boolean authenticate(String uname, String password) { - if ((uname == null) || (password == null)) { - return false; - } - - return pwfile.authenticate(uname, password); - } - - /** - * Return the href to the root of this application. - * @return the root element's URL - * @throws UnsupportedEncodingException if the application's charset property - * is not a valid encoding name - */ - public String getRootHref() throws UnsupportedEncodingException { - return getNodeHref(null, null, null); - } - - /** - * Return a path to be used in a URL pointing to the given element and action - * @param elem the object to get the URL for - * @param actionName an optional action name - * @param queryParams optional map of query parameters - * @return the element's URL - * @throws UnsupportedEncodingException if the application's charset property - * is not a valid encoding name - */ - public String getNodeHref(Object elem, String actionName, Map queryParams) - throws UnsupportedEncodingException { - StringBuffer buffer = new StringBuffer(baseURI); - - composeHref(elem, buffer, 0); - - if (actionName != null) { - buffer.append(UrlEncoded.encode(actionName, charset)); - } - if (queryParams != null) { - appendQueryParams(buffer, queryParams, null, 0); - } - - return buffer.toString(); - } - - private int appendQueryParams(StringBuffer buffer, Map params, - String prefix, int count) - throws UnsupportedEncodingException { - for (Iterator it = params.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); - Object value = entry.getValue(); - if (value == null) { - continue; - } - String key = UrlEncoded.encode(entry.getKey().toString(), charset); - if (prefix != null) key = prefix + '[' + key + ']'; - if (value instanceof Map) { - count = appendQueryParams(buffer, (Map) value, key, count); - } else { - buffer.append(count++ == 0 ? '?' : '&'); - buffer.append(key); - buffer.append('='); - buffer.append(UrlEncoded.encode(value.toString(), charset)); - } - } - return count; - } - - private void composeHref(Object elem, StringBuffer b, int pathCount) - throws UnsupportedEncodingException { - if ((elem == null) || (pathCount > 50)) { - return; - } - - if ((hrefRootPrototype != null) && - hrefRootPrototype.equals(getPrototypeName(elem))) { - return; - } - - Object parent = getParentElement(elem); - - if (parent == null) { - return; - } - - // recurse to parent element - composeHref(getParentElement(elem), b, ++pathCount); - - // append ourselves - String ename = getElementName(elem); - if (ename != null) { - b.append(UrlEncoded.encode(ename, charset)); - b.append("/"); - } - } - - /** - * Returns the baseURI for Hrefs in this application. - */ - public String getBaseURI() { - return baseURI; - } - - - /** - * This method sets the base URL of this application which will be prepended to - * the actual object path. - */ - public void setBaseURI(String uri) { - if (uri == null) { - this.baseURI = "/"; - } else if (!uri.endsWith("/")) { - this.baseURI = uri + "/"; - } else { - this.baseURI = uri; - } - } - - /** - * Return true if the baseURI property is defined in the application - * properties, false otherwise. - */ - public boolean hasExplicitBaseURI() { - return props.containsKey("baseuri"); - } - - /** - * Returns the prototype name that Hrefs in this application should - * start with. - */ - public String getHrefRootPrototype() { - return hrefRootPrototype; - } - - /** - * Tell other classes whether they should output logging information for - * this application. - */ - public boolean debug() { - return debug; - } - - /** - * Get the current RequestEvaluator, or null if the calling thread - * is not evaluating a request. - * - * @return the RequestEvaluator belonging to the current thread - */ - public RequestEvaluator getCurrentRequestEvaluator() { - return (RequestEvaluator) currentEvaluator.get(); - } - - /** - * Set the current RequestEvaluator for the calling thread. - * @param eval the RequestEvaluator belonging to the current thread - */ - protected void setCurrentRequestEvaluator(RequestEvaluator eval) { - currentEvaluator.set(eval); - } - - /** - * Utility function invoker for the methods below. This *must* be called - * by an active RequestEvaluator thread. - */ - private Object invokeFunction(Object obj, String func, Object[] args) { - RequestEvaluator reval = getCurrentRequestEvaluator(); - if (reval != null) { - if (args == null) { - args = RequestEvaluator.EMPTY_ARGS; - } - try { - return reval.invokeDirectFunction(obj, func, args); - } catch (Exception x) { - if (debug) { - System.err.println("Error in Application.invokeFunction (" + - func + "): " + x); - } - } - } - return null; - } - - /** - * Returns the correct property name which is either case sensitive or case insensitive - * @param propName the raw property name - * @return the correct property name - */ - public String correctPropertyName(String propName) { - if (propName == null) - return null; - if (caseInsensitive) - return propName.toLowerCase(); - return propName; - } - - /** - * Return the application's classloader - */ - public ClassLoader getClassLoader() { - return typemgr.getClassLoader(); - } - - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - /// The following methods mimic the IPathElement interface. This allows us - /// to script any Java object: If the object implements IPathElement (as does - /// the Node class in Helma's internal objectmodel) then the corresponding - /// method is called in the object itself. Otherwise, a corresponding script function - /// is called on the object. - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - - /** - * Return the name to be used to get this element from its parent - */ - public String getElementName(Object obj) { - if (obj instanceof IPathElement) { - return ((IPathElement) obj).getElementName(); - } - - Object retval = invokeFunction(obj, "getElementName", RequestEvaluator.EMPTY_ARGS); - - if (retval != null) { - return retval.toString(); - } - - return null; - } - - /** - * Retrieve a child element of this object by name. - */ - public Object getChildElement(Object obj, String name) { - if (obj instanceof IPathElement) { - return ((IPathElement) obj).getChildElement(name); - } - - Object[] arg = new Object[] { name }; - return invokeFunction(obj, "getChildElement", arg); - } - - /** - * Return the parent element of this object. - */ - public Object getParentElement(Object obj) { - if (obj instanceof IPathElement) { - return ((IPathElement) obj).getParentElement(); - } - - return invokeFunction(obj, "getParentElement", RequestEvaluator.EMPTY_ARGS); - } - - /** - * Get the name of the prototype to be used for this object. This will - * determine which scripts, actions and skins can be called on it - * within the Helma scripting and rendering framework. - */ - public String getPrototypeName(Object obj) { - if (obj == null) { - return "global"; - } else if (obj instanceof IPathElement) { - // check if e implements the IPathElement interface - return ((IPathElement) obj).getPrototype(); - } - - // How class name to prototype name lookup works: - // If an object is not found by its direct class name, a cache entry is added - // for the class name. For negative result, the string "(unmapped)" is used - // as cache value. - // - // Caching is done directly in classProperties, as ResourceProperties have - // the nice effect of being purged when the underlying resource is updated, - // so cache invalidation happens implicitely. - - Class clazz = obj.getClass(); - String className = clazz.getName(); - String protoName = classMapping.getProperty(className); - // fast path: direct hit, either positive or negative - if (protoName != null) { - return protoName == CLASS_NOT_MAPPED ? null : protoName; - } - - // walk down superclass path. We already checked the actual class, - // and we know that java.lang.Object does not implement any interfaces, - // and the code is streamlined a bit to take advantage of this. - while (clazz != Object.class) { - // check interfaces - Class[] classes = clazz.getInterfaces(); - for (int i = 0; i < classes.length; i++) { - protoName = classMapping.getProperty(classes[i].getName()); - if (protoName != null) { - // cache the class name for the object so we run faster next time - classMapping.setProperty(className, protoName); - return protoName; - } - } - clazz = clazz.getSuperclass(); - protoName = classMapping.getProperty(clazz.getName()); - if (protoName != null) { - // cache the class name for the object so we run faster next time - classMapping.setProperty(className, protoName); - return protoName == CLASS_NOT_MAPPED ? null : protoName; - } - } - // not mapped - cache negative result - classMapping.setProperty(className, CLASS_NOT_MAPPED); - return null; - } - - //////////////////////////////////////////////////////////////////////// - - /** - * Log an application error - */ - public void logError(String msg, Throwable error) { - if (eventLog == null) { - eventLog = getLogger(eventLogName); - } - eventLog.error(msg, error); - } - - /** - * Log an application error - */ - public void logError(String msg) { - if (eventLog == null) { - eventLog = getLogger(eventLogName); - } - eventLog.error(msg); - } - - /** - * Log a generic application event - */ - public void logEvent(String msg) { - getEventLog().info(msg); - } - - /** - * Log a generic application debug message - */ - public void logDebug(String msg) { - getEventLog().debug(msg); - } - - /** - * Log an application access - */ - public void logAccess(String msg) { - getAccessLog().info(msg); - } - - /** - * get the app's event log. - */ - public Log getEventLog() { - if (eventLog == null) { - eventLog = getLogger(eventLogName); - setEventLogLevel(); - } - return eventLog; - } - - /** - * get the app's access log. - */ - public Log getAccessLog() { - if (accessLog == null) { - accessLog = getLogger(accessLogName); - } - return accessLog; - } - - /** - * Get a logger object to log events for this application. - */ - public Log getLogger(String logname) { - if ("console".equals(logDir) || "console".equals(logname)) { - return Logging.getConsoleLog(); - } else { - return LogFactory.getLog(logname); - } - } - - private void setEventLogLevel() { - // set log level for event log in case it is a helma.util.Logger - if (eventLog instanceof Logger) { - if (debug) { - if (!eventLog.isDebugEnabled()) { - ((Logger) eventLog).setLogLevel(Logger.DEBUG); - } - } else if (eventLog.isDebugEnabled()) { - ((Logger) eventLog).setLogLevel(Logger.INFO); - } - } - } - - /** - * The run method performs periodic tasks like executing the scheduler method and - * kicking out expired user sessions. - */ - public void run() { - - // interval between session cleanups - long lastSessionCleanup = System.currentTimeMillis(); - - while (Thread.currentThread() == worker) { - - try { - // interval between scheduler runs - long sleepInterval = 60000; - - try { - String sleepProp = props.getProperty("schedulerInterval"); - if (sleepProp != null) { - sleepInterval = Math.max(1000, Integer.parseInt(sleepProp) * 1000); - } else { - sleepInterval = CronJob.millisToNextFullMinute(); - } - } catch (Exception ignore) { - // we'll use the default interval - } - - // sleep until the next full minute - try { - Thread.sleep(sleepInterval); - } catch (InterruptedException x) { - worker = null; - break; - } - - // purge sessions - try { - lastSessionCleanup = sessionMgr.cleanupSessions(lastSessionCleanup); - } catch (Exception x) { - logError("Error in session cleanup: " + x, x); - } catch (LinkageError x) { - logError("Error in session cleanup: " + x, x); - } - - // execute cron jobs - try { - executeCronJobs(); - } catch (Exception x) { - logError("Error in cron job execution: " + x, x); - } catch (LinkageError x) { - logError("Error in cron job execution: " + x, x); - } - - } catch (VirtualMachineError error) { - logError("Error in scheduler loop: " + error, error); - } - } - - // when interrupted, shutdown running cron jobs - synchronized (activeCronJobs) { - for (Iterator i = activeCronJobs.values().iterator(); i.hasNext();) { - ((CronRunner) i.next()).interrupt(); - i.remove(); - } - } - - logEvent("Scheduler for " + name + " exiting"); - } - - /** - * Executes cron jobs for the application, which are either - * defined in app.properties or via app.addCronJob(). - * This method is called by run(). - */ - private void executeCronJobs() { - // loop-local cron job data - List jobs = CronJob.parse(props.getSubProperties("cron.")); - Date date = new Date(); - - jobs.addAll(customCronJobs.values()); - CronJob.sort(jobs); - - if (debug) { - logEvent("Running cron jobs: " + jobs); - } - if (!activeCronJobs.isEmpty()) { - logEvent("Cron jobs still running from last minute: " + activeCronJobs); - } - - for (Iterator i = jobs.iterator(); i.hasNext();) { - CronJob job = (CronJob) i.next(); - - if (job.appliesToDate(date)) { - // check if the job is already active ... - if (activeCronJobs.containsKey(job.getName())) { - logEvent(job + " is still active, skipped in this minute"); - - continue; - } - - RequestEvaluator evaluator; - - try { - evaluator = getEvaluator(); - } catch (RuntimeException rt) { - if (running) { - logEvent("couldn't execute " + job + - ", maximum thread count reached"); - - continue; - } else { - break; - } - } - - // if the job has a long timeout or we're already late during this minute - // the job is run from an extra thread - if ((job.getTimeout() > 20000) || - (CronJob.millisToNextFullMinute() < 30000)) { - CronRunner runner = new CronRunner(evaluator, job); - - activeCronJobs.put(job.getName(), runner); - runner.start(); - } else { - try { - evaluator.invokeInternal(null, job.getFunction(), - RequestEvaluator.EMPTY_ARGS, job.getTimeout()); - } catch (Exception ex) { - logEvent("error running " + job + ": " + ex); - } finally { - releaseEvaluator(evaluator); - } - } - } - } - } - - /** - * Check whether a prototype is for scripting a java class, i.e. if there's an entry - * for it in the class.properties file. - */ - public boolean isJavaPrototype(String typename) { - return classMapping.contains(typename); - } - - /** - * Return the java class that a given prototype wraps, or null. - */ - public String getJavaClassForPrototype(String typename) { - - for (Iterator it = classMapping.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); - - if (typename.equals(entry.getValue())) { - return (String) entry.getKey(); - } - } - - return null; - } - - - /** - * Return a DbSource object for a given name. A DbSource is a relational database defined - * in a db.properties file. - */ - public DbSource getDbSource(String name) { - String dbSrcName = name.toLowerCase(); - DbSource dbs = (DbSource) dbSources.get(dbSrcName); - - if (dbs != null) { - return dbs; - } - - try { - dbs = new DbSource(name, dbProps); - dbSources.put(dbSrcName, dbs); - } catch (Exception problem) { - logEvent("Error creating DbSource " + name +": "); - logEvent(problem.toString()); - } - - return dbs; - } - - /** - * Return the name of this application - */ - public String getName() { - return name; - } - - /** - * Add a repository to this app's repository list. This is used for - * ZipRepositories contained in top-level file repositories, for instance. - * - * @param rep the repository to add - * @param current the current/parent repository - * @return if the repository was not yet contained - */ - public boolean addRepository(Repository rep, Repository current) { - if (rep != null && !repositories.contains(rep)) { - // Add the new repository before its parent/current repository. - // This establishes the order of compilation between FileRepositories - // and embedded ZipRepositories, or repositories added - // via app.addRepository() - if (current != null) { - int pos = repositories.indexOf(current); - if (pos > -1) { - repositories.add(pos, rep); - return true; - } - } - // no parent or parent not in app's repositories, add at end of list. - repositories.add(rep); - return true; - } - return false; - } - - /** - * Searches for the index of the given repository for this app. - * The arguement must be a root argument, or -1 will be returned. - * - * @param rep one of this app's root repositories. - * @return the index of the first occurrence of the argument in this - * list; returns -1 if the object is not found. - */ - public int getRepositoryIndex(Repository rep) { - return repositories.indexOf(rep); - } - - /** - * Returns the repositories of this application - * @return iterator through application repositories - */ - public List getRepositories() { - return Collections.unmodifiableList(repositories); - } - - /** - * Set the code resource currently being evaluated/compiled. This is used - * to set the proper parent repository when a new repository is added - * via app.addRepository(). - * - * @param resource the resource being currently evaluated/compiled - */ - public void setCurrentCodeResource(Resource resource) { - currentCodeResource = resource; - } - - /** - * Set the code resource currently being evaluated/compiled. This is used - * to set the proper parent repository when a new repository is added - * via app.addRepository(). - - * @return the resource being currently evaluated/compiled - */ - public Resource getCurrentCodeResource() { - return currentCodeResource; - } - - /** - * Return the directory of the Helma server - */ - public File getServerDir() { - return hopHome; - } - - /** - * Get the DbMapping associated with a prototype name in this application - */ - public DbMapping getDbMapping(String typename) { - Prototype proto = typemgr.getPrototype(typename); - - if (proto == null) { - return null; - } - - return proto.getDbMapping(); - } - - /** - * Return the current upload status. - * @param req the upload RequestTrans - * @return the current upload status. - */ - public UploadStatus getUploadStatus(RequestTrans req) { - String uploadId = (String) req.get("upload_id"); - if (uploadId == null) - return null; - - String sessionId = req.getSession(); - Session session = getSession(sessionId); - if (session == null) - return null; - return session.createUpload(uploadId); - } - - - - private synchronized void updateProperties() { - // if so property file has been updated, re-read props. - if (props.lastModified() > lastPropertyRead) { - // force property update - props.update(); - - // character encoding to be used for responses - charset = props.getProperty("charset", "UTF-8"); - - // debug flag - debug = "true".equalsIgnoreCase(props.getProperty("debug")); - - // if rhino debugger is enabled use higher (10 min) default request timeout - String defaultReqTimeout = - "true".equalsIgnoreCase(props.getProperty("rhino.debug")) ? - "600" : "60"; - String reqTimeout = props.getProperty("requesttimeout", defaultReqTimeout); - try { - requestTimeout = Long.parseLong(reqTimeout) * 1000L; - } catch (Exception ignore) { - // go with default value - requestTimeout = 60000L; - } - - // set base URI - String base = props.getProperty("baseuri"); - - if (base != null) { - setBaseURI(base); - } else if (baseURI == null) { - baseURI = "/"; - } - - hrefRootPrototype = props.getProperty("hrefrootprototype"); - rootObjectPropertyName = props.getProperty("rootobjectpropertyname"); - rootObjectFunctionName = props.getProperty("rootobjectfunctionname"); - - // update the XML-RPC access list, containting prototype.method - // entries of functions that may be called via XML-RPC - String xmlrpcAccessProp = props.getProperty("xmlrpcaccess"); - HashSet xra = new HashSet(); - - if (xmlrpcAccessProp != null) { - StringTokenizer st = new StringTokenizer(xmlrpcAccessProp, ",; "); - - while (st.hasMoreTokens()) { - String token = st.nextToken().trim(); - - xra.add(token.toLowerCase()); - } - } - - xmlrpcAccess = xra; - - // if node manager exists, update it - if (nmgr != null) { - nmgr.updateProperties(props); - } - - // update extensions - if (Server.getServer() != null) { - Vector extensions = Server.getServer().getExtensions(); - - for (int i = 0; i < extensions.size(); i++) { - HelmaExtension ext = (HelmaExtension) extensions.get(i); - - try { - ext.applicationUpdated(this); - } catch (ConfigurationException e) { - logEvent("Error updating extension "+ext+": "+e); - } - } - } - - String loggerFactory = props.getProperty("loggerFactory", "helma.util.Logging"); - if ("helma.util.Logging".equals(loggerFactory)) { - logDir = props.getProperty("logdir", "log"); - if (System.getProperty("helma.logdir") == null) { - // set up helma.logdir system property in case we're using it - // FIXME: this sets a global System property, should be per-app - File dir = new File(logDir); - System.setProperty("helma.logdir", dir.getAbsolutePath()); - } - } else { - logDir = null; - } - - // set log level for event log in case debug flag has changed - setEventLogLevel(); - - // set prop read timestamp - lastPropertyRead = props.lastModified(); - } - } - - /** - * Get a checksum that mirrors the state of this application in the sense - * that if anything in the applciation changes, the checksum hopefully will - * change, too. - */ - public long getChecksum() { - return starttime + - typemgr.getLastCodeUpdate() + - props.getChecksum(); - } - - /** - * Proxy method to get a property from the applications properties. - */ - public String getProperty(String propname) { - return props.getProperty(propname); - } - - /** - * Proxy method to get a property from the applications properties. - */ - public String getProperty(String propname, String defvalue) { - return props.getProperty(propname, defvalue); - } - - /** - * Get the application's app properties - * - * @return the properties reflecting the app.properties - */ - public ResourceProperties getProperties() { - return props; - } - - /** - * Get the application's db properties - * - * @return the properties reflecting the db.properties - */ - public ResourceProperties getDbProperties() { - return dbProps; - } - - - /** - * Return the XML-RPC handler name for this app. The contract is to - * always return the same string, even if it has been changed in the properties file - * during runtime, so the app gets unregistered correctly. - */ - public String getXmlRpcHandlerName() { - if (xmlrpcHandlerName == null) { - xmlrpcHandlerName = props.getProperty("xmlrpcHandlerName", this.name); - } - - return xmlrpcHandlerName; - } - - /** - * Return a string representation for this app. - */ - public String toString() { - return "[Application "+name+"]"; - } - - /** - * - */ - public int countThreads() { - return threadgroup.activeCount(); - } - - /** - * - */ - public int countEvaluators() { - return allThreads.size(); - } - - /** - * - */ - public int countFreeEvaluators() { - return freeThreads.size(); - } - - /** - * - */ - public int countActiveEvaluators() { - return allThreads.size() - freeThreads.size(); - } - - /** - * - */ - public int countMaxActiveEvaluators() { - // return typemgr.countRegisteredRequestEvaluators () -1; - // not available due to framework refactoring - return -1; - } - - /** - * - */ - public long getRequestCount() { - return requestCount; - } - - /** - * - */ - public long getXmlrpcCount() { - return xmlrpcCount; - } - - /** - * - */ - public long getErrorCount() { - return errorCount; - } - - /** - * - * - * @return ... - */ - public long getStarttime() { - return starttime; - } - - /** - * Return the name of the character encoding used by this application - * - * @return the character encoding - */ - public String getCharset() { - return charset; - } - - /** - * Periodically called to log thread stats for this application - */ - public void printThreadStats() { - logEvent("Thread Stats for " + name + ": " + threadgroup.activeCount() + - " active"); - - Runtime rt = Runtime.getRuntime(); - long free = rt.freeMemory(); - long total = rt.totalMemory(); - - logEvent("Free memory: " + (free / 1024) + " kB"); - logEvent("Total memory: " + (total / 1024) + " kB"); - } - - /** - * Check if a method may be invoked via XML-RPC on a prototype. - */ - protected void checkXmlRpcAccess(String proto, String method) - throws Exception { - String key = proto + "." + method; - - // XML-RPC access items are case insensitive and stored in lower case - if (!xmlrpcAccess.contains(key.toLowerCase())) { - throw new Exception("Method " + key + " is not callable via XML-RPC"); - } - } - - class CronRunner extends Thread { - RequestEvaluator thisEvaluator; - CronJob job; - - public CronRunner(RequestEvaluator thisEvaluator, CronJob job) { - this.thisEvaluator = thisEvaluator; - this.job = job; - } - - public void run() { - try { - thisEvaluator.invokeInternal(null, job.getFunction(), - RequestEvaluator.EMPTY_ARGS, job.getTimeout()); - } catch (Exception ex) { - logEvent("error running " + job + ": " + ex); - } finally { - releaseEvaluator(thisEvaluator); - thisEvaluator = null; - activeCronJobs.remove(job.getName()); - } - } - - public String toString() { - return "CronRunner[" + job + "]"; - } - } -} diff --git a/src/main/java/helma/framework/core/ApplicationBean.java b/src/main/java/helma/framework/core/ApplicationBean.java deleted file mode 100644 index 8e26929e..00000000 --- a/src/main/java/helma/framework/core/ApplicationBean.java +++ /dev/null @@ -1,841 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.core; - -import helma.objectmodel.INode; -import helma.objectmodel.db.DbSource; -import helma.util.CronJob; -import helma.util.SystemMap; -import helma.util.WrappedMap; -import helma.framework.repository.*; -import helma.framework.FutureResult; -import helma.main.Server; - -import java.io.File; -import java.io.Serializable; -import java.io.IOException; -import java.util.*; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Application bean that provides a handle to the scripting environment to - * application specific functionality. - */ -public class ApplicationBean implements Serializable { - private static final long serialVersionUID = -5053315391709405106L; - - transient Application app; - WrappedMap properties = null; - - /** - * Creates a new ApplicationBean object. - * - * @param app ... - */ - public ApplicationBean(Application app) { - this.app = app; - } - - /** - * Clear the application cache. - */ - public void clearCache() { - app.clearCache(); - } - - /** - * Get the app's event logger. This is a Log with the - * category helma.[appname].event. - * - * @return the app logger. - */ - public Log getLogger() { - return app.getEventLog(); - } - - /** - * Get the app logger. This is a commons-logging Log with the - * category logname. - * - * @return a logger for the given log name. - */ - public Log getLogger(String logname) { - return LogFactory.getLog(logname); - } - - /** - * Log a INFO message to the app log. - * - * @param msg the log message - */ - public void log(Object msg) { - getLogger().info(msg); - } - - /** - * Log a INFO message to the log defined by logname. - * - * @param logname the name (category) of the log - * @param msg the log message - */ - public void log(String logname, Object msg) { - getLogger(logname).info(msg); - } - - /** - * Log a DEBUG message to the app log if debug is set to true in - * app.properties. - * - * @param msg the log message - */ - public void debug(Object msg) { - if (app.debug()) { - getLogger().debug(msg); - } - } - - /** - * Log a DEBUG message to the log defined by logname - * if debug is set to true in app.properties. - * - * @param logname the name (category) of the log - * @param msg the log message - */ - public void debug(String logname, Object msg) { - if (app.debug()) { - getLogger(logname).debug(msg); - } - } - - /** - * Returns the app's repository list. - * - * @return the an array containing this app's repositories - */ - public Object[] getRepositories() { - return app.getRepositories().toArray(); - } - - /** - * Add a repository to the app's repository list. The .zip extension - * is automatically added, if the original library path does not - * point to an existing file or directory. - * - * @param obj the repository, relative or absolute path to the library. - */ - public synchronized void addRepository(Object obj) { - Resource current = app.getCurrentCodeResource(); - Repository parent = current == null ? - null : current.getRepository().getRootRepository(); - Repository rep; - if (obj instanceof String) { - String path = (String) obj; - File file = findResource(null, path); - if (file == null) { - file = findResource(app.hopHome, path); - if (file == null) { - throw new RuntimeException("Repository not found: " + path); - } - } - if (file.isDirectory()) { - rep = new FileRepository(file); - } else if (file.isFile()) { - if (file.getName().endsWith(".zip")) { - rep = new ZipRepository(file); - } else { - rep = new SingleFileRepository(file); - } - } else { - throw new RuntimeException("Unsupported file type in addRepository: " + file); - } - } else if (obj instanceof Repository) { - rep = (Repository) obj; - } else { - throw new RuntimeException("Invalid argument to addRepository: " + obj); - } - app.addRepository(rep, parent); - try { - app.typemgr.checkRepository(rep, true); - } catch (IOException iox) { - getLogger().error("Error checking repository " + rep, iox); - } - } - - /** - * Helper method to resolve a repository path. Returns null if no file is found. - * @param parent the parent file - * @param path the repository path - * @return an existing file, or null - */ - private File findResource(File parent, String path) { - File file = new File(parent, path).getAbsoluteFile(); - if (!file.exists()) { - // if file does not exist, try with .zip and .js extensions appended - file = new File(parent, path + ".zip").getAbsoluteFile(); - if (!file.exists()) { - file = new File(parent, path + ".js").getAbsoluteFile(); - } - } - return file.exists() ? file : null; - } - - /** - * Get the app's classloader - * @return the app's classloader - */ - public ClassLoader getClassLoader() { - return app.getClassLoader(); - } - - /** - * Return the number of currently active sessions - * @return the current number of active sessions - */ - public int countSessions() { - return app.countSessions(); - } - - /** - * Get a session object for the specified session id - * @param sessionID the session id - * @return the session belonging to the session id, or null - */ - public SessionBean getSession(String sessionID) { - if (sessionID == null) { - return null; - } - - Session session = app.getSession(sessionID.trim()); - - if (session == null) { - return null; - } - - return new SessionBean(session); - } - - /** - * Create a new session with the given session id - * @param sessionID the session id - * @return the newly created session - */ - public SessionBean createSession(String sessionID) { - if (sessionID == null) { - return null; - } - - Session session = app.createSession(sessionID.trim()); - - if (session == null) { - return null; - } - - return new SessionBean(session); - } - - /** - * Get an array of all active sessions - * @return an array of session beans - */ - public SessionBean[] getSessions() { - Map sessions = app.getSessions(); - SessionBean[] array = new SessionBean[sessions.size()]; - int i = 0; - - Iterator it = sessions.values().iterator(); - while (it.hasNext()) { - array[i++] = new SessionBean((Session) it.next()); - } - - return array; - } - - /** - * Register a user with the given name and password using the - * database mapping of the User prototype - * @param username the user name - * @param password the user password - * @return the newly registered user, or null if we failed - */ - public INode registerUser(String username, String password) { - if ((username == null) || (password == null) || "".equals(username.trim()) || - "".equals(password.trim())) { - return null; - } else { - return app.registerUser(username, password); - } - } - - /** - * Get a user object with the given name - * @param username the user name - * @return the user object, or null - */ - public INode getUser(String username) { - if ((username == null) || "".equals(username.trim())) { - return null; - } - - return app.getUserNode(username); - } - - /** - * Get an array of currently active registered users - * @return an array of user nodes - */ - public INode[] getActiveUsers() { - List activeUsers = app.getActiveUsers(); - - return (INode[]) activeUsers.toArray(new INode[0]); - } - - /** - * Get an array of all registered users - * @return an array containing all registered users - */ - public INode[] getRegisteredUsers() { - List registeredUsers = app.getRegisteredUsers(); - - return (INode[]) registeredUsers.toArray(new INode[0]); - } - - /** - * Get an array of all currently active sessions for a given user node - * @param usernode the user node - * @return an array of sessions for the given user - */ - public SessionBean[] getSessionsForUser(INode usernode) { - if (usernode == null) { - return new SessionBean[0]; - } else { - return getSessionsForUser(usernode.getName()); - } - } - - /** - * Get an array of all currently active sessions for a given user name - * @param username the user node - * @return an array of sessions for the given user - */ - public SessionBean[] getSessionsForUser(String username) { - if ((username == null) || "".equals(username.trim())) { - return new SessionBean[0]; - } - - List userSessions = app.getSessionsForUsername(username); - - return (SessionBean[]) userSessions.toArray(new SessionBean[0]); - } - - /** - * Add a cron job that will run once a minute - * @param functionName the function name - */ - public void addCronJob(String functionName) { - CronJob job = new CronJob(functionName); - - job.setFunction(functionName); - app.customCronJobs.put(functionName, job); - } - - /** - * Add a cron job that will run at the specified time intervals - * - * @param functionName the function name - * @param year comma separated list of years, or * - * @param month comma separated list of months, or * - * @param day comma separated list of days, or * - * @param weekday comma separated list of weekdays, or * - * @param hour comma separated list of hours, or * - * @param minute comma separated list of minutes, or * - */ - public void addCronJob(String functionName, String year, String month, String day, - String weekday, String hour, String minute) { - CronJob job = CronJob.newJob(functionName, year, month, day, weekday, hour, minute); - - app.customCronJobs.put(functionName, job); - } - - /** - * Unregister a previously registered cron job - * @param functionName the function name - */ - public void removeCronJob(String functionName) { - app.customCronJobs.remove(functionName); - } - - /** - * Returns an read-only map of the custom cron jobs registered with the app - * - * @return a map of cron jobs - */ - public Map getCronJobs() { - return new WrappedMap(app.customCronJobs, true); - } - - /** - * Returns the number of elements in the NodeManager's cache - */ - public int getCacheusage() { - return app.getCacheUsage(); - } - - /** - * Returns the app's data node used to share data between the app's evaluators - * - * @return the app.data node - */ - public INode getData() { - return app.getCacheNode(); - } - - /** - * Returns the app's modules map used to register application modules - * - * @return the module map - */ - public Map getModules() { - return app.modules; - } - - /** - * Returns the absolute path of the app dir. When using repositories this - * equals the first file based repository. - * - * @return the app dir - */ - public String getDir() { - return app.getAppDir().getAbsolutePath(); - } - - /** - * @return the app name - */ - public String getName() { - return app.getName(); - } - - /** - * @return the application start time - */ - public Date getUpSince() { - return new Date(app.starttime); - } - - /** - * @return the number of requests processed by this app - */ - public long getRequestCount() { - return app.getRequestCount(); - } - - /** - * @return the number of XML-RPC requests processed - */ - public long getXmlrpcCount() { - return app.getXmlrpcCount(); - } - - /** - * @return the number of errors encountered - */ - public long getErrorCount() { - return app.getErrorCount(); - } - - /** - * @return the wrapped helma.framework.core.Application object - */ - public Application get__app__() { - return app; - } - - /** - * Get a wrapper around the app's properties - * - * @return a readonly wrapper around the application's app properties - */ - public Map getProperties() { - if (properties == null) { - properties = new WrappedMap(app.getProperties(), true); - } - return properties; - } - - /** - * Get a wrapper around the app's db properties - * - * @return a readonly wrapper around the application's db properties - */ - public Map getDbProperties() { - return new WrappedMap(app.getDbProperties(), true); - } - - /** - * Return a DbSource object for a given name. - */ - public DbSource getDbSource(String name) { - return app.getDbSource(name); - } - - /** - * Get a wrapper around the app's apps.properties - * - * @return a readonly wrapper around the application's apps.properties - */ - public Map getAppsProperties() { - Server server = Server.getServer(); - if (server == null) - return new SystemMap(); - return new WrappedMap(server.getAppsProperties(app.getName()), true); - } - - /** - * Get an array of this app's prototypes - * - * @return an array containing the app's prototypes - */ - public Prototype[] getPrototypes() { - return (Prototype[]) app.getPrototypes().toArray(new Prototype[0]); - } - - /** - * Get a prototype by name. - * - * @param name the prototype name - * @return the prototype - */ - public Prototype getPrototype(String name) { - return app.getPrototypeByName(name); - } - - /** - * Get the number of currently available threads/request evaluators - * @return the currently available threads - */ - public int getFreeThreads() { - return app.countFreeEvaluators(); - } - - /** - * Get the number of currently active request threads - * @return the number of currently active threads - */ - public int getActiveThreads() { - return app.countActiveEvaluators(); - } - - /** - * Get the maximal thread number for this application - * @return the maximal number of threads/request evaluators - */ - public int getMaxThreads() { - return app.countEvaluators(); - } - - /** - * Set the maximal thread number for this application - * @param n the maximal number of threads/request evaluators - */ - public void setMaxThreads(int n) { - // add one to the number to compensate for the internal scheduler. - app.setNumberOfEvaluators(n + 1); - } - - /** - * Return a skin for a given object. The skin is found by determining the prototype - * to use for the object, then looking up the skin for the prototype. - */ - public Skin getSkin(String protoname, String skinname, Object[] skinpath) { - try { - return app.getSkin(protoname, skinname, skinpath); - } catch (Exception x) { - return null; - } - } - - /** - * Return a map of skin resources - * - * @return a map containing the skin resources - */ - public Map getSkinfiles() { - Map skinz = new SystemMap(); - - for (Iterator it = app.getPrototypes().iterator(); it.hasNext();) { - Prototype p = (Prototype) it.next(); - - Object skinmap = p.getScriptableSkinMap(); - skinz.put(p.getName(), skinmap); - skinz.put(p.getLowerCaseName(), skinmap); - } - - return skinz; - } - - /** - * Return a map of skin resources including the app-specific skinpath - * - * @param skinpath an array of directory paths or HopObjects to search for skins - * @return a map containing the skin resources - */ - public Map getSkinfilesInPath(Object[] skinpath) { - Map skinz = new SystemMap(); - - for (Iterator it = app.getPrototypes().iterator(); it.hasNext();) { - Prototype p = (Prototype) it.next(); - - Object skinmap = p.getScriptableSkinMap(skinpath); - skinz.put(p.getName(), skinmap); - skinz.put(p.getLowerCaseName(), skinmap); - } - - return skinz; - } - - /** - * Return the absolute application directory (appdir property - * in apps.properties file) - * @return the app directory as absolute path - */ - public String getAppDir() { - return app.getAppDir().getAbsolutePath(); - } - - /** - * Return the absolute server directory - * @return the server directory as absolute path - */ - public String getServerDir() { - File f = app.getServerDir(); - - if (f == null) { - return app.getAppDir().getAbsolutePath(); - } - - return f.getAbsolutePath(); - } - - /** - * Return the app's default charset/encoding. - * @return the app's charset - */ - public String getCharset() { - return app.getCharset(); - } - - /** - * Set the path for global macro resolution - * @param path an array of global namespaces, or null - */ - public void setGlobalMacroPath(String[] path) { - app.globalMacroPath = path; - } - - /** - * Get the path for global macro resolution - * @return an array of global namespaces, or null - */ - public String[] getGlobalMacroPath() { - return app.globalMacroPath; - } - - /** - * Trigger a synchronous Helma invocation with a default timeout of 30 seconds. - * - * @param thisObject the object to invoke the function on, - * or null for global invokation - * @param function the function or function name to invoke - * @param args an array of arguments - * @return the value returned by the function - * @throws Exception exception thrown by the function - */ - public Object invoke(Object thisObject, Object function, Object[] args) - throws Exception { - // default timeout of 30 seconds - return invoke(thisObject, function, args, 30000L); - } - - /** - * Trigger a synchronous Helma invocation. - * - * @param thisObject the object to invoke the function on, - * or null for global invokation - * @param function the function or function name to invoke - * @param args an array of arguments - * @param timeout the timeout in milliseconds. After waiting - * this long, we will try to interrupt the invocation - * @return the value returned by the function - * @throws Exception exception thrown by the function - */ - public Object invoke(Object thisObject, Object function, - Object[] args, long timeout) - throws Exception { - RequestEvaluator reval = app.getEvaluator(); - try { - return reval.invokeInternal(thisObject, function, args, timeout); - } finally { - app.releaseEvaluator(reval); - } - } - - /** - * Trigger an asynchronous Helma invocation. This method returns - * immedately with an object that allows to track the result of the - * function invocation with the following properties: - * - *
      - *
    • running - true while the function is running, false afterwards
    • - *
    • result - the value returned by the function, if any
    • - *
    • exception - the exception thrown by the function, if any
    • - *
    • waitForResult() - wait indefinitely until invocation terminates - * and return the result
    • - *
    • waitForResult(t) - wait for the specified number of milliseconds - * for invocation to terminate and return the result
    • - *
    - * - * @param thisObject the object to invoke the function on, - * or null for global invokation - * @param function the function or function name to invoke - * @param args an array of arguments - * this long, we will try to interrupt the invocation - * @return an object with the properties described above - */ - public FutureResult invokeAsync(Object thisObject, - final Object function, - final Object[] args) { - // default timeout of 15 minutes - return new AsyncInvoker(thisObject, function, args, 60000L * 15); - } - - /** - * Trigger an asynchronous Helma invocation. This method returns - * immedately with an object that allows to track the result of the - * function invocation with the following methods and properties: - * - *
      - *
    • running - true while the function is running, false afterwards
    • - *
    • result - the value returned by the function, if any
    • - *
    • exception - the exception thrown by the function, if any
    • - *
    • waitForResult() - wait indefinitely until invocation terminates - * and return the result
    • - *
    • waitForResult(t) - wait for the specified number of milliseconds - * for invocation to terminate and return the result
    • - *
    - * - * @param thisObject the object to invoke the function on, - * or null for global invokation - * @param function the function or function name to invoke - * @param args an array of arguments - * @param timeout the timeout in milliseconds. After waiting - * this long, we will try to interrupt the invocation - * @return an object with the properties described above - */ - public FutureResult invokeAsync(Object thisObject, Object function, - Object[] args, long timeout) { - return new AsyncInvoker(thisObject, function, args, timeout); - } - - /** - * Return a string presentation of this AppBean - * @return string description of this app bean object - */ - public String toString() { - return "[Application " + app.getName() + "]"; - } - - class AsyncInvoker extends Thread implements FutureResult { - - private Object thisObject; - private Object function; - private Object[] args; - private long timeout; - - private Object result; - private Exception exception; - private boolean running = true; - - private AsyncInvoker(Object thisObj, Object func, Object[] args, long timeout) { - thisObject = thisObj; - function = func; - this.args = args; - this.timeout = timeout; - start(); - } - - public void run() { - RequestEvaluator reval = null; - try { - reval = app.getEvaluator(); - setResult(reval.invokeInternal(thisObject, function, args, timeout)); - } catch (Exception x) { - setException(x); - } finally { - running = false; - app.releaseEvaluator(reval); - } - } - - public synchronized boolean getRunning() { - return running; - } - - private synchronized void setResult(Object obj) { - result = obj; - running = false; - notifyAll(); - } - - public synchronized Object getResult() { - return result; - } - - public synchronized Object waitForResult() throws InterruptedException { - if (!running) - return result; - wait(); - return result; - } - - public synchronized Object waitForResult(long timeout) - throws InterruptedException { - if (!running) - return result; - wait(timeout); - return result; - } - - private synchronized void setException(Exception x) { - exception = x; - running = false; - notifyAll(); - } - - public synchronized Exception getException() { - return exception; - } - - public String toString() { - return new StringBuffer("AsyncInvokeThread{running: ").append(running) - .append(", result: ").append(result).append(", exception: ") - .append(exception).append("}").toString(); - } - - } -} diff --git a/src/main/java/helma/framework/core/Prototype.java b/src/main/java/helma/framework/core/Prototype.java deleted file mode 100644 index ec5e5dbc..00000000 --- a/src/main/java/helma/framework/core/Prototype.java +++ /dev/null @@ -1,654 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.core; - -import helma.objectmodel.db.DbMapping; -import helma.util.ResourceProperties; -import helma.util.WrappedMap; -import helma.framework.repository.Resource; -import helma.framework.repository.Repository; -import helma.framework.repository.ResourceTracker; -import helma.framework.repository.FileResource; -import helma.scripting.ScriptingEngine; - -import java.io.*; -import java.util.*; - -/** - * The Prototype class represents Script prototypes/type defined in a Helma - * application. This class manages a prototypes templates, functions and actions - * as well as optional information about the mapping of this type to a - * relational database table. - */ -public final class Prototype { - // the app this prototype belongs to - Application app; - - // this prototype's name in natural and lower case - String name; - String lowerCaseName; - - // this prototype's resources - Resource[] resources; - - // tells us the checksum of the repositories at the time we last updated them - long lastChecksum = -1; - - // the time at which any of the prototype's files were found updated the last time - volatile long lastCodeUpdate = 0; - - TreeSet code; - TreeSet skins; - - HashMap trackers; - - TreeSet repositories; - - // a map of this prototype's skins as raw strings - // used for exposing skins to application (script) code (via app.skinfiles). - SkinMap skinMap; - - DbMapping dbmap; - - private Prototype parent; - - ResourceProperties props; - - /** - * Creates a new Prototype object. - * - * @param name the prototype's name - * @param repository the first prototype's repository - * @param app the application this prototype is a part of - * @param typeProps custom type mapping properties - */ - public Prototype(String name, Repository repository, Application app, Map typeProps) { - // app.logEvent ("Constructing Prototype "+app.getName()+"/"+name); - this.app = app; - this.name = name; - repositories = new TreeSet(app.getResourceComparator()); - if (repository != null) { - repositories.add(repository); - } - lowerCaseName = name.toLowerCase(); - - // Create and register type properties file - props = new ResourceProperties(app); - if (typeProps != null) { - props.putAll(typeProps); - } else if (repository != null) { - props.addResource(repository.getResource("type.properties")); - props.addResource(repository.getResource(name + ".properties")); - } - - dbmap = new DbMapping(app, name, props); - // we don't need to put the DbMapping into proto.updatables, because - // dbmappings are checked separately in TypeManager.checkFiles() for - // each request - - code = new TreeSet(app.getResourceComparator()); - skins = new TreeSet(app.getResourceComparator()); - - trackers = new HashMap(); - - skinMap = new SkinMap(); - } - - /** - * Return the application this prototype is a part of - */ - public Application getApplication() { - return app; - } - - /** - * Adds an repository to the list of repositories - * @param repository repository to add - * @param update indicates whether to immediately update the prototype with the new code - * @throws IOException if reading/updating from the repository fails - */ - public void addRepository(Repository repository, boolean update) throws IOException { - if (!repositories.contains(repository)) { - repositories.add(repository); - props.addResource(repository.getResource("type.properties")); - props.addResource(repository.getResource(name + ".properties")); - if (update) { - RequestEvaluator eval = app.getCurrentRequestEvaluator(); - ScriptingEngine engine = eval == null ? null : eval.scriptingEngine; - Iterator it = repository.getAllResources().iterator(); - while (it.hasNext()) { - checkResource((Resource) it.next(), engine); - } - } - } - } - - /** - * Check a prototype for new or updated resources. After this has been - * called the code and skins collections of this prototype should be - * up-to-date and the lastCodeUpdate be set if there has been any changes. - */ - public synchronized void checkForUpdates() { - boolean updatedResources = false; - - // check if any resource the prototype knows about has changed or gone - for (Iterator i = trackers.values().iterator(); i.hasNext();) { - ResourceTracker tracker = (ResourceTracker) i.next(); - - try { - if (tracker.hasChanged()) { - updatedResources = true; - // let tracker know we've seen the update - tracker.markClean(); - // if resource has gone remove it - if (!tracker.getResource().exists()) { - i.remove(); - String name = tracker.getResource().getName(); - if (name.endsWith(TypeManager.skinExtension)) { - skins.remove(tracker.getResource()); - } else { - code.remove(tracker.getResource()); - } - } - } - } catch (IOException iox) { - iox.printStackTrace(); - } - } - - // next we check if resources have been created or removed - Resource[] resources = getResources(); - - for (int i = 0; i < resources.length; i++) { - updatedResources |= checkResource(resources[i], null); - } - - if (updatedResources) { - // mark prototype as dirty and the code as updated - lastCodeUpdate = System.currentTimeMillis(); - app.typemgr.setLastCodeUpdate(lastCodeUpdate); - } - } - - private boolean checkResource(Resource res, ScriptingEngine engine) { - String name = res.getName(); - boolean updated = false; - if (!trackers.containsKey(name)) { - if (name.endsWith(TypeManager.templateExtension) || - name.endsWith(TypeManager.scriptExtension) || - name.endsWith(TypeManager.actionExtension) || - name.endsWith(TypeManager.skinExtension)) { - updated = true; - if (name.endsWith(TypeManager.skinExtension)) { - skins.add(res); - } else { - if (engine != null) { - engine.injectCodeResource(lowerCaseName, res); - } - code.add(res); - } - trackers.put(res.getName(), new ResourceTracker(res)); - } - } - return updated; - } - - /** - * Returns the list of resources in this prototype's repositories. Used - * by checkForUpdates() to see whether there is anything new. - */ - public Resource[] getResources() { - long checksum = getRepositoryChecksum(); - // reload resources if the repositories checksum has changed - if (checksum != lastChecksum) { - ArrayList list = new ArrayList(); - Iterator iterator = repositories.iterator(); - - while (iterator.hasNext()) { - try { - list.addAll(((Repository) iterator.next()).getAllResources()); - } catch (IOException iox) { - iox.printStackTrace(); - } - } - - resources = (Resource[]) list.toArray(new Resource[list.size()]); - lastChecksum = checksum; - } - return resources; - } - - /** - * Returns an array of repositories containing code for this prototype. - */ - public Repository[] getRepositories() { - return (Repository[]) repositories.toArray(new Repository[repositories.size()]); - } - - /** - * Get a checksum over this prototype's repositories. This tells us - * if any resources were added or removed. - */ - long getRepositoryChecksum() { - long checksum = 0; - Iterator iterator = repositories.iterator(); - - while (iterator.hasNext()) { - try { - checksum += ((Repository) iterator.next()).getChecksum(); - } catch (IOException iox) { - iox.printStackTrace(); - } - } - - return checksum; - } - - /** - * Set the parent prototype of this prototype, i.e. the prototype this - * prototype inherits from. - */ - public void setParentPrototype(Prototype parent) { - // this is not allowed for the hopobject and global prototypes - if ("hopobject".equals(lowerCaseName) || "global".equals(lowerCaseName)) { - return; - } - - this.parent = parent; - } - - /** - * Get the parent prototype from which we inherit, or null - * if we are top of the line. - */ - public Prototype getParentPrototype() { - return parent; - } - - /** - * Check if the given prototype is within this prototype's parent chain. - */ - public final boolean isInstanceOf(String pname) { - if (name.equalsIgnoreCase(pname)) { - return true; - } - - if (parent != null) { - return parent.isInstanceOf(pname); - } - - return false; - } - - /** - * Register an object as handler for all our parent prototypes, but only if - * a handler by that prototype name isn't registered yet. This is used to - * implement direct over indirect prototype precedence and child over parent - * precedence. - */ - public final void registerParents(Map handlers, Object obj) { - - Prototype p = parent; - - while ((p != null) && !"hopobject".equals(p.getLowerCaseName())) { - Object old = handlers.put(p.name, obj); - // if an object was already registered by this name, put it back in again. - if (old != null) { - handlers.put(p.name, old); - } - // same with lower case name - old = handlers.put(p.lowerCaseName, obj); - if (old != null) { - handlers.put(p.lowerCaseName, old); - } - - p = p.parent; - } - } - - /** - * Get the DbMapping associated with this prototype - */ - public DbMapping getDbMapping() { - return dbmap; - } - - /** - * Get a skin for this prototype. This only works for skins - * residing in the prototype directory, not for skins files in - * other locations or database stored skins. If parentName and - * subName are defined, the skin may be a subskin of another skin. - */ - public Skin getSkin(Prototype proto, String skinname, String subskin, Object[] skinpath) - throws IOException { - Resource res = skinMap.getResource(skinname); - while (res != null) { - Skin skin = Skin.getSkin(res, app); - if (subskin == null && skin.hasMainskin()) { - return skin; - } else if (subskin != null && skin.hasSubskin(subskin)) { - return skin.getSubskin(subskin); - } - String baseskin = skin.getExtends(); - if (baseskin != null && !baseskin.equalsIgnoreCase(skinname)) { - // we need to call SkinManager.getSkin() to fetch overwritten - // base skins from skinpath - return app.skinmgr.getSkin(proto, baseskin, subskin, skinpath); - } - res = res.getOverloadedResource(); - } - return null; - } - - /** - * Return this prototype's name - * - * @return ... - */ - public String getName() { - return name; - } - - /** - * Return this prototype's name in lower case letters - * - * @return ... - */ - public String getLowerCaseName() { - return lowerCaseName; - } - - /** - * Get the last time any script has been re-read for this prototype. - */ - public long lastCodeUpdate() { - return lastCodeUpdate; - } - - /** - * Signal that some script in this prototype has been - * re-read from disk and needs to be re-compiled by - * the evaluators. - */ - public void markUpdated() { - lastCodeUpdate = System.currentTimeMillis(); - } - - /** - * Set the custom type properties for this prototype and update the database mapping. - * @param map the custom type mapping properties. - */ - public void setTypeProperties(Map map) { - props.clear(); - props.putAll(map); - dbmap.update(); - } - - /** - * Get the prototype's aggregated type.properties - * - * @return type.properties - */ - public ResourceProperties getTypeProperties() { - return props; - } - - /** - * Return an iterator over this prototype's code resoruces. Synchronized - * to not return a collection in a transient state where it is just being - * updated by the type manager. - * - * @return an iterator of this prototype's code resources - */ - public synchronized Iterator getCodeResources() { - // if code has never been updated, do so now before returning an empty or incomplete list - if (lastCodeUpdate == 0) { - checkForUpdates(); - } - - // we copy over to a new list, because the underlying set may grow - // during compilation through use of app.addRepository() - return new ArrayList(code).iterator(); - } - - /** - * Return an iterator over this prototype's skin resoruces. Synchronized - * to not return a collection in a transient state where it is just being - * updated by the type manager. - * - * @return an iterator over this prototype's skin resources - */ - public Iterator getSkinResources() { - return skins.iterator(); - } - - /** - * Return a string representing this prototype. - */ - public String toString() { - return "[Prototype " + app.getName() + "/" + name + "]"; - } - - /** - * Get a map containing this prototype's skins as strings - * - * @return a scriptable skin map - */ - public Map getScriptableSkinMap() { - return new ScriptableSkinMap(new SkinMap()); - } - - /** - * Get a map containing this prototype's skins as strings, overloaded by the - * skins found in the given skinpath. - * - * @return a scriptable skin map - */ - public Map getScriptableSkinMap(Object[] skinpath) { - return new ScriptableSkinMap(new SkinMap(skinpath)); - } - - /** - * A map of this prototype's skins that acts as a native JavaScript object in - * rhino and returns the skins as strings. This is used to expose the skins - * to JavaScript in app.skinfiles[prototypeName][skinName]. - */ - class ScriptableSkinMap extends WrappedMap { - - public ScriptableSkinMap(Map wrapped) { - super(wrapped); - } - - public Object get(Object key) { - Resource res = (Resource) super.get(key); - - if (res == null || !res.exists()) { - return null; - } - - try { - return res.getContent(); - } catch (IOException iox) { - return null; - } - } - } - - /** - * A Map that dynamically expands to all skins in this prototype. - */ - class SkinMap extends HashMap { - private static final long serialVersionUID = -8855785541204100909L; - - volatile long lastSkinmapLoad = -1; - Object[] skinpath; - - SkinMap() { - skinpath = null; - } - - SkinMap(Object[] path) { - skinpath = path; - } - - public boolean containsKey(Object key) { - checkForUpdates(); - return super.containsKey(key); - } - - public boolean containsValue(Object value) { - checkForUpdates(); - return super.containsValue(value); - } - - public Set entrySet() { - checkForUpdates(); - return super.entrySet(); - } - - public boolean equals(Object obj) { - checkForUpdates(); - return super.equals(obj); - } - - public Skin getSkin(Object key) throws IOException { - Resource res = (Resource) get(key); - - if (res != null) { - return Skin.getSkin(res, app); - } else { - return null; - } - } - - public Resource getResource(Object key) { - return (Resource) get(key); - } - - public Object get(Object key) { - checkForUpdates(); - return super.get(key); - } - - public int hashCode() { - checkForUpdates(); - return super.hashCode(); - } - - public boolean isEmpty() { - checkForUpdates(); - return super.isEmpty(); - } - - public Set keySet() { - checkForUpdates(); - return super.keySet(); - } - - public Object put(Object key, Object value) { - // checkForUpdates (); - return super.put(key, value); - } - - public void putAll(Map t) { - // checkForUpdates (); - super.putAll(t); - } - - public Object remove(Object key) { - checkForUpdates(); - return super.remove(key); - } - - public int size() { - checkForUpdates(); - return super.size(); - } - - public Collection values() { - checkForUpdates(); - return super.values(); - } - - private void checkForUpdates() { - if (lastCodeUpdate > lastSkinmapLoad) { - if (lastCodeUpdate == 0) { - // if prototype resources haven't been checked yet, check them now - Prototype.this.checkForUpdates(); - } - loadSkins(); - } - } - - private synchronized void loadSkins() { - if (lastCodeUpdate == lastSkinmapLoad) { - return; - } - - super.clear(); - - // load Skins - for (Iterator i = skins.iterator(); i.hasNext();) { - Resource res = (Resource) i.next(); - Resource prev = (Resource) super.put(res.getBaseName(), res); - res.setOverloadedResource(prev); - } - - // if skinpath is not null, overload/add skins from there - if (skinpath != null) { - for (int i = skinpath.length - 1; i >= 0; i--) { - if ((skinpath[i] != null) && skinpath[i] instanceof String) { - loadSkinFiles((String) skinpath[i]); - } - } - } - - lastSkinmapLoad = lastCodeUpdate; - } - - private void loadSkinFiles(String skinDir) { - File dir = new File(skinDir, Prototype.this.getName()); - // if directory does not exist use lower case property name - if (!dir.isDirectory()) { - dir = new File(skinDir, Prototype.this.getLowerCaseName()); - if (!dir.isDirectory()) { - return; - } - } - - String[] skinNames = dir.list(app.skinmgr); - - if ((skinNames == null) || (skinNames.length == 0)) { - return; - } - - for (int i = 0; i < skinNames.length; i++) { - String name = skinNames[i].substring(0, skinNames[i].length() - 5); - File file = new File(dir, skinNames[i]); - - Resource res = new FileResource(file); - Resource prev = (Resource) super.put(name, res); - res.setOverloadedResource(prev); - } - - } - - public String toString() { - return "[SkinMap " + name + "]"; - } - } -} \ No newline at end of file diff --git a/src/main/java/helma/framework/core/RequestEvaluator.java b/src/main/java/helma/framework/core/RequestEvaluator.java deleted file mode 100644 index e8b6051c..00000000 --- a/src/main/java/helma/framework/core/RequestEvaluator.java +++ /dev/null @@ -1,1148 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.core; - -import helma.framework.*; -import helma.objectmodel.*; -import helma.objectmodel.db.*; -import helma.scripting.*; -import java.lang.reflect.*; -import java.util.*; - -import org.apache.xmlrpc.XmlRpcRequestProcessor; -import org.apache.xmlrpc.XmlRpcServerRequest; -import org.apache.commons.logging.Log; - -/** - * This class does the work for incoming requests. It holds a transactor thread - * and an EcmaScript evaluator to get the work done. Incoming threads are - * blocked until the request has been serviced by the evaluator, or the timeout - * specified by the application has passed. In the latter case, the evaluator thread - * is killed and an error message is returned. - */ -public final class RequestEvaluator implements Runnable { - static final int NONE = 0; // no request - static final int HTTP = 1; // via HTTP gateway - static final int XMLRPC = 2; // via XML-RPC - static final int INTERNAL = 3; // generic function call, e.g. by scheduler - static final int EXTERNAL = 4; // function from script etc - - public static final Object[] EMPTY_ARGS = new Object[0]; - - public final Application app; - - protected ScriptingEngine scriptingEngine; - - // skin depth counter, used to avoid recursive skin rendering - protected int skinDepth; - - private volatile RequestTrans req; - private volatile ResponseTrans res; - - // the one and only transactor thread - private volatile Thread thread; - - private volatile Transactor transactor; - - // the type of request to be serviced, - // used to coordinate worker and waiter threads - private volatile int reqtype; - - // the object on which to invoke a function, if specified - private volatile Object thisObject; - - // the method to be executed - private volatile Object function; - - // the session object associated with the current request - private volatile Session session; - - // arguments passed to the function - private volatile Object[] args; - - // the result of the operation - private volatile Object result; - - // the exception thrown by the evaluator, if any. - private volatile Exception exception; - - // For numbering threads. - private int threadId; - - - /** - * Create a new RequestEvaluator for this application. - * @param app the application - */ - public RequestEvaluator(Application app) { - this.app = app; - } - - protected synchronized void initScriptingEngine() { - if (scriptingEngine == null) { - String engineClassName = app.getProperty("scriptingEngine", - "helma.scripting.rhino.RhinoEngine"); - try { - app.setCurrentRequestEvaluator(this); - Class clazz = app.getClassLoader().loadClass(engineClassName); - - scriptingEngine = (ScriptingEngine) clazz.newInstance(); - scriptingEngine.init(app, this); - } catch (Exception x) { - Throwable t = x; - - if (x instanceof InvocationTargetException) { - t = ((InvocationTargetException) x).getTargetException(); - } - - app.logEvent("******************************************"); - app.logEvent("*** Error creating scripting engine: "); - app.logEvent("*** " + t.toString()); - app.logEvent("******************************************"); - app.logError("Error creating scripting engine", t); - - // null out invalid scriptingEngine - scriptingEngine = null; - // rethrow exception - if (t instanceof RuntimeException) { - throw((RuntimeException) t); - } else { - throw new RuntimeException(t.toString(), t); - } - } finally { - app.setCurrentRequestEvaluator(null); - } - } - } - - protected synchronized void shutdown() { - if (scriptingEngine != null) { - scriptingEngine.shutdown(); - } - } - - /** - * - */ - public void run() { - // first, set a local variable to the current transactor thread so we know - // when it's time to quit because another thread took over. - Thread localThread = Thread.currentThread(); - - // spans whole execution loop - close connections in finally clause - try { - - // while this thread is serving requests - while (localThread == thread) { - - // object reference to ressolve request path - Object currentElement; - - // Get req and res into local variables to avoid memory caching problems - // in unsynchronized method. - RequestTrans req = getRequest(); - ResponseTrans res = getResponse(); - - // request path object - RequestPath requestPath = new RequestPath(app); - - String txname = req.getMethod() + ":" + req.getPath(); - Log eventLog = app.getEventLog(); - if (eventLog.isDebugEnabled()) { - eventLog.debug(txname + " starting"); - } - - int tries = 0; - boolean done = false; - Throwable error = null; - String functionName = function instanceof String ? - (String) function : null; - - while (!done && localThread == thread) { - // catch errors in path resolution and script execution - try { - - // initialize scripting engine - initScriptingEngine(); - app.setCurrentRequestEvaluator(this); - // update scripting prototypes - scriptingEngine.enterContext(); - - - // avoid going into transaction if called function doesn't exist. - // this only works for the (common) case that method is a plain - // method name, not an obj.method path - if (reqtype == INTERNAL) { - // if object is an instance of NodeHandle, get the node object itself. - if (thisObject instanceof NodeHandle) { - thisObject = ((NodeHandle) thisObject).getNode(app.nmgr.safe); - // If no valid node object return immediately - if (thisObject == null) { - done = true; - reqtype = NONE; - break; - } - } - // If function doesn't exist, return immediately - if (functionName != null && !scriptingEngine.hasFunction(thisObject, functionName, true)) { - app.logEvent(missingFunctionMessage(thisObject, functionName)); - done = true; - reqtype = NONE; - break; - } - } else if (function != null && functionName == null) { - // only internal requests may pass a function instead of a function name - throw new IllegalStateException("No function name in non-internal request "); - } - - // Update transaction name in case we're processing an error - if (error != null) { - txname = "error:" + txname; - } - - // begin transaction - transactor = Transactor.getInstance(app.nmgr); - transactor.begin(txname); - - Object root = app.getDataRoot(scriptingEngine); - initGlobals(root, requestPath); - - String action = null; - - if (error != null) { - res.setError(error); - } - - switch (reqtype) { - case HTTP: - - // bring over the message from a redirect - session.recoverResponseMessages(res); - - // catch redirect in path resolution or script execution - try { - // catch object not found in path resolution - try { - if (error != null) { - // there was an error in the previous loop, call error handler - currentElement = root; - res.setStatus(500); - - // do not reset the requestPath so error handler can use the original one - // get error handler action - String errorAction = app.props.getProperty("error", - "error"); - - action = getAction(currentElement, errorAction, req); - - if (action == null) { - throw new RuntimeException(error); - } - } else if ((req.getPath() == null) || - "".equals(req.getPath().trim())) { - currentElement = root; - requestPath.add(null, currentElement); - - action = getAction(currentElement, null, req); - - if (action == null) { - throw new NotFoundException("Action not found"); - } - } else { - // march down request path... - StringTokenizer st = new StringTokenizer(req.getPath(), - "/"); - int ntokens = st.countTokens(); - - // limit path to < 50 tokens - if (ntokens > 50) { - throw new RuntimeException("Path too long"); - } - - String[] pathItems = new String[ntokens]; - - for (int i = 0; i < ntokens; i++) - pathItems[i] = st.nextToken(); - - currentElement = root; - requestPath.add(null, currentElement); - - for (int i = 0; i < ntokens; i++) { - if (currentElement == null) { - throw new NotFoundException("Object not found."); - } - - if (pathItems[i].length() == 0) { - continue; - } - - // if we're at the last element of the path, - // try to interpret it as action name. - if (i == (ntokens - 1) && !req.getPath().endsWith("/")) { - action = getAction(currentElement, pathItems[i], req); - } - - if (action == null) { - currentElement = getChildElement(currentElement, - pathItems[i]); - - // add object to request path if suitable - if (currentElement != null) { - // add to requestPath array - requestPath.add(pathItems[i], currentElement); - } - } - } - - if (currentElement == null) { - throw new NotFoundException("Object not found."); - } - - if (action == null) { - action = getAction(currentElement, null, req); - } - - if (action == null) { - throw new NotFoundException("Action not found"); - } - } - } catch (NotFoundException notfound) { - if (error != null) { - - // we already have an error and the error template wasn't found, - // display it instead of notfound message - throw new RuntimeException(); - } - - // The path could not be resolved. Check if there is a "not found" action - // specified in the property file. - res.setStatus(404); - - String notFoundAction = app.props.getProperty("notfound", - "notfound"); - - currentElement = root; - action = getAction(currentElement, notFoundAction, req); - - if (action == null) { - throw new NotFoundException(notfound.getMessage()); - } - } - - // register path objects with their prototype names in - // res.handlers - Map macroHandlers = res.getMacroHandlers(); - int l = requestPath.size(); - Prototype[] protos = new Prototype[l]; - - for (int i = 0; i < l; i++) { - - Object obj = requestPath.get(i); - - protos[i] = app.getPrototype(obj); - - // immediately register objects with their direct prototype name - if (protos[i] != null) { - macroHandlers.put(protos[i].getName(), obj); - macroHandlers.put(protos[i].getLowerCaseName(), obj); - } - } - - // in a second pass, we register path objects with their indirect - // (i.e. parent prototype) names, starting at the end and only - // if the name isn't occupied yet. - for (int i = l - 1; i >= 0; i--) { - if (protos[i] != null) { - protos[i].registerParents(macroHandlers, requestPath.get(i)); - } - } - - ///////////////////////////////////////////////////////////////////////////// - // end of path resolution section - ///////////////////////////////////////////////////////////////////////////// - // beginning of execution section - - // set the req.action property, cutting off the _action suffix - req.setAction(action); - - // reset skin recursion detection counter - skinDepth = 0; - - // try calling onRequest() function on object before - // calling the actual action - scriptingEngine.invoke(currentElement, - "onRequest", - EMPTY_ARGS, - ScriptingEngine.ARGS_WRAP_DEFAULT, - false); - - // reset skin recursion detection counter - skinDepth = 0; - - Object actionProcessor = req.getActionHandler() != null ? - req.getActionHandler() : action; - - // do the actual action invocation - if (req.isXmlRpc()) { - XmlRpcRequestProcessor xreqproc = new XmlRpcRequestProcessor(); - XmlRpcServerRequest xreq = xreqproc.decodeRequest(req.getServletRequest() - .getInputStream()); - Vector args = xreq.getParameters(); - args.add(0, xreq.getMethodName()); - result = scriptingEngine.invoke(currentElement, - actionProcessor, - args.toArray(), - ScriptingEngine.ARGS_WRAP_XMLRPC, - false); - res.writeXmlRpcResponse(result); - app.xmlrpcCount += 1; - } else { - scriptingEngine.invoke(currentElement, - actionProcessor, - EMPTY_ARGS, - ScriptingEngine.ARGS_WRAP_DEFAULT, - false); - } - - // try calling onResponse() function on object before - // calling the actual action - scriptingEngine.invoke(currentElement, - "onResponse", - EMPTY_ARGS, - ScriptingEngine.ARGS_WRAP_DEFAULT, - false); - - } catch (RedirectException redirect) { - // if there is a message set, save it on the user object for the next request - if (res.getRedirect() != null) - session.storeResponseMessages(res); - } - - // check if request is still valid, or if the requesting thread has stopped waiting already - if (localThread != thread) { - return; - } - commitTransaction(); - done = true; - - break; - - case XMLRPC: - case EXTERNAL: - - try { - currentElement = root; - - if (functionName.indexOf('.') > -1) { - StringTokenizer st = new StringTokenizer(functionName, "."); - int cnt = st.countTokens(); - - for (int i = 1; i < cnt; i++) { - String next = st.nextToken(); - currentElement = getChildElement(currentElement, next); - } - - if (currentElement == null) { - throw new NotFoundException("Method name \"" + - function + "\" could not be resolved."); - } - - functionName = st.nextToken(); - } - - if (reqtype == XMLRPC) { - // check XML-RPC access permissions - String proto = app.getPrototypeName(currentElement); - app.checkXmlRpcAccess(proto, functionName); - } - - // reset skin recursion detection counter - skinDepth = 0; - if (!scriptingEngine.hasFunction(currentElement, functionName, false)) { - throw new NotFoundException(missingFunctionMessage(currentElement, functionName)); - } - result = scriptingEngine.invoke(currentElement, - functionName, args, - ScriptingEngine.ARGS_WRAP_XMLRPC, - false); - // check if request is still valid, or if the requesting thread has stopped waiting already - if (localThread != thread) { - return; - } - commitTransaction(); - } catch (Exception x) { - // check if request is still valid, or if the requesting thread has stopped waiting already - if (localThread != thread) { - return; - } - abortTransaction(); - app.logError(txname + " " + error, x); - - // If the transactor thread has been killed by the invoker thread we don't have to - // bother for the error message, just quit. - if (localThread != thread) { - return; - } - - this.exception = x; - } - - done = true; - break; - - case INTERNAL: - - try { - // reset skin recursion detection counter - skinDepth = 0; - - result = scriptingEngine.invoke(thisObject, - function, - args, - ScriptingEngine.ARGS_WRAP_DEFAULT, - true); - // check if request is still valid, or if the requesting thread has stopped waiting already - if (localThread != thread) { - return; - } - commitTransaction(); - } catch (Exception x) { - // check if request is still valid, or if the requesting thread has stopped waiting already - if (localThread != thread) { - return; - } - abortTransaction(); - app.logError(txname + " " + error, x); - - // If the transactor thread has been killed by the invoker thread we don't have to - // bother for the error message, just quit. - if (localThread != thread) { - return; - } - - this.exception = x; - } - - done = true; - break; - - } // switch (reqtype) - } catch (AbortException x) { - // res.abort() just aborts the transaction and - // leaves the response untouched - // check if request is still valid, or if the requesting thread has stopped waiting already - if (localThread != thread) { - return; - } - abortTransaction(); - done = true; - } catch (ConcurrencyException x) { - res.reset(); - - if (++tries < 8) { - // try again after waiting some period - // check if request is still valid, or if the requesting thread has stopped waiting already - if (localThread != thread) { - return; - } - abortTransaction(); - - try { - // wait a bit longer with each try - int base = 800 * tries; - Thread.sleep((long) (base + (Math.random() * base * 2))); - } catch (InterruptedException interrupt) { - // we got interrrupted, create minimal error message - res.reportError(interrupt); - done = true; - // and release resources and thread - thread = null; - transactor = null; - } - } else { - // check if request is still valid, or if the requesting thread has stopped waiting already - if (localThread != thread) { - return; - } - abortTransaction(); - - // error in error action. use traditional minimal error message - res.reportError("Application too busy, please try again later"); - done = true; - } - } catch (Throwable x) { - // check if request is still valid, or if the requesting thread has stopped waiting already - if (localThread != thread) { - return; - } - abortTransaction(); - - // If the transactor thread has been killed by the invoker thread we don't have to - // bother for the error message, just quit. - if (localThread != thread) { - return; - } - - res.reset(); - - // check if we tried to process the error already, - // or if this is an XML-RPC request - if (error == null) { - if (!(x instanceof NotFoundException)) { - app.errorCount += 1; - } - - // set done to false so that the error will be processed - done = false; - error = x; - - app.logError(txname + " " + error, x); - - if (req.isXmlRpc()) { - // if it's an XML-RPC exception immediately generate error response - if (!(x instanceof Exception)) { - // we need an exception to pass to XML-RPC responder - x = new Exception(x.toString(), x); - } - res.writeXmlRpcError((Exception) x); - done = true; - } - } else { - // error in error action. use traditional minimal error message - res.reportError(error); - done = true; - } - } finally { - app.setCurrentRequestEvaluator(null); - // exit execution context - if (scriptingEngine != null) { - try { - scriptingEngine.exitContext(); - } catch (Throwable t) { - // broken rhino, just get out of here - } - } - } - } - - notifyAndWait(); - - } - } finally { - Transactor tx = Transactor.getInstance(); - if (tx != null) tx.closeConnections(); - } - } - - /** - * Called by the transactor thread when it has successfully fulfilled a request. - * @throws Exception transaction couldn't be committed - */ - synchronized void commitTransaction() throws Exception { - Thread localThread = Thread.currentThread(); - - if (localThread == thread) { - Transactor tx = Transactor.getInstance(); - if (tx != null) - tx.commit(); - } else { - throw new TimeoutException(); - } - } - - /** - * Called by the transactor thread when the request didn't terminate successfully. - */ - synchronized void abortTransaction() { - Transactor tx = Transactor.getInstance(); - if (tx != null) tx.abort(); - } - - /** - * Initialize and start the transactor thread. - */ - private synchronized void startTransactor() { - if (!app.isRunning()) { - throw new ApplicationStoppedException(); - } - - if ((thread == null) || !thread.isAlive()) { - // app.logEvent ("Starting Thread"); - thread = new Thread(app.threadgroup, this, app.getName() + "-" + (++threadId)); - thread.setContextClassLoader(app.getClassLoader()); - thread.start(); - } else { - notifyAll(); - } - } - - /** - * Tell waiting thread that we're done, then wait for next request - */ - synchronized void notifyAndWait() { - Thread localThread = Thread.currentThread(); - - // make sure there is only one thread running per instance of this class - // if localrtx != rtx, the current thread has been aborted and there's no need to notify - if (localThread != thread) { - // A new request came in while we were finishing the last one. - // Return to run() to get the work done. - Transactor tx = Transactor.getInstance(); - if (tx != null) { - tx.closeConnections(); - } - return; - } - - reqtype = NONE; - notifyAll(); - - try { - // wait for request, max 10 min - wait(1000 * 60 * 10); - } catch (InterruptedException ix) { - // we got interrrupted, releases resources and thread - thread = null; - transactor = null; - } - - // if no request arrived, release ressources and thread - if ((reqtype == NONE) && (thread == localThread)) { - // comment this in to release not just the thread, but also the scripting engine. - // currently we don't do this because of the risk of memory leaks (objects from - // framework referencing into the scripting engine) - // scriptingEngine = null; - thread = null; - transactor = null; - } - } - - /** - * Stop this request evaluator's current thread. This is called by the - * waiting thread when it times out and stops waiting, or from an outside - * thread. If currently active kill the request, otherwise just notify. - */ - synchronized boolean stopTransactor() { - Transactor t = transactor; - thread = null; - transactor = null; - boolean stopped = false; - if (t != null && t.isActive()) { - // let the scripting engine know that the - // current transaction is being aborted. - if (scriptingEngine != null) { - scriptingEngine.abort(); - } - - app.logEvent("Request timeout for thread " + t); - - reqtype = NONE; - - t.kill(); - t.abort(); - t.closeConnections(); - stopped = true; - } - notifyAll(); - return stopped; - } - - /** - * Invoke an action function for a HTTP request. The function is dispatched - * in a new thread and waits for it to finish. - * - * @param req the incoming HTTP request - * @param session the client's session - * @return the result returned by the invocation - * @throws Exception any exception thrown by the invocation - */ - public synchronized ResponseTrans invokeHttp(RequestTrans req, Session session) - throws Exception { - initObjects(req, session); - - app.activeRequests.put(req, this); - - startTransactor(); - wait(app.requestTimeout); - - if (reqtype != NONE && stopTransactor()) { - res.reset(); - res.reportError("Request timed out"); - } - - session.commit(this, app.sessionMgr); - return res; - } - - /** - * This checks if the Evaluator is already executing an equal request. - * If so, attach to it and wait for it to complete. Otherwise return null, - * so the application knows it has to run the request. - */ - public synchronized ResponseTrans attachHttpRequest(RequestTrans req) - throws Exception { - // Get a reference to the res object at the time we enter - ResponseTrans localRes = res; - - if (localRes == null || !req.equals(this.req)) { - return null; - } - - if (reqtype != NONE) { - wait(app.requestTimeout); - } - - return localRes; - } - - /* - * TODO invokeXmlRpc(), invokeExternal() and invokeInternal() are basically the same - * and should be unified - */ - - /** - * Invoke a function for an XML-RPC request. The function is dispatched in a new thread - * and waits for it to finish. - * - * @param functionName the name of the function to invoke - * @param args the arguments - * @return the result returned by the invocation - * @throws Exception any exception thrown by the invocation - */ - public synchronized Object invokeXmlRpc(String functionName, Object[] args) - throws Exception { - initObjects(functionName, XMLRPC, RequestTrans.XMLRPC); - this.function = functionName; - this.args = args; - - startTransactor(); - wait(app.requestTimeout); - - if (reqtype != NONE && stopTransactor()) { - exception = new RuntimeException("Request timed out"); - } - - // reset res for garbage collection (res.data may hold reference to evaluator) - res = null; - - if (exception != null) { - throw (exception); - } - - return result; - } - - - - /** - * Invoke a function for an external request. The function is dispatched - * in a new thread and waits for it to finish. - * - * @param functionName the name of the function to invoke - * @param args the arguments - * @return the result returned by the invocation - * @throws Exception any exception thrown by the invocation - */ - public synchronized Object invokeExternal(String functionName, Object[] args) - throws Exception { - initObjects(functionName, EXTERNAL, RequestTrans.EXTERNAL); - this.function = functionName; - this.args = args; - - startTransactor(); - wait(); - - if (reqtype != NONE && stopTransactor()) { - exception = new RuntimeException("Request timed out"); - } - - // reset res for garbage collection (res.data may hold reference to evaluator) - res = null; - - if (exception != null) { - throw (exception); - } - - return result; - } - - /** - * Invoke a function internally and directly, using the thread we're running on. - * - * @param obj the object to invoke the function on - * @param function the function or name of the function to invoke - * @param args the arguments - * @return the result returned by the invocation - * @throws Exception any exception thrown by the invocation - */ - public Object invokeDirectFunction(Object obj, Object function, Object[] args) - throws Exception { - return scriptingEngine.invoke(obj, function, args, - ScriptingEngine.ARGS_WRAP_DEFAULT, true); - } - - /** - * Invoke a function internally. The function is dispatched in a new thread - * and waits for it to finish. - * - * @param object the object to invoke the function on - * @param function the function or name of the function to invoke - * @param args the arguments - * @return the result returned by the invocation - * @throws Exception any exception thrown by the invocation - */ - public synchronized Object invokeInternal(Object object, Object function, - Object[] args) - throws Exception { - // give internal call more time (15 minutes) to complete - return invokeInternal(object, function, args, 60000L * 15); - } - - /** - * Invoke a function internally. The function is dispatched in a new thread - * and waits for it to finish. - * - * @param object the object to invoke the function on - * @param function the function or name of the function to invoke - * @param args the arguments - * @param timeout the time in milliseconds to wait for the function to return, or - * -1 to wait indefinitely - * @return the result returned by the invocation - * @throws Exception any exception thrown by the invocation - */ - public synchronized Object invokeInternal(Object object, Object function, - Object[] args, long timeout) - throws Exception { - initObjects(function, INTERNAL, RequestTrans.INTERNAL); - thisObject = object; - this.function = function; - this.args = args; - - startTransactor(); - if (timeout < 0) - wait(); - else - wait(timeout); - - if (reqtype != NONE && stopTransactor()) { - exception = new RuntimeException("Request timed out"); - } - - // reset res for garbage collection (res.data may hold reference to evaluator) - res = null; - - if (exception != null) { - throw (exception); - } - - return result; - } - - - /** - * Init this evaluator's objects from a RequestTrans for a HTTP request - * - * @param req - * @param session - */ - private synchronized void initObjects(RequestTrans req, Session session) { - this.req = req; - this.reqtype = HTTP; - this.session = session; - res = new ResponseTrans(app, req); - result = null; - exception = null; - } - - /** - * Init this evaluator's objects for an internal, external or XML-RPC type - * request. - * - * @param function the function name or object - * @param reqtype the request type - * @param reqtypeName the request type name - */ - private synchronized void initObjects(Object function, int reqtype, String reqtypeName) { - this.reqtype = reqtype; - String functionName = function instanceof String ? - (String) function : ""; - req = new RequestTrans(reqtypeName, functionName); - session = new Session(functionName, app); - res = new ResponseTrans(app, req); - result = null; - exception = null; - } - - /** - * Initialize the globals in the scripting engine for the current request. - * - * @param root - * @throws ScriptingException - */ - private synchronized void initGlobals(Object root, Object requestPath) - throws ScriptingException { - HashMap globals = new HashMap(); - - globals.put("root", root); - globals.put("session", new SessionBean(session)); - globals.put("req", new RequestBean(req)); - globals.put("res", new ResponseBean(res)); - globals.put("app", new ApplicationBean(app)); - globals.put("path", requestPath); - - // enter execution context - scriptingEngine.setGlobals(globals); - } - - /** - * Get the child element with the given name from the given object. - * - * @param obj - * @param name - * @return - * @throws ScriptingException - */ - private Object getChildElement(Object obj, String name) throws ScriptingException { - if (scriptingEngine.hasFunction(obj, "getChildElement", false)) { - return scriptingEngine.invoke(obj, "getChildElement", new Object[] {name}, - ScriptingEngine.ARGS_WRAP_DEFAULT, false); - } - - if (obj instanceof IPathElement) { - return ((IPathElement) obj).getChildElement(name); - } - - return null; - } - - /** - * Null out some fields, mostly for the sake of garbage collection. - */ - synchronized void recycle() { - res = null; - req = null; - session = null; - function = null; - args = null; - result = null; - exception = null; - } - - /** - * Check if an action with a given name is defined for a scripted object. If it is, - * return the action's function name. Otherwise, return null. - */ - public String getAction(Object obj, String action, RequestTrans req) { - if (obj == null) - return null; - - if (action == null) - action = "main"; - - StringBuffer buffer = new StringBuffer(action).append("_action"); - // record length so we can check without method - // afterwards for GET, POST, HEAD requests - int length = buffer.length(); - - if (req.checkXmlRpc()) { - // append _methodname - buffer.append("_xmlrpc"); - if (scriptingEngine.hasFunction(obj, buffer.toString(), false)) { - // handle as XML-RPC request - req.setMethod(RequestTrans.XMLRPC); - return buffer.toString(); - } - // cut off method in case it has been appended - buffer.setLength(length); - } - - String method = req.getMethod(); - // append HTTP method to action name - if (method != null) { - // append _methodname - buffer.append('_').append(method.toLowerCase()); - if (scriptingEngine.hasFunction(obj, buffer.toString(), false)) - return buffer.toString(); - - // cut off method in case it has been appended - buffer.setLength(length); - } - - // if no method specified or "ordinary" request try action without method - if (method == null || "GET".equalsIgnoreCase(method) || - "POST".equalsIgnoreCase(method) || - "HEAD".equalsIgnoreCase(method)) { - if (scriptingEngine.hasFunction(obj, buffer.toString(), false)) - return buffer.toString(); - } - - return null; - } - - /** - * Returns this evaluator's scripting engine - */ - public ScriptingEngine getScriptingEngine() { - if (scriptingEngine == null) { - initScriptingEngine(); - } - return scriptingEngine; - } - - /** - * Get the request object for the current request. - * - * @return the request object - */ - public synchronized RequestTrans getRequest() { - return req; - } - - /** - * Get the response object for the current request. - * - * @return the response object - */ - public synchronized ResponseTrans getResponse() { - return res; - } - - /** - * Get the current transactor thread - * - * @return the current transactor thread - */ - public synchronized Thread getThread() { - return thread; - } - - /** - * Return the current session - * - * @return the session for the current request - */ - public synchronized Session getSession() { - return session; - } - - private String missingFunctionMessage(Object obj, String funcName) { - if (obj == null) - return "Function " + funcName + " not defined in global scope"; - else - return "Function " + funcName + " not defined for " + obj; - } -} diff --git a/src/main/java/helma/framework/core/RequestPath.java b/src/main/java/helma/framework/core/RequestPath.java deleted file mode 100644 index da49ee87..00000000 --- a/src/main/java/helma/framework/core/RequestPath.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.core; - -import java.util.*; -import java.io.UnsupportedEncodingException; - -import helma.util.UrlEncoded; - -/** - * Represents a URI request path that has been resolved to an object path. - * Offers methods to access objects in the path by index and prototype names, - * and to render the path as URI again. - */ -public class RequestPath { - - Application app; - - List objects; - List ids; - - Map primaryProtos; - Map secondaryProtos; - - /** - * Creates a new RequestPath object. - * - * @param app the application we're running in - */ - public RequestPath(Application app) { - this.app = app; - objects = new ArrayList(); - ids = new ArrayList(); - primaryProtos = new HashMap(); - secondaryProtos = new HashMap(); - } - - /** - * Adds an item to the end of the path. - * - * @param id the item id representing the path in the URL - * @param obj the object to which the id resolves - */ - public void add(String id, Object obj) { - ids.add(id); - objects.add(obj); - - Prototype proto = app.getPrototype(obj); - - if (proto != null) { - primaryProtos.put(proto.getName(), obj); - primaryProtos.put(proto.getLowerCaseName(), obj); - proto.registerParents(secondaryProtos, obj); - } - } - - /** - * Returns the number of objects in the request path. - */ - public int size() { - return objects.size(); - } - - /** - * Gets an object in the path by index. - * - * @param idx the index of the object in the request path - */ - public Object get(int idx) { - if (idx < 0 || idx >= objects.size()) { - return null; - } - - return objects.get(idx); - } - - /** - * Gets an object in the path by prototype name. - * - * @param typeName the prototype name of the object in the request path - */ - public Object getByPrototypeName(String typeName) { - // search primary prototypes first - Object obj = primaryProtos.get(typeName); - - if (obj != null) { - return obj; - } - - // if that fails, consult secondary prototype map - return secondaryProtos.get(typeName); - } - - /** - * Returns the string representation of this path usable for links. - */ - public String href(String action) throws UnsupportedEncodingException { - StringBuffer buffer = new StringBuffer(app.getBaseURI()); - - int start = 1; - String hrefRootPrototype = app.getHrefRootPrototype(); - - if (hrefRootPrototype != null) { - Object rootObject = getByPrototypeName(hrefRootPrototype); - - if (rootObject != null) { - start = objects.indexOf(rootObject) + 1; - } - } - - for (int i=start; iSession object and - * exposes it to the scripting framework. - */ -public class SessionBean implements Serializable { - private static final long serialVersionUID = 7500231949937123265L; - - // the wrapped session object - Session session; - - /** - * Creates a new SessionBean around a Session object. - * - * @param session ... - */ - public SessionBean(Session session) { - this.session = session; - } - - /** - * - * - * @return ... - */ - public String toString() { - return session.toString(); - } - - /** - * Attempts to log in a user with the given username/password credentials. - * If username and password match, the user node is associated with the session - * and bound to the session.user property. - * - * @param username the username - * @param password the password - * - * @return true if the user exists and the password matches the user's password property. - */ - public boolean login(String username, String password) { - return session.login(username, password); - } - - /** - * Directly associates the session with a user object without requiring - * a username/password pair. This is for applications that use their own - * authentication mechanism. - * - * @param userNode the HopObject node representing the user. - */ - public void login(INode userNode) { - session.login(userNode); - } - - /** - * Disassociate this session from any user object it may have been associated with. - */ - public void logout() { - session.logout(); - } - - /** - * Touching the session marks it as active, avoiding session timeout. - * Usually, sessions are touched when the user associated with it sends - * a request. This method may be used to artificially keep a session alive. - */ - public void touch() { - session.touch(); - } - - /** - * Returns the time this session was last touched. - * - * @return ... - */ - public Date lastActive() { - return new Date(session.lastTouched()); - } - - /** - * Returns the time this session was created. - * - * @return ... - */ - public Date onSince() { - return new Date(session.onSince()); - } - - // property-related methods: - - /** - * Get the cache/data node for this session. This object may be used - * to store transient per-session data. It is reflected to the scripting - * environment as session.data. - */ - public INode getData() { - return session.getCacheNode(); - } - - /** - * Gets the user object for this session. This method returns null unless - * one of the session.login methods was previously invoked. - * - * @return ... - */ - public INode getUser() { - return session.getUserNode(); - } - - /** - * Returns the unique identifier for a session object (session cookie). - * - * @return ... - */ - public String get_id() { - return session.getSessionId(); - } - - /** - * Returns the unique identifier for a session object (session cookie). - * - * @return ... - */ - public String getCookie() { - return session.getSessionId(); - } - - /** - * Returns the time this session was last touched. - * - * @return ... - */ - public Date getLastActive() { - return new Date(session.lastTouched()); - } - - /** - * Returns a date object representing the time a user's session was started. - * - * @return ... - */ - public Date getOnSince() { - return new Date(session.onSince()); - } - - /** - * Gets the date at which the session was created or a login or - * logout was performed the last time. - * - * @return ... - */ - public Date getLastModified() { - return new Date(session.lastModified()); - } - - /** - * Sets the date at which the session was created or a login or - * logout was performed the last time. - * - * @param date ... - */ - public void setLastModified(Date date) { - if (date != null) { - session.setLastModified(date.getTime()); - } - } - - /** - * Return the message that is to be displayed upon the next - * request within this session. - * - * @return the message, or null if none was set. - */ - public String getMessage() { - return session.message; - } - - /** - * Set a message to be displayed to this session's user. This - * can be used to save a message over to the next request when - * the current request can't be used to display a user visible - * message. - * - * @param msg - */ - public void setMessage(String msg) { - session.message = msg; - } - - /** - * Get an upload status for the current user session. - * @param uploadId the upload id - * @return the upload status - */ - public UploadStatus getUploadStatus(String uploadId) { - return session.getUpload(uploadId); - } - -} diff --git a/src/main/java/helma/framework/core/SessionManager.java b/src/main/java/helma/framework/core/SessionManager.java deleted file mode 100644 index 3f7a2893..00000000 --- a/src/main/java/helma/framework/core/SessionManager.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ -package helma.framework.core; - -import helma.objectmodel.INode; -import helma.objectmodel.db.NodeHandle; -import helma.objectmodel.db.Transactor; -import helma.scripting.ScriptingEngine; - -import java.util.*; -import java.io.*; - -public class SessionManager { - - protected Hashtable sessions; - - protected Application app; - - public SessionManager() { - sessions = new Hashtable(); - } - - public void init(Application app) { - this.app = app; - } - - public void shutdown() { - sessions.clear(); - } - - public Session createSession(String sessionId) { - Session session = getSession(sessionId); - if (session == null) { - session = new Session(sessionId, app); - } - return session; - } - - public Session getSession(String sessionId) { - if (sessionId == null) { - return null; - } - return (Session) sessions.get(sessionId); - } - - public void registerSession(Session session) { - sessions.put(session.getSessionId(), session); - } - - /** - * Return the whole session map. We return a clone of the table to prevent - * actual changes from the table itself, which is managed by the application. - * It is safe and allowed to manipulate the session objects contained in the table, though. - */ - public Map getSessions() { - return (Map) sessions.clone(); - } - - /** - * Returns the number of currenty active sessions. - */ - public int countSessions() { - return sessions.size(); - } - - /** - * Remove the session from the sessions-table and logout the user. - */ - public void discardSession(Session session) { - session.logout(); - sessions.remove(session.getSessionId()); - } - - - /** - * Return an array of SessionBean objects currently associated with a given - * Helma user. - */ - public List getSessionsForUsername(String username) { - ArrayList list = new ArrayList(); - - if (username == null) { - return list; - } - - Enumeration e = sessions.elements(); - while (e.hasMoreElements()) { - Session s = (Session) e.nextElement(); - - if (s != null && username.equals(s.getUID())) { - // append to list if session is logged in and fits the given username - list.add(new SessionBean(s)); - } - } - - return list; - } - - /** - * Return a list of Helma nodes (HopObjects - the database object representing the user, - * not the session object) representing currently logged in users. - */ - public List getActiveUsers() { - ArrayList list = new ArrayList(); - - for (Enumeration e = sessions.elements(); e.hasMoreElements();) { - Session s = (Session) e.nextElement(); - - if (s != null && s.isLoggedIn()) { - // returns a session if it is logged in and has not been - // returned before (so for each logged-in user is only added once) - INode node = s.getUserNode(); - - // we check again because user may have been logged out between the first check - if (node != null && !list.contains(node)) { - list.add(node); - } - } - } - - return list; - } - - - /** - * Dump session state to a file. - * - * @param f the file to write session into, or null to use the default sesssion store. - */ - public void storeSessionData(File f, ScriptingEngine engine) { - if (f == null) { - f = new File(app.dbDir, "sessions"); - } - - try { - OutputStream ostream = new BufferedOutputStream(new FileOutputStream(f)); - ObjectOutputStream p = new ObjectOutputStream(ostream); - - synchronized (sessions) { - p.writeInt(sessions.size()); - - for (Enumeration e = sessions.elements(); e.hasMoreElements();) { - try { - engine.serialize(e.nextElement(), p); - // p.writeObject(e.nextElement()); - } catch (NotSerializableException nsx) { - // not serializable, skip this session - app.logError("Error serializing session.", nsx); - } - } - } - - p.flush(); - ostream.close(); - app.logEvent("stored " + sessions.size() + " sessions in file"); - } catch (Exception e) { - app.logError("error storing session data.", e); - } - } - - /** - * loads the serialized session table from a given file or from dbdir/sessions - */ - public void loadSessionData(File f, ScriptingEngine engine) { - if (f == null) { - f = new File(app.dbDir, "sessions"); - } - - // compute session timeout value - int sessionTimeout = 30; - - try { - sessionTimeout = Math.max(0, - Integer.parseInt(app.getProperty("sessionTimeout", - "30"))); - } catch (Exception ignore) { - System.out.println(ignore.toString()); - } - - long now = System.currentTimeMillis(); - Transactor tx = Transactor.getInstance(app.getNodeManager()); - - try { - tx.begin("sessionloader"); - // load the stored data: - InputStream istream = new BufferedInputStream(new FileInputStream(f)); - ObjectInputStream p = new ObjectInputStream(istream); - int size = p.readInt(); - int ct = 0; - Hashtable newSessions = new Hashtable(); - - while (ct < size) { - Session session = (Session) engine.deserialize(p); - - if ((now - session.lastTouched()) < (sessionTimeout * 60000)) { - session.setApp(app); - newSessions.put(session.getSessionId(), session); - } - - ct++; - } - - p.close(); - istream.close(); - sessions = newSessions; - app.logEvent("loaded " + newSessions.size() + " sessions from file"); - tx.commit(); - } catch (FileNotFoundException fnf) { - // suppress error message if session file doesn't exist - tx.abort(); - } catch (Exception e) { - app.logError("error loading session data.", e); - tx.abort(); - } finally { - tx.closeConnections(); - } - - } - - /** - * Purge sessions that have not been used for a certain amount of time. - * This is called by run(). - * - * @param lastSessionCleanup the last time sessions were purged - * @return the updated lastSessionCleanup value - */ - protected long cleanupSessions(long lastSessionCleanup) { - - long now = System.currentTimeMillis(); - long sessionCleanupInterval = 60000; - - // check if we should clean up user sessions - if ((now - lastSessionCleanup) > sessionCleanupInterval) { - - // get session timeout - int sessionTimeout = 30; - - try { - sessionTimeout = Math.max(0, - Integer.parseInt(app.getProperty("sessionTimeout", "30"))); - } catch (NumberFormatException nfe) { - app.logEvent("Invalid sessionTimeout setting: " + app.getProperty("sessionTimeout")); - } - - RequestEvaluator thisEvaluator = null; - - try { - - thisEvaluator = app.getEvaluator(); - - Session[] sessionArray = (Session[]) sessions.values().toArray(new Session[0]); - - for (int i = 0; i < sessionArray.length; i++) { - Session session = sessionArray[i]; - - session.pruneUploads(); - if ((now - session.lastTouched()) > (sessionTimeout * 60000)) { - NodeHandle userhandle = session.userHandle; - - if (userhandle != null) { - try { - Object[] param = {session.getSessionId()}; - - thisEvaluator.invokeInternal(userhandle, "onLogout", param); - } catch (Exception x) { - // errors should already be logged by requestevaluator, but you never know - app.logError("Error in onLogout", x); - } - } - - discardSession(session); - } - } - } catch (Exception cx) { - app.logError("Error cleaning up sessions", cx); - } finally { - if (thisEvaluator != null) { - app.releaseEvaluator(thisEvaluator); - } - } - return now; - } else { - return lastSessionCleanup; - } - } - - -} diff --git a/src/main/java/helma/framework/core/Skin.java b/src/main/java/helma/framework/core/Skin.java deleted file mode 100644 index 3393d304..00000000 --- a/src/main/java/helma/framework/core/Skin.java +++ /dev/null @@ -1,1201 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.core; - -import helma.framework.*; -import helma.framework.repository.Resource; -import helma.objectmodel.ConcurrencyException; -import helma.util.*; -import helma.scripting.ScriptingEngine; - -import java.util.*; -import java.io.UnsupportedEncodingException; -import java.io.Reader; -import java.io.InputStreamReader; -import java.io.IOException; - -/** - * This represents a Helma skin, i.e. a template created from containing Macro tags - * that will be dynamically evaluated.. It uses the request path array - * from the RequestEvaluator object to resolve Macro handlers by type name. - */ -public final class Skin { - - private Macro[] macros; - private Application app; - private char[] source; - private int offset, length; // start and end index of skin content - private HashSet sandbox; - private HashMap subskins; - private Skin parentSkin = this; - private String extendz = null; - private boolean hasContent = false; - - static private final int PARSE_MACRONAME = 0; - static private final int PARSE_PARAM = 1; - static private final int PARSE_DONE = 2; - - static private final int ENCODE_NONE = 0; - static private final int ENCODE_HTML = 1; - static private final int ENCODE_XML = 2; - static private final int ENCODE_FORM = 3; - static private final int ENCODE_URL = 4; - static private final int ENCODE_ALL = 5; - - static private final int HANDLER_RESPONSE = 0; - static private final int HANDLER_REQUEST = 1; - static private final int HANDLER_SESSION = 2; - static private final int HANDLER_PARAM = 3; - static private final int HANDLER_GLOBAL = 4; - static private final int HANDLER_THIS = 5; - static private final int HANDLER_OTHER = 6; - - static private final int FAIL_DEFAULT = 0; - static private final int FAIL_SILENT = 1; - static private final int FAIL_VERBOSE = 2; - - /** - * Create a skin without any restrictions on which macros are allowed to be called from it - */ - public Skin(String content, Application app) { - this.app = app; - this.sandbox = null; - this.source = content.toCharArray(); - this.offset = 0; - this.length = source.length; - parse(); - } - - /** - * Create a skin with a sandbox which contains the names of macros allowed to be called - */ - public Skin(String content, Application app, HashSet sandbox) { - this.app = app; - this.sandbox = sandbox; - this.source = content.toCharArray(); - this.offset = 0; - length = source.length; - parse(); - } - - /** - * Create a skin without any restrictions on the macros from a char array. - */ - public Skin(char[] content, int length, Application app) { - this.app = app; - this.sandbox = null; - this.source = content; - this.offset = 0; - this.length = length; - parse(); - } - - /** - * Subskin constructor. - */ - private Skin(Skin parentSkin, Macro anchorMacro) { - this.parentSkin = parentSkin; - this.app = parentSkin.app; - this.sandbox = parentSkin.sandbox; - this.source = parentSkin.source; - this.offset = anchorMacro.end; - this.length = parentSkin.length; - parentSkin.addSubskin(anchorMacro.name, this); - parse(); - } - - public static Skin getSkin(Resource res, Application app) throws IOException { - String encoding = app.getProperty("skinCharset"); - Reader reader; - if (encoding == null) { - reader = new InputStreamReader(res.getInputStream()); - } else { - reader = new InputStreamReader(res.getInputStream(), encoding); - } - - int length = (int) res.getLength(); - char[] characterBuffer = new char[length]; - int read = 0; - try { - while (read < length) { - int r = reader.read(characterBuffer, read, length - read); - if (r == -1) - break; - read += r; - } - } finally { - reader.close(); - } - return new Skin(characterBuffer, read, app); - } - - /** - * Parse a skin object from source text - */ - private void parse() { - ArrayList partBuffer = new ArrayList(); - - boolean escape = false; - for (int i = offset; i < (length - 1); i++) { - if (source[i] == '<' && source[i + 1] == '%' && !escape) { - // found macro start tag - Macro macro = new Macro(i, 2); - if (macro.isSubskinMacro) { - new Skin(parentSkin, macro); - length = i; - break; - } else { - if (!macro.isCommentMacro) { - hasContent = true; - } - partBuffer.add(macro); - } - i = macro.end - 1; - } else { - if (!hasContent && !Character.isWhitespace(source[i])){ - hasContent = true; - } - escape = source[i] == '\\' && !escape; - } - } - - macros = new Macro[partBuffer.size()]; - partBuffer.toArray(macros); - } - - private void addSubskin(String name, Skin subskin) { - if (subskins == null) { - subskins = new HashMap(); - } - subskins.put(name, subskin); - } - - /** - * Return the list of macros found by the parser - * @return the list of macros - */ - public Macro[] getMacros() { - return macros; - } - - /** - * Check if this skin has a main skin, as opposed to consisting just of subskins - * @return true if this skin contains a main skin - */ - public boolean hasMainskin() { - return hasContent; - } - - /** - * Check if this skin contains a subskin with the given name - * @param name a subskin name - * @return true if the given subskin exists - */ - public boolean hasSubskin(String name) { - return subskins != null && subskins.containsKey(name); - } - - /** - * Get a subskin by name - * @param name the subskin name - * @return the subskin - */ - public Skin getSubskin(String name) { - return subskins == null ? null : (Skin) subskins.get(name); - } - - /** - * Return an array of subskin names defined in this skin - * @return a string array containing this skin's substrings - */ - public String[] getSubskinNames() { - return subskins == null ? - new String[0] : - (String[]) subskins.keySet().toArray(new String[0]); - } - - public String getExtends() { - return extendz; - } - - /** - * Get the raw source text this skin was parsed from - */ - public String getSource() { - return new String(source, offset, length - offset); - } - - /** - * Render this skin and return it as string - */ - public String renderAsString(RequestEvaluator reval, Object thisObject, Object paramObject) - throws RedirectException, UnsupportedEncodingException { - String result = ""; - ResponseTrans res = reval.getResponse(); - res.pushBuffer(null); - try { - render(reval, thisObject, paramObject); - } finally { - result = res.popString(); - } - return result; - } - - - /** - * Render this skin - */ - public void render(RequestEvaluator reval, Object thisObject, Object paramObject) - throws RedirectException, UnsupportedEncodingException { - // check for endless skin recursion - if (++reval.skinDepth > 50) { - throw new RuntimeException("Recursive skin invocation suspected"); - } - - ResponseTrans res = reval.getResponse(); - - if (macros == null) { - res.write(source, offset, length - offset); - reval.skinDepth--; - return; - } - - // register param object, remember previous one to reset afterwards - Map handlers = res.getMacroHandlers(); - Object previousParam = handlers.put("param", paramObject); - Skin previousSkin = res.switchActiveSkin(parentSkin); - - try { - int written = offset; - Map handlerCache = null; - - if (macros.length > 3) { - handlerCache = new HashMap(); - } - RenderContext cx = new RenderContext(reval, thisObject, handlerCache); - - for (int i = 0; i < macros.length; i++) { - if (macros[i].start > written) { - res.write(source, written, macros[i].start - written); - } - - macros[i].render(cx); - written = macros[i].end; - } - - if (written < length) { - res.write(source, written, length - written); - } - } finally { - reval.skinDepth--; - res.switchActiveSkin(previousSkin); - if (previousParam == null) { - handlers.remove("param"); - } else { - handlers.put("param", previousParam); - } - } - } - - /** - * Check if a certain macro is present in this skin. The macro name is in handler.name notation - */ - public boolean containsMacro(String macroname) { - for (int i = 0; i < macros.length; i++) { - if (macros[i] instanceof Macro) { - Macro m = macros[i]; - - if (macroname.equals(m.name)) { - return true; - } - } - } - - return false; - } - - /** - * Adds a macro to the list of allowed macros. The macro is in handler.name notation. - */ - public void allowMacro(String macroname) { - if (sandbox == null) { - sandbox = new HashSet(); - } - - sandbox.add(macroname); - } - - private Object processParameter(Object value, RenderContext cx) - throws Exception { - if (value instanceof Macro) { - return ((Macro) value).invokeAsParameter(cx); - } else { - return value; - } - } - - public class Macro { - public final int start, end; - String name; - String[] path; - int handlerType = HANDLER_OTHER; - int encoding = ENCODE_NONE; - boolean hasNestedMacros = false; - - // default render parameters - may be overridden if macro changes - // param.prefix/suffix/default - StandardParams standardParams = new StandardParams(); - Map namedParams = null; - List positionalParams = null; - // filters defined via <% foo | bar %> - Macro filterChain; - - // comment macros are silently dropped during rendering - boolean isCommentMacro = false; - // subskin macros delimits the beginning of a new subskin - boolean isSubskinMacro = false; - - /** - * Create and parse a new macro. - * @param start the start of the macro within the skin source - * @param macroOffset offset of the macro content from the start index - */ - Macro(int start, int macroOffset) { - this.start = start; - - int i = parse(macroOffset, false); - - if (isSubskinMacro) { - if (i + 1 < length && source[i] == '\r' && source[i + 1] == '\n') - end = Math.min(length, i + 2); - else if (i < length && (source[i] == '\r' || source[i] == '\n')) - end = Math.min(length, i + 1); - else - end = Math.min(length, i); - } else { - end = Math.min(length, i); - } - - path = StringUtils.split(name, "."); - if (path.length <= 1) { - handlerType = HANDLER_GLOBAL; - } else { - String handlerName = path[0]; - if ("this".equalsIgnoreCase(handlerName)) { - handlerType = HANDLER_THIS; - } else if ("response".equalsIgnoreCase(handlerName)) { - handlerType = HANDLER_RESPONSE; - } else if ("request".equalsIgnoreCase(handlerName)) { - handlerType = HANDLER_REQUEST; - } else if ("session".equalsIgnoreCase(handlerName)) { - handlerType = HANDLER_SESSION; - } else if ("param".equalsIgnoreCase(handlerName)) { - handlerType = HANDLER_PARAM; - } - } - - if (".extends".equals(name)) { - if (parentSkin != Skin.this) { - throw new RuntimeException("Found .extends in subskin"); - } - if (positionalParams == null || positionalParams.size() < 1 - || !(positionalParams.get(0) instanceof String)) { - throw new RuntimeException(".extends requires an unnamed string parameter"); - } - extendz = (String) positionalParams.get(0); - isCommentMacro = true; // don't render - } - } - - private int parse(int macroOffset, boolean lenient) { - int state = PARSE_MACRONAME; - boolean escape = false; - char quotechar = '\u0000'; - String lastParamName = null; - StringBuffer b = new StringBuffer(); - int i; - - loop: - for (i = start + macroOffset; i < length - 1; i++) { - - switch (source[i]) { - - case '<': - - if (state == PARSE_PARAM && quotechar == '\u0000' - && b.length() == 0 && source[i + 1] == '%') { - Macro macro = new Macro(i, 2); - addParameter(lastParamName, macro); - lastParamName = null; - b.setLength(0); - i = macro.end - 1; - } else { - b.append(source[i]); - escape = false; - } - break; - - case '%': - - if ((state != PARSE_PARAM || quotechar == '\u0000' || lenient) - && source[i + 1] == '>') { - state = PARSE_DONE; - break loop; - } - b.append(source[i]); - escape = false; - break; - - case '/': - - b.append(source[i]); - escape = false; - - if (state == PARSE_MACRONAME && "//".equals(b.toString())) { - isCommentMacro = true; - // just continue parsing the macro as this is the only way - // to correctly catch embedded macros - see bug 588 - } - break; - - case '#': - - if (state == PARSE_MACRONAME && b.length() == 0) { - // this is a subskin/skinlet - isSubskinMacro = true; - break; - } - b.append(source[i]); - escape = false; - break; - - case '|': - - if (!escape && quotechar == '\u0000') { - filterChain = new Macro(i, 1); - i = filterChain.end - 2; - lastParamName = null; - b.setLength(0); - state = PARSE_DONE; - break loop; - } - b.append(source[i]); - escape = false; - break; - - case '\\': - - if (escape) { - b.append(source[i]); - } - - escape = !escape; - - break; - - case '"': - case '\'': - - if (!escape && state == PARSE_PARAM) { - if (quotechar == source[i]) { - if (source[i + 1] != '%' && !Character.isWhitespace(source[i + 1]) && !lenient) { - // closing quotes and next character is not space or end tag - - // switch to lenient mode - reset(); - return parse(macroOffset, true); - } - // add parameter - addParameter(lastParamName, b.toString()); - lastParamName = null; - b.setLength(0); - quotechar = '\u0000'; - } else if (quotechar == '\u0000') { - quotechar = source[i]; - b.setLength(0); - } else { - b.append(source[i]); - } - } else { - b.append(source[i]); - } - - escape = false; - - break; - - case ' ': - case '\t': - case '\n': - case '\r': - case '\f': - - if (state == PARSE_MACRONAME && b.length() > 0) { - name = b.toString().trim(); - b.setLength(0); - state = PARSE_PARAM; - } else if (state == PARSE_PARAM) { - if (quotechar == '\u0000') { - if (b.length() > 0) { - // add parameter - addParameter(lastParamName, b.toString()); - lastParamName = null; - b.setLength(0); - } - } else { - b.append(source[i]); - escape = false; - } - } - - break; - - case '=': - - if (!escape && quotechar == '\u0000' && state == PARSE_PARAM && lastParamName == null) { - lastParamName = b.toString().trim(); - b.setLength(0); - } else { - b.append(source[i]); - escape = false; - } - - break; - - default: - b.append(source[i]); - escape = false; - } - - if (i == length - 2 && !lenient && - (state != PARSE_DONE ||quotechar != '\u0000')) { - // macro tag is not properly terminated, switch to lenient mode - reset(); - return parse(macroOffset, true); - } - } - - if (b.length() > 0) { - if (name == null) { - name = b.toString().trim(); - } else { - addParameter(lastParamName, b.toString()); - } - } - - if (state != PARSE_DONE) { - app.logError("Unterminated Macro Tag: " +this); - } - - return i + 2; - } - - private void reset() { - filterChain = null; - name = null; - standardParams = new StandardParams(); - namedParams = null; - positionalParams = null; - } - - private void addParameter(String name, Object value) { - if (!(value instanceof String)) { - hasNestedMacros = true; - } - if (name == null) { - // take shortcut for positional parameters - if (positionalParams == null) { - positionalParams = new ArrayList(); - } - positionalParams.add(value); - return; - } - // check if this is parameter is relevant to us - if ("prefix".equals(name)) { - standardParams.prefix = value; - } else if ("suffix".equals(name)) { - standardParams.suffix = value; - } else if ("encoding".equals(name)) { - if ("html".equals(value)) { - encoding = ENCODE_HTML; - } else if ("xml".equals(value)) { - encoding = ENCODE_XML; - } else if ("form".equals(value)) { - encoding = ENCODE_FORM; - } else if ("url".equals(value)) { - encoding = ENCODE_URL; - } else if ("all".equals(value)) { - encoding = ENCODE_ALL; - } else { - app.logEvent("Unrecognized encoding in skin macro: " + value); - } - } else if ("default".equals(name)) { - standardParams.defaultValue = value; - } else if ("failmode".equals(name)) { - standardParams.setFailMode(value); - } - - // Add parameter to parameter map - if (namedParams == null) { - namedParams = new HashMap(); - } - namedParams.put(name, value); - } - - private Object invokeAsMacro(RenderContext cx, StandardParams stdParams, boolean asObject) - throws Exception { - - // immediately return for comment macros - if (isCommentMacro || name == null) { - return null; - } - - if ((sandbox != null) && !sandbox.contains(name)) { - throw new MacroException("Macro not allowed in sandbox: " + name); - } - - Object handler = null; - Object value = null; - ScriptingEngine engine = cx.reval.scriptingEngine; - - if (handlerType != HANDLER_GLOBAL) { - handler = cx.resolveHandler(path[0], handlerType); - handler = resolvePath(handler, cx.reval); - } - - if (handlerType == HANDLER_GLOBAL || handler != null) { - // check if a function called name_macro is defined. - // if so, the macro evaluates to the function. Otherwise, - // a property/field with the name is used, if defined. - String propName = path[path.length - 1]; - String funcName = resolveFunctionName(handler, propName + "_macro", engine); - - // remember length of response buffer before calling macro - StringBuffer buffer = cx.reval.getResponse().getBuffer(); - int bufLength = buffer.length(); - - if (funcName != null) { - - Object[] arguments = prepareArguments(0, cx); - // get reference to rendered named params for after invocation - Map params = (Map) arguments[0]; - value = cx.reval.invokeDirectFunction(handler, - funcName, - arguments); - - // update StandardParams to override defaults in case the macro changed anything - if (stdParams != null) stdParams.readFrom(params); - - // if macro has a filter chain and didn't return anything, use output - // as filter argument. - if (asObject && value == null && buffer.length() > bufLength) { - value = buffer.substring(bufLength); - buffer.setLength(bufLength); - } - - return filter(value, cx); - } else { - if (handlerType == HANDLER_RESPONSE) { - // some special handling for response handler - if ("message".equals(propName)) - value = cx.reval.getResponse().getMessage(); - else if ("error".equals(propName)) - value = cx.reval.getResponse().getErrorMessage(); - if (value != null) - return filter(value, cx); - } - // display error message unless onUnhandledMacro is defined or silent failmode is on - if (!engine.hasProperty(handler, propName)) { - if (engine.hasFunction(handler, "onUnhandledMacro", false)) { - Object[] arguments = prepareArguments(1, cx); - arguments[0] = propName; - value = cx.reval.invokeDirectFunction(handler, "onUnhandledMacro", arguments); - // if macro has a filter chain and didn't return anything, use output - // as filter argument. - if (asObject && value == null && buffer.length() > bufLength) { - value = buffer.substring(bufLength); - buffer.setLength(bufLength); - } - } else if (standardParams.verboseFailmode(handler, engine)) { - throw new MacroException("Unhandled macro: " + name); - } - } else { - value = engine.getProperty(handler, propName); - } - return filter(value, cx); - } - } else if (standardParams.verboseFailmode(handler, engine)) { - throw new MacroException("Unhandled macro: " + name); - } - return filter(null, cx); - } - - /** - * Render this macro as nested macro, only converting to string - * if necessary. - */ - Object invokeAsParameter(RenderContext cx) throws Exception { - StandardParams stdParams = standardParams.render(cx); - Object value = invokeAsMacro(cx, stdParams, true); - if (stdParams.prefix != null || stdParams.suffix != null) { - ResponseTrans res = cx.reval.getResponse(); - res.pushBuffer(null); - writeResponse(value, cx.reval, stdParams, true); - return res.popString(); - } else if (stdParams.defaultValue != null && - (value == null || "".equals(value))) { - return stdParams.defaultValue; - } else { - return value; - } - } - - /** - * Render the macro given a handler object. - */ - void render(RenderContext cx) - throws RedirectException, UnsupportedEncodingException { - StringBuffer buffer = cx.reval.getResponse().getBuffer(); - // remember length of response buffer before calling macro - int bufLength = buffer.length(); - try { - StandardParams stdParams = standardParams.render(cx); - boolean asObject = filterChain != null; - Object value = invokeAsMacro(cx, stdParams, asObject); - - // check if macro wrote out to response buffer - if (buffer.length() == bufLength) { - // If the macro function didn't write anything to the response itself, - // we interpret its return value as macro output. - writeResponse(value, cx.reval, stdParams, true); - } else { - // if an encoding is specified, re-encode the macro's output - if (encoding != ENCODE_NONE) { - String output = buffer.substring(bufLength); - - buffer.setLength(bufLength); - writeResponse(output, cx.reval, stdParams, false); - } else { - // insert prefix, - if (stdParams.prefix != null) { - buffer.insert(bufLength, stdParams.prefix); - } - // append suffix - if (stdParams.suffix != null) { - buffer.append(stdParams.suffix); - } - } - - // Append macro return value even if it wrote something to the response, - // but don't render default value in case it returned nothing. - // We do this for the sake of consistency. - writeResponse(value, cx.reval, stdParams, false); - } - - } catch (RedirectException redir) { - throw redir; - } catch (ConcurrencyException concur) { - throw concur; - } catch (TimeoutException timeout) { - throw timeout; - } catch (MacroException mx) { - String msg = mx.getMessage(); - cx.reval.getResponse().write(" [" + msg + "] "); - app.logError(msg); - } catch (Exception x) { - String msg = x.getMessage(); - if ((msg == null) || (msg.length() < 10)) { - msg = x.toString(); - } - msg = new StringBuffer("Macro error in ").append(name) - .append(": ").append(msg).toString(); - cx.reval.getResponse().write(" [" + msg + "] "); - app.logError(msg, x); - } - } - - private Object filter(Object returnValue, RenderContext cx) - throws Exception { - // invoke filter chain if defined - if (filterChain != null) { - return filterChain.invokeAsFilter(returnValue, cx); - } else { - return returnValue; - } - } - - private Object invokeAsFilter(Object returnValue, RenderContext cx) - throws Exception { - - if (name == null) { - throw new MacroException("Empty macro filter"); - } else if (sandbox != null && !sandbox.contains(name)) { - throw new MacroException("Macro not allowed in sandbox: " + name); - } - Object handlerObject = null; - - if (handlerType != HANDLER_GLOBAL) { - handlerObject = cx.resolveHandler(path[0], handlerType); - handlerObject = resolvePath(handlerObject, cx.reval); - } - - String propName = path[path.length - 1] + "_filter"; - String funcName = resolveFunctionName(handlerObject, propName, - cx.reval.scriptingEngine); - - if (funcName != null) { - Object[] arguments = prepareArguments(1, cx); - arguments[0] = returnValue; - Object retval = cx.reval.invokeDirectFunction(handlerObject, - funcName, - arguments); - - return filter(retval, cx); - } else { - throw new MacroException("Undefined macro filter: " + name); - } - } - - private Object[] prepareArguments(int offset, RenderContext cx) - throws Exception { - int nPosArgs = (positionalParams == null) ? 0 : positionalParams.size(); - Object[] arguments = new Object[offset + 1 + nPosArgs]; - - if (namedParams == null) { - arguments[offset] = new SystemMap(4); - } else if (hasNestedMacros) { - SystemMap map = new SystemMap((int) (namedParams.size() * 1.5)); - for (Iterator it = namedParams.entrySet().iterator(); it.hasNext(); ) { - Map.Entry entry = (Map.Entry) it.next(); - Object value = entry.getValue(); - if (!(value instanceof String)) - value = processParameter(value, cx); - map.put(entry.getKey(), value); - } - arguments[offset] = map; - } else { - // pass a clone/copy of the parameter map so if the script changes it, - arguments[offset] = new CopyOnWriteMap(namedParams); - } - if (positionalParams != null) { - for (int i = 0; i < nPosArgs; i++) { - Object value = positionalParams.get(i); - if (!(value instanceof String)) - value = processParameter(value, cx); - arguments[offset + 1 + i] = value; - } - } - return arguments; - } - - private Object resolvePath(Object handler, RequestEvaluator reval) throws Exception { - for (int i = 1; i < path.length - 1; i++) { - Object[] arguments = {path[i]}; - Object next = reval.invokeDirectFunction(handler, "getMacroHandler", arguments); - if (next != null) { - handler = next; - } else if (!reval.scriptingEngine.isTypedObject(handler)) { - handler = reval.scriptingEngine.getProperty(handler, path[i]); - if (handler == null) { - return null; - } - } else { - return null; - } - } - return handler; - } - - private String resolveFunctionName(Object handler, String functionName, - ScriptingEngine engine) { - if (handlerType == HANDLER_GLOBAL) { - String[] macroPath = app.globalMacroPath; - if (macroPath == null || macroPath.length == 0) { - if (engine.hasFunction(null, functionName, false)) - return functionName; - } else { - for (int i = 0; i < macroPath.length; i++) { - String path = macroPath[i]; - String funcName = path == null || path.length() == 0 ? - functionName : path + "." + functionName; - if (engine.hasFunction(null, funcName, true)) - return funcName; - } - } - } else { - if (engine.hasFunction(handler, functionName, false)) - return functionName; - } - return null; - } - - /** - * Utility method for writing text out to the response object. - */ - void writeResponse(Object value, RequestEvaluator reval, - StandardParams stdParams, boolean useDefault) - throws Exception { - String text; - StringBuffer buffer = reval.getResponse().getBuffer(); - - if (value == null || "".equals(value)) { - if (useDefault) { - text = (String) stdParams.defaultValue; - } else { - return; - } - } else { - text = reval.scriptingEngine.toString(value); - } - - if ((text != null) && (text.length() > 0)) { - // only write prefix/suffix if value is not null, if we write the default - // value provided by the macro tag, we assume it's already complete - if (stdParams.prefix != null && value != null) { - buffer.append(stdParams.prefix); - } - - switch (encoding) { - case ENCODE_NONE: - buffer.append(text); - - break; - - case ENCODE_HTML: - HtmlEncoder.encode(text, buffer); - - break; - - case ENCODE_XML: - HtmlEncoder.encodeXml(text, buffer); - - break; - - case ENCODE_FORM: - HtmlEncoder.encodeFormValue(text, buffer); - - break; - - case ENCODE_URL: - buffer.append(UrlEncoded.encode(text, app.charset)); - - break; - - case ENCODE_ALL: - HtmlEncoder.encodeAll(text, buffer); - - break; - } - - if (stdParams.suffix != null && value != null) { - buffer.append(stdParams.suffix); - } - } - } - - public String toString() { - return "[Macro: " + name + "]"; - } - - /** - * Return the full name of the macro in handler.name notation - * @return the macro name - */ - public String getName() { - return name; - } - - /** - * Return the numeric type of the macro handler - * @return the handler type - */ - public int getHandlerType() { - return handlerType; - } - - /** - * Return the list of named parameters - * @return the list of named parameters - */ - public Map getNamedParams() { - return namedParams; - } - - /** - * Return the list of positional parameters - * @return the list of positional parameters - */ - public List getPositionalParams() { - return positionalParams; - } - - public boolean hasNestedMacros() { - return hasNestedMacros; - } - - } - - class StandardParams { - Object prefix = null; - Object suffix = null; - Object defaultValue = null; - int failmode = FAIL_DEFAULT; - - StandardParams() {} - - StandardParams(Map map) { - readFrom(map); - } - - void readFrom(Map map) { - prefix = map.get("prefix"); - suffix = map.get("suffix"); - defaultValue = map.get("default"); - } - - boolean containsMacros() { - return !(prefix instanceof String) - || !(suffix instanceof String) - || !(defaultValue instanceof String); - } - - void setFailMode(Object value) { - if ("silent".equals(value)) - failmode = FAIL_SILENT; - else if ("verbose".equals(value)) - failmode = FAIL_VERBOSE; - else if (value != null) - app.logEvent("unrecognized failmode value: " + value); - } - - boolean verboseFailmode(Object handler, ScriptingEngine engine) { - return (failmode == FAIL_VERBOSE) || - (failmode == FAIL_DEFAULT && - (handler == null || - engine.isTypedObject(handler))); - } - - StandardParams render(RenderContext cx) - throws Exception { - if (!containsMacros()) - return this; - StandardParams stdParams = new StandardParams(); - stdParams.prefix = renderToString(prefix, cx); - stdParams.suffix = renderToString(suffix, cx); - stdParams.defaultValue = renderToString(defaultValue, cx); - return stdParams; - } - - String renderToString(Object obj, RenderContext cx) throws Exception { - Object value = processParameter(obj, cx); - if (value == null) - return null; - else if (value instanceof String) - return (String) value; - else - return cx.reval.scriptingEngine.toString(value); - } - - } - - class RenderContext { - final RequestEvaluator reval; - final Object thisObject; - final Map handlerCache; - - RenderContext(RequestEvaluator reval, Object thisObject, Map handlerCache) { - this.reval = reval; - this.thisObject = thisObject; - this.handlerCache = handlerCache; - } - - private Object resolveHandler(String handlerName, int handlerType) { - switch (handlerType) { - case HANDLER_THIS: - return thisObject; - case HANDLER_RESPONSE: - return reval.getResponse().getResponseData(); - case HANDLER_REQUEST: - return reval.getRequest().getRequestData(); - case HANDLER_SESSION: - return reval.getSession().getCacheNode(); - } - - // try to get handler from handlerCache first - if (handlerCache != null && handlerCache.containsKey(handlerName)) { - return handlerCache.get(handlerName); - } - - // if handler object wasn't found in cache first check this-object - if (thisObject != null) { - // not a global macro - need to find handler object - // was called with this object - check this-object for matching prototype - Prototype proto = app.getPrototype(thisObject); - - if (proto != null && proto.isInstanceOf(handlerName)) { - return cacheHandler(handlerName, thisObject); - } - } - - // next look in res.handlers - Map macroHandlers = reval.getResponse().getMacroHandlers(); - Object obj = macroHandlers.get(handlerName); - if (obj != null) { - return cacheHandler(handlerName, obj); - } - - // finally walk down the this-object's parent chain - if (thisObject != null) { - obj = app.getParentElement(thisObject); - // walk down parent chain to find handler object, - // limiting to 50 passes to avoid infinite loops - int maxloop = 50; - while (obj != null && maxloop-- > 0) { - Prototype proto = app.getPrototype(obj); - - if (proto != null && proto.isInstanceOf(handlerName)) { - return cacheHandler(handlerName, obj); - } - - obj = app.getParentElement(obj); - } - } - - return cacheHandler(handlerName, null); - } - - private Object cacheHandler(String name, Object handler) { - if (handlerCache != null) { - handlerCache.put(name, handler); - } - return handler; - } - - } - - /** - * Exception type for unhandled, forbidden or failed macros - */ - class MacroException extends Exception { - private static final long serialVersionUID = 396025641010781784L; - - MacroException(String message) { - super(message); - } - } - -} - diff --git a/src/main/java/helma/framework/core/SkinManager.java b/src/main/java/helma/framework/core/SkinManager.java deleted file mode 100644 index da234c89..00000000 --- a/src/main/java/helma/framework/core/SkinManager.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.core; - -import helma.objectmodel.INode; -import helma.framework.repository.FileResource; - -import java.io.*; - -/** - * Manages skins for a Helma application - */ -public final class SkinManager implements FilenameFilter { - Application app; - // the skin property name to use in database skin objects - final String skinProperty; - // the file name extension for skin files - final String skinExtension; - - /** - * Creates a new SkinManager object. - * - * @param app ... - */ - public SkinManager(Application app) { - this.app = app; - skinProperty = app.getProperty("skinProperty", "skin"); - skinExtension = ".skin"; - } - - public Skin getSkin(Prototype prototype, String skinname, Object[] skinpath) - throws IOException { - if (prototype == null) { - return null; - } - - // if name contains '#' split name into mainskin and subskin - String subskin = null; - int hash = skinname.indexOf('#'); - if (hash > -1) { - subskin = skinname.substring(hash + 1); - skinname = skinname.substring(0, hash); - } - return getSkin(prototype, skinname, subskin, skinpath); - } - - public Skin getSkin(Prototype prototype, String skinname, - String subskin, Object[] skinpath) - throws IOException { - Prototype proto = prototype; - - // Loop over prototype chain and check skinpath and prototype skin resources - while (proto != null) { - Skin skin; - if (skinpath != null) { - for (int i = 0; i < skinpath.length; i++) { - skin = getSkinInPath(skinpath[i], proto.getName(), skinname); - if (skin != null) { - // check if skin skin contains main skin - if (subskin == null && skin.hasMainskin()) { - return skin; - } else if (subskin != null && skin.hasSubskin(subskin)) { - return skin.getSubskin(subskin); - } - String baseskin = skin.getExtends(); - if (baseskin != null && !baseskin.equals(skinname)) { - return getSkin(prototype, baseskin, subskin, skinpath); - } - } - } - } - - // skin for this prototype wasn't found in the skinsets. - // the next step is to look if it is defined as skin file in the application directory - skin = proto.getSkin(prototype, skinname, subskin, skinpath); - if (skin != null) { - return skin; - } - - // still not found. See if there is a parent prototype which might define the skin. - proto = proto.getParentPrototype(); - } - - // looked every where, nothing to be found - return null; - } - - private Skin getSkinInPath(Object skinset, String prototype, String skinname) throws IOException { - if ((prototype == null) || (skinset == null)) { - return null; - } - - // check if the skinset object is a HopObject (db based skin) - // or a String (file based skin) - if (skinset instanceof INode) { - INode n = (INode) ((INode) skinset).getChildElement(prototype); - - if (n != null) { - n = (INode) n.getChildElement(skinname); - - if (n != null) { - String skin = n.getString(skinProperty); - - if (skin != null) { - return new Skin(skin, app); - } - } - } - } else { - // Skinset is interpreted as directory name from which to - // retrieve the skin - StringBuffer b = new StringBuffer(skinset.toString()); - b.append(File.separatorChar).append(prototype).append(File.separatorChar) - .append(skinname).append(skinExtension); - - // TODO: check for lower case prototype name for backwards compat - - File f = new File(b.toString()); - - if (f.exists() && f.canRead()) { - return Skin.getSkin(new FileResource(f), app); - } - } - - // Inheritance is taken care of in the above getSkin method. - // the sequence is prototype.skin-from-db, prototype.skin-from-file, parent.from-db, parent.from-file etc. - return null; - } - - /** - * Implements java.io.FilenameFilter.accept() - */ - public boolean accept(File d, String n) { - return n.endsWith(skinExtension); - } -} diff --git a/src/main/java/helma/framework/core/TypeManager.java b/src/main/java/helma/framework/core/TypeManager.java deleted file mode 100644 index 7d7efdf7..00000000 --- a/src/main/java/helma/framework/core/TypeManager.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.core; - -import helma.objectmodel.db.DbMapping; -import helma.framework.repository.Resource; -import helma.framework.repository.Repository; -import helma.util.StringUtils; - -import java.io.*; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.*; - -/** - * The type manager periodically checks the prototype definitions for its - * applications and updates the evaluators if anything has changed. - */ -public final class TypeManager { - final static String[] standardTypes = { "User", "Global", "Root", "HopObject" }; - final static String templateExtension = ".hsp"; - final static String scriptExtension = ".js"; - final static String actionExtension = ".hac"; - final static String skinExtension = ".skin"; - - private Application app; - // map of prototypes - private HashMap prototypes; - - // set of Java archives - private HashSet jarfiles; - - // set of directory names to ignore - private HashSet ignoreDirs; - - private long lastCheck = 0; - private long lastCodeUpdate; - private HashMap lastRepoScan; - - // app specific class loader, includes jar files in the app directory - private AppClassLoader loader; - - /** - * Creates a new TypeManager object. - * - * @param app ... - * - * @throws RuntimeException ... - */ - public TypeManager(Application app, String ignore) { - this.app = app; - prototypes = new HashMap(); - jarfiles = new HashSet(); - ignoreDirs = new HashSet(); - lastRepoScan = new HashMap(); - // split ignore dirs list and add to hash set - if (ignore != null) { - String[] arr = StringUtils.split(ignore, ","); - for (int i=0; ifalse. - */ - public synchronized Resource getResource(String name) { - update(); - - Resource res = (Resource) resources.get(name); - // if resource does not exist, create it - if (res == null) { - res = createResource(name); - resources.put(name, res); - } - return res; - } - - /** - * Get an iterator over the resources contained in this repository. - */ - public synchronized Iterator getResources() { - update(); - - return resources.values().iterator(); - } - - /** - * Get an iterator over the sub-repositories contained in this repository. - */ - public synchronized Repository[] getRepositories() { - update(); - - return repositories; - } - - /** - * Get this repository's parent repository. - */ - public Repository getParentRepository() { - return parent; - } - - /** - * Get a deep list of this repository's resources, including all resources - * contained in sub-reposotories. - */ - public synchronized List getAllResources() throws IOException { - update(); - - ArrayList allResources = new ArrayList(); - allResources.addAll(resources.values()); - - for (int i = 0; i < repositories.length; i++) { - allResources.addAll(repositories[i].getAllResources()); - } - - return allResources; - } - - /** - * Returns the repositories full name as string representation. - * @see {getName()} - */ - public String toString() { - return getName(); - } - -} diff --git a/src/main/java/helma/framework/repository/AbstractResource.java b/src/main/java/helma/framework/repository/AbstractResource.java deleted file mode 100644 index 04da1771..00000000 --- a/src/main/java/helma/framework/repository/AbstractResource.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -/** - * Abstract resource base class that implents get/setOverloadedResource. - */ -public abstract class AbstractResource implements Resource { - - protected Resource overloaded = null; - - /** - * Method for registering a Resource this Resource is overloading - * - * @param res the overloaded resource - */ - public void setOverloadedResource(Resource res) { - overloaded = res; - } - - /** - * Get a Resource this Resource is overloading - * - * @return the overloaded resource - */ - public Resource getOverloadedResource() { - return overloaded; - } -} diff --git a/src/main/java/helma/framework/repository/FileRepository.java b/src/main/java/helma/framework/repository/FileRepository.java deleted file mode 100644 index cf05f9de..00000000 --- a/src/main/java/helma/framework/repository/FileRepository.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; - -/** - * Repository implementation for directories providing file resources - */ -public class FileRepository extends AbstractRepository { - - // Directory serving sub-repositories and file resources - protected File directory; - - protected long lastModified = -1; - protected long lastChecksum = 0; - protected long lastChecksumTime = 0; - - /** - * Defines how long the checksum of the repository will be cached - */ - final long cacheTime = 1000L; - - /** - * Constructs a FileRepository using the given argument - * @param initArgs absolute path to the directory - */ - public FileRepository(String initArgs) { - this(new File(initArgs), null); - } - - /** - * Constructs a FileRepository using the given directory as top-level - * repository - * @param dir directory - */ - public FileRepository(File dir) { - this(dir, null); - } - - /** - * Constructs a FileRepository using the given directory and top-level - * repository - * @param dir directory - * @param parent the parent repository, or null - */ - public FileRepository(File dir, Repository parent) { - // make sure our directory has an absolute path, - // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4117557 - if (dir.isAbsolute()) { - directory = dir; - } else { - directory = dir.getAbsoluteFile(); - } - if (!directory.exists()) { - create(); - } else if (!directory.isDirectory()) { - throw new IllegalArgumentException("File " + directory + " is not a directory"); - } - - if (parent == null) { - name = shortName = directory.getAbsolutePath(); - } else { - this.parent = parent; - shortName = directory.getName(); - name = directory.getAbsolutePath(); - } - } - - public boolean exists() { - return directory.exists() && directory.isDirectory(); - } - - public void create() { - if (!directory.exists() || !directory.isDirectory()) { - directory.mkdirs(); - } - } - - /** - * Checks wether the repository is to be considered a top-level - * repository from a scripting point of view. For example, a zip - * file within a file repository is not a root repository from - * a physical point of view, but from the scripting point of view it is. - * - * @return true if the repository is to be considered a top-level script repository - */ - public boolean isScriptRoot() { - return parent == null || parent instanceof MultiFileRepository; - } - - public long lastModified() { - return directory.lastModified(); - } - - public synchronized long getChecksum() throws IOException { - // delay checksum check if already checked recently - if (System.currentTimeMillis() > lastChecksumTime + cacheTime) { - - update(); - long checksum = lastModified; - - for (int i = 0; i < repositories.length; i++) { - checksum += repositories[i].getChecksum(); - } - - lastChecksum = checksum; - lastChecksumTime = System.currentTimeMillis(); - } - - return lastChecksum; - } - - /** - * Updates the content cache of the repository - * Gets called from within all methods returning sub-repositories or - * resources - */ - public synchronized void update() { - if (!directory.exists()) { - repositories = emptyRepositories; - if (resources == null) { - resources = new HashMap(); - } else { - resources.clear(); - } - lastModified = 0; - return; - } - - if (directory.lastModified() != lastModified) { - lastModified = directory.lastModified(); - - File[] list = directory.listFiles(); - - ArrayList newRepositories = new ArrayList(list.length); - HashMap newResources = new HashMap(list.length); - - for (int i = 0; i < list.length; i++) { - if (list[i].isDirectory()) { - // a nested directory aka child file repository - newRepositories.add(new FileRepository(list[i], this)); - } else if (list[i].getName().endsWith(".zip")) { - // a nested zip repository - newRepositories.add(new ZipRepository(list[i], this)); - } else if (list[i].isFile()) { - // a file resource - FileResource resource = new FileResource(list[i], this); - newResources.put(resource.getShortName(), resource); - } - } - - repositories = (Repository[]) - newRepositories.toArray(new Repository[newRepositories.size()]); - resources = newResources; - } - } - - /** - * Called to create a child resource for this repository - */ - protected Resource createResource(String name) { - return new FileResource(new File(directory, name), this); - } - - /** - * Get the repository's directory - */ - public File getDirectory() { - return directory; - } - - public int hashCode() { - return 17 + (37 * directory.hashCode()); - } - - public boolean equals(Object obj) { - return obj instanceof FileRepository && - directory.equals(((FileRepository) obj).directory); - } - - public String toString() { - return new StringBuffer("FileRepository[").append(name).append("]").toString(); - } -} diff --git a/src/main/java/helma/framework/repository/FileResource.java b/src/main/java/helma/framework/repository/FileResource.java deleted file mode 100644 index 6c3a5578..00000000 --- a/src/main/java/helma/framework/repository/FileResource.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import java.net.*; -import java.io.*; - -public class FileResource extends AbstractResource { - - File file; - Repository repository; - String name; - String shortName; - String baseName; - - public FileResource(File file) { - this(file, null); - } - - protected FileResource(File file, Repository repository) { - this.file = file; - - this.repository = repository; - name = file.getAbsolutePath(); - shortName = file.getName(); - // base name is short name with extension cut off - int lastDot = shortName.lastIndexOf("."); - baseName = (lastDot == -1) ? shortName : shortName.substring(0, lastDot); - } - - public String getName() { - return name; - } - - public String getShortName() { - return shortName; - } - - public String getBaseName() { - return baseName; - } - - public InputStream getInputStream() throws IOException { - return new FileInputStream(file); - } - - public URL getUrl() { - try { - return new URL("file:" + file.getAbsolutePath()); - } catch (MalformedURLException ex) { - return null; - } - } - - public long lastModified() { - return file.lastModified(); - } - - public String getContent(String encoding) throws IOException { - InputStream in = getInputStream(); - int size = (int) file.length(); - byte[] buf = new byte[size]; - int read = 0; - while (read < size) { - int r = in.read(buf, read, size - read); - if (r == -1) - break; - read += r; - } - in.close(); - return encoding == null ? - new String(buf) : - new String(buf, encoding); - } - - public String getContent() throws IOException { - return getContent(null); - } - - public long getLength() { - return file.length(); - } - - public boolean exists() { - return file.exists(); - } - - public Repository getRepository() { - return repository; - } - - public int hashCode() { - return 17 + name.hashCode(); - } - - public boolean equals(Object obj) { - return obj instanceof FileResource && name.equals(((FileResource)obj).name); - } - - public String toString() { - return getName(); - } -} diff --git a/src/main/java/helma/framework/repository/MultiFileRepository.java b/src/main/java/helma/framework/repository/MultiFileRepository.java deleted file mode 100644 index c43a26a2..00000000 --- a/src/main/java/helma/framework/repository/MultiFileRepository.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 2005 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; - -/** - * Repository implementation that provides all of its subdirectories - * as top-level FileRepositories - * - * @author Barbara Ondrisek - */ -public class MultiFileRepository extends FileRepository { - - /** - * Constructs a MultiFileRepository using the given argument - * @param initArgs absolute path to the directory - */ - public MultiFileRepository(String initArgs) { - this(new File(initArgs)); - } - - /** - * Constructs a MultiFileRepository using the given directory as top-level - * repository - * @param dir directory - */ - public MultiFileRepository(File dir) { - super(dir, null); - } - - /** - * Updates the content cache of the repository. We override this - * to create child repositories that act as top-level script repositories - * rather than prototype repositories. Zip files are handled as top-level - * script repositories like in FileRepository, while resources are ignored. - */ - public synchronized void update() { - if (!directory.exists()) { - repositories = emptyRepositories; - if (resources != null) - resources.clear(); - lastModified = 0; - return; - } - - if (directory.lastModified() != lastModified) { - lastModified = directory.lastModified(); - - File[] list = directory.listFiles(); - - ArrayList newRepositories = new ArrayList(list.length); - HashMap newResources = new HashMap(list.length); - - for (int i = 0; i < list.length; i++) { - // create both directories and zip files as top-level repositories, - // while resources (files) are ignored. - if (list[i].isDirectory()) { - // a nested directory aka child file repository - newRepositories.add(new FileRepository(list[i], this)); - } else if (list[i].getName().endsWith(".zip")) { - // a nested zip repository - newRepositories.add(new ZipRepository(list[i], this)); - } - } - - repositories = (Repository[]) - newRepositories.toArray(new Repository[newRepositories.size()]); - resources = newResources; - } - } - - /** - * get hashcode - * @return int - */ - public int hashCode() { - return 37 + (37 * directory.hashCode()); - } - - /** - * equals object - * @param obj Object - * @return boolean - */ - public boolean equals(Object obj) { - return obj instanceof MultiFileRepository && - directory.equals(((MultiFileRepository) obj).directory); - } - - /** - * get object serialized as string - * @return String - */ - public String toString() { - return new StringBuffer("MultiFileRepository[").append(name).append("]").toString(); - } -} diff --git a/src/main/java/helma/framework/repository/Repository.java b/src/main/java/helma/framework/repository/Repository.java deleted file mode 100644 index 780ee892..00000000 --- a/src/main/java/helma/framework/repository/Repository.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import java.util.List; -import java.util.Iterator; -import java.io.IOException; - -/** - * Repository represents an abstract container of resources (e.g. code, skins, ...). - * In addition to resources, repositories may contain other repositories, building - * a hierarchical structure. - */ -public interface Repository { - - /** - * Checksum of the repository and all its content. Implementations - * should make sure - * - * @return checksum - * @throws IOException - */ - public long getChecksum() throws IOException; - - /** - * Returns the date the repository was last modified. - * - * @return last modified date - * @throws IOException - */ - public long lastModified() throws IOException; - - - /** - * Returns a specific direct resource of the repository - * - * @param resourceName name of the child resource to return - * @return specified child resource - */ - public Resource getResource(String resourceName); - - /** - * Returns all direct resources - * - * @return direct resources - * @throws IOException - */ - public Iterator getResources() throws IOException; - - /** - * Returns all direct and indirect resources - * - * @return resources recursive - * @throws IOException - */ - public List getAllResources() throws IOException; - - /** - * Returns this repository's direct child repositories - * - * @return direct repositories - * @throws IOException - */ - public Repository[] getRepositories() throws IOException; - - /** - * Checks wether the repository actually (or still) exists - * - * @return true if the repository exists - * @throws IOException - */ - public boolean exists() throws IOException; - - /** - * Creates the repository if does not exist yet - * - * @throws IOException - */ - public void create() throws IOException; - - /** - * Checks wether the repository is to be considered a top-level - * repository from a scripting point of view. For example, a zip - * file within a file repository is not a root repository from - * a physical point of view, but from the scripting point of view it is. - * - * @return true if the repository is to be considered a top-level script repository - */ - public boolean isScriptRoot(); - - /** - * Returns this repository's parent repository. - * Returns null if this repository already is the top-level repository - * - * @return the parent repository - */ - public Repository getParentRepository(); - - /** - * Get this repository's logical script root repository. - * - * @see {isScriptRoot()} - * @return top-level repository - */ - public Repository getRootRepository(); - - /** - * Returns the name of the repository; this is a full name including all - * parent repositories. - * - * @return full name of the repository - */ - public String getName(); - - /** - * Returns the name of the repository. - * - * @return name of the repository - */ - public String getShortName(); - -} diff --git a/src/main/java/helma/framework/repository/Resource.java b/src/main/java/helma/framework/repository/Resource.java deleted file mode 100644 index 3eb431b8..00000000 --- a/src/main/java/helma/framework/repository/Resource.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import java.io.InputStream; -import java.io.IOException; -import java.net.URL; - -/** - * Resource represents a pointer to some kind of information (code, skin, ...) - * from which the content can be fetched - */ -public interface Resource { - - /** - * Returns the date the resource was last modified - * @return last modified date - */ - public long lastModified(); - - /** - * Checks wether this resource actually (still) exists - * @return true if the resource exists - */ - public boolean exists(); - - /** - * Returns the lengh of the resource's content - * @return content length - * @throws IOException I/O related problem - */ - public long getLength() throws IOException; - - /** - * Returns an input stream to the content of the resource - * @return content input stream - * @throws IOException I/O related problem - */ - public InputStream getInputStream() throws IOException; - - /** - * Returns the content of the resource in a given encoding - * @param encoding the character encoding - * @return content - * @throws IOException I/O related problem - */ - public String getContent(String encoding) throws IOException; - - /** - * Returns the content of the resource - * @return content - * @throws IOException I/O related problem - */ - public String getContent() throws IOException; - - /** - * Returns the name of the resource; does not include the name of the - * repository the resource was fetched from - * @return name of the resource - */ - public String getName(); - - /** - * Returns the short name of the resource which is its name exclusive file - * ending if it exists - * @return short name of the resource - */ - public String getShortName(); - - /** - * Returns the short name of the resource with the file extension - * (everything following the last dot character) cut off. - * @return the file name without the file extension - */ - public String getBaseName(); - - /** - * Returns an url to the resource if the repository of this resource is - * able to provide urls - * @return url to the resource - * @throws UnsupportedOperationException if resource does not support URL schema - */ - public URL getUrl() throws UnsupportedOperationException; - - /** - * Get a Resource this Resource is overloading - * @return the overloaded resource - */ - public Resource getOverloadedResource(); - - /** - * Method for registering a Resource this Resource is overloading - * @param res the overloaded resource - */ - public void setOverloadedResource(Resource res); - - /** - * Returns the repository the resource does belong to - * @return upper repository - */ - public Repository getRepository(); - -} diff --git a/src/main/java/helma/framework/repository/ResourceComparator.java b/src/main/java/helma/framework/repository/ResourceComparator.java deleted file mode 100644 index 383a1fa1..00000000 --- a/src/main/java/helma/framework/repository/ResourceComparator.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import java.util.Comparator; -import helma.framework.core.Application; - -/** - * Sorts resources according to the order of their repositories - */ -public class ResourceComparator implements Comparator { - - // the application where the top-level repositories can be found - protected Application app; - - /** - * Constructcs a ResourceComparator sorting according to the top-level - * repositories of the given application - * @param app application that provides the top-level repositories - */ - public ResourceComparator(Application app) { - this.app = app; - } - - /** - * Compares two Repositories, Resources or RepositoryTrackers - * @param obj1 Repository, Resource or RepositoryTrackers - * @param obj2 Repository, Resource or RepositoryTrackers - * @return a negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - * @throws ClassCastException if the arguments' types prevent them from - * being compared by this Comparator. - */ - public int compare(Object obj1, Object obj2) { - if (obj1.equals(obj2)) - return 0; - - Repository rep1 = getRootRepository(obj1); - Repository rep2 = getRootRepository(obj2); - - int pos1 = app.getRepositoryIndex(rep1); - int pos2 = app.getRepositoryIndex(rep2); - - if (rep1 == rep2 || (pos1 == -1 && pos2 == -1)) { - // Same root repository, but we must not return 0 unless objects are equal - // (see JavaDoc on java.util.TreeSet) so we compare full names - return getFullName(obj1).compareTo(getFullName(obj2)); - } - - return pos1 - pos2; - } - - /** - * Checks if the comparator is equal to the given comparator - * A ResourceComparator is equal to another ResourceComparator if the - * applications they belong to are equal - * - * @param obj comparator - * @return true if the given comparator equals - */ - public boolean equals(Object obj) { - return (obj instanceof ResourceComparator) && - app == ((ResourceComparator) obj).getApplication(); - } - - /** - * Return the application we're comparing resources for - * - * @return the application instance - */ - public Application getApplication() { - return app; - } - - private Repository getRootRepository(Object obj) { - if (obj instanceof Resource) - return ((Resource) obj).getRepository() - .getRootRepository(); - if (obj instanceof Repository) - return ((Repository) obj).getRootRepository(); - - // something we can't compare - throw new IllegalArgumentException("Can't compare "+obj); - } - - private String getFullName(Object obj) { - if (obj instanceof Resource) - return ((Resource) obj).getName(); - if (obj instanceof Repository) - return ((Repository) obj).getName(); - - // something we can't compare - throw new IllegalArgumentException("Can't compare "+obj); - } - -} diff --git a/src/main/java/helma/framework/repository/ResourceTracker.java b/src/main/java/helma/framework/repository/ResourceTracker.java deleted file mode 100644 index 4107138c..00000000 --- a/src/main/java/helma/framework/repository/ResourceTracker.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import java.io.IOException; - -/** - * A utility class that allows Resource consumers to track changes - * on resources. - */ -public class ResourceTracker { - - Resource resource; - long lastModified; - - public ResourceTracker(Resource resource) { - this.resource = resource; - markClean(); - } - - public boolean hasChanged() throws IOException { - return lastModified != resource.lastModified(); - } - - public void markClean() { - lastModified = resource.lastModified(); - } - - public Resource getResource() { - return resource; - } -} diff --git a/src/main/java/helma/framework/repository/SingleFileRepository.java b/src/main/java/helma/framework/repository/SingleFileRepository.java deleted file mode 100644 index 14b86669..00000000 --- a/src/main/java/helma/framework/repository/SingleFileRepository.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2006 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import java.io.IOException; -import java.io.File; -import java.util.List; -import java.util.Iterator; -import java.util.LinkedList; - -public class SingleFileRepository implements Repository { - - final Resource res; - final Repository parent; - final Repository[] repositories; - final LinkedList resources = new LinkedList(); - final LinkedList allResources = new LinkedList(); - final boolean isScriptFile; - - /** - * Constructs a SingleFileRepository using the given argument - * @param initArgs absolute path to the script file - */ - public SingleFileRepository(String initArgs) { - this(new File(initArgs), null); - } - - /** - * Constructs a SingleFileRepository using the given argument - * @param file the script file - */ - public SingleFileRepository(File file) { - this(file, null); - } - - /** - * Constructs a SingleFileRepository using the given argument - * @param file the script file - * @param parent the parent repository, or null - */ - public SingleFileRepository(File file, Repository parent) { - this.parent = parent; - res = new FileResource(file, this); - allResources.add(res); - isScriptFile = file.getName().endsWith(".js"); - if (isScriptFile) { - repositories = new Repository[] { new FakeGlobal() }; - } else { - repositories = AbstractRepository.emptyRepositories; - resources.add(res); - } - } - - /** - * Checksum of the repository and all its content. Implementations - * should make sure - * - * @return checksum - * @throws java.io.IOException - */ - public long getChecksum() throws IOException { - return res.lastModified(); - } - - /** - * Returns the name of the repository. - * - * @return name of the repository - */ - public String getShortName() { - return res.getShortName(); - } - - /** - * Returns the name of the repository; this is a full name including all - * parent repositories. - * - * @return full name of the repository - */ - public String getName() { - return res.getName(); - } - - /** - * Get this repository's logical script root repository. - * - * @return top-level repository - * @see {isScriptRoot()} - */ - public Repository getRootRepository() { - return this; - } - - /** - * Returns this repository's parent repository. - * Returns null if this repository already is the top-level repository - * - * @return the parent repository - */ - public Repository getParentRepository() { - return parent; - } - - /** - * Checks wether the repository is to be considered a top-level - * repository from a scripting point of view. For example, a zip - * file within a file repository is not a root repository from - * a physical point of view, but from the scripting point of view it is. - * - * @return true if the repository is to be considered a top-level script repository - */ - public boolean isScriptRoot() { - return false; - } - - /** - * Creates the repository if does not exist yet - * - * @throws java.io.IOException - */ - public void create() throws IOException { - // noop - } - - /** - * Checks wether the repository actually (or still) exists - * - * @return true if the repository exists - * @throws java.io.IOException - */ - public boolean exists() throws IOException { - return res.exists(); - } - - /** - * Returns this repository's direct child repositories - * - * @return direct repositories - * @throws java.io.IOException - */ - public Repository[] getRepositories() throws IOException { - return repositories; - } - - /** - * Returns all direct and indirect resources - * - * @return resources recursive - * @throws java.io.IOException - */ - public List getAllResources() throws IOException { - return resources; - } - - /** - * Returns all direct resources - * - * @return direct resources - * @throws java.io.IOException - */ - public Iterator getResources() throws IOException { - return resources.iterator(); - } - - /** - * Returns a specific direct resource of the repository - * - * @param resourceName name of the child resource to return - * @return specified child resource - */ - public Resource getResource(String resourceName) { - if (!isScriptFile && res.getName().equals(resourceName)) { - return res; - } - return null; - } - - /** - * Returns the date the repository was last modified. - * - * @return last modified date - * @throws java.io.IOException - */ - public long lastModified() throws IOException { - return res.lastModified(); - } - - /** - * Return our single resource. - * @return the wrapped resource - */ - protected Resource getResource() { - return res; - } - - /** - * Indicates whether some other object is "equal to" this one. - */ - public boolean equals(Object obj) { - return (obj instanceof SingleFileRepository && - res.equals(((SingleFileRepository) obj).res)); - } - - /** - * Returns a hash code value for the object. - */ - public int hashCode() { - return res.hashCode(); - } - - /** - * Returns a string representation of the object. - */ - public String toString() { - return new StringBuffer("SingleFileRepository[") - .append(res.getName()).append("]").toString(); - } - - class FakeGlobal implements Repository { - - /** - * Checksum of the repository and all its content. Implementations - * should make sure - * - * @return checksum - * @throws java.io.IOException - */ - public long getChecksum() throws IOException { - return res.lastModified(); - } - - /** - * Returns the name of the repository. - * - * @return name of the repository - */ - public String getShortName() { - // we need to return "Global" here in order to be recognized as - // global code folder - that's the whole purpose of this class - return "Global"; - } - - /** - * Returns the name of the repository; this is a full name including all - * parent repositories. - * - * @return full name of the repository - */ - public String getName() { - return res.getName(); - } - - /** - * Get this repository's logical script root repository. - * - * @return top-level repository - * @see {isScriptRoot()} - */ - public Repository getRootRepository() { - return SingleFileRepository.this; - } - - /** - * Returns this repository's parent repository. - * Returns null if this repository already is the top-level repository - * - * @return the parent repository - */ - public Repository getParentRepository() { - return SingleFileRepository.this; - } - - /** - * Checks wether the repository is to be considered a top-level - * repository from a scripting point of view. For example, a zip - * file within a file repository is not a root repository from - * a physical point of view, but from the scripting point of view it is. - * - * @return true if the repository is to be considered a top-level script repository - */ - public boolean isScriptRoot() { - return false; - } - - /** - * Creates the repository if does not exist yet - * - * @throws java.io.IOException - */ - public void create() throws IOException { - } - - /** - * Checks wether the repository actually (or still) exists - * - * @return true if the repository exists - * @throws java.io.IOException - */ - public boolean exists() throws IOException { - return res.exists(); - } - - /** - * Returns this repository's direct child repositories - * - * @return direct repositories - * @throws java.io.IOException - */ - public Repository[] getRepositories() throws IOException { - return AbstractRepository.emptyRepositories; - } - - /** - * Returns all direct and indirect resources - * - * @return resources recursive - * @throws java.io.IOException - */ - public List getAllResources() throws IOException { - return allResources; - } - - /** - * Returns all direct resources - * - * @return direct resources - * @throws java.io.IOException - */ - public Iterator getResources() throws IOException { - return allResources.iterator(); - } - - /** - * Returns a specific direct resource of the repository - * - * @param resourceName name of the child resource to return - * @return specified child resource - */ - public Resource getResource(String resourceName) { - if (res.getName().equals(resourceName)) { - return res; - } - return null; - } - - /** - * Returns the date the repository was last modified. - * - * @return last modified date - * @throws java.io.IOException - */ - public long lastModified() throws IOException { - return res.lastModified(); - } - } - - -} - diff --git a/src/main/java/helma/framework/repository/ZipRepository.java b/src/main/java/helma/framework/repository/ZipRepository.java deleted file mode 100644 index ec40bbb3..00000000 --- a/src/main/java/helma/framework/repository/ZipRepository.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import helma.util.StringUtils; - -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public final class ZipRepository extends AbstractRepository { - - // zip file serving sub-repositories and zip file resources - private File file; - - // the nested directory depth of this repository - private int depth; - - String entryPath; - - private long lastModified = -1; - - /** - * Constructs a ZipRespository using the given argument - * @param initArgs absolute path to the zip file - */ - public ZipRepository(String initArgs) { - this(new File(initArgs), null, null); - } - - /** - * Constructs a ZipRespository using the given argument - * @param file zip file - */ - public ZipRepository(File file) { - this(file, null, null); - } - - /** - * Constructs a ZipRepository using the given zip file as top-level - * repository - * @param file a zip file - * @param parent the parent repository, or null - */ - public ZipRepository(File file, Repository parent) { - this(file, parent, null); - } - - /** - * Constructs a ZipRepository using the zip entryName belonging to the given - * zip file and top-level repository - * @param file a zip file - * @param zipentry zip entryName - * @param parent repository - */ - private ZipRepository(File file, Repository parent, ZipEntry zipentry) { - // make sure our file has an absolute path, - // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4117557 - if (file.isAbsolute()) { - this.file = file; - } else { - this.file = file.getAbsoluteFile(); - } - this.parent = parent; - - if (zipentry == null) { - name = shortName = file.getName(); - depth = 0; - entryPath = ""; - } else { - String[] pathArray = StringUtils.split(zipentry.getName(), "/"); - depth = pathArray.length; - shortName = pathArray[depth - 1]; - entryPath = zipentry.getName(); - name = new StringBuffer(parent.getName()) - .append('/').append(shortName).toString(); - } - } - - /** - * Returns a java.util.zip.ZipFile for this repository. It is the caller's - * responsability to call close() in it when it is no longer needed. - * @return a ZipFile for reading - * @throws IOException - */ - protected ZipFile getZipFile() throws IOException { - return new ZipFile(file); - } - - public synchronized void update() { - if (file.lastModified() != lastModified || - repositories == null || - resources == null) { - lastModified = file.lastModified(); - ZipFile zipfile = null; - - try { - zipfile = getZipFile(); - Enumeration en = zipfile.entries(); - HashMap newRepositories = new HashMap(); - HashMap newResources = new HashMap(); - - while (en.hasMoreElements()) { - ZipEntry entry = (ZipEntry) en.nextElement(); - String eName = entry.getName(); - - if (!eName.regionMatches(0, entryPath, 0, entryPath.length())) { - // names don't match - not a child of ours - continue; - } - String[] entrypath = StringUtils.split(eName, "/"); - if (depth > 0 && !shortName.equals(entrypath[depth-1])) { - // catch case where our name is Foo and other's is FooBar - continue; - } - - // create new repositories and resources for all entries with a - // path depth of this.depth + 1 - if (entrypath.length == depth + 1 && !entry.isDirectory()) { - // create a new child resource - ZipResource resource = new ZipResource(entry.getName(), this); - newResources.put(resource.getShortName(), resource); - } else if (entrypath.length > depth) { - // create a new child repository - if (!newRepositories.containsKey(entrypath[depth])) { - ZipEntry child = composeChildEntry(entrypath[depth]); - ZipRepository rep = new ZipRepository(file, this, child); - newRepositories.put(entrypath[depth], rep); - } - } - } - - repositories = (Repository[]) newRepositories.values() - .toArray(new Repository[newRepositories.size()]); - resources = newResources; - - } catch (Exception ex) { - ex.printStackTrace(); - repositories = emptyRepositories; - if (resources == null) { - resources = new HashMap(); - } else { - resources.clear(); - } - - } finally { - try { - // unlocks the zip file in the underlying filesystem - zipfile.close(); - } catch (Exception ex) {} - } - } - } - - private ZipEntry composeChildEntry(String name) { - if (entryPath == null || entryPath.length() == 0) { - return new ZipEntry(name); - } else if (entryPath.endsWith("/")) { - return new ZipEntry(entryPath + name); - } else { - return new ZipEntry(entryPath + "/" + name); - } - } - - /** - * Called to create a child resource for this repository - */ - protected Resource createResource(String name) { - return new ZipResource(entryPath + "/" + name, this); - } - - public long getChecksum() { - return file.lastModified(); - } - - public boolean exists() { - ZipFile zipfile = null; - try { - /* a ZipFile needs to be created to see if the zip file actually - exists; this is not cached to provide blocking the zip file in - the underlying filesystem */ - zipfile = getZipFile(); - return true; - } catch (IOException ex) { - return false; - } - finally { - try { - // unlocks the zip file in the underlying filesystem - zipfile.close(); - } catch (Exception ex) { - return false; - } - } - } - - public void create() { - // we do not create zip files as it makes no sense - throw new UnsupportedOperationException("create() not implemented for ZipRepository"); - } - - /** - * Checks wether the repository is to be considered a top-level - * repository from a scripting point of view. For example, a zip - * file within a file repository is not a root repository from - * a physical point of view, but from the scripting point of view it is. - * - * @return true if the repository is to be considered a top-level script repository - */ - public boolean isScriptRoot() { - return depth == 0; - } - - public long lastModified() { - return file.lastModified(); - } - - public int hashCode() { - return 17 + (37 * file.hashCode()) + (37 * name.hashCode()); - } - - public boolean equals(Object obj) { - if (!(obj instanceof ZipRepository)) { - return false; - } - - ZipRepository rep = (ZipRepository) obj; - return (file.equals(rep.file) && name.equals(rep.name)); - } - - public String toString() { - return new StringBuffer("ZipRepository[").append(name).append("]").toString(); - } - -} diff --git a/src/main/java/helma/framework/repository/ZipResource.java b/src/main/java/helma/framework/repository/ZipResource.java deleted file mode 100644 index cb607530..00000000 --- a/src/main/java/helma/framework/repository/ZipResource.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.framework.repository; - -import java.io.*; -import java.net.URL; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public final class ZipResource extends AbstractResource { - - private String entryName; - private ZipRepository repository; - private String name; - private String shortName; - private String baseName; - - protected ZipResource(String zipentryName, ZipRepository repository) { - this.entryName = zipentryName; - this.repository = repository; - - int lastSlash = entryName.lastIndexOf('/'); - - shortName = entryName.substring(lastSlash + 1); - name = new StringBuffer(repository.getName()).append('/') - .append(shortName).toString(); - - // base name is short name with extension cut off - int lastDot = shortName.lastIndexOf("."); - baseName = (lastDot == -1) ? shortName : shortName.substring(0, lastDot); - } - - public long lastModified() { - return repository.lastModified(); - } - - public InputStream getInputStream() throws IOException { - ZipFile zipfile = null; - try { - zipfile = repository.getZipFile(); - ZipEntry entry = zipfile.getEntry(entryName); - if (entry == null) { - throw new IOException("Zip resource " + this + " does not exist"); - } - int size = (int) entry.getSize(); - byte[] buf = new byte[size]; - InputStream in = zipfile.getInputStream(entry); - int read = 0; - while (read < size) { - int r = in.read(buf, read, size-read); - if (r == -1) - break; - read += r; - } - in.close(); - return new ByteArrayInputStream(buf); - } finally { - zipfile.close(); - } - } - - public boolean exists() { - ZipFile zipfile = null; - try { - zipfile = repository.getZipFile(); - return (zipfile.getEntry(entryName) != null); - } catch (Exception ex) { - return false; - } finally { - try { - zipfile.close(); - } catch (Exception ex) {} - } - } - - public String getContent(String encoding) throws IOException { - ZipFile zipfile = null; - try { - zipfile = repository.getZipFile(); - ZipEntry entry = zipfile.getEntry(entryName); - if (entry == null) { - throw new IOException("Zip resource " + this + " does not exist"); - } - InputStream in = zipfile.getInputStream(entry); - int size = (int) entry.getSize(); - byte[] buf = new byte[size]; - int read = 0; - while (read < size) { - int r = in.read(buf, read, size-read); - if (r == -1) - break; - read += r; - } - in.close(); - return encoding == null ? - new String(buf) : - new String(buf, encoding); - } finally { - if (zipfile != null) { - zipfile.close(); - } - } - } - - public String getContent() throws IOException { - return getContent(null); - } - - public String getName() { - return name; - } - - public String getShortName() { - return shortName; - } - - public String getBaseName() { - return baseName; - } - - public URL getUrl() { - // TODO: we might want to return a Jar URL - // http://java.sun.com/j2se/1.5.0/docs/api/java/net/JarURLConnection.html - throw new UnsupportedOperationException("getUrl() not implemented for ZipResource"); - } - - public long getLength() { - ZipFile zipfile = null; - try { - zipfile = repository.getZipFile(); - return zipfile.getEntry(entryName).getSize(); - } catch (Exception ex) { - return 0; - } finally { - try { - zipfile.close(); - } catch (Exception ex) {} - } - } - - public Repository getRepository() { - return repository; - } - - public int hashCode() { - return 17 + name.hashCode(); - } - - public boolean equals(Object obj) { - return obj instanceof ZipResource && name.equals(((ZipResource) obj).name); - } - - public String toString() { - return getName(); - } -} diff --git a/src/main/java/helma/image/ColorQuantizer.java b/src/main/java/helma/image/ColorQuantizer.java deleted file mode 100644 index d7882311..00000000 --- a/src/main/java/helma/image/ColorQuantizer.java +++ /dev/null @@ -1,622 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.image; - -import java.awt.AlphaComposite; -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; -import java.awt.image.DataBufferByte; -import java.awt.image.DataBufferInt; -import java.awt.image.IndexColorModel; - -/* - * Modifications by Juerg Lehni: - * - * - Ported to Java from C - * - Support for alpha-channels. - * - Returns a BufferedImage of TYPE_BYTE_INDEXED with a IndexColorModel. - * - Dithering of images through helma.image.DiffusionFilterOp by setting - * the dither parameter to true. - * - Support for a transparent color, which is correctly rendered by GIFEncoder. - * All pixels with alpha < 0x80 are converted to this color when the parameter - * alphaToBitmask is set to true. - */ -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % -% QQQ U U AAA N N TTTTT IIIII ZZZZZ EEEEE % -% Q Q U U A A NN N T I ZZ E % -% Q Q U U AAAAA N N N T I ZZZ EEEEE % -% Q QQ U U A A N NN T I ZZ E % -% QQQQ UUU A A N N T IIIII ZZZZZ EEEEE % -% % -% % -% Methods to Reduce the Number of Unique Colors in an Image % -% % -% % -% Software Design % -% John Cristy % -% July 1992 % -% % -% % -% Copyright (C) 2003 ImageMagick Studio, a non-profit organization dedicated % -% to making software imaging solutions freely available. % -% % -% Permission is hereby granted, free of charge, to any person obtaining a % -% copy of this software and associated documentation files ("ImageMagick"), % -% to deal in ImageMagick without restriction, including without limitation % -% the rights to use, copy, modify, merge, publish, distribute, sublicense, % -% and/or sell copies of ImageMagick, and to permit persons to whom the % -% ImageMagick is furnished to do so, subject to the following conditions: % -% % -% The above copyright notice and this permission notice shall be included in % -% all copies or substantial portions of ImageMagick. % -% % -% The software is provided "as is", without warranty of any kind, express or % -% implied, including but not limited to the warranties of merchantability, % -% fitness for a particular purpose and noninfringement. In no event shall % -% ImageMagick Studio be liable for any claim, damages or other liability, % -% whether in an action of contract, tort or otherwise, arising from, out of % -% or in connection with ImageMagick or the use or other dealings in % -% ImageMagick. % -% % -% Except as contained in this notice, the name of the ImageMagick Studio % -% shall not be used in advertising or otherwise to promote the sale, use or % -% other dealings in ImageMagick without prior written authorization from the % -% ImageMagick Studio. % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% Realism in computer graphics typically requires using 24 bits/pixel to -% generate an image. Yet many graphic display devices do not contain the -% amount of memory necessary to match the spatial and color resolution of -% the human eye. The Quantize methods takes a 24 bit image and reduces -% the number of colors so it can be displayed on raster device with less -% bits per pixel. In most instances, the quantized image closely -% resembles the original reference image. -% -% A reduction of colors in an image is also desirable for image -% transmission and real-time animation. -% -% QuantizeImage() takes a standard RGB or monochrome images and quantizes -% them down to some fixed number of colors. -% -% For purposes of color allocation, an image is a set of n pixels, where -% each pixel is a point in RGB space. RGB space is a 3-dimensional -% vector space, and each pixel, Pi, is defined by an ordered triple of -% red, green, and blue coordinates, (Ri, Gi, Bi). -% -% Each primary color component (red, green, or blue) represents an -% intensity which varies linearly from 0 to a maximum value, Cmax, which -% corresponds to full saturation of that color. Color allocation is -% defined over a domain consisting of the cube in RGB space with opposite -% vertices at (0,0,0) and (Cmax, Cmax, Cmax). QUANTIZE requires Cmax = -% 255. -% -% The algorithm maps this domain onto a tree in which each node -% represents a cube within that domain. In the following discussion -% these cubes are defined by the coordinate of two opposite vertices: -% The vertex nearest the origin in RGB space and the vertex farthest from -% the origin. -% -% The tree's root node represents the the entire domain, (0,0,0) through -% (Cmax,Cmax,Cmax). Each lower level in the tree is generated by -% subdividing one node's cube into eight smaller cubes of equal size. -% This corresponds to bisecting the parent cube with planes passing -% through the midpoints of each edge. -% -% The basic algorithm operates in three phases: Classification, -% Reduction, and Assignment. Classification builds a color description -% tree for the image. Reduction collapses the tree until the number it -% represents, at most, the number of colors desired in the output image. -% Assignment defines the output image's color map and sets each pixel's -% color by restorage_class in the reduced tree. Our goal is to minimize -% the numerical discrepancies between the original colors and quantized -% colors (quantization error). -% -% Classification begins by initializing a color description tree of -% sufficient depth to represent each possible input color in a leaf. -% However, it is impractical to generate a fully-formed color description -% tree in the storage_class phase for realistic values of Cmax. If -% colors components in the input image are quantized to k-bit precision, -% so that Cmax= 2k-1, the tree would need k levels below the root node to -% allow representing each possible input color in a leaf. This becomes -% prohibitive because the tree's total number of nodes is 1 + -% sum(i=1, k, 8k). -% -% A complete tree would require 19,173,961 nodes for k = 8, Cmax = 255. -% Therefore, to avoid building a fully populated tree, QUANTIZE: (1) -% Initializes data structures for nodes only as they are needed; (2) -% Chooses a maximum depth for the tree as a function of the desired -% number of colors in the output image (currently log2(colormap size)). -% -% For each pixel in the input image, storage_class scans downward from -% the root of the color description tree. At each level of the tree it -% identifies the single node which represents a cube in RGB space -% containing the pixel's color. It updates the following data for each -% such node: -% -% n1: Number of pixels whose color is contained in the RGB cube which -% this node represents; -% -% n2: Number of pixels whose color is not represented in a node at -% lower depth in the tree; initially, n2 = 0 for all nodes except -% leaves of the tree. -% -% Sr, Sg, Sb: Sums of the red, green, and blue component values for all -% pixels not classified at a lower depth. The combination of these sums -% and n2 will ultimately characterize the mean color of a set of -% pixels represented by this node. -% -% E: The distance squared in RGB space between each pixel contained -% within a node and the nodes' center. This represents the -% quantization error for a node. -% -% Reduction repeatedly prunes the tree until the number of nodes with n2 -% > 0 is less than or equal to the maximum number of colors allowed in -% the output image. On any given iteration over the tree, it selects -% those nodes whose E count is minimal for pruning and merges their color -% statistics upward. It uses a pruning threshold, Ep, to govern node -% selection as follows: -% -% Ep = 0 -% while number of nodes with (n2 > 0) > required maximum number of colors -% prune all nodes such that E <= Ep -% Set Ep to minimum E in remaining nodes -% -% This has the effect of minimizing any quantization error when merging -% two nodes together. -% -% When a node to be pruned has offspring, the pruning procedure invokes -% itself recursively in order to prune the tree from the leaves upward. -% n2, Sr, Sg, and Sb in a node being pruned are always added to the -% corresponding data in that node's parent. This retains the pruned -% node's color characteristics for later averaging. -% -% For each node, n2 pixels exist for which that node represents the -% smallest volume in RGB space containing those pixel's colors. When n2 -% > 0 the node will uniquely define a color in the output image. At the -% beginning of reduction, n2 = 0 for all nodes except a the leaves of -% the tree which represent colors present in the input image. -% -% The other pixel count, n1, indicates the total number of colors within -% the cubic volume which the node represents. This includes n1 - n2 -% pixels whose colors should be defined by nodes at a lower level in the -% tree. -% -% Assignment generates the output image from the pruned tree. The output -% image consists of two parts: (1) A color map, which is an array of -% color descriptions (RGB triples) for each color present in the output -% image; (2) A pixel array, which represents each pixel as an index -% into the color map array. -% -% First, the assignment phase makes one pass over the pruned color -% description tree to establish the image's color map. For each node -% with n2 > 0, it divides Sr, Sg, and Sb by n2 . This produces the mean -% color of all pixels that classify no lower than this node. Each of -% these colors becomes an entry in the color map. -% -% Finally, the assignment phase reclassifies each pixel in the pruned -% tree to identify the deepest node containing the pixel's color. The -% pixel's value in the pixel array becomes the index of this node's mean -% color in the color map. -% -% This method is based on a similar algorithm written by Paul Raveling. -% -% -*/ - -public class ColorQuantizer { - public static final int MAX_NODES = 266817; - public static final int MAX_TREE_DEPTH = 8; - public static final int MAX_CHILDREN = 16; - public static final int MAX_RGB = 255; - - static class ClosestColor { - int distance; - int colorIndex; - } - - static class Node { - Cube cube; - Node parent; - Node children[]; - int numChildren; - - int id; - int level; - - int uniqueCount; - - int totalRed; - int totalGreen; - int totalBlue; - int totalAlpha; - long quantizeError; - - int colorIndex; - - Node(Cube cube) { - this(cube, 0, 0, null); - this.parent = this; - } - - Node(Cube cube, int id, int level, Node parent) { - this.cube = cube; - this.parent = parent; - this.id = id; - this.level = level; - this.children = new Node[MAX_CHILDREN]; - this.numChildren = 0; - if (parent != null) { - parent.children[id] = this; - parent.numChildren++; - } - cube.numNodes++; - } - - void pruneLevel() { - // Traverse any children. - if (numChildren > 0) - for (int id = 0; id < MAX_CHILDREN; id++) - if (children[id] != null) - children[id].pruneLevel(); - if (level == cube.depth) - prune(); - } - - void pruneToCubeDepth() { - // Traverse any children. - if (numChildren > 0) - for (int id = 0; id < MAX_CHILDREN; id++) - if (children[id] != null) - children[id].pruneToCubeDepth(); - if (level > cube.depth) - prune(); - } - - void prune() { - // Traverse any children. - if (numChildren > 0) - for (int id = 0; id < MAX_CHILDREN; id++) - if (children[id] != null) - children[id].prune(); - // Merge color statistics into parent. - parent.uniqueCount += uniqueCount; - parent.totalRed += totalRed; - parent.totalGreen += totalGreen; - parent.totalBlue += totalBlue; - parent.totalAlpha += totalAlpha; - parent.children[id] = null; - parent.numChildren--; - cube.numNodes--; - } - - void reduce(long pruningThreshold) { - // Traverse any children. - if (numChildren > 0) - for (int id = 0; id < MAX_CHILDREN; id++) - if (children[id] != null) - children[id].reduce(pruningThreshold); - if (quantizeError <= pruningThreshold) - prune(); - else { - // Find minimum pruning threshold. - if (uniqueCount > 0) - cube.numColors++; - if (quantizeError < cube.nextThreshold) - cube.nextThreshold = quantizeError; - } - } - - void findClosestColor(int red, int green, int blue, int alpha, ClosestColor closest) { - // Traverse any children. - if (numChildren > 0) - for (int id = 0; id < MAX_CHILDREN; id++) - if (children[id] != null) - children[id].findClosestColor(red, green, blue, alpha, closest); - if (uniqueCount != 0) { - // Determine if this color is "closest". - int dr = (cube.colorMap[0][colorIndex] & 0xff) - red; - int dg = (cube.colorMap[1][colorIndex] & 0xff) - green; - int db = (cube.colorMap[2][colorIndex] & 0xff) - blue; - int da = (cube.colorMap[3][colorIndex] & 0xff) - alpha; - int distance = da * da + dr * dr + dg * dg + db * db; - if (distance < closest.distance) { - closest.distance = distance; - closest.colorIndex = colorIndex; - } - } - } - - int fillColorMap(byte colorMap[][], int index) { - // Traverse any children. - if (numChildren > 0) - for (int id = 0; id < MAX_CHILDREN; id++) - if (children[id] != null) - index = children[id].fillColorMap(colorMap, index); - if (uniqueCount != 0) { - // Colormap entry is defined by the mean color in this cube. - colorMap[0][index] = (byte) (totalRed / uniqueCount + 0.5); - colorMap[1][index] = (byte) (totalGreen / uniqueCount + 0.5); - colorMap[2][index] = (byte) (totalBlue / uniqueCount + 0.5); - colorMap[3][index] = (byte) (totalAlpha / uniqueCount + 0.5); - colorIndex = index++; - } - return index; - } - } - - static class Cube { - Node root; - - int numColors; - boolean addTransparency; - // firstColor is set to 1 when when addTransparency is true! - int firstColor; - byte colorMap[][]; - - long nextThreshold; - - int numNodes; - int depth; - - Cube(int maxColors) { - this.depth = getDepth(maxColors); - this.numColors = 0; - root = new Node(this); - } - - int getDepth(int numColors) { - // Depth of color tree is: Log4(colormap size)+2. - int depth; - for (depth = 1; numColors != 0; depth++) - numColors >>= 2; - if (depth > MAX_TREE_DEPTH) - depth = MAX_TREE_DEPTH; - if (depth < 2) - depth = 2; - return depth; - } - - void classifyImageColors(BufferedImage image, boolean alphaToBitmask) { - addTransparency = false; - firstColor = 0; - - Node node, child; - int x, px, y, index, level, id, count; - int pixel, red, green, blue, alpha; - int bisect, midRed, midGreen, midBlue, midAlpha; - - int width = image.getWidth(); - int height = image.getHeight(); - - // Classify the first 256 colors to a tree depth of MAX_TREE_DEPTH. - int levelThreshold = MAX_TREE_DEPTH; - // create a BufferedImage of only 1 pixel height for fetching the rows - // of the image in the correct format (ARGB) - // This speeds up things by more than factor 2, compared to the standard - // BufferedImage.getRGB solution - BufferedImage row = new BufferedImage(width, 1, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = row.createGraphics(); - int pixels[] = ((DataBufferInt) row.getRaster().getDataBuffer()).getData(); - // make sure alpha values do not add up for each row: - g2d.setComposite(AlphaComposite.Src); - // calculate scanline by scanline in order to safe memory. - // It also seems to run faster like that - for (y = 0; y < height; y++) { - g2d.drawImage(image, null, 0, -y); - // now pixels contains the rgb values of the row y! - if (numNodes > MAX_NODES) { - // Prune one level if the color tree is too large. - root.pruneLevel(); - depth--; - } - for (x = 0; x < width;) { - pixel = pixels[x]; - red = (pixel >> 16) & 0xff; - green = (pixel >> 8) & 0xff; - blue = (pixel >> 0) & 0xff; - alpha = (pixel >> 24) & 0xff; - if (alphaToBitmask) - alpha = alpha < 0x80 ? 0 : 0xff; - - // skip same pixels, but count them - px = x; - for (++x; x < width; x++) - if (pixels[x] != pixel) - break; - count = x - px; - - // Start at the root and descend the color cube tree. - if (alpha > 0) { - index = MAX_TREE_DEPTH - 1; - bisect = (MAX_RGB + 1) >> 1; - midRed = bisect; - midGreen = bisect; - midBlue = bisect; - midAlpha = bisect; - node = root; - for (level = 1; level <= levelThreshold; level++) { - id = (((red >> index) & 0x01) << 3 | - ((green >> index) & 0x01) << 2 | - ((blue >> index) & 0x01) << 1 | - ((alpha >> index) & 0x01)); - bisect >>= 1; - midRed += (id & 8) != 0 ? bisect : -bisect; - midGreen += (id & 4) != 0 ? bisect : -bisect; - midBlue += (id & 2) != 0 ? bisect : -bisect; - midAlpha += (id & 1) != 0 ? bisect : -bisect; - child = node.children[id]; - if (child == null) { - // Set colors of new node to contain pixel. - child = new Node(this, id, level, node); - if (level == levelThreshold) { - numColors++; - if (numColors == 256) { - // More than 256 colors; classify to the - // cube_info.depth tree depth. - levelThreshold = depth; - root.pruneToCubeDepth(); - } - } - } - // Approximate the quantization error represented by - // this node. - node = child; - int r = red - midRed; - int g = green - midGreen; - int b = blue - midBlue; - int a = alpha - midAlpha; - node.quantizeError += count * (r * r + g * g + b * b + a * a); - root.quantizeError += node.quantizeError; - index--; - } - // Sum RGB for this leaf for later derivation of the mean - // cube color. - node.uniqueCount += count; - node.totalRed += count * red; - node.totalGreen += count * green; - node.totalBlue += count * blue; - node.totalAlpha += count * alpha; - } else if (!addTransparency) { - addTransparency = true; - numColors++; - firstColor = 1; // start at 1 as 0 will be the transparent color - } - } - } - } - - void reduceImageColors(int maxColors) { - nextThreshold = 0; - while (numColors > maxColors) { - long pruningThreshold = nextThreshold; - nextThreshold = root.quantizeError - 1; - numColors = firstColor; - root.reduce(pruningThreshold); - } - } - - BufferedImage assignImageColors(BufferedImage image, boolean dither, boolean alphaToBitmask) { - // Allocate image colormap. - colorMap = new byte[4][numColors]; - root.fillColorMap(colorMap, firstColor); - // create the right color model, depending on transparency settings: - IndexColorModel icm; - - int width = image.getWidth(); - int height = image.getHeight(); - - if (alphaToBitmask) { - if (addTransparency) { - icm = new IndexColorModel(depth, numColors, colorMap[0], colorMap[1], colorMap[2], 0); - } else { - icm = new IndexColorModel(depth, numColors, colorMap[0], colorMap[1], colorMap[2]); - } - } else { - icm = new IndexColorModel(depth, numColors, colorMap[0], colorMap[1], colorMap[2], colorMap[3]); - } - - // create the indexed BufferedImage: - BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, icm); - - if (dither) - new DiffusionFilterOp().filter(image, dest); - else { - ClosestColor closest = new ClosestColor(); - // convert to indexed color - byte[] dst = ((DataBufferByte) dest.getRaster().getDataBuffer()).getData(); - - // create a BufferedImage of only 1 pixel height for fetching - // the rows of the image in the correct format (ARGB) - // This speeds up things by more than factor 2, compared to the - // standard BufferedImage.getRGB solution - BufferedImage row = new BufferedImage(width, 1, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = row.createGraphics(); - int pixels[] = ((DataBufferInt) row.getRaster().getDataBuffer()).getData(); - // make sure alpha values do not add up for each row: - g2d.setComposite(AlphaComposite.Src); - // calculate scanline by scanline in order to safe memory. - // It also seems to run faster like that - Node node; - int x, y, i, id; - int pixel, red, green, blue, alpha; - int pos = 0; - for (y = 0; y < height; y++) { - g2d.drawImage(image, null, 0, -y); - // now pixels contains the rgb values of the row y! - // filter this row now: - for (x = 0; x < width;) { - pixel = pixels[x]; - red = (pixel >> 16) & 0xff; - green = (pixel >> 8) & 0xff; - blue = (pixel >> 0) & 0xff; - alpha = (pixel >> 24) & 0xff; - - if (alphaToBitmask) - alpha = alpha < 128 ? 0 : 0xff; - - byte col; - if (alpha == 0 && addTransparency) { - col = 0; // transparency color is at position 0 of color map - } else { - // walk the tree to find the cube containing that - // color - node = root; - for (i = MAX_TREE_DEPTH - 1; i > 0; i--) { - id = (((red >> i) & 0x01) << 3 | - ((green >> i) & 0x01) << 2 | - ((blue >> i) & 0x01) << 1 | - ((alpha >> i) & 0x01)); - if (node.children[id] == null) - break; - node = node.children[id]; - } - - // Find the closest color. - closest.distance = Integer.MAX_VALUE; - node.parent.findClosestColor(red, green, blue, alpha, closest); - col = (byte) closest.colorIndex; - } - - // first color - dst[pos++] = col; - - // next colors the same? - for (++x; x < width; x++) { - if (pixels[x] != pixel) - break; - dst[pos++] = col; - } - } - } - } - return dest; - } - } - - static BufferedImage quantizeImage(BufferedImage image, int maxColors, boolean dither, boolean alphaToBitmask) { - Cube cube = new Cube(maxColors); - cube.classifyImageColors(image, alphaToBitmask); - cube.reduceImageColors(maxColors); - return cube.assignImageColors(image, dither, alphaToBitmask); - } - -} diff --git a/src/main/java/helma/image/DiffusionFilterOp.java b/src/main/java/helma/image/DiffusionFilterOp.java deleted file mode 100644 index cbc31ce6..00000000 --- a/src/main/java/helma/image/DiffusionFilterOp.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -/* - * DiffusionFilter code from com.jhlabs.image.DiffusionFilter, Java Image Processing - * Copyright (C) Jerry Huxtable 1998 - * http://www.jhlabs.com/ip/ - * - * Conversion to a BufferedImageOp inspired by: - * http://www.peter-cockerell.net:8080/java/FloydSteinberg/FloydSteinbergFilterOp.java - * - */ - -package helma.image; - -import java.awt.*; -import java.awt.geom.*; -import java.awt.image.*; - -public class DiffusionFilterOp implements BufferedImageOp { - - protected final static int[] diffusionMatrix = { - 0, 0, 0, - 0, 0, 7, - 3, 5, 1, - }; - - private int[] matrix; - private int sum; - private boolean serpentine = true; - private int[] colorMap; - - /** - * Construct a DiffusionFilter - */ - public DiffusionFilterOp() { - setMatrix(diffusionMatrix); - } - - /** - * Set whether to use a serpentine pattern for return or not. - * This can reduce 'avalanche' artifacts in the output. - * @param serpentine true to use serpentine pattern - */ - public void setSerpentine(boolean serpentine) { - this.serpentine = serpentine; - } - - /** - * Return the serpentine setting - * @return the current setting - */ - public boolean getSerpentine() { - return serpentine; - } - - public void setMatrix(int[] matrix) { - this.matrix = matrix; - sum = 0; - for (int i = 0; i < matrix.length; i++) - sum += matrix[i]; - } - - public int[] getMatrix() { - return matrix; - } - - /** - * Do the filter operation - * - * @param src The source BufferedImage. Can be any type. - * @param dst The destination image. If not null, must be of type TYPE_BYTE_INDEXED - * @return A dithered version of src in a BufferedImage of type TYPE_BYTE_INDEXED - */ - public BufferedImage filter(BufferedImage src, BufferedImage dst) { - - // If there's no dest. create one - if (dst == null) - dst = createCompatibleDestImage(src, null); - - // Otherwise check that the provided dest is an indexed image - else if (dst.getType() != BufferedImage.TYPE_BYTE_INDEXED) { - throw new IllegalArgumentException("Wrong Destination Buffer type"); - } - - DataBufferByte dstBuffer = (DataBufferByte) dst.getRaster().getDataBuffer(); - byte dstData[] = dstBuffer.getData(); - - // Other things to test are pixel bit strides, scanline stride and transfer type - // Same goes for the source image - - IndexColorModel icm = (IndexColorModel) dst.getColorModel(); - colorMap = new int[icm.getMapSize()]; - icm.getRGBs(colorMap); - - int width = src.getWidth(); - int height = src.getHeight(); - - // This is the offset into the buffer of the current source pixel - int index = 0; - - // Loop through each pixel - // create a BufferedImage of only 1 pixel height for fetching the rows - // of the image in the correct format (ARGB) - // This speeds up things by more than factor 2, compared to the standard - // BufferedImage.getRGB solution - BufferedImage row = new BufferedImage(width, 1, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = row.createGraphics(); - int pixels[] = ((DataBufferInt) row.getRaster().getDataBuffer()).getData(); - // make sure alpha values do not add up for each row: - g2d.setComposite(AlphaComposite.Src); - // calculate scanline by scanline in order to safe memory. - // It also seems to run faster like that - int rowIndex = 0; - for (int y = 0; y < height; y++, rowIndex += width) { - g2d.drawImage(src, null, 0, -y); - // now pixels contains the rgb values of the row y! - boolean reverse = serpentine && (y & 1) == 1; - int direction; - if (reverse) { - index = width - 1; - direction = -1; - } else { - index = 0; - direction = 1; - } - for (int x = 0; x < width; x++) { - int rgb1 = pixels[index]; - int a1 = (rgb1 >> 24) & 0xff; - int r1 = (rgb1 >> 16) & 0xff; - int g1 = (rgb1 >> 8) & 0xff; - int b1 = rgb1 & 0xff; - - int idx = findIndex(r1, g1, b1, a1); - dstData[rowIndex + index] = (byte) idx; - - int rgb2 = colorMap[idx]; - int a2 = (rgb2 >> 24) & 0xff; - int r2 = (rgb2 >> 16) & 0xff; - int g2 = (rgb2 >> 8) & 0xff; - int b2 = rgb2 & 0xff; - - int er = r1 - r2; - int eg = g1 - g2; - int eb = b1 - b2; - int ea = a1 - a2; - - for (int i = -1; i <= 1; i++) { - int iy = i + y; - if (0 <= iy && iy < height) { - for (int j = -1; j <= 1; j++) { - int jx = j + x; - if (0 <= jx && jx < width) { - int w; - if (reverse) - w = matrix[(i + 1) * 3 - j + 1]; - else - w = matrix[(i + 1) * 3 + j + 1]; - if (w != 0) { - int k = reverse ? index - j : index + j; - rgb1 = pixels[k]; - a1 = ((rgb1 >> 24) & 0xff) + ea * w / sum; - r1 = ((rgb1 >> 16) & 0xff) + er * w / sum; - g1 = ((rgb1 >> 8) & 0xff) + eg * w / sum; - b1 = (rgb1 & 0xff) + eb * w / sum; - pixels[k] = - (clamp(a1) << 24) | - (clamp(r1) << 16) | - (clamp(g1) << 8) | - clamp(b1); - } - } - } - } - } - index += direction; - } - } - - return dst; - } - - private static int clamp(int c) { - if (c < 0) - return 0; - if (c > 255) - return 255; - return c; - } - - int findIndex(int r1, int g1, int b1, int a1) - throws ArrayIndexOutOfBoundsException { - int idx = 0; - int dist = Integer.MAX_VALUE; - for (int i = 0; i < colorMap.length; i++) { - int rgb2 = colorMap[i]; - int da = a1 - ((rgb2 >> 24) & 0xff); - int dr = r1 - ((rgb2 >> 16) & 0xff); - int dg = g1 - ((rgb2 >> 8) & 0xff); - int db = b1 - (rgb2 & 0xff); - int newdist = da * da + dr * dr + dg * dg + db * db; - if (newdist < dist) { - idx = i; - dist = newdist; - } - } - return idx; - } - - // This always returns an indexed image - public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM) { - return new BufferedImage(src.getWidth(), src.getHeight(), - BufferedImage.TYPE_BYTE_INDEXED); - } - - // There are no rendering hints - public RenderingHints getRenderingHints() { - return null; - } - - // No transformation, so return the source point - public Point2D getPoint2D(Point2D srcPt, Point2D dstPt) { - if (dstPt == null) - dstPt = new Point2D.Float(); - dstPt.setLocation(srcPt.getX(), srcPt.getY()); - return dstPt; - } - - // No transformation, so return the source bounds - public Rectangle2D getBounds2D(BufferedImage src) { - return src.getRaster().getBounds(); - } -} \ No newline at end of file diff --git a/src/main/java/helma/image/GIFEncoder.java b/src/main/java/helma/image/GIFEncoder.java deleted file mode 100644 index 7b2fca11..00000000 --- a/src/main/java/helma/image/GIFEncoder.java +++ /dev/null @@ -1,533 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -/* - * The GIF encoding routines are based on the Acme libary - * - * The following changes and extensions were added by Juerg Lehni: - * - * - encode now directly works on BufferedImage objects, the ImageEncoder - * and ImageConsumer oriented frameworks has been removed. - * - Only BufferedImages with IndexColorModel are taken, so no more - * palette optimization with IntHashtable objects are necessary. If the - * BufferedImage is in wrong format, helma.image.ColorQuantizer is used to - * convert it into a index based image. - * - This version is much less space consuming as it only takes one sample - * row of the rastered image at a time into memory during compression. - * - The overall time for color reduction and gif compression should - * therefore be greatly reduced. - * - * Acme Disclaimer: - * - * Transparency handling and variable bit size courtesy of Jack Palevich. - * - * Copyright (C)1996,1998 by Jef Poskanzer . All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Visit the ACME Labs Java page for up-to-date versions of this and other - * fine Java utilities: http://www.acme.com/java/ - * - * GifEncoder is adapted from ppmtogif, which is based on GIFENCOD by David - * Rowley . Lempel-Zim compression - * based on "compress". - * - */ - -package helma.image; - -import java.awt.image.BufferedImage; -import java.awt.image.IndexColorModel; -import java.awt.image.Raster; -import java.io.DataOutput; -import java.io.IOException; - -public class GIFEncoder { - private boolean interlace = false; - - private int width, height; - private Raster raster; - // DataOutput is used for compatibility with ImageIO (see helma.image.imageio.gif.GIFImageWriter) - // otherwise, OutputStream would make much more sense here: - private DataOutput out; - - private int curx, cury; - private int countdown; - private int pass; - private int[] row; - - public void encode(BufferedImage bi, DataOutput out) throws IOException { - encode(bi, out, false, null); - } - - public void encode(BufferedImage bi, DataOutput out, boolean interlace, - String comment) throws IOException { - this.out = out; - this.interlace = interlace; - - // make sure it's index colors: - if (bi.getType() != BufferedImage.TYPE_BYTE_INDEXED) - bi = ColorQuantizer.quantizeImage(bi, 256, false, true); - - raster = bi.getRaster(); - - width = bi.getWidth(); - height = bi.getHeight(); - - int numPixels = width * height; - - IndexColorModel icm = (IndexColorModel) bi.getColorModel(); - int transparentIndex = icm.getTransparentPixel(); - int numColors = icm.getMapSize(); - - // Figure out how many bits to use. - int bitsPerPixel; - if (numColors <= 2) - bitsPerPixel = 1; - else if (numColors <= 4) - bitsPerPixel = 2; - else if (numColors <= 16) - bitsPerPixel = 4; - else - bitsPerPixel = 8; - - int initCodeSize; - - // Calculate number of bits we are expecting - countdown = numPixels; - - // Indicate which pass we are on (if interlace) - pass = 0; - - // The initial code size - if (bitsPerPixel <= 1) - initCodeSize = 2; - else - initCodeSize = bitsPerPixel; - - // Set up the current x and y position - curx = 0; - cury = 0; - row = new int[width]; - - // Write the Magic header - writeString("GIF89a"); - - // Write out the screen width and height - writeWord(width); - writeWord(height); - - // Indicate that there is a global colour map - byte flags = (byte) 0x80; // Yes, there is a color map - // OR in the resolution - flags |= (byte) ((8 - 1) << 4); - // Not sorted - // OR in the Bits per Pixel - flags |= (byte) ((bitsPerPixel - 1)); - // Write it out - out.write(flags); - - // Write out the Background colour - out.write((byte) 0); - - // Pixel aspect ratio - 1:1. - //out.write((byte) 49); - // Java's GIF reader currently has a bug, if the aspect ratio byte is - // not zero it throws an ImageFormatException. It doesn't know that - // 49 means a 1:1 aspect ratio. Well, whatever, zero works with all - // the other decoders I've tried so it probably doesn't hurt. - out.write((byte) 0); - - // Write out the Global Colour Map - // Turn colors into colormap entries. - int mapSize = 1 << bitsPerPixel; - byte[] reds = new byte[mapSize], greens = new byte[mapSize], blues = new byte[mapSize]; - icm.getReds(reds); - icm.getGreens(greens); - icm.getBlues(blues); - - for (int i = 0; i < mapSize; ++i) { - out.write(reds[i]); - out.write(greens[i]); - out.write(blues[i]); - } - - // Write out extension for transparent colour index, if necessary. - if (transparentIndex != -1) { - out.write((byte) '!'); - out.write((byte) 0xf9); - out.write((byte) 4); - out.write((byte) 1); - out.write((byte) 0); - out.write((byte) 0); - out.write((byte) transparentIndex); - out.write((byte) 0); - } - - // Write an Image separator - out.write((byte) ','); - - // Write the Image header - writeWord(0); // leftOfs - writeWord(0); // topOfs - writeWord(width); - writeWord(height); - - // Write out whether or not the image is interlaced - if (interlace) - out.write((byte) 0x40); - else - out.write((byte) 0x00); - - // Write out the initial code size - out.write((byte) initCodeSize); - - // Go and actually compress the data - compress(initCodeSize + 1); - - // Write out a Zero-length packet (to end the series) - out.write((byte) 0); - - // Write out the comment - if (comment != null && comment.length() > 0) { - out.write((byte) 0x21); - out.write((byte) 0xFE); - out.write((byte) comment.length()); - writeString(comment); - out.write((byte) 0); - } - - // Write the GIF file terminator - out.write((byte) ';'); - } - - // Return the next pixel from the image - int getNextPixel() throws IOException { - if (countdown == 0) - return -1; - - --countdown; - - if (curx == 0) - row = raster.getSamples(0, cury, width, 1, 0, row); - int index = row[curx]; - - // Bump the current X position - ++curx; - - // If we are at the end of a scan line, set curx back to the beginning - // If we are interlaced, bump the cury to the appropriate spot, - // otherwise, just increment it. - if (curx == width) { - curx = 0; - - if (!interlace) { - ++cury; - } else { - switch (pass) { - case 0: - cury += 8; - if (cury >= height) { - ++pass; - cury = 4; - } - break; - - case 1: - cury += 8; - if (cury >= height) { - ++pass; - cury = 2; - } - break; - - case 2: - cury += 4; - if (cury >= height) { - ++pass; - cury = 1; - } - break; - - case 3: - cury += 2; - break; - } - } - } - return index; - } - - void writeString(String str) throws IOException { - byte[] buf = str.getBytes(); - out.write(buf); - } - - // Write out a word to the GIF file - void writeWord(int w) throws IOException { - out.write((byte) (w & 0xff)); - out.write((byte) ((w >> 8) & 0xff)); - } - - // GIFCOMPR.C - GIF Image compression routines - // - // Lempel-Ziv compression based on 'compress'. GIF modifications by - // David Rowley (mgardi@watdcsu.waterloo.edu) - - // General DEFINEs - - static final int BITS = 12; - - static final int HASH_SIZE = 5003; // 80% occupancy - - // GIF Image compression - modified 'compress' - // - // Based on: compress.c - File compression ala IEEE Computer, June 1984. - // - // By Authors: Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas) - // Jim McKie (decvax!mcvax!jim) - // Steve Davies (decvax!vax135!petsd!peora!srd) - // Ken Turkowski (decvax!decwrl!turtlevax!ken) - // James A. Woods (decvax!ihnp4!ames!jaw) - // Joe Orost (decvax!vax135!petsd!joe) - - private int numBits; // number of bits/code - private int maxBits = BITS; // user settable max # bits/code - private int maxCode; // maximum code, given numBits - private int maxMaxCode = 1 << BITS; // should NEVER generate this code - - final int getMaxCode(int numBits) { - return (1 << numBits) - 1; - } - - private int[] hashTable = new int[HASH_SIZE]; - private int[] codeTable = new int[HASH_SIZE]; - - private int freeEntry = 0; // first unused entry - - // block compression parameters -- after all codes are used up, - // and compression rate changes, start over. - private boolean clearFlag = false; - - // Algorithm: use open addressing double hashing (no chaining) on the - // prefix code / next character combination. We do a variant of Knuth's - // algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime - // secondary probe. Here, the modular division first probe is gives way - // to a faster exclusive-or manipulation. Also do block compression with - // an adaptive reset, whereby the code table is cleared when the compression - // ratio decreases, but after the table fills. The variable-length output - // codes are re-sized at this point, and a special CLEAR code is generated - // for the decompressor. Late addition: construct the table according to - // file size for noticeable speed improvement on small files. Please direct - // questions about this implementation to ames!jaw. - - private int initBits; - - private int clearCode; - private int EOFCode; - - void compress(int initBits) throws IOException { - // Set up the globals: initBits - initial number of bits - this.initBits = initBits; - - // Set up the necessary values - clearFlag = false; - numBits = initBits; - maxCode = getMaxCode(numBits); - - clearCode = 1 << (initBits - 1); - EOFCode = clearCode + 1; - freeEntry = clearCode + 2; - - charInit(); - - int ent = getNextPixel(); - - int hashShift = 0; - for (int fcode = HASH_SIZE; fcode < 65536; fcode *= 2) - ++hashShift; - hashShift = 8 - hashShift; // set hash code range bound - - clearHash(); // clear hash table - - output(clearCode); - - int c; - outerLoop: while ((c = getNextPixel()) != -1) { - int fcode = (c << maxBits) + ent; - int i = (c << hashShift) ^ ent; // xor hashing - - if (hashTable[i] == fcode) { - ent = codeTable[i]; - continue; - } else if (hashTable[i] >= 0) { // non-empty slot - int disp = HASH_SIZE - i; // secondary hash (after G. Knott) - if (i == 0) - disp = 1; - do { - if ((i -= disp) < 0) - i += HASH_SIZE; - - if (hashTable[i] == fcode) { - ent = codeTable[i]; - continue outerLoop; - } - } while (hashTable[i] >= 0); - } - output(ent); - ent = c; - if (freeEntry < maxMaxCode) { - codeTable[i] = freeEntry++; // code -> hashtable - hashTable[i] = fcode; - } else - clearBlock(); - } - // Put out the final code. - output(ent); - output(EOFCode); - } - - // output - // - // Output the given code. - // Inputs: - // code: A numBits-bit integer. If == -1, then EOF. This assumes - // that numBits =< wordsize - 1. - // Outputs: - // Outputs code to the file. - // Assumptions: - // Chars are 8 bits long. - // Algorithm: - // Maintain a BITS character long buffer (so that 8 codes will - // fit in it exactly). Use the VAX insv instruction to insert each - // code in turn. When the buffer fills up empty it and start over. - - int curAccum = 0; - int curBits = 0; - - int masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, - 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, - 0x7FFF, 0xFFFF }; - - void output(int code) throws IOException { - curAccum &= masks[curBits]; - - if (curBits > 0) - curAccum |= (code << curBits); - else - curAccum = code; - - curBits += numBits; - - while (curBits >= 8) { - charOut((byte) (curAccum & 0xff)); - curAccum >>= 8; - curBits -= 8; - } - - // If the next entry is going to be too big for the code size, - // then increase it, if possible. - if (freeEntry > maxCode || clearFlag) { - if (clearFlag) { - maxCode = getMaxCode(numBits = initBits); - clearFlag = false; - } else { - ++numBits; - if (numBits == maxBits) - maxCode = maxMaxCode; - else - maxCode = getMaxCode(numBits); - } - } - - if (code == EOFCode) { - // At EOF, write the rest of the buffer. - while (curBits > 0) { - charOut((byte) (curAccum & 0xff)); - curAccum >>= 8; - curBits -= 8; - } - - charFlush(); - } - } - - // Clear out the hash table - - // table clear for block compress - void clearBlock() throws IOException { - clearHash(); - freeEntry = clearCode + 2; - clearFlag = true; - - output(clearCode); - } - - // reset code table - void clearHash() { - for (int i = 0; i < HASH_SIZE; ++i) - hashTable[i] = -1; - } - - // GIF Specific routines - - // Number of characters so far in this 'packet' - private int a_count; - - // Set up the 'byte output' routine - void charInit() { - a_count = 0; - } - - // Define the storage for the packet accumulator - private byte[] accum = new byte[256]; - - // Add a character to the end of the current packet, and if it is 254 - // characters, flush the packet to disk. - void charOut(byte c) throws IOException { - accum[a_count++] = c; - if (a_count >= 254) - charFlush(); - } - - // Flush the packet to disk, and reset the accumulator - void charFlush() throws IOException { - if (a_count > 0) { - out.write(a_count); - out.write(accum, 0, a_count); - a_count = 0; - } - } -} \ No newline at end of file diff --git a/src/main/java/helma/image/ImageFilterOp.java b/src/main/java/helma/image/ImageFilterOp.java deleted file mode 100644 index 7d9b6e5e..00000000 --- a/src/main/java/helma/image/ImageFilterOp.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License Version 2.0 (the - * "License"). You may not use this file except in compliance with the License. - * A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -/** - * This class does pretty much the opposite of java.awt.image.BufferedImageFilter: - * It wraps an ImageFilter in a BufferedImageOp - * Optimizations have been added, like the ignoring of color models - * and the assumption of INT_RGB type for destination buffers in - * order to speed things up by almost a factor of 4. - */ - -package helma.image; - -import java.awt.*; -import java.awt.geom.*; -import java.awt.image.*; -import java.util.Hashtable; - -public class ImageFilterOp implements BufferedImageOp { - ImageFilter filter; - - /** - * Construct a ImageFilterOp - */ - public ImageFilterOp(ImageFilter filter) { - this.filter = filter; - } - - /** - * Do the filter operation - * - * @param src The source BufferedImage. Can be any type. - * @param dst The destination image. If not null, must be of type - * TYPE_INT_RGB, TYPE_INT_ARGB or TYPE_INT_ARGB_PRE - * @return the filtered image - */ - public BufferedImage filter(BufferedImage src, BufferedImage dst) { - int width = src.getWidth(); - int height = src.getHeight(); - - BufferedImageConsumer consumer = new BufferedImageConsumer(dst); - - ImageFilter fltr = filter.getFilterInstance(consumer); - fltr.setDimensions(width, height); - - /* - ColorModel cm = src.getColorModel(); - if (cm.getPixelSize() == 8) { - // byte. indexed or gray: - WritableRaster raster = src.getRaster(); - byte pixels[] = new byte[width]; - // calculate scanline by scanline in order to safe memory. - // It also seems to run faster like that - for (int y = 0; y < height; y++) { - raster.getDataElements(0, y, width, 1, pixels); - fltr.setPixels(0, y, width, 1, cm, pixels, 0, width); - } - } else { - // integer, use the simple rgb mode: - WritableRaster raster = src.getRaster(); - int pixels[] = new int[width]; - // calculate scanline by scanline in order to safe memory. - // It also seems to run faster like that - for (int y = 0; y < height; y++) { - raster.getDataElements(0, y, width, 1, pixels); - fltr.setPixels(0, y, width, 1, cm, pixels, 0, width); - } - } - */ - - // Always work in integer mode. this is more effective, and most - // filters convert to integer internally anyhow - ColorModel cm = new SimpleColorModel(); - - // Create a BufferedImage of only 1 pixel height for fetching the rows of the image in the correct format (ARGB) - // This speeds up things by more than factor 2, compared to the standard BufferedImage.getRGB solution, - // which is supposed to be fast too. This is probably the case because drawing to BufferedImages uses - // very optimized code which may even be hardware accelerated. - BufferedImage row = new BufferedImage(width, 1, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = row.createGraphics(); - int pixels[] = ((DataBufferInt)row.getRaster().getDataBuffer()).getData(); - - // Make sure alpha values do not add up for each row: - g2d.setComposite(AlphaComposite.Src); - // Calculate scanline by scanline in order to safe memory. - // It also seems to run faster like that - for (int y = 0; y < height; y++) { - g2d.drawImage(src, null, 0, -y); - // Now pixels contains the rgb values of the row y! - // filter this row now: - fltr.setPixels(0, y, width, 1, cm, pixels, 0, width); - } - g2d.dispose(); - // The consumer now contains the filtered image, return it. - return consumer.getImage(); - } - - public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM) { - return null; - } - - public RenderingHints getRenderingHints() { - return null; - } - - public Point2D getPoint2D(Point2D srcPt, Point2D dstPt) { - return null; - } - - public Rectangle2D getBounds2D(BufferedImage src) { - return null; - } - - /** - * This is a dummy ColorModel that does nothing else than returning an - * unchanged rgb value in getRGB, getRed, getGreen, getBlue, getAlpha. - * This speeds up things for BufferedImages by at least a factor 1.5! - */ - class SimpleColorModel extends ColorModel { - public SimpleColorModel() { - this(32); - } - - public SimpleColorModel(int bits) { - super(bits); - } - - public int getRGB(int rgb) { - // This is the part that speeds up most. - // java.awt.image.ColorModel would return the same value, but with - // 4 function calls and a lot of shifts and ors per color! - return rgb; - } - - public int getAlpha(int pixel) { - return pixel >> 24; - } - - public int getRed(int pixel) { - return (pixel >> 16) & 0xff; - } - - public int getGreen(int pixel) { - return (pixel >> 8) & 0xff; - } - - public int getBlue(int pixel) { - return pixel & 0xff; - } - } - - /** - * This is a dummy ImageConsumser that does nothing else than writing - * The resulting rows from the ImageFilter into the image - * If the image was not specified in the constructor, setDimensions - * creates it with the given dimensions. - */ - class BufferedImageConsumer implements ImageConsumer { - BufferedImage image; - BufferedImage compatible; - int width; - int height; - boolean first = true; - - /* - * Constructor with no compatible image. if image is null, setDimensions - * will create a default INT_ARGB image of the size defined by the filter. - */ - public BufferedImageConsumer(BufferedImage image) { - this(image, null); - } - - /* - * Constructor with a compatible image. if image is null, setDimensions - * will create a compatible image of the size defined by the filter. - */ - public BufferedImageConsumer(BufferedImage image, BufferedImage compatible) { - this.image = image; - this.compatible = compatible; - } - - public BufferedImage getImage() { - return image; - } - - public void setDimensions(int w, int h) { - if (image == null) { - if (compatible != null) { - // create a compatible image with the new dimensions: - image = new BufferedImage( - compatible.getColorModel(), - compatible.getRaster().createCompatibleWritableRaster(w, h), - compatible.isAlphaPremultiplied(), - null - ); - } else { - // assume standard format: - image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); - } - } - width = image.getWidth(); - height = image.getHeight(); - } - - public void setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize) { - // Cropping may be necessary: It's possible that the size of the - // specified destination image is not the same as the size the - // ImageFilter would produce! - if (x < width && y < height) { - if (x + w > width) - w = width - x; - if (y + h > height) - h = height - y; - - if (w > 0 && h > 0) - image.setRGB(x, y, w, h, pixels, off, scansize); - } - } - - public void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize) { - if (x < width && y < height) { - if (x + w > width) - w = width - x; - if (y + h > height) - h = height - y; - - if (w > 0 && h > 0) - image.getRaster().setDataElements(x, y, w, h, pixels); - } - } - - public void setProperties(Hashtable props) { - } - - public void setColorModel(ColorModel model) { - } - - public void setHints(int hintflags) { - } - - public void imageComplete(int status) { - } - } -} \ No newline at end of file diff --git a/src/main/java/helma/image/ImageGenerator.java b/src/main/java/helma/image/ImageGenerator.java deleted file mode 100644 index c7d85a96..00000000 --- a/src/main/java/helma/image/ImageGenerator.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.image; - -import helma.main.Server; - -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.*; -import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; - -/** - * Factory class for generating Image objects from various sources. - * - */ -public abstract class ImageGenerator { - protected static ImageGenerator generator = null; - - /** - * Returns an ImageGenerator singleton, creating it if necessary. If the JIMI - * package is installed, an instance of {@link helma.image.jimi.JimiGenerator JimiGenerator} - * will be returned. Otherwise, if the javax.imageio package is available, - * an instance of {@link helma.image.imageio.ImageIOGenerator ImageIOGenerator} - * is returned. Additionally, the class of the ImageGenerator implementation - * to be used can be set using the imageGenerator property in either - * the app.properties or server.properties file. - * - * @return a new ImageGenerator instance - */ - public static ImageGenerator getInstance() { - if (generator == null) { - // first see wether an image wrapper class was specified in - // server.properties: - String className = null; - if (Server.getServer() != null) { - className = Server.getServer().getProperty("imageGenerator"); - } - - Class generatorClass = null; - if (className == null) { - // if no class is defined, try the default ones: - try { - // start with ImageIO - Class.forName("javax.imageio.ImageIO"); - // if we're still here, ImageIOWrapper can be used - className = "helma.image.imageio.ImageIOGenerator"; - } catch (ClassNotFoundException e1) { - throw new RuntimeException("ImageIOGenerator cannot be used. Please use a custom image processing library for Java and set the imageGenerator property accordingly."); - } - } - // now let's get the generator class and create an instance: - try { - generatorClass = Class.forName(className); - } catch (ClassNotFoundException e) { - throw new RuntimeException( - "The imageGenerator class cannot be found: " + className); - } - try { - generator = (ImageGenerator)generatorClass.newInstance(); - } catch (Exception e) { - throw new RuntimeException( - "The ImageGenerator instance could not be created: " - + className); - } - } - return generator; - } - - /** - * @param w ... - * @param h ... - * - * @return ... - */ - public ImageWrapper createImage(int w, int h) { - BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); - return new ImageWrapper(img, w, h, this); - } - - /** - * @param src ... - * - * @return ... - * @throws IOException - */ - public ImageWrapper createImage(byte[] src) throws IOException { - Image img = read(src); - return img != null ? new ImageWrapper(img, this) : null; - } - - /** - * @param filenamne ... - * - * @return ... - * @throws IOException - */ - public ImageWrapper createImage(String filenamne) - throws IOException { - Image img = read(filenamne); - return img != null ? new ImageWrapper(img, this) : null; - } - - /** - * @param url ... - * - * @return ... - * @throws MalformedURLException - * @throws IOException - */ - public ImageWrapper createImage(URL url) - throws MalformedURLException, IOException { - Image img = read(url); - return img != null ? new ImageWrapper(img, this) : null; - } - - /** - * @param input ... - * @return ... - * @throws IOException - */ - public ImageWrapper createImage(InputStream input) - throws IOException { - Image img = read(input); - return img != null ? new ImageWrapper(img, this) : null; - } - - - /** - * @param iw ... - * @param filter ... - * - * @return ... - */ - public ImageWrapper createImage(ImageWrapper iw, ImageFilter filter) { - // use the ImagFilterOp wrapper for ImageFilters that works directly - // on BufferedImages. The filtering is much faster like that. - // Attention: needs testing with all the filters! - - return createImage(iw, new ImageFilterOp(filter)); -// Image img = ImageWaiter.waitForImage( -// Toolkit.getDefaultToolkit().createImage( -// new FilteredImageSource(iw.getSource(), filter))); -// return img != null ? new ImageWrapper(img, this) : null; - } - - /** - * @param iw ... - * @param imageOp ... - * - * @return ... - */ - public ImageWrapper createImage(ImageWrapper iw, BufferedImageOp imageOp) { - Image img = imageOp.filter(iw.getBufferedImage(), null); - return img != null ? new ImageWrapper(img, this) : null; - } - - /** - * @param filename the filename of the image to create - * - * @return the newly created image - * @throws IOException - */ - public Image read(String filename) throws IOException { - return ImageIO.read(new File(filename)); - } - - /** - * @param url the URL of the image to create - * - * @return the newly created image - * @throws IOException - */ - public Image read(URL url) throws IOException { - return ImageIO.read(url); - } - - /** - * @param src the data of the image to create - * - * @return the newly created image - * @throws IOException - */ - public Image read(byte[] src) throws IOException { - return ImageIO.read(new ByteArrayInputStream(src)); - } - - /** - * @param input the data of the image to create - * - * @return the newly created image - * @throws IOException - */ - public Image read(InputStream input) throws IOException { - return ImageIO.read(input); - } - - /** - * Saves the image. Image format is deduced from filename. - * - * @param wrapper - * @param filename - * @param quality - * @param alpha - * @throws IOException - */ - public abstract void write(ImageWrapper wrapper, String filename, - float quality, boolean alpha) throws IOException; - - /** - * Saves the image. Image format is deduced from the dataSource. - * - * @param wrapper - * @param out - * @param quality - * @param alpha - * @throws IOException - */ - public abstract void write(ImageWrapper wrapper, OutputStream out, String type, - float quality, boolean alpha) throws IOException; -} \ No newline at end of file diff --git a/src/main/java/helma/image/ImageInfo.java b/src/main/java/helma/image/ImageInfo.java deleted file mode 100644 index 1de5f211..00000000 --- a/src/main/java/helma/image/ImageInfo.java +++ /dev/null @@ -1,1299 +0,0 @@ -/* - * ImageInfo.java - * - * Version 1.5 - * - * A Java class to determine image width, height and color depth for - * a number of image file formats. - * - * Written by Marco Schmidt - * . - * - * Contributed to the Public Domain. - * - * Last modification 2004-02-29 - */ - -package helma.image; - -import java.io.DataInput; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Vector; - -/** - * Get file format, image resolution, number of bits per pixel and optionally - * number of images, comments and physical resolution from - * JPEG, GIF, BMP, PCX, PNG, IFF, RAS, PBM, PGM, PPM, PSD and SWF files - * (or input streams). - *

    - * Use the class like this: - *

    - * ImageInfo ii = new ImageInfo();
    - * ii.setInput(in); // in can be InputStream or RandomAccessFile
    - * ii.setDetermineImageNumber(true); // default is false
    - * ii.setCollectComments(true); // default is false
    - * if (!ii.check()) {
    - *   System.err.println("Not a supported image file format.");
    - *   return;
    - * }
    - * System.out.println(ii.getFormatName() + ", " + ii.getMimeType() + 
    - *   ", " + ii.getWidth() + " x " + ii.getHeight() + " pixels, " + 
    - *   ii.getBitsPerPixel() + " bits per pixel, " + ii.getNumberOfImages() +
    - *   " image(s), " + ii.getNumberOfComments() + " comment(s).");
    - *  // there are other properties, check out the API documentation
    - * 
    - * You can also use this class as a command line program. - * Call it with a number of image file names and URLs as parameters: - *
    - *   java ImageInfo *.jpg *.png *.gif http://somesite.tld/image.jpg
    - * 
    - * or call it without parameters and pipe data to it: - *
    - *   java ImageInfo < image.jpg  
    - * 
    - *

    - * Known limitations: - *

      - *
    • When the determination of the number of images is turned off, GIF bits - * per pixel are only read from the global header. - * For some GIFs, local palettes change this to a typically larger - * value. To be certain to get the correct color depth, call - * setDetermineImageNumber(true) before calling check(). - * The complete scan over the GIF file will take additional time.
    • - *
    • Transparency information is not included in the bits per pixel count. - * Actually, it was my decision not to include those bits, so it's a feature! ;-)
    • - *
    - *

    - * Requirements: - *

      - *
    • Java 1.1 or higher
    • - *
    - *

    - * The latest version can be found at http://www.geocities.com/marcoschmidt.geo/image-info.html. - *

    - * Written by Marco Schmidt. - *

    - * This class is contributed to the Public Domain. - * Use it at your own risk. - *

    - * Last modification 2004-02-29. - *

    - * History: - *

      - *
    • 2001-08-24 Initial version.
    • - *
    • 2001-10-13 Added support for the file formats BMP and PCX.
    • - *
    • 2001-10-16 Fixed bug in read(int[], int, int) that returned - *
    • 2002-01-22 Added support for file formats Amiga IFF and Sun Raster (RAS).
    • - *
    • 2002-01-24 Added support for file formats Portable Bitmap / Graymap / Pixmap (PBM, PGM, PPM) and Adobe Photoshop (PSD). - * Added new method getMimeType() to return the MIME type associated with a particular file format.
    • - *
    • 2002-03-15 Added support to recognize number of images in file. Only works with GIF. - * Use {@link #setDetermineImageNumber} with true as argument to identify animated GIFs - * ({@link #getNumberOfImages()} will return a value larger than 1).
    • - *
    • 2002-04-10 Fixed a bug in the feature 'determine number of images in animated GIF' introduced with version 1.1. - * Thanks to Marcelo P. Lima for sending in the bug report. - * Released as 1.1.1.
    • - *
    • 2002-04-18 Added {@link #setCollectComments(boolean)}. - * That new method lets the user specify whether textual comments are to be - * stored in an internal list when encountered in an input image file / stream. - * Added two methods to return the physical width and height of the image in dpi: - * {@link #getPhysicalWidthDpi()} and {@link #getPhysicalHeightDpi()}. - * If the physical resolution could not be retrieved, these methods return -1. - *
    • - *
    • 2002-04-23 Added support for the new properties physical resolution and - * comments for some formats. Released as 1.2.
    • - *
    • 2002-06-17 Added support for SWF, sent in by Michael Aird. - * Changed checkJpeg() so that other APP markers than APP0 will not lead to a failure anymore. - * Released as 1.3.
    • - *
    • 2003-07-28 Bug fix - skip method now takes return values into consideration. - * Less bytes than necessary may have been skipped, leading to flaws in the retrieved information in some cases. - * Thanks to Bernard Bernstein for pointing that out. - * Released as 1.4.
    • - *
    • 2004-02-29 Added support for recognizing progressive JPEG and - * interlaced PNG and GIF. A new method {@link #isProgressive()} returns whether ImageInfo - * has found that the storage type is progressive (or interlaced). - * Thanks to Joe Germuska for suggesting the feature. - * Bug fix: BMP physical resolution is now correctly determined. - * Released as 1.5.
    • - *
    - */ -public class ImageInfo { - /** - * Return value of {@link #getFormat()} for JPEG streams. - * ImageInfo can extract physical resolution and comments - * from JPEGs (only from APP0 headers). - * Only one image can be stored in a file. - * It is determined whether the JPEG stream is progressive - * (see {@link #isProgressive()}). - */ - public static final int FORMAT_JPEG = 0; - - /** - * Return value of {@link #getFormat()} for GIF streams. - * ImageInfo can extract comments from GIFs and count the number - * of images (GIFs with more than one image are animations). - * If you know of a place where GIFs store the physical resolution - * of an image, please - * send me a mail! - * It is determined whether the GIF stream is interlaced (see {@link #isProgressive()}). - */ - public static final int FORMAT_GIF = 1; - - /** - * Return value of {@link #getFormat()} for PNG streams. - * PNG only supports one image per file. - * Both physical resolution and comments can be stored with PNG, - * but ImageInfo is currently not able to extract those. - * It is determined whether the PNG stream is interlaced (see {@link #isProgressive()}). - */ - public static final int FORMAT_PNG = 2; - - /** - * Return value of {@link #getFormat()} for BMP streams. - * BMP only supports one image per file. - * BMP does not allow for comments. - * The physical resolution can be stored. - */ - public static final int FORMAT_BMP = 3; - - /** - * Return value of {@link #getFormat()} for PCX streams. - * PCX does not allow for comments or more than one image per file. - * However, the physical resolution can be stored. - */ - public static final int FORMAT_PCX = 4; - - /** - * Return value of {@link #getFormat()} for IFF streams. - */ - public static final int FORMAT_IFF = 5; - - /** - * Return value of {@link #getFormat()} for RAS streams. - * Sun Raster allows for one image per file only and is not able to - * store physical resolution or comments. - */ - public static final int FORMAT_RAS = 6; - - /** Return value of {@link #getFormat()} for PBM streams. */ - public static final int FORMAT_PBM = 7; - - /** Return value of {@link #getFormat()} for PGM streams. */ - public static final int FORMAT_PGM = 8; - - /** Return value of {@link #getFormat()} for PPM streams. */ - public static final int FORMAT_PPM = 9; - - /** Return value of {@link #getFormat()} for PSD streams. */ - public static final int FORMAT_PSD = 10; - - /** Return value of {@link #getFormat()} for SWF (Shockwave) streams. */ - public static final int FORMAT_SWF = 11; - - public static final int COLOR_TYPE_UNKNOWN = -1; - public static final int COLOR_TYPE_TRUECOLOR_RGB = 0; - public static final int COLOR_TYPE_PALETTED = 1; - public static final int COLOR_TYPE_GRAYSCALE= 2; - public static final int COLOR_TYPE_BLACK_AND_WHITE = 3; - - /** - * The names of all supported file formats. - * The FORMAT_xyz int constants can be used as index values for - * this array. - */ - private static final String[] FORMAT_NAMES = - {"JPEG", "GIF", "PNG", "BMP", "PCX", - "IFF", "RAS", "PBM", "PGM", "PPM", - "PSD", "SWF"}; - - /** - * The names of the MIME types for all supported file formats. - * The FORMAT_xyz int constants can be used as index values for - * this array. - */ - private static final String[] MIME_TYPE_STRINGS = - {"image/jpeg", "image/gif", "image/png", "image/bmp", "image/pcx", - "image/iff", "image/ras", "image/x-portable-bitmap", "image/x-portable-graymap", "image/x-portable-pixmap", - "image/psd", "application/x-shockwave-flash"}; - - private int width; - private int height; - private int bitsPerPixel; - private int numColors; - private int colorType = COLOR_TYPE_UNKNOWN; - private boolean progressive; - private int format; - private InputStream in; - private DataInput din; - private boolean collectComments = true; - private Vector comments; - private boolean determineNumberOfImages; - private int numberOfImages; - private int physicalHeightDpi; - private int physicalWidthDpi; - private int bitBuf; - private int bitPos; - - private void addComment(String s) { - if (comments == null) { - comments = new Vector(); - } - comments.addElement(s); - } - - /** - * Call this method after you have provided an input stream or file - * using {@link #setInput(InputStream)} or {@link #setInput(DataInput)}. - * If true is returned, the file format was known and information - * on the file's content can be retrieved using the various getXyz methods. - * @return if information could be retrieved from input - */ - public boolean check() { - format = -1; - width = -1; - height = -1; - bitsPerPixel = -1; - numberOfImages = 1; - physicalHeightDpi = -1; - physicalWidthDpi = -1; - numColors = -1; - comments = null; - try { - int b1 = read() & 0xff; - int b2 = read() & 0xff; - if (b1 == 0x47 && b2 == 0x49) { - return checkGif(); - } - else - if (b1 == 0x89 && b2 == 0x50) { - return checkPng(); - } - else - if (b1 == 0xff && b2 == 0xd8) { - return checkJpeg(); - } - else - if (b1 == 0x42 && b2 == 0x4d) { - return checkBmp(); - } - else - if (b1 == 0x0a && b2 < 0x06) { - return checkPcx(); - } - else - if (b1 == 0x46 && b2 == 0x4f) { - return checkIff(); - } - else - if (b1 == 0x59 && b2 == 0xa6) { - return checkRas(); - } - else - if (b1 == 0x50 && b2 >= 0x31 && b2 <= 0x36) { - return checkPnm(b2 - '0'); - } - else - if (b1 == 0x38 && b2 == 0x42) { - return checkPsd(); - } - else - if (b1 == 0x46 && b2 == 0x57) { - return checkSwf(); - } - else { - return false; - } - } catch (IOException ioe) { - return false; - } - } - - private boolean checkBmp() throws IOException { - byte[] a = new byte[44]; - if (read(a) != a.length) { - return false; - } - width = getIntLittleEndian(a, 16); - height = getIntLittleEndian(a, 20); - if (width < 1 || height < 1) { - return false; - } - bitsPerPixel = getShortLittleEndian(a, 26); - if (bitsPerPixel != 1 && bitsPerPixel != 4 && - bitsPerPixel != 8 && bitsPerPixel != 16 && - bitsPerPixel != 24 && bitsPerPixel != 32) { - return false; - } - int x = (int)(getIntLittleEndian(a, 36) * 0.0254); - if (x > 0) { - setPhysicalWidthDpi(x); - } - int y = (int)(getIntLittleEndian(a, 40) * 0.0254); - if (y > 0) { - setPhysicalHeightDpi(y); - } - format = FORMAT_BMP; - return true; - } - - private boolean checkGif() throws IOException { - final byte[] GIF_MAGIC_87A = {0x46, 0x38, 0x37, 0x61}; - final byte[] GIF_MAGIC_89A = {0x46, 0x38, 0x39, 0x61}; - byte[] a = new byte[11]; // 4 from the GIF signature + 7 from the global header - if (read(a) != 11) { - return false; - } - if ((!equals(a, 0, GIF_MAGIC_89A, 0, 4)) && - (!equals(a, 0, GIF_MAGIC_87A, 0, 4))) { - return false; - } - format = FORMAT_GIF; - width = getShortLittleEndian(a, 4); - height = getShortLittleEndian(a, 6); - int flags = a[8] & 0xff; - bitsPerPixel = ((flags >> 4) & 0x07) + 1; - progressive = (flags & 0x02) != 0; - // skip global color palette - if ((flags & 0x80) != 0) { - numColors = (1 << ((flags & 7) + 1)); - skip(numColors * 3); - } - if (!determineNumberOfImages) { - return true; - } - numberOfImages = 0; - int blockType; - do - { - blockType = read(); - switch(blockType) - { - case(0x2c): // image separator - { - if (read(a, 0, 9) != 9) { - return false; - } - flags = a[8] & 0xff; - int localBitsPerPixel = (flags & 0x07) + 1; - if (localBitsPerPixel > bitsPerPixel) { - bitsPerPixel = localBitsPerPixel; - } - if ((flags & 0x80) != 0) { - int localNumColors = 1 << localBitsPerPixel; - skip(localNumColors * 3); - if (localNumColors > numColors) { - numColors = localNumColors; - } - } - skip(1); // initial code length - int n; - do - { - n = read(); - if (n > 0) { - skip(n); - } - else - if (n == -1) { - return false; - } - } - while (n > 0); - numberOfImages++; - break; - } - case(0x21): // extension - { - int extensionType = read(); - if (collectComments && extensionType == 0xfe) { - StringBuffer sb = new StringBuffer(); - int n; - do - { - n = read(); - if (n == -1) { - return false; - } - if (n > 0) { - for (int i = 0; i < n; i++) { - int ch = read(); - if (ch == -1) { - return false; - } - sb.append((char)ch); - } - } - } - while (n > 0); - } else { - int n; - do - { - n = read(); - if (n > 0) { - skip(n); - } - else - if (n == -1) { - return false; - } - } - while (n > 0); - } - break; - } - case(0x3b): // end of file - { - break; - } - default: - { - return false; - } - } - } - while (blockType != 0x3b); - return true; - } - - private boolean checkIff() throws IOException { - byte[] a = new byte[10]; - // read remaining 2 bytes of file id, 4 bytes file size - // and 4 bytes IFF subformat - if (read(a, 0, 10) != 10) { - return false; - } - final byte[] IFF_RM = {0x52, 0x4d}; - if (!equals(a, 0, IFF_RM, 0, 2)) { - return false; - } - int type = getIntBigEndian(a, 6); - if (type != 0x494c424d && // type must be ILBM... - type != 0x50424d20) { // ...or PBM - return false; - } - // loop chunks to find BMHD chunk - do { - if (read(a, 0, 8) != 8) { - return false; - } - int chunkId = getIntBigEndian(a, 0); - int size = getIntBigEndian(a, 4); - if ((size & 1) == 1) { - size++; - } - if (chunkId == 0x424d4844) { // BMHD chunk - if (read(a, 0, 9) != 9) { - return false; - } - format = FORMAT_IFF; - width = getShortBigEndian(a, 0); - height = getShortBigEndian(a, 2); - bitsPerPixel = a[8] & 0xff; - return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel < 33); - } else { - skip(size); - } - } while (true); - } - - private boolean checkJpeg() throws IOException { - byte[] data = new byte[12]; - while (true) { - if (read(data, 0, 4) != 4) { - return false; - } - int marker = getShortBigEndian(data, 0); - int size = getShortBigEndian(data, 2); - if ((marker & 0xff00) != 0xff00) { - return false; // not a valid marker - } - if (marker == 0xffe0) { // APPx - if (size < 14) { - return false; // APPx header must be >= 14 bytes - } - if (read(data, 0, 12) != 12) { - return false; - } - final byte[] APP0_ID = {0x4a, 0x46, 0x49, 0x46, 0x00}; - if (equals(APP0_ID, 0, data, 0, 5)) { - //System.out.println("data 7=" + data[7]); - if (data[7] == 1) { - setPhysicalWidthDpi(getShortBigEndian(data, 8)); - setPhysicalHeightDpi(getShortBigEndian(data, 10)); - } - else - if (data[7] == 2) { - int x = getShortBigEndian(data, 8); - int y = getShortBigEndian(data, 10); - setPhysicalWidthDpi((int)(x * 2.54f)); - setPhysicalHeightDpi((int)(y * 2.54f)); - } - } - skip(size - 14); - } - else - if (collectComments && size > 2 && marker == 0xfffe) { // comment - size -= 2; - byte[] chars = new byte[size]; - if (read(chars, 0, size) != size) { - return false; - } - String comment = new String(chars, "iso-8859-1"); - comment = comment.trim(); - addComment(comment); - } - else - if (marker >= 0xffc0 && marker <= 0xffcf && marker != 0xffc4 && marker != 0xffc8) { - if (read(data, 0, 6) != 6) { - return false; - } - format = FORMAT_JPEG; - bitsPerPixel = (data[0] & 0xff) * (data[5] & 0xff); - progressive = marker == 0xffc2 || marker == 0xffc6 || - marker == 0xffca || marker == 0xffce; - width = getShortBigEndian(data, 3); - height = getShortBigEndian(data, 1); - return true; - } else { - skip(size - 2); - } - } - } - - private boolean checkPcx() throws IOException { - byte[] a = new byte[64]; - if (read(a) != a.length) { - return false; - } - if (a[0] != 1) { // encoding, 1=RLE is only valid value - return false; - } - // width / height - int x1 = getShortLittleEndian(a, 2); - int y1 = getShortLittleEndian(a, 4); - int x2 = getShortLittleEndian(a, 6); - int y2 = getShortLittleEndian(a, 8); - if (x1 < 0 || x2 < x1 || y1 < 0 || y2 < y1) { - return false; - } - width = x2 - x1 + 1; - height = y2 - y1 + 1; - // color depth - int bits = a[1]; - int planes = a[63]; - if (planes == 1 && - (bits == 1 || bits == 2 || bits == 4 || bits == 8)) { - // paletted - bitsPerPixel = bits; - } else - if (planes == 3 && bits == 8) { - // RGB truecolor - bitsPerPixel = 24; - } else { - return false; - } - setPhysicalWidthDpi(getShortLittleEndian(a, 10)); - setPhysicalHeightDpi(getShortLittleEndian(a, 10)); - format = FORMAT_PCX; - return true; - } - - private boolean checkPng() throws IOException { - final byte[] PNG_MAGIC = {0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}; - byte[] a = new byte[27]; - if (read(a) != 27) { - return false; - } - if (!equals(a, 0, PNG_MAGIC, 0, 6)) { - return false; - } - format = FORMAT_PNG; - width = getIntBigEndian(a, 14); - height = getIntBigEndian(a, 18); - bitsPerPixel = a[22] & 0xff; - int colorType = a[23] & 0xff; - if (colorType == 2 || colorType == 6) { - bitsPerPixel *= 3; - } - progressive = (a[26] & 0xff) != 0; - return true; - } - - private boolean checkPnm(int id) throws IOException { - if (id < 1 || id > 6) { - return false; - } - final int[] PNM_FORMATS = {FORMAT_PBM, FORMAT_PGM, FORMAT_PPM}; - format = PNM_FORMATS[(id - 1) % 3]; - boolean hasPixelResolution = false; - String s; - while (true) - { - s = readLine(); - if (s != null) { - s = s.trim(); - } - if (s == null || s.length() < 1) { - continue; - } - if (s.charAt(0) == '#') { // comment - if (collectComments && s.length() > 1) { - addComment(s.substring(1)); - } - continue; - } - if (!hasPixelResolution) { // split "343 966" into width=343, height=966 - int spaceIndex = s.indexOf(' '); - if (spaceIndex == -1) { - return false; - } - String widthString = s.substring(0, spaceIndex); - spaceIndex = s.lastIndexOf(' '); - if (spaceIndex == -1) { - return false; - } - String heightString = s.substring(spaceIndex + 1); - try { - width = Integer.parseInt(widthString); - height = Integer.parseInt(heightString); - } catch (NumberFormatException nfe) { - return false; - } - if (width < 1 || height < 1) { - return false; - } - if (format == FORMAT_PBM) { - bitsPerPixel = 1; - return true; - } - hasPixelResolution = true; - } - else - { - int maxSample; - try { - maxSample = Integer.parseInt(s); - } catch (NumberFormatException nfe) { - return false; - } - if (maxSample < 0) { - return false; - } - for (int i = 0; i < 25; i++) { - if (maxSample < (1 << (i + 1))) { - bitsPerPixel = i + 1; - if (format == FORMAT_PPM) { - bitsPerPixel *= 3; - } - return true; - } - } - return false; - } - } - } - - private boolean checkPsd() throws IOException { - byte[] a = new byte[24]; - if (read(a) != a.length) { - return false; - } - final byte[] PSD_MAGIC = {0x50, 0x53}; - if (!equals(a, 0, PSD_MAGIC, 0, 2)) { - return false; - } - format = FORMAT_PSD; - width = getIntBigEndian(a, 16); - height = getIntBigEndian(a, 12); - int channels = getShortBigEndian(a, 10); - int depth = getShortBigEndian(a, 20); - bitsPerPixel = channels * depth; - return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel <= 64); - } - - private boolean checkRas() throws IOException { - byte[] a = new byte[14]; - if (read(a) != a.length) { - return false; - } - final byte[] RAS_MAGIC = {0x6a, (byte)0x95}; - if (!equals(a, 0, RAS_MAGIC, 0, 2)) { - return false; - } - format = FORMAT_RAS; - width = getIntBigEndian(a, 2); - height = getIntBigEndian(a, 6); - bitsPerPixel = getIntBigEndian(a, 10); - return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel <= 24); - } - - // Written by Michael Aird. - private boolean checkSwf() throws IOException { - //get rid of the last byte of the signature, the byte of the version and 4 bytes of the size - byte[] a = new byte[6]; - if (read(a) != a.length) { - return false; - } - format = FORMAT_SWF; - int bitSize = (int)readUBits( 5 ); - int minX = (int)readSBits( bitSize ); - int maxX = (int)readSBits( bitSize ); - int minY = (int)readSBits( bitSize ); - int maxY = (int)readSBits( bitSize ); - width = maxX/20; //cause we're in twips - height = maxY/20; //cause we're in twips - setPhysicalWidthDpi(72); - setPhysicalHeightDpi(72); - return (width > 0 && height > 0); - } - - /** - * Run over String list, return false iff at least one of the arguments - * equals -c. - */ - private static boolean determineVerbosity(String[] args) { - if (args != null && args.length > 0) { - for (int i = 0; i < args.length; i++) { - if ("-c".equals(args[i])) { - return false; - } - } - } - return true; - } - - private boolean equals(byte[] a1, int offs1, byte[] a2, int offs2, int num) { - while (num-- > 0) { - if (a1[offs1++] != a2[offs2++]) { - return false; - } - } - return true; - } - - /** - * If {@link #check()} was successful, returns the image's number of bits per pixel. - * Does not include transparency information like the alpha channel. - * @return number of bits per image pixel - */ - public int getBitsPerPixel() { - return bitsPerPixel; - } - - /** - * @return number of colors, for palette based images - */ - public int getNumColors() { - return numColors; - } - - /** - * Returns the index'th comment retrieved from the image. - * @throws IllegalArgumentException if index is smaller than 0 or larger than or equal - * to the number of comments retrieved - * @see #getNumberOfComments - */ - public String getComment(int index) { - if (comments == null || index < 0 || index >= comments.size()) { - throw new IllegalArgumentException("Not a valid comment index: " + index); - } - return (String)comments.elementAt(index); - } - - /** - * If {@link #check()} was successful, returns the image format as one - * of the FORMAT_xyz constants from this class. - * Use {@link #getFormatName()} to get a textual description of the file format. - * @return file format as a FORMAT_xyz constant - */ - public int getFormat() { - return format; - } - - /** - * If {@link #check()} was successful, returns the image format's name. - * Use {@link #getFormat()} to get a unique number. - * @return file format name - */ - public String getFormatName() { - if (format >= 0 && format < FORMAT_NAMES.length) { - return FORMAT_NAMES[format]; - } else { - return "?"; - } - } - - /** - * If {@link #check()} was successful, returns one the image's vertical - * resolution in pixels. - * @return image height in pixels - */ - public int getHeight() { - return height; - } - - private int getIntBigEndian(byte[] a, int offs) { - return - (a[offs] & 0xff) << 24 | - (a[offs + 1] & 0xff) << 16 | - (a[offs + 2] & 0xff) << 8 | - a[offs + 3] & 0xff; - } - - private int getIntLittleEndian(byte[] a, int offs) { - return - (a[offs + 3] & 0xff) << 24 | - (a[offs + 2] & 0xff) << 16 | - (a[offs + 1] & 0xff) << 8 | - a[offs] & 0xff; - } - - /** - * If {@link #check()} was successful, returns a String with the - * MIME type of the format. - * @return MIME type, e.g. image/jpeg - */ - public String getMimeType() { - if (format >= 0 && format < MIME_TYPE_STRINGS.length) { - if (format == FORMAT_JPEG && progressive) - { - return "image/pjpeg"; - } - return MIME_TYPE_STRINGS[format]; - } else { - return null; - } - } - - /** - * If {@link #check()} was successful and {@link #setCollectComments(boolean)} was called with - * true as argument, returns the number of comments retrieved - * from the input image stream / file. - * Any number >= 0 and smaller than this number of comments is then a - * valid argument for the {@link #getComment(int)} method. - * @return number of comments retrieved from input image - */ - public int getNumberOfComments() - { - if (comments == null) { - return 0; - } else { - return comments.size(); - } - } - - /** - * Returns the number of images in the examined file. - * Assumes that setDetermineImageNumber(true); was called before - * a successful call to {@link #check()}. - * This value can currently be only different from 1 for GIF images. - * @return number of images in file - */ - public int getNumberOfImages() - { - return numberOfImages; - } - - /** - * Returns the physical height of this image in dots per inch (dpi). - * Assumes that {@link #check()} was successful. - * Returns -1 on failure. - * @return physical height (in dpi) - * @see #getPhysicalWidthDpi() - * @see #getPhysicalHeightInch() - */ - public int getPhysicalHeightDpi() { - return physicalHeightDpi; - } - - /** - * If {@link #check()} was successful, returns the physical width of this image in dpi (dots per inch) - * or -1 if no value could be found. - * @return physical height (in dpi) - * @see #getPhysicalHeightDpi() - * @see #getPhysicalWidthDpi() - * @see #getPhysicalWidthInch() - */ - public float getPhysicalHeightInch() { - int h = getHeight(); - int ph = getPhysicalHeightDpi(); - if (h > 0 && ph > 0) { - return ((float)h) / ((float)ph); - } else { - return -1.0f; - } - } - - /** - * If {@link #check()} was successful, returns the physical width of this image in dpi (dots per inch) - * or -1 if no value could be found. - * @return physical width (in dpi) - * @see #getPhysicalHeightDpi() - * @see #getPhysicalWidthInch() - * @see #getPhysicalHeightInch() - */ - public int getPhysicalWidthDpi() { - return physicalWidthDpi; - } - - /** - * Returns the physical width of an image in inches, or - * -1.0f if width information is not available. - * Assumes that {@link #check} has been called successfully. - * @return physical width in inches or -1.0f on failure - * @see #getPhysicalWidthDpi - * @see #getPhysicalHeightInch - */ - public float getPhysicalWidthInch() { - int w = getWidth(); - int pw = getPhysicalWidthDpi(); - if (w > 0 && pw > 0) { - return ((float)w) / ((float)pw); - } else { - return -1.0f; - } - } - - private int getShortBigEndian(byte[] a, int offs) { - return - (a[offs] & 0xff) << 8 | - (a[offs + 1] & 0xff); - } - - private int getShortLittleEndian(byte[] a, int offs) { - return (a[offs] & 0xff) | (a[offs + 1] & 0xff) << 8; - } - - /** - * If {@link #check()} was successful, returns one the image's horizontal - * resolution in pixels. - * @return image width in pixels - */ - public int getWidth() { - return width; - } - - /** - * Returns whether the image is stored in a progressive (also called: interlaced) way. - * @return true for progressive/interlaced, false otherwise - */ - public boolean isProgressive() - { - return progressive; - } - - /** - * To use this class as a command line application, give it either - * some file names as parameters (information on them will be - * printed to standard output, one line per file) or call - * it with no parameters. It will then check data given to it - * via standard input. - * @param args the program arguments which must be file names - */ - public static void main(String[] args) { - ImageInfo imageInfo = new ImageInfo(); - imageInfo.setDetermineImageNumber(true); - boolean verbose = determineVerbosity(args); - if (args.length == 0) { - run(null, System.in, imageInfo, verbose); - } else { - int index = 0; - while (index < args.length) { - InputStream in = null; - try { - String name = args[index++]; - System.out.print(name + ";"); - if (name.startsWith("http://")) { - in = new URL(name).openConnection().getInputStream(); - } else { - in = new FileInputStream(name); - } - run(name, in, imageInfo, verbose); - in.close(); - } catch (Exception e) { - System.out.println(e); - try { - in.close(); - } catch (Exception ee) { - } - } - } - } - } - - private static void print(String sourceName, ImageInfo ii, boolean verbose) { - if (verbose) { - printVerbose(sourceName, ii); - } else { - printCompact(sourceName, ii); - } - } - - private static void printCompact(String sourceName, ImageInfo imageInfo) { - System.out.println( - imageInfo.getFormatName() + ";" + - imageInfo.getMimeType() + ";" + - imageInfo.getWidth() + ";" + - imageInfo.getHeight() + ";" + - imageInfo.getBitsPerPixel() + ";" + - imageInfo.getNumberOfImages() + ";" + - imageInfo.getPhysicalWidthDpi() + ";" + - imageInfo.getPhysicalHeightDpi() + ";" + - imageInfo.getPhysicalWidthInch() + ";" + - imageInfo.getPhysicalHeightInch() + ";" + - imageInfo.isProgressive() - ); - } - - private static void printLine(int indentLevels, String text, float value, float minValidValue) { - if (value < minValidValue) { - return; - } - printLine(indentLevels, text, Float.toString(value)); - } - - private static void printLine(int indentLevels, String text, int value, int minValidValue) { - if (value >= minValidValue) { - printLine(indentLevels, text, Integer.toString(value)); - } - } - - private static void printLine(int indentLevels, String text, String value) { - if (value == null || value.length() == 0) { - return; - } - while (indentLevels-- > 0) { - System.out.print("\t"); - } - if (text != null && text.length() > 0) { - System.out.print(text); - System.out.print(" "); - } - System.out.println(value); - } - - private static void printVerbose(String sourceName, ImageInfo ii) { - printLine(0, null, sourceName); - printLine(1, "File format: ", ii.getFormatName()); - printLine(1, "MIME type: ", ii.getMimeType()); - printLine(1, "Width (pixels): ", ii.getWidth(), 1); - printLine(1, "Height (pixels): ", ii.getHeight(), 1); - printLine(1, "Bits per pixel: ", ii.getBitsPerPixel(), 1); - printLine(1, "Progressive: ", Boolean.toString(ii.isProgressive())); - printLine(1, "Number of images: ", ii.getNumberOfImages(), 1); - printLine(1, "Physical width (dpi): ", ii.getPhysicalWidthDpi(), 1); - printLine(1, "Physical height (dpi): ", ii.getPhysicalHeightDpi(), 1); - printLine(1, "Physical width (inches): ", ii.getPhysicalWidthInch(), 1.0f); - printLine(1, "Physical height (inches): ", ii.getPhysicalHeightInch(), 1.0f); - int numComments = ii.getNumberOfComments(); - printLine(1, "Number of textual comments: ", numComments, 1); - if (numComments > 0) { - for (int i = 0; i < numComments; i++) { - printLine(2, null, ii.getComment(i)); - } - } - } - - private int read() throws IOException { - if (in != null) { - return in.read(); - } else { - return din.readByte(); - } - } - - private int read(byte[] a) throws IOException { - if (in != null) { - return in.read(a); - } else { - din.readFully(a); - return a.length; - } - } - - private int read(byte[] a, int offset, int num) throws IOException { - if (in != null) { - return in.read(a, offset, num); - } else { - din.readFully(a, offset, num); - return num; - } - } - - private String readLine() throws IOException { - return readLine(new StringBuffer()); - } - - private String readLine(StringBuffer sb) throws IOException { - boolean finished; - do { - int value = read(); - finished = (value == -1 || value == 10); - if (!finished) { - sb.append((char)value); - } - } while (!finished); - return sb.toString(); - } - - private long readUBits( int numBits ) throws IOException - { - if (numBits == 0) { - return 0; - } - int bitsLeft = numBits; - long result = 0; - if (bitPos == 0) { //no value in the buffer - read a byte - if (in != null) { - bitBuf = in.read(); - } else { - bitBuf = din.readByte(); - } - bitPos = 8; - } - - while( true ) - { - int shift = bitsLeft - bitPos; - if( shift > 0 ) - { - // Consume the entire buffer - result |= bitBuf << shift; - bitsLeft -= bitPos; - - // Get the next byte from the input stream - if (in != null) { - bitBuf = in.read(); - } else { - bitBuf = din.readByte(); - } - bitPos = 8; - } - else - { - // Consume a portion of the buffer - result |= bitBuf >> -shift; - bitPos -= bitsLeft; - bitBuf &= 0xff >> (8 - bitPos); // mask off the consumed bits - - return result; - } - } - } - - /** - * Read a signed value from the given number of bits - */ - private int readSBits( int numBits ) throws IOException - { - // Get the number as an unsigned value. - long uBits = readUBits( numBits ); - - // Is the number negative? - if( ( uBits & (1L << (numBits - 1))) != 0 ) - { - // Yes. Extend the sign. - uBits |= -1L << numBits; - } - - return (int)uBits; - } - - private void synchBits() - { - bitBuf = 0; - bitPos = 0; - } - - private String readLine(int firstChar) throws IOException { - StringBuffer result = new StringBuffer(); - result.append((char)firstChar); - return readLine(result); - } - - private static void run(String sourceName, InputStream in, ImageInfo imageInfo, boolean verbose) { - imageInfo.setInput(in); - imageInfo.setDetermineImageNumber(false); - imageInfo.setCollectComments(verbose); - if (imageInfo.check()) { - print(sourceName, imageInfo, verbose); - } - } - - /** - * Specify whether textual comments are supposed to be extracted from input. - * Default is false. - * If enabled, comments will be added to an internal list. - * @param newValue if true, this class will read comments - * @see #getNumberOfComments - * @see #getComment - */ - public void setCollectComments(boolean newValue) - { - collectComments = newValue; - } - - /** - * Specify whether the number of images in a file is to be - * determined - default is false. - * This is a special option because some file formats require running over - * the entire file to find out the number of images, a rather time-consuming - * task. - * Not all file formats support more than one image. - * If this method is called with true as argument, - * the actual number of images can be queried via - * {@link #getNumberOfImages()} after a successful call to - * {@link #check()}. - * @param newValue will the number of images be determined? - * @see #getNumberOfImages - */ - public void setDetermineImageNumber(boolean newValue) - { - determineNumberOfImages = newValue; - } - - /** - * Set the input stream to the argument stream (or file). - * Note that {@link java.io.RandomAccessFile} implements - * {@link java.io.DataInput}. - * @param dataInput the input stream to read from - */ - public void setInput(DataInput dataInput) { - din = dataInput; - in = null; - } - - /** - * Set the input stream to the argument stream (or file). - * @param inputStream the input stream to read from - */ - public void setInput(InputStream inputStream) { - in = inputStream; - din = null; - } - - private void setPhysicalHeightDpi(int newValue) { - physicalWidthDpi = newValue; - } - - private void setPhysicalWidthDpi(int newValue) { - physicalHeightDpi = newValue; - } - - private void skip(int num) throws IOException { - while (num > 0) { - long result; - if (in != null) { - result = in.skip(num); - } else { - result = din.skipBytes(num); - } - if (result > 0) { - num -= result; - } - } - } -} diff --git a/src/main/java/helma/image/ImageWaiter.java b/src/main/java/helma/image/ImageWaiter.java deleted file mode 100644 index f444a97c..00000000 --- a/src/main/java/helma/image/ImageWaiter.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.image; - -import java.awt.Image; - -import java.awt.image.ImageObserver; - -/** - * The ImageWaiter will only be used like this: - * image = ImageWaiter.waitForImage(image); - */ -public class ImageWaiter implements ImageObserver { - Image image; - int width; - int height; - boolean waiting; - boolean firstFrameLoaded; - - private ImageWaiter(Image image) { - this.image = image; - waiting = true; - firstFrameLoaded = false; - } - - public static Image waitForImage(Image image) { - ImageWaiter waiter = new ImageWaiter(image); - try { - waiter.waitForImage(); - } finally { - waiter.done(); - } - return waiter.width == -1 || waiter.height == -1 ? null : image; - } - - private synchronized void waitForImage() { - width = image.getWidth(this); - height = image.getHeight(this); - - if (width == -1 || height == -1) { - try { - wait(45000); - } catch (InterruptedException x) { - waiting = false; - return; - } finally { - waiting = false; - } - } - - // if width and height haven't been set, throw tantrum - if (width == -1 || height == -1) { - throw new RuntimeException("Error loading image"); - } - } - - private synchronized void done() { - waiting = false; - notifyAll(); - } - - public synchronized boolean imageUpdate(Image img, int infoflags, int x, - int y, int w, int h) { - // check if there was an error - if (!waiting || (infoflags & ERROR) > 0 || (infoflags & ABORT) > 0) { - // we either timed out or there was an error. - notifyAll(); - - return false; - } - - if ((infoflags & WIDTH) > 0 || (infoflags & HEIGHT) > 0) { - if ((infoflags & WIDTH) > 0) { - width = w; - } - - if ((infoflags & HEIGHT) > 0) { - height = h; - } - - if (width > -1 && h > -1 && firstFrameLoaded) { - notifyAll(); - - return false; - } - } - - if ((infoflags & ALLBITS) > 0 || (infoflags & FRAMEBITS) > 0) { - firstFrameLoaded = true; - notifyAll(); - - return false; - } - - return true; - } -} \ No newline at end of file diff --git a/src/main/java/helma/image/ImageWrapper.java b/src/main/java/helma/image/ImageWrapper.java deleted file mode 100644 index 9a1ea62f..00000000 --- a/src/main/java/helma/image/ImageWrapper.java +++ /dev/null @@ -1,679 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -/* - * A few explanations: - * - * - this.image is either an AWT Image or a BufferedImage. - * It depends on the ImageGenerator in what form the Image initially is. - * (the ImageIO implementation only uses BufferedImages for example.) - * - * As soon as some action that needs the graphics object is performed and the - * image is still in AWT format, it is converted to a BufferedImage - * - * Any internal function that performs graphical actions needs to call - * getGraphics, never rely on this.graphics being set correctly! - * - * - ImageWrapper objects are created and safed by the ImageGenerator class - * all different implementations of Imaging functionallity are implemented - * as a ImageGenerator extending class. - * - */ - -package helma.image; - -import java.awt.*; -import java.awt.geom.AffineTransform; -import java.awt.image.*; -import java.io.*; - -/** - * Abstract base class for Image Wrappers. - */ -public class ImageWrapper { - protected Image image; - protected int width; - protected int height; - protected ImageGenerator generator; - private Graphics2D graphics; - - /** - * Creates a new ImageWrapper object. - * - * @param image ... - * @param width ... - * @param height ... - */ - public ImageWrapper(Image image, int width, int height, - ImageGenerator generator) { - this.image = image; - this.width = width; - this.height = height; - this.generator = generator; - // graphics are turned off by default. getGraphics activates it if necessary. - this.graphics = null; - } - - public ImageWrapper(Image image, ImageGenerator generator) { - this(image, image.getWidth(null), image.getHeight(null), generator); - } - - /** - * Converts the internal image object to a BufferedImage (if it's not - * already) and returns it. this is necessary as not all images are of type - * BufferedImage. e.g. images loaded from a resource with the Toolkit are - * not. By using getBufferedImage, images are only converted to a - * getBufferedImage when this is actually needed, which is better than - * storing images as BufferedImage in general. - * - * @return the Image object as a BufferedImage - */ - public BufferedImage getBufferedImage() { - if (!(image instanceof BufferedImage)) { - BufferedImage buffered = new BufferedImage(width, height, - BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = buffered.createGraphics(); - g2d.drawImage(image, 0, 0, null); - g2d.dispose(); - setImage(buffered); - } - return (BufferedImage)image; - } - - /** - * Returns the Graphics object to directly paint to this Image. Converts the - * internal image to a BufferedImage if necessary. - * - * @return the Graphics object for drawing into this image - */ - public Graphics2D getGraphics() { - if (graphics == null) { - // make sure the image is a BufferedImage and then create a graphics object - BufferedImage img = getBufferedImage(); - graphics = img.createGraphics(); - } - return graphics; - } - - /** - * Sets the internal image and clears the stored graphics object. - * Any code that is changing the internal image should do it through this function - * to make sure getGraphcis() returns a valid graphics object the next time it is called. - */ - protected void setImage(Image img) { - // flush image and dispose graphics before updating them - if (graphics != null) { - graphics.dispose(); - graphics = null; - } - if (image != null) { - image.flush(); - } - image = img; - width = image.getWidth(null); - height = image.getHeight(null); - } - - /** - * Creates and returns a copy of this image. - * - * @return a clone of this image. - */ - public Object clone() { - ImageWrapper wrapper = generator.createImage(this.width, - this.height); - wrapper.getGraphics().drawImage(image, 0, 0, null); - return wrapper; - } - - /** - * Returns the Image object represented by this ImageWrapper. - * - * @return the image object - */ - public Image getImage() { - return image; - } - - /** - * Returns the ImageProducer of the wrapped image - * - * @return the images's ImageProducer - */ - public ImageProducer getSource() { - return image.getSource(); - } - - /** - * Dispose the Graphics context and null out the image. - */ - public void dispose() { - if (image != null) { - image.flush(); - image = null; - } - if (graphics != null) { - graphics.dispose(); - graphics = null; - } - } - - /** - * Set the font used to write on this image. - */ - public void setFont(String name, int style, int size) { - getGraphics().setFont(new Font(name, style, size)); - } - - /** - * Sets the color used to write/paint to this image. - * - * @param red ... - * @param green ... - * @param blue ... - */ - public void setColor(int red, int green, int blue) { - getGraphics().setColor(new Color(red, green, blue)); - } - - /** - * Sets the color used to write/paint to this image. - * - * @param color ... - */ - public void setColor(int color) { - getGraphics().setColor(new Color(color)); - } - - /** - * Sets the color used to write/paint to this image. - * - * @param color ... - */ - public void setColor(Color color) { - getGraphics().setColor(color); - } - - /** - * Sets the color used to write/paint to this image. - * - * @param color ... - */ - public void setColor(String color) { - getGraphics().setColor(Color.decode(color)); - } - /** - * Draws a string to this image at the given coordinates. - * - * @param str ... - * @param x ... - * @param y ... - */ - public void drawString(String str, int x, int y) { - getGraphics().drawString(str, x, y); - } - - /** - * Draws a line to this image from x1/y1 to x2/y2. - * - * @param x1 ... - * @param y1 ... - * @param x2 ... - * @param y2 ... - */ - public void drawLine(int x1, int y1, int x2, int y2) { - getGraphics().drawLine(x1, y1, x2, y2); - } - - /** - * Draws a rectangle to this image. - * - * @param x ... - * @param y ... - * @param w ... - * @param h ... - */ - public void drawRect(int x, int y, int w, int h) { - getGraphics().drawRect(x, y, w, h); - } - - /** - * Draws another image to this image. - * - * @param filename ... - * @param x ... - * @param y ... - */ - public void drawImage(String filename, int x, int y) - throws IOException { - Image img = generator.read(filename); - if (img != null) - getGraphics().drawImage(img, x, y, null); - } - - /** - * Draws another image to this image. - * - * @param image ... - * @param x ... - * @param y ... - */ - public void drawImage(ImageWrapper image, int x, int y) - throws IOException { - getGraphics().drawImage(image.getImage(), x, y, null); - } - - /** - * Draws another image to this image. - * - * @param image ... - * @param at ... - */ - public void drawImage(ImageWrapper image, AffineTransform at) - throws IOException { - getGraphics().drawImage(image.getImage(), at, null); - } - - /** - * Draws a filled rectangle to this image. - * - * @param x ... - * @param y ... - * @param w ... - * @param h ... - */ - public void fillRect(int x, int y, int w, int h) { - getGraphics().fillRect(x, y, w, h); - } - - /** - * Returns the width of this image. - * - * @return the width of this image - */ - public int getWidth() { - return width; - } - - /** - * Returns the height of this image. - * - * @return the height of this image - */ - public int getHeight() { - return height; - } - - /** - * Crops the image. - * - * @param x ... - * @param y ... - * @param w ... - * @param h ... - */ - public void crop(int x, int y, int w, int h) { - // do not use the CropFilter any longer: - if (image instanceof BufferedImage && x + w <= width && y + h <= height) { - // BufferedImages define their own function for cropping: - setImage(((BufferedImage)image).getSubimage(x, y, w, h)); - } else { - // The internal image will be a BufferedImage after this. - // Simply create it with the cropped dimensions and draw the image into it: - BufferedImage buffered = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = buffered.createGraphics(); - g2d.drawImage(image, -x, -y, null); - g2d.dispose(); - setImage(buffered); - } - } - - /** - * Trims the image. - * - * @param x the x-coordinate of the pixel specifying the background color - * @param y the y-coordinate of the pixel specifying the background color - */ - - public void trim(int x, int y) { - trim(x, y, true, true, true, true); - } - - /** - * Trims the image. - * - * @param x - * @param y - * @param trimLeft - * @param trimTop - * @param trimRight - * @param trimBottom - */ - public void trim(int x, int y, boolean trimLeft, boolean trimTop, boolean trimRight, boolean trimBottom) { - BufferedImage bi = this.getBufferedImage(); - int color = bi.getRGB(x, y); - int left = 0, top = 0, right = width - 1, bottom = height - 1; - - // create a BufferedImage of only 1 pixel height for fetching the rows of the image in the correct format (ARGB) - // This speeds up things by more than factor 2, compared to the standard BufferedImage.getRGB solution, - // which is supposed to be fast too. This is probably the case because drawing to BufferedImages uses - // very optimized code which may even be hardware accelerated. - if (trimTop || trimBottom) { - BufferedImage row = new BufferedImage(width, 1, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = row.createGraphics(); - int pixels[] = ((DataBufferInt)row.getRaster().getDataBuffer()).getData(); - // make sure alpha values do not add up for each row: - g2d.setComposite(AlphaComposite.Src); - if (trimTop) { - // top: - for (top = 0; top < height; top++) { - g2d.drawImage(bi, null, 0, -top); - // now pixels contains the rgb values of the row y! - // scan this row now: - for (x = 0; x < width; x++) { - if (pixels[x] != color) - break; - } - if (x < width) - break; - } - } - if (trimBottom) { - // bottom: - for (bottom = height - 1; bottom > top; bottom--) { - g2d.drawImage(bi, null, 0, -bottom); - // now pixels contains the rgb values of the row y! - // scan this row now: - for (x = 0; x < width; x++) { - if (pixels[x] != color) - break; - } - if (x < width) - break; - } - } - g2d.dispose(); - } - if (trimLeft || trimRight) { - BufferedImage column = new BufferedImage(1, height, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = column.createGraphics(); - int pixels[] = ((DataBufferInt)column.getRaster().getDataBuffer()).getData(); - // make sure alpha values do not add up for each row: - g2d.setComposite(AlphaComposite.Src); - if (trimLeft) { - // left: - for (left = 0; left < width; left++) { - g2d.drawImage(bi, null, -left, 0); - // now pixels contains the rgb values of the row y! - // scan this row now: - for (y = 0; y < height; y++) { - if (pixels[y] != color) - break; - } - if (y < height) - break; - } - } - if (trimRight) { - // right: - for (right = width - 1; right > left; right--) { - g2d.drawImage(bi, null, -right, 0); - // now pixels contains the rgb values of the row y! - // scan this row now: - for (y = 0; y < height; y++) { - if (pixels[y] != color) - break; - } - if (y < height) - break; - } - } - g2d.dispose(); - } - crop(left, top, right - left + 1, bottom - top + 1); - } - - /** - * Resizes the image using the Graphics2D approach - */ - protected void resize(int w, int h, boolean smooth) { - BufferedImage buffered = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = buffered.createGraphics(); - - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, - smooth ? RenderingHints.VALUE_INTERPOLATION_BICUBIC : - RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR - ); - - g2d.setRenderingHint(RenderingHints.KEY_RENDERING, - smooth ? RenderingHints.VALUE_RENDER_QUALITY : - RenderingHints.VALUE_RENDER_SPEED - ); - - AffineTransform at = AffineTransform.getScaleInstance( - (double) w / width, - (double) h / height - ); - g2d.drawImage(image, at, null); - g2d.dispose(); - setImage(buffered); - } - - /** - * Resizes the image - * - * @param w ... - * @param h ... - */ - public void resize(int w, int h) { - double factor = Math.max( - (double) w / width, - (double) h / height - ); - // If the image is scaled, used the Graphcis2D method, otherwise use AWT: - if (factor > 1f) { - // Scale it with the Graphics2D approach for superior quality. - resize(w, h, true); - } else { - // Area averaging has the best results for shrinking of images: - - // As getScaledInstance is asynchronous, the ImageWaiter is needed here too: - // Image scaled = ImageWaiter.waitForImage(image.getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING)); - // if (scaled == null) - // throw new RuntimeException("Image cannot be resized."); - - // This version is up to 4 times faster than getScaledInstance: - ImageFilterOp filter = new ImageFilterOp(new AreaAveragingScaleFilter(w, h)); - setImage(filter.filter(getBufferedImage(), null)); - } - } - - /** - * Resize the image, using a fast and cheap algorithm - * - * @param w ... - * @param h ... - */ - public void resizeFast(int w, int h) { - resize(w, h, false); - } - - /** - * Reduces the colors used in the image. Necessary before saving as GIF. - * - * @param colors colors the number of colors to use, usually {@literal <}= 256. - */ - public void reduceColors(int colors) { - reduceColors(colors, false); - } - - /** - * Reduces the colors used in the image. Necessary before saving as GIF. - * - * @param colors colors the number of colors to use, usually {@literal <}= 256. - * @param dither ... - */ - public void reduceColors(int colors, boolean dither) { - reduceColors(colors, dither, true); - } - - /** - * Reduce the colors used in this image. Useful and necessary before saving - * the image as GIF file. - * - * @param colors the number of colors to use, usually {@literal <}= 256. - * @param dither ... - * @param alphaToBitmask ... - */ - - public void reduceColors(int colors, boolean dither, boolean alphaToBitmask) { - setImage(ColorQuantizer.quantizeImage(getBufferedImage(), colors, dither, - alphaToBitmask)); - } - - /** - * Save the image. Image format is deduced from filename. - * - * @param filename ... - * @throws IOException - */ - public void saveAs(String filename) - throws IOException { - saveAs(filename, -1f, false); // -1 means default quality - } - - /** - * Saves the image. Image format is deduced from filename. - * - * @param filename ... - * @param quality ... - * @throws IOException - */ - public void saveAs(String filename, float quality) - throws IOException { - saveAs(filename, quality, false); - } - - /** - * Saves the image. Image format is deduced from filename. - * - * @param filename ... - * @param quality ... - * @param alpha ... - * @throws IOException - */ - public void saveAs(String filename, float quality, boolean alpha) - throws IOException { - generator.write(this, checkFilename(filename), quality, alpha); - } - - /** - * Saves the image. Image format is deduced from mimeType. - * - * @param out ... - * @param mimeType ... - * @throws IOException - */ - public void saveAs(OutputStream out, String mimeType) - throws IOException { - generator.write(this, out, mimeType, -1f, false); // -1 means default quality - } - - /** - * Saves the image. Image format is deduced from mimeType. - * - * @param out ... - * @param mimeType ... - * @param quality ... - * @throws IOException - */ - public void saveAs(OutputStream out, String mimeType, float quality) - throws IOException { - generator.write(this, out, mimeType, quality, false); - } - - /** - * Saves the image. Image format is deduced from mimeType. - * - * @param out ... - * @param mimeType ... - * @param quality ... - * @param alpha ... - * @throws IOException - */ - public void saveAs(OutputStream out, String mimeType, float quality, boolean alpha) - throws IOException { - generator.write(this, out, mimeType, quality, alpha); - } - - /** - * Sets the palette index of the transparent color for Images with an - * IndexColorModel. This can be used together with - * {@link helma.image.ImageWrapper#getPixel}. - */ - public void setTransparentPixel(int trans) { - BufferedImage bi = this.getBufferedImage(); - ColorModel cm = bi.getColorModel(); - if (!(cm instanceof IndexColorModel)) - throw new RuntimeException("Image is not indexed!"); - IndexColorModel icm = (IndexColorModel) cm; - int mapSize = icm.getMapSize(); - byte reds[] = new byte[mapSize]; - byte greens[] = new byte[mapSize]; - byte blues[] = new byte[mapSize]; - icm.getReds(reds); - icm.getGreens(greens); - icm.getBlues(blues); - // create the new IndexColorModel with the changed transparentPixel: - icm = new IndexColorModel(icm.getPixelSize(), mapSize, reds, greens, - blues, trans); - // create a new BufferedImage with the new IndexColorModel and the old - // raster: - setImage(new BufferedImage(icm, bi.getRaster(), false, null)); - } - - /** - * Returns the pixel at x, y. If the image is indexed, it returns the - * palette index, otherwise the rgb code of the color is returned. - * - * @param x the x coordinate of the pixel - * @param y the y coordinate of the pixel - * @return the pixel at x, y - */ - public int getPixel(int x, int y) { - BufferedImage bi = this.getBufferedImage(); - if (bi.getColorModel() instanceof IndexColorModel) - return bi.getRaster().getSample(x, y, 0); - else - return bi.getRGB(x, y); - } - - /** - * Utility method to be used by write(). - * Converts file name to absolute path and creates parent directories. - * @param filename the file name - * @return the absolute path for the file name - * @throws IOException if missing directories could not be created - */ - String checkFilename(String filename) throws IOException { - File file = new File(filename).getAbsoluteFile(); - File parent = file.getParentFile(); - if (parent != null && !parent.exists() && !parent.mkdirs()) { - throw new IOException("Error creating directories for " + filename); - } - return file.getPath(); - } -} diff --git a/src/main/java/helma/image/imageio/ImageIOGenerator.java b/src/main/java/helma/image/imageio/ImageIOGenerator.java deleted file mode 100644 index 0b0149e9..00000000 --- a/src/main/java/helma/image/imageio/ImageIOGenerator.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -/* - * ImageIOGenerator defines it's own functions for reading from various - * resources. These return BufferedImages, therefore all the images - * are from the beginning in that format when working with ImageIO - */ - -package helma.image.imageio; - -import helma.image.ImageGenerator; -import helma.image.ImageWrapper; - -import java.awt.image.BufferedImage; -import java.awt.image.DirectColorModel; -import java.awt.image.WritableRaster; -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Iterator; - -import javax.imageio.IIOImage; -import javax.imageio.ImageIO; -import javax.imageio.ImageWriteParam; -import javax.imageio.ImageWriter; -import javax.imageio.stream.ImageOutputStream; - - -/** - * A wrapper for an image that uses the ImageIO Framework. - */ -public class ImageIOGenerator extends ImageGenerator { - - protected void write(ImageWrapper wrapper, ImageWriter writer, float quality, boolean alpha) throws IOException { - BufferedImage bi = wrapper.getBufferedImage(); - // Set some parameters - ImageWriteParam param = writer.getDefaultWriteParam(); - if (param.canWriteCompressed() && - quality >= 0.0 && quality <= 1.0) { - param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); - String[] types = param.getCompressionTypes(); - // If compression types are defined, but none is set, set the first one, - // since setCompressionQuality, which requires MODE_EXPLICIT to be set, - // will complain otherwise. - if (types != null && param.getCompressionType() == null) { - param.setCompressionType(types[0]); - } - param.setCompressionQuality(quality); - } - if (param.canWriteProgressive()) - param.setProgressiveMode(ImageWriteParam.MODE_DISABLED); - // if bi has type ARGB and alpha is false, we have to tell the writer to not use the alpha channel: - // this is especially needed for jpeg files where imageio seems to produce wrong jpeg files right now... - if (bi.getType() == BufferedImage.TYPE_INT_ARGB - && !alpha) { - // create a new BufferedImage that uses a WritableRaster of bi, with all the bands except the alpha band: - WritableRaster raster = bi.getRaster(); - WritableRaster newRaster = raster.createWritableChild( - 0, 0, raster.getWidth(), raster.getHeight(), - 0, 0, new int[] {0, 1, 2 } - ); - // create a ColorModel that represents the one of the ARGB except the alpha channel: - DirectColorModel cm = (DirectColorModel) bi.getColorModel(); - DirectColorModel newCM = new DirectColorModel( - cm.getPixelSize(), cm.getRedMask(), - cm.getGreenMask(), cm.getBlueMask()); - // now create the new buffer that is used ot write the image: - BufferedImage rgbBuffer = new BufferedImage(newCM, - newRaster, false, null); - writer.write(null, new IIOImage(rgbBuffer, null, - null), param); - } else { - writer.write(null, new IIOImage(bi, null, null), - param); - } - } - - /** - * Saves the image. Image format is deduced from filename. - * - * @param wrapper the image to write - * @param filename the file to write to - * @param quality image quality - * @param alpha to enable alpha - * @throws IOException - * @see helma.image.ImageGenerator#write(helma.image.ImageWrapper, java.lang.String, float, boolean) - */ - public void write(ImageWrapper wrapper, String filename, float quality, boolean alpha) throws IOException { - // determine suffix: - int pos = filename.lastIndexOf('.'); - if (pos != -1) { - String extension = filename.substring(pos + 1, filename.length()).toLowerCase(); - - // Find a writer for that file suffix - ImageWriter writer = null; - Iterator iter = ImageIO.getImageWritersBySuffix(extension); - if (iter.hasNext()) - writer = (ImageWriter)iter.next(); - if (writer != null) { - ImageOutputStream ios = null; - try { - // Prepare output file - File file = new File(filename); - if (file.exists()) - file.delete(); - ios = ImageIO.createImageOutputStream(file); - writer.setOutput(ios); - this.write(wrapper, writer, quality, alpha); - } finally { - if (ios != null) - ios.close(); - writer.dispose(); - } - } - } - } - - /** - * Saves the image. Image format is deduced from type. - * - * @param wrapper the image to write - * @param out the outputstream to write to - * @param mimeType the mime type - * @param quality image quality - * @param alpha to enable alpha - * @throws IOException - * @see helma.image.ImageGenerator#write(helma.image.ImageWrapper, java.io.OutputStream, java.lang.String, float, boolean) - */ - public void write(ImageWrapper wrapper, OutputStream out, String mimeType, float quality, boolean alpha) throws IOException { - // Find a writer for that type - ImageWriter writer = null; - Iterator iter = ImageIO.getImageWritersByMIMEType(mimeType); - if (iter.hasNext()) - writer = (ImageWriter)iter.next(); - if (writer != null) { - ImageOutputStream ios = null; - try { - ios = ImageIO.createImageOutputStream(out); - writer.setOutput(ios); - this.write(wrapper, writer, quality, alpha); - } finally { - if (ios != null) - ios.close(); - writer.dispose(); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/helma/image/imageio/gif/GIFImageWriteParam.java b/src/main/java/helma/image/imageio/gif/GIFImageWriteParam.java deleted file mode 100644 index 14b370e2..00000000 --- a/src/main/java/helma/image/imageio/gif/GIFImageWriteParam.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -/* - * The imageio integration is inspired by the package org.freehep.graphicsio.gif - */ - -package helma.image.imageio.gif; - -import java.util.*; -import javax.imageio.*; - -public class GIFImageWriteParam extends ImageWriteParam { - - public GIFImageWriteParam(Locale locale) { - super(locale); - canWriteProgressive = true; - progressiveMode = MODE_DEFAULT; - } - - public ImageWriteParam getWriteParam(Properties properties) { - return this; - } -} \ No newline at end of file diff --git a/src/main/java/helma/image/imageio/gif/GIFImageWriter.java b/src/main/java/helma/image/imageio/gif/GIFImageWriter.java deleted file mode 100644 index 94a99c2c..00000000 --- a/src/main/java/helma/image/imageio/gif/GIFImageWriter.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -/* - * The imageio integration is inspired by the package org.freehep.graphicsio.gif - */ - -package helma.image.imageio.gif; - -import java.awt.image.*; -import java.io.*; -import javax.imageio.*; -import javax.imageio.metadata.*; - -import helma.image.*; - -public class GIFImageWriter extends ImageWriter { - GIFEncoder encoder; - - public GIFImageWriter(GIFImageWriterSpi originatingProvider) { - super(originatingProvider); - encoder = new GIFEncoder(); - } - - public void write(IIOMetadata streamMetadata, IIOImage image, - ImageWriteParam param) throws IOException { - if (image == null) - throw new IllegalArgumentException("image == null"); - - if (image.hasRaster()) - throw new UnsupportedOperationException("Cannot write rasters"); - - Object output = getOutput(); - if (output == null) - throw new IllegalStateException("output was not set"); - - if (param == null) - param = getDefaultWriteParam(); - - RenderedImage ri = image.getRenderedImage(); - if (!(ri instanceof BufferedImage)) - throw new IOException("RenderedImage is not a BufferedImage"); - if (!(output instanceof DataOutput)) - throw new IOException("output is not a DataOutput"); - encoder.encode((BufferedImage) ri, (DataOutput) output, - param.getProgressiveMode() != ImageWriteParam.MODE_DISABLED, null); - } - - public IIOMetadata convertStreamMetadata(IIOMetadata inData, - ImageWriteParam param) { - return null; - } - - public IIOMetadata convertImageMetadata(IIOMetadata inData, - ImageTypeSpecifier imageType, ImageWriteParam param) { - return null; - } - - public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, - ImageWriteParam param) { - return null; - } - - public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param) { - return null; - } - - public ImageWriteParam getDefaultWriteParam() { - return new GIFImageWriteParam(getLocale()); - } -} \ No newline at end of file diff --git a/src/main/java/helma/image/imageio/gif/GIFImageWriterSpi.java b/src/main/java/helma/image/imageio/gif/GIFImageWriterSpi.java deleted file mode 100644 index 778b7ce7..00000000 --- a/src/main/java/helma/image/imageio/gif/GIFImageWriterSpi.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -/* - * The imageio integration is inspired by the package org.freehep.graphicsio.gif - */ - -package helma.image.imageio.gif; - -import java.io.*; -import java.util.*; -import javax.imageio.*; -import javax.imageio.spi.*; - -public class GIFImageWriterSpi extends ImageWriterSpi { - - public GIFImageWriterSpi() { - super( - "Helma Object Publisher, http://helma.org/", - "1.0", - new String[] {"gif", "GIF"}, - new String[] {"gif", "GIF"}, - new String[] {"image/gif", "image/x-gif"}, - "helma.image.imageio.gif.GIFImageWriter", - STANDARD_OUTPUT_TYPE, - null, - false, null, null, null, null, - false, null, null, null, null - ); - } - - public String getDescription(Locale locale) { - return "Graphics Interchange Format"; - } - - public ImageWriter createWriterInstance(Object extension) - throws IOException { - return new GIFImageWriter(this); - } - - public boolean canEncodeImage(ImageTypeSpecifier type) { - // FIXME handle # colors - return true; - } -} \ No newline at end of file diff --git a/src/main/java/helma/main/ApplicationManager.java b/src/main/java/helma/main/ApplicationManager.java deleted file mode 100644 index e699a8d8..00000000 --- a/src/main/java/helma/main/ApplicationManager.java +++ /dev/null @@ -1,598 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - */ - -package helma.main; - -import java.io.File; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -import org.apache.commons.logging.Log; -import org.apache.xmlrpc.XmlRpcHandler; - -import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.server.handler.ContextHandlerCollection; -import org.eclipse.jetty.server.handler.ResourceHandler; -import org.eclipse.jetty.ee9.servlet.ServletContextHandler; -import org.eclipse.jetty.ee9.servlet.ServletHolder; -import org.eclipse.jetty.util.resource.ResourceFactory; - -import helma.framework.core.Application; -import helma.framework.repository.FileRepository; -import helma.framework.repository.Repository; -import helma.servlet.EmbeddedServletClient; -import helma.util.ResourceProperties; -import helma.util.StringUtils; - -/** - * This class is responsible for starting and stopping Helma applications. - */ -public class ApplicationManager implements XmlRpcHandler { - private Hashtable descriptors; - private Hashtable applications; - private Hashtable xmlrpcHandlers; - private ResourceProperties props; - private Server server; - private long lastModified; - private ContextHandlerCollection context; - private JettyServer jetty = null; - - /** - * Creates a new ApplicationManager object. - * - * @param props the properties defining the running apps - * @param server the server instance - */ - public ApplicationManager(ResourceProperties props, Server server) { - this.props = props; - this.server = server; - this.descriptors = new Hashtable(); - this.applications = new Hashtable(); - this.xmlrpcHandlers = new Hashtable(); - this.lastModified = 0; - this.jetty = server.jetty; - } - - /** - * Called regularely check applications property file - * to create and start new applications. - */ - protected void checkForChanges() { - if (this.props.lastModified() > this.lastModified && this.server.getApplicationsOption() == null) { - try { - for (Enumeration e = this.props.keys(); e.hasMoreElements();) { - String appName = (String) e.nextElement(); - - if ((appName.indexOf(".") == -1) && //$NON-NLS-1$ - (this.applications.get(appName) == null)) { - AppDescriptor appDesc = new AppDescriptor(appName); - appDesc.start(); - appDesc.bind(); - } - } - - // then stop deleted ones - for (Enumeration e = this.descriptors.elements(); e.hasMoreElements();) { - AppDescriptor appDesc = (AppDescriptor) e.nextElement(); - - // check if application has been removed and should be stopped - if (!this.props.containsKey(appDesc.appName)) { - appDesc.stop(); - } else if (this.server.jetty != null) { - // If application continues to run, remount - // as the mounting options may have changed. - AppDescriptor ndesc = new AppDescriptor(appDesc.appName); - ndesc.app = appDesc.app; - appDesc.unbind(); - ndesc.bind(); - this.descriptors.put(ndesc.appName, ndesc); - } - } - } catch (Exception mx) { - getLogger().error("Error checking applications", mx); - } - - this.lastModified = System.currentTimeMillis(); - } - } - - - /** - * Start an application by name - */ - public void start(String appName) { - AppDescriptor desc = new AppDescriptor(appName); - desc.start(); - } - - /** - * Bind an application by name - */ - public void register(String appName) { - AppDescriptor desc = (AppDescriptor) this.descriptors.get(appName); - if (desc != null) { - desc.bind(); - } - } - - /** - * Stop an application by name - */ - public void stop(String appName) { - AppDescriptor desc = (AppDescriptor) this.descriptors.get(appName); - if (desc != null) { - desc.stop(); - } - } - - - /** - * Start all applications listed in the properties - */ - public void startAll() { - try { - String[] apps = this.server.getApplicationsOption(); - if (apps != null) { - for (int i = 0; i < apps.length; i++) { - AppDescriptor desc = new AppDescriptor(apps[i]); - desc.start(); - } - } else { - for (Enumeration e = this.props.keys(); e.hasMoreElements();) { - String appName = (String) e.nextElement(); - - if (appName.indexOf(".") == -1) { //$NON-NLS-1$ - String appValue = this.props.getProperty(appName); - - if (appValue != null && appValue.length() > 0) { - appName = appValue; - } - - AppDescriptor desc = new AppDescriptor(appName); - desc.start(); - } - } - } - - for (Enumeration e = this.descriptors.elements(); e.hasMoreElements();) { - AppDescriptor appDesc = (AppDescriptor) e.nextElement(); - appDesc.bind(); - } - - this.lastModified = System.currentTimeMillis(); - } catch (Exception mx) { - getLogger().error("Error starting applications", mx); - mx.printStackTrace(); - } - } - - /** - * Stop all running applications. - */ - public void stopAll() { - for (Enumeration en = this.descriptors.elements(); en.hasMoreElements();) { - try { - AppDescriptor appDesc = (AppDescriptor) en.nextElement(); - - appDesc.stop(); - } catch (Exception x) { - // ignore exception in application shutdown - } - } - } - - /** - * Get an array containing all currently running applications. - */ - public Object[] getApplications() { - return this.applications.values().toArray(); - } - - /** - * Get an application by name. - */ - public Application getApplication(String name) { - return (Application) this.applications.get(name); - } - - /** - * Implements org.apache.xmlrpc.XmlRpcHandler.execute() - */ - public Object execute(String method, Vector params) - throws Exception { - int dot = method.indexOf("."); //$NON-NLS-1$ - - if (dot == -1) { - throw new Exception("Method name \"" + method + - "\" does not specify a handler application"); - } - - if ((dot == 0) || (dot == (method.length() - 1))) { - throw new Exception("\"" + method + "\" is not a valid XML-RPC method name"); - } - - String handler = method.substring(0, dot); - String method2 = method.substring(dot + 1); - Application app = (Application) this.xmlrpcHandlers.get(handler); - - if (app == null) { - app = (Application) this.xmlrpcHandlers.get("*"); //$NON-NLS-1$ - // use the original method name, the handler is resolved within the app. - method2 = method; - } - - if (app == null) { - throw new Exception("Handler \"" + handler + "\" not found for " + method); - } - - return app.executeXmlRpc(method2, params); - } - - private String getMountpoint(String mountpoint) { - mountpoint = mountpoint.trim(); - - if ("".equals(mountpoint)) { //$NON-NLS-1$ - return "/"; //$NON-NLS-1$ - } else if (!mountpoint.startsWith("/")) { //$NON-NLS-1$ - return "/" + mountpoint; //$NON-NLS-1$ - } - - return mountpoint; - } - - private String joinMountpoint(String prefix, String suffix) { - if (prefix.endsWith("/") || suffix.startsWith("/")) { //$NON-NLS-1$//$NON-NLS-2$ - return prefix+suffix; - } - return prefix+"/"+suffix; //$NON-NLS-1$ - } - - private String getPathPattern(String mountpoint) { - if (!mountpoint.startsWith("/")) { //$NON-NLS-1$ - mountpoint = "/"+mountpoint; //$NON-NLS-1$ - } - - if ("/".equals(mountpoint)) { //$NON-NLS-1$ - return "/"; //$NON-NLS-1$ - } - - if (mountpoint.endsWith("/")) { //$NON-NLS-1$ - return mountpoint.substring(0, mountpoint.length()-1); - } - - return mountpoint; - } - - private File getAbsoluteFile(String path) { - // make sure our directory has an absolute path, - // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4117557 - File file = new File(path); - if (file.isAbsolute()) { - return file; - } - return file.getAbsoluteFile(); - } - - private Log getLogger() { - return this.server.getLogger(); - } - - private String findResource(String path) { - File file = new File(path); - if (!file.isAbsolute() && !file.exists()) { - file = new File(this.server.getHopHome(), path); - } - return file.getAbsolutePath(); - } - - /** - * Inner class that describes an application and its start settings. - */ - class AppDescriptor { - - Application app; - - private ContextHandler staticContext = null; - private ServletContextHandler appContext = null; - - String appName; - File appDir; - File dbDir; - String mountpoint; - String pathPattern; - String staticDir; - String protectedStaticDir; - String staticMountpoint; - boolean staticIndex; - String[] staticHome; - String xmlrpcHandlerName; - String cookieDomain; - String sessionCookieName; - String protectedSessionCookie; - String uploadLimit; - String uploadSoftfail; - String debug; - Repository[] repositories; - String servletClassName; - - /** - * extend apps.properties, add [appname].ignore - */ - String ignoreDirs; - - /** - * Creates an AppDescriptor from the properties. - * @param name the application name - */ - AppDescriptor(String name) { - ResourceProperties conf = ApplicationManager.this.props.getSubProperties(name + '.'); - this.appName = name; - this.mountpoint = getMountpoint(conf.getProperty("mountpoint", this.appName)); //$NON-NLS-1$ - this.pathPattern = getPathPattern(this.mountpoint); - this.staticDir = conf.getProperty("static"); //$NON-NLS-1$ - this.staticMountpoint = getPathPattern(conf.getProperty("staticMountpoint", //$NON-NLS-1$ - joinMountpoint(this.mountpoint, "static"))); //$NON-NLS-1$ - this.staticIndex = "true".equalsIgnoreCase(conf.getProperty("staticIndex")); //$NON-NLS-1$//$NON-NLS-2$ - String home = conf.getProperty("staticHome"); //$NON-NLS-1$ - if (home == null) { - this.staticHome = new String[] {"index.html", "index.htm"}; //$NON-NLS-1$ //$NON-NLS-2$ - } else { - this.staticHome = StringUtils.split(home, ","); //$NON-NLS-1$ - } - this.protectedStaticDir = conf.getProperty("protectedStatic"); //$NON-NLS-1$ - - this.cookieDomain = conf.getProperty("cookieDomain"); //$NON-NLS-1$ - this.sessionCookieName = conf.getProperty("sessionCookieName"); //$NON-NLS-1$ - this.protectedSessionCookie = conf.getProperty("protectedSessionCookie"); //$NON-NLS-1$ - this.uploadLimit = conf.getProperty("uploadLimit"); //$NON-NLS-1$ - this.uploadSoftfail = conf.getProperty("uploadSoftfail"); //$NON-NLS-1$ - this.debug = conf.getProperty("debug"); //$NON-NLS-1$ - String appDirName = conf.getProperty("appdir"); //$NON-NLS-1$ - this.appDir = (appDirName == null) ? null : getAbsoluteFile(appDirName); - String dbDirName = conf.getProperty("dbdir"); //$NON-NLS-1$ - this.dbDir = (dbDirName == null) ? null : getAbsoluteFile(dbDirName); - this.servletClassName = conf.getProperty("servletClass"); //$NON-NLS-1$ - - // got ignore dirs - this.ignoreDirs = conf.getProperty("ignore"); //$NON-NLS-1$ - - // read and configure app repositories - ArrayList repositoryList = new ArrayList(); - Class[] parameters = { String.class }; - for (int i = 0; true; i++) { - String repositoryArgs = conf.getProperty("repository." + i); //$NON-NLS-1$ - - if (repositoryArgs != null) { - // lookup repository implementation - String repositoryImpl = conf.getProperty("repository." + i + //$NON-NLS-1$ - ".implementation"); //$NON-NLS-1$ - if (repositoryImpl == null) { - // implementation not set manually, have to guess it - if (repositoryArgs.endsWith(".zip")) { //$NON-NLS-1$ - repositoryArgs = findResource(repositoryArgs); - repositoryImpl = "helma.framework.repository.ZipRepository"; //$NON-NLS-1$ - } else if (repositoryArgs.endsWith(".js")) { //$NON-NLS-1$ - repositoryArgs = findResource(repositoryArgs); - repositoryImpl = "helma.framework.repository.SingleFileRepository"; //$NON-NLS-1$ - } else { - repositoryArgs = findResource(repositoryArgs); - repositoryImpl = "helma.framework.repository.FileRepository"; //$NON-NLS-1$ - } - } - - try { - Repository newRepository = (Repository) Class.forName(repositoryImpl) - .getConstructor(parameters) - .newInstance(new Object[] {repositoryArgs}); - repositoryList.add(newRepository); - } catch (Exception ex) { - getLogger().error("Adding repository " + repositoryArgs + " failed. " + - "Will not use that repository. Check your initArgs!", ex); - } - } else { - // we always scan repositories 0-9, beyond that only if defined - if (i > 9) { - break; - } - } - } - - if (this.appDir != null) { - FileRepository appRep = new FileRepository(this.appDir); - if (!repositoryList.contains(appRep)) { - repositoryList.add(appRep); - } - } else if (repositoryList.isEmpty()) { - repositoryList.add(new FileRepository( - new File(ApplicationManager.this.server.getAppsHome(), this.appName))); - } - - this.repositories = (Repository[]) repositoryList.toArray(new Repository[repositoryList.size()]); - } - - - void start() { - getLogger().info("Building application " + appName); - - try { - // create the application instance - this.app = new Application(this.appName, ApplicationManager.this.server, this.repositories, this.appDir, this.dbDir); - - // register ourselves - ApplicationManager.this.descriptors.put(this.appName, this); - ApplicationManager.this.applications.put(this.appName, this.app); - - // the application is started later in the register method, when it's bound - this.app.init(this.ignoreDirs); - - // set application URL prefix if it isn't set in app.properties - if (!this.app.hasExplicitBaseURI()) { - this.app.setBaseURI(this.mountpoint); - } - - this.app.start(); - } catch (Exception x) { - getLogger().error("Error creating application " + appName, x); - x.printStackTrace(); - } - } - - void stop() { - getLogger().info("Stopping application " + appName); - - // unbind application - unbind(); - - // stop application - try { - app.stop(); - getLogger().info("Stopped application " + appName); - } catch (Exception x) { - getLogger().error("Couldn't stop app", x); - } - - ApplicationManager.this.descriptors.remove(this.appName); - ApplicationManager.this.applications.remove(this.appName); - } - - void bind() { - try { - getLogger().info("Binding application " + appName + " :: " + app.hashCode() + " :: " + this.hashCode()); - - // set application URL prefix if it isn't set in app.properties - if (!this.app.hasExplicitBaseURI()) { - this.app.setBaseURI(this.mountpoint); - } - - // bind to Jetty HTTP server - if (jetty != null) { - if (context == null) { - context = new ContextHandlerCollection(); - jetty.getHttpServer().setHandler(context); - } - - // if there is a static direcory specified, mount it - if (this.staticDir != null) { - String staticPath = getAbsoluteFile(this.staticDir).getCanonicalPath(); - - getLogger().info("Serving static from " + staticPath); - getLogger().info("Mounting static at " + staticMountpoint); - - ResourceHandler rhandler = new ResourceHandler(); - rhandler.setBaseResource(ResourceFactory.of(rhandler).newResource(staticPath)); - rhandler.setWelcomeFiles(staticHome); - - ContextHandler staticContext = new ContextHandler(); - staticContext.setContextPath(staticMountpoint); - staticContext.setHandler(rhandler); - - ApplicationManager.this.context.addHandler(staticContext); - staticContext.start(); - } - - // I hope I am correct assuming Helma does not need Jetty’s session management, but using - // `ServletContextHandler.SESSIONS` causes an exception: Shared scheduler not started - appContext = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); - appContext.setContextPath(pathPattern); - context.addHandler(appContext); - - Class servletClass = servletClassName == null ? - EmbeddedServletClient.class : Class.forName(servletClassName); - ServletHolder holder = new ServletHolder(servletClass); - holder.setInitParameter("application", appName); - appContext.addServlet(holder, "/*"); - - if (this.cookieDomain != null) { - holder.setInitParameter("cookieDomain", this.cookieDomain); //$NON-NLS-1$ - } - - if (this.sessionCookieName != null) { - holder.setInitParameter("sessionCookieName", this.sessionCookieName); //$NON-NLS-1$ - } - - if (this.protectedSessionCookie != null) { - holder.setInitParameter("protectedSessionCookie", this.protectedSessionCookie); //$NON-NLS-1$ - } - - if (this.uploadLimit != null) { - holder.setInitParameter("uploadLimit", this.uploadLimit); //$NON-NLS-1$ - } - - if (this.uploadSoftfail != null) { - holder.setInitParameter("uploadSoftfail", this.uploadSoftfail); //$NON-NLS-1$ - } - - if (this.debug != null) { - holder.setInitParameter("debug", this.debug); //$NON-NLS-1$ - } - - if (protectedStaticDir != null) { - String protectedContent = getAbsoluteFile(protectedStaticDir).getCanonicalPath(); - appContext.setBaseResourceAsString(protectedContent); - getLogger().info("Serving protected static from " + protectedContent); - } - - // Remap the context paths and start - ApplicationManager.this.context.mapContexts(); - this.appContext.start(); - } - - // register as XML-RPC handler - this.xmlrpcHandlerName = this.app.getXmlRpcHandlerName(); - ApplicationManager.this.xmlrpcHandlers.put(this.xmlrpcHandlerName, this.app); - } catch (Exception x) { - getLogger().error("Couldn't bind app", x); - x.printStackTrace(); - } - } - - void unbind() { - getLogger().info("Unbinding application " + appName); - - try { - // unbind from Jetty HTTP server - if (ApplicationManager.this.jetty != null) { - if (this.appContext != null) { - // Adding appContext to the ContextHandlerCollection works (see above) but removing it causes an exception of - // incompatible types: ServletContextHandler cannot be converted to Handler - //ApplicationManager.this.context.removeHandler(this.appContext); - this.appContext.stop(); - this.appContext.destroy(); - this.appContext = null; - } - - if (this.staticContext != null) { - ApplicationManager.this.context.removeHandler(this.staticContext); - this.staticContext.stop(); - this.staticContext.destroy(); - this.staticContext = null; - } - ApplicationManager.this.context.mapContexts(); - } - - // unregister as XML-RPC handler - if (this.xmlrpcHandlerName != null) { - ApplicationManager.this.xmlrpcHandlers.remove(this.xmlrpcHandlerName); - } - } catch (Exception x) { - getLogger().error("Couldn't unbind app", x); - } - - } - - @Override - public String toString() { - return "[AppDescriptor "+this.app+"]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } -} diff --git a/src/main/java/helma/main/CommandlineRunner.java b/src/main/java/helma/main/CommandlineRunner.java deleted file mode 100644 index aeaaee1f..00000000 --- a/src/main/java/helma/main/CommandlineRunner.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.main; - -import helma.framework.core.Application; -import java.io.File; -import java.util.*; - -/** - * Helma command line runner class. This class creates and starts a single application, - * invokes a function in, writes its return value to the console and exits. - * - * @author Stefan Pollach - */ -public class CommandlineRunner { - - /** - * boot method for running a request from the command line. - * This retrieves the Helma home directory, creates the app and - * runs the function. - * - * @param args command line arguments - * - * @throws Exception if the Helma home dir or classpath couldn't be built - */ - public static void main(String[] args) throws Exception { - - ServerConfig config = new ServerConfig(); - String commandStr = null; - Vector funcArgs = new Vector(); - - // get possible environment setting for helma home - if (System.getProperty("helma.home")!=null) { - config.setHomeDir(new File(System.getProperty("helma.home"))); - } - - // parse arguments - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-h") && ((i + 1) < args.length)) { - config.setHomeDir(new File(args[++i])); - } else if (args[i].equals("-f") && ((i + 1) < args.length)) { - config.setPropFile(new File(args[++i])); - } else if (commandStr != null) { - // we're past the command str, all args for the function - funcArgs.add (args[i]); - } else if ((i%2)==0 && !args[i].startsWith("-")) { - // first argument without a switch - commandStr = args[i]; - } - } - - // get server.properties from home dir or vv - try { - Server.guessConfig (config); - } catch (Exception ex) { - printUsageError(ex.toString()); - System.exit(1); - } - - String appName = null; - String function = null; - // now split application name + path/function-name - try { - int pos1 = commandStr.indexOf("."); - appName = commandStr.substring(0, pos1); - function = commandStr.substring(pos1+1); - } catch (Exception ex) { - printUsageError(); - System.exit(1); - } - - // init a server instance and start the application - Server server = new Server(config); - server.init(); - server.checkAppManager(); - server.startApplication(appName); - Application app = server.getApplication(appName); - - // execute the function - try { - Object result = app.executeExternal(function, funcArgs); - if (result != null) { - System.out.println(result.toString()); - } - } catch (Exception ex) { - System.out.println("Error in application " + appName + ":"); - System.out.println(ex.getMessage()); - if ("true".equals(server.getProperty("debug"))) { - System.out.println(""); - ex.printStackTrace(); - } - } - - // stop the application and server - server.stop(); - server.shutdown(); - } - - - - /** - * print the usage hints and prefix them with a message. - */ - public static void printUsageError(String msg) { - System.out.println(msg); - printUsageError(); - } - - - /** - * print the usage hints - */ - public static void printUsageError() { - System.out.println(""); - System.out.println("Error parsing command"); - System.out.println(""); - System.out.println("Usage: java helma.main.launcher.Commandline [options] [appname].[function] [argument-list]"); - System.out.println(""); - System.out.println("Possible options:"); - System.out.println(" -h dir Specify hop home directory"); - System.out.println(" -f file Specify server.properties file"); - System.out.println(""); - } - -} diff --git a/src/main/java/helma/main/HelmaSecurityManager.java b/src/main/java/helma/main/HelmaSecurityManager.java deleted file mode 100644 index aebf5400..00000000 --- a/src/main/java/helma/main/HelmaSecurityManager.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.main; - -import helma.framework.core.AppClassLoader; -import java.io.FileDescriptor; -import java.net.InetAddress; -import java.security.Permission; -import java.util.HashSet; - -/** - * Liberal security manager for Helma system that makes sure application code - * is not allowed to exit the VM and set a security manager. - * - * This class can be subclassed to implement actual security policies. It contains - * a utility method getApplication that can be used to determine - * the name of the application trying to execute the action in question, if any. - */ -public class HelmaSecurityManager extends SecurityManager { - // The set of actions forbidden to application code. - // We are pretty permissive, forbidding only System.exit() - // and setting the security manager. - private final static HashSet forbidden = new HashSet(); - - static { - forbidden.add("exitVM"); - forbidden.add("setSecurityManager"); - } - - /** - * - * - * @param p ... - */ - public void checkPermission(Permission p) { - if (p instanceof RuntimePermission) { - if (forbidden.contains(p.getName())) { - Class[] classes = getClassContext(); - - for (int i = 0; i < classes.length; i++) { - if (classes[i].getClassLoader() instanceof AppClassLoader) { - throw new SecurityException(p.getName() + - " not allowed for application code"); - } - } - } - } - } - - /** - * - * - * @param p ... - * @param context ... - */ - public void checkPermission(Permission p, Object context) { - } - - /** - * - */ - public void checkCreateClassLoader() { - } - - /** - * - * - * @param thread ... - */ - public void checkAccess(Thread thread) { - } - - /** - * - * - * @param group ... - */ - public void checkAccess(ThreadGroup group) { - } - - /** - * - * - * @param status ... - */ - public void checkExit(int status) { - Class[] classes = getClassContext(); - - for (int i = 0; i < classes.length; i++) { - if (classes[i].getClassLoader() instanceof AppClassLoader) { - throw new SecurityException("operation not allowed for application code"); - } - } - } - - /** - * - * - * @param cmd ... - */ - public void checkExec(String cmd) { - } - - /** - * - * - * @param lib ... - */ - public void checkLink(String lib) { - } - - /** - * - * - * @param fdesc ... - */ - public void checkRead(FileDescriptor fdesc) { - } - - /** - * - * - * @param file ... - */ - public void checkRead(String file) { - } - - /** - * - * - * @param file ... - * @param context ... - */ - public void checkRead(String file, Object context) { - } - - /** - * - * - * @param fdesc ... - */ - public void checkWrite(FileDescriptor fdesc) { - } - - /** - * - * - * @param file ... - */ - public void checkWrite(String file) { - } - - /** - * - * - * @param file ... - */ - public void checkDelete(String file) { - } - - /** - * - * - * @param host ... - * @param port ... - */ - public void checkConnect(String host, int port) { - } - - /** - * - * - * @param host ... - * @param port ... - * @param context ... - */ - public void checkConnect(String host, int port, Object context) { - } - - /** - * - * - * @param port ... - */ - public void checkListen(int port) { - } - - /** - * - * - * @param host ... - * @param port ... - */ - public void checkAccept(String host, int port) { - } - - /** - * - * - * @param addr ... - */ - public void checkMulticast(InetAddress addr) { - } - - /** - * - */ - public void checkPropertiesAccess() { - } - - /** - * - * - * @param key ... - */ - public void checkPropertyAccess(String key) { - } - - /** - * - * - * @param window ... - * - * @return ... - */ - public boolean checkTopLevelWindow(Object window) { - return true; - } - - /** - * - */ - public void checkPrintJobAccess() { - } - - /** - * - */ - public void checkSystemClipboardAccess() { - } - - /** - * - */ - public void checkAwtEventQueueAccess() { - } - - /** - * - * - * @param pkg ... - */ - public void checkPackageAccess(String pkg) { - } - - /** - * - * - * @param pkg ... - */ - public void checkPackageDefinition(String pkg) { - } - - /** - * - */ - public void checkSetFactory() { - } - - /** - * - * - * @param clazz ... - * @param which ... - */ - public void checkMemberAccess(Class clazz, int which) { - } - - /** - * - * - * @param target ... - */ - public void checkSecurityAccess(String target) { - } - - /** - * Utility method that returns the name of the application trying - * to execute the code in question. Returns null if the current code - * does not belong to any application. - */ - protected String getApplication() { - Class[] classes = getClassContext(); - - for (int i = 0; i < classes.length; i++) { - if (classes[i].getClassLoader() instanceof AppClassLoader) { - return ((AppClassLoader) classes[i].getClassLoader()).getAppName(); - } - } - - // no application class loader found in stack - return null - return null; - } -} diff --git a/src/main/java/helma/main/HelmaShutdownHook.java b/src/main/java/helma/main/HelmaShutdownHook.java deleted file mode 100644 index f3eff903..00000000 --- a/src/main/java/helma/main/HelmaShutdownHook.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.main; - -import helma.util.*; -import org.apache.commons.logging.LogFactory; - -/** - * ShutdownHook that shuts down all running Helma applications on exit. - */ -public class HelmaShutdownHook extends Thread { - - - /** - * - */ - public void run() { - System.err.println("Shutting down Helma - please stand by..."); - - Server server = Server.getServer(); - if (server != null) { - server.stop(); - server.shutdown(); - } - } -} diff --git a/src/main/java/helma/main/JettyServer.java b/src/main/java/helma/main/JettyServer.java deleted file mode 100644 index 83e09bcf..00000000 --- a/src/main/java/helma/main/JettyServer.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.main; - -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.HttpConfiguration; -import org.eclipse.jetty.server.HttpConnectionFactory; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.URLResourceFactory; -import org.eclipse.jetty.xml.XmlConfiguration; - -import java.net.URL; -import java.net.InetSocketAddress; -import java.io.IOException; -import java.io.File; - -public class JettyServer { - - // the embedded web server - protected org.eclipse.jetty.server.Server http; - - public static JettyServer init(Server server, ServerConfig config) throws IOException { - File configFile = config.getConfigFile(); - if (configFile != null && configFile.exists()) { - URLResourceFactory resourceFactory = new URLResourceFactory(); - Resource resource = resourceFactory.newResource(configFile.toURI()); - return new JettyServer(resource); - } else if (config.hasWebsrvPort()) { - return new JettyServer(config.getWebsrvPort(), server); - } - return null; - } - - private JettyServer(Resource resource) throws IOException { - http = new org.eclipse.jetty.server.Server(); - - try { - XmlConfiguration config = new XmlConfiguration(resource); - config.configure(http); - - } catch (IOException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException("Jetty configuration problem: " + e); - } - } - - private JettyServer(InetSocketAddress webPort, Server server) - throws IOException { - - http = new org.eclipse.jetty.server.Server(); - - // start embedded web server if port is specified - if (webPort != null) { - HttpConfiguration httpConfig = new HttpConfiguration(); - httpConfig.setSendServerVersion(false); - httpConfig.setSendDateHeader(false); - HttpConnectionFactory connectionFactory = new HttpConnectionFactory(httpConfig); - - ServerConnector connector = new ServerConnector(http, -1, -1, connectionFactory); - connector.setHost(webPort.getAddress().getHostAddress()); - connector.setPort(webPort.getPort()); - connector.setIdleTimeout(30000); - connector.setAcceptorPriorityDelta(0); - connector.setAcceptQueueSize(0); - - http.addConnector(connector); - } - - } - - public org.eclipse.jetty.server.Server getHttpServer() { - return http; - } - - public void start() throws Exception { - openListeners(); - http.start(); - } - - public void stop() throws Exception { - http.stop(); - } - - public void destroy() { - http.destroy(); - } - - private void openListeners() throws IOException { - // opening the listener here allows us to run on privileged port 80 under jsvc - // even as non-root user, because init() is called with root privileges - // while start() will be called with the user we will actually run as - for (var connector : http.getConnectors()) { - if (connector instanceof ServerConnector) { - ((ServerConnector) connector).open(); - } - } - } -} diff --git a/src/main/java/helma/main/Server.java b/src/main/java/helma/main/Server.java deleted file mode 100644 index d951adae..00000000 --- a/src/main/java/helma/main/Server.java +++ /dev/null @@ -1,810 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile: Server.java,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.main; - -import helma.extensions.HelmaExtension; -import helma.framework.repository.FileResource; -import helma.framework.core.*; -import helma.objectmodel.db.DbSource; -import helma.util.*; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.xmlrpc.*; - -import java.io.*; -import java.util.*; -import java.net.*; - -import helma.util.ResourceProperties; - -/** - * Helma server main class. - */ -public class Server implements Runnable { - // version string - public static final String version = "__version__"; - - // build date - public static final String buildDate = "__builddate__"; - - // commit hash - public static final String commitHash = "__commithash__"; - - // static server instance - private static Server server; - - // Server home directory - protected File hopHome; - - // server-wide properties - ResourceProperties appsProps; - ResourceProperties dbProps; - ResourceProperties sysProps; - - // our logger - private Log logger; - // are we using helma.util.Logging? - private boolean helmaLogging; - - // server start time - public final long starttime; - - // if paranoid == true we only accept XML-RPC connections from - // explicitly listed hosts. - public boolean paranoid; - private ApplicationManager appManager; - private Vector extensions; - private Thread mainThread; - - // configuration - ServerConfig config; - - // map of server-wide database sources - Hashtable dbSources; - - // the embedded web server - // protected Serve websrv; - protected JettyServer jetty; - - // the XML-RPC server - protected WebServer xmlrpc; - - Thread shutdownhook; - - - /** - * Constructs a new Server instance with an array of command line options. - * TODO make this a singleton - * @param config the configuration - */ - public Server(ServerConfig config) { - server = this; - starttime = System.currentTimeMillis(); - - this.config = config; - hopHome = config.getHomeDir(); - if (hopHome == null) { - throw new RuntimeException("helma.home property not set"); - } - - // create system properties - sysProps = new ResourceProperties(); - if (config.hasPropFile()) { - sysProps.addResource(new FileResource(config.getPropFile())); - } - } - - - /** - * Static main entry point. - * @param args the command line arguments - */ - public static void main(String[] args) throws IOException { - loadServer(args); - // parse properties files etc - server.init(); - // start the server main thread - server.start(); - } - - /** - * Entry point used by launcher.jar to load a server instance - * @param args the command line arguments - * @return the server instance - */ - public static Server loadServer(String[] args) { - checkJavaVersion(); - - ServerConfig config = null; - try { - config = getConfig(args); - } catch (Exception cex) { - printUsageError("error reading configuration: " + cex.getMessage()); - System.exit(1); - } - - checkRunning(config); - - // create new server instance - server = new Server(config); - return server; - } - - - /** - * check if we are running on a Java 2 VM - otherwise exit with an error message - */ - public static void checkJavaVersion() { - String javaVersion = System.getProperty("java.version", "0"); - int majorVersion = Integer.parseInt(javaVersion.split("\\.")[0]); - - if (majorVersion < 17) { - System.err.println("This version of Helma requires Java 17 or greater."); - - if (majorVersion == 0) { // don't think this will ever happen, but you never know - System.err.println("Your Java Runtime did not provide a version number. Please update to a more recent version."); - } else { - System.err.println("Your Java Runtime is version " + javaVersion + - ". Please update to a more recent version."); - } - - System.exit(1); - } - } - - - /** - * parse the command line arguments, read a given server.properties file - * and check the values given for server ports - * @return ServerConfig if successfull - * @throws Exception on any configuration error - */ - public static ServerConfig getConfig(String[] args) throws Exception { - - ServerConfig config = new ServerConfig(); - - // get possible environment setting for helma home - if (System.getProperty("helma.home")!=null) { - config.setHomeDir(new File(System.getProperty("helma.home"))); - } - - parseArgs(config, args); - - guessConfig(config); - - // create system properties - ResourceProperties sysProps = new ResourceProperties(); - sysProps.addResource(new FileResource(config.getPropFile())); - - // check if there's a property setting for those ports not specified via command line - if (!config.hasWebsrvPort() && sysProps.getProperty("webPort") != null) { - try { - config.setWebsrvPort(getInetSocketAddress(sysProps.getProperty("webPort"))); - } catch (Exception portx) { - throw new Exception("Error parsing web server port property from server.properties: " + portx); - } - } - - if (!config.hasXmlrpcPort() && sysProps.getProperty("xmlrpcPort") != null) { - try { - config.setXmlrpcPort(getInetSocketAddress(sysProps.getProperty("xmlrpcPort"))); - } catch (Exception portx) { - throw new Exception("Error parsing XML-RPC server port property from server.properties: " + portx); - } - } - return config; - } - - - /** - * parse argument list from command line and store values - * in given ServerConfig object - * @throws Exception when argument can't be parsed into an InetAddrPort - * or invalid token is given. - */ - public static void parseArgs(ServerConfig config, String[] args) throws Exception { - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-h") && ((i + 1) < args.length)) { - config.setHomeDir(new File(args[++i])); - } else if (args[i].equals("-f") && ((i + 1) < args.length)) { - config.setPropFile(new File(args[++i])); - } else if (args[i].equals("-a") && ((i + 1) < args.length)) { - config.setApps(StringUtils.split(args[++i])); - } else if (args[i].equals("-x") && ((i + 1) < args.length)) { - try { - config.setXmlrpcPort(getInetSocketAddress(args[++i])); - } catch (Exception portx) { - throw new Exception("Error parsing XML-RPC server port property: " + portx); - } - } else if (args[i].equals("-w") && ((i + 1) < args.length)) { - try { - config.setWebsrvPort(getInetSocketAddress(args[++i])); - } catch (Exception portx) { - throw new Exception("Error parsing web server port property: " + portx); - } - } else if (args[i].equals("-c") && ((i + 1) < args.length)) { - config.setConfigFile(new File(args[++i])); - } else if (args[i].equals("-i") && ((i + 1) < args.length)) { - // eat away the -i parameter which is meant for helma.main.launcher.Main - i++; - } else { - throw new Exception("Unknown command line token: " + args[i]); - } - } - } - - - /** - * get main property file from home dir or vice versa, - * depending on what we have - */ - public static void guessConfig(ServerConfig config) throws Exception { - // get property file from hopHome: - if (!config.hasPropFile()) { - if (config.hasHomeDir()) { - config.setPropFile(new File(config.getHomeDir(), "server.properties")); - } else { - config.setPropFile(new File("server.properties")); - } - } - - // create system properties - ResourceProperties sysProps = new ResourceProperties(); - sysProps.addResource(new FileResource(config.getPropFile())); - - // try to get hopHome from property file - if (!config.hasHomeDir() && sysProps.getProperty("hophome") != null) { - config.setHomeDir(new File(sysProps.getProperty("hophome"))); - } - - // use the directory where server.properties is located: - if (!config.hasHomeDir() && config.hasPropFile()) { - config.setHomeDir(config.getPropFile().getAbsoluteFile().getParentFile()); - } - - if (!config.hasPropFile()) { - throw new Exception ("no server.properties found"); - } - - if (!config.hasHomeDir()) { - throw new Exception ("couldn't determine helma directory"); - } - } - - - /** - * print the usage hints and prefix them with a message. - */ - public static void printUsageError(String msg) { - System.out.println(msg); - printUsageError(); - } - - - /** - * print the usage hints - */ - public static void printUsageError() { - System.out.println(""); - System.out.println("Usage: java helma.main.Server [options]"); - System.out.println("Possible options:"); - System.out.println(" -a app[,...] Specify applications to start"); - System.out.println(" -h dir Specify hop home directory"); - System.out.println(" -f file Specify server.properties file"); - System.out.println(" -c jetty.xml Specify Jetty XML configuration file"); - System.out.println(" -w [ip:]port Specify embedded web server address/port"); - System.out.println(" -x [ip:]port Specify XML-RPC address/port"); - System.out.println(""); - System.out.println("Supported formats for server ports:"); - System.out.println(" "); - System.out.println(" :"); - System.out.println(" :"); - System.out.println(""); - System.err.println("Usage Error - exiting"); - System.out.println(""); - } - - - - /** - * Check wheter a server is already running on any of the given ports - * - otherwise exit with an error message - */ - public static void checkRunning(ServerConfig config) { - // check if any of the specified server ports is in use already - try { - if (config.hasWebsrvPort()) { - checkPort(config.getWebsrvPort()); - } - - if (config.hasXmlrpcPort()) { - checkPort(config.getXmlrpcPort()); - } - - } catch (Exception running) { - System.out.println(running.getMessage()); - System.exit(1); - } - - } - - - /** - * Check whether a server port is available by trying to open a server socket - */ - private static void checkPort(InetSocketAddress endpoint) throws IOException { - try { - ServerSocket sock = new ServerSocket(); - sock.bind(endpoint); - sock.close(); - } catch (IOException x) { - throw new IOException("Error binding to " + endpoint + ": " + x.getMessage()); - } - } - - - /** - * initialize the server - */ - public void init() throws IOException { - - // set the log factory property - String logFactory = sysProps.getProperty("loggerFactory", - "helma.util.Logging"); - - helmaLogging = "helma.util.Logging".equals(logFactory); - System.setProperty("org.apache.commons.logging.LogFactory", logFactory); - - // set the current working directory to the helma home dir. - // note that this is not a real cwd, which is not supported - // by java. It makes sure relative to absolute path name - // conversion is done right, so for Helma code, this should work. - System.setProperty("user.dir", hopHome.getPath()); - - // from now on it's safe to call getLogger() because hopHome is set up - getLogger(); - - String startMessage = "Starting Helma " + version + " on Java " + - System.getProperty("java.version"); - - logger.info(startMessage); - - // also print a msg to System.out - System.out.println(startMessage); - - logger.info("Setting Helma Home to " + hopHome); - - - // read db.properties file in helma home directory - String dbPropfile = sysProps.getProperty("dbPropFile"); - File file; - if ((dbPropfile != null) && !"".equals(dbPropfile.trim())) { - file = new File(dbPropfile); - } else { - file = new File(hopHome, "db.properties"); - } - - dbProps = new ResourceProperties(); - dbProps.setIgnoreCase(false); - dbProps.addResource(new FileResource(file)); - DbSource.setDefaultProps(dbProps); - - // read apps.properties file - String appsPropfile = sysProps.getProperty("appsPropFile"); - if ((appsPropfile != null) && !"".equals(appsPropfile.trim())) { - file = new File(appsPropfile); - } else { - file = new File(hopHome, "apps.properties"); - } - appsProps = new ResourceProperties(); - appsProps.setIgnoreCase(true); - appsProps.addResource(new FileResource(file)); - - paranoid = "true".equalsIgnoreCase(sysProps.getProperty("paranoid")); - - String language = sysProps.getProperty("language"); - String country = sysProps.getProperty("country"); - String timezone = sysProps.getProperty("timezone"); - - if ((language != null) && (country != null)) { - Locale.setDefault(new Locale(language, country)); - } - - if (timezone != null) { - TimeZone.setDefault(TimeZone.getTimeZone(timezone)); - } - - // logger.debug("Locale = " + Locale.getDefault()); - // logger.debug("TimeZone = " + - // TimeZone.getDefault().getDisplayName(Locale.getDefault())); - - dbSources = new Hashtable(); - - // try to load the extensions - extensions = new Vector(); - if (sysProps.getProperty("extensions") != null) { - initExtensions(); - } - jetty = JettyServer.init(this, config); - } - - - /** - * initialize extensions - */ - private void initExtensions() { - StringTokenizer tok = new StringTokenizer(sysProps.getProperty("extensions"), ","); - while (tok.hasMoreTokens()) { - String extClassName = tok.nextToken().trim(); - - try { - Class extClass = Class.forName(extClassName); - HelmaExtension ext = (HelmaExtension) extClass.newInstance(); - ext.init(this); - extensions.add(ext); - logger.info("Loaded: " + extClassName); - } catch (Throwable e) { - logger.error("Error loading extension " + extClassName + ": " + e.toString()); - } - } - } - - - - public void start() { - // Start running, finishing setup and then entering a loop to check changes - // in the apps.properties file. - mainThread = new Thread(this); - mainThread.start(); - } - - public void stop() { - mainThread = null; - appManager.stopAll(); - } - - public void shutdown() { - getLogger().info("Shutting down Helma"); - - if (jetty != null) { - try { - jetty.stop(); - jetty.destroy(); - } catch (Exception x) { - // exception in jettx stop. ignore. - } - } - - if (xmlrpc != null) { - try { - xmlrpc.shutdown(); - } catch (Exception x) { - // exception in xmlrpc server shutdown, ignore. - } - } - - if (helmaLogging) { - Logging.shutdown(); - } - - server = null; - - try { - Runtime.getRuntime().removeShutdownHook(shutdownhook); - // HACK: running the shutdownhook seems to be necessary in order - // to prevent it from blocking garbage collection of helma - // classes/classloaders. Since we already set server to null it - // won't do anything anyhow. - shutdownhook.start(); - shutdownhook = null; - } catch (Exception x) { - // invalid shutdown hook or already shutting down. ignore. - } - } - - /** - * The main method of the Server. Basically, we set up Applications and than - * periodically check for changes in the apps.properties file, shutting down - * apps or starting new ones. - */ - public void run() { - try { - if (config.hasXmlrpcPort()) { - InetSocketAddress xmlrpcPort = config.getXmlrpcPort(); - String xmlparser = sysProps.getProperty("xmlparser"); - - if (xmlparser != null) { - XmlRpc.setDriver(xmlparser); - } - - if (xmlrpcPort.getAddress() != null) { - xmlrpc = new WebServer(xmlrpcPort.getPort(), xmlrpcPort.getAddress()); - } else { - xmlrpc = new WebServer(xmlrpcPort.getPort()); - } - - if (paranoid) { - xmlrpc.setParanoid(true); - - String xallow = sysProps.getProperty("allowXmlRpc"); - - if (xallow != null) { - StringTokenizer st = new StringTokenizer(xallow, " ,;"); - - while (st.hasMoreTokens()) - xmlrpc.acceptClient(st.nextToken()); - } - } - xmlrpc.start(); - logger.info("Starting XML-RPC server on port " + (xmlrpcPort)); - } - - appManager = new ApplicationManager(appsProps, this); - - if (xmlrpc != null) { - xmlrpc.addHandler("$default", appManager); - } - - // add shutdown hook to close running apps and servers on exit - shutdownhook = new HelmaShutdownHook(); - Runtime.getRuntime().addShutdownHook(shutdownhook); - } catch (Exception x) { - throw new RuntimeException("Error setting up Server", x); - } - - // set the security manager. - // the default implementation is helma.main.HelmaSecurityManager. - try { - String secManClass = sysProps.getProperty("securityManager"); - - if (secManClass != null) { - SecurityManager secMan = (SecurityManager) Class.forName(secManClass) - .newInstance(); - - System.setSecurityManager(secMan); - logger.info("Setting security manager to " + secManClass); - } - } catch (Exception x) { - logger.error("Error setting security manager", x); - } - - // start applications - appManager.startAll(); - - // start embedded web server - if (jetty != null) { - try { - jetty.start(); - } catch (Exception m) { - throw new RuntimeException("Error starting embedded web server", m); - } - } - - while (Thread.currentThread() == mainThread) { - try { - Thread.sleep(3000L); - } catch (InterruptedException ie) { - } - - try { - appManager.checkForChanges(); - } catch (Exception x) { - logger.warn("Caught in app manager loop: " + x); - } - } - } - - /** - * Make sure this server has an ApplicationManager (e.g. used when - * accessed from CommandlineRunner) - */ - public void checkAppManager() { - if (appManager == null) { - appManager = new ApplicationManager(appsProps, this); - } - } - - /** - * Get an Iterator over the applications currently running on this Server. - */ - public Object[] getApplications() { - return appManager.getApplications(); - } - - /** - * Get an Application by name - */ - public Application getApplication(String name) { - return appManager.getApplication(name); - } - - /** - * Get a logger to use for output in this server. - */ - public Log getLogger() { - if (logger == null) { - if (helmaLogging) { - // set up system properties for helma.util.Logging - String logDir = sysProps.getProperty("logdir", "log"); - - if (!"console".equals(logDir)) { - // try to get the absolute logdir path - - // set up helma.logdir system property - File dir = new File(logDir); - if (!dir.isAbsolute()) { - dir = new File(hopHome, logDir); - } - - logDir = dir.getAbsolutePath(); - } - System.setProperty("helma.logdir", logDir); - } - logger = LogFactory.getLog("helma.server"); - } - - return logger; - } - - /** - * Get the Home directory of this server. - */ - public File getHopHome() { - return hopHome; - } - - /** - * Get the explicit list of apps if started with -a option - * @return - */ - public String[] getApplicationsOption() { - return config.getApps(); - } - - /** - * Get the main Server instance. - */ - public static Server getServer() { - return server; - } - - /** - * Get the Server's XML-RPC web server. - */ - public static WebServer getXmlRpcServer() { - return server.xmlrpc; - } - - /** - * - * - * @param key ... - * - * @return ... - */ - public String getProperty(String key) { - return (String) sysProps.get(key); - } - - /** - * Return the server.properties for this server - * @return the server.properties - */ - public ResourceProperties getProperties() { - return sysProps; - } - - /** - * Return the server-wide db.properties - * @return the server-wide db.properties - */ - public ResourceProperties getDbProperties() { - return dbProps; - } - - /** - * Return the apps.properties entries for a given application - * @param appName the app name - * @return the apps.properties subproperties for the given app - */ - public ResourceProperties getAppsProperties(String appName) { - if (appName == null) { - return appsProps; - } else { - return appsProps.getSubProperties(appName + "."); - } - } - - /** - * - * - * @return ... - */ - public File getAppsHome() { - String appHome = sysProps.getProperty("appHome", ""); - - if (appHome.trim().length() != 0) { - return new File(appHome); - } else { - return new File(hopHome, "apps"); - } - } - - /** - * - * - * @return ... - */ - public File getDbHome() { - String dbHome = sysProps.getProperty("dbHome", ""); - - if (dbHome.trim().length() != 0) { - return new File(dbHome); - } else { - return new File(hopHome, "db"); - } - } - - /** - * - * - * @return ... - */ - public Vector getExtensions() { - return extensions; - } - - /** - * - * - * @param name ... - */ - public void startApplication(String name) { - appManager.start(name); - appManager.register(name); - } - - /** - * - * - * @param name ... - */ - public void stopApplication(String name) { - appManager.stop(name); - } - - private static InetSocketAddress getInetSocketAddress(String inetAddrPort) - throws UnknownHostException { - InetAddress addr = null; - int c = inetAddrPort.indexOf(':'); - if (c >= 0) { - String a = inetAddrPort.substring(0, c); - if (a.indexOf('/') > 0) - a = a.substring(a.indexOf('/') + 1); - inetAddrPort = inetAddrPort.substring(c + 1); - - if (a.length() > 0 && !"0.0.0.0".equals(a)) { - addr = InetAddress.getByName(a); - } - } - int port = Integer.parseInt(inetAddrPort); - return new InetSocketAddress(addr, port); - } -} - - diff --git a/src/main/java/helma/main/ServerConfig.java b/src/main/java/helma/main/ServerConfig.java deleted file mode 100644 index 125601c2..00000000 --- a/src/main/java/helma/main/ServerConfig.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.main; - -import java.io.File; -import java.net.InetSocketAddress; - -/** - * Utility class for server config - */ - -public class ServerConfig { - - private InetSocketAddress xmlrpcPort = null; - private InetSocketAddress websrvPort = null; - private File propFile = null; - private File homeDir = null; - private File configFile = null; - private String[] apps = null; - - public boolean hasPropFile() { - return (propFile != null); - } - - public boolean hasConfigFile() { - return (configFile != null); - } - - public boolean hasHomeDir() { - return (homeDir != null); - } - - public boolean hasXmlrpcPort() { - return (xmlrpcPort != null); - } - - public boolean hasWebsrvPort() { - return (websrvPort != null); - } - - public boolean hasApps() { - return (apps != null); - } - - public InetSocketAddress getXmlrpcPort() { - return xmlrpcPort; - } - - public void setXmlrpcPort(InetSocketAddress xmlrpcPort) { - this.xmlrpcPort = xmlrpcPort; - } - - public InetSocketAddress getWebsrvPort() { - return websrvPort; - } - - public void setWebsrvPort(InetSocketAddress websrvPort) { - this.websrvPort = websrvPort; - } - - public File getPropFile() { - return propFile; - } - - public void setPropFile(File propFile) { - this.propFile = propFile == null ? null : propFile.getAbsoluteFile(); - } - - public File getHomeDir() { - return homeDir; - } - - public void setHomeDir(File homeDir) { - this.homeDir = homeDir == null ? null : homeDir.getAbsoluteFile(); - } - - public File getConfigFile() { - return configFile; - } - - public void setConfigFile(File configFile) { - this.configFile = configFile == null ? null : configFile.getAbsoluteFile(); - } - - public String[] getApps() { - return apps; - } - - public void setApps(String[] apps) { - this.apps = apps; - } -} diff --git a/src/main/java/helma/objectmodel/ConcurrencyException.java b/src/main/java/helma/objectmodel/ConcurrencyException.java deleted file mode 100644 index 0c059e9f..00000000 --- a/src/main/java/helma/objectmodel/ConcurrencyException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - - -/** - * Thrown when more than one thrad tries to modify a Node. The evaluator - * will normally catch this and try again after a period of time. - */ -public class ConcurrencyException extends Error { - private static final long serialVersionUID = 4031542073544406467L; - - /** - * Creates a new ConcurrencyException object. - * - * @param msg ... - */ - public ConcurrencyException(String msg) { - super(msg); - } -} diff --git a/src/main/java/helma/objectmodel/DatabaseException.java b/src/main/java/helma/objectmodel/DatabaseException.java deleted file mode 100644 index 4576013f..00000000 --- a/src/main/java/helma/objectmodel/DatabaseException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - - -/** - * Thrown on any kind of Database-Error - */ -public class DatabaseException extends RuntimeException { - private static final long serialVersionUID = -5715728591015640819L; - - /** - * Creates a new DatabaseException object. - * - * @param msg ... - */ - public DatabaseException(String msg) { - super(msg); - } -} diff --git a/src/main/java/helma/objectmodel/IDatabase.java b/src/main/java/helma/objectmodel/IDatabase.java deleted file mode 100644 index c09be3f0..00000000 --- a/src/main/java/helma/objectmodel/IDatabase.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - -import helma.framework.core.Application; - -import java.io.IOException; -import java.io.File; - -/** - * Interface that is implemented by Database wrappers - */ -public interface IDatabase { - - /** - * Initialize the database with the given db directory and application. - * - * @param dbHome - * @param app - */ - public void init(File dbHome, Application app); - - /** - * Let the database know we're shutting down. - */ - public void shutdown(); - - /** - * Get the next ID from the db's ID generator - * @return a unique id - * @throws ObjectNotFoundException - */ - public String nextID() throws ObjectNotFoundException; - - - /** - * Get the node from the database specified by the given key. - * - * @param transaction - * @param key - * @return - * @throws IOException - * @throws ObjectNotFoundException if no object exists for the key. - */ - public INode getNode(ITransaction transaction, String key) - throws IOException, ObjectNotFoundException; - - /** - * Insert a node with the given key - * - * @param transaction - * @param key - * @param node - * @throws IOException - */ - public void insertNode(ITransaction transaction, String key, INode node) - throws IOException; - - /** - * Update a node with the given key - * - * @param transaction - * @param key - * @param node - * @throws IOException - */ - public void updateNode(ITransaction transaction, String key, INode node) - throws IOException; - - /** - * Delete the node specified by the given key. - * - * @param transaction ... - * @param key ... - * @throws IOException ... - */ - public void deleteNode(ITransaction transaction, String key) - throws IOException; - - /** - * Begin a new transaction. - * - * @return the transaction - */ - public ITransaction beginTransaction(); - - /** - * Commit a transaction, making all changes persistent - * - * @param transaction - * @throws DatabaseException - */ - public void commitTransaction(ITransaction transaction) - throws DatabaseException; - - /** - * Abort a transaction, rolling back all changes. - * - * @param transaction - * @throws DatabaseException - */ - public void abortTransaction(ITransaction transaction) - throws DatabaseException; -} diff --git a/src/main/java/helma/objectmodel/INode.java b/src/main/java/helma/objectmodel/INode.java deleted file mode 100644 index c5ab4fe5..00000000 --- a/src/main/java/helma/objectmodel/INode.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - -import helma.framework.IPathElement; -import helma.objectmodel.db.DbMapping; -import java.util.*; - -/** - * Interface that all Nodes implement. Currently, there are two implementations: - * Transient nodes which only exist in memory, and persistent Nodes, which are - * stored in a database (either the internal Object DB or an external relational DB). - */ -public interface INode extends INodeState, IPathElement { - /** - * Get the node's ID. - */ - public String getID(); - - /** - * Get the node's name. - */ - public String getName(); - - /** - * Set the node's {@link DbMapping}. - */ - public void setDbMapping(DbMapping dbmap); - - /** - * Get the node's {@link DbMapping}. - */ - public DbMapping getDbMapping(); - - /** - * Get the node's state flag. - * @return one of the constants defined in the {@link INodeState} interface. - */ - public int getState(); - - /** - * Set the node's state flag. - * @param s one of the constants defined in the {@link INodeState} interface. - */ - public void setState(int s); - - /** - * Set the node's name. - */ - public void setName(String name); - - /** - * Get the node's last modification timestamp. - */ - public long lastModified(); - - /** - * Get the node's creation timestamp. - */ - public long created(); - - /** - * Returns true if this node is an unnamed node. - */ - public boolean isAnonymous(); - - /** - * Return the node's prototype name. - */ - public String getPrototype(); - - /** - * Set the node's prototype name. - */ - public void setPrototype(String prototype); - - /** - * Get the cache node associated with this node. - */ - public INode getCacheNode(); - - /** - * Clear the cache node associated with this node. - */ - public void clearCacheNode(); - - /** - * Get the node's path. - */ - public String getPath(); - - /** - * Get the node's parent node. - */ - public INode getParent(); - - /** - * Set an explicit select clause for the node's subnodes - */ - public void setSubnodeRelation(String clause); - - /** - * Get the node's explicit subnode select clause if one was set, or null - */ - public String getSubnodeRelation(); - - /** - * Get the number the node's direct child nodes. - */ - public int numberOfNodes(); - - /** - * Add a child node to this node. - */ - public INode addNode(INode node); - - /** - * Add a child node to this node at the given position - */ - public INode addNode(INode node, int where); - - /** - * Create a new named property with a node value - */ - public INode createNode(String name); - - /** - * Create a new unnamed child node at the given position. - */ - public INode createNode(String name, int where); - - /** - * Get an enumeration of this node's unnamed child nodes - */ - public Enumeration getSubnodes(); - - /** - * Get a named child node with the given name or id. - */ - public INode getSubnode(String name); - - /** - * GEt an unnamed child node at the given position - */ - public INode getSubnodeAt(int index); - - /** - * Returns the position of the child or -1. - */ - public int contains(INode node); - - /** - * Remove this node from the database. - */ - public boolean remove(); - - /** - * Remove the given node from this node's child nodes. - */ - public void removeNode(INode node); - - /** - * Get an enumeration over the node's properties. - */ - public Enumeration properties(); - - /** - * Get a property with the given name. - */ - public IProperty get(String name); - - /** - * Get a string property with the given name. - */ - public String getString(String name); - - /** - * Get a boolean property with the given name. - */ - public boolean getBoolean(String name); - - /** - * Get a date property with the given name. - */ - public Date getDate(String name); - - /** - * Get an integer property with the given name. - */ - public long getInteger(String name); - - /** - * Get a float property with the given name. - */ - public double getFloat(String name); - - /** - * Get a node property with the given name. - */ - public INode getNode(String name); - - /** - * Get a Java object property with the given name. - */ - public Object getJavaObject(String name); - - /** - * Set the property with the given name to the given string value. - */ - public void setString(String name, String value); - - /** - * Set the property with the given name to the given boolean value. - */ - public void setBoolean(String name, boolean value); - - /** - * Set the property with the given name to the given date value. - */ - public void setDate(String name, Date value); - - /** - * Set the property with the given name to the given integer value. - */ - public void setInteger(String name, long value); - - /** - * Set the property with the given name to the given float value. - */ - public void setFloat(String name, double value); - - /** - * Set the property with the given name to the given node value. - */ - public void setNode(String name, INode value); - - /** - * Set the property with the given name to the given Java object value. - */ - public void setJavaObject(String name, Object value); - - /** - * Unset the property with the given name.. - */ - public void unset(String name); -} diff --git a/src/main/java/helma/objectmodel/INodeState.java b/src/main/java/helma/objectmodel/INodeState.java deleted file mode 100644 index 6d509b70..00000000 --- a/src/main/java/helma/objectmodel/INodeState.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - -/** - * Interface that defines states of nodes - */ -public interface INodeState { - public final static int TRANSIENT = -3; - public final static int VIRTUAL = -2; - public final static int INVALID = -1; - public final static int CLEAN = 0; - public final static int NEW = 1; - public final static int MODIFIED = 2; - public final static int DELETED = 3; -} diff --git a/src/main/java/helma/objectmodel/IProperty.java b/src/main/java/helma/objectmodel/IProperty.java deleted file mode 100644 index 95198079..00000000 --- a/src/main/java/helma/objectmodel/IProperty.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - -import java.util.Date; - -/** - * Interface that is implemented by node properties. - */ -public interface IProperty { - public static final int STRING = 1; - public static final int BOOLEAN = 2; - public static final int DATE = 3; - public static final int INTEGER = 4; - public static final int FLOAT = 5; - public static final int NODE = 6; - public static final int JAVAOBJECT = 7; - - /** - * - * - * @return ... - */ - public String getName(); - - /** - * - * - * @return ... - */ - public int getType(); - - /** - * - * - * @return ... - */ - public Object getValue(); - - /** - * - * - * @return ... - */ - public INode getNodeValue(); - - /** - * - * - * @return ... - */ - public String getStringValue(); - - /** - * - * - * @return ... - */ - public boolean getBooleanValue(); - - /** - * - * - * @return ... - */ - public long getIntegerValue(); - - /** - * - * - * @return ... - */ - public double getFloatValue(); - - /** - * - * - * @return ... - */ - public Date getDateValue(); - - /** - * - * - * @return ... - */ - public Object getJavaObjectValue(); -} diff --git a/src/main/java/helma/objectmodel/ITransaction.java b/src/main/java/helma/objectmodel/ITransaction.java deleted file mode 100644 index 360571f1..00000000 --- a/src/main/java/helma/objectmodel/ITransaction.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - - -/** - * This interface is kept for databases that are able - * to run transactions. - */ -public interface ITransaction { - - public final int ADDED = 0; - public final int UPDATED = 1; - public final int DELETED = 2; - - /** - * Complete the transaction by making its changes persistent. - */ - public void commit() throws DatabaseException; - - /** - * Rollback the transaction, forgetting the changed items - */ - public void abort() throws DatabaseException; - - /** - * Adds a resource to the list of resources encompassed by this transaction - * - * @param res the resource to add - * @param status the status of the resource (ADDED|UPDATED|DELETED) - */ - public void addResource(Object res, int status) throws DatabaseException; -} diff --git a/src/main/java/helma/objectmodel/NodeEvent.java b/src/main/java/helma/objectmodel/NodeEvent.java deleted file mode 100644 index b0928ae1..00000000 --- a/src/main/java/helma/objectmodel/NodeEvent.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - -import java.io.*; - -/** - * This is passed to NodeListeners when a node is modified. - */ -public class NodeEvent implements Serializable { - private static final long serialVersionUID = 4322426080131107600L; - - public static final int CONTENT_CHANGED = 0; - public static final int PROPERTIES_CHANGED = 1; - public static final int NODE_REMOVED = 2; - public static final int NODE_RENAMED = 3; - public static final int SUBNODE_ADDED = 4; - public static final int SUBNODE_REMOVED = 5; - public int type; - public String id; - public transient INode node; - public transient Object arg; - - /** - * Creates a new NodeEvent object. - * - * @param node ... - * @param type ... - */ - public NodeEvent(INode node, int type) { - super(); - this.node = node; - this.id = node.getID(); - this.type = type; - } - - /** - * Creates a new NodeEvent object. - * - * @param node ... - * @param type ... - * @param arg ... - */ - public NodeEvent(INode node, int type, Object arg) { - super(); - this.node = node; - this.id = node.getID(); - this.type = type; - this.arg = arg; - } - - /** - * - * - * @return ... - */ - public String toString() { - switch (type) { - case CONTENT_CHANGED: - return "NodeEvent: content changed"; - - case PROPERTIES_CHANGED: - return "NodeEvent: properties changed"; - - case NODE_REMOVED: - return "NodeEvent: node removed"; - - case NODE_RENAMED: - return "NodeEvent: node moved"; - - case SUBNODE_ADDED: - return "NodeEvent: subnode added"; - - case SUBNODE_REMOVED: - return "NodeEvent: subnode removed"; - } - - return "NodeEvent: invalid type"; - } -} diff --git a/src/main/java/helma/objectmodel/ObjectCache.java b/src/main/java/helma/objectmodel/ObjectCache.java deleted file mode 100644 index 402cd79f..00000000 --- a/src/main/java/helma/objectmodel/ObjectCache.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - -import helma.framework.core.Application; - -import java.util.Properties; - -/** - * Interface Helma object cache classes need to implement. - * - */ -public interface ObjectCache { - - /** - * Set the {@link helma.framework.core.Application Application} instance - * for the cache. - * @param app the app instance - */ - void init(Application app); - - /** - * Called when the application holding the cache is stopped. - */ - void shutdown(); - - /** - * Called when the application's properties have been updated to let - * the cache implementation update its settings. - * @param props - */ - void updateProperties(Properties props); - - /** - * Returns true if the collection contains an element for the key. - * - * @param key the key that we are looking for - */ - boolean containsKey(Object key); - - /** - * Returns the number of keys in object array keys that - * were not found in the Map. - * Those keys that are contained in the Map are nulled out in the array. - * @param keys an array of key objects we are looking for - * @see ObjectCache#containsKey - */ - int containsKeys(Object[] keys); - - /** - * Gets the object associated with the specified key in the - * hashtable. - * @param key the specified key - * @return the element for the key or null if the key - * is not defined in the hash table. - * @see ObjectCache#put - */ - Object get(Object key); - - /** - * Puts the specified element into the hashtable, using the specified - * key. The element may be retrieved by doing a get() with the same key. - * The key and the element cannot be null. - * @param key the specified key in the hashtable - * @param value the specified element - * @exception NullPointerException If the value of the element - * is equal to null. - * @see ObjectCache#get - * @return the old value of the key, or null if it did not have one. - */ - Object put(Object key, Object value); - - /** - * Removes the element corresponding to the key. Does nothing if the - * key is not present. - * @param key the key that needs to be removed - * @return the value of key, or null if the key was not found. - */ - Object remove(Object key); - - /** - * Removes all items currently stored in the cache. - * - * @return true if the operation succeeded - */ - boolean clear(); - - /** - * Return the number of objects currently stored in the cache. - * @return the number of cached items - */ - int size(); - - /** - * Return an array with all objects currently contained in the cache. - */ - Object[] getCachedObjects(); - - /** - * Returns a map of statistics about the cache - */ - java.util.Map getStatistics(); -} diff --git a/src/main/java/helma/objectmodel/ObjectNotFoundException.java b/src/main/java/helma/objectmodel/ObjectNotFoundException.java deleted file mode 100644 index 7405b347..00000000 --- a/src/main/java/helma/objectmodel/ObjectNotFoundException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - - -/** - * Thrown when an object could not found in the database where - * it was expected. - */ -public class ObjectNotFoundException extends Exception { - private static final long serialVersionUID = -5368941052804232094L; - - /** - * Creates a new ObjectNotFoundException object. - * - * @param msg ... - */ - public ObjectNotFoundException(String msg) { - super(msg); - } -} diff --git a/src/main/java/helma/objectmodel/TransientNode.java b/src/main/java/helma/objectmodel/TransientNode.java deleted file mode 100644 index e1410e17..00000000 --- a/src/main/java/helma/objectmodel/TransientNode.java +++ /dev/null @@ -1,608 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - -import helma.framework.IPathElement; -import helma.framework.core.Application; -import helma.framework.core.RequestEvaluator; -import helma.objectmodel.db.DbMapping; -import helma.objectmodel.db.Relation; -import helma.objectmodel.db.Node; -import helma.util.*; -import java.io.*; -import java.util.Date; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.StringTokenizer; -import java.util.Vector; - -/** - * A transient implementation of INode. An instance of this class can't be - * made persistent by reachability from a persistent node. To make a persistent-capable - * object, class helma.objectmodel.db.Node has to be used. - */ -public class TransientNode implements INode, Serializable { - private static final long serialVersionUID = -4599844796152072979L; - - private static long idgen = 0; - protected Hashtable propMap; - protected Hashtable nodeMap; - protected Vector nodes; - protected TransientNode parent; - transient String prototype; - protected long created; - protected long lastmodified; - protected String id; - protected String name; - private final Application app; - - // is the main identity a named property or an anonymous node in a collection? - protected boolean anonymous = false; - transient DbMapping dbmap; - INode cacheNode; - - /** - * Creates a new TransientNode object. - */ - public TransientNode(Application app) { - id = generateID(); - name = id; - created = lastmodified = System.currentTimeMillis(); - this.app=app; - } - - private TransientNode() { - app=null; - } - - /** - * Make a new TransientNode object with a given name - */ - public TransientNode(Application app, String n) { - id = generateID(); - name = (n == null || n.length() == 0) ? id : n; - // HACK - decrease creation and last-modified timestamp by 1 so we notice - // modifications that take place immediately after object creation - created = lastmodified = System.currentTimeMillis() - 1; - this.app = app; - } - - public static String generateID() { - // make transient ids differ from persistent ones - // and are unique within on runtime session - return "t" + idgen++; - } - - public void setDbMapping(DbMapping dbmap) { - this.dbmap = dbmap; - } - - public DbMapping getDbMapping() { - return dbmap; - } - - public String getID() { - return id; - } - - public boolean isAnonymous() { - return anonymous; - } - - public String getName() { - return name; - } - - public String getElementName() { - return anonymous ? id : name; - } - - public int getState() { - return TRANSIENT; - } - - public void setState(int s) { - // state always is TRANSIENT on this kind of node - } - - public String getPath() { - return getFullName(null); - } - - public String getFullName(INode root) { - String divider = null; - StringBuffer b = new StringBuffer(); - TransientNode p = this; - - while ((p != null) && (p.parent != null) && (p != root)) { - if (divider != null) { - b.insert(0, divider); - } else { - divider = "/"; - } - - b.insert(0, p.getElementName()); - p = p.parent; - } - - return b.toString(); - } - - public void setName(String name) { - // if (name.indexOf('/') > -1) - // throw new RuntimeException ("The name of the node must not contain \"/\"."); - if ((name == null) || (name.trim().length() == 0)) { - this.name = id; - } else { - this.name = name; - } - } - - public String getPrototype() { - // if prototype is null, it's a vanilla HopObject. - if (prototype == null) { - return "HopObject"; - } - - return prototype; - } - - public void setPrototype(String proto) { - this.prototype = proto; - } - - public INode getParent() { - return parent; - } - - public void setSubnodeRelation(String rel) { - throw new UnsupportedOperationException("Can't set subnode relation for non-persistent Node."); - } - - public String getSubnodeRelation() { - return null; - } - - public int numberOfNodes() { - return (nodes == null) ? 0 : nodes.size(); - } - - public INode addNode(INode elem) { - return addNode(elem, numberOfNodes()); - } - - public INode addNode(INode elem, int where) { - if ((where < 0) || (where > numberOfNodes())) { - where = numberOfNodes(); - } - - String n = elem.getName(); - - if (n.indexOf('/') > -1) { - throw new RuntimeException("The name of a node must not contain \"/\" (slash)."); - } - - if ((nodeMap != null) && (nodeMap.get(elem.getID()) != null)) { - nodes.removeElement(elem); - where = Math.min(where, numberOfNodes()); - nodes.insertElementAt(elem, where); - - return elem; - } - - if (nodeMap == null) { - nodeMap = new Hashtable(); - } - - if (nodes == null) { - nodes = new Vector(); - } - - nodeMap.put(elem.getID(), elem); - nodes.insertElementAt(elem, where); - - if (elem instanceof TransientNode) { - TransientNode node = (TransientNode) elem; - - if (node.parent == null) { - node.parent = this; - node.anonymous = true; - } - } - - lastmodified = System.currentTimeMillis(); - return elem; - } - - public INode createNode() { - return createNode(null, 0); // where is ignored since this is an anonymous node - } - - public INode createNode(int where) { - return createNode(null, where); - } - - public INode createNode(String nm) { - return createNode(nm, numberOfNodes()); // where is usually ignored (if nm != null) - } - - public INode createNode(String nm, int where) { - boolean anon = false; - - if ((nm == null) || "".equals(nm.trim())) { - anon = true; - } - - INode n = new TransientNode(app, nm); - - if (anon) { - addNode(n, where); - } else { - setNode(nm, n); - } - - return n; - } - - - public IPathElement getParentElement() { - return getParent(); - } - - public IPathElement getChildElement(String name) { - return getNode(name); - } - - public INode getSubnode(String name) { - StringTokenizer st = new StringTokenizer(name, "/"); - TransientNode retval = this; - TransientNode runner; - - while (st.hasMoreTokens() && (retval != null)) { - runner = retval; - - String next = st.nextToken().trim().toLowerCase(); - - if ("".equals(next)) { - retval = this; - } else { - retval = (runner.nodeMap == null) ? null - : (TransientNode) runner.nodeMap.get(next); - } - - if (retval == null) { - retval = (TransientNode) runner.getNode(next); - } - } - - return retval; - } - - public INode getSubnodeAt(int index) { - return (nodes == null) ? null : (INode) nodes.elementAt(index); - } - - public int contains(INode n) { - if ((n == null) || (nodes == null)) { - return -1; - } - - return nodes.indexOf(n); - } - - public boolean remove() { - if (anonymous) { - parent.unset(name); - } else { - parent.removeNode(this); - } - - return true; - } - - public void removeNode(INode node) { - // IServer.getLogger().log ("removing: "+ node); - releaseNode(node); - - TransientNode n = (TransientNode) node; - - if ((n.getParent() == this) && n.anonymous) { - - // remove all subnodes, giving them a chance to destroy themselves. - Vector v = new Vector(); // removeElement modifies the Vector we are enumerating, so we are extra careful. - - for (Enumeration e3 = n.getSubnodes(); e3.hasMoreElements();) { - v.addElement(e3.nextElement()); - } - - int m = v.size(); - - for (int i = 0; i < m; i++) { - n.removeNode((TransientNode) v.elementAt(i)); - } - } - } - - /** - * "Physically" remove a subnode from the subnodes table. - * the logical stuff necessary for keeping data consistent is done elsewhere (in removeNode). - */ - protected void releaseNode(INode node) { - if ((nodes == null) || (nodeMap == null)) { - - return; - } - - int runner = nodes.indexOf(node); - - // this is due to difference between .equals() and == - while ((runner > -1) && (nodes.elementAt(runner) != node)) - runner = nodes.indexOf(node, Math.min(nodes.size() - 1, runner + 1)); - - if (runner > -1) { - nodes.removeElementAt(runner); - } - - nodeMap.remove(node.getName().toLowerCase()); - lastmodified = System.currentTimeMillis(); - } - - /** - * - * - * @return ... - */ - public Enumeration getSubnodes() { - return (nodes == null) ? new Vector().elements() : nodes.elements(); - } - - /** - * property-related - */ - public Enumeration properties() { - return (propMap == null) ? new EmptyEnumeration() : propMap.keys(); - } - - private TransientProperty getProperty(String propname) { - TransientProperty prop = (propMap == null) ? null - : (TransientProperty) propMap.get(correctPropertyName(propname)); - - // check if we have to create a virtual node - if ((prop == null) && (dbmap != null)) { - Relation rel = dbmap.getPropertyRelation(propname); - - if ((rel != null) && rel.isVirtual()) { - prop = makeVirtualNode(propname, rel); - } - } - - return prop; - } - - private TransientProperty makeVirtualNode(String propname, Relation rel) { - INode node = new Node(rel.getPropName(), rel.getPrototype(), - dbmap.getWrappedNodeManager()); - - node.setDbMapping(rel.getVirtualMapping()); - setNode(propname, node); - - return (TransientProperty) propMap.get(correctPropertyName(propname)); - } - - public IProperty get(String propname) { - return getProperty(propname); - } - - public String getString(String propname, String defaultValue) { - String propValue = getString(propname); - - return (propValue == null) ? defaultValue : propValue; - } - - public String getString(String propname) { - TransientProperty prop = getProperty(propname); - - try { - return prop.getStringValue(); - } catch (Exception ignore) { - } - - return null; - } - - public long getInteger(String propname) { - TransientProperty prop = getProperty(propname); - - try { - return prop.getIntegerValue(); - } catch (Exception ignore) { - } - - return 0; - } - - public double getFloat(String propname) { - TransientProperty prop = getProperty(propname); - - try { - return prop.getFloatValue(); - } catch (Exception ignore) { - } - - return 0.0; - } - - public Date getDate(String propname) { - TransientProperty prop = getProperty(propname); - - try { - return prop.getDateValue(); - } catch (Exception ignore) { - } - - return null; - } - - public boolean getBoolean(String propname) { - TransientProperty prop = getProperty(propname); - - try { - return prop.getBooleanValue(); - } catch (Exception ignore) { - } - - return false; - } - - public INode getNode(String propname) { - TransientProperty prop = getProperty(propname); - - try { - return prop.getNodeValue(); - } catch (Exception ignore) { - } - - return null; - } - - public Object getJavaObject(String propname) { - TransientProperty prop = getProperty(propname); - - try { - return prop.getJavaObjectValue(); - } catch (Exception ignore) { - } - - return null; - } - - // create a property if it doesn't exist for this name - private TransientProperty initProperty(String propname) { - if (propMap == null) { - propMap = new Hashtable(); - } - - propname = propname.trim(); - String cpn = correctPropertyName(propname); - TransientProperty prop = (TransientProperty) propMap.get(cpn); - - if (prop == null) { - prop = new TransientProperty(propname, this); - propMap.put(cpn, prop); - } - - return prop; - } - - public void setString(String propname, String value) { - TransientProperty prop = initProperty(propname); - prop.setStringValue(value); - lastmodified = System.currentTimeMillis(); - } - - public void setInteger(String propname, long value) { - TransientProperty prop = initProperty(propname); - prop.setIntegerValue(value); - lastmodified = System.currentTimeMillis(); - } - - public void setFloat(String propname, double value) { - TransientProperty prop = initProperty(propname); - prop.setFloatValue(value); - lastmodified = System.currentTimeMillis(); - } - - public void setBoolean(String propname, boolean value) { - TransientProperty prop = initProperty(propname); - prop.setBooleanValue(value); - lastmodified = System.currentTimeMillis(); - } - - public void setDate(String propname, Date value) { - TransientProperty prop = initProperty(propname); - prop.setDateValue(value); - lastmodified = System.currentTimeMillis(); - } - - public void setJavaObject(String propname, Object value) { - TransientProperty prop = initProperty(propname); - prop.setJavaObjectValue(value); - lastmodified = System.currentTimeMillis(); - } - - public void setNode(String propname, INode value) { - TransientProperty prop = initProperty(propname); - prop.setNodeValue(value); - - // check if the main identity of this node is as a named property - // or as an anonymous node in a collection - if (value instanceof TransientNode) { - TransientNode n = (TransientNode) value; - - if (n.parent == null) { - n.name = propname; - n.parent = this; - n.anonymous = false; - } - } - - lastmodified = System.currentTimeMillis(); - } - - public void unset(String propname) { - if (propMap != null && propname != null) { - propMap.remove(correctPropertyName(propname)); - lastmodified = System.currentTimeMillis(); - } - } - - public long lastModified() { - return lastmodified; - } - - public long created() { - return created; - } - - public String toString() { - return "TransientNode " + name; - } - - /** - * Get the cache node for this node. This can - * be used to store transient cache data per node - * from Javascript. - */ - public synchronized INode getCacheNode() { - if (cacheNode == null) { - cacheNode = new TransientNode(app); - } - - return cacheNode; - } - - /** - * Reset the cache node for this node. - */ - public synchronized void clearCacheNode() { - cacheNode = null; - } - - private String correctPropertyName(String propname) { - return app.correctPropertyName(propname); - } -} diff --git a/src/main/java/helma/objectmodel/TransientProperty.java b/src/main/java/helma/objectmodel/TransientProperty.java deleted file mode 100644 index e3d1d6bf..00000000 --- a/src/main/java/helma/objectmodel/TransientProperty.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel; - -import java.io.*; -import java.text.*; -import java.util.Date; - -/** - * A property implementation for Nodes stored inside a database. - */ -public final class TransientProperty implements IProperty, Serializable { - private static final long serialVersionUID = 3128899239601365229L; - - protected String propname; - protected TransientNode node; - public String svalue; - public boolean bvalue; - public long lvalue; - public double dvalue; - public INode nvalue; - public Object jvalue; - public int type; - - /** - * Creates a new Property object. - * - * @param node ... - */ - public TransientProperty(TransientNode node) { - this.node = node; - } - - /** - * Creates a new Property object. - * - * @param propname ... - * @param node ... - */ - public TransientProperty(String propname, TransientNode node) { - this.propname = propname; - this.node = node; - } - - /** - * - * - * @return ... - */ - public String getName() { - return propname; - } - - /** - * - * - * @return ... - */ - public Object getValue() { - switch (type) { - case STRING: - return svalue; - - case BOOLEAN: - return Boolean.valueOf(bvalue); - - case INTEGER: - return Long.valueOf(lvalue); - - case FLOAT: - return Double.valueOf(dvalue); - - case DATE: - return new Date(lvalue); - - case NODE: - return nvalue; - - case JAVAOBJECT: - return jvalue; - } - - return null; - } - - /** - * - * - * @param value ... - */ - public void setStringValue(String value) { - if (type == NODE) { - this.nvalue = null; - } - - if (type == JAVAOBJECT) { - this.jvalue = null; - } - - type = STRING; - this.svalue = value; - } - - /** - * - * - * @param value ... - */ - public void setIntegerValue(long value) { - if (type == NODE) { - this.nvalue = null; - } - - if (type == JAVAOBJECT) { - this.jvalue = null; - } - - type = INTEGER; - this.lvalue = value; - } - - /** - * - * - * @param value ... - */ - public void setFloatValue(double value) { - if (type == NODE) { - this.nvalue = null; - } - - if (type == JAVAOBJECT) { - this.jvalue = null; - } - - type = FLOAT; - this.dvalue = value; - } - - /** - * - * - * @param value ... - */ - public void setDateValue(Date value) { - if (type == NODE) { - this.nvalue = null; - } - - if (type == JAVAOBJECT) { - this.jvalue = null; - } - - type = DATE; - this.lvalue = value.getTime(); - } - - /** - * - * - * @param value ... - */ - public void setBooleanValue(boolean value) { - if (type == NODE) { - this.nvalue = null; - } - - if (type == JAVAOBJECT) { - this.jvalue = null; - } - - type = BOOLEAN; - this.bvalue = value; - } - - /** - * - * - * @param value ... - */ - public void setNodeValue(INode value) { - if (type == JAVAOBJECT) { - this.jvalue = null; - } - - type = NODE; - this.nvalue = value; - } - - /** - * - * - * @param value ... - */ - public void setJavaObjectValue(Object value) { - if (type == NODE) { - this.nvalue = null; - } - - type = JAVAOBJECT; - this.jvalue = value; - } - - /** - * - * - * @return ... - */ - public String getStringValue() { - switch (type) { - case STRING: - return svalue; - - case BOOLEAN: - return "" + bvalue; - - case DATE: - - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - return format.format(new Date(lvalue)); - - case INTEGER: - return Long.toString(lvalue); - - case FLOAT: - return Double.toString(dvalue); - - case NODE: - return nvalue.getName(); - - case JAVAOBJECT: - return (jvalue == null) ? null : jvalue.toString(); - } - - return ""; - } - - /** - * - * - * @return ... - */ - public String toString() { - return getStringValue(); - } - - /** - * - * - * @return ... - */ - public long getIntegerValue() { - if (type == INTEGER) { - return lvalue; - } - - return 0; - } - - /** - * - * - * @return ... - */ - public double getFloatValue() { - if (type == FLOAT) { - return dvalue; - } - - return 0.0; - } - - /** - * - * - * @return ... - */ - public Date getDateValue() { - if (type == DATE) { - return new Date(lvalue); - } - - return null; - } - - /** - * - * - * @return ... - */ - public boolean getBooleanValue() { - if (type == BOOLEAN) { - return bvalue; - } - - return false; - } - - /** - * - * - * @return ... - */ - public INode getNodeValue() { - if (type == NODE) { - return nvalue; - } - - return null; - } - - /** - * - * - * @return ... - */ - public Object getJavaObjectValue() { - if (type == JAVAOBJECT) { - return jvalue; - } - - return null; - } - - /** - * - * - * @return ... - */ - public int getType() { - return type; - } -} diff --git a/src/main/java/helma/objectmodel/db/DbColumn.java b/src/main/java/helma/objectmodel/db/DbColumn.java deleted file mode 100644 index 75e3dbd8..00000000 --- a/src/main/java/helma/objectmodel/db/DbColumn.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import java.sql.Types; - -/** - * A class that encapsulates the Column name and data type of a column in a - * relational table. - */ -public final class DbColumn { - private final String name; - private final int type; - private final Relation relation; - - private final boolean isId; - private final boolean isPrototype; - private final boolean isName; - - /** - * Constructor - */ - public DbColumn(String name, int type, Relation rel, DbMapping dbmap) { - this.name = name; - this.type = type; - this.relation = rel; - - if (relation != null) { - relation.setColumnType(type); - } - - isId = name.equalsIgnoreCase(dbmap.getIDField()); - isPrototype = name.equalsIgnoreCase(dbmap.getPrototypeField()); - isName = name.equalsIgnoreCase(dbmap.getNameField()); - } - - /** - * Get the column name. - */ - public String getName() { - return name; - } - - /** - * Get this columns SQL data type. - */ - public int getType() { - return type; - } - - /** - * Return the relation associated with this column. May be null. - */ - public Relation getRelation() { - return relation; - } - - /** - * Returns true if this column serves as ID field for the prototype. - */ - public boolean isIdField() { - return isId; - } - - /** - * Returns true if this column serves as prototype field for the prototype. - */ - public boolean isPrototypeField() { - return isPrototype; - } - - /** - * Returns true if this column serves as name field for the prototype. - */ - public boolean isNameField() { - return isName; - } - - /** - * Returns true if this field is mapped by the prototype's db mapping. - */ - public boolean isMapped() { - // Note: not sure if check for primitive or reference relation is really - // needed, but we did it before, so we leave it in for safety. - return isId || isPrototype || isName || - (relation != null && relation.isPrimitiveOrReference()); - } - - /** - * Checks whether values for this column need to be quoted in insert/update - * stmts - * - * @return true if values need to be wrapped in quotes - */ - public boolean needsQuotes() { - switch (type) { - case Types.CHAR: - case Types.VARCHAR: - case Types.LONGVARCHAR: - case Types.BINARY: - case Types.VARBINARY: - case Types.LONGVARBINARY: - case Types.DATE: - case Types.TIME: - case Types.TIMESTAMP: - return true; - default: - return false; - } - } - -} diff --git a/src/main/java/helma/objectmodel/db/DbKey.java b/src/main/java/helma/objectmodel/db/DbKey.java deleted file mode 100644 index 3636b3d9..00000000 --- a/src/main/java/helma/objectmodel/db/DbKey.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - - -/** - * This is the internal representation of a database key. It is constructed - * from the logical table (type) name and the object's primary key - * within the table. Currently only single keys are supported. - */ -public final class DbKey implements Key, Serializable { - // the name of the prototype which defines the storage of this object. - // this is the name of the object's prototype, or one of its ancestors. - // If null, the object is stored in the embedded db. - private String storageName; - - // the id that defines this key's object within the above storage space - private String id; - - // lazily initialized hashcode - private transient int hashcode = 0; - - static final long serialVersionUID = 1618863960930966588L; - - /** - * make a key for a persistent Object, describing its datasource and id. - */ - public DbKey(DbMapping dbmap, String id) { - if (id == null) { - throw new IllegalArgumentException("id null in DbKey"); - } - this.id = id; - this.storageName = (dbmap == null) ? null : dbmap.getStorageTypeName(); - } - - /** - * - * - * @param what the other key to be compared with this one - * - * @return true if both keys are identical - */ - public boolean equals(Object what) { - if (what == this) { - return true; - } - - if (!(what instanceof DbKey)) { - return false; - } - - DbKey k = (DbKey) what; - - // storageName is an interned string (by DbMapping, from where we got it) - // so we can compare by using == instead of the equals method. - return (storageName == k.storageName) && ((id == k.id) || id.equals(k.id)); - } - - /** - * - * - * @return this key's hash code - */ - public int hashCode() { - if (hashcode == 0) { - hashcode = (storageName == null) ? (17 + (37 * id.hashCode())) - : (17 + (37 * storageName.hashCode()) + - (+37 * id.hashCode())); - } - - return hashcode; - } - - /** - * - * - * @return the key of this key's object's parent object - */ - public Key getParentKey() { - return null; - } - - /** - * - * - * @return the unique storage name for this key's object - */ - public String getStorageName() { - return storageName; - } - - /** - * - * - * @return this key's object's id - */ - public String getID() { - return id; - } - - /** - * - * - * @return a string representation for this key - */ - public String toString() { - return (storageName == null) ? ("[" + id + "]") : (storageName + "[" + id + "]"); - } - - // We implement write/readObject to set storageName - // to the interned version of the string. - - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.writeObject(storageName); - stream.writeObject(id); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - storageName = (String) stream.readObject(); - id = (String) stream.readObject(); - // if storageName is not null, set it to the interned version - if (storageName != null) { - storageName = storageName.intern(); - } - } - -} diff --git a/src/main/java/helma/objectmodel/db/DbMapping.java b/src/main/java/helma/objectmodel/db/DbMapping.java deleted file mode 100644 index 208ec954..00000000 --- a/src/main/java/helma/objectmodel/db/DbMapping.java +++ /dev/null @@ -1,1650 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.framework.core.Application; -import helma.framework.core.Prototype; -import helma.util.ResourceProperties; - -import java.sql.*; -import java.util.*; - -/** - * A DbMapping describes how a certain type of Nodes is to mapped to a - * relational database table. Basically it consists of a set of JavaScript property-to- - * Database row bindings which are represented by instances of the Relation class. - */ -public final class DbMapping { - // DbMappings belong to an application - protected final Application app; - - // prototype name of this mapping - private final String typename; - - // properties from where the mapping is read - private final Properties props; - - // name of data dbSource to which this mapping writes - private DbSource dbSource; - - // name of datasource - private String dbSourceName; - - // name of db table - private String tableName; - - // the verbatim, unparsed _parent specification - private String parentSetting; - - // list of properties to try for parent - private ParentInfo[] parentInfo; - - // Relations describing subnodes and properties. - protected Relation subRelation; - protected Relation propRelation; - - // if this defines a subnode mapping with groupby layer, - // we need a DbMapping for those groupby nodes - private DbMapping groupbyMapping; - - // Map of property names to Relations objects - private HashMap prop2db; - - // Map of db columns to Relations objects. - // Case insensitive, keys are stored in lower case so - // lookups must do a toLowerCase(). - private HashMap db2prop; - - // list of columns to fetch from db - private DbColumn[] columns = null; - - // Map of db columns by name - private HashMap columnMap; - - // Array of aggressively loaded references - private Relation[] joins; - - // pre-rendered select statement - private String selectString = null; - private String insertString = null; - private String updateString = null; - - // db field used as primary key - private String idField; - - // db field used as object name - private String nameField; - - // db field used to identify name of prototype to use for object instantiation - private String protoField; - - // Used to map prototype ids to prototype names for - // prototypes which extend the prototype represented by - // this DbMapping. - private ResourceProperties extensionMap; - - // a numeric or literal id used to represent this type in db - private String extensionId; - - // dbmapping of parent prototype, if any - private DbMapping parentMapping; - - // descriptor for key generation method - private String idgen; - - // remember last key generated for this table - private long lastID; - - // timestamp of last modification of the mapping (type.properties) - // init value is -1 so we know we have to run update once even if - // the underlying properties file is non-existent - long lastTypeChange = -1; - - // timestamp of last modification of an object of this type - long lastDataChange = 0; - - // Set of mappings that depend on us and should be forwarded last data change events - HashSet dependentMappings = new HashSet(); - - // does this DbMapping describe a virtual node (collection, mountpoint, groupnode)? - private boolean isVirtual = false; - - // does this Dbmapping describe a group node? - private boolean isGroup = false; - - /** - * Create an internal DbMapping used for "virtual" mappings aka collections, mountpoints etc. - */ - public DbMapping(Application app, String parentTypeName) { - this(app, parentTypeName, null); - // DbMappings created with this constructor always define virtual nodes - isVirtual = true; - if (parentTypeName != null) { - parentMapping = app.getDbMapping(parentTypeName); - if (parentMapping == null) { - throw new IllegalArgumentException("Unknown parent mapping: " + parentTypeName); - } - } - } - - /** - * Create a DbMapping from a type.properties property file - */ - public DbMapping(Application app, String typename, Properties props, boolean virtual) { - this(app, typename, props); - isVirtual = virtual; - } - - /** - * Create a DbMapping from a type.properties property file - */ - public DbMapping(Application app, String typename, Properties props) { - this.app = app; - // create a unique instance of the string. This is useful so - // we can compare types just by using == instead of equals. - this.typename = typename == null ? null : typename.intern(); - - prop2db = new HashMap(); - db2prop = new HashMap(); - columnMap = new HashMap(); - parentInfo = null; - idField = null; - this.props = props; - - if (props != null) { - readBasicProperties(); - } - } - - /** - * Tell the type manager whether we need update() to be called - */ - public boolean needsUpdate() { - if (props instanceof ResourceProperties) { - return ((ResourceProperties) props).lastModified() != lastTypeChange; - } - return false; - } - - /** - * Read in basic properties and register dbmapping with the - * dbsource. - */ - private void readBasicProperties() { - tableName = props.getProperty("_table"); - dbSourceName = props.getProperty("_db"); - - if (dbSourceName != null) { - dbSource = app.getDbSource(dbSourceName); - - if (dbSource == null) { - app.logError("Data Source for prototype " + typename + - " does not exist: " + dbSourceName); - app.logError("Accessing or storing a " + typename + - " object will cause an error."); - } else if (tableName == null) { - app.logError("No table name specified for prototype " + typename); - app.logError("Accessing or storing a " + typename + - " object will cause an error."); - - // mark mapping as invalid by nulling the dbSource field - dbSource = null; - } else { - // dbSource and tableName not null - register this instance - dbSource.registerDbMapping(this); - } - } - } - - - - /** - * Read the mapping from the Properties. Return true if the properties were changed. - * The read is split in two, this method and the rewire method. The reason is that in order - * for rewire to work, all other db mappings must have been initialized and registered. - */ - public synchronized void update() { - // read in properties - readBasicProperties(); - idgen = props.getProperty("_idgen"); - // if id field is null, we assume "ID" as default. We don't set it - // however, so that if null we check the parent prototype first. - idField = props.getProperty("_id"); - nameField = props.getProperty("_name"); - protoField = props.getProperty("_prototype"); - - parentSetting = props.getProperty("_parent"); - if (parentSetting != null) { - // comma-separated list of properties to be used as parent - StringTokenizer st = new StringTokenizer(parentSetting, ",;"); - parentInfo = new ParentInfo[st.countTokens()]; - - for (int i = 0; i < parentInfo.length; i++) { - parentInfo[i] = new ParentInfo(st.nextToken().trim()); - } - } else { - parentInfo = null; - } - - lastTypeChange = props instanceof ResourceProperties ? - ((ResourceProperties) props).lastModified() : System.currentTimeMillis(); - - // see if this prototype extends (inherits from) any other prototype - String extendsProto = props.getProperty("_extends"); - - if (extendsProto != null) { - parentMapping = app.getDbMapping(extendsProto); - if (parentMapping == null) { - app.logError("Parent mapping for prototype " + typename + - " does not exist: " + extendsProto); - } else { - if (parentMapping.needsUpdate()) { - parentMapping.update(); - } - // if tableName or DbSource are inherited from the parent mapping - // set them to null so we are aware of the fact. - if (tableName != null && - tableName.equals(parentMapping.getTableName())) { - tableName = null; - } - if (dbSourceName != null && - dbSourceName.equals(parentMapping.getDbSourceName())) { - dbSourceName = null; - dbSource = null; - } - } - } else { - parentMapping = null; - } - - if (inheritsStorage() && getPrototypeField() == null) { - app.logError("No _prototype mapping in extended prototype " + typename); - app.logError("Objects fetched from db will have base prototype " + extendsProto); - } - - // check if there is an extension-id specified inside the type.properties - extensionId = props.getProperty("_extensionId", typename); - registerExtension(extensionId, typename); - - // set the parent prototype in the corresponding Prototype object! - // this was previously done by TypeManager, but we need to do it - // ourself because DbMapping.update() may be called by other code than - // the TypeManager. - if (typename != null && - !"global".equalsIgnoreCase(typename) && - !"hopobject".equalsIgnoreCase(typename)) { - Prototype proto = app.getPrototypeByName(typename); - if (proto != null) { - if (extendsProto != null) { - proto.setParentPrototype(app.getPrototypeByName(extendsProto)); - } else if (!app.isJavaPrototype(typename)) { - proto.setParentPrototype(app.getPrototypeByName("hopobject")); - } - } - } - - // null the cached columns and select string - columns = null; - columnMap.clear(); - selectString = insertString = updateString = null; - - HashMap p2d = new HashMap(); - HashMap d2p = new HashMap(); - ArrayList joinList = new ArrayList(); - - for (Iterator it = props.entrySet().iterator(); it.hasNext(); ) { - Map.Entry entry = (Map.Entry) it.next(); - - try { - String propName = (String) entry.getKey(); - - // ignore internal properties (starting with "_") and sub-options (containing a ".") - if (!propName.startsWith("_") && propName.indexOf(".") < 0) { - Object propValue = entry.getValue(); - propName = app.correctPropertyName(propName); - - // check if a relation for this propery already exists. If so, reuse it - Relation rel = (Relation) prop2db.get(propName); - - if (rel == null) { - rel = new Relation(propName, this); - } - - rel.update(propValue, getSubProperties(propName)); - p2d.put(propName, rel); - - if ((rel.columnName != null) && rel.isPrimitiveOrReference()) { - Relation old = (Relation) d2p.put(rel.columnName.toLowerCase(), rel); - // check if we're overwriting another relation - // if so, primitive relations get precendence to references - if (old != null) { - if (rel.isPrimitive() && old.isPrimitive()) { - app.logEvent("Duplicate mapping for " + typename + "." + rel.columnName); - } else if (rel.isReference() && old.isPrimitive()) { - // if a column is used both in a primitive and a reference mapping, - // use primitive mapping as primary one and mark reference as - // complex so it will be fetched separately - d2p.put(old.columnName.toLowerCase(), old); - rel.reftype = Relation.COMPLEX_REFERENCE; - } else if (rel.isPrimitive() && old.isReference()) { - old.reftype = Relation.COMPLEX_REFERENCE; - } - } - } - - // check if a reference is aggressively fetched - if (rel.aggressiveLoading && - (rel.isReference() || rel.isComplexReference())) { - joinList.add(rel); - } - - // app.logEvent ("Mapping "+propName+" -> "+dbField); - } - } catch (Exception x) { - app.logEvent("Error in type.properties: " + x.getMessage()); - } - } - - prop2db = p2d; - db2prop = d2p; - - joins = new Relation[joinList.size()]; - joins = (Relation[]) joinList.toArray(joins); - - Object subnodeMapping = props.get("_children"); - - if (subnodeMapping != null) { - try { - // check if subnode relation already exists. If so, reuse it - if (subRelation == null) { - subRelation = new Relation("_children", this); - } - - subRelation.update(subnodeMapping, getSubProperties("_children")); - - // if subnodes are accessed via access name or group name, - // the subnode relation is also the property relation. - if ((subRelation.accessName != null) || (subRelation.groupby != null)) { - propRelation = subRelation; - } else { - propRelation = null; - } - } catch (Exception x) { - app.logEvent("Error reading _subnodes relation for " + typename + ": " + - x.getMessage()); - - // subRelation = null; - } - } else { - subRelation = propRelation = null; - } - - if (groupbyMapping != null) { - initGroupbyMapping(); - groupbyMapping.lastTypeChange = this.lastTypeChange; - } - } - - /** - * Add the given extensionId and the coresponding prototypename - * to extensionMap for later lookup. - * @param extID the id mapping to the prototypename recogniced by helma - * @param extName the name of the extending prototype - */ - private void registerExtension(String extID, String extName) { - // lazy initialization of extensionMap - if (extID == null) { - return; - } - if (extensionMap == null) { - extensionMap = new ResourceProperties(); - extensionMap.setIgnoreCase(true); - } else if (extensionMap.containsValue(extName)) { - // remove any preexisting mapping for the given childmapping - extensionMap.values().remove(extName); - } - extensionMap.setProperty(extID, extName); - if (inheritsStorage()) { - parentMapping.registerExtension(extID, extName); - } - } - - /** - * Returns the Set of Prototypes extending this prototype - * @return the Set of Prototypes extending this prototype - */ - public String[] getExtensions() { - return extensionMap == null - ? new String[] { extensionId } - : (String[]) extensionMap.keySet().toArray(new String[0]); - } - - /** - * Looks up the prototype name identified by the given id, returing - * our own type name if it can't be resolved - * @param id the id specified for the prototype - * @return the name of the extending prototype - */ - public String getPrototypeName(String id) { - if (inheritsStorage()) { - return parentMapping.getPrototypeName(id); - } - // fallback to base-prototype if the proto isn't recogniced - if (id == null) { - return typename; - } - return extensionMap.getProperty(id, typename); - } - - /** - * get the id-value of this extension - */ - public String getExtensionId() { - return extensionId; - } - - /** - * Method in interface Updatable. - */ - public void remove() { - // do nothing, removing of type properties is not implemented. - } - - /** - * Get a JDBC connection for this DbMapping. - */ - public Connection getConnection() throws ClassNotFoundException, SQLException { - if (dbSourceName == null) { - if (parentMapping != null) { - return parentMapping.getConnection(); - } else { - throw new SQLException("Tried to get Connection from non-relational embedded data source."); - } - } - - if (tableName == null) { - throw new SQLException("Invalid DbMapping, _table not specified: " + this); - } - - // if dbSource was previously not available, check again - if (dbSource == null) { - dbSource = app.getDbSource(dbSourceName); - } - - if (dbSource == null) { - throw new SQLException("Datasource not defined or unable to load driver: " + dbSourceName + "."); - } - - return dbSource.getConnection(); - } - - /** - * Get the DbSource object for this DbMapping. The DbSource describes a JDBC - * data source including URL, JDBC driver, username and password. - */ - public DbSource getDbSource() { - if (dbSource == null) { - if (dbSourceName != null) { - dbSource = app.getDbSource(dbSourceName); - } else if (parentMapping != null) { - return parentMapping.getDbSource(); - } - } - - return dbSource; - } - - /** - * Get the dbsource name used for this type mapping. - */ - public String getDbSourceName() { - if ((dbSourceName == null) && (parentMapping != null)) { - return parentMapping.getDbSourceName(); - } - - return dbSourceName; - } - - /** - * Get the table name used for this type mapping. - */ - public String getTableName() { - if ((tableName == null) && (parentMapping != null)) { - return parentMapping.getTableName(); - } - - return tableName; - } - - /** - * Get the application this DbMapping belongs to. - */ - public Application getApplication() { - return app; - } - - /** - * Get the name of this mapping's application - */ - public String getAppName() { - return app.getName(); - } - - /** - * Get the name of the object type this DbMapping belongs to. - */ - public String getTypeName() { - return typename; - } - - /** - * Get the name of this type's parent type, if any. - */ - public String getExtends() { - return parentMapping == null ? null : parentMapping.getTypeName(); - } - - /** - * Get the primary key column name for objects using this mapping. - */ - public String getIDField() { - if ((idField == null) && (parentMapping != null)) { - return parentMapping.getIDField(); - } - - return (idField == null) ? "ID" : idField; - } - - /** - * Get the column used for (internal) names of objects of this type. - */ - public String getNameField() { - if ((nameField == null) && (parentMapping != null)) { - return parentMapping.getNameField(); - } - - return nameField; - } - - /** - * Get the column used for names of prototype. - */ - public String getPrototypeField() { - if ((protoField == null) && (parentMapping != null)) { - return parentMapping.getPrototypeField(); - } - - return protoField; - } - - /** - * Translate a database column name to an object property name according to this mapping. - */ - public String columnNameToProperty(String columnName) { - if (columnName == null) { - return null; - } - - // SEMIHACK: If columnName is a function call, try to extract actual - // column name from it - int open = columnName.indexOf('('); - int close = columnName.indexOf(')'); - if (open > -1 && close > open) { - columnName = columnName.substring(open + 1, close); - } - - return _columnNameToProperty(columnName.toLowerCase()); - } - - private String _columnNameToProperty(final String columnName) { - Relation rel = (Relation) db2prop.get(columnName); - - if ((rel == null) && (parentMapping != null)) { - return parentMapping._columnNameToProperty(columnName); - } - - if ((rel != null) && rel.isPrimitiveOrReference()) { - return rel.propName; - } - - return null; - } - - /** - * Translate an object property name to a database column name according - * to this mapping. If no mapping is found, the property name is returned, - * assuming property and column names are equal. - */ - public String propertyToColumnName(String propName) { - if (propName == null) { - return null; - } - - return _propertyToColumnName(propName); - } - - private String _propertyToColumnName(final String propName) { - Relation rel = (Relation) prop2db.get(app.correctPropertyName(propName)); - - if ((rel == null) && (parentMapping != null)) { - return parentMapping._propertyToColumnName(propName); - } - - if ((rel != null) && (rel.isPrimitiveOrReference())) { - return rel.columnName; - } - - return null; - } - - /** - * Translate a database column name to an object property name according to this mapping. - */ - public Relation columnNameToRelation(String columnName) { - if (columnName == null) { - return null; - } - - return _columnNameToRelation(columnName.toLowerCase()); - } - - private Relation _columnNameToRelation(final String columnName) { - Relation rel = (Relation) db2prop.get(columnName); - - if ((rel == null) && (parentMapping != null)) { - return parentMapping._columnNameToRelation(columnName); - } - - return rel; - } - - /** - * Translate an object property name to a database column name according to this mapping. - */ - public Relation propertyToRelation(String propName) { - if (propName == null) { - return null; - } - - return _propertyToRelation(propName); - } - - private Relation _propertyToRelation(String propName) { - Relation rel = (Relation) prop2db.get(app.correctPropertyName(propName)); - - if ((rel == null) && (parentMapping != null)) { - return parentMapping._propertyToRelation(propName); - } - - return rel; - } - - /** - * @return the parent info as unparsed string. - */ - public String getParentSetting() { - if ((parentSetting == null) && (parentMapping != null)) { - return parentMapping.getParentSetting(); - } - return parentSetting; - } - - /** - * @return the parent info array, which tells an object of this type how to - * determine its parent object. - */ - public synchronized ParentInfo[] getParentInfo() { - if ((parentInfo == null) && (parentMapping != null)) { - return parentMapping.getParentInfo(); - } - - return parentInfo; - } - - /** - * - * - * @return ... - */ - public DbMapping getSubnodeMapping() { - if (subRelation != null) { - return subRelation.otherType; - } - - if (parentMapping != null) { - return parentMapping.getSubnodeMapping(); - } - - return null; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public DbMapping getPropertyMapping(String propname) { - Relation rel = getPropertyRelation(propname); - - if (rel != null) { - // if this is a virtual node, it doesn't have a dbmapping - if (rel.virtual && (rel.prototype == null)) { - return null; - } else { - return rel.otherType; - } - } - - return null; - } - - /** - * If subnodes are grouped by one of their properties, return the - * db-mapping with the right relations to create the group-by nodes - */ - public synchronized DbMapping getGroupbyMapping() { - if (subRelation == null && parentMapping != null) { - return parentMapping.getGroupbyMapping(); - } else if (subRelation == null || subRelation.groupby == null) { - return null; - } else if (groupbyMapping == null) { - initGroupbyMapping(); - } - - return groupbyMapping; - } - - /** - * Initialize the dbmapping used for group-by nodes. - */ - private void initGroupbyMapping() { - // if a prototype is defined for groupby nodes, use that - // if mapping doesn' exist or isn't defined, create a new (anonymous internal) one - groupbyMapping = new DbMapping(app, subRelation.groupbyPrototype); - groupbyMapping.lastTypeChange = this.lastTypeChange; - groupbyMapping.isGroup = true; - - // set subnode and property relations - groupbyMapping.subRelation = subRelation.getGroupbySubnodeRelation(); - - if (propRelation != null) { - groupbyMapping.propRelation = propRelation.getGroupbyPropertyRelation(); - } else { - groupbyMapping.propRelation = subRelation.getGroupbyPropertyRelation(); - } - } - - /** - * - * - * @param rel ... - */ - public void setPropertyRelation(Relation rel) { - propRelation = rel; - } - - /** - * - * - * @return ... - */ - public Relation getSubnodeRelation() { - if ((subRelation == null) && (parentMapping != null)) { - return parentMapping.getSubnodeRelation(); - } - - return subRelation; - } - - /** - * Return the list of defined property names as String array. - */ - public String[] getPropertyNames() { - return (String[]) prop2db.keySet().toArray(new String[prop2db.size()]); - } - - /** - * - * - * @return ... - */ - private Relation getPropertyRelation() { - if ((propRelation == null) && (parentMapping != null)) { - return parentMapping.getPropertyRelation(); - } - - return propRelation; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public Relation getPropertyRelation(String propname) { - if (propname == null) { - return getPropertyRelation(); - } - - // first try finding an exact match for the property name - Relation rel = getExactPropertyRelation(propname); - - // if not defined, return the generic property mapping - if (rel == null) { - rel = getPropertyRelation(); - } - - return rel; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public Relation getExactPropertyRelation(String propname) { - if (propname == null) { - return null; - } - - Relation rel = (Relation) prop2db.get(app.correctPropertyName(propname)); - - if ((rel == null) && (parentMapping != null)) { - rel = parentMapping.getExactPropertyRelation(propname); - } - - return rel; - } - - /** - * - * - * @return ... - */ - public String getSubnodeGroupby() { - if ((subRelation == null) && (parentMapping != null)) { - return parentMapping.getSubnodeGroupby(); - } - - return (subRelation == null) ? null : subRelation.groupby; - } - - /** - * - * - * @return ... - */ - public String getIDgen() { - if ((idgen == null) && (parentMapping != null)) { - return parentMapping.getIDgen(); - } - - return idgen; - } - - /** - * - * - * @return ... - */ - public WrappedNodeManager getWrappedNodeManager() { - if (app == null) { - throw new RuntimeException("Can't get node manager from internal db mapping"); - } - - return app.getWrappedNodeManager(); - } - - /** - * Tell whether this data mapping maps to a relational database table. This returns true - * if a datasource is specified, even if it is not a valid one. Otherwise, objects with invalid - * mappings would be stored in the embedded db instead of an error being thrown, which is - * not what we want. - */ - public boolean isRelational() { - return dbSourceName != null || (parentMapping != null && parentMapping.isRelational()); - } - - /** - * Return an array of DbColumns for the relational table mapped by this DbMapping. - */ - public synchronized DbColumn[] getColumns() - throws ClassNotFoundException, SQLException { - if (!isRelational()) { - throw new SQLException("Can't get columns for non-relational data mapping " + this); - } - - // Use local variable cols to avoid synchronization (schema may be nulled elsewhere) - if (columns == null) { - // we do two things here: set the SQL type on the Relation mappings - // and build a string of column names. - Connection con = getConnection(); - Statement stmt = con.createStatement(); - String table = getTableName(); - - if (table == null) { - throw new SQLException("Table name is null in getColumns() for " + this); - } - - ResultSet rs = stmt.executeQuery(new StringBuffer("SELECT * FROM ").append(table) - .append(" WHERE 1 = 0") - .toString()); - - if (rs == null) { - throw new SQLException("Error retrieving columns for " + this); - } - - ResultSetMetaData meta = rs.getMetaData(); - - // ok, we have the meta data, now loop through mapping... - int ncols = meta.getColumnCount(); - ArrayList list = new ArrayList(ncols); - - for (int i = 0; i < ncols; i++) { - String colName = meta.getColumnName(i + 1); - Relation rel = columnNameToRelation(colName); - - DbColumn col = new DbColumn(colName, meta.getColumnType(i + 1), rel, this); - list.add(col); - } - columns = (DbColumn[]) list.toArray(new DbColumn[list.size()]); - } - - return columns; - } - - /** - * Return the array of relations that are fetched with objects of this type. - */ - public Relation[] getJoins() { - return joins; - } - - /** - * - * - * @param columnName ... - * - * @return ... - * - * @throws ClassNotFoundException ... - * @throws SQLException ... - */ - public DbColumn getColumn(String columnName) - throws ClassNotFoundException, SQLException { - DbColumn col = (DbColumn) columnMap.get(columnName); - if (col == null) { - DbColumn[] cols = columns; - if (cols == null) { - cols = getColumns(); - } - for (int i = 0; i < cols.length; i++) { - if (columnName.equalsIgnoreCase(cols[i].getName())) { - col = cols[i]; - break; - } - } - columnMap.put(columnName, col); - } - return col; - } - - /** - * Get a StringBuffer initialized to the first part of the select statement - * for objects defined by this DbMapping - * - * @param rel the Relation we use to select. Currently only used for optimizer hints. - * Is null if selecting by primary key. - * @return the StringBuffer containing the first part of the select query - */ - public StringBuffer getSelect(Relation rel) { - // assign to local variable first so we are thread safe - // (selectString may be reset by other threads) - String sel = selectString; - boolean isOracle = isOracle(); - - if (rel == null && sel != null) { - return new StringBuffer(sel); - } - - StringBuffer s = new StringBuffer("SELECT "); - - if (rel != null && rel.queryHints != null) { - s.append(rel.queryHints).append(" "); - } - - String table = getTableName(); - - // all columns from the main table - s.append(table); - s.append(".*"); - - for (int i = 0; i < joins.length; i++) { - if (!joins[i].otherType.isRelational()) { - continue; - } - s.append(", "); - s.append(Relation.JOIN_PREFIX); - s.append(joins[i].propName); - s.append(".*"); - } - - s.append(" FROM "); - - s.append(table); - - if (rel != null) { - rel.appendAdditionalTables(s); - } - - s.append(" "); - - for (int i = 0; i < joins.length; i++) { - if (!joins[i].otherType.isRelational()) { - continue; - } - if (isOracle) { - // generate an old-style oracle left join - see - // http://www.praetoriate.com/oracle_tips_outer_joins.htm - s.append(", "); - s.append(joins[i].otherType.getTableName()); - s.append(" "); - s.append(Relation.JOIN_PREFIX); - s.append(joins[i].propName); - s.append(" "); - } else { - s.append("LEFT OUTER JOIN "); - s.append(joins[i].otherType.getTableName()); - s.append(" "); - s.append(Relation.JOIN_PREFIX); - s.append(joins[i].propName); - s.append(" ON "); - joins[i].renderJoinConstraints(s, isOracle); - } - } - - // cache rendered string for later calls, but only if it wasn't - // built for a particular Relation - if (rel == null) { - selectString = s.toString(); - } - - return s; - } - - /** - * - * - * @return ... - */ - public String getInsert() throws ClassNotFoundException, SQLException { - String ins = insertString; - - if (ins != null) { - return ins; - } - - StringBuffer b1 = new StringBuffer("INSERT INTO "); - StringBuffer b2 = new StringBuffer(" ) VALUES ( "); - b1.append(getTableName()); - b1.append(" ( "); - - DbColumn[] cols = getColumns(); - boolean needsComma = false; - - for (int i = 0; i < cols.length; i++) { - if (cols[i].isMapped()) { - if (needsComma) { - b1.append(", "); - b2.append(", "); - } - b1.append(cols[i].getName()); - b2.append("?"); - needsComma = true; - } - } - - b1.append(b2.toString()); - b1.append(" )"); - - // cache rendered string for later calls. - ins = insertString = b1.toString(); - - return ins; - } - - - /** - * - * - * @return ... - */ - public StringBuffer getUpdate() { - String upd = updateString; - - if (upd != null) { - return new StringBuffer(upd); - } - - StringBuffer s = new StringBuffer("UPDATE "); - - s.append(getTableName()); - s.append(" SET "); - - // cache rendered string for later calls. - updateString = s.toString(); - - return s; - } - - /** - * Return true if values for the column identified by the parameter need - * to be quoted in SQL queries. - */ - public boolean needsQuotes(String columnName) throws SQLException, ClassNotFoundException { - if ((tableName == null) && (parentMapping != null)) { - return parentMapping.needsQuotes(columnName); - } - DbColumn col = getColumn(columnName); - // This is not a mapped column. In case of doubt, add quotes. - if (col == null) { - return true; - } else { - return col.needsQuotes(); - } - } - - /** - * Add constraints to select query string to join object references - */ - public void addJoinConstraints(StringBuffer s, String pre) { - boolean isOracle = isOracle(); - String prefix = pre; - - if (!isOracle) { - // constraints have already been rendered by getSelect() - return; - } - - for (int i = 0; i < joins.length; i++) { - if (!joins[i].otherType.isRelational()) { - continue; - } - s.append(prefix); - joins[i].renderJoinConstraints(s, isOracle); - prefix = " AND "; - } - } - - /** - * Is the database behind this an Oracle db? - * - * @return true if the dbsource is using an oracle JDBC driver - */ - public boolean isOracle() { - if (dbSource != null) { - return dbSource.isOracle(); - } - if (parentMapping != null) { - return parentMapping.isOracle(); - } - return false; - } - - /** - * Is the database behind this a MySQL db? - * - * @return true if the dbsource is using a MySQL JDBC driver - */ - public boolean isMySQL() { - if (dbSource != null) { - return dbSource.isMySQL(); - } - if (parentMapping != null) { - return parentMapping.isMySQL(); - } - return false; - } - - /** - * Is the database behind this a PostgreSQL db? - * - * @return true if the dbsource is using a PostgreSQL JDBC driver - */ - public boolean isPostgreSQL() { - if (dbSource != null) { - return dbSource.isPostgreSQL(); - } - if (parentMapping != null) { - return parentMapping.isPostgreSQL(); - } - return false; - } - - /** - * Is the database behind this a H2 db? - * - * @return true if the dbsource is using a H2 JDBC driver - */ - public boolean isH2() { - if (dbSource != null) { - return dbSource.isH2(); - } - if (parentMapping != null) { - return parentMapping.isH2(); - } - return false; - } - - /** - * Return a string representation for this DbMapping - * - * @return a string representation - */ - public String toString() { - if (typename == null) { - return "[unspecified internal DbMapping]"; - } else { - return ("[" + app.getName() + "." + typename + "]"); - } - } - - /** - * Get the last time something changed in the Mapping - * - * @return time of last mapping change - */ - public long getLastTypeChange() { - return lastTypeChange; - } - - /** - * Get the last time something changed in our data - * - * @return time of last data change - */ - public long getLastDataChange() { - // refer to parent mapping if it uses the same db/table - if (inheritsStorage()) { - return parentMapping.getLastDataChange(); - } else { - return lastDataChange; - } - } - - /** - * Set the last time something changed in the data, propagating the event - * to mappings that depend on us through an additionalTables switch. - */ - public void setLastDataChange() { - // forward data change timestamp to storage-compatible parent mapping - if (inheritsStorage()) { - parentMapping.setLastDataChange(); - } else { - lastDataChange += 1; - // propagate data change timestamp to mappings that depend on us - if (!dependentMappings.isEmpty()) { - Iterator it = dependentMappings.iterator(); - while(it.hasNext()) { - DbMapping dbmap = (DbMapping) it.next(); - dbmap.setIndirectDataChange(); - } - } - } - } - - /** - * Set the last time something changed in the data. This is already an indirect - * data change triggered by a mapping we depend on, so we don't propagate it to - * mappings that depend on us through an additionalTables switch. - */ - protected void setIndirectDataChange() { - // forward data change timestamp to storage-compatible parent mapping - if (inheritsStorage()) { - parentMapping.setIndirectDataChange(); - } else { - lastDataChange += 1; - } - } - - /** - * Helper method to generate a new ID. This is only used in the special case - * when using the select(max) method and the underlying table is still empty. - * - * @param dbmax the maximum value already stored in db - * @return a new and hopefully unique id - */ - protected synchronized long getNewID(long dbmax) { - // refer to parent mapping if it uses the same db/table - if (inheritsStorage()) { - return parentMapping.getNewID(dbmax); - } else { - lastID = Math.max(dbmax + 1, lastID + 1); - return lastID; - } - } - - /** - * Return an enumeration of all properties defined by this db mapping. - * - * @return the property enumeration - */ - public Enumeration getPropertyEnumeration() { - HashSet set = new HashSet(); - - collectPropertyNames(set); - - final Iterator it = set.iterator(); - - return new Enumeration() { - public boolean hasMoreElements() { - return it.hasNext(); - } - - public Object nextElement() { - return it.next(); - } - }; - } - - /** - * Collect a set of all properties defined by this db mapping - * - * @param basket the set to put properties into - */ - private void collectPropertyNames(HashSet basket) { - // fetch propnames from parent mapping first, than add our own. - if (parentMapping != null) { - parentMapping.collectPropertyNames(basket); - } - - if (!prop2db.isEmpty()) { - basket.addAll(prop2db.keySet()); - } - } - - /** - * Return the name of the prototype which specifies the storage location - * (dbsource + tablename) for this type, or null if it is stored in the embedded - * db. - */ - public String getStorageTypeName() { - if (inheritsStorage()) { - return parentMapping.getStorageTypeName(); - } - return (getDbSourceName() == null) ? null : typename; - } - - /** - * Check whether this DbMapping inherits its storage location from its - * parent mapping. The raison d'etre for this is that we need to detect - * inherited storage even if the dbsource and table are explicitly set - * in the extended mapping. - * - * @return true if this mapping shares its parent mapping storage - */ - protected boolean inheritsStorage() { - // note: tableName and dbSourceName are nulled out in update() if they - // are inherited from the parent mapping. This way we know that - // storage is not inherited if either of them is not null. - return isRelational() && parentMapping != null - && tableName == null && dbSourceName == null; - } - - /** - * Static utility method to check whether two DbMappings use the same storage. - * - * @return true if both use the embedded database or the same relational table. - */ - public static boolean areStorageCompatible(DbMapping dbm1, DbMapping dbm2) { - if (dbm1 == null) - return dbm2 == null || !dbm2.isRelational(); - return dbm1.isStorageCompatible(dbm2); - } - - /** - * Tell if this DbMapping uses the same storage as the given DbMapping. - * - * @return true if both use the embedded database or the same relational table. - */ - public boolean isStorageCompatible(DbMapping other) { - if (other == null) { - return !isRelational(); - } else if (other == this) { - return true; - } else if (isRelational()) { - return getTableName().equals(other.getTableName()) && - getDbSource().equals(other.getDbSource()); - } - - return !other.isRelational(); - } - - /** - * Return true if this db mapping represents the prototype indicated - * by the string argument, either itself or via one of its parent prototypes. - */ - public boolean isInstanceOf(String other) { - if ((typename != null) && typename.equals(other)) { - return true; - } - - DbMapping p = parentMapping; - - while (p != null) { - if ((p.typename != null) && p.typename.equals(other)) { - return true; - } - - p = p.parentMapping; - } - - return false; - } - - /** - * Get the mapping we inherit from, or null - * - * @return the parent DbMapping, or null - */ - public DbMapping getParentMapping() { - return parentMapping; - } - - /** - * Get our ResourceProperties - * - * @return our properties - */ - public Properties getProperties() { - return props; - } - - public Properties getSubProperties(String prefix) { - if (props.get(prefix) instanceof Properties) { - return (Properties) props.get(prefix); - } else if (props instanceof ResourceProperties) { - return ((ResourceProperties) props).getSubProperties(prefix + "."); - } else { - Properties subprops = new Properties(); - prefix = prefix + "."; - Iterator it = props.entrySet().iterator(); - int prefixLength = prefix.length(); - while (it.hasNext()) { - Map.Entry entry = (Map.Entry) it.next(); - String key = entry.getKey().toString(); - if (key.regionMatches(false, 0, prefix, 0, prefixLength)) { - subprops.put(key.substring(prefixLength), entry.getValue()); - } - } - return subprops; - } - } - - /** - * Register a DbMapping that depends on this DbMapping, so that collections of other mapping - * should be reloaded if data on this mapping is updated. - * - * @param dbmap the DbMapping that depends on us - */ - protected void addDependency(DbMapping dbmap) { - this.dependentMappings.add(dbmap); - } - - /** - * Append a sql-condition for the given column which must have - * one of the values contained inside the given Set to the given - * StringBuffer. - * @param q the StringBuffer to append to - * @param column the column which must match one of the values - * @param values the list of values - * @throws SQLException - */ - protected void appendCondition(StringBuffer q, String column, String[] values) - throws SQLException, ClassNotFoundException { - if (values.length == 1) { - appendCondition(q, column, values[0]); - return; - } - if (column.indexOf('(') == -1 && column.indexOf('.') == -1) { - q.append(getTableName()).append("."); - } - q.append(column).append(" in ("); - - if (needsQuotes(column)) { - for (int i = 0; i < values.length; i++) { - if (i > 0) - q.append(", "); - q.append("'").append(escapeString(values[i])).append("'"); - } - } else { - for (int i = 0; i < values.length; i++) { - if (i > 0) - q.append(", "); - q.append(checkNumber(values[i])); - } - } - q.append(")"); - } - - /** - * Append a sql-condition for the given column which must have - * the value given to the given StringBuffer. - * @param q the StringBuffer to append to - * @param column the column which must match one of the values - * @param val the value - * @throws SQLException - */ - protected void appendCondition(StringBuffer q, String column, String val) - throws SQLException, ClassNotFoundException { - if (column.indexOf('(') == -1 && column.indexOf('.') == -1) { - q.append(getTableName()).append("."); - } - q.append(column).append(" = "); - - if (needsQuotes(column)) { - q.append("'").append(escapeString(val)).append("'"); - } else { - q.append(checkNumber(val)); - } - } - - /** - * a utility method to escape single quotes used for inserting - * string-values into relational databases. - * Searches for "'" characters and escapes them by duplicating them (= "''") - * @param value the string to escape - * @return the escaped string - */ - static String escapeString(Object value) { - String str = value == null ? null : value.toString(); - if (str == null) { - return null; - } else if (str.indexOf('\'') < 0 && str.indexOf('\\') < 0) { - return str; - } - - int l = str.length(); - StringBuffer sbuf = new StringBuffer(l + 10); - - for (int i = 0; i < l; i++) { - char c = str.charAt(i); - - if (c == '\'') { - sbuf.append("\\'"); - } else if (c == '\\') { - sbuf.append("\\\\"); - } else { - sbuf.append(c); - } - } - return sbuf.toString(); - } - - /** - * Utility method to check whether the argument is a number literal. - * @param value a string representing a number literal - * @return the argument, if it conforms to the number literal syntax - * @throws IllegalArgumentException if the argument does not represent a number - */ - static String checkNumber(Object value) throws IllegalArgumentException { - String str = value == null ? null : value.toString(); - if (str == null) { - return null; - } else { - str = str.trim(); - if (str.matches("(?:\\+|\\-)??\\d+(?:\\.\\d+)??")) { - return str; - } - } - throw new IllegalArgumentException("Illegal numeric literal: " + str); - } - - /** - * Find if this DbMapping describes a virtual node (collection, mountpoint, groupnode) - * @return true if this instance describes a virtual node. - */ - public boolean isVirtual() { - return isVirtual; - } - - /** - * Find if this DbMapping describes a group node. - * @return true if this instance describes a group node. - */ - public boolean isGroup() { - return isGroup; - } - - /** - * Find whether a node with this DbMapping must be stored in the database. - * This is true if this mapping defines a non-virtual node, or a virtual - * node with non-relational child objects. - * @return true if this node needs to be stored in the db, false otherwise - */ - public boolean needsPersistence() { - DbMapping submap = getSubnodeMapping(); - return !isVirtual || (submap != null && !submap.isRelational()); - } -} - diff --git a/src/main/java/helma/objectmodel/db/DbSource.java b/src/main/java/helma/objectmodel/db/DbSource.java deleted file mode 100644 index 33e1dbc8..00000000 --- a/src/main/java/helma/objectmodel/db/DbSource.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.util.ResourceProperties; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Enumeration; -import java.util.Properties; -import java.util.Hashtable; - -/** - * This class describes a releational data source (URL, driver, user and password). - */ -public class DbSource { - private static ResourceProperties defaultProps = null; - private Properties conProps; - private final String name; - private ResourceProperties props, subProps; - protected String url; - private String driver; - private boolean isOracle, isMySQL, isPostgreSQL, isH2; - private long lastRead = 0L; - private Hashtable dbmappings = new Hashtable(); - // compute hashcode statically because it's expensive and we need it often - private int hashcode; - // thread local connection holder for non-transactor threads - private ThreadLocal connection; - - /** - * Creates a new DbSource object. - * - * @param name the db source name - * @param props the properties - * @throws ClassNotFoundException if the JDBC driver couldn't be loaded - */ - public DbSource(String name, ResourceProperties props) - throws ClassNotFoundException { - this.name = name; - this.props = props; - init(); - } - - /** - * Get a JDBC connection to the db source. - * - * @return a JDBC connection - * - * @throws ClassNotFoundException if the JDBC driver couldn't be loaded - * @throws SQLException if the connection couldn't be created - */ - public synchronized Connection getConnection() - throws ClassNotFoundException, SQLException { - Connection con; - Transactor tx = Transactor.getInstance(); - if (tx != null) { - con = tx.getConnection(this); - } else { - con = getThreadLocalConnection(); - } - - boolean fileUpdated = props.lastModified() > lastRead || - (defaultProps != null && defaultProps.lastModified() > lastRead); - - if (con == null || con.isClosed() || fileUpdated) { - init(); - con = DriverManager.getConnection(url, conProps); - - // If we wanted to use SQL transactions, we'd set autoCommit to - // false here and make commit/rollback invocations in Transactor methods; - // System.err.println ("Created new Connection to "+url); - if (tx != null) { - tx.registerConnection(this, con); - } else { - connection.set(con); - } - } - - return con; - } - - /** - * Used for connections not managed by a Helma transactor - * @return a thread local tested connection, or null - */ - private Connection getThreadLocalConnection() { - if (connection == null) { - connection = new ThreadLocal(); - return null; - } - Connection con = (Connection) connection.get(); - if (con != null) { - // test if connection is still ok - try { - Statement stmt = con.createStatement(); - stmt.execute("SELECT 1"); - stmt.close(); - } catch (SQLException sx) { - try { - con.close(); - } catch (SQLException ignore) {/* nothing to do */} - return null; - } - } - return con; - } - - /** - * Set the db properties to newProps, and return the old properties. - * @param newProps the new properties to use for this db source - * @return the old properties - * @throws ClassNotFoundException if jdbc driver class couldn't be found - */ - public synchronized ResourceProperties switchProperties(ResourceProperties newProps) - throws ClassNotFoundException { - ResourceProperties oldProps = props; - props = newProps; - init(); - return oldProps; - } - - /** - * Initialize the db source from the properties - * - * @throws ClassNotFoundException if the JDBC driver couldn't be loaded - */ - private synchronized void init() throws ClassNotFoundException { - lastRead = (defaultProps == null) ? props.lastModified() - : Math.max(props.lastModified(), - defaultProps.lastModified()); - // refresh sub-properties for this DbSource - subProps = props.getSubProperties(name + '.'); - // use properties hashcode for ourselves - hashcode = subProps.hashCode(); - // get JDBC URL and driver class name - url = subProps.getProperty("url"); - driver = subProps.getProperty("driver"); - // sanity checks - if (url == null) { - throw new NullPointerException(name+".url is not defined in db.properties"); - } - if (driver == null) { - throw new NullPointerException(name+".driver class not defined in db.properties"); - } - // test if this is an Oracle or MySQL driver - isOracle = driver.startsWith("oracle.jdbc.driver"); - isMySQL = driver.startsWith("com.mysql.jdbc") || - driver.startsWith("org.gjt.mm.mysql"); - isPostgreSQL = driver.equals("org.postgresql.Driver"); - isH2 = driver.equals("org.h2.Driver"); - // test if driver class is available - Class.forName(driver); - - // set up driver connection properties - conProps=new Properties(); - String prop = subProps.getProperty("user"); - if (prop != null) { - conProps.put("user", prop); - } - prop = subProps.getProperty("password"); - if (prop != null) { - conProps.put("password", prop); - } - - // read any remaining extra properties to be passed to the driver - for (Enumeration e = subProps.keys(); e.hasMoreElements(); ) { - String key = (String) e.nextElement(); - - // filter out properties we alread have - if ("url".equalsIgnoreCase(key) || - "driver".equalsIgnoreCase(key) || - "user".equalsIgnoreCase(key) || - "password".equalsIgnoreCase(key)) { - continue; - } - conProps.setProperty(key, subProps.getProperty(key)); - } - } - - /** - * Return the class name of the JDBC driver - * - * @return the class name of the JDBC driver - */ - public String getDriverName() { - return driver; - } - - /** - * Return the name of the db dource - * - * @return the name of the db dource - */ - public String getName() { - return name; - } - - /** - * Set the default (server-wide) properties - * - * @param props server default db.properties - */ - public static void setDefaultProps(ResourceProperties props) { - defaultProps = props; - } - - /** - * Check if this DbSource represents an Oracle database - * - * @return true if we're using an oracle JDBC driver - */ - public boolean isOracle() { - return isOracle; - } - - /** - * Check if this DbSource represents a MySQL database - * - * @return true if we're using a MySQL JDBC driver - */ - public boolean isMySQL() { - return isMySQL; - } - - /** - * Check if this DbSource represents a PostgreSQL database - * - * @return true if we're using a PostgreSQL JDBC driver - */ - public boolean isPostgreSQL() { - return isPostgreSQL; - } - - /** - * Check if this DbSource represents a H2 database - * - * @return true if we're using a H2 JDBC driver - */ - public boolean isH2() { - return isH2; - } - - /** - * Register a dbmapping by its table name. - * - * @param dbmap the DbMapping instance to register - */ - protected void registerDbMapping(DbMapping dbmap) { - if (!dbmap.inheritsStorage() && dbmap.getTableName() != null) { - dbmappings.put(dbmap.getTableName().toUpperCase(), dbmap); - } - } - - /** - * Look up a DbMapping instance for the given table name. - * - * @param tablename the table name - * @return the matching DbMapping instance - */ - protected DbMapping getDbMapping(String tablename) { - return (DbMapping) dbmappings.get(tablename.toUpperCase()); - } - - /** - * Returns a hash code value for the object. - */ - public int hashCode() { - return hashcode; - } - - /** - * Indicates whether some other object is "equal to" this one. - */ - public boolean equals(Object obj) { - return obj instanceof DbSource && subProps.equals(((DbSource) obj).subProps); - } -} diff --git a/src/main/java/helma/objectmodel/db/IDGenerator.java b/src/main/java/helma/objectmodel/db/IDGenerator.java deleted file mode 100644 index be07a14f..00000000 --- a/src/main/java/helma/objectmodel/db/IDGenerator.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.framework.core.Application; - - -/** - * An interface for objects that generate IDs (Strings) that are - * unique for a specific type. - */ -public interface IDGenerator { - - /** - * Init the ID generator for the given application. - * - * @param app - */ - public void init(Application app); - - /** - * Shut down the ID generator. - */ - public void shutdown(); - - /** - * Generate a new ID for a specific type. - * - * @param dbmap - * @return - */ - public String generateID(DbMapping dbmap) throws Exception; - -} diff --git a/src/main/java/helma/objectmodel/db/Key.java b/src/main/java/helma/objectmodel/db/Key.java deleted file mode 100644 index 7fa5271a..00000000 --- a/src/main/java/helma/objectmodel/db/Key.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - - -/** - * This is the interface for the internal representation of an object key. - * - */ -public interface Key { - - /** - * Get the key's parent key - * - * @return ... - */ - public Key getParentKey(); - - /** - * Get the key's ID part - * - * @return ... - */ - public String getID(); - - /** - * Get the key's storage type name - * - * @return ... - */ - public String getStorageName(); - -} diff --git a/src/main/java/helma/objectmodel/db/MultiKey.java b/src/main/java/helma/objectmodel/db/MultiKey.java deleted file mode 100644 index 77d36dca..00000000 --- a/src/main/java/helma/objectmodel/db/MultiKey.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.Map; - -/** - * This is the internal representation of a database key with multiple - * columns. It is constructed from the logical table (type) name and the - * column name/column value pairs that identify the key's object - * - * NOTE: This class doesn't fully support the Key interface - getID always - * returns null since there is no unique key (at least we don't know about it). - */ -public final class MultiKey implements Key, Serializable { - // the name of the prototype which defines the storage of this object. - // this is the name of the object's prototype, or one of its ancestors. - // If null, the object is stored in the embedded db. - private String storageName; - - // the id that defines this key's object within the above storage space - private Map parts; - - // lazily initialized hashcode - private transient int hashcode = 0; - - static final long serialVersionUID = -9173409137561990089L; - - - /** - * Make a key for a persistent Object, describing its datasource and key parts. - */ - public MultiKey(DbMapping dbmap, Map parts) { - this.parts = parts; - this.storageName = getStorageNameFromParts(dbmap, parts); - } - - /** - * Get the actual dbmapping prototype name out of the parts map if possible. - * This is necessary to implement references to unspecified prototype targets. - * @param dbmap the nominal/static dbmapping - * @param parts the parts map - * @return the actual dbmapping name - */ - private String getStorageNameFromParts(DbMapping dbmap, Map parts) { - if (dbmap == null) - return null; - String protoName = (String) parts.get("$prototype"); - if (protoName != null) { - DbMapping dynamap = dbmap.app.getDbMapping(protoName); - if (dynamap != null) { - return (dynamap.getStorageTypeName()); - } - } - return dbmap.getStorageTypeName(); - } - - /** - * - * - * @param what the other key to be compared with this one - * - * @return true if both keys are identical - */ - public boolean equals(Object what) { - if (what == this) { - return true; - } - - if (!(what instanceof MultiKey)) { - return false; - } - - MultiKey k = (MultiKey) what; - - // storageName is an interned string (by DbMapping, from where we got it) - // so we can compare by using == instead of the equals method. - return (storageName == k.storageName) && - ((parts == k.parts) || parts.equals(k.parts)); - } - - /** - * - * - * @return this key's hash code - */ - public int hashCode() { - if (hashcode == 0) { - hashcode = (storageName == null) ? (17 + (37 * parts.hashCode())) - : (17 + (37 * storageName.hashCode()) + - (+37 * parts.hashCode())); - } - - return hashcode; - } - - /** - * - * - * @return the key of this key's object's parent object - */ - public Key getParentKey() { - return null; - } - - /** - * - * - * @return the unique storage name for this key's object - */ - public String getStorageName() { - return storageName; - } - - /** - * - * - * @return this key's object's id - */ - public String getID() { - return null; - } - - /** - * - * - * @return a string representation for this key - */ - public String toString() { - return (storageName == null) ? ("[" + parts + "]") : (storageName + "[" + parts + "]"); - } - - // We implement write/readObject to set storageName - // to the interned version of the string. - - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.writeObject(storageName); - stream.writeObject(parts); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - storageName = (String) stream.readObject(); - parts = (Map) stream.readObject(); - // if storageName is not null, set it to the interned version - if (storageName != null) { - storageName = storageName.intern(); - } - } - -} diff --git a/src/main/java/helma/objectmodel/db/Node.java b/src/main/java/helma/objectmodel/db/Node.java deleted file mode 100644 index 2cab8f44..00000000 --- a/src/main/java/helma/objectmodel/db/Node.java +++ /dev/null @@ -1,2574 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.framework.IPathElement; -import helma.framework.core.RequestEvaluator; -import helma.framework.core.Application; -import helma.objectmodel.ConcurrencyException; -import helma.objectmodel.INode; -import helma.objectmodel.IProperty; -import helma.objectmodel.TransientNode; -import helma.util.EmptyEnumeration; - -import java.util.*; - -/** - * An implementation of INode that can be stored in the internal database or - * an external relational database. - */ -public final class Node implements INode { - - // The handle to the node's parent - protected NodeHandle parentHandle; - - // Ordered list of subnodes of this node - private SubnodeList subnodes; - - // Named subnodes (properties) of this node - private Hashtable propMap; - - protected long created; - protected long lastmodified; - private String id; - private String name; - - // is this node's main identity as a named property or an - // anonymous node in a subnode collection? - protected boolean anonymous = false; - - // the serialization version this object was read from (see readObject()) - protected short version = 0; - private String prototype; - private NodeHandle handle; - private INode cacheNode; - final WrappedNodeManager nmgr; - DbMapping dbmap; - Key primaryKey = null; - String subnodeRelation = null; - long lastNameCheck = 0; - long lastParentSet = 0; - private volatile Transactor lock; - private volatile int state; - private static long idgen = 0; - - /** - * Creates an empty, uninitialized Node with the given create and modify time. - * This is used for null-node references in the node cache. - * @param timestamp - */ - protected Node(long timestamp) { - created = lastmodified = timestamp; - this.nmgr = null; - } - - /** - * Creates an empty, uninitialized Node. The init() method must be called on the - * Node before it can do anything useful. - */ - protected Node(WrappedNodeManager nmgr) { - if (nmgr == null) { - throw new NullPointerException("nmgr"); - } - this.nmgr = nmgr; - created = lastmodified = System.currentTimeMillis(); - } - - /** - * Creates a new Node with the given name. Used by NodeManager for creating "root nodes" - * outside of a Transaction context, which is why we can immediately mark it as CLEAN. - * Also used by embedded database to re-create an existing Node. - */ - public Node(String name, String id, String prototype, WrappedNodeManager nmgr) { - if (nmgr == null) { - throw new NullPointerException("nmgr"); - } - this.nmgr = nmgr; - if (prototype == null) { - prototype = "HopObject"; - } - init(nmgr.getDbMapping(prototype), id, name, prototype, null); - } - - /** - * Constructor used to create a Node with a given name from a embedded database. - */ - public Node(String name, String id, String prototype, WrappedNodeManager nmgr, - long created, long lastmodified) { - this(name, id, prototype, nmgr); - this.created = created; - this.lastmodified = lastmodified; - } - - /** - * Constructor used for virtual nodes. - */ - public Node(Node home, String propname, WrappedNodeManager nmgr, String prototype) { - if (nmgr == null) { - throw new NullPointerException("nmgr"); - } - this.nmgr = nmgr; - setParent(home); - // generate a key for the virtual node that can't be mistaken for a Database Key - primaryKey = new SyntheticKey(home.getKey(), propname); - this.id = primaryKey.getID(); - this.name = propname; - this.prototype = prototype; - this.anonymous = false; - - // set the collection's state according to the home node's state - if (home.state == NEW || home.state == TRANSIENT) { - this.state = TRANSIENT; - } else { - this.state = VIRTUAL; - } - } - - /** - * Creates a new Node with the given name. This is used for ordinary transient nodes. - */ - public Node(String name, String prototype, WrappedNodeManager nmgr) { - if (nmgr == null) { - throw new NullPointerException("nmgr"); - } - this.nmgr = nmgr; - this.prototype = prototype; - dbmap = nmgr.getDbMapping(prototype); - - // the id is only generated when the node is actually checked into db, - // or when it's explicitly requested. - id = null; - this.name = (name == null) ? "" : name; - created = lastmodified = System.currentTimeMillis(); - state = TRANSIENT; - - if (prototype != null && dbmap != null) { - String protoProperty = dbmap.columnNameToProperty(dbmap.getPrototypeField()); - if (protoProperty != null) { - setString(protoProperty, dbmap.getExtensionId()); - } - } - } - - /** - * Initializer used for nodes being instanced from an embedded or relational database. - */ - public synchronized void init(DbMapping dbm, String id, String name, - String prototype, Hashtable propMap) { - this.dbmap = dbm; - this.prototype = prototype; - this.id = id; - this.name = name; - // If name was not set from resultset, create a synthetical name now. - if ((name == null) || (name.length() == 0)) { - this.name = prototype + " " + id; - } - - this.propMap = propMap; - - // set lastmodified and created timestamps and mark as clean - created = lastmodified = System.currentTimeMillis(); - - if (state != CLEAN) { - markAs(CLEAN); - } - } - - /** - * used by Xml deserialization - */ - public synchronized void setPropMap(Hashtable propMap) { - this.propMap = propMap; - } - - /** - * Get the write lock on this node, throwing a ConcurrencyException if the - * lock is already held by another thread. - */ - synchronized void checkWriteLock() { - if (state == TRANSIENT) { - return; // no need to lock transient node - } - - Transactor tx = Transactor.getInstanceOrFail(); - - if (!tx.isActive()) { - throw new helma.framework.TimeoutException(); - } - - if (state == INVALID) { - nmgr.logEvent("Got Invalid Node: " + this); - Thread.dumpStack(); - throw new ConcurrencyException("Node " + this + - " was invalidated by another thread."); - } - - if ((lock != null) && (lock != tx) && lock.isAlive() && lock.isActive()) { - // nmgr.logEvent("Concurrency conflict for " + this + ", lock held by " + lock); - throw new ConcurrencyException("Tried to modify " + this + - " from two threads at the same time."); - } - - tx.visitDirtyNode(this); - lock = tx; - } - - /** - * Clear the write lock on this node. - */ - synchronized void clearWriteLock() { - lock = null; - } - - /** - * Set this node's state, registering it with the transactor if necessary. - */ - void markAs(int s) { - if (s == state || state == INVALID || state == VIRTUAL || state == TRANSIENT) { - return; - } - - state = s; - - Transactor tx = Transactor.getInstance(); - if (tx != null) { - if (s == CLEAN) { - clearWriteLock(); - tx.dropDirtyNode(this); - } else { - tx.visitDirtyNode(this); - - if (s == NEW) { - clearWriteLock(); - tx.visitCleanNode(this); - } - } - } - } - - /** - * Register this node as parent node with the transactor so that - * setLastSubnodeChange is called when the transaction completes. - */ - void registerSubnodeChange() { - // we do not fetch subnodes for nodes that haven't been persisted yet or are in - // the process of being persistified - except if "manual" subnoderelation is set. - if ((state == TRANSIENT || state == NEW) && subnodeRelation == null) { - return; - } else { - Transactor tx = Transactor.getInstance(); - if (tx != null) { - tx.visitParentNode(this); - } - } - } - - /** - * Notify the node's parent that its child collection needs to be reloaded - * in case the changed property has an affect on collection order or content. - * - * @param propname the name of the property being changed - */ - void notifyPropertyChange(String propname) { - Node parent = (parentHandle == null) ? null : (Node) getParent(); - - if ((parent != null) && (parent.getDbMapping() != null)) { - // check if this node is already registered with the old name; if so, remove it. - // then set parent's property to this node for the new name value - DbMapping parentmap = parent.getDbMapping(); - Relation subrel = parentmap.getSubnodeRelation(); - String dbcolumn = dbmap.propertyToColumnName(propname); - if (subrel == null || dbcolumn == null) - return; - - if (subrel.order != null && subrel.order.indexOf(dbcolumn) > -1) { - parent.registerSubnodeChange(); - } - } - } - - /** - * Called by the transactor on registered parent nodes to mark the - * child index as changed - */ - public void markSubnodesChanged() { - if (subnodes != null) { - subnodes.markAsChanged(); - } - } - - /** - * Gets this node's stateas defined in the INode interface - * - * @return this node's state - */ - public int getState() { - return state; - } - - /** - * Sets this node's state as defined in the INode interface - * - * @param s this node's new state - */ - public void setState(int s) { - state = s; - } - - /** - * Mark node as invalid so it is re-fetched from the database - */ - public void invalidate() { - // This doesn't make sense for transient nodes - if ((state == TRANSIENT) || (state == NEW)) { - return; - } - - checkWriteLock(); - nmgr.evictNode(this); - } - - /** - * Check for a child mapping and evict the object specified by key from the cache - */ - public void invalidateNode(String key) { - // This doesn't make sense for transient nodes - if ((state == TRANSIENT) || (state == NEW)) { - return; - } - - Relation rel = getDbMapping().getSubnodeRelation(); - - if (rel != null) { - if (rel.usesPrimaryKey()) { - nmgr.evictNodeByKey(new DbKey(getDbMapping().getSubnodeMapping(), key)); - } else { - nmgr.evictNodeByKey(new SyntheticKey(getKey(), key)); - } - } - } - - /** - * Get the ID of this Node. This is the primary database key and used as part of the - * key for the internal node cache. - */ - public String getID() { - // if we are transient, we generate an id on demand. It's possible that we'll never need - // it, but if we do it's important to keep the one we have. - if (state == TRANSIENT && id == null) { - id = generateTransientID(); - } - return id; - } - - /** - * Returns true if this node is accessed by id from its aprent, false if it - * is accessed by name - */ - public boolean isAnonymous() { - return anonymous; - } - - /** - * Return this node' name, which may or may not have some meaning - */ - public String getName() { - return name; - } - - /** - * Get something to identify this node within a URL. This is the ID for anonymous nodes - * and a property value for named properties. - */ - public String getElementName() { - // check element name - this is either the Node's id or name. - long lastmod = lastmodified; - - if (dbmap != null) { - lastmod = Math.max(lastmod, dbmap.getLastTypeChange()); - } - - if ((parentHandle != null) && (lastNameCheck <= lastmod)) { - try { - Node p = parentHandle.getNode(nmgr); - DbMapping parentmap = p.getDbMapping(); - Relation prel = parentmap.getSubnodeRelation(); - - if (prel != null) { - if (prel.groupby != null) { - setName(getString("groupname")); - anonymous = false; - } else if (prel.accessName != null) { - String propname = dbmap.columnNameToProperty(prel.accessName); - String propvalue = getString(propname); - - if ((propvalue != null) && (propvalue.length() > 0)) { - setName(propvalue); - anonymous = false; - } else if (!anonymous && p.isParentOf(this)) { - anonymous = true; - } - } else if (!anonymous && p.isParentOf(this)) { - anonymous = true; - } - } else if (!anonymous && p.isParentOf(this)) { - anonymous = true; - } - } catch (Exception ignore) { - // FIXME: add proper NullPointer checks in try statement - // just fall back to default method - } - - lastNameCheck = System.currentTimeMillis(); - } - - return (anonymous || (name == null) || (name.length() == 0)) ? id : name; - } - - /** - * Get the node's path - */ - public String getPath() { - String divider = null; - StringBuffer b = new StringBuffer(); - INode p = this; - int loopWatch = 0; - - while (p != null && p.getParent() != null) { - if (divider != null) { - b.insert(0, divider); - } else { - divider = "/"; - } - - b.insert(0, p.getElementName()); - p = p.getParent(); - - loopWatch++; - - if (loopWatch > 10) { - b.insert(0, "..."); - - break; - } - } - return b.toString(); - } - - /** - * Return the node's prototype name. - */ - public String getPrototype() { - // if prototype is null, it's a vanilla HopObject. - if (prototype == null) { - return "HopObject"; - } - - return prototype; - } - - /** - * Set the node's prototype name. - */ - public void setPrototype(String proto) { - this.prototype = proto; - // Note: we mustn't set the DbMapping according to the prototype, - // because some nodes have custom dbmappings, e.g. the groupby - // dbmappings created in DbMapping.initGroupbyMapping(). - } - - /** - * Set the node's {@link DbMapping}. - */ - public void setDbMapping(DbMapping dbmap) { - this.dbmap = dbmap; - } - - /** - * Get the node's {@link DbMapping}. - */ - public DbMapping getDbMapping() { - return dbmap; - } - - /** - * Get the node's key. - */ - public Key getKey() { - if (primaryKey == null && state == TRANSIENT) { - throw new RuntimeException("getKey called on transient Node: " + this); - } - - if ((dbmap == null) && (prototype != null) && (nmgr != null)) { - dbmap = nmgr.getDbMapping(prototype); - } - - if (primaryKey == null) { - primaryKey = new DbKey(dbmap, id); - } - - return primaryKey; - } - - /** - * Get the node's handle. - */ - public NodeHandle getHandle() { - if (handle == null) { - handle = new NodeHandle(this); - } - return handle; - } - - /** - * Set an explicit select clause for the node's subnodes - */ - public synchronized void setSubnodeRelation(String rel) { - if ((rel == null && this.subnodeRelation == null) || - (rel != null && rel.equalsIgnoreCase(this.subnodeRelation))) { - return; - } - - checkWriteLock(); - this.subnodeRelation = rel; - - DbMapping smap = (dbmap == null) ? null : dbmap.getSubnodeMapping(); - - if (subnodes != null && smap != null && smap.isRelational()) { - subnodes = null; - } - } - - /** - * Get the node's explicit subnode select clause if one was set, or null - */ - public synchronized String getSubnodeRelation() { - return subnodeRelation; - } - - /** - * Set the node's name. - */ - public void setName(String name) { - if ((name == null) || (name.length() == 0)) { - // use id as name - this.name = id; - } else if (name.indexOf('/') > -1) { - // "/" is used as delimiter, so it's not a legal char - return; - } else { - this.name = name; - } - } - - /** - * Set this node's parent node. - */ - public void setParent(Node parent) { - parentHandle = (parent == null) ? null : parent.getHandle(); - } - - /** - * Set this node's parent node to the node referred to by the NodeHandle. - */ - public void setParentHandle(NodeHandle parent) { - parentHandle = parent; - } - - /** - * Get parent, retrieving it if necessary. - */ - public INode getParent() { - // check what's specified in the type.properties for this node. - ParentInfo[] parentInfo = null; - - if (isRelational() && lastParentSet <= Math.max(dbmap.getLastTypeChange(), lastmodified)) { - parentInfo = dbmap.getParentInfo(); - } - - // check if current parent candidate matches presciption, - // if not, try to get one that does. - if (nmgr.isRootNode(this)) { - parentHandle = null; - lastParentSet = System.currentTimeMillis(); - return null; - } else if (parentInfo != null) { - - Node parentFallback = null; - - for (int i = 0; i < parentInfo.length; i++) { - - ParentInfo pinfo = parentInfo[i]; - Node parentNode = null; - - // see if there is an explicit relation defined for this parent info - // we only try to fetch a node if an explicit relation is specified for the prop name - Relation rel = dbmap.propertyToRelation(pinfo.propname); - if ((rel != null) && (rel.isReference() || rel.isComplexReference())) { - parentNode = (Node) getNode(pinfo.propname); - } - - // the parent of this node is the app's root node... - if ((parentNode == null) && pinfo.isroot) { - parentNode = nmgr.getRootNode(); - } - - // if we found a parent node, check if we ought to use a virtual or groupby node as parent - if (parentNode != null) { - // see if dbmapping specifies anonymity for this node - if (pinfo.virtualname != null) { - Node pn2 = (Node) parentNode.getNode(pinfo.virtualname); - if (pn2 == null) { - getApp().logError("Error: Can't retrieve parent node " + - pinfo + " for " + this); - } else if (pinfo.collectionname != null) { - pn2 = (Node) pn2.getNode(pinfo.collectionname); - } else if (pn2.equals(this)) { - // a special case we want to support: virtualname is actually - // a reference to this node, not a collection containing this node. - parentHandle = parentNode.getHandle(); - name = pinfo.virtualname; - anonymous = false; - return parentNode; - } - - parentNode = pn2; - } - - DbMapping dbm = (parentNode == null) ? null : parentNode.getDbMapping(); - - try { - if ((dbm != null) && (dbm.getSubnodeGroupby() != null)) { - // check for groupby - rel = dbmap.columnNameToRelation(dbm.getSubnodeGroupby()); - parentNode = (Node) parentNode.getChildElement(getString(rel.propName)); - } - - // check if parent actually contains this node. If it does, - // accept it immediately, otherwise, keep it as fallback in case - // no other parent matches. See http://helma.org/bugs/show_bug.cgi?id=593 - if (parentNode != null) { - if (parentNode.isParentOf(this)) { - parentHandle = parentNode.getHandle(); - lastParentSet = System.currentTimeMillis(); - return parentNode; - } else if (parentFallback == null) { - parentFallback = parentNode; - } - } - } catch (Exception x) { - getApp().logError("Error retrieving parent node " + - pinfo + " for " + this, x); - } - } - } - lastParentSet = System.currentTimeMillis(); - // if we came till here and we didn't find a parent. - // set parent to null unless we have a fallback. - if (parentFallback != null) { - parentHandle = parentFallback.getHandle(); - return parentFallback; - } else { - parentHandle = null; - if (state != TRANSIENT) { - getApp().logEvent("*** Couldn't resolve parent for " + this + - " - please check _parent info in type.properties!"); - } - return null; - } - } - - return parentHandle == null ? null : parentHandle.getNode(nmgr); - } - - /** - * Get parent, using cached info if it exists. - */ - public Node getCachedParent() { - if (parentHandle == null) { - return null; - } - - return parentHandle.getNode(nmgr); - } - - /** - * INode-related - */ - public INode addNode(INode elem) { - return addNode(elem, -1); - } - - /** - * Add a node to this Node's subnodes, making the added node persistent if it - * hasn't been before and this Node is already persistent. - * - * @param elem the node to add to this Nodes subnode-list - * @param where the index-position where this node has to be added - * - * @return the added node itselve - */ - public INode addNode(INode elem, int where) { - Node node = null; - - if (elem instanceof Node) { - node = (Node) elem; - } else { - throw new RuntimeException("Can't add fixed-transient node to a persistent node"); - } - - // only lock nodes if parent node is not transient - if (state != TRANSIENT) { - // only lock parent if it has to be modified for a change in subnodes - if (!ignoreSubnodeChange()) { - checkWriteLock(); - } - node.checkWriteLock(); - } - - Relation subrel = dbmap == null ? null : dbmap.getSubnodeRelation(); - // if subnodes are defined via relation, make sure its constraints are enforced. - if (subrel != null && (subrel.countConstraints() < 2 || state != TRANSIENT)) { - subrel.setConstraints(this, node); - } - - // if the new node is marked as TRANSIENT and this node is not, mark new node as NEW - if (state != TRANSIENT && node.state == TRANSIENT) { - node.makePersistable(); - } - - // only mark this node as modified if subnodes are not in relational db - // pointing to this node. - if (!ignoreSubnodeChange() && (state == CLEAN || state == DELETED)) { - markAs(MODIFIED); - } - - // TODO this is a rather minimal fix for bug http://helma.org/bugs/show_bug.cgi?id=554 - // - eventually we want to get rid of this code as a whole. - if (state != TRANSIENT && (node.state == CLEAN || node.state == DELETED)) { - node.markAs(MODIFIED); - } - - loadNodes(); - - if (subrel != null && subrel.groupby != null) { - // check if this node has a group-by subnode-relation - Node groupbyNode = getGroupbySubnode(node, true); - if (groupbyNode != null) { - groupbyNode.addNode(node); - return node; - } - } - - NodeHandle nhandle = node.getHandle(); - - if (subnodes != null && subnodes.contains(nhandle)) { - // Node is already subnode of this - just move to new position - synchronized (subnodes) { - subnodes.remove(nhandle); - // check if index is out of bounds when adding - if (where < 0 || where > subnodes.size()) { - subnodes.add(nhandle); - } else { - subnodes.add(where, nhandle); - } - } - } else { - // create subnode list if necessary - if (subnodes == null) { - subnodes = createSubnodeList(); - } - - // check if subnode accessname is set. If so, check if another node - // uses the same access name, throwing an exception if so. - if (dbmap != null && node.dbmap != null) { - Relation prel = dbmap.getSubnodeRelation(); - - if (prel != null && prel.accessName != null) { - Relation localrel = node.dbmap.columnNameToRelation(prel.accessName); - - // if no relation from db column to prop name is found, - // assume that both are equal - String propname = (localrel == null) ? prel.accessName - : localrel.propName; - String prop = node.getString(propname); - - if (prop != null && prop.length() > 0) { - INode old = (INode) getChildElement(prop); - - if (old != null && old != node) { - // A node with this name already exists. This is a - // programming error, throw an exception. - throw new RuntimeException("An object named \"" + prop + - "\" is already contained in the collection."); - } - - if (state != TRANSIENT) { - Transactor tx = Transactor.getInstanceOrFail(); - SyntheticKey key = new SyntheticKey(this.getKey(), prop); - tx.visitCleanNode(key, node); - nmgr.registerNode(node, key); - } - } - } - } - - // actually add the new child to the subnode list - synchronized (subnodes) { - // check if index is out of bounds when adding - if (where < 0 || where > subnodes.size()) { - subnodes.add(nhandle); - } else { - subnodes.add(where, nhandle); - } - } - - if (node != this && !nmgr.isRootNode(node)) { - // avoid calling getParent() because it would return bogus results - // for the not-anymore transient node - Node nparent = (node.parentHandle == null) ? null - : node.parentHandle.getNode(nmgr); - - // if the node doesn't have a parent yet, or it has one but it's - // transient while we are persistent, make this the nodes new parent. - if ((nparent == null) || - ((state != TRANSIENT) && (nparent.getState() == TRANSIENT))) { - node.setParent(this); - node.anonymous = true; - } - } - } - - lastmodified = System.currentTimeMillis(); - // we want the element name to be recomputed on the child node - node.lastNameCheck = 0; - registerSubnodeChange(); - - return node; - } - - /** - * - * - * @return ... - */ - public INode createNode() { - // create new node at end of subnode array - return createNode(null, -1); - } - - /** - * - * - * @param where ... - * - * @return ... - */ - public INode createNode(int where) { - return createNode(null, where); - } - - /** - * - * - * @param nm ... - * - * @return ... - */ - public INode createNode(String nm) { - // parameter where is ignored if nm != null so we try to avoid calling numberOfNodes() - return createNode(nm, -1); - } - - /** - * - * - * @param nm ... - * @param where ... - * - * @return ... - */ - public INode createNode(String nm, int where) { - // checkWriteLock(); - - boolean anon = false; - - if ((nm == null) || "".equals(nm.trim())) { - anon = true; - } - - String proto = null; - - // try to get proper prototype for new node - if (dbmap != null) { - DbMapping childmap = anon ? - dbmap.getSubnodeMapping() : - dbmap.getPropertyMapping(nm); - if (childmap != null) { - proto = childmap.getTypeName(); - } - } - - Node n = new Node(nm, proto, nmgr); - - if (anon) { - addNode(n, where); - } else { - setNode(nm, n); - } - - return n; - } - - - /** - * This implements the getChildElement() method of the IPathElement interface - */ - public IPathElement getChildElement(String name) { - if (dbmap != null) { - // if a dbmapping is provided, check what it tells us about - // getting this specific child element - Relation rel = dbmap.getExactPropertyRelation(name); - - if (rel != null && !rel.isPrimitive()) { - return getNode(name); - } - - rel = dbmap.getSubnodeRelation(); - - if ((rel != null) && (rel.groupby != null || rel.accessName != null)) { - if (state != TRANSIENT && rel.otherType != null && rel.otherType.isRelational()) { - return nmgr.getNode(this, name, rel); - } else { - // Do what we have to do: loop through subnodes and - // check if any one matches - String propname = rel.groupby != null ? "groupname" : rel.accessName; - INode node = null; - Enumeration e = getSubnodes(); - while (e.hasMoreElements()) { - Node n = (Node) e.nextElement(); - if (name.equalsIgnoreCase(n.getString(propname))) { - node = n; - break; - } - } - // set DbMapping for embedded db group nodes - if (node != null && rel.groupby != null) { - node.setDbMapping(dbmap.getGroupbyMapping()); - } - return node; - } - } - - return getSubnode(name); - } else { - // no dbmapping - just try child collection first, then named property. - INode child = getSubnode(name); - - if (child == null) { - child = getNode(name); - } - - return child; - } - } - - /** - * This implements the getParentElement() method of the IPathElement interface - */ - public IPathElement getParentElement() { - return getParent(); - } - - /** - * Get a named child node with the given id. - */ - public INode getSubnode(String subid) { - if (subid == null || subid.length() == 0) { - return null; - } - - Node retval = null; - loadNodes(); - if (subnodes == null || subnodes.size() == 0) { - return null; - } - - NodeHandle nhandle = null; - int l = subnodes.size(); - - for (int i = 0; i < l; i++) { - try { - NodeHandle shandle = subnodes.get(i); - if (subid.equals(shandle.getID())) { - nhandle = shandle; - break; - } - } catch (Exception x) { - break; - } - } - - if (nhandle != null) { - retval = nhandle.getNode(nmgr); - } - - // This would be a better way to do it, without loading the subnodes, - // but it currently isn't supported by NodeManager. - // if (dbmap != null && dbmap.getSubnodeRelation () != null) - // retval = nmgr.getNode (this, subid, dbmap.getSubnodeRelation ()); - - if (retval != null && retval.parentHandle == null && !nmgr.isRootNode(retval)) { - retval.setParent(this); - retval.anonymous = true; - } - - return retval; - } - - /** - * Get a node at a given position. This causes the subnode list to be loaded in case - * it isn't up to date. - * @param index the subnode index - * @return the node at the given index - */ - public INode getSubnodeAt(int index) { - loadNodes(); - if (subnodes == null) { - return null; - } - return subnodes.getNode(index); - } - - /** - * Get or create a group name for a given content node. - * - * @param node the content node - * @param create whether the node should be created if it doesn't exist - * @return the group node, or null - */ - protected Node getGroupbySubnode(Node node, boolean create) { - if (node.dbmap != null && node.dbmap.isGroup()) { - return null; - } - - if (dbmap != null) { - Relation subrel = dbmap.getSubnodeRelation(); - - if (subrel != null && subrel.groupby != null) { - // use actual child mapping to resolve group property name, - // otherwise the subnode mapping defined for the collection. - DbMapping childmap = node.dbmap == null ? subrel.otherType : node.dbmap; - Relation grouprel = childmap.columnNameToRelation(subrel.groupby); - // If group name can't be resolved to a property name use the group name itself - String groupprop = (grouprel != null) ? grouprel.propName : subrel.groupby; - String groupname = node.getString(groupprop); - Node groupbyNode = (Node) getChildElement(groupname); - - // if group-by node doesn't exist, we'll create it - if (groupbyNode == null) { - groupbyNode = getGroupbySubnode(groupname, create); - // mark subnodes as changed as we have a new group node - if (create && groupbyNode != null) { - Transactor.getInstance().visitParentNode(this); - } - } else { - groupbyNode.setDbMapping(dbmap.getGroupbyMapping()); - } - - return groupbyNode; - } - } - return null; - } - - /** - * Get or create a group name for a given group name. - * - * @param groupname the group name - * @param create whether the node should be created if it doesn't exist - * @return the group node, or null - */ - protected Node getGroupbySubnode(String groupname, boolean create) { - if (groupname == null) { - throw new IllegalArgumentException("Can't create group by null"); - } - - boolean persistent = state != TRANSIENT; - - loadNodes(); - - if (subnodes == null) { - subnodes = new SubnodeList(this); - } - - if (create || subnodes.contains(new NodeHandle(new SyntheticKey(getKey(), groupname)))) { - try { - DbMapping groupbyMapping = dbmap.getGroupbyMapping(); - boolean relational = groupbyMapping.getSubnodeMapping().isRelational(); - - if (relational || create) { - Node node; - if (relational && persistent) { - node = new Node(this, groupname, nmgr, null); - } else { - node = new Node(groupname, null, nmgr); - node.setParent(this); - } - - // set "groupname" property to value of groupby field - node.setString("groupname", groupname); - // Set the dbmapping on the group node - node.setDbMapping(groupbyMapping); - node.setPrototype(groupbyMapping.getTypeName()); - - // if we're relational and persistent, make new node persistable - if (!relational && persistent) { - node.makePersistable(); - node.checkWriteLock(); - } - - // if we created a new node, check if we need to add it to subnodes - if (create) { - NodeHandle handle = node.getHandle(); - if (!subnodes.contains(handle)) - subnodes.add(handle); - } - - // If we created the group node, we register it with the - // nodemanager. Otherwise, we just evict whatever was there before - if (persistent) { - if (create) { - // register group node with transactor - Transactor tx = Transactor.getInstanceOrFail(); - tx.visitCleanNode(node); - nmgr.registerNode(node); - } else { - nmgr.evictKey(node.getKey()); - } - } - - return node; - } - } catch (Exception noluck) { - nmgr.nmgr.app.logError("Error creating group-by node for " + groupname, noluck); - } - } - - return null; - } - - /** - * - * - * @return ... - */ - public boolean remove() { - INode parent = getParent(); - if (parent != null) { - try { - parent.removeNode(this); - } catch (Exception x) { - // couldn't remove from parent. Log and continue - getApp().logError("Couldn't remove node from parent: " + x); - } - } - deepRemoveNode(); - return true; - } - - /** - * - * - * @param node ... - */ - public void removeNode(INode node) { - Node n = (Node) node; - releaseNode(n); - } - - /** - * "Locally" remove a subnode from the subnodes table. - * The logical stuff necessary for keeping data consistent is done in - * {@link #removeNode(INode)}. - */ - protected void releaseNode(Node node) { - - Node groupNode = getGroupbySubnode(node, false); - if (groupNode != null) { - groupNode.releaseNode(node); - return; - } - - INode parent = node.getParent(); - - checkWriteLock(); - node.checkWriteLock(); - - // load subnodes in case they haven't been loaded. - // this is to prevent subsequent access to reload the - // index which would potentially still contain the removed child - loadNodes(); - - if (subnodes != null) { - boolean removed = false; - synchronized (subnodes) { - removed = subnodes.remove(node.getHandle()); - } - if (dbmap != null && dbmap.isGroup() && subnodes.size() == 0) { - // clean up ourself if we're an empty group node - remove(); - } else if (removed) { - registerSubnodeChange(); - } - } - - - // check if subnodes are also accessed as properties. If so, also unset the property - if (dbmap != null && node.dbmap != null) { - Relation prel = dbmap.getSubnodeRelation(); - - if (prel != null) { - if (prel.accessName != null) { - Relation localrel = node.dbmap.columnNameToRelation(prel.accessName); - - // if no relation from db column to prop name is found, assume that both are equal - String propname = (localrel == null) ? prel.accessName : localrel.propName; - String prop = node.getString(propname); - - if (prop != null) { - if (getNode(prop) == node) { - unset(prop); - } - // let the node cache know this key's not for this node anymore. - if (state != TRANSIENT) { - nmgr.evictKey(new SyntheticKey(getKey(), prop)); - } - } - } else if (prel.groupby != null) { - String prop = node.getString("groupname"); - if (prop != null && state != TRANSIENT) { - nmgr.evictKey(new SyntheticKey(getKey(), prop)); - } - - } - // TODO: We should unset constraints to actually remove subnodes here, - // but omit it by convention and to keep backwards compatible. - // if (prel.countConstraints() > 1) { - // prel.unsetConstraints(this, node); - // } - } - } - - if (parent == this) { - // node.markAs(MODIFIED); - node.setParentHandle(null); - } - - // If subnodes are relational no need to mark this node as modified - if (ignoreSubnodeChange()) { - return; - } - - lastmodified = System.currentTimeMillis(); - - if (state == CLEAN) { - markAs(MODIFIED); - } - } - - /** - * Delete the node from the db. This mainly tries to notify all nodes referring to this that - * it's going away. For nodes from the embedded db it also does a cascading delete, since - * it can tell which nodes are actual children and which are just linked in. - */ - protected void deepRemoveNode() { - - // tell all nodes that are properties of n that they are no longer used as such - if (propMap != null) { - for (Enumeration en = propMap.elements(); en.hasMoreElements();) { - Property p = (Property) en.nextElement(); - - if ((p != null) && (p.getType() == Property.NODE)) { - Node n = (Node) p.getNodeValue(); - if (n != null && !n.isRelational() && n.getParent() == this) { - n.deepRemoveNode(); - } - } - } - } - - // cascading delete of all subnodes. This is never done for relational subnodes, because - // the parent info is not 100% accurate for them. - if (subnodes != null) { - Vector v = new Vector(); - - // remove modifies the Vector we are enumerating, so we are extra careful. - for (Enumeration en = getSubnodes(); en.hasMoreElements();) { - v.add(en.nextElement()); - } - - int m = v.size(); - - for (int i = 0; i < m; i++) { - // getParent() is heuristical/implicit for relational nodes, so we don't base - // a cascading delete on that criterium for relational nodes. - Node n = (Node) v.get(i); - - if (!n.isRelational() && n.getParent() == this) { - n.deepRemoveNode(); - } - } - } - - // mark the node as deleted and evict its primary key - setParent(null); - if (primaryKey != null || state != TRANSIENT) { - nmgr.evictKey(getKey()); - } - markAs(DELETED); - } - - /** - * Check if the given node is contained in this node's child list. - * If it is contained return its index in the list, otherwise return -1. - * - * @param n a node - * - * @return the node's index position in the child list, or -1 - */ - public int contains(INode n) { - if (n == null) { - return -1; - } - - loadNodes(); - - if (subnodes == null) { - return -1; - } - - // if the node contains relational groupby subnodes, the subnodes vector - // contains the names instead of ids. - if (!(n instanceof Node)) { - return -1; - } - - Node node = (Node) n; - - return subnodes.indexOf(node.getHandle()); - } - - /** - * Check if the given node is contained in this node's child list. This - * is similar to contains(INode) but does not load the - * child index for relational nodes. - * - * @param n a node - * @return true if the given node is contained in this node's child list - */ - public boolean isParentOf(Node n) { - if (dbmap != null) { - Relation subrel = dbmap.getSubnodeRelation(); - // if we're dealing with relational child nodes use - // Relation.checkConstraints to avoid loading the child index. - // Note that we only do that if no filter is set, since - // Relation.checkConstraints() would always return false - // if there was a filter property. - if (subrel != null && subrel.otherType != null - && subrel.otherType.isRelational() - && subrel.filter == null) { - // first check if types are stored in same table - if (!subrel.otherType.isStorageCompatible(n.getDbMapping())) { - return false; - } - // if they are, check if constraints are met - return subrel.checkConstraints(this, n); - } - } - // just fall back to contains() for non-relational nodes - return contains(n) > -1; - } - - /** - * Count the subnodes of this node. If they're stored in a relational data source, we - * may actually load their IDs in order to do this. - */ - public int numberOfNodes() { - loadNodes(); - return (subnodes == null) ? 0 : subnodes.size(); - } - - /** - * Make sure the subnode index is loaded for subnodes stored in a relational data source. - * Depending on the subnode.loadmode specified in the type.properties, we'll load just the - * ID index or the actual nodes. - */ - public void loadNodes() { - // Don't do this for transient nodes which don't have an explicit subnode relation set - if ((state == TRANSIENT || state == NEW) && subnodeRelation == null) { - return; - } - - DbMapping subMap = (dbmap == null) ? null : dbmap.getSubnodeMapping(); - - if (subMap != null && subMap.isRelational()) { - // check if subnodes need to be reloaded - synchronized (this) { - if (subnodes == null) { - createSubnodeList(); - } - subnodes.update(); - } - } - } - - /** - * Create an empty subnode list. - * @return List an empty List of the type used by this Node - */ - public SubnodeList createSubnodeList() { - Relation subrel = dbmap == null ? null : dbmap.getSubnodeRelation(); - subnodes = subrel == null || !subrel.lazyLoading ? - new SubnodeList(this) : new SegmentedSubnodeList(this); - return subnodes; - } - - /** - * Compute a serial number indicating the last change in subnode collection - * @return a serial number that increases with each subnode change - */ - long getLastSubnodeChange() { - // TODO check if we should compute this on demand - if (subnodes == null) { - createSubnodeList(); - } - return subnodes.getLastSubnodeChange(); - } - - /** - * - * - * @param startIndex ... - * @param length ... - * - * @throws Exception ... - */ - public void prefetchChildren(int startIndex, int length) { - if (startIndex < 0) { - return; - } - - loadNodes(); - - if (subnodes == null || startIndex >= subnodes.size()) { - return; - } - - subnodes.prefetch(startIndex, length); - } - - /** - * Enumerate through the subnodes of this node. - * @return an enumeration of this node's subnodes - */ - public Enumeration getSubnodes() { - loadNodes(); - return getLoadedSubnodes(); - } - - private Enumeration getLoadedSubnodes() { - final SubnodeList list = subnodes; - if (list == null) { - return new EmptyEnumeration(); - } - - return new Enumeration() { - int pos = 0; - - public boolean hasMoreElements() { - return pos < list.size(); - } - - public Object nextElement() { - // prefetch in batches of 100 - // if (pos % 100 == 0) - // list.prefetch(pos, 100); - return list.getNode(pos++); - } - }; - } - - /** - * Return this Node's subnode list - * - * @return the subnode list - */ - public SubnodeList getSubnodeList() { - return subnodes; - } - - /** - * Return true if a change in subnodes can be ignored because it is - * stored in the subnodes themselves. - */ - private boolean ignoreSubnodeChange() { - Relation rel = (dbmap == null) ? null : dbmap.getSubnodeRelation(); - - return ((rel != null) && (rel.otherType != null) && rel.otherType.isRelational()); - } - - /** - * Get all properties of this node. - */ - public Enumeration properties() { - if ((dbmap != null) && dbmap.isRelational()) { - // return the properties defined in type.properties, if there are any - return dbmap.getPropertyEnumeration(); - } - - Relation prel = (dbmap == null) ? null : dbmap.getSubnodeRelation(); - - if (state != TRANSIENT && prel != null && prel.hasAccessName() && - prel.otherType != null && prel.otherType.isRelational()) { - // return names of objects from a relational db table - return nmgr.getPropertyNames(this, prel).elements(); - } else if (propMap != null) { - // return the actually explicitly stored properties - return propMap.keys(); - } - - // sorry, no properties for this Node - return new EmptyEnumeration(); - } - - /** - * - * - * @return ... - */ - public Hashtable getPropMap() { - return propMap; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public IProperty get(String propname) { - return getProperty(propname); - } - - /** - * - * - * @return ... - */ - public String getParentInfo() { - return "anonymous:" + anonymous + ",parentHandle" + parentHandle + ",parent:" + - getParent(); - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - protected Property getProperty(String propname) { - if (propname == null) { - return null; - } - - Relation rel = dbmap == null ? - null : dbmap.getExactPropertyRelation(propname); - - // 1) check if the property is contained in the propMap - Property prop = propMap == null ? null : - (Property) propMap.get(correctPropertyName(propname)); - - if (prop != null) { - if (rel != null) { - // Is a relational node stored by id but things it's a string or int. Fix it. - if (rel.otherType != null && prop.getType() != Property.NODE) { - prop.convertToNodeReference(rel); - } - if (rel.isVirtual()) { - // property was found in propMap and is a collection - this is - // a collection holding non-relational objects. set DbMapping and - // NodeManager - Node n = (Node) prop.getNodeValue(); - if (n != null) { - // do set DbMapping for embedded db collection nodes - n.setDbMapping(rel.getVirtualMapping()); - } - } - } - return prop; - } else if (state == TRANSIENT && rel != null && rel.isVirtual()) { - // When we get a collection from a transient node for the first time, or when - // we get a collection whose content objects are stored in the embedded - // XML data storage, we just want to create and set a generic node without - // consulting the NodeManager about it. - Node n = new Node(propname, rel.getPrototype(), nmgr); - n.setDbMapping(rel.getVirtualMapping()); - n.setParent(this); - setNode(propname, n); - return (Property) propMap.get(correctPropertyName(propname)); - } - - // 2) check if this is a create-on-demand node property - if (rel != null && (rel.isVirtual() || rel.isComplexReference())) { - if (state != TRANSIENT) { - Node n = nmgr.getNode(this, propname, rel); - - if (n != null) { - if ((n.parentHandle == null) && - !nmgr.isRootNode(n)) { - n.setParent(this); - n.name = propname; - n.anonymous = false; - } - return new Property(propname, this, n); - } - } - } - - // 4) nothing to be found - return null - return null; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public String getString(String propname) { - Property prop = getProperty(propname); - - try { - return prop.getStringValue(); - } catch (Exception ignore) { - } - - return null; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public long getInteger(String propname) { - Property prop = getProperty(propname); - - try { - return prop.getIntegerValue(); - } catch (Exception ignore) { - } - - return 0; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public double getFloat(String propname) { - Property prop = getProperty(propname); - - try { - return prop.getFloatValue(); - } catch (Exception ignore) { - } - - return 0.0; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public Date getDate(String propname) { - Property prop = getProperty(propname); - - try { - return prop.getDateValue(); - } catch (Exception ignore) { - } - - return null; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public boolean getBoolean(String propname) { - Property prop = getProperty(propname); - - try { - return prop.getBooleanValue(); - } catch (Exception ignore) { - } - - return false; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public INode getNode(String propname) { - Property prop = getProperty(propname); - - try { - return prop.getNodeValue(); - } catch (Exception ignore) { - } - - return null; - } - - /** - * - * - * @param propname ... - * - * @return ... - */ - public Object getJavaObject(String propname) { - Property prop = getProperty(propname); - - try { - return prop.getJavaObjectValue(); - } catch (Exception ignore) { - } - - return null; - } - - /** - * Directly set a property on this node - * - * @param propname ... - * @param value ... - */ - protected void set(String propname, Object value, int type) { - boolean isPersistable = state != TRANSIENT && isPersistableProperty(propname); - if (isPersistable) { - checkWriteLock(); - } - - if (propMap == null) { - propMap = new Hashtable(); - } - - propname = propname.trim(); - String p2 = correctPropertyName(propname); - Property prop = (Property) propMap.get(p2); - - if (prop != null) { - prop.setValue(value, type); - } else { - prop = new Property(propname, this); - prop.setValue(value, type); - propMap.put(p2, prop); - } - - lastmodified = System.currentTimeMillis(); - - if (state == CLEAN && isPersistable) { - markAs(MODIFIED); - } - } - - /** - * - * - * @param propname ... - * @param value ... - */ - public void setString(String propname, String value) { - // nmgr.logEvent ("setting String prop"); - boolean isPersistable = state != TRANSIENT && isPersistableProperty(propname); - if (isPersistable) { - checkWriteLock(); - } - - if (propMap == null) { - propMap = new Hashtable(); - } - - propname = propname.trim(); - String p2 = correctPropertyName(propname); - Property prop = (Property) propMap.get(p2); - String oldvalue = null; - - if (prop != null) { - oldvalue = prop.getStringValue(); - - // check if the value has changed - if ((value != null) && value.equals(oldvalue)) { - return; - } - - prop.setStringValue(value); - } else { - prop = new Property(propname, this); - prop.setStringValue(value); - propMap.put(p2, prop); - } - - if (dbmap != null) { - - // check if this may have an effect on the node's parerent's child collection - // in combination with the accessname or order field. - Node parent = (parentHandle == null) ? null : (Node) getParent(); - - if ((parent != null) && (parent.getDbMapping() != null)) { - DbMapping parentmap = parent.getDbMapping(); - Relation subrel = parentmap.getSubnodeRelation(); - String dbcolumn = dbmap.propertyToColumnName(propname); - - if (subrel != null && dbcolumn != null) { - // inlined version of notifyPropertyChange(); - if (subrel.order != null && subrel.order.indexOf(dbcolumn) > -1) { - parent.registerSubnodeChange(); - } - // check if accessname has changed - if (subrel.accessName != null && - subrel.accessName.equals(dbcolumn)) { - // if any other node is contained with the new value, remove it - INode n = (INode) parent.getChildElement(value); - - if ((n != null) && (n != this)) { - throw new RuntimeException(this + - " already contains an object named " + value); - } - - // check if this node is already registered with the old name; - // if so, remove it, then add again with the new acessname - if (oldvalue != null) { - n = (INode) parent.getChildElement(oldvalue); - - if (n == this) { - parent.unset(oldvalue); - parent.addNode(this); - - // let the node cache know this key's not for this node anymore. - nmgr.evictKey(new SyntheticKey(parent.getKey(), oldvalue)); - } - } - - setName(value); - } - } - } - - // check if the property we're setting specifies the prototype of this object. - if (state != TRANSIENT && - propname.equals(dbmap.columnNameToProperty(dbmap.getPrototypeField()))) { - DbMapping newmap = nmgr.getDbMapping(value); - - if (newmap != null) { - // see if old and new prototypes have same storage - otherwise type change is ignored - String oldStorage = dbmap.getStorageTypeName(); - String newStorage = newmap.getStorageTypeName(); - - if (((oldStorage == null) && (newStorage == null)) || - ((oldStorage != null) && oldStorage.equals(newStorage))) { - // long now = System.currentTimeMillis(); - dbmap.setLastDataChange(); - newmap.setLastDataChange(); - this.dbmap = newmap; - this.prototype = value; - } - } - } - } - - lastmodified = System.currentTimeMillis(); - - if (state == CLEAN && isPersistable) { - markAs(MODIFIED); - } - } - - /** - * - * - * @param propname ... - * @param value ... - */ - public void setInteger(String propname, long value) { - // nmgr.logEvent ("setting bool prop"); - boolean isPersistable = state != TRANSIENT && isPersistableProperty(propname); - if (isPersistable) { - checkWriteLock(); - } - - if (propMap == null) { - propMap = new Hashtable(); - } - - propname = propname.trim(); - String p2 = correctPropertyName(propname); - Property prop = (Property) propMap.get(p2); - - if (prop != null) { - prop.setIntegerValue(value); - } else { - prop = new Property(propname, this); - prop.setIntegerValue(value); - propMap.put(p2, prop); - } - - notifyPropertyChange(propname); - - lastmodified = System.currentTimeMillis(); - - if (state == CLEAN && isPersistable) { - markAs(MODIFIED); - } - } - - /** - * - * - * @param propname ... - * @param value ... - */ - public void setFloat(String propname, double value) { - // nmgr.logEvent ("setting bool prop"); - boolean isPersistable = state != TRANSIENT && isPersistableProperty(propname); - if (isPersistable) { - checkWriteLock(); - } - - if (propMap == null) { - propMap = new Hashtable(); - } - - propname = propname.trim(); - String p2 = correctPropertyName(propname); - Property prop = (Property) propMap.get(p2); - - if (prop != null) { - prop.setFloatValue(value); - } else { - prop = new Property(propname, this); - prop.setFloatValue(value); - propMap.put(p2, prop); - } - - notifyPropertyChange(propname); - - lastmodified = System.currentTimeMillis(); - - if (state == CLEAN && isPersistable) { - markAs(MODIFIED); - } - } - - /** - * - * - * @param propname ... - * @param value ... - */ - public void setBoolean(String propname, boolean value) { - // nmgr.logEvent ("setting bool prop"); - boolean isPersistable = state != TRANSIENT && isPersistableProperty(propname); - if (isPersistable) { - checkWriteLock(); - } - - if (propMap == null) { - propMap = new Hashtable(); - } - - propname = propname.trim(); - String p2 = correctPropertyName(propname); - Property prop = (Property) propMap.get(p2); - - if (prop != null) { - prop.setBooleanValue(value); - } else { - prop = new Property(propname, this); - prop.setBooleanValue(value); - propMap.put(p2, prop); - } - - notifyPropertyChange(propname); - - lastmodified = System.currentTimeMillis(); - - if (state == CLEAN && isPersistable) { - markAs(MODIFIED); - } - } - - /** - * - * - * @param propname ... - * @param value ... - */ - public void setDate(String propname, Date value) { - // nmgr.logEvent ("setting date prop"); - boolean isPersistable = state != TRANSIENT && isPersistableProperty(propname); - if (isPersistable) { - checkWriteLock(); - } - - if (propMap == null) { - propMap = new Hashtable(); - } - - propname = propname.trim(); - String p2 = correctPropertyName(propname); - Property prop = (Property) propMap.get(p2); - - if (prop != null) { - prop.setDateValue(value); - } else { - prop = new Property(propname, this); - prop.setDateValue(value); - propMap.put(p2, prop); - } - - notifyPropertyChange(propname); - - lastmodified = System.currentTimeMillis(); - - if (state == CLEAN && isPersistable) { - markAs(MODIFIED); - } - } - - /** - * - * - * @param propname ... - * @param value ... - */ - public void setJavaObject(String propname, Object value) { - // nmgr.logEvent ("setting jobject prop"); - boolean isPersistable = state != TRANSIENT && isPersistableProperty(propname); - if (isPersistable) { - checkWriteLock(); - } - - if (propMap == null) { - propMap = new Hashtable(); - } - - propname = propname.trim(); - String p2 = correctPropertyName(propname); - Property prop = (Property) propMap.get(p2); - - if (prop != null) { - prop.setJavaObjectValue(value); - } else { - prop = new Property(propname, this); - prop.setJavaObjectValue(value); - propMap.put(p2, prop); - } - - notifyPropertyChange(propname); - - lastmodified = System.currentTimeMillis(); - - if (state == CLEAN && isPersistable) { - markAs(MODIFIED); - } - } - - /** - * - * - * @param propname ... - * @param value ... - */ - public void setNode(String propname, INode value) { - // nmgr.logEvent ("setting node prop"); - // check if types match, otherwise throw exception - Relation rel = (dbmap == null) ? - null : dbmap.getExactPropertyRelation(propname); - DbMapping nmap = (rel == null) ? null : rel.getPropertyMapping(); - DbMapping vmap = value.getDbMapping(); - - if ((nmap != null) && (nmap != vmap)) { - if (vmap == null) { - value.setDbMapping(nmap); - } else if (!nmap.isStorageCompatible(vmap) && !rel.isComplexReference()) { - throw new RuntimeException("Can't set " + propname + - " to object with prototype " + - value.getPrototype() + ", was expecting " + - nmap.getTypeName()); - } - } - - if (state != TRANSIENT) { - checkWriteLock(); - } - - Node n = null; - - if (value instanceof Node) { - n = (Node) value; - } else { - throw new RuntimeException("Can't add fixed-transient node to a persistent node"); - } - - boolean isPersistable = isPersistableProperty(propname); - // if the new node is marked as TRANSIENT and this node is not, mark new node as NEW - if (state != TRANSIENT && n.state == TRANSIENT && isPersistable) { - n.makePersistable(); - } - - if (state != TRANSIENT) { - n.checkWriteLock(); - } - - // check if the main identity of this node is as a named property - // or as an anonymous node in a collection - if (n != this && !nmgr.isRootNode(n) && isPersistable) { - // avoid calling getParent() because it would return bogus results - // for the not-anymore transient node - Node nparent = (n.parentHandle == null) ? null - : n.parentHandle.getNode(nmgr); - - // if the node doesn't have a parent yet, or it has one but it's - // transient while we are persistent, make this the nodes new parent. - if ((nparent == null) || - ((state != TRANSIENT) && (nparent.getState() == TRANSIENT))) { - n.setParent(this); - n.name = propname; - n.anonymous = false; - } - } - - propname = propname.trim(); - String p2 = correctPropertyName(propname); - if (rel == null && dbmap != null) { - // widen relation to non-exact (collection) mapping - rel = dbmap.getPropertyRelation(propname); - } - - if (rel != null && state != TRANSIENT && (rel.countConstraints() > 1 || rel.isComplexReference())) { - rel.setConstraints(this, n); - if (rel.isComplexReference()) { - Key key = new MultiKey(n.getDbMapping(), rel.getKeyParts(this)); - nmgr.nmgr.registerNode(n, key); - return; - } - } - - Property prop = (propMap == null) ? null : (Property) propMap.get(p2); - - if (prop != null) { - if ((prop.getType() == IProperty.NODE) && - n.getHandle().equals(prop.getNodeHandle())) { - // nothing to do, just clean up locks and return - if (state == CLEAN) { - clearWriteLock(); - } - - if (n.state == CLEAN) { - n.clearWriteLock(); - } - - return; - } - } else { - prop = new Property(propname, this); - } - - prop.setNodeValue(n); - - if ((rel == null) || - rel.isReference() || - state == TRANSIENT || - rel.otherType == null || - !rel.otherType.isRelational()) { - // the node must be stored as explicit property - if (propMap == null) { - propMap = new Hashtable(); - } - - propMap.put(p2, prop); - - if (state == CLEAN && isPersistable) { - markAs(MODIFIED); - } - } - - // don't check node in transactor cache if node is transient - - // this is done anyway when the node becomes persistent. - if (n.state != TRANSIENT) { - // check node in with transactor cache - Transactor tx = Transactor.getInstanceOrFail(); - - // tx.visitCleanNode (new DbKey (dbm, nID), n); - // UPDATE: using n.getKey() instead of manually constructing key. HW 2002/09/13 - tx.visitCleanNode(n.getKey(), n); - - // if the field is not the primary key of the property, also register it - if ((rel != null) && (rel.accessName != null) && (state != TRANSIENT)) { - Key secKey = new SyntheticKey(getKey(), propname); - nmgr.registerNode(n, secKey); - tx.visitCleanNode(secKey, n); - } - } - - lastmodified = System.currentTimeMillis(); - - if (n.state == DELETED) { - n.markAs(MODIFIED); - } - } - - private boolean isPersistableProperty(String propname) { - return propname.length() > 0 && propname.charAt(0) != '_'; - } - - /** - * Remove a property. Note that this works only for explicitly set properties, not for those - * specified via property relation. - */ - public void unset(String propname) { - - try { - // if node is relational, leave a null property so that it is - // updated in the DB. Otherwise, remove the property. - Property p = null; - boolean relational = (dbmap != null) && dbmap.isRelational(); - - if (propMap != null) { - if (relational) { - p = (Property) propMap.get(correctPropertyName(propname)); - } else { - p = (Property) propMap.remove(correctPropertyName(propname)); - } - } - - if (p != null) { - boolean isPersistable = state != TRANSIENT && isPersistableProperty(propname); - if (isPersistable) { - checkWriteLock(); - } - - if (relational) { - p.setStringValue(null); - notifyPropertyChange(propname); - } - - lastmodified = System.currentTimeMillis(); - - if (state == CLEAN && isPersistable) { - markAs(MODIFIED); - } - } else if (dbmap != null) { - // check if this is a complex constraint and we have to - // unset constraints. - Relation rel = dbmap.getExactPropertyRelation(propname); - - if (rel != null && (rel.isComplexReference())) { - p = getProperty(propname); - rel.unsetConstraints(this, p.getNodeValue()); - } - } - } catch (Exception x) { - getApp().logError("Error unsetting property", x); - } - } - - /** - * - * - * @return ... - */ - public long lastModified() { - return lastmodified; - } - - /** - * - * - * @return ... - */ - public long created() { - return created; - } - - /** - * Return a string representation for this node. This tries to call the - * javascript implemented toString() if it is defined. - * @return a string representing this node. - */ - public String toString() { - try { - // We need to reach deap into helma.framework.core to invoke toString(), - // but the functionality is really worth it. - RequestEvaluator reval = getApp().getCurrentRequestEvaluator(); - if (reval != null) { - Object str = reval.invokeDirectFunction(this, "toString", RequestEvaluator.EMPTY_ARGS); - if (str instanceof String) - return (String) str; - } - } catch (Exception x) { - // fall back to default representation - } - return "HopObject " + name; - } - - /** - * Tell whether this node is stored inside a relational db. This doesn't mean - * it actually is stored in a relational db, just that it would be, if the node was - * persistent - */ - public boolean isRelational() { - return (dbmap != null) && dbmap.isRelational(); - } - - /** - * Public method to make a node persistent. - */ - public void persist() { - if (state == TRANSIENT) { - makePersistable(); - } else if (state == CLEAN) { - markAs(MODIFIED); - } - - } - - /** - * Turn node status from TRANSIENT to NEW so that the Transactor will - * know it has to insert this node. Recursively persistifies all child nodes - * and references. This method will immediately cause the node it is called upon to - * be stored in db when the transaction is committed, so it should be called - * with care. - */ - private void makePersistable() { - // if this isn't a transient node, do nothing. - if (state != TRANSIENT) { - return; - } - - // mark as new - setState(NEW); - - // generate a real, persistent ID for this object - id = nmgr.generateID(dbmap); - getHandle().becomePersistent(); - - // register node with the transactor - Transactor tx = Transactor.getInstanceOrFail(); - tx.visitDirtyNode(this); - tx.visitCleanNode(this); - - // recursively make children persistable - makeChildrenPersistable(); - } - - /** - * Recursively turn node status from TRANSIENT to NEW on child nodes - * so that the Transactor knows they are to be persistified. This method - * can be called on TRANSIENT nodes that have just been made perstable - * using makePersistable() or converted to virtual using convertToVirtual(). - */ - private void makeChildrenPersistable() { - Relation subrel = dbmap == null ? null : dbmap.getSubnodeRelation(); - for (Enumeration e = getLoadedSubnodes(); e.hasMoreElements();) { - Node node = (Node) e.nextElement(); - - if (node.state == TRANSIENT) { - DbMapping submap = node.getDbMapping(); - if (submap != null && submap.isVirtual() && !submap.needsPersistence()) { - convertToVirtual(node); - } else { - node.makePersistable(); - if (subrel != null && subrel.countConstraints() > 1) { - subrel.setConstraints(this, node); - } - } - } - } - - // no need to make properties of virtual nodes persistable - if (state == VIRTUAL) return; - - for (Enumeration e = properties(); e.hasMoreElements();) { - String propname = (String) e.nextElement(); - IProperty next = get(propname); - - if (next == null || next.getType() != IProperty.NODE) { - continue; - } - - // check if this property actually needs to be persisted. - Node node = (Node) next.getNodeValue(); - Relation rel = null; - - if (node == null || node == this) { - continue; - } - - rel = dbmap == null ? null : dbmap.getExactPropertyRelation(next.getName()); - if (rel != null && rel.isVirtual() && !rel.needsPersistence()) { - convertToVirtual(node); - } else { - node.makePersistable(); - if (rel != null && rel.isComplexReference()) { - // if this is a complex reference, make binding properties are set - rel.setConstraints(this, node); - } - } - } - } - - /** - * Convert a node to a virtual (collection or group ) node. This is used when we - * encounter a node that is defined as virtual from within the makePeristable() and - * makeChildrenPersistable() methods. It will first mark the node as virtual and then - * call makeChildrenPersistable() on it. - * @param node a previously transient node to be converted to a virtual node. - */ - private void convertToVirtual(Node node) { - // Make node a virtual node with this as parent node. what we do is - // basically to replay the things done in the constructor for virtual nodes. - node.setState(VIRTUAL); - node.primaryKey = new SyntheticKey(getKey(), node.name); - node.id = node.name; - node.makeChildrenPersistable(); - } - - /** - * Get the cache node for this node. This can be - * used to store transient cache data per node from Javascript. - */ - public synchronized INode getCacheNode() { - if (cacheNode == null) { - cacheNode = new TransientNode(this.getApp()); - } - - return cacheNode; - } - - /** - * Reset the cache node for this node. - */ - public synchronized void clearCacheNode() { - cacheNode = null; - } - - /** - * This method walks down node path to the first non-virtual node and return it. - * limit max depth to 5, since there shouldn't be more then 2 layers of virtual nodes. - */ - public Node getNonVirtualParent() { - Node node = this; - - for (int i = 0; i < 5; i++) { - if (node == null) { - break; - } - - if (node.getState() == Node.TRANSIENT) { - DbMapping map = node.getDbMapping(); - if (map == null || !map.isVirtual()) - return node; - } else if (node.getState() != Node.VIRTUAL) { - return node; - } - - node = (Node) node.getParent(); - } - - return null; - } - - /** - * Instances of this class may be used to mark an entry in the object cache as null. - * This method tells the caller whether this is the case. - */ - public boolean isNullNode() { - return nmgr == null; - } - - String generateTransientID() { - // make transient ids differ from persistent ones - // and are unique within on runtime session - return "t" + idgen++; - } - - /** - * We overwrite hashCode to make it dependant from the prototype. That way, when the prototype - * changes, the node will automatically get a new ESNode wrapper, since they're cached in a hashtable. - * You gotta love these hash code tricks ;-) - */ - public int hashCode() { - if (prototype == null) { - return super.hashCode(); - } else { - return super.hashCode() + prototype.hashCode(); - } - } - - /** - * - */ - public void dump() { - System.err.println("subnodes: " + subnodes); - System.err.println("properties: " + propMap); - } - - /** - * Get the application this node belongs to. - * @return the app we belong to - */ - private Application getApp() { - return nmgr.nmgr.app; - } - - private String correctPropertyName(String propname) { - return getApp().correctPropertyName(propname); - } -} \ No newline at end of file diff --git a/src/main/java/helma/objectmodel/db/NodeChangeListener.java b/src/main/java/helma/objectmodel/db/NodeChangeListener.java deleted file mode 100644 index 4011a1de..00000000 --- a/src/main/java/helma/objectmodel/db/NodeChangeListener.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import java.util.List; - -public interface NodeChangeListener { - - /** - * Called when a transaction is committed that has created, modified, - * deleted or changed the child collection one or more nodes. - */ - public void nodesChanged(List inserted, List updated, List deleted, List parents); - -} diff --git a/src/main/java/helma/objectmodel/db/NodeHandle.java b/src/main/java/helma/objectmodel/db/NodeHandle.java deleted file mode 100644 index 89aaa66b..00000000 --- a/src/main/java/helma/objectmodel/db/NodeHandle.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.objectmodel.INodeState; - -import java.io.Serializable; - -/** - * This class is a handle or reference to a Node. This is to abstract from different - * methods of reference: Transient Nodes are referred to directly, while persistent - * nodes are referred to via key/node manager. - * - * A handle is used to refer to a node in a safe way over a longer period. - * While a direct reference may point to a node that has been evicted from the cache - * and reinstanciated since being set, NodeHandle will always return an up-to-date - * instance of its node. - * - * Helma tries to ensure the following rules on NodeHandles: - *
      - *
    1. For transient nodes there exists only one NodeHandle.
    2. - *
    3. If a transient node becomes persistent its node handle is notified and - * converted into a persistent NodeHandle.
    4. - *
    - * These two properties guarantee that NodeHandle comparisons are easy and usually correct. - * - */ -public final class NodeHandle implements INodeState, Serializable { - static final long serialVersionUID = 3067763116576910931L; - - // direct reference to the node - private Node node; - - // the node's key - private Key key; - - /** - * Builds a handle for a node. This constructor is package private in order to make - * sure only one NodeHandle exists per transient node. Use {@link Node#getHandle()} - * to get a Node's handle. - * @param node the node - */ - NodeHandle(Node node) { - int state = node.getState(); - - if (state == TRANSIENT) { - this.node = node; - key = null; - } else { - this.node = null; - key = node.getKey(); - } - } - - /** - * Builds a handle given a node's retrieval information. At the time this is called, - * the node is ususally not yet created. It will be fetched on demand when accessed by - * application code. - * @param key the key - */ - public NodeHandle(Key key) { - this.node = null; - this.key = key; - } - - /** - * Get the node described by this node handle - */ - public Node getNode(WrappedNodeManager nodemgr) { - if (node != null) { - return node; - } - return nodemgr.getNode(key); - } - - /** - * Check if the node is available without fetching it from the node manager - * @return true if we alreay have a reference to our node - */ - public boolean hasNode() { - return node != null; - } - - /** - * Get the key for the node described by this handle. - * This will return null for transient Nodes. - */ - public Key getKey() { - return key; - } - - /** - * Get the ID for the node described by this handle. - * This may only be called on persistent Nodes. - */ - public String getID() { - if (key == null) { - return node.getID(); - } - return key.getID(); - } - - private Object getObject() { - if (node != null) { - return node; - } else { - return key; - } - } - - /** - * - * - * @param other ... - * - * @return ... - */ - public boolean equals(Object other) { - if (other instanceof NodeHandle) { - Object obj1 = getObject(); - Object obj2 = ((NodeHandle) other).getObject(); - return obj1 == obj2 || obj1.equals(obj2); - } - return false; - } - - /** - * This is to notify the handle that the underlying node is becoming - * persistent and we have to refer to it via the key from now on. - */ - protected void becomePersistent() { - if (node != null) { - key = node.getKey(); - node = null; - } - } - - /** - * - * - * @return ... - */ - public String toString() { - if (node != null) { - return "NodeHandle[transient:" + node + "]"; - } else { - return "NodeHandle[" + key + "]"; - } - } -} diff --git a/src/main/java/helma/objectmodel/db/NodeManager.java b/src/main/java/helma/objectmodel/db/NodeManager.java deleted file mode 100644 index 83187981..00000000 --- a/src/main/java/helma/objectmodel/db/NodeManager.java +++ /dev/null @@ -1,1890 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.framework.core.Application; -import helma.framework.core.RequestEvaluator; -import helma.objectmodel.*; -import helma.objectmodel.dom.XmlDatabase; - -import java.io.*; -import java.math.BigDecimal; -import java.sql.*; -import java.util.*; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * The NodeManager is responsible for fetching Nodes from the internal or - * external data sources, caching them in a least-recently-used Hashtable, - * and writing changes back to the databases. - */ -public final class NodeManager { - - protected Application app; - private ObjectCache cache; - protected IDatabase db; - protected IDGenerator idgen; - private boolean logSql; - private Log sqlLog = null; - private ArrayList listeners = new ArrayList(); - - // a wrapper that catches some Exceptions while accessing this NM - public final WrappedNodeManager safe; - - /** - * Create a new NodeManager for Application app. - */ - public NodeManager(Application app) { - this.app = app; - safe = new WrappedNodeManager(this); - } - - /** - * Initialize the NodeManager for the given dbHome and - * application properties. An embedded database will be - * created in dbHome if one doesn't already exist. - */ - public void init(File dbHome, Properties props) - throws DatabaseException, ClassNotFoundException, - IllegalAccessException, InstantiationException { - String cacheImpl = props.getProperty("cacheimpl", "helma.util.CacheMap"); - - cache = (ObjectCache) Class.forName(cacheImpl).newInstance(); - cache.init(app); - - String idgenImpl = props.getProperty("idGeneratorImpl"); - - if (idgenImpl != null) { - idgen = (IDGenerator) Class.forName(idgenImpl).newInstance(); - idgen.init(app); - } - - logSql = "true".equalsIgnoreCase(props.getProperty("logsql")); - - db = new XmlDatabase(); - db.init(dbHome, app); - } - - /** - * Gets the application's root node. - */ - public Node getRootNode() throws Exception { - DbMapping rootMapping = app.getRootMapping(); - DbKey key = new DbKey(rootMapping, app.getRootId()); - Node node = getNode(key); - if (node != null && rootMapping != null) { - node.setDbMapping(rootMapping); - node.setPrototype(rootMapping.getTypeName()); - } - return node; - } - /** - * Checks if the given node is the application's root node. - */ - public boolean isRootNode(Node node) { - return node.getState() != Node.TRANSIENT && app.getRootId().equals(node.getID()) && - DbMapping.areStorageCompatible(app.getRootMapping(), node.getDbMapping()); - } - - /** - * app.properties file has been updated. Reread some settings. - */ - public void updateProperties(Properties props) { - // notify the cache about the properties update - cache.updateProperties(props); - logSql = "true".equalsIgnoreCase(props.getProperty("logsql")); - } - - /** - * Shut down this node manager. This is called when the application - * using this node manager is stopped. - */ - public void shutdown() throws DatabaseException { - db.shutdown(); - - if (cache != null) { - cache.shutdown(); - cache = null; - } - - if (idgen != null) { - idgen.shutdown(); - } - } - - /** - * Delete a node from the database. - */ - public void deleteNode(Node node) throws Exception { - if (node != null) { - synchronized (this) { - Transactor tx = Transactor.getInstanceOrFail(); - - node.setState(Node.INVALID); - deleteNode(db, tx.txn, node); - } - } - } - - /** - * Get a node by key. This is called from a node that already holds - * a reference to another node via a NodeHandle/Key. - */ - public Node getNode(Key key) throws Exception { - Transactor tx = Transactor.getInstanceOrFail(); - - // See if Transactor has already come across this node - Node node = tx.getCleanNode(key); - - if ((node != null) && (node.getState() != Node.INVALID)) { - return node; - } - - // try to get the node from the shared cache - node = (Node) cache.get(key); - - if ((node == null) || (node.getState() == Node.INVALID)) { - // The requested node isn't in the shared cache. - if (key instanceof SyntheticKey) { - Node parent = getNode(key.getParentKey()); - Relation rel = parent.dbmap.getPropertyRelation(key.getID()); - - if (rel != null) { - return getNode(parent, key.getID(), rel); - } else { - return null; - } - } else if (key instanceof DbKey) { - node = getNodeByKey(tx.txn, (DbKey) key); - } - - if (node != null) { - node = registerNewNode(node, null); - } - } - - if (node != null) { - tx.visitCleanNode(key, node); - } - - return node; - } - - /** - * Get a node by relation, using the home node, the relation and a key to apply. - * In contrast to getNode (Key key), this is usually called when we don't yet know - * whether such a node exists. - */ - public Node getNode(Node home, String kstr, Relation rel) - throws Exception { - if (kstr == null) { - return null; - } - - Transactor tx = Transactor.getInstanceOrFail(); - - Key key; - DbMapping otherDbm = rel == null ? null : rel.otherType; - // check what kind of object we're looking for and make an appropriate key - if (rel.isComplexReference()) { - // a key for a complex reference - key = new MultiKey(rel.otherType, rel.getKeyParts(home)); - otherDbm = app.getDbMapping(key.getStorageName()); - } else if (rel.createOnDemand()) { - // a key for a virtually defined object that's never actually stored in the db - // or a key for an object that represents subobjects grouped by some property, - // generated on the fly - key = new SyntheticKey(home.getKey(), kstr); - } else { - // Not a relation we can use getNodeByRelation() for. - return null; - } - - // See if Transactor has already come across this node - Node node = tx.getCleanNode(key); - - if (node != null && node.getState() != Node.INVALID) { - // we used to refresh the node in the main cache here to avoid the primary key - // entry being flushed from cache before the secondary one - // (risking duplicate nodes in cache) but we don't need to since we fetched - // the node from the threadlocal transactor cache and didn't refresh it in the - // main cache. - return node; - } - - // try to get the node from the shared cache - node = (Node) cache.get(key); - - // check if we can use the cached node without further checks. - // we need further checks for subnodes fetched by name if the subnodes were changed. - if (node != null && node.getState() != Node.INVALID) { - // check if node is null node (cached null) - if (node.isNullNode()) { - // do not check reference nodes against child collection - if (rel.isComplexReference() || node.created != home.getLastSubnodeChange()) { - node = null; // cached null not valid anymore - } - } else if (!rel.virtual) { - // apply different consistency checks for groupby nodes and database nodes: - // for group nodes, check if they're contained - if (rel.groupby != null) { - if (home.contains(node) < 0) { - node = null; - } - - // for database nodes, check if constraints are fulfilled - } else if (!rel.usesPrimaryKey()) { - if (!rel.checkConstraints(home, node)) { - node = null; - } - } - } - } - - if (node == null || node.getState() == Node.INVALID) { - // The requested node isn't in the shared cache. - // Synchronize with key to make sure only one version is fetched - // from the database. - node = getNodeByRelation(tx.txn, home, kstr, rel, otherDbm); - - if (node != null && node.getState() != Node.DELETED) { - Node newNode = node; - if (key.equals(node.getKey())) { - node = registerNewNode(node, null); - } else { - node = registerNewNode(node, key); - } - // reset create time of old node, otherwise Relation.checkConstraints - // will reject it under certain circumstances. - if (node != newNode) { - node.created = node.lastmodified; - } - } else { - // node fetched from db is null, cache result using nullNode - synchronized (cache) { - // do not use child collection timestamp as cache guard for object references - long lastchange = rel.isComplexReference() ? 0 : home.getLastSubnodeChange(); - cache.put(key, new Node(lastchange)); - - // we ignore the case that onother thread has created the node in the meantime - return null; - } - } - } else if (node.isNullNode()) { - // the nullNode caches a null value, i.e. an object that doesn't exist - return null; - } else { - // update primary key in cache to keep it from being flushed, see above - if (!rel.usesPrimaryKey() && node.getState() != Node.TRANSIENT) { - synchronized (cache) { - Node old = (Node) cache.put(node.getKey(), node); - - if (old != node && old != null && !old.isNullNode() && - old.getState() != Node.INVALID) { - cache.put(node.getKey(), old); - cache.put(key, old); - node = old; - } - } - } - } - - if (node != null) { - tx.visitCleanNode(key, node); - } - - return node; - } - - /** - * Register a newly created node in the node cache unless it it is already contained. - * If so, the previously registered node is kept and returned. Otherwise, the onInit() - * function is called on the new node and it is returned. - * @param node the node to register - * @return the newly registered node, or the one that was already registered with the node's key - */ - private Node registerNewNode(Node node, Key secondaryKey) { - Key key = node.getKey(); - RequestEvaluator reval = app.getCurrentRequestEvaluator(); - // if no request evaluator is associated with current thread, do not cache node - // as we cannot invoke onInit() on it. - if (reval == null) { - Node old = (Node) cache.get(key); - if (old != null && !old.isNullNode() && old.getState() != INode.INVALID) { - return old; - } - return node; - } - - synchronized(cache) { - Node old = (Node) cache.put(key, node); - - if (old != null && !old.isNullNode() && old.getState() != INode.INVALID) { - cache.put(key, old); - if (secondaryKey != null) { - cache.put(secondaryKey, old); - } - return old; - } else if (secondaryKey != null) { - cache.put(secondaryKey, node); - } - } - // New node is going ot be used, invoke onInit() on it - // Invoke onInit() if it is defined by this Node's prototype - try { - // We need to reach deap into helma.framework.core to invoke onInit(), - // but the functionality is really worth it. - reval.invokeDirectFunction(node, "onInit", RequestEvaluator.EMPTY_ARGS); - } catch (Exception x) { - app.logError("Error invoking onInit()", x); - } - return node; - } - - /** - * Register a node in the node cache. - */ - public void registerNode(Node node) { - cache.put(node.getKey(), node); - } - - /** - * Register a node in the node cache using the key argument. - */ - protected void registerNode(Node node, Key key) { - cache.put(key, node); - } - - /** - * Remove a node from the node cache. If at a later time it is accessed again, - * it will be refetched from the database. - */ - public void evictNode(Node node) { - node.setState(INode.INVALID); - cache.remove(node.getKey()); - } - - /** - * Remove a node from the node cache. If at a later time it is accessed again, - * it will be refetched from the database. - */ - public void evictNodeByKey(Key key) { - Node n = (Node) cache.remove(key); - - if (n != null) { - n.setState(INode.INVALID); - - if (!(key instanceof DbKey)) { - cache.remove(n.getKey()); - } - } - } - - /** - * Used when a key stops being valid for a node. The cached node itself - * remains valid, if it is present in the cache by other keys. - */ - public void evictKey(Key key) { - cache.remove(key); - // also drop key from thread-local transactor cache - Transactor tx = Transactor.getInstance(); - if (tx != null) { - tx.dropCleanNode(key); - } - } - - //////////////////////////////////////////////////////////////////////// - // methods to do the actual db work - //////////////////////////////////////////////////////////////////////// - - /** - * Insert a new node in the embedded database or a relational database table, - * depending on its db mapping. - */ - public void insertNode(IDatabase db, ITransaction txn, Node node) - throws IOException, SQLException, ClassNotFoundException { - invokeOnPersist(node); - DbMapping dbm = node.getDbMapping(); - - if ((dbm == null) || !dbm.isRelational()) { - db.insertNode(txn, node.getID(), node); - } else { - insertRelationalNode(node, dbm, dbm.getConnection()); - } - } - - /** - * Insert a node into a different (relational) database than its default one. - */ - public void exportNode(Node node, DbSource dbs) - throws SQLException, ClassNotFoundException { - if (node == null) { - throw new IllegalArgumentException("Node can't be null in exportNode"); - } - - DbMapping dbm = node.getDbMapping(); - - if (dbs == null) { - throw new IllegalArgumentException("DbSource can't be null in exportNode"); - } else if ((dbm == null) || !dbm.isRelational()) { - throw new IllegalArgumentException("Can't export into non-relational database"); - } else { - insertRelationalNode(node, dbm, dbs.getConnection()); - } - } - - /** - * Insert a node into a different (relational) database than its default one. - */ - public void exportNode(Node node, DbMapping dbm) - throws SQLException, ClassNotFoundException { - if (node == null) { - throw new IllegalArgumentException("Node can't be null in exportNode"); - } - - if (dbm == null) { - throw new IllegalArgumentException("DbMapping can't be null in exportNode"); - } else if (!dbm.isRelational()) { - throw new IllegalArgumentException("Can't export into non-relational database"); - } else { - insertRelationalNode(node, dbm, dbm.getConnection()); - } - } - - /** - * Insert a node into a relational database. - */ - protected void insertRelationalNode(Node node, DbMapping dbm, Connection con) - throws ClassNotFoundException, SQLException { - - if (con == null) { - throw new NullPointerException("Error inserting relational node: Connection is null"); - } - - // set connection to write mode - if (con.isReadOnly()) con.setReadOnly(false); - - String insertString = dbm.getInsert(); - PreparedStatement stmt = con.prepareStatement(insertString); - - // app.logEvent ("inserting relational node: " + node.getID ()); - DbColumn[] columns = dbm.getColumns(); - - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - - try { - int columnNumber = 1; - - for (int i = 0; i < columns.length; i++) { - DbColumn col = columns[i]; - if (!col.isMapped()) - continue; - if (col.isIdField()) { - setStatementValue(stmt, columnNumber, node.getID(), col); - } else if (col.isPrototypeField()) { - setStatementValue(stmt, columnNumber, dbm.getExtensionId(), col); - } else { - Relation rel = col.getRelation(); - Property p = rel == null ? null : node.getProperty(rel.getPropName()); - - if (p != null) { - setStatementValue(stmt, columnNumber, p, col.getType()); - } else if (col.isNameField()) { - stmt.setString(columnNumber, node.getName()); - } else { - stmt.setNull(columnNumber, col.getType()); - } - } - columnNumber += 1; - } - stmt.executeUpdate(); - - } finally { - if (logSql) { - long logTimeStop = java.lang.System.currentTimeMillis(); - logSqlStatement("SQL INSERT", dbm.getTableName(), - logTimeStart, logTimeStop, insertString); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) {} - } - } - } - - /** - * calls onPersist function for the HopObject - */ - private void invokeOnPersist(Node node) { - try { - // We need to reach deap into helma.framework.core to invoke onPersist(), - // but the functionality is really worth it. - RequestEvaluator reval = app.getCurrentRequestEvaluator(); - if (reval != null) { - reval.invokeDirectFunction(node, "onPersist", RequestEvaluator.EMPTY_ARGS); - } - } catch (Exception x) { - app.logError("Error invoking onPersist()", x); - } - } - - /** - * Updates a modified node in the embedded db or an external relational database, depending - * on its database mapping. - * - * @return true if the DbMapping of the updated Node is to be marked as updated via - * DbMapping.setLastDataChange - */ - public boolean updateNode(IDatabase db, ITransaction txn, Node node) - throws IOException, SQLException, ClassNotFoundException { - - invokeOnPersist(node); - DbMapping dbm = node.getDbMapping(); - boolean markMappingAsUpdated = false; - - if ((dbm == null) || !dbm.isRelational()) { - db.updateNode(txn, node.getID(), node); - } else { - Hashtable propMap = node.getPropMap(); - Property[] props; - - if (propMap == null) { - props = new Property[0]; - } else { - props = new Property[propMap.size()]; - propMap.values().toArray(props); - } - - // make sure table meta info is loaded by dbmapping - dbm.getColumns(); - - StringBuffer b = dbm.getUpdate(); - - // comma flag set after the first dirty column, also tells as - // if there are dirty columns at all - boolean comma = false; - - for (int i = 0; i < props.length; i++) { - // skip clean properties - if ((props[i] == null) || !props[i].dirty) { - // null out clean property so we don't consider it later - props[i] = null; - continue; - } - - Relation rel = dbm.propertyToRelation(props[i].getName()); - - // skip readonly, virtual and collection relations - if ((rel == null) || rel.readonly || rel.virtual || - (!rel.isPrimitiveOrReference())) { - // null out property so we don't consider it later - props[i] = null; - continue; - } - - if (comma) { - b.append(", "); - } else { - comma = true; - } - - b.append(rel.getDbField()); - b.append(" = ?"); - } - - // if no columns were updated, return false - if (!comma) { - return false; - } - - b.append(" WHERE "); - dbm.appendCondition(b, dbm.getIDField(), node.getID()); - - Connection con = dbm.getConnection(); - // set connection to write mode - if (con.isReadOnly()) con.setReadOnly(false); - PreparedStatement stmt = con.prepareStatement(b.toString()); - - int stmtNumber = 0; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - - try { - for (int i = 0; i < props.length; i++) { - Property p = props[i]; - - if (p == null) { - continue; - } - - Relation rel = dbm.propertyToRelation(p.getName()); - - stmtNumber++; - setStatementValue(stmt, stmtNumber, p, rel.getColumnType()); - - p.dirty = false; - - if (!rel.isPrivate()) { - markMappingAsUpdated = true; - } - } - - stmt.executeUpdate(); - - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL UPDATE", dbm.getTableName(), - logTimeStart, logTimeStop, b.toString()); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - } - } - } - } - - // update may cause changes in the node's parent subnode array - // TODO: is this really needed anymore? - if (markMappingAsUpdated && node.isAnonymous()) { - Node parent = node.getCachedParent(); - - if (parent != null) { - parent.markSubnodesChanged(); - } - } - - return markMappingAsUpdated; - } - - /** - * Performs the actual deletion of a node from either the embedded or an external - * SQL database. - */ - public void deleteNode(IDatabase db, ITransaction txn, Node node) - throws Exception { - DbMapping dbm = node.getDbMapping(); - - if ((dbm == null) || !dbm.isRelational()) { - db.deleteNode(txn, node.getID()); - } else { - Statement st = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - String str = new StringBuffer("DELETE FROM ").append(dbm.getTableName()) - .append(" WHERE ") - .append(dbm.getIDField()) - .append(" = ") - .append(node.getID()) - .toString(); - - try { - Connection con = dbm.getConnection(); - // set connection to write mode - if (con.isReadOnly()) con.setReadOnly(false); - - st = con.createStatement(); - - st.executeUpdate(str); - - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL DELETE", dbm.getTableName(), - logTimeStart, logTimeStop, str); - } - if (st != null) { - try { - st.close(); - } catch (Exception ignore) { - } - } - } - } - - // node may still be cached via non-primary keys. mark as invalid - node.setState(Node.INVALID); - } - - - /** - * Generate a new ID for a given type, delegating to our IDGenerator if set. - */ - public String generateID(DbMapping map) throws Exception { - if (idgen != null) { - // use our custom IDGenerator - return idgen.generateID(map); - } else { - return doGenerateID(map); - } - } - - /** - * Actually generates an ID, using a method matching the given DbMapping. - */ - public String doGenerateID(DbMapping map) throws Exception { - if ((map == null) || !map.isRelational()) { - // use embedded db id generator - return generateEmbeddedID(map); - } - String idMethod = map.getIDgen(); - if (idMethod == null || "[max]".equalsIgnoreCase(idMethod) || map.isMySQL()) { - // use select max as id generator - return generateMaxID(map); - } else if ("[hop]".equalsIgnoreCase(idMethod)) { - // use embedded db id generator - return generateEmbeddedID(map); - } else { - // use db sequence as id generator - return generateSequenceID(map); - } - } - - /** - * Gererates an ID for use with the embedded database. - */ - synchronized String generateEmbeddedID(DbMapping map) throws Exception { - return db.nextID(); - } - - /** - * Generates an ID for the table by finding out the maximum current value - */ - synchronized String generateMaxID(DbMapping map) - throws Exception { - String retval = null; - Statement stmt = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - String q = new StringBuffer("SELECT MAX(").append(map.getIDField()) - .append(") FROM ") - .append(map.getTableName()) - .toString(); - - try { - Connection con = map.getConnection(); - // set connection to read-only mode - if (!con.isReadOnly()) con.setReadOnly(true); - - stmt = con.createStatement(); - - ResultSet rs = stmt.executeQuery(q); - - // check for empty table - if (!rs.next()) { - long currMax = map.getNewID(0); - - retval = Long.toString(currMax); - } else { - long currMax = rs.getLong(1); - - currMax = map.getNewID(currMax); - retval = Long.toString(currMax); - } - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL SELECT_MAX", map.getTableName(), - logTimeStart, logTimeStop, q); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - } - } - } - - return retval; - } - - String generateSequenceID(DbMapping map) throws Exception { - Statement stmt = null; - String retval = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - String q; - if (map.isOracle()) { - q = new StringBuffer("SELECT ").append(map.getIDgen()) - .append(".nextval FROM dual").toString(); - } else if (map.isPostgreSQL() || map.isH2()) { - q = new StringBuffer("SELECT nextval('") - .append(map.getIDgen()).append("')").toString(); - } else { - throw new RuntimeException("Unable to generate sequence: unknown DB"); - } - - try { - Connection con = map.getConnection(); - // TODO is it necessary to set connection to write mode here? - if (con.isReadOnly()) con.setReadOnly(false); - - stmt = con.createStatement(); - - ResultSet rs = stmt.executeQuery(q); - - if (!rs.next()) { - throw new SQLException("Error creating ID from Sequence: empty recordset"); - } - - retval = rs.getString(1); - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL SELECT_NEXTVAL", map.getTableName(), - logTimeStart, logTimeStop, q); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - } - } - } - - return retval; - } - - /** - * Loades subnodes via subnode relation. Only the ID index is loaded, the nodes are - * loaded later on demand. - */ - public List getNodeIDs(Node home, Relation rel) throws Exception { - DbMapping type = rel == null ? null : rel.otherType; - if (type == null || !type.isRelational()) { - // this should never be called for embedded nodes - throw new RuntimeException("getNodeIDs called for non-relational node " + home); - } - List retval = new ArrayList(); - - // if we do a groupby query (creating an intermediate layer of groupby nodes), - // retrieve the value of that field instead of the primary key - Connection con = type.getConnection(); - // set connection to read-only mode - if (!con.isReadOnly()) con.setReadOnly(true); - - Statement stmt = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - String query = null; - - try { - StringBuffer b = rel.getIdSelect(); - - if (home.getSubnodeRelation() != null) { - // subnode relation was explicitly set - query = b.append(" ").append(home.getSubnodeRelation()).toString(); - } else { - // let relation object build the query - rel.buildQuery(b, home, true, false); - query = b.toString(); - } - - stmt = con.createStatement(); - - if (rel.maxSize > 0) { - stmt.setMaxRows(rel.maxSize); - } - - ResultSet result = stmt.executeQuery(query); - - // problem: how do we derive a SyntheticKey from a not-yet-persistent Node? - Key k = (rel.groupby != null) ? home.getKey() : null; - - while (result.next()) { - String kstr = result.getString(1); - - // jump over null values - this can happen especially when the selected - // column is a group-by column. - if (kstr == null) { - continue; - } - - // make the proper key for the object, either a generic DB key or a groupby key - Key key = (rel.groupby == null) - ? (Key) new DbKey(rel.otherType, kstr) - : (Key) new SyntheticKey(k, kstr); - retval.add(new NodeHandle(key)); - - // if these are groupby nodes, evict nullNode keys - if (rel.groupby != null) { - Node n = (Node) cache.get(key); - - if ((n != null) && n.isNullNode()) { - evictKey(key); - } - } - } - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL SELECT_IDS", type.getTableName(), - logTimeStart, logTimeStop, query); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - } - } - } - - return retval; - } - - /** - * Loades subnodes via subnode relation. This is similar to getNodeIDs, but it - * actually loades all nodes in one go, which is better for small node collections. - * This method is used when xxx.loadmode=aggressive is specified. - */ - public List getNodes(Node home, Relation rel) throws Exception { - // This does not apply for groupby nodes - use getNodeIDs instead - assert rel.groupby == null; - - if ((rel == null) || (rel.otherType == null) || !rel.otherType.isRelational()) { - // this should never be called for embedded nodes - throw new RuntimeException("getNodes called for non-relational node " + - home); - } - - List retval = new ArrayList(); - DbMapping dbm = rel.otherType; - - Connection con = dbm.getConnection(); - // set connection to read-only mode - if (!con.isReadOnly()) con.setReadOnly(true); - - Statement stmt = con.createStatement(); - DbColumn[] columns = dbm.getColumns(); - Relation[] joins = dbm.getJoins(); - String query = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - - try { - StringBuffer b = dbm.getSelect(rel); - - if (home.getSubnodeRelation() != null) { - b.append(home.getSubnodeRelation()); - } else { - // let relation object build the query - rel.buildQuery(b, home, true, false); - } - - query = b.toString(); - - if (rel.maxSize > 0) { - stmt.setMaxRows(rel.maxSize); - } - - ResultSet rs = stmt.executeQuery(query); - - while (rs.next()) { - // create new Nodes. - Node node = createNode(rel.otherType, rs, columns, 0); - if (node == null) { - continue; - } - Key primKey = node.getKey(); - - retval.add(new NodeHandle(primKey)); - - registerNewNode(node, null); - - fetchJoinedNodes(rs, joins, columns.length); - } - - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL SELECT_ALL", dbm.getTableName(), - logTimeStart, logTimeStop, query); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - } - } - } - - return retval; - } - - protected List collectMissingKeys(SubnodeList list, int start, int length) { - List retval = null; - for (int i = start; i < start + length; i++) { - NodeHandle handle = list.get(i); - if (handle != null && !cache.containsKey(handle.getKey())) { - if (retval == null) { - retval = new ArrayList(); - } - retval.add(handle.getKey().getID()); - } - } - return retval; - } - - /** - * - */ - public void prefetchNodes(Node home, Relation rel, SubnodeList list, int start, int length) - throws Exception { - DbMapping dbm = rel.otherType; - - // this does nothing for objects in the embedded database - if (dbm != null && dbm.isRelational()) { - // int missing = cache.containsKeys(keys); - List missing = collectMissingKeys(list, start, length); - - if (missing != null) { - Connection con = dbm.getConnection(); - // set connection to read-only mode - if (!con.isReadOnly()) con.setReadOnly(true); - - Statement stmt = con.createStatement(); - DbColumn[] columns = dbm.getColumns(); - Relation[] joins = dbm.getJoins(); - String query = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - - try { - StringBuffer b = dbm.getSelect(null).append(" WHERE "); - String idfield = (rel.groupby != null) ? rel.groupby : dbm.getIDField(); - String[] ids = (String[]) missing.toArray(new String[missing.size()]); - - dbm.appendCondition(b, idfield, ids); - dbm.addJoinConstraints(b, " AND "); - - if (rel.groupby != null) { - rel.renderConstraints(b, home, " AND "); - - if (rel.order != null) { - b.append(" ORDER BY "); - b.append(rel.order); - } - } - - query = b.toString(); - - ResultSet rs = stmt.executeQuery(query); - - String groupbyProp = null; - HashMap groupbySubnodes = null; - - if (rel.groupby != null) { - groupbyProp = dbm.columnNameToProperty(rel.groupby); - groupbySubnodes = new HashMap(); - } - - String accessProp = null; - - if ((rel.accessName != null) && !rel.usesPrimaryKey()) { - accessProp = dbm.columnNameToProperty(rel.accessName); - } - - while (rs.next()) { - // create new Nodes. - Node node = createNode(dbm, rs, columns, 0); - if (node == null) { - continue; - } - Key key = node.getKey(); - Key secondaryKey = null; - - // for grouped nodes, collect subnode lists for the intermediary - // group nodes. - String groupName = null; - - if (groupbyProp != null) { - groupName = node.getString(groupbyProp); - if (groupName != null) { - Node groupNode = (Node) groupbySubnodes.get(groupName); - - if (groupNode == null) { - groupNode = home.getGroupbySubnode(groupName, true); - groupbySubnodes.put(groupName, groupNode); - } - - SubnodeList subnodes = groupNode.getSubnodeList(); - if (subnodes == null) { - subnodes = groupNode.createSubnodeList(); - // mark subnodes as up-to-date - subnodes.lastSubnodeFetch = subnodes.getLastSubnodeChange(); - } - subnodes.add(new NodeHandle(key)); - } - } - - // if relation doesn't use primary key as accessName, get secondary key - if (accessProp != null) { - String accessName = node.getString(accessProp); - if (accessName != null) { - if (groupName == null) { - secondaryKey = new SyntheticKey(home.getKey(), accessName); - } else { - Key groupKey = new SyntheticKey(home.getKey(), groupName); - secondaryKey = new SyntheticKey(groupKey, accessName); - } - } - - } - - // register new nodes with the cache. If an up-to-date copy - // existed in the cache, use that. - registerNewNode(node, secondaryKey); - fetchJoinedNodes(rs, joins, columns.length); - } - - } catch (Exception x) { - app.logError("Error in prefetchNodes()", x); - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL SELECT_PREFETCH", dbm.getTableName(), - logTimeStart, logTimeStop, query); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - } - } - } - } - } - } - - /** - * Count the nodes contained in the child collection of the home node - * which is defined by Relation rel. - */ - public int countNodes(Node home, Relation rel) throws Exception { - DbMapping type = rel == null ? null : rel.otherType; - if (type == null || !type.isRelational()) { - // this should never be called for embedded nodes - throw new RuntimeException("countNodes called for non-relational node " + home); - } - int retval = 0; - Connection con = type.getConnection(); - // set connection to read-only mode - if (!con.isReadOnly()) con.setReadOnly(true); - - Statement stmt = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - String query = null; - - try { - StringBuffer b = rel.getCountSelect(); - - if (home.getSubnodeRelation() != null) { - // use the manually set subnoderelation of the home node - query = b.append(" ").append(home.getSubnodeRelation()).toString(); - } else { - // let relation object build the query - rel.buildQuery(b, home, false, true); - query = b.toString(); - } - - stmt = con.createStatement(); - ResultSet rs = stmt.executeQuery(query); - - if (!rs.next()) { - retval = 0; - } else { - retval = rs.getInt(1); - } - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL SELECT_COUNT", type.getTableName(), - logTimeStart, logTimeStop, query); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - } - } - } - - return (rel.maxSize > 0) ? Math.min(rel.maxSize, retval) : retval; - } - - /** - * Similar to getNodeIDs, but returns a List that contains the nodes property names instead of IDs - */ - public Vector getPropertyNames(Node home, Relation rel) - throws Exception { - DbMapping type = rel == null ? null : rel.otherType; - if (type == null || !type.isRelational()) { - // this should never be called for embedded nodes - throw new RuntimeException("getPropertyNames called for non-relational node " + home); - } - Vector retval = new Vector(); - - Connection con = rel.otherType.getConnection(); - // set connection to read-only mode - if (!con.isReadOnly()) con.setReadOnly(true); - - Statement stmt = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - String query = null; - - try { - // NOTE: we explicitly convert tables StringBuffer to a String - // before appending to be compatible with JDK 1.3 - StringBuffer b = rel.getNamesSelect(); - - if (home.getSubnodeRelation() != null) { - b.append(" ").append(home.getSubnodeRelation()); - } else { - // let relation object build the query - rel.buildQuery(b, home, true, false); - } - - stmt = con.createStatement(); - - query = b.toString(); - - ResultSet rs = stmt.executeQuery(query); - - while (rs.next()) { - String n = rs.getString(1); - - if (n != null) { - retval.add(n); - } - } - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL SELECT_ACCESSNAMES", type.getTableName(), - logTimeStart, logTimeStop, query); - } - - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - } - } - } - - return retval; - } - - /////////////////////////////////////////////////////////////////////////////////////// - // private getNode methods - /////////////////////////////////////////////////////////////////////////////////////// - private Node getNodeByKey(ITransaction txn, DbKey key) - throws Exception { - // Note: Key must be a DbKey, otherwise will not work for relational objects - Node node = null; - DbMapping dbm = app.getDbMapping(key.getStorageName()); - String kstr = key.getID(); - - if ((dbm == null) || !dbm.isRelational()) { - node = (Node) db.getNode(txn, kstr); - if ((node != null) && (dbm != null)) { - node.setDbMapping(dbm); - } - } else { - String idfield = dbm.getIDField(); - - Statement stmt = null; - String query = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - - try { - Connection con = dbm.getConnection(); - // set connection to read-only mode - if (!con.isReadOnly()) con.setReadOnly(true); - - stmt = con.createStatement(); - - DbColumn[] columns = dbm.getColumns(); - Relation[] joins = dbm.getJoins(); - - StringBuffer b = dbm.getSelect(null).append("WHERE "); - dbm.appendCondition(b, idfield, kstr); - dbm.addJoinConstraints(b, " AND "); - query = b.toString(); - - ResultSet rs = stmt.executeQuery(query); - - if (!rs.next()) { - return null; - } - node = createNode(dbm, rs, columns, 0); - - fetchJoinedNodes(rs, joins, columns.length); - - if (rs.next()) { - app.logError("Warning: More than one value returned for query " + query); - } - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL SELECT_BYKEY", dbm.getTableName(), - logTimeStart, logTimeStop, query); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - // ignore - } - } - } - } - - return node; - } - - private Node getNodeByRelation(ITransaction txn, Node home, String kstr, Relation rel, DbMapping dbm) - throws Exception { - Node node = null; - - if (rel != null && rel.virtual) { - if (rel.needsPersistence()) { - node = (Node) home.createNode(kstr); - } else { - node = new Node(home, kstr, safe, rel.prototype); - } - - // set prototype and dbmapping on the newly created virtual/collection node - node.setPrototype(rel.prototype); - node.setDbMapping(rel.getVirtualMapping()); - } else if (rel != null && rel.groupby != null) { - node = home.getGroupbySubnode(kstr, false); - - if (node == null && (dbm == null || !dbm.isRelational())) { - node = (Node) db.getNode(txn, kstr); - } - return node; - } else if (rel == null || dbm == null || !dbm.isRelational()) { - node = (Node) db.getNode(txn, kstr); - node.setDbMapping(dbm); - return node; - } else { - Statement stmt = null; - String query = null; - long logTimeStart = logSql ? System.currentTimeMillis() : 0; - - try { - Connection con = dbm.getConnection(); - // set connection to read-only mode - if (!con.isReadOnly()) con.setReadOnly(true); - DbColumn[] columns = dbm.getColumns(); - Relation[] joins = dbm.getJoins(); - StringBuffer b = dbm.getSelect(rel); - - if (home.getSubnodeRelation() != null && !rel.isComplexReference()) { - // combine our key with the constraints in the manually set subnode relation - b.append(" WHERE "); - dbm.appendCondition(b, rel.accessName, kstr); - // add join contraints in case this is an old oracle style join - dbm.addJoinConstraints(b, " AND "); - // add potential constraints from manually set subnodeRelation - String subrel = home.getSubnodeRelation().trim(); - if (subrel.length() > 5) { - b.append(" AND ("); - b.append(subrel.substring(5).trim()); - b.append(")"); - } - } else { - rel.buildQuery(b, home, dbm, kstr, false, false); - } - - stmt = con.createStatement(); - - query = b.toString(); - - ResultSet rs = stmt.executeQuery(query); - - if (!rs.next()) { - return null; - } - - node = createNode(dbm, rs, columns, 0); - - fetchJoinedNodes(rs, joins, columns.length); - - if (rs.next()) { - app.logError("Warning: More than one value returned for query " + query); - } - - } finally { - if (logSql) { - long logTimeStop = System.currentTimeMillis(); - logSqlStatement("SQL SELECT_BYRELATION", dbm.getTableName(), - logTimeStart, logTimeStop, query); - } - if (stmt != null) { - try { - stmt.close(); - } catch (Exception ignore) { - // ignore - } - } - } - } - - return node; - } - - /** - * Create a new Node from a ResultSet. - */ - public Node createNode(DbMapping dbm, ResultSet rs, DbColumn[] columns, int offset) - throws SQLException, IOException, ClassNotFoundException { - HashMap propBuffer = new HashMap(); - String id = null; - String name = null; - String protoName = dbm.getTypeName(); - DbMapping dbmap = dbm; - - Node node = new Node(safe); - - for (int i = 0; i < columns.length; i++) { - - int columnNumber = i + 1 + offset; - - // set prototype? - if (columns[i].isPrototypeField()) { - String protoId = rs.getString(columnNumber); - protoName = dbm.getPrototypeName(protoId); - - if (protoName != null) { - dbmap = getDbMapping(protoName); - - if (dbmap == null) { - // invalid prototype name! - app.logError("No prototype defined for prototype mapping \"" - + protoName + "\" - Using default prototype \"" - + dbm.getTypeName() + "\"."); - dbmap = dbm; - protoName = dbmap.getTypeName(); - } - } - } - - // set id? - if (columns[i].isIdField()) { - id = rs.getString(columnNumber); - // if id == null, the object doesn't actually exist - return null - if (id == null) { - return null; - } - } - - // set name? - if (columns[i].isNameField()) { - name = rs.getString(columnNumber); - } - - Property newprop = new Property(node); - - switch (columns[i].getType()) { - case Types.BIT: - case Types.BOOLEAN: - newprop.setBooleanValue(rs.getBoolean(columnNumber)); - - break; - - case Types.TINYINT: - case Types.BIGINT: - case Types.SMALLINT: - case Types.INTEGER: - newprop.setIntegerValue(rs.getLong(columnNumber)); - - break; - - case Types.REAL: - case Types.FLOAT: - case Types.DOUBLE: - newprop.setFloatValue(rs.getDouble(columnNumber)); - - break; - - case Types.DECIMAL: - case Types.NUMERIC: - - BigDecimal num = rs.getBigDecimal(columnNumber); - if (num == null) { - break; - } - if (num.scale() > 0) { - newprop.setFloatValue(num.doubleValue()); - } else { - newprop.setIntegerValue(num.longValue()); - } - - break; - - case Types.VARBINARY: - case Types.BINARY: - newprop.setJavaObjectValue(rs.getBytes(columnNumber)); - - break; - - case Types.BLOB: - case Types.LONGVARBINARY: - { - InputStream in = rs.getBinaryStream(columnNumber); - if (in == null) { - break; - } - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - byte[] buffer = new byte[2048]; - int read; - while ((read = in.read(buffer)) > -1) { - bout.write(buffer, 0, read); - } - newprop.setJavaObjectValue(bout.toByteArray()); - } - - break; - - case Types.LONGVARCHAR: - try { - newprop.setStringValue(rs.getString(columnNumber)); - } catch (SQLException x) { - Reader in = rs.getCharacterStream(columnNumber); - if (in == null) { - newprop.setStringValue(null); - break; - } - StringBuffer out = new StringBuffer(); - char[] buffer = new char[2048]; - int read; - while ((read = in.read(buffer)) > -1) { - out.append(buffer, 0, read); - } - newprop.setStringValue(out.toString()); - } - - break; - - case Types.CHAR: - case Types.VARCHAR: - case Types.OTHER: - newprop.setStringValue(rs.getString(columnNumber)); - - break; - - case Types.DATE: - case Types.TIME: - case Types.TIMESTAMP: - newprop.setDateValue(rs.getTimestamp(columnNumber)); - - break; - - case Types.NULL: - newprop.setStringValue(null); - - break; - - case Types.CLOB: - Clob cl = rs.getClob(columnNumber); - if (cl == null) { - newprop.setStringValue(null); - break; - } - char[] c = new char[(int) cl.length()]; - Reader isr = cl.getCharacterStream(); - isr.read(c); - newprop.setStringValue(String.copyValueOf(c)); - break; - - default: - newprop.setStringValue(rs.getString(columnNumber)); - - break; - } - - if (rs.wasNull()) { - newprop.setStringValue(null); - } - - propBuffer.put(columns[i].getName(), newprop); - - // mark property as clean, since it's fresh from the db - newprop.dirty = false; - } - - if (id == null) { - return null; - } else { - Transactor tx = Transactor.getInstance(); - if (tx != null) { - // Check if the node is already registered with the transactor - - // it may be in the process of being DELETED, but do return the - // new node if the old one has been marked as INVALID. - DbKey key = new DbKey(dbmap, id); - Node dirtyNode = tx.getDirtyNode(key); - if (dirtyNode != null && dirtyNode.getState() != Node.INVALID) { - return dirtyNode; - } - } - } - - Hashtable propMap = new Hashtable(); - DbColumn[] columns2 = dbmap.getColumns(); - for (int i=0; i 0; - } - - /** - * Called by transactors after committing. - */ - protected void fireNodeChangeEvent(List inserted, List updated, List deleted, List parents) { - int l = listeners.size(); - - for (int i=0; i -1 ? desc.substring(0, n) : desc; - - String[] parts = StringUtils.split(desc, "."); - - propname = parts.length > 0 ? parts[0].trim() : null; - virtualname = parts.length > 1 ? parts[1].trim() : null; - collectionname = parts.length > 2 ? parts[2].trim() : null; - - isroot = "root".equalsIgnoreCase(propname); - } - - /** - * @return a string representation of the parent info - */ - public String toString() { - StringBuffer b = new StringBuffer("ParentInfo[").append(propname); - if (virtualname != null) - b.append(".").append(virtualname); - if (collectionname != null) - b.append(".").append(collectionname); - return b.append("]").toString(); - } -} diff --git a/src/main/java/helma/objectmodel/db/Property.java b/src/main/java/helma/objectmodel/db/Property.java deleted file mode 100644 index 9bcf326b..00000000 --- a/src/main/java/helma/objectmodel/db/Property.java +++ /dev/null @@ -1,547 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.objectmodel.INode; -import helma.objectmodel.IProperty; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.sql.Timestamp; -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * A property implementation for Nodes stored inside a database. Basically - * the same as for transient nodes, with a few hooks added. - */ -public final class Property implements IProperty, Serializable, Cloneable, Comparable { - static final long serialVersionUID = -1022221688349192379L; - private String propname; - private Node node; - private Object value; - private int type; - transient boolean dirty; - - /** - * Creates a new Property object. - * - * @param node ... - */ - public Property(Node node) { - this.node = node; - dirty = true; - } - - /** - * Creates a new Property object. - * - * @param propname ... - * @param node ... - */ - public Property(String propname, Node node) { - this.propname = propname; - this.node = node; - dirty = true; - } - - /** - * Creates a new Property object. - * - * @param propname ... - * @param node ... - * @param valueNode ... - */ - public Property(String propname, Node node, Node valueNode) { - this(propname, node); - type = NODE; - value = (valueNode == null) ? null : valueNode.getHandle(); - dirty = true; - } - - private void readObject(ObjectInputStream in) throws IOException { - try { - propname = in.readUTF(); - node = (Node) in.readObject(); - type = in.readInt(); - - switch (type) { - case STRING: - value = in.readObject(); - - break; - - case BOOLEAN: - value = in.readBoolean() ? Boolean.TRUE : Boolean.FALSE; - - break; - - case INTEGER: - value = Long.valueOf(in.readLong()); - - break; - - case DATE: - value = new Date(in.readLong()); - - break; - - case FLOAT: - value = Double.valueOf(in.readDouble()); - - break; - - case NODE: - value = in.readObject(); - - break; - - case JAVAOBJECT: - value = in.readObject(); - - break; - } - } catch (ClassNotFoundException x) { - throw new IOException(x.toString()); - } - } - - private void writeObject(ObjectOutputStream out) throws IOException { - out.writeUTF(propname); - out.writeObject(node); - out.writeInt(type); - - switch (type) { - case STRING: - out.writeObject(value); - - break; - - case BOOLEAN: - out.writeBoolean(((Boolean) value).booleanValue()); - - break; - - case INTEGER: - out.writeLong(((Long) value).longValue()); - - break; - - case DATE: - out.writeLong(((Date) value).getTime()); - - break; - - case FLOAT: - out.writeDouble(((Double) value).doubleValue()); - - break; - - case NODE: - out.writeObject(value); - - break; - - case JAVAOBJECT: - - if ((value != null) && !(value instanceof Serializable)) { - out.writeObject(null); - } else { - out.writeObject(value); - } - - break; - } - } - - /** - * Get the name of the property - * - * @return this property's name - */ - public String getName() { - return propname; - } - - /** - * Set the name of the property - */ - protected void setName(String name) { - this.propname = name; - } - - /** - * - * - * @return the property's value in its native class - */ - public Object getValue() { - return value; - } - - /** - * - * - * @return the property's type as defined in helma.objectmodel.IProperty.java - */ - public int getType() { - return type; - } - - /** - * Directly set the value of this property. - */ - protected void setValue(Object value, int type) { - this.value = value; - this.type = type; - dirty = true; - } - - /** - * - * - * @param str ... - */ - public void setStringValue(String str) { - type = STRING; - value = str; - dirty = true; - } - - /** - * - * - * @param l ... - */ - public void setIntegerValue(long l) { - type = INTEGER; - value = Long.valueOf(l); - dirty = true; - } - - /** - * - * - * @param d ... - */ - public void setFloatValue(double d) { - type = FLOAT; - value = Double.valueOf(d); - dirty = true; - } - - /** - * - * - * @param date ... - */ - public void setDateValue(Date date) { - type = DATE; - // normalize from java.sql.* Date subclasses - if (date != null && date.getClass() != Date.class) { - value = new Date(date.getTime()); - } else { - value = date; - } - dirty = true; - } - - /** - * - * - * @param bool ... - */ - public void setBooleanValue(boolean bool) { - type = BOOLEAN; - value = bool ? Boolean.TRUE : Boolean.FALSE; - dirty = true; - } - - /** - * - * - * @param node ... - */ - public void setNodeValue(Node node) { - type = NODE; - value = (node == null) ? null : node.getHandle(); - dirty = true; - } - - /** - * - * - * @param handle ... - */ - public void setNodeHandle(NodeHandle handle) { - type = NODE; - value = handle; - dirty = true; - } - - /** - * - * - * @return ... - */ - public NodeHandle getNodeHandle() { - if (type == NODE) { - return (NodeHandle) value; - } - - return null; - } - - /** - * - * - * @param rel the Relation - */ - public void convertToNodeReference(Relation rel) { - if ((value != null) && !(value instanceof NodeHandle)) { - if (rel.usesPrimaryKey()) { - value = new NodeHandle(new DbKey(rel.otherType, value.toString())); - } else { - value = new NodeHandle(new MultiKey(rel.otherType, rel.getKeyParts(node))); - } - } - - type = NODE; - } - - /** - * - * - * @param obj ... - */ - public void setJavaObjectValue(Object obj) { - type = JAVAOBJECT; - value = obj; - dirty = true; - } - - - /** - * - * - * @return ... - */ - public String getStringValue() { - if (value == null) { - return null; - } - - switch (type) { - case STRING: - case BOOLEAN: - case INTEGER: - case FLOAT: - case JAVAOBJECT: - return value.toString(); - - case DATE: - - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - return format.format((Date) value); - - case NODE: - return ((NodeHandle) value).getID(); - } - - return ""; - } - - /** - * - * - * @return ... - */ - public String toString() { - return getStringValue(); - } - - /** - * - * - * @return ... - */ - public long getIntegerValue() { - if (type == INTEGER) { - return ((Long) value).longValue(); - } - - if (type == FLOAT) { - return ((Double) value).longValue(); - } - - if (type == BOOLEAN) { - return ((Boolean) value).booleanValue() ? 1 : 0; - } - - try { - return Long.parseLong(getStringValue()); - } catch (Exception x) { - return 0; - } - } - - /** - * - * - * @return ... - */ - public double getFloatValue() { - if (type == FLOAT) { - return ((Double) value).doubleValue(); - } - - if (type == INTEGER) { - return ((Long) value).doubleValue(); - } - - try { - return Double.parseDouble(getStringValue()); - } catch (Exception x) { - return 0.0; - } - } - - /** - * - * - * @return ... - */ - public Date getDateValue() { - if (type == DATE) { - return (Date) value; - } - - return null; - } - - /** - * - * - * @return ... - */ - public Timestamp getTimestampValue() { - if ((type == DATE) && (value != null)) { - return new Timestamp(((Date) value).getTime()); - } - - return null; - } - - /** - * - * - * @return ... - */ - public boolean getBooleanValue() { - if (type == BOOLEAN) { - return ((Boolean) value).booleanValue(); - } - - return 0 != getIntegerValue(); - } - - /** - * - * - * @return ... - */ - public INode getNodeValue() { - if ((type == NODE) && (value != null)) { - NodeHandle nhandle = (NodeHandle) value; - - return nhandle.getNode(node.nmgr); - } - - return null; - } - - /** - * - * - * @return ... - */ - public Object getJavaObjectValue() { - if (type == JAVAOBJECT) { - return value; - } - - return null; - } - - /** - * @see java.lang.Comparable#compareTo(java.lang.Object) - * - * The following cases throw a ClassCastException - * - Properties of a different type - * - Properties of boolean or node type - */ - public int compareTo(Object obj) { - Property p = (Property) obj; - int ptype = p.getType(); - Object pvalue = p.getValue(); - - if (type==NODE || ptype==NODE || - type == BOOLEAN || ptype == BOOLEAN) { - throw new ClassCastException("uncomparable values " + this + "(" + type + ") : " + p + "(" + ptype + ")"); - } - if (value==null && pvalue == null) { - return 0; - } else if (value == null) { - return 1; - } if (pvalue == null) { - return -1; - } - if (type != ptype) { - // float/integer sometimes get mixed up in Rhino - if ((type == FLOAT && ptype == INTEGER) || (type == INTEGER && ptype == FLOAT)) - return Double.compare(((Number) value).doubleValue(), ((Number) pvalue).doubleValue()); - throw new ClassCastException("uncomparable values " + this + "(" + type + ") : " + p + "(" + ptype + ")"); - - } - if (!(value instanceof Comparable)) { - throw new ClassCastException("uncomparable value " + value + "(" + value.getClass() + ")"); - } - // System.err.println("COMPARING: " + value.getClass() + " TO " + pvalue.getClass()); - return ((Comparable) value).compareTo(pvalue); - } - - /** - * Return true if object o is equal to this property. - * - * @param obj the object to compare to - * @return true if this equals obj - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null) - return false; - if (!(obj instanceof Property)) - return false; - Property p = (Property) obj; - return value == null ? p.value == null : value.equals(p.value); - } -} diff --git a/src/main/java/helma/objectmodel/db/Relation.java b/src/main/java/helma/objectmodel/db/Relation.java deleted file mode 100644 index 38fbe278..00000000 --- a/src/main/java/helma/objectmodel/db/Relation.java +++ /dev/null @@ -1,1552 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.framework.core.Application; -import helma.objectmodel.INode; -import helma.objectmodel.IProperty; -import helma.util.StringUtils; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.Enumeration; -import java.util.Vector; - -/** - * This describes how a property of a persistent Object is stored in a - * relational database table. This can be either a scalar property (string, date, number etc.) - * or a reference to one or more other objects. - */ -public final class Relation { - // these constants define different type of property-to-db-mappings - // there is an error in the description of this relation - public final static int INVALID = -1; - - // a mapping of a non-object, scalar type - public final static int PRIMITIVE = 0; - - // a 1-to-1 relation, i.e. a field in the table is a foreign key to another object - public final static int REFERENCE = 1; - - // a 1-to-many relation, a field in another table points to objects of this type - public final static int COLLECTION = 2; - - // a 1-to-1 reference with multiple or otherwise not-trivial constraints - // this is managed differently than REFERENCE, hence the separate type. - public final static int COMPLEX_REFERENCE = 3; - - // constraints linked together by OR or AND if applicable? - public final static String AND = " AND "; - public final static String OR = " OR "; - public final static String XOR = " XOR "; - private String logicalOperator = AND; - - // prefix to use for symbolic names of joined tables. The name is composed - // from this prefix and the name of the property we're doing the join for - final static String JOIN_PREFIX = "JOIN_"; - - // direct mapping is a very powerful feature: - // objects of some types can be directly accessed - // by one of their properties/db fields. - // public final static int DIRECT = 3; - // the DbMapping of the type we come from - DbMapping ownType; - - // the DbMapping of the prototype we link to, unless this is a "primitive" (non-object) relation - DbMapping otherType; - - // the column type, as defined in java.sql.Types - int columnType; - - // if this relation defines a virtual node, we need to provide a DbMapping for these virtual nodes - DbMapping virtualMapping; - String propName; - String columnName; - int reftype; - Constraint[] constraints; - boolean virtual; - boolean readonly; - boolean lazyLoading; - boolean aggressiveLoading; - boolean aggressiveCaching; - boolean isPrivate = false; - boolean referencesPrimaryKey = false; - String updateCriteria; - String accessName; // db column used to access objects through this relation - String order; - boolean autoSorted = false; - String groupbyOrder; - String groupby; - String prototype; - String groupbyPrototype; - String filter; - private String additionalTables; - private boolean additionalTablesJoined = false; - String queryHints; - Vector filterFragments; - Vector filterPropertyRefs; - int maxSize = 0; - int offset = 0; - - /** - * This constructor makes a copy of an existing relation. Not all fields are copied, just those - * which are needed in groupby- and virtual nodes defined by this relation. use - * {@link Relation#getClone()} to get a full copy of this relation. - */ - protected Relation(Relation rel) { - // Note: prototype, groupby, groupbyPrototype and groupbyOrder aren't copied here. - // these are set by the individual get*Relation() methods as appropriate. - this.ownType = rel.ownType; - this.otherType = rel.otherType; - this.propName = rel.propName; - this.columnName = rel.columnName; - this.reftype = rel.reftype; - this.order = rel.order; - this.filter = rel.filter; - this.filterFragments = rel.filterFragments; - this.filterPropertyRefs = rel.filterPropertyRefs; - this.additionalTables = rel.additionalTables; - this.additionalTablesJoined = rel.additionalTablesJoined; - this.queryHints = rel.queryHints; - this.maxSize = rel.maxSize; - this.offset = rel.offset; - this.constraints = rel.constraints; - this.accessName = rel.accessName; - this.logicalOperator = rel.logicalOperator; - this.lazyLoading = rel.lazyLoading; - this.aggressiveLoading = rel.aggressiveLoading; - this.aggressiveCaching = rel.aggressiveCaching; - this.updateCriteria = rel.updateCriteria; - this.autoSorted = rel.autoSorted; - } - - /** - * Reads a relation entry from a line in a properties file. - */ - public Relation(String propName, DbMapping ownType) { - this.ownType = ownType; - this.propName = propName; - otherType = null; - } - - /** - * Update this relation object from a properties object. - * @param desc the top level relation descriptor. For relations - * defined in a type.properties file, this is a string like - * "collection(Type)", but for relations defined from - * JavaScript, it is the top level descriptor object. - * @param props The subproperties for this relation. - */ - public void update(Object desc, Properties props) { - Application app = ownType.getApplication(); - - if (desc instanceof Properties || parseDescriptor(desc, props)) { - // converted to internal foo.collection = Bar representation - String proto; - if (props.containsKey("collection")) { - proto = props.getProperty("collection"); - virtual = !"_children".equalsIgnoreCase(propName); - reftype = COLLECTION; - } else if (props.containsKey("mountpoint")) { - proto = props.getProperty("mountpoint"); - reftype = COLLECTION; - virtual = true; - this.prototype = proto; - } else if (props.containsKey("object")) { - proto = props.getProperty("object"); - if (reftype != COMPLEX_REFERENCE) { - reftype = REFERENCE; - } - virtual = false; - } else { - throw new RuntimeException("Invalid property Mapping: " + desc); - } - - otherType = app.getDbMapping(proto); - - if (otherType == null) { - throw new RuntimeException("DbMapping for " + proto + - " not found from " + ownType.getTypeName()); - } - - // make sure the type we're referring to is up to date! - if (otherType.needsUpdate()) { - otherType.update(); - } - - } - - readonly = "true".equalsIgnoreCase(props.getProperty("readonly")); - isPrivate = "true".equalsIgnoreCase(props.getProperty("private")); - - // the following options only apply to object and collection relations - if ((reftype != PRIMITIVE) && (reftype != INVALID)) { - Vector newConstraints = new Vector(); - - parseOptions(newConstraints, props); - - constraints = new Constraint[newConstraints.size()]; - newConstraints.copyInto(constraints); - - - if (reftype == REFERENCE || reftype == COMPLEX_REFERENCE) { - if (constraints.length == 0) { - referencesPrimaryKey = true; - } else { - boolean rprim = false; - for (int i=0; i 1 || !usesPrimaryKey()) { - reftype = COMPLEX_REFERENCE; - } else { - reftype = REFERENCE; - } - } - - if (reftype == COLLECTION) { - referencesPrimaryKey = (accessName == null) || - accessName.equalsIgnoreCase(otherType.getIDField()); - } - - // if DbMapping for virtual nodes has already been created, - // update its subnode relation. - // FIXME: needs to be synchronized? - if (virtualMapping != null) { - virtualMapping.lastTypeChange = ownType.lastTypeChange; - virtualMapping.subRelation = getVirtualSubnodeRelation(); - virtualMapping.propRelation = getVirtualPropertyRelation(); - } - } else { - referencesPrimaryKey = false; - } - } - - /** - * Converts old style foo = collection(Bar) mapping to new style - * foo.collection = Bar mappinng and returns true if a non-primitive mapping - * was encountered. - * @param value the value of the top level property mapping - * @param config the sub-map for this property mapping - * @return true if the value describes a valid, non-primitive property mapping - */ - protected boolean parseDescriptor(Object value, Map config) { - String desc = value instanceof String ? (String) value : null; - - if (desc == null || "".equals(desc.trim())) { - if (propName != null) { - reftype = PRIMITIVE; - columnName = propName; - } else { - reftype = INVALID; - columnName = propName; - } - return false; - } else { - desc = desc.trim(); - - int open = desc.indexOf("("); - int close = desc.indexOf(")", open); - - if (open > -1 && close > open) { - String ref = desc.substring(0, open).trim(); - String proto = desc.substring(open + 1, close).trim(); - - if ("collection".equalsIgnoreCase(ref)) { - config.put("collection", proto); - } else if ("mountpoint".equalsIgnoreCase(ref)) { - config.put("mountpoint", proto); - } else if ("object".equalsIgnoreCase(ref)) { - config.put("object", proto); - } else { - throw new RuntimeException("Invalid property Mapping: " + desc); - } - - return true; - - } else { - virtual = false; - columnName = desc; - reftype = PRIMITIVE; - return false; - } - } - - } - - protected void parseOptions(Vector cnst, Properties props) { - String loading = props.getProperty("loadmode"); - - if (loading != null) { - loading = loading.trim(); - if ("aggressive".equalsIgnoreCase(loading)) { - aggressiveLoading = true; - lazyLoading = false; - } else if ("lazy".equalsIgnoreCase(loading)) { - lazyLoading = true; - aggressiveLoading = false; - } else { - System.err.println("Unsupported loadmode property in " + ownType + ": " + loading); - aggressiveLoading = lazyLoading = false; - } - } else { - aggressiveLoading = lazyLoading = false; - } - - String caching = props.getProperty("cachemode"); - - aggressiveCaching = (caching != null) && - "aggressive".equalsIgnoreCase(caching.trim()); - - // get order property - order = props.getProperty("order"); - - if ((order != null) && (order.trim().length() == 0)) { - order = null; - } - - // get the criteria(s) for updating this collection - updateCriteria = props.getProperty("updatecriteria"); - - // get the autosorting flag - autoSorted = "auto".equalsIgnoreCase(props.getProperty("sortmode")); - - // get additional filter property - filter = props.getProperty("filter"); - - if (filter != null) { - if (filter.trim().length() == 0) { - filter = null; - filterFragments = filterPropertyRefs = null; - } else { - // parenthesise filter - Vector fragments = new Vector(); - Vector propertyRefs = new Vector(); - parsePropertyString(filter, fragments, propertyRefs); - // if no references where found, just use the filter string - // otherwise use the filter fragments and proeprty refs instead - if (propertyRefs.size() > 0) { - filterFragments = fragments; - filterPropertyRefs = propertyRefs; - } else { - filterFragments = filterPropertyRefs = null; - } - } - } - - // get additional tables - additionalTables = props.getProperty("filter.additionalTables"); - - if (additionalTables != null) { - if (additionalTables.trim().length() == 0) { - additionalTables = null; - } else { - String ucTables = additionalTables.toUpperCase(); - // create dependencies implied by additional tables - DbSource dbsource = otherType.getDbSource(); - if (dbsource != null) { - String[] tables = StringUtils.split(ucTables, ", "); - for (int i=0; i 1) { - String logic = props.getProperty("logicalOperator"); - if ("and".equalsIgnoreCase(logic)) { - logicalOperator = AND; - } else if ("or".equalsIgnoreCase(logic)) { - logicalOperator = OR; - } else if ("xor".equalsIgnoreCase(logic)) { - logicalOperator = XOR; - } else { - logicalOperator = AND; - } - } else { - logicalOperator = AND; - } - - } - - private int getIntegerProperty(String name, Properties props, int defaultValue) { - Object value = props.get(name); - if (value instanceof Number) { - return ((Number) value).intValue(); - } else if (value instanceof String) { - try { - return Integer.parseInt((String) value); - } catch (NumberFormatException nfx) { - ownType.getApplication().logError("Can't parse integer for property " - + name + " from value " + value, nfx); - } - } - return defaultValue; - } - - /////////////////////////////////////////////////////////////////////////////////////////// - - /** - * Get the configuration properties for this relation. - */ - public Map getConfig() { - return ownType.getSubProperties(propName + '.'); - } - - /** - * Does this relation describe a virtual (collection) node? - */ - public boolean isVirtual() { - return virtual; - } - - /** - * Return the target type of this relation, or null if this is a primitive mapping. - */ - public DbMapping getTargetType() { - return otherType; - } - - /** - * Get the reference type of this relation. - */ - public int getRefType() { - return reftype; - } - - /** - * Tell if this relation represents a primitive (scalar) value mapping. - */ - public boolean isPrimitive() { - return reftype == PRIMITIVE; - } - - /** - * Returns true if this Relation describes an object reference property - */ - public boolean isReference() { - return reftype == REFERENCE; - } - - /** - * Returns true if this Relation describes either a primitive value - * or an object reference. - */ - public boolean isPrimitiveOrReference() { - return reftype == PRIMITIVE || reftype == REFERENCE; - } - - /** - * Returns true if this Relation describes a collection. - * NOTE: this will return true both for collection objects - * (aka virtual nodes) and direct child object relations, so - * isVirtual() should be used to identify relations that define - * collection properties! - */ - public boolean isCollection() { - return reftype == COLLECTION; - } - - /** - * Returns true if this Relation describes a complex object reference property - */ - public boolean isComplexReference() { - return reftype == COMPLEX_REFERENCE; - } - - /** - * Tell wether the property described by this relation is to be handled as private, i.e. - * a change on it should not result in any changed object/collection relations. - */ - public boolean isPrivate() { - return isPrivate; - } - - /** - * Check whether aggressive loading is set for this relation - */ - public boolean loadAggressively() { - return aggressiveLoading; - } - - /** - * Returns the number of constraints for this relation. - */ - public int countConstraints() { - if (constraints == null) - return 0; - return constraints.length; - } - - /** - * Returns true if the object represented by this Relation has to be - * created on demand at runtime by the NodeManager. This is true for: - * - * - collection (aka virtual) nodes - * - nodes accessed via accessname - * - group nodes - * - complex reference nodes - */ - public boolean createOnDemand() { - if (otherType == null) { - return false; - } - - return virtual || - (otherType.isRelational() && accessName != null) || - (groupby != null) || isComplexReference(); - } - - /** - * Returns true if the object represented by this Relation has to be - * persisted in the internal db in order to be functional. This is true if - * the subnodes contained in this collection are stored in the embedded - * database. In this case, the collection itself must also be an ordinary - * object stored in the db, since a virtual collection would lose its - * its content after restarts. - */ - public boolean needsPersistence() { - if (!virtual) { - // ordinary object references always need to be persisted - return true; - } - - // collections/mountpoints need to be persisted if the - // child object type is non-relational. Depending on - // whether prototype is null or not, we need to look at - // otherType itself or otherType's subnode mapping. - if (prototype == null) { - // an ordinary, unprototyped virtual node - - // otherType is the content type - return !otherType.isRelational(); - } else { - // a prototyped virtual node or mountpoint - - // otherType is the virtual node type itself - DbMapping sub = otherType.getSubnodeMapping(); - return sub != null && !sub.isRelational(); - } - } - - /** - * Return the prototype to be used for object reached by this relation - */ - public String getPrototype() { - return prototype; - } - - /** - * Return the name of the local property this relation is defined for - */ - public String getPropName() { - return propName; - } - - /** - * - * - * @param ct ... - */ - public void setColumnType(int ct) { - columnType = ct; - } - - /** - * - * - * @return ... - */ - public int getColumnType() { - return columnType; - } - - /** - * Get the group for a collection relation, if defined. - * - * @return the name of the column used to group child objects, if any. - */ - public String getGroup() { - return groupby; - } - - /** - * Add a constraint to the current list of constraints - */ - protected void addConstraint(Constraint c) { - if (constraints == null) { - constraints = new Constraint[1]; - constraints[0] = c; - } else { - Constraint[] nc = new Constraint[constraints.length + 1]; - - System.arraycopy(constraints, 0, nc, 0, constraints.length); - nc[nc.length - 1] = c; - constraints = nc; - } - } - - /** - * - * - * @return true if the foreign key used for this relation is the - * other object's primary key. - */ - public boolean usesPrimaryKey() { - return referencesPrimaryKey; - } - - /** - * - * - * @return ... - */ - public boolean hasAccessName() { - return accessName != null; - } - - /** - * - * - * @return ... - */ - public String getAccessName() { - return accessName; - } - - /** - * - * - * @return ... - */ - public Relation getSubnodeRelation() { - // return subnoderelation; - return null; - } - - /** - * Return the local field name for updates. - */ - public String getDbField() { - return columnName; - } - - /** - * This is taken from org.apache.tools.ant ProjectHelper.java - * distributed under the Apache Software License, Version 1.1 - * - * Parses a string containing ${xxx} style property - * references into two lists. The first list is a collection - * of text fragments, while the other is a set of string property names. - * null entries in the first list indicate a property - * reference from the second list. - * - * @param value Text to parse. Must not be null. - * @param fragments List to add text fragments to. - * Must not be null. - * @param propertyRefs List to add property names to. - * Must not be null. - */ - protected void parsePropertyString(String value, Vector fragments, Vector propertyRefs) { - int prev = 0; - int pos; - //search for the next instance of $ from the 'prev' position - while ((pos = value.indexOf("$", prev)) >= 0) { - - //if there was any text before this, add it as a fragment - //TODO, this check could be modified to go if pos>prev; - //seems like this current version could stick empty strings - //into the list - if (pos > 0) { - fragments.addElement(value.substring(prev, pos)); - } - //if we are at the end of the string, we tack on a $ - //then move past it - if (pos == (value.length() - 1)) { - fragments.addElement("$"); - prev = pos + 1; - } else if (value.charAt(pos + 1) != '{') { - //peek ahead to see if the next char is a property or not - //not a property: insert the char as a literal - /* - fragments.addElement(value.substring(pos + 1, pos + 2)); - prev = pos + 2; - */ - if (value.charAt(pos + 1) == '$') { - //backwards compatibility two $ map to one mode - fragments.addElement("$"); - prev = pos + 2; - } else { - //new behaviour: $X maps to $X for all values of X!='$' - fragments.addElement(value.substring(pos, pos + 2)); - prev = pos + 2; - } - - } else { - //property found, extract its name or bail on a typo - int endName = value.indexOf('}', pos); - if (endName < 0) { - throw new RuntimeException("Syntax error in property: " - + value); - } - String propertyName = value.substring(pos + 2, endName); - fragments.addElement(null); - propertyRefs.addElement(propertyName); - prev = endName + 1; - } - } - //no more $ signs found - //if there is any tail to the file, append it - if (prev < value.length()) { - fragments.addElement(value.substring(prev)); - } - } - - /** - * get a DbMapping to use for virtual aka collection nodes. - */ - public DbMapping getVirtualMapping() { - // return null unless this relation describes a virtual/collection node. - if (!virtual) { - return null; - } - - // create a synthetic DbMapping that describes how to fetch the - // collection's child objects. - if (virtualMapping == null) { - // if the collection node is prototyped (a mountpoint), create - // a virtual sub-mapping from the app's DbMapping for that prototype - if (prototype != null) { - virtualMapping = new DbMapping(ownType.app, prototype); - } else { - virtualMapping = new DbMapping(ownType.app, null); - virtualMapping.subRelation = getVirtualSubnodeRelation(); - virtualMapping.propRelation = getVirtualPropertyRelation(); - } - } - virtualMapping.lastTypeChange = ownType.lastTypeChange; - return virtualMapping; - } - - /** - * Return the db mapping for a propery relation. - * @return the target mapping of this property relation - */ - public DbMapping getPropertyMapping() { - // if this is an untyped virtual node, it doesn't have a dbmapping - if (!virtual || prototype != null) { - return otherType; - } - return null; - } - - /** - * Return a Relation that defines the subnodes of a virtual node. - */ - Relation getVirtualSubnodeRelation() { - if (!virtual) { - throw new RuntimeException("getVirtualSubnodeRelation called on non-virtual relation"); - } - - Relation vr = new Relation(this); - - vr.groupby = groupby; - vr.groupbyOrder = groupbyOrder; - vr.groupbyPrototype = groupbyPrototype; - - return vr; - } - - /** - * Return a Relation that defines the properties of a virtual node. - */ - Relation getVirtualPropertyRelation() { - if (!virtual) { - throw new RuntimeException("getVirtualPropertyRelation called on non-virtual relation"); - } - - Relation vr = new Relation(this); - - vr.groupby = groupby; - vr.groupbyOrder = groupbyOrder; - vr.groupbyPrototype = groupbyPrototype; - - return vr; - } - - /** - * Return a Relation that defines the subnodes of a group-by node. - */ - Relation getGroupbySubnodeRelation() { - if (groupby == null) { - throw new RuntimeException("getGroupbySubnodeRelation called on non-group-by relation"); - } - - Relation vr = new Relation(this); - - vr.prototype = groupbyPrototype; - vr.addConstraint(new Constraint(null, groupby, true)); - - return vr; - } - - /** - * Return a Relation that defines the properties of a group-by node. - */ - Relation getGroupbyPropertyRelation() { - if (groupby == null) { - throw new RuntimeException("getGroupbyPropertyRelation called on non-group-by relation"); - } - - Relation vr = new Relation(this); - - vr.prototype = groupbyPrototype; - vr.addConstraint(new Constraint(null, groupby, true)); - - return vr; - } - - public StringBuffer getIdSelect() { - StringBuffer buf = new StringBuffer("SELECT "); - - if (queryHints != null) { - buf.append(queryHints).append(" "); - } - - String table = otherType.getTableName(); - String idfield; - if (groupby == null) { - idfield = otherType.getIDField(); - } else { - idfield = groupby; - buf.append("DISTINCT "); - } - - if (idfield.indexOf('(') == -1 && idfield.indexOf('.') == -1) { - buf.append(table).append('.'); - } - buf.append(idfield).append(" FROM ").append(table); - appendAdditionalTables(buf); - - return buf; - } - - public StringBuffer getCountSelect() { - StringBuffer buf = new StringBuffer("SELECT "); - if (otherType.isOracle() && maxSize > 0) { - buf.append("* FROM "); - } else { - if (groupby == null) { - buf.append("count(*) FROM "); - } else { - buf.append("count(DISTINCT ").append(groupby).append(") FROM "); - } - } - - buf.append(otherType.getTableName()); - appendAdditionalTables(buf); - - return buf; - } - - public StringBuffer getNamesSelect() { - // if we do a groupby query (creating an intermediate layer of groupby nodes), - // retrieve the value of that field instead of the primary key - String namefield = (groupby == null) ? accessName : groupby; - String table = otherType.getTableName(); - StringBuffer buf = new StringBuffer("SELECT "); - buf.append(namefield).append(" FROM ").append(table); - appendAdditionalTables(buf); - - return buf; - } - - /** - * Build the second half of an SQL select statement according to this relation - * and a local object. - */ - public void buildQuery(StringBuffer q, Node home, boolean useOrder, boolean isCount) - throws SQLException, ClassNotFoundException { - buildQuery(q, home, otherType, null, useOrder, isCount); - } - - /** - * Build the second half of an SQL select statement according to this relation - * and a local object. - */ - public void buildQuery(StringBuffer q, Node home, DbMapping otherDbm, String kstr, - boolean useOrder, boolean isCount) - throws SQLException, ClassNotFoundException { - String prefix = " WHERE "; - Node nonvirtual = home.getNonVirtualParent(); - - if (kstr != null && !isComplexReference()) { - q.append(prefix); - - String accessColumn = (accessName == null) ? - otherDbm.getIDField() : accessName; - otherDbm.appendCondition(q, accessColumn, kstr); - - prefix = " AND "; - } - - // render the constraints and filter - renderConstraints(q, home, nonvirtual, otherDbm, prefix); - - // add joined fetch constraints - ownType.addJoinConstraints(q, prefix); - - // add group and order clauses - if (groupby != null) { - if (useOrder && (groupbyOrder != null)) { - q.append(" ORDER BY ").append(groupbyOrder); - } - } else if (useOrder && (order != null)) { - q.append(" ORDER BY ").append(order); - } - - // apply limit and offset, but not if the query is for a single object - if (maxSize > 0 && kstr == null) { - if (otherType.isOracle()) { - // see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html - String selectItem = isCount ? "count(*)" : "*"; - if (offset > 0) { - q.insert(0, "SELECT " + selectItem + " FROM ( SELECT /*+ FIRST_ROWS(n) */ a.*, ROWNUM rnum FROM ("); - q.append(") a WHERE ROWNUM <= ").append(offset + maxSize).append(") WHERE rnum > ").append(offset); - } else { - q.insert(0, "SELECT /*+ FIRST_ROWS(n) */ " + selectItem + " FROM ("); - q.append(") WHERE ROWNUM <= ").append(maxSize); - } - } else { - q.append(" LIMIT ").append(maxSize); - if (offset > 0) { - q.append(" OFFSET ").append(offset); - } - } - } - - } - - protected void appendAdditionalTables(StringBuffer q) { - if (additionalTables != null) { - q.append(additionalTablesJoined ? ' ' : ','); - q.append(additionalTables); - } - } - - /** - * Build the filter. - */ - protected void appendFilter(StringBuffer q, INode nonvirtual, String prefix) { - q.append(prefix); - q.append('('); - if (filterFragments == null) { - q.append(filter); - } else { - Enumeration i = filterFragments.elements(); - Enumeration j = filterPropertyRefs.elements(); - while (i.hasMoreElements()) { - String fragment = (String) i.nextElement(); - if (fragment == null) { - // begin column version - String columnName = (String) j.nextElement(); - Object value = null; - if (columnName != null) { - DbMapping dbmap = nonvirtual.getDbMapping(); - String propertyName = dbmap.columnNameToProperty(columnName); - if (propertyName == null) - propertyName = columnName; - IProperty property = nonvirtual.get(propertyName); - if (property != null) { - value = property.getStringValue(); - } - if (value == null) { - if (columnName.equalsIgnoreCase(dbmap.getIDField())) { - value = nonvirtual.getID(); - } else if (columnName.equalsIgnoreCase(dbmap.getNameField())) { - value = nonvirtual.getName(); - } else if (columnName.equalsIgnoreCase(dbmap.getPrototypeField())) { - value = dbmap.getExtensionId(); - } - } - } - // end column version - if (value != null) { - q.append(DbMapping.escapeString(value.toString())); - } else { - q.append("NULL"); - } - } else { - q.append(fragment); - } - } - } - q.append(')'); - } - - /** - * Render contraints and filter conditions to an SQL query string buffer. - * - * @param q the query string - * @param home our home node - * @param prefix the prefix to use to append to the existing query (e.g. " AND ") - * - * @throws SQLException sql related exception - * @throws ClassNotFoundException driver class not found - */ - public void renderConstraints(StringBuffer q, Node home, String prefix) - throws SQLException, ClassNotFoundException { - renderConstraints(q, home, home.getNonVirtualParent(), otherType, prefix); - } - - /** - * Render contraints and filter conditions to an SQL query string buffer. - * - * @param q the query string - * @param home our home node - * @param nonvirtual our non-virtual home nod - * @param otherDbm the DbMapping of the remote Node - * @param prefix the prefix to use to append to the existing query (e.g. " AND ") - * - * @throws SQLException sql related exception - * @throws ClassNotFoundException driver class not found - */ - public void renderConstraints(StringBuffer q, Node home, Node nonvirtual, - DbMapping otherDbm, String prefix) - throws SQLException, ClassNotFoundException { - - if (constraints.length > 1 && logicalOperator != AND) { - q.append(prefix); - q.append("("); - prefix = ""; - } - - for (int i = 0; i < constraints.length; i++) { - if (constraints[i].foreignKeyIsPrototype()) { - // if foreign key is $prototype we already have this constraint - // covered by doing the select on the proper table - continue; - } - q.append(prefix); - constraints[i].addToQuery(q, home, nonvirtual, otherDbm); - prefix = logicalOperator; - } - - if (constraints.length > 1 && logicalOperator != AND) { - q.append(")"); - prefix = " AND "; - } - - // also take the prototype into consideration if someone - // specifies an extension of an prototype inside the brakets of - // a type.properties's collection, only nodes having this proto - // sould appear inside the collection - if (otherDbm.inheritsStorage()) { - String protoField = otherDbm.getPrototypeField(); - String[] extensions = otherDbm.getExtensions(); - - // extensions should never be null for extension- and - // extended prototypes. nevertheless we check it here - if (extensions != null && protoField != null) { - q.append(prefix); - otherDbm.appendCondition(q, protoField, extensions); - prefix = " AND "; - } - } - - if (filter != null) { - appendFilter(q, nonvirtual, prefix); - } - } - - /** - * Render the constraints for this relation for use within - * a left outer join select statement for the base object. - * - * @param select the string buffer to write to - * @param isOracle create Oracle pre-9 style left outer join - */ - public void renderJoinConstraints(StringBuffer select, boolean isOracle) { - for (int i = 0; i < constraints.length; i++) { - select.append(ownType.getTableName()); - select.append("."); - select.append(constraints[i].localKey); - select.append(" = "); - select.append(JOIN_PREFIX); - select.append(propName); - select.append("."); - select.append(constraints[i].foreignKey); - if (isOracle) { - // create old oracle style join - see - // http://www.praetoriate.com/oracle_tips_outer_joins.htm - select.append("(+)"); - } - if (i == constraints.length-1) { - select.append(" "); - } else { - select.append(" AND "); - } - } - - } - - /** - * Get the order section to use for this relation - */ - public String getOrder() { - if (groupby != null) { - return groupbyOrder; - } else { - return order; - } - } - - /** - * Tell wether the property described by this relation is to be handled - * as readonly/write protected. - */ - public boolean isReadonly() { - return readonly; - } - - /** - * Get a copy of this relation. - * @return a clone of this relation - */ - public Relation getClone() { - Relation rel = new Relation(this); - rel.prototype = prototype; - rel.groupby = groupby; - rel.groupbyPrototype = groupbyPrototype; - rel.groupbyOrder = groupbyOrder; - return rel; - } - - /** - * Check if the child node fullfills the constraints defined by this relation. - * FIXME: This always returns false if the relation has a filter value set, - * since we can't determine if the filter constraints are met without - * querying the database. - * - * @param parent the parent object - may be a virtual or group node - * @param child the child object - * @return true if all constraints are met - */ - public boolean checkConstraints(Node parent, Node child) { - // problem: if a filter property is defined for this relation, - // i.e. a piece of static SQL-where clause, we'd have to evaluate it - // in order to check the constraints. Because of this, if a filter - // is defined, we return false as soon as the modified-time is greater - // than the create-time of the child, i.e. if the child node has been - // modified since it was first fetched from the db. - if (filter != null && child.lastModified() > child.created()) { - return false; - } - - // counter for constraints and satisfied constraints - int count = 0; - int satisfied = 0; - - INode nonvirtual = parent.getNonVirtualParent(); - DbMapping otherDbm = child.getDbMapping(); - if (otherDbm == null) { - otherDbm = otherType; - } - - for (int i = 0; i < constraints.length; i++) { - Constraint cnst = constraints[i]; - String propname = cnst.foreignProperty(otherDbm); - - if (propname != null) { - INode home = cnst.isGroupby ? parent - : nonvirtual; - String value = null; - - if (cnst.localKeyIsPrimary(home.getDbMapping())) { - value = home.getID(); - } else if (cnst.localKeyIsPrototype()) { - value = home.getDbMapping().getStorageTypeName(); - } else if (ownType.isRelational()) { - value = home.getString(cnst.localProperty()); - } else { - value = home.getString(cnst.localKey); - } - - count++; - - if (value != null && value.equals(child.getString(propname))) { - satisfied++; - } - } - } - - // check if enough constraints are met depending on logical operator - if (logicalOperator == OR) { - return satisfied > 0; - } else if (logicalOperator == XOR) { - return satisfied == 1; - } else { - return satisfied == count; - } - } - - /** - * Make sure that the child node fullfills the constraints defined by this relation by setting the - * appropriate properties - */ - public void setConstraints(Node parent, Node child) { - - // if logical operator is OR or XOR we just return because we - // wouldn't know what to do anyway - if (logicalOperator != AND) { - return; - } - - Node home = parent.getNonVirtualParent(); - - for (int i = 0; i < constraints.length; i++) { - Constraint cnst = constraints[i]; - // don't set groupby constraints since we don't know if the - // parent node is the base node or a group node - if (cnst.isGroupby) { - continue; - } - - // check if we update the local or the other object, depending on - // whether the primary key of either side is used. - boolean foreignIsPrimary = cnst.foreignKeyIsPrimary(); - if (foreignIsPrimary || cnst.foreignKeyIsPrototype()) { - String localProp = cnst.localProperty(); - if (localProp == null) { - throw new RuntimeException("Error: column " + cnst.localKey + - " must be mapped in order to be used as constraint in " + - Relation.this); - } else if (foreignIsPrimary && child.getState() == Node.TRANSIENT) { - throw new RuntimeException(propName + " set to transient object, " + - "can't derive persistent ID for " + localProp); - } else { - String value = foreignIsPrimary ? - child.getID() : child.getDbMapping().getStorageTypeName(); - home.setString(localProp, value); - } - continue; - } - - DbMapping otherDbm = child.getDbMapping(); - if (otherDbm == null) { - otherDbm = otherType; - } - - Relation crel = otherDbm.columnNameToRelation(cnst.foreignKey); - - if (crel != null) { - - if (cnst.localKeyIsPrimary(home.getDbMapping())) { - // only set node if property in child object is defined as reference. - if (crel.reftype == REFERENCE) { - INode currentValue = child.getNode(crel.propName); - - // we set the backwards reference iff the reference is currently unset, if - // is set to a transient object, or if the new target is not transient. This - // prevents us from overwriting a persistent refererence with a transient one, - // which would most probably not be what we want. - if ((currentValue == null) || - ((currentValue != home) && - ((currentValue.getState() == Node.TRANSIENT) || - (home.getState() != Node.TRANSIENT)))) try { - child.setNode(crel.propName, home); - } catch (Exception ignore) { - // in some cases, getNonVirtualParent() doesn't work - // correctly for transient nodes, so this may fail. - } - } else if (crel.reftype == PRIMITIVE) { - if (home.getState() == Node.TRANSIENT) { - throw new RuntimeException("Object is transient, can't derive persistent ID for " + crel); - } - child.setString(crel.propName, home.getID()); - } - } else if (crel.reftype == PRIMITIVE) { - if (cnst.localKeyIsPrototype()) { - child.setString(crel.propName, home.getDbMapping().getStorageTypeName()); - } else { - Property prop = home.getProperty(cnst.localProperty()); - if (prop != null) { - child.set(crel.propName, prop.getValue(), prop.getType()); - } else { - prop = child.getProperty(cnst.foreignProperty(child.getDbMapping())); - if (prop != null) { - home.set(cnst.localProperty(), prop.getValue(), prop.getType()); - } - } - } - } - } - } - } - - /** - * Unset the constraints that link two objects together. - */ - public void unsetConstraints(Node parent, INode child) { - Node home = parent.getNonVirtualParent(); - - for (int i = 0; i < constraints.length; i++) { - Constraint cnst = constraints[i]; - // don't set groupby constraints since we don't know if the - // parent node is the base node or a group node - if (cnst.isGroupby) { - continue; - } - - // check if we update the local or the other object, depending on - // whether the primary key of either side is used. - - if (cnst.foreignKeyIsPrimary() || cnst.foreignKeyIsPrototype()) { - String localProp = cnst.localProperty(); - if (localProp != null) { - home.setString(localProp, null); - } - continue; - } - - DbMapping otherDbm = child.getDbMapping(); - if (otherDbm == null) { - otherDbm = otherType; - } - - Relation crel = otherDbm.columnNameToRelation(cnst.foreignKey); - - if (crel != null) { - if (cnst.localKeyIsPrimary(home.getDbMapping())) { - // only set node if property in child object is defined as reference. - if (crel.reftype == REFERENCE) { - INode currentValue = child.getNode(crel.propName); - - if ((currentValue == home)) { - child.setString(crel.propName, null); - } - } else if (crel.reftype == PRIMITIVE) { - child.setString(crel.propName, null); - } - } else if (crel.reftype == PRIMITIVE) { - child.setString(crel.propName, null); - } - } - } - } - - /** - * Returns a map containing the key/value pairs for a specific Node - */ - public Map getKeyParts(INode home) { - Map map = new HashMap(); - for (int i=0; i " + target + c; - } - - /** - * The Constraint class represents a part of the where clause in the query used to - * establish a relation between database mapped objects. - */ - class Constraint { - String localKey; - String foreignKey; - boolean isGroupby; - - Constraint(String local, String foreign, boolean groupby) { - localKey = local; - foreignKey = foreign; - isGroupby = groupby; - } - - public void addToQuery(StringBuffer q, INode home, INode nonvirtual, DbMapping otherDbm) - throws SQLException, ClassNotFoundException { - String local; - INode ref = isGroupby ? home : nonvirtual; - - if (localKeyIsPrimary(ref.getDbMapping())) { - local = ref.getID(); - } else if (localKeyIsPrototype()) { - local = ref.getDbMapping().getStorageTypeName(); - } else { - String homeprop = ownType.columnNameToProperty(localKey); - if (homeprop == null) { - throw new SQLException("Invalid local name '" + localKey + - "' on " + ownType); - } - local = ref.getString(homeprop); - } - - String columnName; - if (foreignKeyIsPrimary()) { - columnName = otherDbm.getIDField(); - } else { - columnName = foreignKey; - } - otherDbm.appendCondition(q, columnName, local); - } - - public boolean foreignKeyIsPrimary() { - return (foreignKey == null) || - "$id".equalsIgnoreCase(foreignKey) || - foreignKey.equalsIgnoreCase(otherType.getIDField()); - } - - public boolean foreignKeyIsPrototype() { - return "$prototype".equalsIgnoreCase(foreignKey); - } - - public boolean localKeyIsPrimary(DbMapping homeMapping) { - return (homeMapping == null) || (localKey == null) || - "$id".equalsIgnoreCase(localKey) || - localKey.equalsIgnoreCase(homeMapping.getIDField()); - } - - public boolean localKeyIsPrototype() { - return "$prototype".equalsIgnoreCase(localKey); - } - - public String foreignProperty(DbMapping otherDbm) { - if (otherDbm.isRelational()) - return otherDbm.columnNameToProperty(foreignKey); - return foreignKey; - } - - public String localProperty() { - if (ownType.isRelational()) - return ownType.columnNameToProperty(localKey); - return localKey; - } - - public String toString() { - return localKey + "=" + otherType.getTypeName() + "." + foreignKey; - } - } -} diff --git a/src/main/java/helma/objectmodel/db/SegmentedSubnodeList.java b/src/main/java/helma/objectmodel/db/SegmentedSubnodeList.java deleted file mode 100644 index 00dc1788..00000000 --- a/src/main/java/helma/objectmodel/db/SegmentedSubnodeList.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 2009 Helma Project. All Rights Reserved. - */ - -package helma.objectmodel.db; - -import java.util.*; - -public class SegmentedSubnodeList extends SubnodeList { - - private static final long serialVersionUID = -4947752577517584610L; - - transient Segment[] segments = null; - static int SEGLENGTH = 1000; - - transient private int subnodeCount = -1; - - /** - * Creates a new subnode list - * @param node the node we belong to - */ - public SegmentedSubnodeList(Node node) { - super(node); - } - - /** - * Adds the specified object to this list performing - * custom ordering - * - * @param handle element to be inserted. - */ - public synchronized boolean add(NodeHandle handle) { - if (!hasRelationalNodes() || segments == null) { - return super.add(handle); - } - if (subnodeCount == -1) { - update(); - } - subnodeCount++; - segments[segments.length - 1].length += 1; - return list.add(handle); - } - /** - * Adds the specified object to the list at the given position - * @param index the index to insert the element at - * @param handle the object to add - */ - public synchronized void add(int index, NodeHandle handle) { - if (!hasRelationalNodes() || segments == null) { - super.add(index, handle); - return; - } - if (subnodeCount == -1) { - update(); - } - subnodeCount++; - list.add(index, handle); - // shift segment indices by one - int s = getSegment(index); - segments[s].length += 1; - for (int i = s + 1; i < segments.length; i++) { - segments[i].startIndex += 1; - } - } - - public NodeHandle get(int index) { - if (!hasRelationalNodes() || segments == null) { - return super.get(index); - } - if (index < 0 || index >= subnodeCount) { - return null; - } - loadSegment(getSegment(index), false); - return (NodeHandle) list.get(index); - } - - public synchronized boolean contains(Object object) { - if (!hasRelationalNodes() || segments == null) { - return super.contains(object); - } - if (list.contains(object)) { - return true; - } - for (int i = 0; i < segments.length; i++) { - if (loadSegment(i, false).contains(object)) { - return true; - } - } - return false; - } - - public synchronized int indexOf(Object object) { - if (!hasRelationalNodes() || segments == null) { - return super.indexOf(object); - } - int index; - if ((index = list.indexOf(object)) > -1) { - return index; - } - for (int i = 0; i < segments.length; i++) { - if ((index = loadSegment(i, false).indexOf(object)) > -1) { - return segments[i].startIndex + index; - } - } - return -1; - } - - /** - * remove the object specified by the given index-position - * @param index the index-position of the NodeHandle to remove - */ - public synchronized Object remove(int index) { - if (!hasRelationalNodes() || segments == null) { - return super.remove(index); - } - if (subnodeCount == -1) { - update(); - } - Object removed = list.remove(index); - int s = getSegment(index); - segments[s].length -= 1; - for (int i = s + 1; i < segments.length; i++) { - segments[i].startIndex -= 1; - } - subnodeCount--; - return removed; - } - - /** - * remove the given Object from this List - * @param object the NodeHandle to remove - */ - public synchronized boolean remove(Object object) { - if (!hasRelationalNodes() || segments == null) { - return super.remove(object); - } - if (subnodeCount == -1) { - update(); - } - int index = indexOf(object); - if (index > -1) { - list.remove(object); - int s = getSegment(index); - segments[s].length -= 1; - for (int i = s + 1; i < segments.length; i++) { - segments[i].startIndex -= 1; - } - subnodeCount--; - return true; - } - return false; - } - - public synchronized Object[] toArray() { - if (!hasRelationalNodes() || segments == null) { - return super.toArray(); - } - node.nmgr.logEvent("Warning: toArray() called on large segmented collection: " + node); - for (int i = 0; i < segments.length; i++) { - loadSegment(i, false); - } - return list.toArray(); - } - - private int getSegment(int index) { - for (int i = 1; i < segments.length; i++) { - if (index < segments[i].startIndex) { - return i - 1; - } - } - return segments.length - 1; - } - - private List loadSegment(int seg, boolean deep) { - Segment segment = segments[seg]; - if (segment != null && !segment.loaded) { - Relation rel = getSubnodeRelation().getClone(); - rel.offset = segment.startIndex; - int expectedSize = rel.maxSize = segment.length; - List seglist = deep ? - node.nmgr.getNodes(node, rel) : - node.nmgr.getNodeIDs(node, rel); - int actualSize = seglist.size(); - if (actualSize != expectedSize) { - node.nmgr.logEvent("Inconsistent segment size in " + node + ": " + segment); - } - int listSize = list.size(); - for (int i = 0; i < actualSize; i++) { - if (segment.startIndex + i < listSize) { - list.set(segment.startIndex + i, seglist.get(i)); - } else { - list.add(seglist.get(i)); - } - // FIXME how to handle inconsistencies? - } - segment.loaded = true; - return seglist; - } - return Collections.EMPTY_LIST; - } - - protected synchronized void update() { - if (!hasRelationalNodes()) { - segments = null; - super.update(); - return; - } - // also reload if the type mapping has changed. - long lastChange = getLastSubnodeChange(); - if (lastChange != lastSubnodeFetch) { - // count nodes in db without fetching anything - subnodeCount = node.nmgr.countNodes(node, getSubnodeRelation()); - if (subnodeCount > SEGLENGTH) { - float size = subnodeCount; - int nsegments = (int) Math.ceil(size / SEGLENGTH); - int remainder = (int) size % SEGLENGTH; - segments = new Segment[nsegments]; - for (int s = 0; s < nsegments; s++) { - int length = (s == nsegments - 1 && remainder > 0) ? - remainder : SEGLENGTH; - segments[s] = new Segment(s * SEGLENGTH, length); - } - list = new ArrayList((int) size + 5); - for (int i = 0; i < size; i++) { - list.add(null); - } - } else { - segments = null; - super.update(); - } - lastSubnodeFetch = lastChange; - } - } - - public int size() { - if (!hasRelationalNodes() || segments == null) { - return super.size(); - } - return subnodeCount; - } - - class Segment { - - int startIndex, length; - boolean loaded; - - Segment(int startIndex, int length) { - this.startIndex = startIndex; - this.length = length; - this.loaded = false; - } - - int endIndex() { - return startIndex + length; - } - - public String toString() { - return "Segment{startIndex: " + startIndex + ", length: " + length + "}"; - } - } - -} - diff --git a/src/main/java/helma/objectmodel/db/SubnodeList.java b/src/main/java/helma/objectmodel/db/SubnodeList.java deleted file mode 100644 index bec94317..00000000 --- a/src/main/java/helma/objectmodel/db/SubnodeList.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import java.util.ArrayList; -import java.util.List; -import java.io.Serializable; - -/** - * Container implementation for subnode collections. - */ -public class SubnodeList implements Serializable { - - private static final long serialVersionUID = 711208015232333566L; - - protected Node node; - protected List list; - - transient protected long lastSubnodeFetch = 0; - transient protected long lastSubnodeChange = 0; - - - /** - * Hide/disable zero argument constructor for subclasses - */ - private SubnodeList() {} - - /** - * Creates a new subnode list - * @param node the node we belong to - */ - public SubnodeList(Node node) { - this.node = node; - this.list = new ArrayList(); - } - - /** - * Adds the specified object to this list performing - * custom ordering - * - * @param handle element to be inserted. - */ - public boolean add(NodeHandle handle) { - return list.add(handle); - } - /** - * Adds the specified object to the list at the given position - * @param idx the index to insert the element at - * @param handle the object to add - */ - public void add(int idx, NodeHandle handle) { - list.add(idx, handle); - } - - public NodeHandle get(int index) { - if (index < 0 || index >= list.size()) { - return null; - } - return (NodeHandle) list.get(index); - } - - public Node getNode(int index) { - Node retval = null; - NodeHandle handle = get(index); - - if (handle != null) { - retval = handle.getNode(node.nmgr); - // Legacy alarm! - if ((retval != null) && (retval.parentHandle == null) && - !node.nmgr.isRootNode(retval)) { - retval.setParent(node); - retval.anonymous = true; - } - } - - return retval; - } - - public boolean contains(Object object) { - return list.contains(object); - } - - public int indexOf(Object object) { - return list.indexOf(object); - } - - /** - * remove the object specified by the given index-position - * @param idx the index-position of the NodeHandle to remove - */ - public Object remove (int idx) { - return list.remove(idx); - } - - /** - * remove the given Object from this List - * @param obj the NodeHandle to remove - */ - public boolean remove (Object obj) { - return list.remove(obj); - } - - public Object[] toArray() { - return list.toArray(); - } - - /** - * Return the size of the list. - * @return the list size - */ - public int size() { - return list.size(); - } - - protected void update() { - // also reload if the type mapping has changed. - long lastChange = getLastSubnodeChange(); - if (lastChange != lastSubnodeFetch) { - Relation rel = getSubnodeRelation(); - if (rel != null && rel.aggressiveLoading && rel.groupby == null) { - list = node.nmgr.getNodes(node, rel); - } else { - list = node.nmgr.getNodeIDs(node, rel); - } - lastSubnodeFetch = lastChange; - } - } - - protected void prefetch(int start, int length) { - if (start < 0 || start >= size()) { - return; - } - length = (length < 0) ? - size() - start : Math.min(length, size() - start); - if (length < 0) { - return; - } - - DbMapping dbmap = getSubnodeMapping(); - - if (dbmap.isRelational()) { - Relation rel = getSubnodeRelation(); - node.nmgr.prefetchNodes(node, rel, this, start, length); - } - } - - /** - * Compute a serial number indicating the last change in subnode collection - * @return a serial number that increases with each subnode change - */ - protected long getLastSubnodeChange() { - // include dbmap.getLastTypeChange to also reload if the type mapping has changed. - long checkSum = lastSubnodeChange + node.dbmap.getLastTypeChange(); - Relation rel = getSubnodeRelation(); - return rel == null || rel.aggressiveCaching ? - checkSum : checkSum + rel.otherType.getLastDataChange(); - } - - protected synchronized void markAsChanged() { - lastSubnodeChange += 1; - } - - protected boolean hasRelationalNodes() { - DbMapping dbmap = getSubnodeMapping(); - return (dbmap != null && dbmap.isRelational() - && ((node.getState() != Node.TRANSIENT && node.getState() != Node.NEW) - || node.getSubnodeRelation() != null)); - } - - protected DbMapping getSubnodeMapping() { - return node.dbmap == null ? null : node.dbmap.getSubnodeMapping(); - } - - protected Relation getSubnodeRelation() { - return node.dbmap == null ? null : node.dbmap.getSubnodeRelation(); - } -} diff --git a/src/main/java/helma/objectmodel/db/SyntheticKey.java b/src/main/java/helma/objectmodel/db/SyntheticKey.java deleted file mode 100644 index 9ba9f686..00000000 --- a/src/main/java/helma/objectmodel/db/SyntheticKey.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import java.io.Serializable; - -/** - * This is the internal key for an object that is not - or not directly - fetched from a db, - * but derived from another object. This is useful for all kinds of object accessed via a - * symbolic name from another object, like objects mounted via a property name column, - * virtual nodes and groupby nodes. - */ -public final class SyntheticKey implements Key, Serializable { - - // the parent key - private final Key parentKey; - - // the name relative to the parent key - private final String name; - - // lazily initialized hashcode - private transient int hashcode = 0; - - static final long serialVersionUID = -693454133259421857L; - - /** - * Make a symbolic key for an object using its parent key and its property name/id. - * @param key the parent key - * @param name the property or collection name - */ - public SyntheticKey(Key key, String name) { - this.parentKey = key; - this.name = name; - } - - /** - * Returns true if this key equals obj - * @param obj another object - * @return true if obj represents the same key as this - */ - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - - if (!(obj instanceof SyntheticKey)) { - return false; - } - - SyntheticKey k = (SyntheticKey) obj; - - return parentKey.equals(k.parentKey) && - ((name == k.name) || name.equals(k.name)); - } - - /** - * Get the hash-code for this key - * @return the hash-code - */ - public int hashCode() { - if (hashcode == 0) { - hashcode = 17 + (37 * name.hashCode()) + - (37 * parentKey.hashCode()); - } - - return hashcode; - } - - /** - * Get the parent key part of this key - * @return the parent key - */ - public Key getParentKey() { - return parentKey; - } - - /** - * Get the ID part of this key - * @return the id part - */ - public String getID() { - return name; - } - - /** - * Get the storage name for this key. This alwys returns null for symbolic keys. - * @return null - */ - public String getStorageName() { - return null; - } - - /** - * Return a string representation for this key - * @return a string representation for this key - */ - public String toString() { - return parentKey + "/" + name; - } -} diff --git a/src/main/java/helma/objectmodel/db/Transactor.java b/src/main/java/helma/objectmodel/db/Transactor.java deleted file mode 100644 index 74f5e5c7..00000000 --- a/src/main/java/helma/objectmodel/db/Transactor.java +++ /dev/null @@ -1,579 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.objectmodel.DatabaseException; -import helma.objectmodel.ITransaction; - -import java.sql.Connection; -import java.sql.Statement; -import java.sql.SQLException; -import java.util.*; - -import org.apache.commons.logging.Log; - -/** - * A subclass of thread that keeps track of changed nodes and triggers - * changes in the database when a transaction is commited. - */ -public class Transactor { - - // The associated node manager - NodeManager nmgr; - - // List of nodes to be updated - private Map dirtyNodes; - - // List of visited clean nodes - private Map cleanNodes; - - // List of nodes whose child index has been modified - private Set parentNodes; - - // Is a transaction in progress? - private volatile boolean active; - private volatile boolean killed; - - // Transaction for the embedded database - protected ITransaction txn; - - // Transactions for SQL data sources - private Map sqlConnections; - - // Set of SQL connections that already have been verified - private Map testedConnections; - - // when did the current transaction start? - private long tstart; - - // a name to log the transaction. For HTTP transactions this is the rerquest path - private String tname; - - // the thread we're associated with - private Thread thread; - - private static final ThreadLocal txtor = new ThreadLocal(); - - /** - * Creates a new Transactor object. - * - * @param nmgr the NodeManager used to fetch and persist nodes. - */ - private Transactor(NodeManager nmgr) { - this.thread = Thread.currentThread(); - this.nmgr = nmgr; - - dirtyNodes = new LinkedHashMap(); - cleanNodes = new HashMap(); - parentNodes = new HashSet(); - - sqlConnections = new HashMap(); - testedConnections = new HashMap(); - active = false; - killed = false; - } - - /** - * Get the transactor for the current thread or null if none exists. - * @return the transactor associated with the current thread - */ - public static Transactor getInstance() { - return (Transactor) txtor.get(); - } - - /** - * Get the transactor for the current thread or throw a IllegalStateException if none exists. - * @return the transactor associated with the current thread - * @throws IllegalStateException if no transactor is associated with the current thread - */ - public static Transactor getInstanceOrFail() throws IllegalStateException { - Transactor tx = (Transactor) txtor.get(); - if (tx == null) - throw new IllegalStateException("Operation requires a Transactor, " + - "but current thread does not have one."); - return tx; - } - - /** - * Get the transactor for the current thread, creating a new one if none exists. - * @param nmgr the NodeManager used to create the transactor - * @return the transactor associated with the current thread - */ - public static Transactor getInstance(NodeManager nmgr) { - Transactor t = (Transactor) txtor.get(); - if (t == null) { - t = new Transactor(nmgr); - txtor.set(t); - } - return t; - } - - /** - * Mark a Node as modified/created/deleted during this transaction - * - * @param node ... - */ - public void visitDirtyNode(Node node) { - if (node != null) { - Key key = node.getKey(); - - dirtyNodes.put(key, node); - } - } - - /** - * Unmark a Node that has previously been marked as modified during the transaction - * - * @param node ... - */ - public void dropDirtyNode(Node node) { - if (node != null) { - Key key = node.getKey(); - - dirtyNodes.remove(key); - } - } - - /** - * Get a dirty Node from this transaction. - * @param key the key - * @return the dirty node associated with the key, or null - */ - public Node getDirtyNode(Key key) { - return (Node) dirtyNodes.get(key); - } - - /** - * Keep a reference to an unmodified Node local to this transaction - * - * @param node the node to register - */ - public void visitCleanNode(Node node) { - if (node != null) { - Key key = node.getKey(); - - if (!cleanNodes.containsKey(key)) { - cleanNodes.put(key, node); - } - } - } - - /** - * Keep a reference to an unmodified Node local to this transaction - * - * @param key the key to register with - * @param node the node to register - */ - public void visitCleanNode(Key key, Node node) { - if (node != null) { - if (!cleanNodes.containsKey(key)) { - cleanNodes.put(key, node); - } - } - } - - /** - * Drop a reference to an unmodified Node previously registered with visitCleanNode(). - * @param key the key - */ - public void dropCleanNode(Key key) { - cleanNodes.remove(key); - } - - /** - * Get a reference to an unmodified Node local to this transaction - * - * @param key ... - * - * @return ... - */ - public Node getCleanNode(Object key) { - return (key == null) ? null : (Node) cleanNodes.get(key); - } - - /** - * - * - * @param node ... - */ - public void visitParentNode(Node node) { - parentNodes.add(node); - } - - - /** - * Returns true if a transaction is currently active. - * @return true if currently a transaction is active - */ - public boolean isActive() { - return active; - } - - /** - * Check whether the thread associated with this transactor is alive. - * This is a proxy to Thread.isAlive(). - * @return true if the thread running this transactor is currently alive. - */ - public boolean isAlive() { - return thread != null && thread.isAlive(); - } - - /** - * Register a db connection with this transactor thread. - * @param src the db source - * @param con the connection - */ - public void registerConnection(DbSource src, Connection con) { - sqlConnections.put(src, con); - // we assume a freshly created connection is ok. - testedConnections.put(src, Long.valueOf(System.currentTimeMillis())); - } - - /** - * Get a db connection that was previously registered with this transactor thread. - * @param src the db source - * @return the connection - */ - public Connection getConnection(DbSource src) { - Connection con = sqlConnections.get(src); - Long tested = testedConnections.get(src); - long now = System.currentTimeMillis(); - if (con != null && (tested == null || now - tested.longValue() > 60000)) { - // Check if the connection is still alive by executing a simple statement. - try { - Statement stmt = con.createStatement(); - if (src.isOracle()) { - stmt.execute("SELECT 1 FROM DUAL"); - } else { - stmt.execute("SELECT 1"); - } - stmt.close(); - testedConnections.put(src, Long.valueOf(now)); - } catch (SQLException sx) { - try { - con.close(); - } catch (SQLException ignore) {/* nothing to do */} - return null; - } - } - return con; - } - - /** - * Start a new transaction with the given name. - * - * @param name The name of the transaction. This is usually the request - * path for the underlying HTTP request. - * - * @throws Exception ... - */ - public synchronized void begin(String name) throws Exception { - if (killed) { - throw new DatabaseException("Transaction started on killed thread"); - } else if (active) { - abort(); - } - - dirtyNodes.clear(); - cleanNodes.clear(); - parentNodes.clear(); - txn = nmgr.db.beginTransaction(); - active = true; - tstart = System.currentTimeMillis(); - tname = name; - } - - /** - * Commit the current transaction, persisting all changes to DB. - * - * @throws Exception ... - */ - public synchronized void commit() throws Exception { - if (killed) { - throw new DatabaseException("commit() called on killed transactor thread"); - } else if (!active) { - return; - } - int inserted = 0; - int updated = 0; - int deleted = 0; - - ArrayList insertedNodes = null; - ArrayList updatedNodes = null; - ArrayList deletedNodes = null; - ArrayList modifiedParentNodes = null; - // if nodemanager has listeners collect dirty nodes - boolean hasListeners = nmgr.hasNodeChangeListeners(); - - if (hasListeners) { - insertedNodes = new ArrayList(); - updatedNodes = new ArrayList(); - deletedNodes = new ArrayList(); - modifiedParentNodes = new ArrayList(); - } - - if (!dirtyNodes.isEmpty()) { - Object[] dirty = dirtyNodes.values().toArray(); - - // the set to collect DbMappings to be marked as changed - HashSet dirtyDbMappings = new HashSet(); - Log eventLog = nmgr.app.getEventLog(); - - for (int i = 0; i < dirty.length; i++) { - Node node = (Node) dirty[i]; - - // update nodes in db - int nstate = node.getState(); - - if (nstate == Node.NEW) { - nmgr.insertNode(nmgr.db, txn, node); - dirtyDbMappings.add(node.getDbMapping()); - node.setState(Node.CLEAN); - - // register node with nodemanager cache - nmgr.registerNode(node); - - if (hasListeners) { - insertedNodes.add(node); - } - - inserted++; - if (eventLog.isDebugEnabled()) { - eventLog.debug("inserted node: " + node.getPrototype() + "/" + - node.getID()); - } - } else if (nstate == Node.MODIFIED) { - // only mark DbMapping as dirty if updateNode returns true - if (nmgr.updateNode(nmgr.db, txn, node)) { - dirtyDbMappings.add(node.getDbMapping()); - } - node.setState(Node.CLEAN); - - // update node with nodemanager cache - nmgr.registerNode(node); - - if (hasListeners) { - updatedNodes.add(node); - } - - updated++; - if (eventLog.isDebugEnabled()) { - eventLog.debug("updated node: " + node.getPrototype() + "/" + - node.getID()); - } - } else if (nstate == Node.DELETED) { - nmgr.deleteNode(nmgr.db, txn, node); - dirtyDbMappings.add(node.getDbMapping()); - - // remove node from nodemanager cache - nmgr.evictNode(node); - - if (hasListeners) { - deletedNodes.add(node); - } - - deleted++; - if (eventLog.isDebugEnabled()) { - eventLog.debug("removed node: " + node.getPrototype() + "/" + - node.getID()); - } - } - - node.clearWriteLock(); - } - - // set last data change times in db-mappings - // long now = System.currentTimeMillis(); - for (Iterator i = dirtyDbMappings.iterator(); i.hasNext(); ) { - DbMapping dbm = (DbMapping) i.next(); - if (dbm != null) { - dbm.setLastDataChange(); - } - } - } - - long now = System.currentTimeMillis(); - - if (!parentNodes.isEmpty()) { - // set last subnode change times in parent nodes - for (Iterator i = parentNodes.iterator(); i.hasNext(); ) { - Node node = (Node) i.next(); - node.markSubnodesChanged(); - if (hasListeners) { - modifiedParentNodes.add(node); - } - } - } - - if (hasListeners) { - nmgr.fireNodeChangeEvent(insertedNodes, updatedNodes, - deletedNodes, modifiedParentNodes); - } - - // clear the node collections - recycle(); - - if (active) { - active = false; - nmgr.db.commitTransaction(txn); - txn = null; - } - - StringBuffer msg = new StringBuffer(tname).append(" done in ") - .append(now - tstart).append(" millis"); - if(inserted + updated + deleted > 0) { - msg.append(" [+") - .append(inserted).append(", ~") - .append(updated).append(", -") - .append(deleted).append("]"); - } - nmgr.app.logAccess(msg.toString()); - - // unset transaction name - tname = null; - } - - /** - * Abort the current transaction, rolling back all changes made. - */ - public synchronized void abort() { - Object[] dirty = dirtyNodes.values().toArray(); - - // evict dirty nodes from cache - for (int i = 0; i < dirty.length; i++) { - Node node = (Node) dirty[i]; - - // Declare node as invalid, so it won't be used by other threads - // that want to write on it and remove it from cache - nmgr.evictNode(node); - node.clearWriteLock(); - } - - long now = System.currentTimeMillis(); - - // set last subnode change times in parent nodes - for (Iterator i = parentNodes.iterator(); i.hasNext(); ) { - Node node = (Node) i.next(); - node.markSubnodesChanged(); - } - - // clear the node collections - recycle(); - // close any JDBC connections associated with this transactor thread - closeConnections(); - - if (active) { - active = false; - - if (txn != null) { - nmgr.db.abortTransaction(txn); - txn = null; - } - - nmgr.app.logAccess(tname + " aborted after " + - (System.currentTimeMillis() - tstart) + " millis"); - } - - // unset transaction name - tname = null; - } - - /** - * Kill this transaction thread. Used as last measure only. - */ - @SuppressWarnings("deprecation") - public synchronized void kill() { - - killed = true; - thread.interrupt(); - - // Interrupt the thread if it has not noticed the flag (e.g. because it is busy - // reading from a network socket). - if (thread.isAlive()) { - thread.interrupt(); - try { - thread.join(1000); - } catch (InterruptedException ir) { - // interrupted by other thread - } - } - - if (thread.isAlive() && "true".equals(nmgr.app.getProperty("requestTimeoutStop"))) { - // still running - check if we ought to stop() it - try { - Thread.sleep(2000); - if (thread.isAlive()) { - // thread is still running, pull emergency break - nmgr.app.logEvent("Stopping Thread for Transactor " + this); - thread.stop(); - } - } catch (InterruptedException ir) { - // interrupted by other thread - } - } - } - - /** - * Closes all open JDBC connections - */ - public void closeConnections() { - if (sqlConnections != null) { - for (Iterator i = sqlConnections.values().iterator(); i.hasNext();) { - try { - Connection con = (Connection) i.next(); - - con.close(); - nmgr.app.logEvent("Closing DB connection: " + con); - } catch (Exception ignore) { - // exception closing db connection, ignore - } - } - - sqlConnections.clear(); - testedConnections.clear(); - } - } - - /** - * Clear collections and throw them away. They may have grown large, - * so the benefit of keeping them (less GC) needs to be weighted against - * the potential increas in memory usage. - */ - private synchronized void recycle() { - // clear the node collections to ease garbage collection - dirtyNodes.clear(); - cleanNodes.clear(); - parentNodes.clear(); - } - - /** - * Return the name of the current transaction. This is usually the request - * path for the underlying HTTP request. - */ - public String getTransactionName() { - return tname; - } - - /** - * Return a string representation of this Transactor thread - * - * @return ... - */ - public String toString() { - return "Transactor[" + tname + "]"; - } -} diff --git a/src/main/java/helma/objectmodel/db/WrappedNodeManager.java b/src/main/java/helma/objectmodel/db/WrappedNodeManager.java deleted file mode 100644 index 1e327a42..00000000 --- a/src/main/java/helma/objectmodel/db/WrappedNodeManager.java +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.db; - -import helma.objectmodel.ObjectNotFoundException; - -import java.util.Vector; -import java.util.List; - -/** - * A wrapper around NodeManager that catches most Exceptions, or rethrows them as RuntimeExceptions. - * The idea behind this is that we don't care a lot about Exception classes, since Hop programming is done - * in JavaScript which doesn't know about them (except for the exception message). - */ -public final class WrappedNodeManager { - NodeManager nmgr; - - /** - * Creates a new WrappedNodeManager object. - * - * @param nmgr ... - */ - public WrappedNodeManager(NodeManager nmgr) { - this.nmgr = nmgr; - } - - /** - * Get a node given its id and DbMapping - * - * @param id - * @param dbmap - * @return - */ - public Node getNode(String id, DbMapping dbmap) { - return getNode(new DbKey(dbmap, id)); - } - - /** - * Get a node given its key - * - * @param key - * @return - */ - public Node getNode(Key key) { - Transactor tx = checkLocalTransactor(); - try { - beginLocalTransaction(tx, "getNode"); - Node node = nmgr.getNode(key); - commitLocalTransaction(tx); - return node; - } catch (ObjectNotFoundException x) { - abortLocalTransaction(tx); - return null; - } catch (Exception x) { - abortLocalTransaction(tx); - nmgr.app.logError("Error retrieving Node for " + key, x); - throw new RuntimeException("Error retrieving Node", x); - } - } - - /** - * Get the node specified by the given id and Relation. - * - * @param home - * @param id - * @param rel - * @return - */ - public Node getNode(Node home, String id, Relation rel) { - Transactor tx = checkLocalTransactor(); - try { - beginLocalTransaction(tx, "getNode"); - Node node = nmgr.getNode(home, id, rel); - commitLocalTransaction(tx); - return node; - } catch (ObjectNotFoundException x) { - abortLocalTransaction(tx); - return null; - } catch (Exception x) { - abortLocalTransaction(tx); - nmgr.app.logError("Error retrieving Node \"" + id + "\" from " + home, x); - throw new RuntimeException("Error retrieving Node", x); - } - } - - /** - * Get the list of nodes contained in the collection of the given - * Node specified by the given Relation. - * - * @param home - * @param rel - * @return - */ - public List getNodes(Node home, Relation rel) { - Transactor tx = checkLocalTransactor(); - try { - beginLocalTransaction(tx, "getNodes"); - List list = nmgr.getNodes(home, rel); - commitLocalTransaction(tx); - return list; - } catch (Exception x) { - abortLocalTransaction(tx); - throw new RuntimeException("Error retrieving Nodes", x); - } - } - - /** - * Get a list of IDs of nodes contained in the given Node's - * collection specified by the given Relation. - * - * @param home - * @param rel - * @return - */ - public List getNodeIDs(Node home, Relation rel) { - try { - return nmgr.getNodeIDs(home, rel); - } catch (Exception x) { - throw new RuntimeException("Error retrieving NodeIDs", x); - } - } - - /** - * @see helma.objectmodel.db.NodeManager#updateSubnodeList(Node, Relation) - */ - /* public int updateSubnodeList (Node home, Relation rel) { - try { - return nmgr.updateSubnodeList(home, rel); - } catch (Exception x) { - throw new RuntimeException("Error retrieving NodeIDs", x); - } - } */ - - /** - * Count the nodes contained in the given Node's collection - * specified by the given Relation. - * - * @param home - * @param rel - * @return - */ - public int countNodes(Node home, Relation rel) { - try { - return nmgr.countNodes(home, rel); - } catch (Exception x) { - throw new RuntimeException("Error counting Nodes", x); - } - } - - public void prefetchNodes(Node node, Relation rel, SubnodeList list, - int start, int length) { - try { - nmgr.prefetchNodes(node, rel, list, start, length); - } catch (Exception x) { - throw new RuntimeException("Error prefetching nodes", x); - } - } - - /** - * Delete a node from the database - * - * @param node - */ - public void deleteNode(Node node) { - Transactor tx = checkLocalTransactor(); - try { - beginLocalTransaction(tx, "deleteNode"); - nmgr.deleteNode(node); - commitLocalTransaction(tx); - } catch (Exception x) { - abortLocalTransaction(tx); - throw new RuntimeException("Error deleting Node", x); - } - } - - /** - * Get a list of property names from the given node. - * TODO: this retrieves access names of child nodes, not property names - * - * @param home - * @param rel - * @return - */ - public Vector getPropertyNames(Node home, Relation rel) { - try { - return nmgr.getPropertyNames(home, rel); - } catch (Exception x) { - throw new RuntimeException("Error retrieving property names ", x); - } - } - - /** - * Register a node with the object cache using its primary key. - * - * @param node - */ - public void registerNode(Node node) { - nmgr.registerNode(node); - } - - /** - * Register a node with the object cache using the given key. - * - * @param node - */ - public void registerNode(Node node, Key key) { - nmgr.registerNode(node, key); - } - - /** - * Evict a node from the object cache - * - * @param node - */ - public void evictNode(Node node) { - nmgr.evictNode(node); - } - - /** - * Completely evict the object with the given key from the object cache - * - * @param key - */ - public void evictNodeByKey(Key key) { - nmgr.evictNodeByKey(key); - } - - /** - * Evict the object with the given key from the object cache - * - * @param key - */ - public void evictKey(Key key) { - nmgr.evictKey(key); - } - - /** - * Generate a new id for an object specified by the DbMapping - * - * @param map the DbMapping to generate an id for - * @return a new unique id - */ - public String generateID(DbMapping map) { - try { - return nmgr.generateID(map); - } catch (Exception x) { - throw new RuntimeException(x.toString(), x); - } - } - - /** - * Gets the application's root node. - */ - public Node getRootNode() { - Transactor tx = checkLocalTransactor(); - try { - beginLocalTransaction(tx, "getRootNode"); - Node node = nmgr.getRootNode(); - commitLocalTransaction(tx); - return node; - } catch (Exception x) { - abortLocalTransaction(tx); - throw new RuntimeException(x.toString(), x); - } - } - - /** - * Checks if the given node is the application's root node. - */ - public boolean isRootNode(Node node) { - return nmgr.isRootNode(node); - } - - /** - * Get an array of all objects in the object cache - */ - public Object[] getCacheEntries() { - return nmgr.getCacheEntries(); - } - - /** - * Write an entry to the application's event log - * - * @param msg event message - */ - public void logEvent(String msg) { - nmgr.app.logEvent(msg); - } - - /** - * Get the DbMapping corresponding to a type name - * - * @param name a type name - * @return the corresponding DbMapping - */ - public DbMapping getDbMapping(String name) { - return nmgr.app.getDbMapping(name); - } - - // helper methods to wrap execution inside local transactions - - private Transactor checkLocalTransactor() { - Transactor tx = Transactor.getInstance(); - if (tx != null) { - // transactor already associated with current thread - return null - return null; - } - return Transactor.getInstance(nmgr); - } - - private void beginLocalTransaction(Transactor tx, String name) { - if (tx != null) { - try { - tx.begin(name); - } catch (Exception x) { - nmgr.app.logError("Error in beginLocalTransaction", x); - } - } - } - - private void commitLocalTransaction(Transactor tx) { - if (tx != null) { - try { - tx.commit(); - } catch (Exception x) { - nmgr.app.logError("Error in commitLocalTransaction", x); - } - } - } - - private void abortLocalTransaction(Transactor tx) { - if (tx != null) { - try { - tx.abort(); - } catch (Exception x) { - nmgr.app.logError("Error in abortLocalTransaction", x); - } - } - } -} diff --git a/src/main/java/helma/objectmodel/dom/XmlConstants.java b/src/main/java/helma/objectmodel/dom/XmlConstants.java deleted file mode 100644 index 7c87064c..00000000 --- a/src/main/java/helma/objectmodel/dom/XmlConstants.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.dom; - -/** - * - */ -public interface XmlConstants { - public final String NAMESPACE = "http://www.helma.org/docs/guide/features/database"; - public final String DATEFORMAT = "dd.MM.yyyy HH:mm:ss z"; -} diff --git a/src/main/java/helma/objectmodel/dom/XmlConverter.java b/src/main/java/helma/objectmodel/dom/XmlConverter.java deleted file mode 100644 index e27f711d..00000000 --- a/src/main/java/helma/objectmodel/dom/XmlConverter.java +++ /dev/null @@ -1,528 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.dom; - -import helma.objectmodel.INode; -import helma.util.SystemProperties; -import org.w3c.dom.*; -import org.xml.sax.InputSource; - -import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * - */ -public class XmlConverter implements XmlConstants { - private boolean DEBUG = false; - private boolean sparse = false; - private Properties props; - private char defaultSeparator = '_'; - private int offset = 0; - - /** - * Creates a new XmlConverter object. - */ - public XmlConverter() { - props = new SystemProperties(); - } - - /** - * Creates a new XmlConverter object. - * - * @param propFile ... - */ - public XmlConverter(String propFile) { - props = new SystemProperties(propFile); - extractProperties(props); - } - - /** - * Creates a new XmlConverter object. - * - * @param propFile ... - */ - public XmlConverter(File propFile) { - this(propFile.getAbsolutePath()); - } - - /** - * Creates a new XmlConverter object. - * - * @param props ... - */ - public XmlConverter(Properties props) { - this.props = props; - extractProperties(props); - } - - /** - * - * - * @param desc ... - * @param helmaNode ... - * - * @return ... - * - * @throws RuntimeException ... - */ - public INode convert(String desc, INode helmaNode) - throws RuntimeException { - try { - return convert(new URL(desc), helmaNode); - } catch (MalformedURLException notanurl) { - try { - return convert(new File(desc), helmaNode); - } catch (FileNotFoundException notfound) { - throw new RuntimeException("couldn't read xml: " + desc); - } - } catch (IOException ioerror) { - throw new RuntimeException("couldn't read xml: " + desc); - } - } - - /** - * - * - * @param file ... - * @param helmaNode ... - * - * @return ... - * - * @throws RuntimeException ... - * @throws FileNotFoundException ... - */ - public INode convert(File file, INode helmaNode) - throws RuntimeException, FileNotFoundException { - return convert(new FileInputStream(file), helmaNode); - } - - /** - * - * - * @param url ... - * @param helmaNode ... - * - * @return ... - * - * @throws RuntimeException ... - * @throws IOException ... - * @throws MalformedURLException ... - */ - public INode convert(URL url, INode helmaNode) - throws RuntimeException, IOException, MalformedURLException { - return convert(url.openConnection().getInputStream(), helmaNode); - } - - /** - * - * - * @param in ... - * @param helmaNode ... - * - * @return ... - * - * @throws RuntimeException ... - */ - public INode convert(InputStream in, INode helmaNode) - throws RuntimeException { - Document document = XmlUtil.parse(in); - - if ((document != null) && (document.getDocumentElement() != null)) { - return convert(document.getDocumentElement(), helmaNode, new HashMap()); - } else { - return helmaNode; - } - } - - /** - * - * - * @param xml ... - * @param helmaNode ... - * - * @return ... - * - * @throws RuntimeException ... - */ - public INode convertFromString(String xml, INode helmaNode) - throws RuntimeException { - Document document = XmlUtil.parse(new InputSource(new StringReader(xml))); - - if ((document != null) && (document.getDocumentElement() != null)) { - return convert(document.getDocumentElement(), helmaNode, new HashMap()); - } else { - return helmaNode; - } - } - - /** - * - * - * @param element ... - * @param helmaNode ... - * @param nodeCache ... - * - * @return ... - */ - public INode convert(Element element, INode helmaNode, Map nodeCache) { - offset++; - - // previousNode is used to cache previous nodes with the same prototype - // so we can reset it in the nodeCache after we've run - Object previousNode = null; - - if (DEBUG) { - debug("reading " + element.getNodeName()); - } - - String prototype = props.getProperty(element.getNodeName() + "._prototype"); - - if ((prototype == null) && !sparse) { - prototype = "HopObject"; - } - - // if we have a prototype (either explicit or implicit "hopobject"), - // set it on the Helma node and store it in the node cache. - if (prototype != null) { - helmaNode.setName(element.getNodeName()); - helmaNode.setPrototype(prototype); - previousNode = nodeCache.put(prototype, helmaNode); - } - - // check attributes of the current element - attributes(element, helmaNode, nodeCache); - - // check child nodes of the current element - if (element.hasChildNodes()) { - children(element, helmaNode, nodeCache); - } - - // if it exists, restore the previous node we've replaced in the node cache. - if (previousNode != null) { - nodeCache.put(prototype, previousNode); - } - - offset--; - - return helmaNode; - } - - /** - * parse xml children and create hopobject-children - */ - private INode children(Element element, helma.objectmodel.INode helmaNode, - Map nodeCache) { - NodeList list = element.getChildNodes(); - int len = list.getLength(); - boolean nodeIsInitialized = !nodeCache.isEmpty(); - StringBuffer textcontent = new StringBuffer(); - String domKey; - String helmaKey; - - for (int i = 0; i < len; i++) { - // loop through the list of children - org.w3c.dom.Node childNode = list.item(i); - - // if the current node hasn't been initialized yet, try if it can - // be initialized and converted from one of the child elements. - if (!nodeIsInitialized) { - if (childNode.getNodeType() == Node.ELEMENT_NODE) { - convert((Element) childNode, helmaNode, nodeCache); - - if (helmaNode.getPrototype() != null) { - return helmaNode; - } - } - - continue; - } - - // if it's text content of this element -> append to StringBuffer - if ((childNode.getNodeType() == Node.TEXT_NODE) || - (childNode.getNodeType() == Node.CDATA_SECTION_NODE)) { - textcontent.append(childNode.getNodeValue().trim()); - - continue; - } - - // it's some kind of element (property or child) - if (childNode.getNodeType() == Node.ELEMENT_NODE) { - Element childElement = (Element) childNode; - - // get the basic key we have to look for in the properties-table - domKey = element.getNodeName() + "." + childElement.getNodeName(); - - // is there a childtext-2-property mapping? - if ((props != null) && props.containsKey(domKey + "._text")) { - helmaKey = props.getProperty(domKey + "._text"); - - if (helmaKey.equals("")) { - // if property is set but without value, read elementname for this mapping - helmaKey = childElement.getNodeName().replace(':', - defaultSeparator); - } - - if (DEBUG) { - debug("childtext-2-property mapping, helmaKey " + helmaKey + - " for domKey " + domKey); - } - - // check if helmaKey contains an explicit prototype name in which to - // set the property. - int dot = helmaKey.indexOf("."); - - if (dot > -1) { - String prototype = helmaKey.substring(0, dot); - INode node = (INode) nodeCache.get(prototype); - - helmaKey = helmaKey.substring(dot + 1); - - if ((node != null) && (node.getString(helmaKey) == null)) { - node.setString(helmaKey, XmlUtil.getTextContent(childNode)); - } - } else if (helmaNode.getString(helmaKey) == null) { - helmaNode.setString(helmaKey, XmlUtil.getTextContent(childNode)); - - if (DEBUG) { - debug("childtext-2-property mapping, setting " + helmaKey + - " as string"); - } - } - - continue; - } - - // is there a simple child-2-property mapping? - // (lets the user define to use only one element and make this a property - // and simply ignore other elements of the same name) - if ((props != null) && props.containsKey(domKey + "._property")) { - helmaKey = props.getProperty(domKey + "._property"); - - // if property is set but without value, read elementname for this mapping: - if (helmaKey.equals("")) { - helmaKey = childElement.getNodeName().replace(':', - defaultSeparator); - } - - if (DEBUG) { - debug("child-2-property mapping, helmaKey " + helmaKey + - " for domKey " + domKey); - } - - // get the node on which to opererate, depending on the helmaKey - // value from the properties file. - INode node = helmaNode; - int dot = helmaKey.indexOf("."); - - if (dot > -1) { - String prototype = helmaKey.substring(0, dot); - - if (!prototype.equalsIgnoreCase(node.getPrototype())) { - node = (INode) nodeCache.get(prototype); - } - - helmaKey = helmaKey.substring(dot + 1); - } - - if (node == null) { - continue; - } - - if (node.getNode(helmaKey) == null) { - convert(childElement, node.createNode(helmaKey), nodeCache); - - if (DEBUG) { - debug("read " + childElement.toString() + - node.getNode(helmaKey).toString()); - } - } - - continue; - } - - // map it to one of the children-lists - helma.objectmodel.INode newHelmaNode = null; - String childrenMapping = props.getProperty(element.getNodeName() + - "._children"); - - // do we need a mapping directly among _children of helmaNode? - // can either be through property elname._children=_all or elname._children=childname - if ((childrenMapping != null) && - (childrenMapping.equals("_all") || - childrenMapping.equals(childElement.getNodeName()))) { - newHelmaNode = convert(childElement, helmaNode.createNode(null), - nodeCache); - } - - // in which virtual subnode collection should objects of this type be stored? - helmaKey = props.getProperty(domKey); - - if ((helmaKey == null) && !sparse) { - helmaKey = childElement.getNodeName().replace(':', defaultSeparator); - } - - if (helmaKey == null) { - // we don't map this child element itself since we do - // sparse parsing, but there may be something of interest - // in the child's attributes and child elements. - attributes(childElement, helmaNode, nodeCache); - children(childElement, helmaNode, nodeCache); - - continue; - } - - // get the node on which to opererate, depending on the helmaKey - // value from the properties file. - INode node = helmaNode; - int dot = helmaKey.indexOf("."); - - if (dot > -1) { - String prototype = helmaKey.substring(0, dot); - - if (!prototype.equalsIgnoreCase(node.getPrototype())) { - node = (INode) nodeCache.get(prototype); - } - - helmaKey = helmaKey.substring(dot + 1); - } - - if (node == null) { - continue; - } - - // try to get the virtual node - INode worknode = null; - - if ("_children".equals(helmaKey)) { - worknode = node; - } else { - worknode = node.getNode(helmaKey); - - if (worknode == null) { - // if virtual node doesn't exist, create it - worknode = helmaNode.createNode(helmaKey); - } - } - - if (DEBUG) { - debug("mounting child " + childElement.getNodeName() + - " at worknode " + worknode.toString()); - } - - // now mount it, possibly re-using the helmaNode that's been created before - if (newHelmaNode != null) { - worknode.addNode(newHelmaNode); - } else { - convert(childElement, worknode.createNode(null), nodeCache); - } - } - - // forget about other types (comments etc) - continue; - } - - // if there's some text content for this element, map it: - if ((textcontent.length() > 0) && !sparse) { - helmaKey = props.getProperty(element.getNodeName() + "._text"); - - if (helmaKey == null) { - helmaKey = "text"; - } - - if (DEBUG) { - debug("setting text " + textcontent + " to property " + helmaKey + - " of object " + helmaNode); - } - - helmaNode.setString(helmaKey, textcontent.toString().trim()); - } - - return helmaNode; - } - - /** - * set element's attributes as properties of helmaNode - */ - private INode attributes(Element element, INode helmaNode, Map nodeCache) { - NamedNodeMap nnm = element.getAttributes(); - int len = nnm.getLength(); - - for (int i = 0; i < len; i++) { - org.w3c.dom.Node attr = nnm.item(i); - String helmaKey = props.getProperty(element.getNodeName() + "._attribute." + - attr.getNodeName()); - - // unless we only map explicit attributes, use attribute name as property name - // in case no property name was defined. - if ((helmaKey == null) && !sparse) { - helmaKey = attr.getNodeName().replace(':', defaultSeparator); - } - - if (helmaKey != null) { - // check if the mapping contains the prototype to which - // the property should be applied - int dot = helmaKey.indexOf("."); - - if (dot > -1) { - String prototype = helmaKey.substring(0, dot); - INode node = (INode) nodeCache.get(prototype); - - if (node != null) { - node.setString(helmaKey.substring(dot + 1), attr.getNodeValue()); - } - } else if (helmaNode.getPrototype() != null) { - helmaNode.setString(helmaKey, attr.getNodeValue()); - } - } - } - - return helmaNode; - } - - /** - * utility function - */ - private void extractProperties(Properties props) { - if (props.containsKey("separator")) { - defaultSeparator = props.getProperty("separator").charAt(0); - } - - sparse = "sparse".equalsIgnoreCase(props.getProperty("_mode")); - } - - /** for testing */ - void debug(Object msg) { - for (int i = 0; i < offset; i++) { - System.out.print(" "); - } - - System.out.println(msg.toString()); - } - - /** - * - * - * @param args ... - */ - public static void main(String[] args) { - } -} diff --git a/src/main/java/helma/objectmodel/dom/XmlDatabase.java b/src/main/java/helma/objectmodel/dom/XmlDatabase.java deleted file mode 100644 index 53ceb9e2..00000000 --- a/src/main/java/helma/objectmodel/dom/XmlDatabase.java +++ /dev/null @@ -1,474 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.dom; - -import helma.objectmodel.*; -import helma.objectmodel.db.NodeManager; -import helma.objectmodel.db.Node; -import helma.framework.core.Application; - -import javax.xml.parsers.ParserConfigurationException; -import java.io.*; -import java.util.ArrayList; - -import org.xml.sax.SAXException; - -/** - * A simple XML-database - */ -public final class XmlDatabase implements IDatabase { - - protected File dbHomeDir; - protected Application app; - protected NodeManager nmgr; - protected XmlIDGenerator idgen; - - // character encoding to use when writing files. - // use standard encoding by default. - protected String encoding = null; - - /** - * Initializes the database from an application. - * @param app - * @throws DatabaseException - */ - public void init(File dbHome, Application app) throws DatabaseException { - this.app = app; - nmgr = app.getNodeManager(); - dbHomeDir = dbHome; - - if (!dbHomeDir.exists() && !dbHomeDir.mkdirs()) { - throw new DatabaseException("Can't create database directory "+dbHomeDir); - } - - if (!dbHomeDir.canWrite()) { - throw new DatabaseException("No write permission for database directory "+dbHomeDir); - } - - File stylesheet = new File(dbHomeDir, "helma.xsl"); - // if style sheet doesn't exist, copy it - if (!stylesheet.exists()) { - copyStylesheet(stylesheet); - } - - this.encoding = app.getCharset(); - - // get the initial id generator value - long idBaseValue; - try { - idBaseValue = Long.parseLong(app.getProperty("idBaseValue", "1")); - // 0 and 1 are reserved for root nodes - idBaseValue = Math.max(1L, idBaseValue); - } catch (NumberFormatException ignore) { - idBaseValue = 1L; - } - - ITransaction txn = null; - - try { - txn = beginTransaction(); - - try { - idgen = getIDGenerator(txn); - - if (idgen.getValue() < idBaseValue) { - idgen.setValue(idBaseValue); - } - } catch (ObjectNotFoundException notfound) { - // will start with idBaseValue+1 - idgen = new XmlIDGenerator(idBaseValue); - } - - // check if we need to set the id generator to a base value - Node node = null; - - try { - getNode(txn, "0"); - } catch (ObjectNotFoundException notfound) { - node = new Node("root", "0", "Root", nmgr.safe); - node.setDbMapping(app.getDbMapping("root")); - insertNode(txn, node.getID(), node); - // register node with nodemanager cache - // nmgr.registerNode(node); - } - - try { - getNode(txn, "1"); - } catch (ObjectNotFoundException notfound) { - node = new Node("users", "1", null, nmgr.safe); - node.setDbMapping(app.getDbMapping("__userroot__")); - insertNode(txn, node.getID(), node); - // register node with nodemanager cache - // nmgr.registerNode(node); - } - - commitTransaction(txn); - } catch (Exception x) { - x.printStackTrace(); - - try { - abortTransaction(txn); - } catch (Exception ignore) { - } - - throw (new DatabaseException("Error initializing db")); - } - } - - /** - * Try to copy style sheet for XML files to database directory - */ - private void copyStylesheet(File destination) { - InputStream in = null; - FileOutputStream out = null; - byte[] buffer = new byte[1024]; - int read; - - try { - in = getClass().getResourceAsStream("helma.xsl"); - out = new FileOutputStream(destination); - while ((read = in.read(buffer, 0, buffer.length)) > 0) { - out.write(buffer, 0, read); - } - } catch (IOException iox) { - System.err.println("Error copying db style sheet: "+iox); - } finally { - try { - if (out != null) - out.close(); - if (in != null) - in.close(); - } catch (IOException ignore) { - } - } - } - - /** - * Shut down the database - */ - public void shutdown() { - // nothing to do - } - - /** - * Start a new transaction. - * - * @return the new tranaction object - * @throws DatabaseException - */ - public ITransaction beginTransaction() throws DatabaseException { - return new XmlTransaction(); - } - - /** - * committ the given transaction, makint its changes persistent - * - * @param txn - * @throws DatabaseException - */ - public void commitTransaction(ITransaction txn) throws DatabaseException { - if (idgen.dirty) { - try { - saveIDGenerator(txn); - idgen.dirty = false; - } catch (IOException x) { - throw new DatabaseException(x.toString()); - } - } - txn.commit(); - } - - /** - * Abort the given transaction - * - * @param txn - * @throws DatabaseException - */ - public void abortTransaction(ITransaction txn) throws DatabaseException { - txn.abort(); - } - - /** - * Get the id for the next new object to be stored. - * - * @return the id for the next new object to be stored - * @throws ObjectNotFoundException - */ - public String nextID() throws ObjectNotFoundException { - if (idgen == null) { - getIDGenerator(null); - } - - return idgen.newID(); - } - - /** - * Get the id-generator for this database. - * - * @param txn - * @return the id-generator for this database - * @throws ObjectNotFoundException - */ - public XmlIDGenerator getIDGenerator(ITransaction txn) - throws ObjectNotFoundException { - File file = new File(dbHomeDir, "idgen.xml"); - - this.idgen = XmlIDGenerator.getIDGenerator(file); - - return idgen; - } - - /** - * Write the id-generator to file. - * - * @param txn - * @throws IOException - */ - public void saveIDGenerator(ITransaction txn) - throws IOException { - File tmp = File.createTempFile("idgen.xml.", ".tmp", dbHomeDir); - - XmlIDGenerator.saveIDGenerator(idgen, tmp); - - File file = new File(dbHomeDir, "idgen.xml"); - if (file.exists() && !file.canWrite()) { - throw new IOException("No write permission for "+file); - } - Resource res = new Resource(file, tmp); - txn.addResource(res, ITransaction.ADDED); - } - - /** - * Retrieves a Node from the database. - * - * @param txn the current transaction - * @param kstr the key - * @return the object associated with the given key - * @throws IOException if an I/O error occurred loading the object. - * @throws ObjectNotFoundException if no object is stored by this key. - */ - public INode getNode(ITransaction txn, String kstr) - throws IOException, ObjectNotFoundException { - File f = new File(dbHomeDir, kstr + ".xml"); - - if (!f.exists()) { - throw new ObjectNotFoundException("Object not found for key " + kstr); - } - - try { - XmlDatabaseReader reader = new XmlDatabaseReader(nmgr); - Node node = reader.read(f); - - return node; - } catch (ParserConfigurationException x) { - app.logError("Error reading " +f, x); - throw new IOException(x.toString()); - } catch (SAXException x) { - app.logError("Error reading " +f, x); - throw new IOException(x.toString()); - } - } - /** - * Save a node with the given key. Writes the node to a temporary file - * which is copied to its final name when the transaction is committed. - * - * @param txn - * @param kstr - * @param node - * @throws java.io.IOException - */ - public void insertNode(ITransaction txn, String kstr, INode node) - throws IOException { - File f = new File(dbHomeDir, kstr + ".xml"); - - if (f.exists()) { - throw new IOException("Object already exists for key " + kstr); - } - - // apart from the above check insertNode() is equivalent to updateNode() - updateNode(txn, kstr, node); - } - - /** - * Update a node with the given key. Writes the node to a temporary file - * which is copied to its final name when the transaction is committed. - * - * @param txn - * @param kstr - * @param node - * @throws java.io.IOException - */ - public void updateNode(ITransaction txn, String kstr, INode node) - throws IOException { - XmlWriter writer = null; - File tmp = File.createTempFile(kstr + ".xml.", ".tmp", dbHomeDir); - - if (encoding != null) { - writer = new XmlWriter(tmp, encoding); - } else { - writer = new XmlWriter(tmp); - } - - writer.setMaxLevels(1); - writer.write(node); - writer.close(); - - File file = new File(dbHomeDir, kstr+".xml"); - if (file.exists() && !file.canWrite()) { - throw new IOException("No write permission for "+file); - } - Resource res = new Resource(file, tmp); - txn.addResource(res, ITransaction.ADDED); - } - - /** - * Marks an element from the database as deleted - * - * @param txn - * @param kstr - * @throws IOException - */ - public void deleteNode(ITransaction txn, String kstr) - throws IOException { - Resource res = new Resource(new File(dbHomeDir, kstr+".xml"), null); - txn.addResource(res, ITransaction.DELETED); - } - - /** - * set the file encoding to use - * - * @param encoding the database's file encoding - */ - public void setEncoding(String encoding) { - this.encoding = encoding; - } - - /** - * get the file encoding used by this database - * - * @return the file encoding used by this database - */ - public String getEncoding() { - return encoding; - } - - class XmlTransaction implements ITransaction { - - ArrayList writeFiles = new ArrayList(); - ArrayList deleteFiles = new ArrayList(); - - /** - * Complete the transaction by making its changes persistent. - */ - public void commit() throws DatabaseException { - // move through updated/created files and persist them - int l = writeFiles.size(); - for (int i=0; i\n"); - out.write("\n"); - out.write("\n"); - out.write("\n"); - out.write(" " + idgen.getValue() + "\n"); - out.write("\n"); - out.close(); - } -} diff --git a/src/main/java/helma/objectmodel/dom/XmlReader.java b/src/main/java/helma/objectmodel/dom/XmlReader.java deleted file mode 100644 index caa41799..00000000 --- a/src/main/java/helma/objectmodel/dom/XmlReader.java +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.dom; - -import helma.objectmodel.INode; -import helma.objectmodel.db.WrappedNodeManager; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import java.io.*; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Stack; - -/** - * - */ -public final class XmlReader extends DefaultHandler implements XmlConstants { - static SAXParserFactory factory = SAXParserFactory.newInstance(); - private INode rootNode; - private INode currentNode; - private Stack nodeStack; - private HashMap convertedNodes; - private String elementType = null; - private String elementName = null; - private StringBuffer charBuffer = null; - boolean parsingHopObject; - WrappedNodeManager nmgr; - - /** - * Creates a new XmlReader object. - */ - public XmlReader(WrappedNodeManager nmgr) { - this.nmgr = nmgr; - } - - /** - * main entry to read an xml-file. - */ - public INode read(File file, INode helmaNode) - throws ParserConfigurationException, SAXException, IOException { - try { - return read(new FileInputStream(file), helmaNode); - } catch (FileNotFoundException notfound) { - System.err.println("couldn't find xml-file: " + file.getAbsolutePath()); - - return helmaNode; - } - } - - /** - * read an InputStream with xml-content. - */ - public INode read(InputStream in, INode helmaNode) - throws ParserConfigurationException, SAXException, IOException { - return read(new InputSource(in), helmaNode); - } - - /** - * read an character reader with xml-content. - */ - public INode read(Reader in, INode helmaNode) - throws ParserConfigurationException, SAXException, IOException { - return read(new InputSource(in), helmaNode); - } - - /** - * read an InputSource with xml-content. - */ - public INode read(InputSource in, INode helmaNode) - throws ParserConfigurationException, SAXException, IOException { - if (helmaNode == null) { - throw new RuntimeException("Can't create a new Node without a root Node"); - } - - SAXParser parser = factory.newSAXParser(); - - rootNode = helmaNode; - currentNode = null; - convertedNodes = new HashMap(); - nodeStack = new Stack(); - parsingHopObject = true; - - parser.parse(in, this); - - return rootNode; - } - - /** - * - * - * @param namespaceURI ... - * @param localName ... - * @param qName ... - * @param atts ... - * - * @throws SAXException ... - */ - public void startElement(String namespaceURI, String localName, String qName, - Attributes atts) throws SAXException { - // System.err.println ("XML-READ: startElement "+namespaceURI+", "+localName+", "+qName+", "+atts.getValue("id")); - // discard the first element called xmlroot - if ("xmlroot".equals(qName) && (currentNode == null)) { - return; - } - - // if currentNode is null, this must be the hopobject node - String id = atts.getValue("id"); - - if (id != null) { - // check if there is a current node. - if (currentNode == null) { - // If currentNode is null, this is the root node we're parsing. - currentNode = rootNode; - } else if ("hop:child".equals(qName)) { - // it's an anonymous child node - nodeStack.push(currentNode); - currentNode = currentNode.createNode(null); - } else { - // it's a named node property - nodeStack.push(currentNode); - - // property name may be encoded as "propertyname" attribute, - // otherwise it is the element name - String propName = atts.getValue("propertyname"); - - if (propName == null) { - propName = qName; - } - - currentNode = currentNode.createNode(propName); - } - - // set the prototype on the current node and - // add it to the map of parsed nodes. - String prototype = atts.getValue("prototype"); - - if (!"".equals(prototype) && !"hopobject".equals(prototype)) { - currentNode.setPrototype(prototype); - currentNode.setDbMapping(nmgr.getDbMapping(prototype)); - } - - String key = id + "-" + prototype; - - convertedNodes.put(key, currentNode); - - return; - } - - // check if we have a currentNode to set properties on, - // otherwise throw exception. - if (currentNode == null) { - throw new SAXException("Invalid XML: No valid root HopObject found"); - } - - // check if we are inside a HopObject - otherwise throw an exception - if (!parsingHopObject) { - throw new SAXException("Invalid XML: Found nested non-HobObject elements"); - } - - // if we got so far, the element is not a hopobject. Set flag to prevent - // the hopobject stack to be popped when the element - // is closed. - parsingHopObject = false; - - // Is it a reference to an already parsed node? - String idref = atts.getValue("idref"); - - if (idref != null) { - // a reference to a node that should have been parsed - // and lying in our cache of parsed nodes. - String prototyperef = atts.getValue("prototyperef"); - String key = idref + "-" + prototyperef; - INode n = (INode) convertedNodes.get(key); - - // if not a reference to a node we already read, try to - // resolve against the NodeManager. - if (n == null) { - n = nmgr.getNode(idref, nmgr.getDbMapping(prototyperef)); - } - - if (n != null) { - if ("hop:child".equals(qName)) { - // add an already parsed node as child to current node - currentNode.addNode(n); - } else { - // set an already parsed node as node property to current node - // property name may be encoded as "propertyname" attribute, - // otherwise it is the element name - String propName = atts.getValue("propertyname"); - - if (propName == null) { - propName = qName; - } - - if ("hop:parent".equals(qName)) { - // FIXME: we ought to set parent here, but we're - // dealing with INodes, which don't have a setParent(). - } else { - currentNode.setNode(propName, n); - } - } - } - } else { - // It's a primitive property. Remember the property name and type - // so we can properly parse/interpret the character data when we - // get it later on. - elementType = atts.getValue("type"); - - if (elementType == null) { - elementType = "string"; - } - - // property name may be encoded as "propertyname" attribute, - // otherwise it is the element name - elementName = atts.getValue("propertyname"); - - if (elementName == null) { - elementName = qName; - } - - if (charBuffer == null) { - charBuffer = new StringBuffer(); - } else { - charBuffer.setLength(0); - } - } - } - - /** - * - * - * @param ch ... - * @param start ... - * @param length ... - * - * @throws SAXException ... - */ - public void characters(char[] ch, int start, int length) - throws SAXException { - // System.err.println ("CHARACTERS: "+new String (ch, start, length)); - // append chars to char buffer - if (elementType != null) { - charBuffer.append(ch, start, length); - } - } - - /** - * - * - * @param namespaceURI ... - * @param localName ... - * @param qName ... - * - * @throws SAXException ... - */ - public void endElement(String namespaceURI, String localName, String qName) - throws SAXException { - if (elementType != null) { - String charValue = charBuffer.toString(); - - charBuffer.setLength(0); - - if ("boolean".equals(elementType)) { - if ("true".equals(charValue)) { - currentNode.setBoolean(elementName, true); - } else { - currentNode.setBoolean(elementName, false); - } - } else if ("date".equals(elementType)) { - SimpleDateFormat format = new SimpleDateFormat(DATEFORMAT); - - try { - Date date = format.parse(charValue); - - currentNode.setDate(elementName, date); - } catch (ParseException e) { - currentNode.setString(elementName, charValue); - } - } else if ("float".equals(elementType)) { - currentNode.setFloat(elementName, (Double.valueOf(charValue)).doubleValue()); - } else if ("integer".equals(elementType)) { - currentNode.setInteger(elementName, (Long.valueOf(charValue)).longValue()); - } else { - currentNode.setString(elementName, charValue); - } - - elementName = null; - elementType = null; - charValue = null; - } - - if (parsingHopObject && !nodeStack.isEmpty()) { - currentNode = (INode) nodeStack.pop(); - } else { - parsingHopObject = true; // the next element end tag closes a hopobject again - } - } -} diff --git a/src/main/java/helma/objectmodel/dom/XmlUtil.java b/src/main/java/helma/objectmodel/dom/XmlUtil.java deleted file mode 100644 index 2ca7ed6d..00000000 --- a/src/main/java/helma/objectmodel/dom/XmlUtil.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.dom; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.io.InputStream; -import java.util.WeakHashMap; - -/** - * - */ -public class XmlUtil { - private static final DocumentBuilderFactory domBuilderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); - private static final WeakHashMap domBuilders = new WeakHashMap(); - - private static synchronized DocumentBuilder getDocumentBuilder() { - DocumentBuilder domBuilder = (DocumentBuilder) domBuilders.get(Thread.currentThread()); - - if (domBuilder != null) { - return domBuilder; - } else { - try { - domBuilder = domBuilderFactory.newDocumentBuilder(); - domBuilders.put(Thread.currentThread(), domBuilder); - - return domBuilder; - } catch (ParserConfigurationException e) { - throw new RuntimeException("Cannot build parser: " + e.toString()); - } - } - } - - /** - * - * - * @return ... - */ - public static Document newDocument() { - DocumentBuilder d = getDocumentBuilder(); - - return d.newDocument(); - } - - /** - * - * - * @param in ... - * - * @return ... - * - * @throws RuntimeException ... - */ - public static Document parse(InputStream in) throws RuntimeException { - DocumentBuilder d = getDocumentBuilder(); - - try { - Document doc = d.parse(in); - - doc.normalize(); - - return doc; - } catch (SAXException e) { - throw new RuntimeException("Bad xml-code: " + e.toString()); - } catch (IOException f) { - throw new RuntimeException("Could not read Xml: " + f.toString()); - } - } - - /** - * - * - * @param in ... - * - * @return ... - * - * @throws RuntimeException ... - */ - public static Document parse(InputSource in) throws RuntimeException { - DocumentBuilder d = getDocumentBuilder(); - - try { - Document doc = d.parse(in); - - doc.normalize(); - - return doc; - } catch (SAXException e) { - throw new RuntimeException("Bad xml-code: " + e.toString()); - } catch (IOException f) { - throw new RuntimeException("Could not read Xml: " + f.toString()); - } - } - - /** - * get first "real" element (ie not the document-rootelement, but the next one - */ - public static Element getFirstElement(Document document) { - Element workelement = null; - - if (document.getDocumentElement() != null) { - org.w3c.dom.Node tmp = document.getDocumentElement().getFirstChild(); - - while (tmp != null) { - tmp = tmp.getNextSibling(); - - if (tmp.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { - workelement = (Element) tmp; - - break; - } - } - } - - return workelement; - } - - /** - * return the text content of an element - */ - public static String getTextContent(org.w3c.dom.Node element) { - StringBuffer childtext = new StringBuffer(); - NodeList childlist = element.getChildNodes(); - int ct = childlist.getLength(); - - for (int j = 0; j < ct; j++) { - org.w3c.dom.Node childNode = childlist.item(j); - - if ((childNode.getNodeType() == Node.TEXT_NODE) || - (childNode.getNodeType() == Node.CDATA_SECTION_NODE)) { - childtext.append(childNode.getNodeValue().trim()); - } - } - - return childtext.toString(); - } -} diff --git a/src/main/java/helma/objectmodel/dom/XmlWriter.java b/src/main/java/helma/objectmodel/dom/XmlWriter.java deleted file mode 100644 index 43a3ecfa..00000000 --- a/src/main/java/helma/objectmodel/dom/XmlWriter.java +++ /dev/null @@ -1,529 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.objectmodel.dom; - - -import helma.objectmodel.INode; -import helma.objectmodel.IProperty; -import helma.objectmodel.INodeState; -import helma.objectmodel.db.DbMapping; -import helma.objectmodel.db.Node; -import helma.util.HtmlEncoder; - -import java.io.*; -import java.text.SimpleDateFormat; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -/** - * - */ -public class XmlWriter extends OutputStreamWriter implements XmlConstants { - private final static String LINESEPARATOR = System.getProperty("line.separator"); - private static int fileid; - private Vector convertedNodes; - private int maxLevels = 3; - private String indent = " "; - private StringBuffer prefix = new StringBuffer(); - private SimpleDateFormat format = new SimpleDateFormat(DATEFORMAT); - private boolean dbmode = true; - - // the helma.objectmodel.INodeState of the node we're writing - public int rootState; - - // Only add encoding to XML declaration if it was explicitly set, not when we're using - // the platform's standard encoding. - private String explicitEncoding; - - /** - * empty constructor, will use System.out as outputstream. - */ - public XmlWriter() { - super(System.out); - } - - /** - * Creates a new XmlWriter object. - * - * @param out ... - */ - public XmlWriter(OutputStream out) { - super(out); - } - - /** - * Creates a new XmlWriter object. - * - * @param out ... - * @param enc ... - * - * @throws UnsupportedEncodingException ... - */ - public XmlWriter(OutputStream out, String enc) throws UnsupportedEncodingException { - super(out, enc); - explicitEncoding = enc; - } - - /** - * Creates a new XmlWriter object. - * - * @param desc ... - * - * @throws FileNotFoundException ... - */ - public XmlWriter(String desc) throws FileNotFoundException { - super(new FileOutputStream(desc)); - } - - /** - * Creates a new XmlWriter object. - * - * @param desc ... - * @param enc ... - * - * @throws FileNotFoundException ... - * @throws UnsupportedEncodingException ... - */ - public XmlWriter(String desc, String enc) - throws FileNotFoundException, UnsupportedEncodingException { - super(new FileOutputStream(desc), enc); - explicitEncoding = enc; - } - - /** - * Creates a new XmlWriter object. - * - * @param file ... - * - * @throws FileNotFoundException ... - */ - public XmlWriter(File file) throws FileNotFoundException { - super(new FileOutputStream(file)); - } - - /** - * Creates a new XmlWriter object. - * - * @param file ... - * @param enc ... - * - * @throws FileNotFoundException ... - * @throws UnsupportedEncodingException ... - */ - public XmlWriter(File file, String enc) - throws FileNotFoundException, UnsupportedEncodingException { - super(new FileOutputStream(file), enc); - explicitEncoding = enc; - } - - // Set of prototypes at which to stop writing. - // private Set stopTypes = null; - - /** - * create ids that can be used for temporary files. - */ - public static int generateID() { - return fileid++; - } - - /** - * by default writing only descends 50 levels into the node tree to prevent - * infite loops. number can be changed here. - */ - public void setMaxLevels(int levels) { - maxLevels = levels; - } - - /** - * - * - * @param dbmode ... - */ - public void setDatabaseMode(boolean dbmode) { - this.dbmode = dbmode; - } - - /** - * Set a group of prototypes at which to stop XML serialization. - */ - - /* public void setStopTypes (Set set) { - this.stopTypes = set; - } */ - - /** - * set the number of space chars - */ - public void setIndent(int ct) { - StringBuffer tmp = new StringBuffer(); - - for (int i = 0; i < ct; i++) { - tmp.append(" "); - } - - indent = tmp.toString(); - } - - /** - * starting point for printing a node tree. - * creates document header too and initializes - * the cache of already converted nodes. - */ - public boolean write(INode node) throws IOException { - rootState = node.getState(); - convertedNodes = new Vector(); - - if (explicitEncoding == null) { - writeln(""); - } else { - writeln(""); - } - // add style sheet processing instruction - writeln(""); - - // writeln (""); - // writeln ("" ); - write(""); - write(node, null, null, 0); - writeln(""); - convertedNodes = null; - - return true; - } - - /** - * write a hopobject and print all its properties and children. - * references are made here if a node already has been fully printed - * or if this is the last level that's going to be dumped - */ - public void write(INode node, String elementName, String propName, int level) - throws IOException { - if (node == null) { - return; - } - - // if (stopTypes != null && stopTypes.contains (node.getPrototype())) - // return; - int previousLength = prefix.length(); - - prefix.append(indent); - - if (++level > maxLevels) { - writeReferenceTag(node, elementName, propName); - prefix.setLength(previousLength); - - return; - } - - if (convertedNodes.contains(node)) { - writeReferenceTag(node, elementName, propName); - } else if (rootState == INodeState.TRANSIENT && - node.getState() > INodeState.TRANSIENT) { - // if we are writing a transient node, and that node - // holds a reference to a persistent one, just write a - // reference tag to that persistent node. - writeReferenceTag(node, elementName, propName); - - } else { - convertedNodes.addElement(node); - writeTagOpen(node, elementName, propName); - - INode parent = node.getParent(); - - if (parent != null) { - writeReferenceTag(parent, "hop:parent", null); - } - - writeProperties(node, level); - writeChildren(node, level); - writeTagClose(elementName); - } - - prefix.setLength(previousLength); - } - - /** - * loop through properties and print them with their property-name - * as elementname - */ - private void writeProperties(INode node, int level) - throws IOException { - Enumeration e = null; - - if (dbmode && node instanceof Node) { - // a newly constructed db.Node doesn't have a propMap, - // but returns an enumeration of all it's db-mapped properties - Hashtable props = ((Node) node).getPropMap(); - - if (props == null) { - return; - } - - e = props.keys(); - } else { - e = node.properties(); - } - - while (e.hasMoreElements()) { - String key = (String) e.nextElement(); - if (dbmode && key.charAt(0) == '_') { - continue; - } - IProperty prop = node.get(key); - - if (prop != null) { - boolean validName = isValidElementName(key); - String elementName; - String propName; - - if (validName) { - elementName = key; - propName = null; - } else { - elementName = "property"; - propName = key; - } - - int type = prop.getType(); - - if (type == IProperty.NODE) { - write(prop.getNodeValue(), elementName, propName, level); - } else { - writeProperty(prop, elementName, propName); - } - } - } - } - - /* public void writeNullProperty (String key) throws IOException { - write (prefix.toString()); - write (indent); - write ("<"); - write (key); - write (" type=\"null\"/>"); - write (LINESEPARATOR); - } */ - - /** - * write a single property, set attribute type according to type, - * apply xml-encoding. - */ - public void writeProperty(IProperty property, String elementName, String propName) - throws IOException { - int propType = property.getType(); - - // we can't encode java objects in XML - if (propType == IProperty.JAVAOBJECT) { - return; - } - - write(prefix.toString()); - write(indent); - write("<"); - write(elementName); - - if (propName != null) { - write(" propertyname=\""); - write(HtmlEncoder.encodeXml(propName)); - write("\""); - } - - switch (propType) { - case IProperty.BOOLEAN: - write(" type=\"boolean\">"); - write(property.getStringValue()); - - break; - - case IProperty.FLOAT: - write(" type=\"float\">"); - write(property.getStringValue()); - - break; - - case IProperty.INTEGER: - write(" type=\"integer\">"); - write(property.getStringValue()); - - break; - - case IProperty.DATE: - write(" type=\"date\">"); - write(format.format(property.getDateValue())); - - break; - - case IProperty.STRING: - write(">"); - - String str = HtmlEncoder.encodeXml(property.getStringValue()); - - if (str != null) { - write(str); - } - break; - } - - write(""); - write(LINESEPARATOR); - } - - /** - * loop through the children-array and print them as - */ - private void writeChildren(INode node, int level) throws IOException { - if (dbmode && node instanceof Node) { - Node dbNode = (Node) node; - DbMapping smap = (dbNode.getDbMapping() == null) ? null - : dbNode.getDbMapping() - .getSubnodeMapping(); - - if ((smap != null) && smap.isRelational()) { - return; - } - } - - Enumeration e = node.getSubnodes(); - - while (e.hasMoreElements()) { - INode nextNode = (INode) e.nextElement(); - - write(nextNode, "hop:child", null, level); - } - } - - /** - * write an opening tag for a node. Include id and prototype, use a - * name if parameter is non-empty. - */ - public void writeTagOpen(INode node, String name, String propName) - throws IOException { - write(prefix.toString()); - write("<"); - write((name == null) ? "hopobject" : name); - write(" id=\""); - write(node.getID()); - - if (propName != null) { - write("\" propertyname=\""); - write(HtmlEncoder.encodeXml(propName)); - } - - write("\" name=\""); - write(HtmlEncoder.encodeXml(node.getName())); - write("\" prototype=\""); - write(getNodePrototype(node)); - write("\" created=\""); - write(Long.toString(node.created())); - write("\" lastModified=\""); - write(Long.toString(node.lastModified())); - - //FIXME: do we need anonymous-property? - write("\">"); - write(LINESEPARATOR); - } - - /** - * write a closing tag for a node - * e.g. - */ - public void writeTagClose(String name) throws IOException { - write(prefix.toString()); - write(""); - write(LINESEPARATOR); - } - - /** - * write a tag holding a reference to an element that has - * been written out before. - * e.g. - */ - public void writeReferenceTag(INode node, String name, String propName) - throws IOException { - write(prefix.toString()); - write("<"); - write((name == null) ? "hopobject" : name); - write(" idref=\""); - write(node.getID()); - - if (propName != null) { - write("\" propertyname=\""); - write(HtmlEncoder.encodeXml(propName)); - } - - write("\" prototyperef=\""); - write(getNodePrototype(node)); - write("\"/>"); - write(LINESEPARATOR); - } - - /** - * retrieve prototype-string of a node, defaults to "hopobject" - */ - private String getNodePrototype(INode node) { - if ((node.getPrototype() == null) || "".equals(node.getPrototype())) { - return "hopobject"; - } else { - return node.getPrototype(); - } - } - - /** - * - * - * @param str ... - * - * @throws IOException ... - */ - public void writeln(String str) throws IOException { - write(str); - write(LINESEPARATOR); - } - - /** - * Check if a string is usable as XML element name. If not, the name - * will be appended as attribute to the XML element. We are - * conservative here, preferring to return false rather too often than - * not enough. - */ - private boolean isValidElementName(String str) { - char c = str.charAt(0); - - if (!Character.isLetter(c)) { - return false; - } - - int l = str.length(); - - for (int i = 1; i < l; i++) { - c = str.charAt(i); - - if (!Character.isLetterOrDigit(c) && (c != '-') && (c != '_')) { - return false; - } - } - - return true; - } -} diff --git a/src/main/java/helma/scripting/ScriptingEngine.java b/src/main/java/helma/scripting/ScriptingEngine.java deleted file mode 100644 index 20a9284f..00000000 --- a/src/main/java/helma/scripting/ScriptingEngine.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting; - -import helma.framework.repository.Resource; -import helma.framework.core.Application; -import helma.framework.core.RequestEvaluator; - -import java.io.OutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; - -/** - * This is the interface that must be implemented to make a scripting environment - * usable by the Helma application server. - * - * Implementations of this interface must have a public zero-argument constructor - * to be usable by the Helma framework. - */ -public interface ScriptingEngine { - - /** - * Argument wrapping mode that indicates arguments are wrapped already - * and should be passed along unchanged. - */ - public final int ARGS_WRAP_NONE = 0; - - /** - * Argument wrapping mode that indicates arguments may be arbitrary - * Java objects that may need to be wrapped. - */ - public final int ARGS_WRAP_DEFAULT = 1; - - /** - * Argument wrapping mode that indicates this is an XML-RPC call and - * arguments should be processed accordingly. - */ - public final int ARGS_WRAP_XMLRPC = 2; - - /** - * Init the scripting engine with an application and a request evaluator - * @param app the application - * @param reval the request evaluator - */ - public void init(Application app, RequestEvaluator reval); - - /** - * Shut down the Scripting engine. - */ - public void shutdown(); - - /** - * This method is called when an execution context for a request - * evaluation is entered to let the Engine know it should update - * its prototype information - * @throws IOException an I/O exception occurred - * @throws ScriptingException a script related exception occurred - */ - public void enterContext() throws IOException, ScriptingException; - - /** - * This method is called when an execution context for a request - * evaluation is entered. The globals parameter contains the global values - * to be applied during this execution context. - * @param globals map of global variables - * @throws ScriptingException a script related exception occurred - */ - public void setGlobals(Map globals) throws ScriptingException; - - /** - * This method is called to let the scripting engine know that the current - * execution context has terminated. - */ - public void exitContext(); - - /** - * Invoke a function on some object, using the given arguments and global vars. - * XML-RPC calls require special input and output parameter conversion. - * - * @param thisObject the object to invoke the function on, or null for - * global functions - * @param function the name of the function to be invoked - * @param args array of argument objects - * @param argsWrapMode indicated the way to process the arguments. Must be - * one of ARGS_WRAP_NONE, - * ARGS_WRAP_DEFAULT, - * ARGS_WRAP_XMLRPC - * @param resolve indicates whether functionName may contain an object path - * or just the plain function name - * @return the return value of the function - * @throws ScriptingException to indicate something went wrong - * with the invocation - */ - public Object invoke(Object thisObject, Object function, - Object[] args, int argsWrapMode, boolean resolve) - throws ScriptingException; - - - /** - * Let the evaluator know that the current evaluation has been aborted. - */ - public void abort(); - - /** - * Get a global property - * @param propertyName the property name - * @return the property value, or null - */ - public Object getGlobalProperty(String propertyName); - - /** - * Get a property on an object - * @param thisObject the object - * @param propertyName the property name - * @return the property value, or null - */ - public Object getProperty(Object thisObject, String propertyName); - - /** - * Return true if a function by that name is defined for that object. - * @param thisObject the object - * @param functionName the function name - * @param resolve if member path in function name should be resolved - * @return true if the function is defined on the object - */ - public boolean hasFunction(Object thisObject, String functionName, boolean resolve); - - /** - * Return true if a property by that name is defined for that object. - * @param thisObject the object - * @param propertyName the property name - * @return true if the function is defined on the object - */ - public boolean hasProperty(Object thisObject, String propertyName); - - /** - * Determine if the given object is mapped to a type of the scripting engine - * @param obj an object - * @return true if the object is mapped to a type - */ - public boolean isTypedObject(Object obj); - - /** - * Return a string representation for the given object - * @param obj an object - * @return a string representing the object - */ - public String toString(Object obj); - - /** - * Provide object serialization for this engine's scripted objects. If no special - * provisions are required, this method should just wrap the stream with an - * ObjectOutputStream and write the object. - * - * @param obj the object to serialize - * @param out the stream to write to - * @throws IOException - */ - public void serialize(Object obj, OutputStream out) throws IOException; - - /** - * Provide object deserialization for this engine's scripted objects. If no special - * provisions are required, this method should just wrap the stream with an - * ObjectIntputStream and read the object. - * - * @param in the stream to read from - * @return the deserialized object - * @throws IOException - */ - public Object deserialize(InputStream in) throws IOException, ClassNotFoundException; - - /** - * Add a code resource to a given prototype by immediately compiling and evaluating it. - * - * @param typename the type this resource belongs to - * @param resource a code resource - */ - public void injectCodeResource(String typename, Resource resource); -} diff --git a/src/main/java/helma/scripting/ScriptingException.java b/src/main/java/helma/scripting/ScriptingException.java deleted file mode 100644 index 2505891b..00000000 --- a/src/main/java/helma/scripting/ScriptingException.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting; - -import org.mozilla.javascript.RhinoException; - -import java.io.*; - -/** - * The base class for wrapped exceptions thrown by invocation of the scripting engine. - * If the wrapped exception is a RhinoException, the script stack trace will be - * prepended to the actual java stack trace in stack dumps. - */ -public class ScriptingException extends Exception { - - private static final long serialVersionUID = -7191341724784015678L; - - String scriptStack = null; - - /** - * Construct a ScriptingException given an error message and wrapped exception. - * @param message the message - * @param cause the original exception - */ - public ScriptingException(String message, Throwable cause) { - super(message, cause); - setScriptStack(cause); - } - - /** - * Extract the JavaScript stack trace element from the source exception - * and copy them over to the target exception. - * @param cause the original exception - */ - private void setScriptStack(Throwable cause) { - if (cause instanceof RhinoException) { - FilenameFilter filter = new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".js") || - name.endsWith(".hac") || - name.endsWith(".hsp"); - } - }; - scriptStack = ((RhinoException) cause).getScriptStackTrace(filter); - } - } - - /** - * Get the script stack, or null if none is available - * @return the script stack trace - */ - public String getScriptStackTrace() { - return scriptStack; - } - - /** - * Get the java stack trace. - * @return the java stack trace - */ - public String getJavaStackTrace() { - StringWriter w = new StringWriter(); - getCause().printStackTrace(new PrintWriter(w)); - return w.toString(); - } - - /* - * Adaption from Throwable.printStackTrace() to also print Script file stack elements. - */ - public void printStackTrace(PrintStream s) { - synchronized (s) { - if (scriptStack != null) { - s.println(this); - s.print(scriptStack); - s.print("Full trace: "); - } - getCause().printStackTrace(s); - } - } - - - /* - * Adaption from Throwable.printStackTrace() to also print Script file stack elements. - */ - public void printStackTrace(PrintWriter s) { - synchronized (s) { - if (scriptStack != null) { - s.println(this); - s.print(scriptStack); - s.print("Full trace: "); - } - getCause().printStackTrace(s); - } - } - -} \ No newline at end of file diff --git a/src/main/java/helma/scripting/rhino/CompiledOrInterpretedModuleScriptProvider.java b/src/main/java/helma/scripting/rhino/CompiledOrInterpretedModuleScriptProvider.java deleted file mode 100644 index cec1e359..00000000 --- a/src/main/java/helma/scripting/rhino/CompiledOrInterpretedModuleScriptProvider.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 2017 Daniel Ruthardt. All rights reserved. - */ - -package helma.scripting.rhino; - -import java.net.URI; - -import org.mozilla.javascript.Context; -import org.mozilla.javascript.EvaluatorException; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.commonjs.module.ModuleScript; -import org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider; -import org.mozilla.javascript.commonjs.module.provider.StrongCachingModuleScriptProvider; - -/** - * Provides module scripts without compiling, should compiling not be possible for whatever reason. - * The main reason being targeted though, is the "generated bytecode for method exceeds 64K limit" issue. - */ -public class CompiledOrInterpretedModuleScriptProvider extends StrongCachingModuleScriptProvider { - - /** - * Define the serialization UID. - */ - private static final long serialVersionUID = 1170789670529274963L; - - /** - * Delegates to the super constructor. - */ - public CompiledOrInterpretedModuleScriptProvider(ModuleSourceProvider moduleSourceProvider) { - // do what would have been done anyways - super(moduleSourceProvider); - } - - @Override - public ModuleScript getModuleScript(Context cx, String moduleId, URI moduleUri, URI baseUri, Scriptable paths) throws Exception { - try { - // try to load the module script with whatever optimization level is set for the application - return super.getModuleScript(cx, moduleId, moduleUri, baseUri, paths); - } catch (EvaluatorException ignore) { - // unlikely, but possible exception during loading the module script without compilation - Exception exception; - // get the application's optimization level - int optimizationLevel = cx.getOptimizationLevel(); - - try { - // set the optimization level to not compile, but interpret - cx.setOptimizationLevel(-1); - // load the module script with the newly set optimization level - ModuleScript moduleScript = super.getModuleScript(cx, moduleId, moduleUri, baseUri, paths); - // return the module script - return moduleScript; - } catch (Exception e) { - // remember the exception - exception = e; - } finally { - // re-set the optimization - cx.setOptimizationLevel(optimizationLevel); - } - - // re-throw the exception catched when trying to load the module script without compilation - throw exception; - } - } - -} \ No newline at end of file diff --git a/src/main/java/helma/scripting/rhino/GlobalObject.java b/src/main/java/helma/scripting/rhino/GlobalObject.java deleted file mode 100644 index 09f4a5b8..00000000 --- a/src/main/java/helma/scripting/rhino/GlobalObject.java +++ /dev/null @@ -1,676 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino; - -import helma.scripting.rhino.extensions.*; -import helma.framework.core.*; -import helma.objectmodel.db.*; -import helma.util.HtmlEncoder; -import helma.util.MimePart; -import helma.util.XmlUtils; -import org.mozilla.javascript.*; -import org.mozilla.javascript.serialize.*; -import org.xml.sax.SAXException; - -import java.util.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.text.*; -import java.io.*; - -/** - * Helma global object defines a number of custom global functions. - */ -public class GlobalObject extends ImporterTopLevel implements PropertyRecorder { - private static final long serialVersionUID = -5058912338247265290L; - - Application app; - RhinoCore core; - boolean isThreadScope = false; - - // fields to implement PropertyRecorder - private volatile boolean isRecording = false; - private volatile HashSet changedProperties; - - /** - * Creates a new GlobalObject object. - * - * @param core ... - * @param app ... - */ - public GlobalObject(RhinoCore core, Application app, boolean isThreadScope) { - this.core = core; - this.app = app; - this.isThreadScope = isThreadScope; - if (isThreadScope) { - setPrototype(core.global); - setParentScope(null); - } - } - - /** - * Initializes the global object. This is only done for the shared - * global objects not the per-thread ones. - */ - public void init() { - String[] globalFuncs = { - "renderSkin", "renderSkinAsString", "getProperty", - "authenticate", "createSkin", "format", "formatParagraphs", - "getXmlDocument", "getHtmlDocument", "seal", - "getDBConnection", "getURL", "write", "writeln", - "serialize", "deserialize", "defineLibraryScope", - "wrapJavaMap", "unwrapJavaMap", "toJava", "definePrototype" - }; - - defineFunctionProperties(globalFuncs, GlobalObject.class, DONTENUM | PERMANENT); - put("app", this, Context.toObject(new ApplicationBean(app), this)); - put("Xml", this, Context.toObject(new XmlObject(core), this)); - put("global", this, this); - // Define dontEnum() on Object prototype - String[] objFuncs = { "dontEnum" }; - ScriptableObject objproto = (ScriptableObject) getObjectPrototype(this); - objproto.defineFunctionProperties(objFuncs, GlobalObject.class, DONTENUM | PERMANENT); - } - - /** - * Get the global object's class name - * - * @return the class name for the global object - */ - public String getClassName() { - return "GlobalObject"; - } - - /** - * Override ScriptableObject.put() to implement PropertyRecorder interface - * and to synchronize method. - * - * @param name - * @param start - * @param value - */ - public void put(String name, Scriptable start, Object value) { - // register property for PropertyRecorder interface - if (isRecording) { - // if during compilation a property is set on the thread scope - // forward it to the shared scope (bug 504) - if (isThreadScope) { - core.global.put(name, core.global, value); - return; - } else { - changedProperties.add(name); - } - } - super.put(name, start, value); - } - - /** - * Override ScriptableObject.get() to use the per-thread scope if possible, - * and return the per-thread scope for "global". - * - * @param name - * @param start - * @return the property for the given name - */ - public Object get(String name, Scriptable start) { - // register property for PropertyRecorder interface - if (isRecording) { - changedProperties.add(name); - } - // expose thread scope as global variable "global" - if (isThreadScope && "global".equals(name)) { - return this; - } - return super.get(name, start); - } - - /** - * - * - * @param skinobj ... - * @param paramobj ... - * - * @return ... - */ - public boolean renderSkin(Object skinobj, Object paramobj) - throws UnsupportedEncodingException, IOException { - RhinoEngine engine = RhinoEngine.getRhinoEngine(); - Skin skin = engine.toSkin(skinobj, "global"); - - if (skin != null) { - skin.render(engine.reval, null, - (paramobj == Undefined.instance) ? null : paramobj); - } - - return true; - } - - /** - * - * - * @param skinobj ... - * @param paramobj ... - * - * @return ... - */ - public String renderSkinAsString(Object skinobj, Object paramobj) - throws UnsupportedEncodingException, IOException { - RhinoEngine engine = RhinoEngine.getRhinoEngine(); - Skin skin = engine.toSkin(skinobj, "global"); - - if (skin != null) { - return skin.renderAsString(engine.reval, null, - (paramobj == Undefined.instance) ? null : paramobj); - } - - return ""; - } - - /** - * - * - * @param propname ... - * @param defvalue ... - * - * @return ... - */ - public String getProperty(String propname, Object defvalue) { - if (defvalue == Undefined.instance) { - return app.getProperty(propname); - } else { - return app.getProperty(propname, toString(defvalue)); - } - } - - /** - * - * - * @param user ... - * @param pwd ... - * - * @return ... - */ - public boolean authenticate(String user, String pwd) { - return app.authenticate(user, pwd); - } - - /** - * Create a Skin object from a string - * - * @param str the source string to parse - * - * @return a parsed skin object - */ - public Object createSkin(String str) { - return Context.toObject(new Skin(str, app), this); - } - - /** - * Get a Helma DB connection specified in db.properties - * - * @param dbsource the db source name - * - * @return a DatabaseObject for the specified DbConnection - */ - public Object getDBConnection(String dbsource) throws Exception { - if (dbsource == null) - throw new EvaluatorException("Wrong number of arguments in getDBConnection(dbsource)"); - DbSource dbsrc = app.getDbSource (dbsource); - if (dbsrc == null) - throw new EvaluatorException("DbSource "+dbsource+" does not exist"); - DatabaseObject db = new DatabaseObject (dbsrc); - return Context.toObject(db, this); - } - - /** - * Retrieve a Document from the specified URL. - * - * @param location the URL to retrieve - * @param condition either a LastModified date or an ETag string for conditional GETs - * @param timeout the optional timeout value in milliseconds used for - * connecting to and reading from the given URL. - * - * @return a wrapped MIME object - */ - public Object getURL(String location, Object condition, Object timeout) { - if (location == null) { - return null; - } - - try { - URL url = new URL(location); - URLConnection con = url.openConnection(); - - // do we have if-modified-since or etag headers to set? - if (condition != null && condition != Undefined.instance) { - if (condition instanceof Scriptable) { - Scriptable scr = (Scriptable) condition; - if ("Date".equals(scr.getClassName())) { - Date date = new Date((long) ScriptRuntime.toNumber(scr)); - - con.setIfModifiedSince(date.getTime()); - - SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", - Locale.UK); - - format.setTimeZone(TimeZone.getTimeZone("GMT")); - con.setRequestProperty("If-Modified-Since", format.format(date)); - }else { - con.setRequestProperty("If-None-Match", scr.toString()); - } - } else { - con.setRequestProperty("If-None-Match", condition.toString()); - } - } - - String httpUserAgent = app.getProperty("httpUserAgent"); - - if (httpUserAgent != null) { - con.setRequestProperty("User-Agent", httpUserAgent); - } - - if (timeout != null && timeout != Undefined.instance) { - int time = ScriptRuntime.toInt32(timeout); - con.setConnectTimeout(time); - con.setReadTimeout(time); - } - - con.setAllowUserInteraction(false); - - String filename = url.getFile(); - String contentType = con.getContentType(); - long lastmod = con.getLastModified(); - String etag = con.getHeaderField("ETag"); - int length = con.getContentLength(); - int resCode = 0; - - if (con instanceof HttpURLConnection) { - resCode = ((HttpURLConnection) con).getResponseCode(); - } - - ByteArrayOutputStream body = new ByteArrayOutputStream(); - - if ((length != 0) && (resCode != 304)) { - InputStream in = new BufferedInputStream(con.getInputStream()); - byte[] b = new byte[1024]; - int read; - - while ((read = in.read(b)) > -1) - body.write(b, 0, read); - - in.close(); - } - - MimePart mime = new MimePart(filename, body.toByteArray(), contentType); - - if (lastmod > 0) { - mime.setLastModified(new Date(lastmod)); - } - - mime.setETag(etag); - - return Context.toObject(mime, this); - } catch (Exception x) { - app.logError("Error getting URL "+location, x); - } - - return null; - } - - /** - * Try to parse an object to a XML DOM tree. The argument must be - * either a URL, a piece of XML, an InputStream or a Reader. - */ - public Object getXmlDocument(Object src) { - try { - Object p = src; - if (p instanceof Wrapper) { - p = ((Wrapper) p).unwrap(); - } - Object doc = XmlUtils.parseXml(p); - - return Context.toObject(doc, this); - } catch (Exception x) { - app.logError("Error creating XML document", x); - } - - return null; - } - - /** - * Try to parse an object to a XML DOM tree. The argument must be - * either a URL, a piece of XML, an InputStream or a Reader. - */ - public Object getHtmlDocument(Object src) { - try { - Object p = src; - if (p instanceof Wrapper) { - p = ((Wrapper) p).unwrap(); - } - Object doc = helma.util.XmlUtils.parseHtml(p); - - return Context.toObject(doc, this); - } catch (IOException iox) { - app.logError("Error creating HTML document", iox); - } catch (SAXException sx) { - app.logError("Error creating HTML document", sx); - } - - return null; - } - - /** - * Creates a libary namespace in the global scope. - * - * @param name the name of the libary namespace - * @deprecated should be implemented in JavaScript instead - */ - @Deprecated - public void defineLibraryScope(final String name) { - Object obj = get(name, this); - if (obj != NOT_FOUND) { - // put the property again to fool PropertyRecorder - // into believing it has been renewed - put(name, this, obj); - return; - } - ScriptableObject scope = new NativeObject() { - private static final long serialVersionUID = 9205558066617631601L; - - public String getClassName() { - return name; - } - }; - scope.setPrototype(ScriptableObject.getObjectPrototype(this)); - put(name, this, scope); - } - - /** - * Wrap a java.util.Map so that it looks and behaves like a native JS object - * @param obj a map - * @return a wrapper that makes the map look like a JS object - */ - public Object wrapJavaMap(Object obj) { - if (obj instanceof Wrapper) { - obj = ((Wrapper) obj).unwrap(); - } - if (!(obj instanceof Map)) { - throw ScriptRuntime.constructError("TypeError", - "Invalid argument to wrapMap(): " + obj); - } - return new MapWrapper((Map) obj, core); - } - - /** - * Unwrap a map previously wrapped using {@link #wrapJavaMap(Object)}. - * @param obj the wrapped map - * @return the map exposed as java object - */ - public Object unwrapJavaMap(Object obj) { - if (!(obj instanceof MapWrapper)) { - throw ScriptRuntime.constructError("TypeError", - "Invalid argument to unwrapMap(): " + obj); - } - obj = ((MapWrapper) obj).unwrap(); - return new NativeJavaObject(core.global, obj, Map.class); - } - - /** - * Convert an object into a wrapper that exposes the java - * methods of the object to JavaScript. This is useful for - * treating native numbers, strings, etc as their java - * counterpart such as java.lang.Double, java.lang.String etc. - * @param obj a java object that is wrapped in a special way - * Rhino - * @return the object wrapped as NativeJavaObject, exposing - * the public methods of the underlying class. - */ - public Object toJava(Object obj) { - if (obj == null || obj instanceof NativeJavaObject - || obj == Undefined.instance) { - return obj; - } - if (obj instanceof Wrapper) { - obj = ((Wrapper) obj).unwrap(); - } else if (obj instanceof Scriptable) { - String className = ((Scriptable) obj).getClassName(); - if ("Date".equals(className)) { - return new NativeJavaObject(this, - new Date((long) ScriptRuntime.toNumber(obj)), null); - } - } - return new NativeJavaObject(this, obj, null); - } - - /** - * - * - * @param obj ... - * - * @return ... - */ - public String format(Object obj) { - return HtmlEncoder.encode(toString(obj)); - } - - /** - * - * - * @param obj ... - * - * @return ... - */ - public String formatParagraphs(Object obj) { - String str = toString(obj); - - if (str == null) { - return null; - } - - int l = str.length(); - - if (l == 0) { - return ""; - } - - // try to make stringbuffer large enough from the start - StringBuffer buffer = new StringBuffer(Math.round(l * 1.4f)); - - HtmlEncoder.encode(str, buffer, true, null); - - return buffer.toString(); - } - - /** - * - * - * @param str ... - */ - public void write(String str) { - System.out.print(str); - } - - /** - * - * - * @param str ... - */ - public void writeln(String str) { - System.out.println(str); - } - - /** - * The seal function seals all supplied arguments. - */ - public static void seal(Context cx, Scriptable thisObj, Object[] args, - Function funObj) - { - for (int i = 0; i != args.length; ++i) { - Object arg = args[i]; - if (!(arg instanceof ScriptableObject) || arg == Undefined.instance) - { - if (!(arg instanceof Scriptable) || arg == Undefined.instance) - { - throw new EvaluatorException("seal() can only be applied to Objects"); - } else { - throw new EvaluatorException("seal() can only be applied to Objects"); - } - } - } - - for (int i = 0; i != args.length; ++i) { - Object arg = args[i]; - ((ScriptableObject)arg).sealObject(); - } - } - - /** - * Serialize a JavaScript object to a file. - */ - public static void serialize(Context cx, Scriptable thisObj, - Object[] args, Function funObj) - throws IOException - { - if (args.length < 2) { - throw Context.reportRuntimeError( - "Expected an object to serialize and a filename to write " + - "the serialization to"); - } - Object obj = args[0]; - File file = new File(Context.toString(args[1])).getAbsoluteFile(); - FileOutputStream fos = new FileOutputStream(file); - Scriptable scope = RhinoCore.getCore().global; - // use a ScriptableOutputStream that unwraps Wrappers - ScriptableOutputStream out = new ScriptableOutputStream(fos, scope) { - protected Object replaceObject(Object obj) throws IOException { - if (obj instanceof Wrapper) - obj = ((Wrapper) obj).unwrap(); - return super.replaceObject(obj); - } - }; - out.writeObject(obj); - out.close(); - } - - /** - * Read a previously serialized JavaScript object from a file. - */ - public static Object deserialize(Context cx, Scriptable thisObj, - Object[] args, Function funObj) - throws IOException, ClassNotFoundException - { - if (args.length < 1) { - throw Context.reportRuntimeError( - "Expected a filename to read the serialization from"); - } - File file = new File(Context.toString(args[0])).getAbsoluteFile(); - FileInputStream fis = new FileInputStream(file); - Scriptable scope = RhinoCore.getCore().global; - ObjectInputStream in = new ScriptableInputStream(fis, scope); - Object deserialized = in.readObject(); - in.close(); - return Context.toObject(deserialized, scope); - } - - /** - * Set DONTENUM attrubutes on the given properties in this object. - * This is set on the JavaScript Object prototype. - */ - public static Object dontEnum (Context cx, Scriptable thisObj, - Object[] args, Function funObj) { - if (!(thisObj instanceof ScriptableObject)) { - throw new EvaluatorException("dontEnum() called on non-ScriptableObject"); - } - ScriptableObject obj = (ScriptableObject) thisObj; - for (int i=0; i (i + 2)) { - if ((i - lastIdx) > 0) { - partBuffer.add(new HspBodyPart(new String(cnt, lastIdx, - i - lastIdx), true)); - } - - String script = new String(cnt, i + 2, (j - i) - 2); - - partBuffer.add(new HspBodyPart(script, false)); - lastIdx = j + 2; - } - - i = j + 1; - } - } - - if (lastIdx < l) { - partBuffer.add(new HspBodyPart(new String(cnt, lastIdx, l - lastIdx), - true)); - } - - StringBuffer templateBody = new StringBuffer(); - int nparts = partBuffer.size(); - - for (int k = 0; k < nparts; k++) { - HspBodyPart nextPart = (HspBodyPart) partBuffer.get(k); - - if (nextPart.isStatic || nextPart.content.trim().startsWith("=")) { - // check for <%= ... %> statements - if (!nextPart.isStatic) { - nextPart.content = nextPart.content.trim().substring(1).trim(); - - // cut trailing ";" - while (nextPart.content.endsWith(";")) - nextPart.content = nextPart.content.substring(0, - nextPart.content.length() - - 1); - } - - StringTokenizer st = new StringTokenizer(nextPart.content, "\r\n", true); - String nextLine = st.hasMoreTokens() ? st.nextToken() : null; - - // count newLines we "swallow", see explanation below - int newLineCount = 0; - - templateBody.append("res.write ("); - - if (nextPart.isStatic) { - templateBody.append("\""); - } - - while (nextLine != null) { - if ("\n".equals(nextLine)) { - // append a CRLF - newLineCount++; - templateBody.append("\\r\\n"); - } else if (!"\r".equals(nextLine)) { - try { - StringReader lineReader = new StringReader(nextLine); - int c = lineReader.read(); - - while (c > -1) { - if (nextPart.isStatic && - (((char) c == '"') || ((char) c == '\\'))) { - templateBody.append('\\'); - } - - templateBody.append((char) c); - c = lineReader.read(); - } - } catch (IOException srx) { - } - } - - nextLine = st.hasMoreTokens() ? st.nextToken() : null; - } - - if (nextPart.isStatic) { - templateBody.append("\""); - } - - templateBody.append("); "); - - // append the number of lines we have "swallowed" into - // one write statement, so error messages will *approximately* - // give correct line numbers. - for (int i = 0; i < newLineCount; i++) { - templateBody.append("\r\n"); - } - } else { - templateBody.append(nextPart.content); - - if (!nextPart.content.trim().endsWith(";")) { - templateBody.append(";"); - } - } - } - - // templateBody.append ("\r\nreturn null;\r\n"); - return templateBody.toString(); - } - - static class HspBodyPart { - String content; - boolean isPart; - boolean isStatic; - - public HspBodyPart(String content, boolean isStatic) { - isPart = false; - this.content = content; - this.isStatic = isStatic; - } - - public String getName() { - return isStatic ? null : content; - } - - public String toString() { - return "Template.Part [" + content + "," + isStatic + "]"; - } - } -} diff --git a/src/main/java/helma/scripting/rhino/HopObject.java b/src/main/java/helma/scripting/rhino/HopObject.java deleted file mode 100644 index 3682da40..00000000 --- a/src/main/java/helma/scripting/rhino/HopObject.java +++ /dev/null @@ -1,1153 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino; - -import helma.framework.core.*; -import helma.framework.repository.Resource; -import helma.objectmodel.*; -import helma.objectmodel.db.*; -import helma.objectmodel.db.Node; -import org.mozilla.javascript.*; - -import java.lang.reflect.Method; -import java.util.*; -import java.io.UnsupportedEncodingException; -import java.io.IOException; - -/** - * - */ -public class HopObject extends ScriptableObject implements Wrapper, PropertyRecorder { - - private static final long serialVersionUID = 1329862822101428427L; - - String className; - final NodeProxy proxy; - final RhinoCore core; - - // fields to implement PropertyRecorder - private boolean isRecording = false; - private HashSet changedProperties; - - /** - * Creates a new HopObject prototype. - * - * @param className the prototype name - * @param core the RhinoCore - */ - protected HopObject(String className, RhinoCore core) { - this.className = className; - this.core = core; - this.proxy = null; - setParentScope(core.global); - } - - /** - * Creates a new HopObject. - * - * @param className the className - * @param core the RhinoCore - * @param node the wrapped node - * @param proto the object's prototype - */ - protected HopObject(String className, RhinoCore core, - INode node, Scriptable proto) { - this.className = className; - this.core = core; - this.proxy = new NodeProxy(node); - if (proto != null) - setPrototype(proto); - setParentScope(core.global); - } - - /** - * Creates a new HopObject. - * - * @param className the className - * @param core the RhinoCore - * @param handle the handle for the wrapped node - * @param proto the object's prototype - */ - protected HopObject(String className, RhinoCore core, - NodeHandle handle, Scriptable proto) { - this.className = className; - this.core = core; - this.proxy = new NodeProxy(handle); - if (proto != null) - setPrototype(proto); - setParentScope(core.global); - } - - /** - * Initialize HopObject prototype for Rhino scope. - * - * @param core the RhinoCore - * @return the HopObject prototype - */ - public static HopObject init(RhinoCore core) { - int attributes = DONTENUM | PERMANENT; - - // create prototype object - HopObject proto = new HopObject("HopObject", core); - proto.setPrototype(getObjectPrototype(core.global)); - - // install JavaScript methods and properties - Method[] methods = HopObject.class.getDeclaredMethods(); - for (int i=0; i= 0; i--) { - Resource resource = resources[i]; - if (resource.exists() && resource.getShortName().equals(resourceName)) - return Context.toObject(resource, core.global); - } - prototype = prototype.getParentPrototype(); - } - return null; - } - - - /** - * Returns an array containing the prototype's resource with a given name. - * - * @param resourceName the name of the resource, e.g. "type.properties", - * "messages.properties", "script.js", etc. - * @return an array of resources with the given name - */ - public Object jsFunction_getResources(String resourceName) { - RhinoEngine engine = RhinoEngine.getRhinoEngine(); - Prototype prototype = engine.core.app.getPrototypeByName(className); - ArrayList a = new ArrayList(); - while (prototype != null) { - Resource[] resources = prototype.getResources(); - for (int i = resources.length - 1; i >= 0; i--) { - Resource resource = resources[i]; - if (resource.exists() && resource.getShortName().equals(resourceName)) - a.add(Context.toObject(resource, core.global)); - } - prototype = prototype.getParentPrototype(); - } - return Context.getCurrentContext().newArray(core.global, a.toArray()); - } - - /** - * Render a skin and return its output as string. - * - * @param skinobj The skin object or name - * @param paramobj An optional parameter object - * - * @return ... - */ - public String jsFunction_renderSkinAsString(Object skinobj, Object paramobj) - throws UnsupportedEncodingException, IOException { - RhinoEngine engine = RhinoEngine.getRhinoEngine(); - Skin skin = engine.toSkin(skinobj, className); - INode node = getNode(); - - if (skin != null) { - return skin.renderAsString(engine.reval, node, - (paramobj == Undefined.instance) ? null : paramobj); - } - - return ""; - } - - /** - * Get the URL for this object with the application - * @param action optional action name - * @param params optional query parameters - * @return the URL for the object - * @throws UnsupportedEncodingException if the application's charset property - * is not a valid encoding name - */ - public Object jsFunction_href(Object action, Object params) - throws UnsupportedEncodingException, IOException { - if (proxy == null) { - return null; - } - - String actionName = null; - Map queryParams = params instanceof Scriptable ? - core.scriptableToProperties((Scriptable) params) : null; - INode node = getNode(); - - if (action != null) { - if (action instanceof Wrapper) { - actionName = ((Wrapper) action).unwrap().toString(); - } else if (!(action instanceof Undefined)) { - actionName = action.toString(); - } - } - - String basicHref = core.app.getNodeHref(node, actionName, queryParams); - - return core.postProcessHref(node, className, basicHref); - } - - /** - * Get a childObject by name/id or index - * - * @param id The name/id or index, depending if the argument is a String or Number. - * - * @return ... - */ - public Object jsFunction_get(Object id) { - if (proxy == null || id == null || id == Undefined.instance) { - return null; - } - - Object child; - INode node = getNode(); - - if (id instanceof Number) { - child = node.getSubnodeAt(((Number) id).intValue()); - } else { - child = node.getChildElement(id.toString()); - } - - if (child != null) { - return Context.toObject(child, core.global); - } - return null; - } - - /** - * Get a child object by ID - * - * @param id the child id. - * - * @return ... - */ - public Object jsFunction_getById(Object id) { - if (proxy == null || id == null || id == Undefined.instance) { - return null; - } - - INode node = getNode(); - String idString = (id instanceof Double) ? - Long.toString(((Double) id).longValue()) : - id.toString(); - Object n = node.getSubnode(idString); - - if (n == null) { - return null; - } else { - return Context.toObject(n, core.global); - } - } - - /** - * Set a property on this HopObject - * - * @param id The name/id or index, depending if the argument is a String or Number. - * - * @return ... - */ - public boolean jsFunction_set(Object id, Object value) { - if (id == Undefined.instance || value == Undefined.instance) { - throw new EvaluatorException("HopObject.set() called with wrong number of arguments"); - } - if (proxy == null) { - return false; - } - - if (id instanceof Number) { - if (!(value instanceof HopObject)) { - throw new EvaluatorException("Can only set HopObjects as child objects in HopObject.set()"); - } - - INode node = getNode(); - - int idx = (((Number) id).intValue()); - INode n = ((HopObject) value).getNode(); - - node.addNode(n, idx); - - } else if (id != null) { - put(id.toString(), this, value); - } - - return true; - } - - /** - * - * - * @return ... - */ - public int jsFunction_count() { - if (proxy == null) { - return 0; - } - INode node = getNode(); - return node.numberOfNodes(); - } - - /** - * - * - * @return ... - */ - public int jsFunction_size() { - return jsFunction_count(); - } - - /** - * Prefetch child objects from (relational) database. - */ - public void jsFunction_prefetchChildren(Object startArg, Object lengthArg) { - // check if we were called with no arguments - if (startArg == Undefined.instance && lengthArg == Undefined.instance) { - prefetchChildren(0, 1000); - } else { - int start = (int) ScriptRuntime.toNumber(startArg); - int length = (int) ScriptRuntime.toNumber(lengthArg); - prefetchChildren(start, length); - } - } - - private void prefetchChildren(int start, int length) { - if (proxy != null) { - INode node = getNode(); - if (node instanceof Node) { - Node n = (Node) node; - if (n.getState() != Node.TRANSIENT && n.getState() != Node.NEW) { - n.prefetchChildren(start, length); - } - } - } - } - - /** - * Clear the node's cache node. - */ - public void jsFunction_clearCache() { - if (proxy != null) { - INode node = getNode(); - node.clearCacheNode(); - } - } - - /** - * Return the full list of child objects in a JavaScript Array. - * This is called by jsFunction_list() if called with no arguments. - * - * @return A JavaScript Array containing all child objects - */ - private Scriptable list() { - Node node = (Node) getNode(); - node.loadNodes(); - SubnodeList list = node.getSubnodeList(); - if (list == null) { - return Context.getCurrentContext().newArray(core.global, 0); - } - Object[] array = list.toArray(); - for (int i = 0; i < array.length; i++) { - array[i] = core.getNodeWrapper((NodeHandle) array[i]); - } - return Context.getCurrentContext().newArray(core.global, array); - } - - /** - * Return a JS array of child objects with the given start and length. - * - * @return A JavaScript Array containing the specified child objects - */ - public Scriptable jsFunction_list(Object startArg, Object lengthArg) { - if (startArg == Undefined.instance && lengthArg == Undefined.instance) { - return list(); - } - - int start = (int) ScriptRuntime.toNumber(startArg); - int length = (int) ScriptRuntime.toNumber(lengthArg); - - if (start < 0 || length < 0) { - throw new EvaluatorException("Arguments must not be negative in HopObject.list(start, length)"); - } - - Node node = (Node) getNode(); - prefetchChildren(start, length); - SubnodeList list = node.getSubnodeList(); - length = list == null ? 0 : Math.min(list.size() - start, length); - if (length <= 0) { - return Context.getCurrentContext().newArray(core.global, 0); - } - Object[] array = new Object[length]; - - for (int i = 0; i < length; i++) { - Object obj = list.get(start + i); - if (obj != null) { - array[i] = Context.toObject(obj, core.global); - } - } - - return Context.getCurrentContext().newArray(core.global, array); - } - - /** - * - * - * @param child ... - * - * @return ... - */ - public boolean jsFunction_add(Object child) { - if (proxy == null || child == null) { - return false; - } - - INode node = getNode(); - - if (child instanceof HopObject) { - node.addNode(((HopObject) child).getNode()); - return true; - } else if (child instanceof INode) { - node.addNode((INode) child); - return true; - } - - return false; - } - - /** - * - * - * @param index ... - * @param child ... - * - * @return ... - */ - public boolean jsFunction_addAt(int index, Object child) { - if (child == null) { - return false; - } - - INode node = getNode(); - - if (child instanceof HopObject) { - node.addNode(((HopObject) child).getNode(), index); - - return true; - } else if (child instanceof INode) { - node.addNode((INode) child, index); - - return true; - } - - return false; - } - - /** - * Remove this object from the database. - */ - public boolean jsFunction_remove(Object arg) { - // shield off usage of old deprecated version taking an argument - if (arg != Undefined.instance) { - System.err.println(" ************* WARNING *************************"); - System.err.println(" The version of HopObject.remove(child) you were "); - System.err.println(" trying to use has been deprecated. Please use "); - System.err.println(" hopobj.removeChild(child)"); - System.err.println(" to remove a child object from a collection without"); - System.err.println(" deleting it, or "); - System.err.println(" hopobj.remove()"); - System.err.println(" without argument to delete the object itself."); - System.err.println(" *************************************************"); - throw new RuntimeException("Caught deprecated usage of HopObject.remove(child)"); - } - - INode node = getNode(); - - return node.remove(); - } - - /** - * Remove a child node from this node's collection without deleting - * it from the database. - */ - public boolean jsFunction_removeChild(Object child) { - - INode node = getNode(); - - if (child instanceof HopObject) { - HopObject hobj = (HopObject) child; - - if (hobj.proxy != null) { - node.removeNode(hobj.getNode()); - return true; - } - } - - return false; - } - - /** - * Makes the HopObject and all its reachable descendants persistent. - * - * @return the ID of the newly persisted HopObject or null if operation failed - */ - public Object jsFunction_persist() { - - INode node = getNode(); - - if (node instanceof Node) { - ((Node) node).persist(); - return node.getID(); - } - return null; - } - - /** - * Invalidate the node itself or a subnode - */ - public boolean jsFunction_invalidate(Object childId) { - if (childId != null && proxy != null) { - INode node = getNode(); - if (!(node instanceof Node)) { - return true; - } - if (childId == Undefined.instance) { - if (node.getState() == INode.INVALID) { - return true; - } - ((Node) node).invalidate(); - } else { - ((Node) node).invalidateNode(childId.toString()); - } - } - - return true; - } - - /** - * Check whether the wrapped Node is persistent. - * This also returns true if the Node is being inserted in the database, - * or it has been in database and is in the proces of being deleted. - * @return true if the the wrapped Node has a valid database id. - */ - public boolean jsFunction_isPersistent() { - if (proxy == null) { - return false; - } - INode node = getNode(); - int nodeState = node.getState(); - return nodeState != INode.TRANSIENT; - } - - /** - * Check whether the wrapped Node is transient. - * This also returns false if the Node is being inserted in the database, - * or it has been in database and is in the proces of being deleted. - * @return true if the the wrapped Node is not stored in a database. - */ - public boolean jsFunction_isTransient() { - if (proxy == null) { - return true; - } - INode node = getNode(); - int nodeState = node.getState(); - return nodeState == INode.TRANSIENT; - } - - /** - * Check if node is contained in the subnode collection. - * Return its index position if it is, and -1 otherwise. - */ - public int jsFunction_indexOf(Object obj) { - - if (proxy != null && obj instanceof HopObject) { - INode node = getNode(); - return node.contains(((HopObject) obj).getNode()); - } - return -1; - } - - /** - * Check if node is contained in the subnode collection. - * Return its index position if it is, and -1 otherwise. - * @deprecated use indexOf(Object) instead. - */ - @Deprecated - public int jsFunction_contains(Object obj) { - return jsFunction_indexOf(obj); - } - - /** - * Set a property in this HopObject - * - * @param name property name - * @param start - * @param value ... - */ - public void put(String name, Scriptable start, Object value) { - if (proxy == null) { - // redirect the scripted constructor to __constructor__, - // constructor is set to the native constructor method. - if ("constructor".equals(name) && value instanceof NativeFunction) { - name = "__constructor__"; - } - // register property for PropertyRecorder interface - if (isRecording) { - changedProperties.add(name); - if (value instanceof Function) { - // reset function's parent scope, needed because of the way we compile - // prototype code, using the prototype objects as scope - Scriptable scriptable = (Scriptable) value; - while (scriptable != null) { - Scriptable scope = scriptable.getParentScope(); - if (scope == this) { - scriptable.setParentScope(core.global); - break; - } - scriptable = scope; - } - } - } - super.put(name, start, value); - } else if (super.has(name, start)) { - // if property is defined as ScriptableObject slot - // (e.g. via __defineGetter__/__defineSetter__) - // use ScriptableObject.put to set it - super.put(name, start, value); - } else { - INode node = getNode(); - - if ("subnodeRelation".equals(name)) { - node.setSubnodeRelation(value == null ? null : value.toString()); - } - - if (value instanceof Wrapper) { - value = ((Wrapper) value).unwrap(); - } - - if ((value == null) || (value == Undefined.instance)) { - node.unset(name); - } else if (value instanceof Scriptable) { - Scriptable s = (Scriptable) value; - String className = s.getClassName(); - if ("Date".equals(className)) { - node.setDate(name, new Date((long) ScriptRuntime.toNumber(s))); - } else if ("String".equals(className)) { - node.setString(name, ScriptRuntime.toString(s)); - } else if ("Number".equals(className)) { - node.setFloat(name, ScriptRuntime.toNumber(s)); - } else if ("Boolean".equals(className)) { - node.setBoolean(name, ScriptRuntime.toBoolean(s)); - } else { - node.setJavaObject(name, s); - } - } else if (value instanceof String) { - node.setString(name, value.toString()); - } else if (value instanceof Boolean) { - node.setBoolean(name, ((Boolean) value).booleanValue()); - } else if (value instanceof Number) { - node.setFloat(name, ((Number) value).doubleValue()); - } else if (value instanceof Date) { - node.setDate(name, (Date) value); - } else if (value instanceof INode) { - node.setNode(name, (INode) value); - } else { - node.setJavaObject(name, value); - } - } - } - - /** - * Check if a property is set in this HopObject - * - * @param name the property name - * @param start the object in which the lookup began - * @return true if the property was found - */ - public boolean has(String name, Scriptable start) { - if (proxy != null) { - INode node = getNode(); - if (node.get(name) != null) { - return true; - } - } - return super.has(name, start); - } - - /** - * - * - * @param name ... - */ - public void delete(String name) { - if ((proxy != null)) { - INode node = getNode(); - node.unset(name); - } - super.delete(name); - } - - /** - * - * - * @param name ... - * @param start ... - * - * @return ... - */ - public Object get(String name, Scriptable start) { - Object obj = super.get(name, start); - if (obj == Scriptable.NOT_FOUND && proxy != null) { - obj = getFromNode(name); - } - return obj; - } - - /** - * Retrieve a property only from the node itself, not the underlying prototype object. - * This is called directly when we call get(x) on a JS HopObject, since we don't want - * to return the prototype functions in that case. - */ - private Object getFromNode(String name) { - if (proxy != null && name != null && name.length() > 0) { - - INode node = getNode(); - - // Property names starting with an underscore is interpreted - // as internal properties - if (name.charAt(0) == '_') { - Object value = getInternalProperty(node, name); - if (value != NOT_FOUND) - return value; - } - - if ("subnodeRelation".equals(name)) { - return node.getSubnodeRelation(); - } - - IProperty p = node.get(name); - - if (p != null) { - switch (p.getType()) { - case IProperty.STRING: - case IProperty.INTEGER: - case IProperty.FLOAT: - case IProperty.BOOLEAN: - return p.getValue(); - } - - Context cx = Context.getCurrentContext(); - - if (p.getType() == IProperty.DATE) { - Date d = p.getDateValue(); - - if (d == null) { - return null; - } else { - Object[] args = { Long.valueOf(d.getTime()) }; - try { - return cx.newObject(core.global, "Date", args); - } catch (JavaScriptException nafx) { - return null; - } - } - } - - if (p.getType() == IProperty.NODE) { - INode n = p.getNodeValue(); - - if (n == null) { - return null; - } else { - return Context.toObject(n, core.global); - } - } - - if (p.getType() == IProperty.JAVAOBJECT) { - Object obj = p.getJavaObjectValue(); - - if (obj == null) { - return null; - } else { - return Context.toObject(obj, core.global); - } - } - } - - DbMapping dbmap = node.getDbMapping(); - if (dbmap != null && dbmap.propertyToRelation(name) != null) { - return null; - } - } - - return NOT_FOUND; - } - - private Object getInternalProperty(INode node, String name) { - if ("__id__".equals(name) || "_id".equals(name)) { - return node.getID(); - } - - if ("__proto__".equals(name)) { - return getPrototype(); // prototype object - } - - if ("__prototype__".equals(name) || "_prototype".equals(name)) { - return node.getPrototype(); // prototype name - } - - if ("__parent__".equals(name) || "_parent".equals(name)) { - return core.getNodeWrapper(node.getParent()); - } - - // some more internal properties - if ("__name__".equals(name)) { - return node.getName(); - } - - if ("__path__".equals(name)) { - return node.getPath(); - } - - if ("__hash__".equals(name)) { - return Integer.toString(node.hashCode()); - } - - if ("__node__".equals(name)) { - return new NativeJavaObject(core.global, node, null); - } - - if ("__created__".equalsIgnoreCase(name)) { - return new Date(node.created()); - } - - if ("__lastmodified__".equalsIgnoreCase(name)) { - return new Date(node.lastModified()); - } - - return NOT_FOUND; - } - - /** - * Return all property names of this object. This method is used by debugger. - * @return array containing the names of all properties defined in this object - */ - public Object[] getAllIds() { - if (proxy == null) { - return super.getAllIds(); - } - return getIds(); - } - - /** - * Return all "ordinary" property ids of this object. This "hides" the prototype methods. - * @return array containing the names of this object's data properties - */ - public Object[] getIds() { - if (proxy == null) { - // HopObject prototypes always return an empty array in order not to - // pollute actual HopObjects properties. Call getAllIds() to get - // a list of properties from a HopObject prototype. - return new Object[0]; - } - - INode node = getNode(); - - Enumeration en = node.properties(); - ArrayList list = new ArrayList(); - - while (en.hasMoreElements()) - list.add(en.nextElement()); - - return list.toArray(); - } - - /** - * - * - * @param idx ... - * @param start ... - * - * @return ... - */ - public boolean has(int idx, Scriptable start) { - if (proxy != null) { - INode node = getNode(); - - return (0 <= idx && idx < node.numberOfNodes()); - } - - return false; - } - - /** - * - * - * @param idx ... - * @param start ... - * - * @return ... - */ - public Object get(int idx, Scriptable start) { - if (proxy != null) { - INode node = getNode(); - - INode n = node.getSubnodeAt(idx); - - if (n != null) { - return Context.toObject(n, core.global); - } - } - - return NOT_FOUND; - } - - /** - * Custom == operator. - * Must return {@link org.mozilla.javascript.Scriptable#NOT_FOUND} if this object does not - * have custom equality operator for the given value, - * Boolean.TRUE if this object is equivalent to value, - * Boolean.FALSE if this object is not equivalent to - * value. - */ - protected Object equivalentValues(Object value) { - if (value == this) { - return Boolean.TRUE; - } - if (value instanceof HopObject && proxy != null - && proxy.equivalentValues(((HopObject) value).proxy)) { - return Boolean.TRUE; - } - return Scriptable.NOT_FOUND; - } - - /** - * Return a string representation of this HopObject. - * @return a string representing this HopObject - */ - public String toString() { - if (proxy == null) { - return "[HopObject prototype " + className + "]"; - } else { - return "[HopObject " + proxy.getNode().getName() + "]"; - } - } - - /** - * Tell this PropertyRecorder to start recording changes to properties - */ - public void startRecording() { - changedProperties = new HashSet(); - isRecording = true; - } - - /** - * Tell this PropertyRecorder to stop recording changes to properties - */ - public void stopRecording() { - isRecording = false; - } - - /** - * Returns a set containing the names of properties changed since - * the last time startRecording() was called. - * - * @return a Set containing the names of changed properties - */ - public Set getChangeSet() { - return changedProperties; - } - - /** - * Clear the set of changed properties. - */ - public void clearChangeSet() { - changedProperties = null; - } - - class NodeProxy { - private INode node; - private NodeHandle handle; - - NodeProxy(INode node) { - this.node = node; - if (node instanceof Node) { - handle = ((Node) node).getHandle(); - } - } - - NodeProxy(NodeHandle handle) { - this.handle = handle; - } - - synchronized INode getNode() { - if (node == null || node.getState() == Node.INVALID) { - if (handle != null) { - node = handle.getNode(core.app.getWrappedNodeManager()); - if (node != null) { - String protoname = node.getPrototype(); - // the actual prototype name may vary from the node handle's prototype name - if (className == null || !className.equals(protoname)) { - Scriptable proto = core.getValidPrototype(protoname); - if (proto == null) { - protoname = "HopObject"; - proto = core.getValidPrototype("HopObject"); - } - className = protoname; - setPrototype(proto); - } - } - } - if (node == null || node.getState() == Node.INVALID) { - // We probably have a deleted node. - // Replace with empty transient node to avoid throwing an exception. - node = new TransientNode(core.app); - } - } - return node; - } - - public boolean equivalentValues(NodeProxy other) { - if (handle == null) { - return other.node == this.node; - } else { - return handle == other.handle || handle.equals(other.handle); - } - } - } -} diff --git a/src/main/java/helma/scripting/rhino/HopObjectCtor.java b/src/main/java/helma/scripting/rhino/HopObjectCtor.java deleted file mode 100644 index 9bcbafb9..00000000 --- a/src/main/java/helma/scripting/rhino/HopObjectCtor.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ -package helma.scripting.rhino; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Properties; - -import helma.objectmodel.INode; -import helma.objectmodel.db.DbMapping; -import helma.objectmodel.db.DbKey; -import helma.objectmodel.db.Node; -import helma.objectmodel.db.WrappedNodeManager; - -import org.mozilla.javascript.*; - -public class HopObjectCtor extends FunctionObject { - - private static final long serialVersionUID = 3787907922712636030L; - - // init flag to trigger prototype compilation on - // static constructor property access - boolean initialized; - RhinoCore core; - Scriptable protoProperty; - - static Method hopObjCtor; - - static long collectionId = 0; - - static { - try { - hopObjCtor = HopObjectCtor.class.getMethod("jsConstructor", new Class[] { - Context.class, Object[].class, Function.class, Boolean.TYPE }); - } catch (NoSuchMethodException e) { - throw new RuntimeException("Error getting HopObjectCtor.jsConstructor()"); - } - } - - static final int attr = DONTENUM | PERMANENT; - - /** - * Create and install a HopObject constructor. - * Part of this is copied from o.m.j.FunctionObject.addAsConstructor(). - * - * @param prototype - */ - public HopObjectCtor(String protoName, RhinoCore core, Scriptable prototype) { - super(protoName, hopObjCtor, core.global); - this.core = core; - this.protoProperty = prototype; - addAsConstructor(core.global, prototype); - defineProperty("getById", new GetById(core.global), attr); - defineProperty("getCollection", new HopCollection(core.global), attr); - } - - /** - * This method is used as HopObject constructor from JavaScript. - */ - public static Object jsConstructor(Context cx, Object[] args, - Function ctorObj, boolean inNewExpr) - throws JavaScriptException { - HopObjectCtor ctor = (HopObjectCtor) ctorObj; - RhinoCore core = ctor.core; - String protoname = ctor.getFunctionName(); - - // if this is a java object prototype, create a new java object - // of the given class instead of a HopObject. - if (core.app.isJavaPrototype(protoname)) { - String classname = core.app.getJavaClassForPrototype(protoname); - try { - Class clazz = Class.forName(classname); - // try to get the constructor matching our arguments - Class[] argsTypes = new Class[args.length]; - for (int i=0; i 2) - throw new IllegalArgumentException("Wrong number of arguments in getById()"); - // If second argument is provided, use it as type name. - // Otherwise, use our own type name. - String type = args.length == 1 ? - HopObjectCtor.this.getFunctionName() : - Context.toString(args[1]); - - DbMapping dbmap = core.app.getDbMapping(type); - if (dbmap == null) - return null; - Object node = null; - try { - DbKey key = new DbKey(dbmap, Context.toString(args[0])); - node = core.app.getNodeManager().getNode(key); - } catch (Exception x) { - return null; - } - - if (node == null - || !HopObjectCtor.this.core.app.getPrototype(node) - .isInstanceOf(type)) { - return null; - } - - return Context.toObject(node, this); - } - - public int getArity() { - return 1; - } - - public int getLength() { - return 1; - } - - } - - class HopCollection extends BaseFunction { - - private static final long serialVersionUID = -4046933261468527204L; - - public HopCollection(Scriptable scope) { - ScriptRuntime.setFunctionProtoAndParent(this, scope); - } - - public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { - if (args.length != 1) { - throw new IllegalArgumentException("Wrong number of arguments in definePrototype()"); - } - if (!(args[0] instanceof Scriptable)) { - throw new IllegalArgumentException("Second argument to HopObject.definePrototype() must be Object"); - } - - Scriptable desc = (Scriptable) args[0]; - Properties childmapping = core.scriptableToProperties(desc); - if (!childmapping.containsKey("collection")) { - // if contained type isn't defined explicitly limit collection to our own type - childmapping.put("collection", HopObjectCtor.this.getFunctionName()); - } - - Properties props = new Properties(); - props.put("_children", childmapping); - DbMapping dbmap = new DbMapping(core.app, null, props, true); - dbmap.update(); - - WrappedNodeManager nmgr = core.app.getWrappedNodeManager(); - Node node = new Node("HopQuery", Long.toString(collectionId++), null, nmgr); - node.setDbMapping(dbmap); - node.setState(Node.VIRTUAL); - return new HopObject("HopQuery", core, node, core.hopObjectProto); - } - - public int getArity() { - return 1; - } - - public int getLength() { - return 1; - } - } - -} diff --git a/src/main/java/helma/scripting/rhino/JSAdapter.java b/src/main/java/helma/scripting/rhino/JSAdapter.java deleted file mode 100644 index 8ddcd9ec..00000000 --- a/src/main/java/helma/scripting/rhino/JSAdapter.java +++ /dev/null @@ -1,336 +0,0 @@ -/* - * The contents of this file are subject to the terms - * of the Common Development and Distribution License - * (the License). You may not use this file except in - * compliance with the License. - * - * You can obtain a copy of the license at - * https://glassfish.dev.java.net/public/CDDLv1.0.html or - * glassfish/bootstrap/legal/CDDLv1.0.txt. - * See the License for the specific language governing - * permissions and limitations under the License. - * - * When distributing Covered Code, include this CDDL - * Header Notice in each file and include the License file - * at glassfish/bootstrap/legal/CDDLv1.0.txt. - * If applicable, add the following below the CDDL Header, - * with the fields enclosed by brackets [] replaced by - * you own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - */ - -package helma.scripting.rhino; - -import org.mozilla.javascript.*; - -/** - * JSAdapter is java.lang.reflect.Proxy equivalent for JavaScript. JSAdapter - * calls specially named JavaScript methods on an adaptee object when property - * access is attempted on it. - * - * Example: - * - * var y = { - * __get__ : function (name) { ... } - * __has__ : function (name) { ... } - * __put__ : function (name, value) {...} - * __delete__ : function (name) { ... } - * __getIds__ : function () { ... } - * }; - * - * var x = new JSAdapter(y); - * - * x.i; // calls y.__get__ - * i in x; // calls y.__has__ - * x.p = 10; // calls y.__put__ - * delete x.p; // calls y.__delete__ - * for (i in x) { print(i); } // calls y.__getIds__ - * - * If a special JavaScript method is not found in the adaptee, then JSAdapter - * forwards the property access to the adaptee itself. - * - * JavaScript caller of adapter object is isolated from the fact that - * the property access/mutation/deletion are really calls to - * JavaScript methods on adaptee. Use cases include 'smart' - * properties, property access tracing/debugging, encaptulation with - * easy client access - in short JavaScript becomes more "Self" like. - * - * Note that Rhino already supports special properties like __proto__ - * (to set, get prototype), __parent__ (to set, get parent scope). We - * follow the same double underscore nameing convention here. Similarly - * the name JSAdapter is derived from JavaAdapter -- which is a facility - * to extend, implement Java classes/interfaces by JavaScript. - * - * @version 1.0 - * @author A. Sundararajan - * @since 1.6 - */ -public final class JSAdapter implements Scriptable, Function { - private JSAdapter(Scriptable obj) { - setAdaptee(obj); - } - - // initializer to setup JSAdapter prototype in the given scope - public static void init(Context cx, Scriptable scope, boolean sealed) - throws RhinoException { - JSAdapter obj = new JSAdapter(cx.newObject(scope)); - obj.setParentScope(scope); - obj.setPrototype(getFunctionPrototype(scope)); - obj.isPrototype = true; - ScriptableObject.defineProperty(scope, "JSAdapter", obj, - ScriptableObject.DONTENUM); - } - - public String getClassName() { - return "JSAdapter"; - } - - public Object get(String name, Scriptable start) { - Function func = getAdapteeFunction(GET_PROP); - if (func != null) { - return call(func, new Object[] { name }); - } else { - start = getAdaptee(); - return start.get(name, start); - } - } - - public Object get(int index, Scriptable start) { - Function func = getAdapteeFunction(GET_PROP); - if (func != null) { - return call(func, new Object[] { Integer.valueOf(index) }); - } else { - start = getAdaptee(); - return start.get(index, start); - } - } - - public boolean has(String name, Scriptable start) { - Function func = getAdapteeFunction(HAS_PROP); - if (func != null) { - Object res = call(func, new Object[] { name }); - return Context.toBoolean(res); - } else { - start = getAdaptee(); - return start.has(name, start); - } - } - - public boolean has(int index, Scriptable start) { - Function func = getAdapteeFunction(HAS_PROP); - if (func != null) { - Object res = call(func, new Object[] { Integer.valueOf(index) }); - return Context.toBoolean(res); - } else { - start = getAdaptee(); - return start.has(index, start); - } - } - - public void put(String name, Scriptable start, Object value) { - if (start == this) { - Function func = getAdapteeFunction(PUT_PROP); - if (func != null) { - call(func, new Object[] { name, value }); - } else { - start = getAdaptee(); - start.put(name, start, value); - } - } else { - start.put(name, start, value); - } - } - - public void put(int index, Scriptable start, Object value) { - if (start == this) { - Function func = getAdapteeFunction(PUT_PROP); - if( func != null) { - call(func, new Object[] { Integer.valueOf(index), value }); - } else { - start = getAdaptee(); - start.put(index, start, value); - } - } else { - start.put(index, start, value); - } - } - - public void delete(String name) { - Function func = getAdapteeFunction(DEL_PROP); - if (func != null) { - call(func, new Object[] { name }); - } else { - getAdaptee().delete(name); - } - } - - public void delete(int index) { - Function func = getAdapteeFunction(DEL_PROP); - if (func != null) { - call(func, new Object[] { Integer.valueOf(index) }); - } else { - getAdaptee().delete(index); - } - } - - public Scriptable getPrototype() { - return prototype; - } - - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - public Scriptable getParentScope() { - return parent; - } - - public void setParentScope(Scriptable parent) { - this.parent = parent; - } - - public Object[] getIds() { - Function func = getAdapteeFunction(GET_PROPIDS); - if (func != null) { - Object val = call(func, new Object[0]); - // in most cases, adaptee would return native JS array - if (val instanceof NativeArray) { - NativeArray array = (NativeArray) val; - Object[] res = new Object[(int)array.getLength()]; - for (int index = 0; index < res.length; index++) { - res[index] = mapToId(array.get(index, array)); - } - return res; - } else if (val instanceof NativeJavaArray) { - // may be attempt wrapped Java array - Object tmp = ((NativeJavaArray)val).unwrap(); - Object[] res; - if (tmp.getClass() == Object[].class) { - Object[] array = (Object[]) tmp; - res = new Object[array.length]; - for (int index = 0; index < array.length; index++) { - res[index] = mapToId(array[index]); - } - } else { - // just return an empty array - res = Context.emptyArgs; - } - return res; - } else { - // some other return type, just return empty array - return Context.emptyArgs; - } - } else { - return getAdaptee().getIds(); - } - } - - public boolean hasInstance(Scriptable scriptable) { - if (scriptable instanceof JSAdapter) { - return true; - } else { - Scriptable proto = scriptable.getPrototype(); - while (proto != null) { - if (proto.equals(this)) return true; - proto = proto.getPrototype(); - } - return false; - } - } - - public Object getDefaultValue(Class hint) { - return ScriptableObject.getDefaultValue(this, hint); - } - - public Object call(Context cx, Scriptable scope, Scriptable thisObj, - Object[] args) - throws RhinoException { - if (isPrototype) { - return construct(cx, scope, args); - } else { - Scriptable tmp = getAdaptee(); - if (tmp instanceof Function) { - return ((Function)tmp).call(cx, scope, tmp, args); - } else { - throw Context.reportRuntimeError("TypeError: not a function"); - } - } - } - - public Scriptable construct(Context cx, Scriptable scope, Object[] args) - throws RhinoException { - if (isPrototype) { - Scriptable topLevel = ScriptableObject.getTopLevelScope(scope); - JSAdapter newObj; - if (args.length > 0) { - newObj = new JSAdapter(Context.toObject(args[0], topLevel)); - } else { - throw Context.reportRuntimeError("JSAdapter requires adaptee"); - } - return newObj; - } else { - Scriptable tmp = getAdaptee(); - if (tmp instanceof Function) { - return ((Function)tmp).construct(cx, scope, args); - } else { - throw Context.reportRuntimeError("TypeError: not a constructor"); - } - } - } - - public Scriptable getAdaptee() { - return adaptee; - } - - public void setAdaptee(Scriptable adaptee) { - if (adaptee == null) { - throw new NullPointerException("adaptee can not be null"); - } - this.adaptee = adaptee; - } - - //-- internals only below this point - - // map a property id. Property id can only be an Integer or String - private Object mapToId(Object tmp) { - if (tmp instanceof Double) { - return Integer.valueOf(((Double)tmp).intValue()); - } else { - return Context.toString(tmp); - } - } - - private static Scriptable getFunctionPrototype(Scriptable scope) { - return ScriptableObject.getFunctionPrototype(scope); - } - - private Function getAdapteeFunction(String name) { - Object o = ScriptableObject.getProperty(getAdaptee(), name); - return (o instanceof Function)? (Function)o : null; - } - - private Object call(Function func, Object[] args) { - Context cx = Context.getCurrentContext(); - Scriptable thisObj = getAdaptee(); - Scriptable scope = func.getParentScope(); - try { - return func.call(cx, scope, thisObj, args); - } catch (RhinoException re) { - throw Context.reportRuntimeError(re.getMessage()); - } - } - - private Scriptable prototype; - private Scriptable parent; - private Scriptable adaptee; - private boolean isPrototype; - - // names of adaptee JavaScript functions - private static final String GET_PROP = "__get__"; - private static final String HAS_PROP = "__has__"; - private static final String PUT_PROP = "__put__"; - private static final String DEL_PROP = "__delete__"; - private static final String GET_PROPIDS = "__getIds__"; -} diff --git a/src/main/java/helma/scripting/rhino/JSONModuleSource.java b/src/main/java/helma/scripting/rhino/JSONModuleSource.java deleted file mode 100644 index 89a3c480..00000000 --- a/src/main/java/helma/scripting/rhino/JSONModuleSource.java +++ /dev/null @@ -1,35 +0,0 @@ -package helma.scripting.rhino; - -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.net.URI; - -import org.apache.commons.io.IOUtils; -import org.mozilla.javascript.commonjs.module.provider.ModuleSource; - -public class JSONModuleSource extends ModuleSource { - - private static final long serialVersionUID = 4446798833357540398L; - - public JSONModuleSource(Object securityDomain, URI uri, URI base, Object validator) { - super(null, securityDomain, uri, base, validator); - } - - @Override - public Reader getReader() { - StringBuffer content = new StringBuffer(); - content.append("module.exports = "); //$NON-NLS-1$ - - try { - content.append(IOUtils.toString(this.getUri().toURL().openStream())); - } catch (IOException e) { - content.append("null"); //$NON-NLS-1$ - } - - content.append(";"); //$NON-NLS-1$ - - return new StringReader(content.toString()); - } - -} diff --git a/src/main/java/helma/scripting/rhino/JavaObject.java b/src/main/java/helma/scripting/rhino/JavaObject.java deleted file mode 100644 index b2f92076..00000000 --- a/src/main/java/helma/scripting/rhino/JavaObject.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino; - -import helma.framework.core.*; -import helma.framework.ResponseTrans; -import helma.framework.repository.Resource; -import org.mozilla.javascript.*; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import java.util.ArrayList; -import java.io.UnsupportedEncodingException; -import java.io.IOException; - -/** - * - */ -public class JavaObject extends NativeJavaObject { - - private static final long serialVersionUID = 6348440950512377606L; - - RhinoCore core; - String protoName; - NativeJavaObject unscriptedJavaObj; - - static HashMap overload; - - static { - overload = new HashMap(); - Method[] m = JavaObject.class.getMethods(); - for (int i=0; i= 0; i--) { - Resource resource = resources[i]; - if (resource.exists() && resource.getShortName().equals(resourceName)) - return Context.toObject(resource, core.global); - } - prototype = prototype.getParentPrototype(); - } - return null; - } - - - /** - * Returns an array containing the prototype's resource with a given name. - * - * @param resourceName the name of the resource, e.g. "type.properties", - * "messages.properties", "script.js", etc. - * @return an array of resources with the given name - */ - public Object getResources(String resourceName) { - RhinoEngine engine = RhinoEngine.getRhinoEngine(); - Prototype prototype = engine.core.app.getPrototypeByName(protoName); - ArrayList a = new ArrayList(); - while (prototype != null) { - Resource[] resources = prototype.getResources(); - for (int i = resources.length - 1; i >= 0; i--) { - Resource resource = resources[i]; - if (resource.exists() && resource.getShortName().equals(resourceName)) - a.add(Context.toObject(resource, core.global)); - } - prototype = prototype.getParentPrototype(); - } - return Context.getCurrentContext().newArray(core.global, a.toArray()); - } - -} diff --git a/src/main/java/helma/scripting/rhino/MapWrapper.java b/src/main/java/helma/scripting/rhino/MapWrapper.java deleted file mode 100644 index 7a9ef493..00000000 --- a/src/main/java/helma/scripting/rhino/MapWrapper.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino; - -import org.mozilla.javascript.Context; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; -import org.mozilla.javascript.Wrapper; -import org.mozilla.javascript.Undefined; -import java.util.HashMap; -import java.util.Map; - -/** - * A class that wraps a Java Map as a native JavaScript object. This is - * used by the RhinoCore Wrapper for instances of helma.util.SystemMap - * and helma.util.WrappedMap. - */ -public class MapWrapper extends ScriptableObject implements Wrapper { - private static final long serialVersionUID = -8802538795495729410L; - - Map map; - RhinoCore core; - - /** - * Creates a new MapWrapper object. - */ - public MapWrapper() { - map = null; - } - - /** - * Creates a new MapWrapper object. - * - * @param map the Map - * @param core the RhinoCore instance - */ - public MapWrapper(Map map, RhinoCore core) { - this.map = map; - this.core = core; - setParentScope(core.global); - setPrototype(ScriptableObject.getObjectPrototype(core.global)); - } - - /** - * - * - * @param name ... - * @param start ... - * @param value ... - */ - public void put(String name, Scriptable start, Object value) { - if (map == null) { - map = new HashMap(); - } - - if (value == null || value == Undefined.instance) { - map.remove(name); - } else if (value instanceof Wrapper) { - map.put(name, ((Wrapper) value).unwrap()); - } else { - map.put(name, value); - } - } - - /** - * - * - * @param name ... - * @param start ... - * - * @return ... - */ - public Object get(String name, Scriptable start) { - if (map == null) { - return null; - } - - Object obj = map.get(name); - - if (obj != null && !(obj instanceof Scriptable)) { - // do NOT wrap primitives - otherwise they'll be wrapped as Objects, - // which makes them unusable for many purposes (e.g. ==) - if (obj instanceof String || - obj instanceof Number || - obj instanceof Boolean) { - return obj; - } - - return Context.toObject(obj, core.global); - } - - return obj; - } - - /** - * - * - * @param name ... - * @param start ... - * - * @return ... - */ - public boolean has(String name, Scriptable start) { - return (map != null) && map.containsKey(name); - } - - /** - * - * - * @param name ... - */ - public void delete(String name) { - if (map != null) { - map.remove(name); - } - } - - /** - * - * - * @param idx ... - * @param start ... - * @param value ... - */ - public void put(int idx, Scriptable start, Object value) { - if (map == null) { - map = new HashMap(); - } - - if (value == null || value == Undefined.instance) { - map.remove(Integer.toString(idx)); - } else if (value instanceof Wrapper) { - map.put(Integer.toString(idx), ((Wrapper) value).unwrap()); - } else { - map.put(Integer.toString(idx), value); - } - } - - /** - * - * - * @param idx ... - * @param start ... - * - * @return ... - */ - public Object get(int idx, Scriptable start) { - if (map == null) { - return null; - } - - Object obj = map.get(Integer.toString(idx)); - - if (obj != null && !(obj instanceof Scriptable)) { - // do NOT wrap primitives - otherwise they'll be wrapped as Objects, - // which makes them unusable for many purposes (e.g. ==) - if (obj instanceof String || - obj instanceof Number || - obj instanceof Boolean) { - return obj; - } - - return Context.toObject(obj, core.global); - } - - return obj; - } - - /** - * - * - * @param idx ... - * @param start ... - * - * @return ... - */ - public boolean has(int idx, Scriptable start) { - return (map != null) && map.containsKey(Integer.toString(idx)); - } - - /** - * - * - * @param idx ... - */ - public void delete(int idx) { - if (map != null) { - map.remove(Integer.toString(idx)); - } - } - - - /** - * Return an array containing the property key values of this map. - */ - public Object[] getIds() { - if (map == null) { - return new Object[0]; - } - - return map.keySet().toArray(); - } - - public Object getDefaultValue(Class hint) { - if (hint == null || hint == String.class) { - return map == null ? "{}" : map.toString(); - } - return super.getDefaultValue(hint); - } - - /** - * Return the wrapped Map object. - */ - public Object unwrap() { - if (map == null) { - map = new HashMap(); - } - return map; - } - - /** - * Return the class name for wrapped maps. - */ - public String getClassName() { - return "[MapWrapper]"; - } - - /** - * Return a string representation for this wrapped map. This calls - * Map.toString(), so usually the contents of the map will be listed. - */ - public String toString() { - if (map == null) { - return "[MapWrapper{}]"; - } else { - return "[MapWrapper"+map.toString()+"]"; - } - } -} diff --git a/src/main/java/helma/scripting/rhino/NodeModulesProvider.java b/src/main/java/helma/scripting/rhino/NodeModulesProvider.java deleted file mode 100644 index 4ee114de..00000000 --- a/src/main/java/helma/scripting/rhino/NodeModulesProvider.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 2017 Daniel Ruthardt. All rights reserved. - */ - -package helma.scripting.rhino; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Files; - -import org.apache.commons.io.FilenameUtils; -import org.mozilla.javascript.commonjs.module.provider.ModuleSource; -import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonSyntaxException; - -/** - * Bridges the gap between CommonJS-style module loading and Node.js-style module loading. - */ -public class NodeModulesProvider extends UrlModuleSourceProvider { - - /** - * Define the serialization UID. - */ - private static final long serialVersionUID = 6858072487233136717L; - - /** - * Delegates to the super constructor. - */ - public NodeModulesProvider(Iterable privilegedUris, Iterable fallbackUris) { - // do what would have been done anyways - super(privilegedUris, fallbackUris); - } - - /** - * Do what Node.js's LOAD_AS_FILE(X) would do. - * Case 4 ("If X.node is a file, load X.node as binary addon. STOP") is currently not supported (for - * quite obvious reasons). We might want to load JAR files in the future. - * - * @see https://nodejs.org/dist/latest-v9.x/docs/api/modules.html#modules_file_modules - * - * @param uri - * The file to load. FILE, FILE.js and FILE.json will be tried in this order. - * @param base - * Not used, only forwarded to - * {@link UrlModuleSourceProvider#loadSource(URI, URI, Object)}. - * @param validator - * Not used, only forwarded to - * {@link UrlModuleSourceProvider#loadSource(URI, URI, Object)}. - * @return - * The module source or null, if the module was not found. - * - * @throws IOException - * See {@link UrlModuleSourceProvider#loadSource(URI, URI, Object)}. - * @throws URISyntaxException - * See {@link UrlModuleSourceProvider#loadSource(URI, URI, Object)}. - */ - private ModuleSource loadAsFile(URI uri, URI base, Object validator) - throws IOException, URISyntaxException { - // lets assume the module is a file - File file = new File(uri); - // check if the file exists and is a file - if (file.exists() && file.isFile()) { - // check if the file is a JSON file - if (file.getAbsolutePath().toLowerCase().endsWith(".json")) { //$NON-NLS-1$ - // return a JSON module source - return new JSONModuleSource(null, file.toURI(), base, validator); - } else { - // do what would have been done anyways - return super.loadFromUri(uri, base, validator); - } - } - - // lets assume the module is a JS file - file = new File(new File(uri).getPath() + ".js"); //$NON-NLS-1$ - // check if a file.js exists and is a file - if (file.exists() && file.isFile()) { - // do what would have been done anyways - return super.loadFromUri(uri, base, validator); - } - - // lets assume the module is a JSON file - file = new File(new File(uri).getPath() + ".json"); //$NON-NLS-1$ - // check if a file.json exists and is a file - if (file.exists() && file.isFile()) { - // return a JSON module source - return new JSONModuleSource(null, file.toURI(), base, validator); - } - - // module not found - return null; - } - - /** - * Do what Node.js's LOAD_AS_DIRECTORY(X) would do. - * - * @see https://nodejs.org/dist/latest-v9.x/docs/api/modules.html#modules_file_modules - * - * @param uri - * The directory to load. - * @param base - * Not used, only forwarded to - * {@link UrlModuleSourceProvider#loadSource(URI, URI, Object)}. - * @param validator - * Not used, only forwarded to - * {@link UrlModuleSourceProvider#loadSource(URI, URI, Object)}. - * @return - * The module source or null, if the module was not found. - * - * @throws JsonSyntaxException - * Thrown for problems accessing the module's "package.json" file. - * @throws IOException - * See {@link UrlModuleSourceProvider#loadSource(URI, URI, Object)}. - * @throws URISyntaxException - * See {@link UrlModuleSourceProvider#loadSource(URI, URI, Object)}. - */ - private ModuleSource loadAsDirectory(URI uri, URI base, Object validator) - throws JsonSyntaxException, IOException, URISyntaxException { - // lets assume the module is a directory - File directory = new File(uri); - // check if the directory exists and is a directory - if (directory.exists() && directory.isDirectory()) { - // the module source - ModuleSource moduleSource; - - // lets assume that there is a "package.json" file in the directory - File packageFile = new File(directory, "package.json"); //$NON-NLS-1$ - - // check if the there is a "package.json" file in the directory - if (packageFile.exists() && packageFile.isFile()) { - // parse the JSON file - JsonObject json = new JsonParser() - .parse(new String(Files.readAllBytes(packageFile.toPath()))).getAsJsonObject(); - // check if the JSON file defines a main JS file - if (json.has("main")) { //$NON-NLS-1$ - // get the main JS file, removing the filename extension - String main = FilenameUtils.removeExtension(json.get("main").getAsString()); //$NON-NLS-1$ - - // load as file - moduleSource = this.loadAsFile(new File(directory, main).toURI(), base, validator); - // check if something was loaded - if (moduleSource != null) { - // return the loaded module source - return moduleSource; - } - } - } - - // load as index - moduleSource = this.loadAsFile(new File(directory, "index").toURI(), base, validator); //$NON-NLS-1$ - // check if something was loaded - if (moduleSource != null) { - // return the loaded module source - return moduleSource; - } - } - - // module not found - return null; - } - - /** - * Do what Node.js's require(X) would do. - * - * Case 1 is not supported, you will have to use modules from npmjs.org, re-implementing the core - * core module's functionality. We might want to use Nodeschnaps in the future. - * Case 2 is not supported, paths are always treated as relative paths within the application's - * "commonjs" directory. - * Case 5 additionally tries {@link UrlModuleSourceProvider#loadSource(URI, URI, Object)}, even if it is - * very unlikely that something, which hasn't been tried yet, will be done. One could say we are just - * delegating throwing the error. - * - * @see https://nodejs.org/dist/latest-v9.x/docs/api/modules.html#modules_file_modules - * @see https://github.com/killmag10/nodeschnaps - */ - protected ModuleSource loadFromUri(URI uri, URI base, Object validator) - throws IOException, URISyntaxException { - // the module source - ModuleSource moduleSource; - - // load as file - moduleSource = this.loadAsFile(uri, base, validator); - // check if something was loaded - if (moduleSource != null) { - // return the loaded module source - return moduleSource; - } - - // load as directory - moduleSource = this.loadAsDirectory(uri, base, validator); - // check if something was loaded - if (moduleSource != null) { - // return the loaded module source - return moduleSource; - } - - // do what would have been done anyways - return super.loadFromUri(uri, base, validator); - } - -} diff --git a/src/main/java/helma/scripting/rhino/PathWrapper.java b/src/main/java/helma/scripting/rhino/PathWrapper.java deleted file mode 100644 index fdecc0ca..00000000 --- a/src/main/java/helma/scripting/rhino/PathWrapper.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino; - -import helma.framework.core.RequestPath; -import org.mozilla.javascript.*; - -import java.io.UnsupportedEncodingException; - -/** - * This class wraps around instances of helma.framework.core.RequestPath and - * exposes them in an array-like fashion to the JavaScript runtime. - * - * @see helma.framework.core.RequestPath - */ -public class PathWrapper extends ScriptableObject { - - private static final long serialVersionUID = 514381479839863014L; - - RequestPath path; - RhinoCore core; - - /** - * Zero arg constructor for creating the PathWrapper prototype. - */ - public PathWrapper (RhinoCore core) throws RhinoException, NoSuchMethodException { - this.core = core; - // create a dummy path object - this.path = new RequestPath(core.app); - - // initialize properties and functions - setParentScope(core.getScope()); - setPrototype(null); - defineProperty("length", PathWrapper.class, DONTENUM | READONLY | PERMANENT); - defineFunctionProperties(new String[] {"href", "contains"}, - PathWrapper.class, DONTENUM | PERMANENT); - } - - /** - * Creates a new PathWrapper around a RequestPath. - */ - PathWrapper(RequestPath path, RhinoCore core) { - this.path = path; - this.core = core; - } - - - /** - * Returns a path object in the wrapped path by property name. - */ - public Object get(String name, Scriptable start) { - Object obj = path.getByPrototypeName(name); - - if (obj != null) { - return Context.toObject(obj, core.getScope()); - } - - return super.get(name, start); - } - - /** - * Returns a path object in the wrapped path by property name. - */ - public Object get(int idx, Scriptable start) { - Object obj = path.get(idx); - - if (obj != null) { - return Context.toObject(obj, core.getScope()); - } - - return null; - } - - /** - * Checks if an object with the given name is contained in the path. - */ - public boolean has(String name, Scriptable start) { - return path.getByPrototypeName(name) != null; - } - - /** - * Checks if an object with the given index is contained in the path. - */ - public boolean has(int index, Scriptable start) { - return index >= 0 && index < path.size(); - } - - /** - * Returns a list of array indices 0..length-1. - */ - public Object[] getIds() { - Object[] ids = new Object[path.size()]; - - for (int i=0; i commonJsPaths = new ArrayList(); - commonJsPaths.add(app.getAppDir().toURI()); - String commonJsAppPath = app.getProperty("commonjs.dir"); - - if (commonJsAppPath != null) { - File commonJsAppDir = new File(app.getAppDir(), commonJsAppPath); - if (commonJsAppDir.isDirectory()) { - commonJsPaths.add(commonJsAppDir.toURI()); - } - } - - // install the global require() function using our custom modules provider, so that - // CommonJS-style as well as NodeJS-style modules can be required - new RequireBuilder() - .setModuleScriptProvider(new CompiledOrInterpretedModuleScriptProvider( - new NodeModulesProvider(commonJsPaths, null))) - .setSandboxed(true) - .createRequire(context, global) - .install(global); - - pathProto = new PathWrapper(this); - - hopObjectProto = HopObject.init(this); - // use lazy loaded constructors for all extension objects that - // adhere to the ScriptableObject.defineClass() protocol - new LazilyLoadedCtor(global, "File", - "helma.scripting.rhino.extensions.FileObject", false); - new LazilyLoadedCtor(global, "Ftp", - "helma.scripting.rhino.extensions.FtpObject", false); - new LazilyLoadedCtor(global, "Image", - "helma.scripting.rhino.extensions.ImageObject", false); - new LazilyLoadedCtor(global, "Remote", - "helma.scripting.rhino.extensions.XmlRpcObject", false); - MailObject.init(global, app.getProperties()); - JSAdapter.init(context, global, false); - - // add some convenience functions to string, date and number prototypes - Scriptable stringProto = ScriptableObject.getClassPrototype(global, "String"); - stringProto.put("trim", stringProto, new StringTrim()); - - Scriptable dateProto = ScriptableObject.getClassPrototype(global, "Date"); - dateProto.put("format", dateProto, new DateFormat()); - - Scriptable numberProto = ScriptableObject.getClassPrototype(global, "Number"); - numberProto.put("format", numberProto, new NumberFormat()); - - Collection protos = app.getPrototypes(); - for (Iterator i = protos.iterator(); i.hasNext();) { - Prototype proto = (Prototype) i.next(); - initPrototype(proto); - } - - // always fully initialize global prototype, because - // we always need it and there's no chance to trigger - // creation on demand. - getPrototype("global"); - - } catch (Exception e) { - app.logError("Cannot initialize interpreter", e); - throw new RuntimeException(e.getMessage(), e); - } finally { - Context.exit(); - isInitialized = true; - } - } - - boolean isInitialized() { - return isInitialized; - } - - public void shutdown() { - if (debugger != null) { - debugger.dispose(); - debugger = null; - } - } - - void initDebugger(Context context) { - context.setGeneratingDebug(true); - try { - if (debugger == null) { - debugger = new HelmaDebugger(app.getName()); - debugger.setScopeProvider(this); - debugger.attachTo(contextFactory); - } - } catch (Exception x) { - app.logError("Error setting up debugger", x); - } - } - - /** - * Initialize a prototype info without compiling its script files. - * - * @param prototype the prototype to be created - */ - protected synchronized TypeInfo initPrototype(Prototype prototype) { - - String name = prototype.getName(); - String lowerCaseName = prototype.getLowerCaseName(); - - TypeInfo type = (TypeInfo) prototypes.get(lowerCaseName); - - // check if the prototype info exists already - ScriptableObject op = (type == null) ? null : type.objProto; - - // if prototype info doesn't exist (i.e. is a standard prototype - // built by HopExtension), create it. - if (op == null) { - if ("global".equals(lowerCaseName)) { - op = global; - } else if ("hopobject".equals(lowerCaseName)) { - op = hopObjectProto; - } else { - op = new HopObject(name, this); - } - type = registerPrototype(prototype, op); - } - - // Register a constructor for all types except global. - // This will first create a new prototyped HopObject and then calls - // the actual (scripted) constructor on it. - if (!"global".equals(lowerCaseName)) { - try { - new HopObjectCtor(name, this, op); - op.setParentScope(global); - } catch (Exception x) { - app.logError("Error adding ctor for " + name, x); - } - } - - return type; - } - - /** - * Set up a prototype, parsing and compiling all its script files. - * - * @param type the info, containing the object proto, last update time and - * the set of compiled functions properties - */ - private synchronized void evaluatePrototype(final TypeInfo type) { - - type.prepareCompilation(); - final Prototype prototype = type.frameworkProto; - - // set the parent prototype in case it hasn't been done before - // or it has changed... - setParentPrototype(prototype, type); - - type.error = null; - if ("global".equals(prototype.getLowerCaseName())) { - globalError = null; - } - - contextFactory.call(new ContextAction() { - public Object run(Context cx) { - // loop through the prototype's code elements and evaluate them - Iterator code = prototype.getCodeResources(); - while (code.hasNext()) { - evaluate(cx, type, (Resource) code.next()); - } - return null; - } - }); - type.commitCompilation(); - } - - /** - * Set the parent prototype on the ObjectPrototype. - * - * @param prototype the prototype spec - * @param type the prototype object info - */ - protected void setParentPrototype(Prototype prototype, TypeInfo type) { - String name = prototype.getName(); - String lowerCaseName = prototype.getLowerCaseName(); - - if (!"global".equals(lowerCaseName) && !"hopobject".equals(lowerCaseName)) { - - // get the prototype's prototype if possible and necessary - TypeInfo parentType = null; - Prototype parent = prototype.getParentPrototype(); - - if (parent != null) { - // see if parent prototype is already registered. if not, register it - parentType = getPrototypeInfo(parent.getName()); - } - - if (parentType == null && !app.isJavaPrototype(name)) { - // FIXME: does this ever occur? - parentType = getPrototypeInfo("hopobject"); - } - - type.setParentType(parentType); - } - } - - /** - * This method is called before an execution context is entered to let the - * engine know it should update its prototype information. The update policy - * here is to check for update those prototypes which already have been compiled - * before. Others will be updated/compiled on demand. - */ - public synchronized void updatePrototypes() throws IOException { - if ((System.currentTimeMillis() - lastUpdate) < 1000L + updateSnooze) { - return; - } - - // init prototypes and/or update prototype checksums - app.typemgr.checkPrototypes(); - - // get a collection of all prototypes (code directories) - Collection protos = app.getPrototypes(); - - // in order to respect inter-prototype dependencies, we try to update - // the global prototype before all other prototypes, and parent - // prototypes before their descendants. - - HashSet checked = new HashSet(protos.size() * 2); - - TypeInfo type = (TypeInfo) prototypes.get("global"); - - if (type != null) { - updatePrototype(type, checked); - } - - for (Iterator i = protos.iterator(); i.hasNext();) { - Prototype proto = (Prototype) i.next(); - - if (checked.contains(proto)) { - continue; - } - - type = (TypeInfo) prototypes.get(proto.getLowerCaseName()); - - if (type == null) { - // a prototype we don't know anything about yet. Init local update info. - initPrototype(proto); - } else if (type.lastUpdate > -1) { - // only need to update prototype if it has already been initialized. - // otherwise, this will be done on demand. - updatePrototype(type, checked); - } - } - - lastUpdate = System.currentTimeMillis(); - // max updateSnooze is 4 seconds, reached after 66.6 idle minutes - long newSnooze = (lastUpdate - app.typemgr.getLastCodeUpdate()) / 1000; - updateSnooze = Math.min(4000, Math.max(0, newSnooze)); - } - - /** - * Check one prototype for updates. Used by upatePrototypes(). - * - * @param type the type info to check - * @param checked a set of prototypes that have already been checked - */ - private void updatePrototype(TypeInfo type, HashSet checked) { - // first, remember prototype as updated - checked.add(type.frameworkProto); - - if (type.parentType != null && - !checked.contains(type.parentType.frameworkProto)) { - updatePrototype(type.getParentType(), checked); - } - - // let the prototype check if its resources have changed - type.frameworkProto.checkForUpdates(); - - // and re-evaluate if necessary - if (type.needsUpdate()) { - evaluatePrototype(type); - } - } - - /** - * A version of getPrototype() that retrieves a prototype and checks - * if it is valid, i.e. there were no errors when compiling it. If - * invalid, a ScriptingException is thrown. - */ - public Scriptable getValidPrototype(String protoName) { - if (globalError != null) { - throw new EvaluatorException(globalError); - } - TypeInfo type = getPrototypeInfo(protoName); - if (type != null) { - if (type.hasError()) { - throw new EvaluatorException(type.getError()); - } - return type.objProto; - } - return null; - } - - /** - * Get the object prototype for a prototype name and initialize/update it - * if necessary. The policy here is to update the prototype only if it - * hasn't been updated before, otherwise we assume it already was updated - * by updatePrototypes(), which is called for each request. - */ - public Scriptable getPrototype(String protoName) { - TypeInfo type = getPrototypeInfo(protoName); - return type == null ? null : type.objProto; - } - - /** - * Get an array containing the property ids of all properties that were - * compiled from scripts for the given prototype. - * - * @param protoName the name of the prototype - * @return an array containing all compiled properties of the given prototype - */ - public Map getPrototypeProperties(String protoName) { - TypeInfo type = getPrototypeInfo(protoName); - SystemMap map = new SystemMap(); - Iterator it = type.compiledProperties.iterator(); - while(it.hasNext()) { - Object key = it.next(); - if (key instanceof String) - map.put(key, type.objProto.get((String) key, type.objProto)); - } - return map; - } - - /** - * Private helper function that retrieves a prototype's TypeInfo - * and creates it if not yet created. This is used by getPrototype() and - * getValidPrototype(). - */ - private TypeInfo getPrototypeInfo(String protoName) { - if (protoName == null) { - return null; - } - - TypeInfo type = (TypeInfo) prototypes.get(protoName.toLowerCase()); - - // if type exists and hasn't been evaluated (used) yet, evaluate it now. - // otherwise, it has already been evaluated for this request by updatePrototypes(), - // which is called before a request is handled. - if ((type != null) && (type.lastUpdate == -1)) { - type.frameworkProto.checkForUpdates(); - - if (type.needsUpdate()) { - evaluatePrototype(type); - } - } - - return type; - } - - /** - * Register an object prototype for a prototype name. - */ - private TypeInfo registerPrototype(Prototype proto, ScriptableObject op) { - TypeInfo type = new TypeInfo(proto, op); - prototypes.put(proto.getLowerCaseName(), type); - return type; - } - - /** - * Check if an object has a function property (public method if it - * is a java object) with that name. - */ - public boolean hasFunction(String protoname, String fname) { - // throws EvaluatorException if type has a syntax error - Scriptable op = getValidPrototype(protoname); - - // if this is an untyped object return false - if (op == null) { - return false; - } - - return ScriptableObject.getProperty(op, fname) instanceof Function; - } - - /** - * Convert an input argument from Java to the scripting runtime - * representation. - */ - public Object processXmlRpcArgument (Object arg) { - if (arg == null) - return null; - if (arg instanceof Vector) { - Vector v = (Vector) arg; - Object[] a = v.toArray(); - for (int i=0; i lastUpdate; - } - - public void setParentType(TypeInfo type) { - parentType = type; - if (type == null) { - objProto.setPrototype(null); - } else { - objProto.setPrototype(type.objProto); - } - } - - public TypeInfo getParentType() { - return parentType; - } - - public boolean hasError() { - TypeInfo p = this; - while (p != null) { - if (p.error != null) - return true; - p = p.parentType; - } - return false; - } - - public String getError() { - TypeInfo p = this; - while (p != null) { - if (p.error != null) - return p.error; - p = p.parentType; - } - return null; - } - - public String toString() { - return ("TypeInfo[" + frameworkProto + "," + new Date(lastUpdate) + "]"); - } - } - - /** - * Object wrapper class - */ - class WrapMaker extends WrapFactory { - - public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) { - // taking a shortcut here on things normally defined by setJavaPrimitivesWrap() - if (obj == null || obj == Undefined.instance - || obj instanceof Scriptable || obj instanceof String - || obj instanceof Number || obj instanceof Boolean) { - return obj; - } - // Wrap Nodes - if (obj instanceof INode) { - return getNodeWrapper((INode) obj); - } - if (obj instanceof NodeHandle) { - return getNodeWrapper((NodeHandle) obj); - } - - // Masquerade SystemMap and WrappedMap as native JavaScript objects - if (obj instanceof SystemMap || obj instanceof WrappedMap) { - return new MapWrapper((Map) obj, RhinoCore.this); - } - - // Convert java.util.Date objects to JavaScript Dates - if (obj instanceof Date) { - Object[] args = { Long.valueOf(((Date) obj).getTime()) }; - try { - return cx.newObject(global, "Date", args); - } catch (JavaScriptException nafx) { - return obj; - } - } - - // Wrap scripted Java objects - if (obj != null && app.getPrototypeName(obj) != null) { - return getElementWrapper(obj); - } - - return super.wrap(cx, scope, obj, staticType); - } - - public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj) { - if (obj instanceof Scriptable) { - return (Scriptable) obj; - } - if (obj instanceof INode) { - return getNodeWrapper((INode) obj); - } - - if (obj != null && app.getPrototypeName(obj) != null) { - return getElementWrapper(obj); - } - - return super.wrapNewObject(cx, scope, obj); - } - } - - class StringTrim extends BaseFunction { - private static final long serialVersionUID = -1515630068911501925L; - - public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { - String str = thisObj.toString(); - return str.trim(); - } - } - - class DateFormat extends BaseFunction { - private static final long serialVersionUID = 4694440247686532087L; - - public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { - Date date = new Date((long) ScriptRuntime.toNumber(thisObj)); - SimpleDateFormat df; - - if (args.length > 0 && args[0] != Undefined.instance && args[0] != null) { - if (args.length > 1 && args[1] instanceof NativeJavaObject) { - Object locale = ((NativeJavaObject) args[1]).unwrap(); - if (locale instanceof Locale) { - df = new SimpleDateFormat(args[0].toString(), (Locale) locale); - } else { - throw new IllegalArgumentException("Second argument to Date.format() not a java.util.Locale: " + - locale.getClass()); - } - } else { - df = new SimpleDateFormat(args[0].toString()); - } - } else { - df = new SimpleDateFormat(); - } - return df.format(date); - } - } - - class NumberFormat extends BaseFunction { - private static final long serialVersionUID = -6999409297243210875L; - - public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { - DecimalFormat df; - if (args.length > 0 && args[0] != Undefined.instance) { - df = new DecimalFormat(args[0].toString()); - } else { - df = new DecimalFormat("#,##0.00"); - } - return df.format(ScriptRuntime.toNumber(thisObj)); - } - } - - class HelmaContextFactory extends ContextFactory { - - final boolean strictVars = "true".equalsIgnoreCase(app.getProperty("strictVars")); - - protected void onContextCreated(Context cx) { - cx.setWrapFactory(wrapper); - cx.setOptimizationLevel(optLevel); - cx.setInstructionObserverThreshold(10000); - if (Context.isValidLanguageVersion(languageVersion)) { - cx.setLanguageVersion(languageVersion); - } else { - app.logError("Unsupported rhino.languageVersion: " + languageVersion); - } - - // Set up visual debugger if rhino.debug = true - if (hasDebugger) - initDebugger(cx); - super.onContextCreated(cx); - } - - protected boolean hasFeature(Context cx, int featureIndex) { - switch (featureIndex) { - case Context.FEATURE_DYNAMIC_SCOPE: - return true; - - case Context.FEATURE_STRICT_VARS: - case Context.FEATURE_WARNING_AS_ERROR: - return strictVars; - - default: - return super.hasFeature(cx, featureIndex); - } - } - - /** - * Implementation of - * {@link Context#observeInstructionCount(int instructionCount)}. - * This can be used to customize {@link Context} without introducing - * additional subclasses. - */ - protected void observeInstructionCount(Context cx, int instructionCount) { - RhinoEngine engine = RhinoEngine.getRhinoEngine(); - if (engine != null && engine.thread != Thread.currentThread()) { - throw new EvaluatorException("Request timed out"); - } - } - } -} diff --git a/src/main/java/helma/scripting/rhino/RhinoEngine.java b/src/main/java/helma/scripting/rhino/RhinoEngine.java deleted file mode 100644 index 1af70d90..00000000 --- a/src/main/java/helma/scripting/rhino/RhinoEngine.java +++ /dev/null @@ -1,743 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino; - -import helma.extensions.ConfigurationException; -import helma.extensions.HelmaExtension; -import helma.framework.*; -import helma.framework.repository.Resource; -import helma.framework.core.*; -import helma.main.Server; -import helma.objectmodel.*; -import helma.objectmodel.db.DbMapping; -import helma.objectmodel.db.Relation; -import helma.objectmodel.db.Node; -import helma.scripting.*; -import helma.scripting.rhino.debug.Tracer; -import helma.scripting.rhino.debug.Profiler; -import helma.util.StringUtils; -import org.mozilla.javascript.*; -import org.mozilla.javascript.serialize.ScriptableOutputStream; -import org.mozilla.javascript.serialize.ScriptableInputStream; - -import java.util.*; -import java.io.*; -import java.lang.ref.WeakReference; - -/** - * This is the implementation of ScriptingEnvironment for the Mozilla Rhino EcmaScript interpreter. - */ -public class RhinoEngine implements ScriptingEngine { - // map for Application to RhinoCore binding - static final Map coreMap = new WeakHashMap(); - - // the application we're running in - public Application app; - - // The Rhino context - Context context; - - // the per-thread global object - GlobalObject global; - - // the request evaluator instance owning this rhino engine - RequestEvaluator reval; - - // the rhino core - RhinoCore core; - - // the global vars set by extensions - HashMap extensionGlobals; - - // the thread currently running this engine - volatile Thread thread; - - // thread local engine registry - static ThreadLocal engines = new ThreadLocal(); - - /** - * Zero argument constructor. - */ - public RhinoEngine() { - // nothing to do - } - - /** - * Init the scripting engine with an application and a request evaluator - */ - public synchronized void init(Application app, RequestEvaluator reval) { - this.app = app; - this.reval = reval; - initRhinoCore(app); - - context = core.contextFactory.enterContext(); - - try { - extensionGlobals = new HashMap(); - - if (Server.getServer() != null) { - Vector extVec = Server.getServer().getExtensions(); - - for (int i = 0; i < extVec.size(); i++) { - HelmaExtension ext = (HelmaExtension) extVec.get(i); - - try { - HashMap tmpGlobals = ext.initScripting(app, this); - - if (tmpGlobals != null) { - extensionGlobals.putAll(tmpGlobals); - } - } catch (ConfigurationException e) { - app.logError("Couldn't initialize extension " + ext.getName(), e); - } - } - } - - } catch (Exception e) { - app.logError("Cannot initialize interpreter", e); - throw new RuntimeException(e.getMessage(), e); - } finally { - Context.exit(); - } - } - - /** - * Shut down the scripting engine. - */ - public void shutdown() { - core.shutdown(); - } - - /** - * Return the RhinoEngine associated with the current thread, or null. - * @return the RhinoEngine assocated with the current thread - */ - public static RhinoEngine getRhinoEngine() { - return (RhinoEngine) engines.get(); - } - - /** - * Initialize the RhinoCore instance for this engine and application. - * @param app the application we belong to - */ - private synchronized void initRhinoCore(Application app) { - synchronized (coreMap) { - WeakReference ref = (WeakReference) coreMap.get(app); - if (ref != null) { - core = (RhinoCore) ref.get(); - } - - if (core == null) { - core = new RhinoCore(app); - core.initialize(); - coreMap.put(app, new WeakReference(core)); - } - } - } - - /** - * This method is called before an execution context is entered to let the - * engine know it should update its prototype information. - */ - public synchronized void enterContext() throws IOException { - // remember the current thread as our thread - we do this here so - // the thread is already set when the RequestEvaluator calls - // Application.getDataRoot(), which may result in a function invocation - // (chicken and egg problem, kind of) - thread = Thread.currentThread(); - global = new GlobalObject(core, app, true); - context = core.contextFactory.enterContext(); - - if (core.hasTracer) { - context.setDebugger(new Tracer(getResponse()), null); - } else if (useProfiler()) { - context.setDebugger(new Profiler(), null); - } - - // register the engine with the current thread - engines.set(this); - // update prototypes - core.updatePrototypes(); - } - - /** - * This method is called when an execution context for a request - * evaluation is entered. The globals parameter contains the global values - * to be applied during this execution context. - */ - public synchronized void setGlobals(Map globals) throws ScriptingException { - // remember the current thread as our thread - thread = Thread.currentThread(); - - // set globals on the global object - // add globals from extensions - globals.putAll(extensionGlobals); - // loop through global vars and set them - for (Iterator i = globals.keySet().iterator(); i.hasNext();) { - String k = (String) i.next(); - Object v = globals.get(k); - Scriptable scriptable; - - // create a special wrapper for the path object. - // other objects are wrapped in the default way. - if (v == null) { - continue; - } else if (v instanceof RequestPath) { - scriptable = new PathWrapper((RequestPath) v, core); - scriptable.setPrototype(core.pathProto); - } else { - scriptable = Context.toObject(v, global); - } - - global.put(k, global, scriptable); - } - } - - /** - * This method is called to let the scripting engine know that the current - * execution context has terminated. - */ - public synchronized void exitContext() { - if (useProfiler()) { - try { - Profiler profiler = (Profiler) Context.getCurrentContext().getDebugger(); - String result = profiler.getResult(); - ResponseTrans res = getResponse(); - if (res != null) { - getResponse().debug("
    " + result + "
    "); - } - app.logEvent("Profiler data for " + getRequest() + ":\n" + result); - } catch (Exception x) { - app.logError("Error in profiler: " + x, x); - } - } - // unregister the engine threadlocal - engines.set(null); - Context.exit(); - thread = null; - global = null; - } - - /** - * Invoke a function on some object, using the given arguments and global vars. - * XML-RPC calls require special input and output parameter conversion. - * - * @param thisObject the object to invoke the function on, or null for - * global functions - * @param function the function or name of the function to be invoked - * @param args array of argument objects - * @param argsWrapMode indicated the way to process the arguments. Must be - * one of ARGS_WRAP_NONE, - * ARGS_WRAP_DEFAULT, - * ARGS_WRAP_XMLRPC - * @param resolve indicates whether functionName may contain an object path - * or just the plain function name - * @return the return value of the function - * @throws ScriptingException to indicate something went wrong - * with the invocation - */ - public Object invoke(Object thisObject, Object function, Object[] args, - int argsWrapMode, boolean resolve) throws ScriptingException { - if (function == null) { - throw new IllegalArgumentException("Function argument must not be null"); - } - if (args == null) { - throw new IllegalArgumentException("Arguments array must not be null"); - } - try { - Scriptable obj = thisObject == null ? global : Context.toObject(thisObject, global); - Function func; - if (function instanceof String) { - String funcName = (String) function; - // if function name should be resolved interpret it as member expression, - // otherwise replace dots with underscores. - if (resolve) { - if (funcName.indexOf('.') > 0) { - String[] path = StringUtils.split(funcName, "."); - for (int i = 0; i < path.length - 1; i++) { - Object propValue = ScriptableObject.getProperty(obj, path[i]); - if (propValue instanceof Scriptable) { - obj = (Scriptable) propValue; - } else { - throw new RuntimeException("Can't resolve function name " + - funcName + " in " + thisObject); - } - } - funcName = path[path.length - 1]; - } - } else { - funcName = funcName.replace('.', '_'); - } - Object funcvalue = ScriptableObject.getProperty(obj, funcName); - - if (!(funcvalue instanceof Function)) - return null; - func = (Function) funcvalue; - - } else { - if (function instanceof Wrapper) - function = ((Wrapper) function).unwrap(); - if (!(function instanceof Function)) - throw new IllegalArgumentException("Not a function or function name: " + function); - func = (Function) function; - } - - - for (int i = 0; i < args.length; i++) { - switch (argsWrapMode) { - case ARGS_WRAP_DEFAULT: - // convert java objects to JavaScript - if (args[i] != null) { - args[i] = Context.javaToJS(args[i], global); - } - break; - case ARGS_WRAP_XMLRPC: - // XML-RPC requires special argument conversion - args[i] = core.processXmlRpcArgument(args[i]); - break; - } - } - - // use Context.call() in order to set the context's factory - Object retval = Context.call(core.contextFactory, func, global, obj, args); - - if (retval instanceof Wrapper) { - retval = ((Wrapper) retval).unwrap(); - } - - if ((retval == null) || (retval == Undefined.instance)) { - return null; - } else if (argsWrapMode == ARGS_WRAP_XMLRPC) { - return core.processXmlRpcResponse (retval); - } else { - return retval; - } - } catch (RedirectException redirect) { - throw redirect; - } catch (TimeoutException timeout) { - throw timeout; - } catch (ConcurrencyException concur) { - throw concur; - } catch (Exception x) { - // has the request timed out? If so, throw TimeoutException - if (thread != Thread.currentThread()) { - throw new TimeoutException(); - } - - if (x instanceof WrappedException) { - // wrapped java excepiton - Throwable wrapped = ((WrappedException) x).getWrappedException(); - // rethrow if this is a wrapped concurrency or redirect exception - if (wrapped instanceof ConcurrencyException) { - throw (ConcurrencyException) wrapped; - } else if (wrapped instanceof RedirectException) { - throw (RedirectException) wrapped; - } - } - // create and throw a ScriptingException with the right message - String msg = x.getMessage(); - throw new ScriptingException(msg, x); - } - } - - /** - * Let the evaluator know that the current evaluation has been - * aborted. - */ - public void abort() { - // current request has been aborted. - Thread t = thread; - // set thread to null - thread = null; - if (t != null && t.isAlive()) { - t.interrupt(); - try { - t.join(1000); - } catch (InterruptedException ir) { - // interrupted by other thread - } - } - } - - /** - * Check if an object has a function property (public method if it - * is a java object) with that name. - */ - public boolean hasFunction(Object obj, String fname, boolean resolve) { - if (resolve) { - if (fname.indexOf('.') > 0) { - Scriptable op = obj == null ? global : Context.toObject(obj, global); - String[] path = StringUtils.split(fname, "."); - for (int i = 0; i < path.length; i++) { - Object value = ScriptableObject.getProperty(op, path[i]); - if (value instanceof Scriptable) { - op = (Scriptable) value; - } else { - return false; - } - } - return (op instanceof Function); - } - } else { - // Convert '.' to '_' in function name - fname = fname.replace('.', '_'); - } - - // Treat HopObjects separately - otherwise we risk to fetch database - // references/child objects just to check for function properties. - if (obj instanceof INode) { - String protoname = ((INode) obj).getPrototype(); - if (protoname != null && core.hasFunction(protoname, fname)) - return true; - } - - Scriptable op = obj == null ? global : Context.toObject(obj, global); - return ScriptableObject.getProperty(op, fname) instanceof Callable; - } - - /** - * Check if an object has a value property defined with that name. - */ - public boolean hasProperty(Object obj, String propname) { - if (obj == null || propname == null) { - return false; - } else if (obj instanceof Map) { - return ((Map) obj).containsKey(propname); - } - - String prototypeName = app.getPrototypeName(obj); - - if ("user".equalsIgnoreCase(prototypeName) - && "password".equalsIgnoreCase(propname)) { - return false; - } - - // if this is a HopObject, check if the property is defined - // in the type.properties db-mapping. - if (obj instanceof INode && ! "hopobject".equalsIgnoreCase(prototypeName)) { - DbMapping dbm = app.getDbMapping(prototypeName); - if (dbm != null) { - Relation rel = dbm.propertyToRelation(propname); - if (rel != null && (rel.isPrimitive() || rel.isCollection())) - return true; - } - } - Scriptable wrapped = Context.toObject(obj, global); - return wrapped.has(propname, wrapped); - } - - /** - * Get a property from the global object. - * @param propname the property name - * @return the property value if the property is defined, or null - */ - public Object getGlobalProperty(String propname) { - if (propname == null) { - return null; - } - try { - Object prop = core.global.get(propname, global); - if (prop == null - || prop == Undefined.instance - || prop == ScriptableObject.NOT_FOUND) { - return null; - } else if (prop instanceof Wrapper) { - return ((Wrapper) prop).unwrap(); - } else { - // Do not return functions as properties as this - // is a potential security problem - return (prop instanceof Function) ? null : prop; - } - } catch (Exception esx) { - app.logError("Error getting global property " + propname + ": " + esx); - return null; - } - } - - /** - * Check if an object has a defined property (public field if it - * is a java object) with that name. - */ - public Object getProperty(Object obj, String propname) { - if (obj == null || propname == null) { - return null; - } else if (obj instanceof Map) { - Object prop = ((Map) obj).get(propname); - // Do not return functions as properties as this - // is a potential security problem - return (prop instanceof Function) ? null : prop; - } - - // use Rhino wrappers and methods to get property - Scriptable so = Context.toObject(obj, global); - - try { - Object prop = so.get(propname, so); - - if (prop == null - || prop == Undefined.instance - || prop == ScriptableObject.NOT_FOUND) { - return null; - } else if (prop instanceof Wrapper) { - return ((Wrapper) prop).unwrap(); - } else { - // Do not return functions as properties as this - // is a potential security problem - return (prop instanceof Function) ? null : prop; - } - } catch (Exception esx) { - app.logError("Error getting property " + propname + ": " + esx); - return null; - } - } - - - /** - * Determine if the given object is mapped to a type of the scripting engine - * @param obj an object - * @return true if the object is mapped to a type - */ - public boolean isTypedObject(Object obj) { - if (obj instanceof Wrapper) - obj = ((Wrapper) obj).unwrap(); - if (obj == null || obj instanceof Map || obj instanceof NativeObject) - return false; - if (obj instanceof IPathElement) { - String protoName = ((IPathElement) obj).getPrototype(); - return protoName != null && !"hopobject".equalsIgnoreCase(protoName); - } - // assume java object is typed - return true; - } - - /** - * Return a string representation for the given object - * @param obj an object - * @return a string representing the object - */ - public String toString(Object obj) { - // not all Rhino types convert to a string as expected - // when calling toString() - try to do better by using - // Rhino's ScriptRuntime.toString(). Note that this - // assumes that people always use this method to get - // a string representation of the object - which is - // currently the case since it's only used in Skin rendering. - try { - return ScriptRuntime.toString(obj); - } catch (Exception x) { - // just return original property object - } - return obj.toString(); - } - - /** - * Provide object serialization for this engine's scripted objects. If no special - * provisions are required, this method should just wrap the stream with an - * ObjectOutputStream and write the object. - * - * @param obj the object to serialize - * @param out the stream to write to - * @throws java.io.IOException - */ - public void serialize(Object obj, OutputStream out) throws IOException { - core.contextFactory.enterContext(); - engines.set(this); - try { - // use a special ScriptableOutputStream that unwraps Wrappers - ScriptableOutputStream sout = new ScriptableOutputStream(out, core.global) { - protected Object replaceObject(Object obj) throws IOException { - if (obj instanceof HopObject) - return new HopObjectProxy((HopObject) obj); - if (obj instanceof Node) - return new HopObjectProxy((Node) obj); - if (obj instanceof GlobalObject) - return new GlobalProxy((GlobalObject) obj); - if (obj instanceof ApplicationBean) - return new ScriptBeanProxy("app"); - if (obj instanceof Application) - return new ApplicationProxy(); - if (obj instanceof RequestBean) - return new ScriptBeanProxy("req"); - if (obj instanceof ResponseBean) - return new ScriptBeanProxy("res"); - if (obj instanceof PathWrapper) - return new ScriptBeanProxy("path"); - return super.replaceObject(obj); - } - }; - // sout.addExcludedName("Xml"); - // sout.addExcludedName("global"); - - sout.writeObject(obj); - sout.flush(); - } finally { - Context.exit(); - } - } - - /** - * Provide object deserialization for this engine's scripted objects. If no special - * provisions are required, this method should just wrap the stream with an - * ObjectIntputStream and read the object. - * - * @param in the stream to read from - * @return the deserialized object - * @throws java.io.IOException - */ - public Object deserialize(InputStream in) throws IOException, ClassNotFoundException { - core.contextFactory.enterContext(); - engines.set(this); - try { - ObjectInputStream sin = new ScriptableInputStream(in, core.global) { - protected Object resolveObject(Object obj) throws IOException { - if (obj instanceof SerializationProxy) { - return ((SerializationProxy) obj).getObject(RhinoEngine.this); - } - return super.resolveObject(obj); - } - }; - return sin.readObject(); - } finally { - Context.exit(); - } - } - - /** - * Add a code resource to a given prototype by immediately compiling and evaluating it. - * - * @param typename the type this resource belongs to - * @param resource a code resource - */ - public void injectCodeResource(String typename, Resource resource) { - // we activate recording on thread scope to make it forward - // property puts to the shared scope (bug 504) - if (global != null) - global.startRecording(); - try { - core.injectCodeResource(typename, resource); - } finally { - if (global != null) - global.stopRecording(); - } - } - - /** - * Return the application we're running in - */ - public Application getApplication() { - return app; - } - - /** - * Return the RequestEvaluator owningthis rhino engine. - */ - public RequestEvaluator getRequestEvaluator() { - return reval; - } - - /** - * Return the Response object of the current evaluation context. - * Proxy method to RequestEvaluator. - */ - public ResponseTrans getResponse() { - return reval.getResponse(); - } - - /** - * Return the Request object of the current evaluation context. - * Proxy method to RequestEvaluator. - */ - public RequestTrans getRequest() { - return reval.getRequest(); - } - - /** - * Return the RhinoCore object for the application this engine belongs to. - * - * @return this engine's RhinoCore instance - */ - public RhinoCore getCore() { - return core; - } - - /** - * Try to get a skin from the parameter object. - */ - public Skin toSkin(Object skinobj, String protoName) throws IOException { - if (skinobj == null) { - return null; - } else if (skinobj instanceof Wrapper) { - skinobj = ((Wrapper) skinobj).unwrap(); - } - - if (skinobj instanceof Skin) { - return (Skin) skinobj; - } else { - return getSkin(protoName, skinobj.toString()); - } - } - - /** - * Get a skin for the given prototype and skin name. This method considers the - * skinpath set in the current response object and does per-response skin - * caching. - */ - public Skin getSkin(String protoName, String skinName) throws IOException { - Skin skin; - ResponseTrans res = getResponse(); - if (skinName.startsWith("#")) { - // evaluate relative subskin name against currently rendering skin - skin = res.getActiveSkin(); - return skin == null ? - null : skin.getSubskin(skinName.substring(1)); - } - - SkinKey key = new SkinKey(protoName, skinName); - skin = res.getCachedSkin(key); - - if (skin == null) { - // retrieve res.skinpath, an array of objects that tell us where to look for skins - // (strings for directory names and INodes for internal, db-stored skinsets) - Object[] skinpath = res.getSkinpath(); - RhinoCore.unwrapSkinpath(skinpath); - skin = app.getSkin(protoName, skinName, skinpath); - res.cacheSkin(key, skin); - } - return skin; - } - - /** - * Determine if we should use a profiler on the current thread. This returns true if - * the rhino.profile app property is set to true (requires restart) and the - * rhino.profile.session property is either unset, or set to "all", or matching - * the session id of the current request. - * @return true if the current request should be profiled - */ - private boolean useProfiler() { - if (!core.hasProfiler) { - return false; - } - String profilerSession = app.getProperty("rhino.profile.session"); - if (profilerSession == null || "all".equalsIgnoreCase(profilerSession)) { - return true; - } - RequestTrans req = getRequest(); - return req != null && req.getSession() != null - && req.getSession().indexOf(profilerSession) == 0; - } - -} diff --git a/src/main/java/helma/scripting/rhino/SerializationProxy.java b/src/main/java/helma/scripting/rhino/SerializationProxy.java deleted file mode 100644 index 75d93d56..00000000 --- a/src/main/java/helma/scripting/rhino/SerializationProxy.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 2008 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino; - -import helma.objectmodel.INode; -import helma.objectmodel.db.NodeHandle; -import helma.objectmodel.db.Node; -import org.mozilla.javascript.Context; - -import java.io.Serializable; - -/** - * Serialization proxy/placeholder interface. This is used for - * for various Helma and Rhino related classes.. - */ -public interface SerializationProxy extends Serializable { - public Object getObject(RhinoEngine engine); -} - -/** - * Serialization proxy for app, req, res, path objects. - */ -class ScriptBeanProxy implements SerializationProxy { - private static final long serialVersionUID = -1002489933060844917L; - - String name; - - ScriptBeanProxy(String name) { - this.name = name; - } - - /** - * Lookup the actual object in the current scope - * - * @return the object represented by this proxy - */ - public Object getObject(RhinoEngine engine) { - try { - Object object = engine.global.get(name, engine.global); - } catch (Exception e) { - System.out.println(name); - } - - return engine.global.get(name, engine.global); - } -} - -/** - * Serialization proxy for the application object. - * - * @author Daniel Ruthardt - * @since 20170918 - */ -class ApplicationProxy implements SerializationProxy { - private static final long serialVersionUID = -3635418002212260600L; - - @Override - public Object getObject(RhinoEngine engine) { - // return the application - return engine.app; - } -} - -/** - * Serialization proxy for global scope - */ -class GlobalProxy implements SerializationProxy { - private static final long serialVersionUID = -3200125667487274257L; - - boolean shared; - - GlobalProxy(GlobalObject scope) { - shared = !scope.isThreadScope; - } - - /** - * Lookup the actual object in the current scope - * - * @return the object represented by this proxy - */ - public Object getObject(RhinoEngine engine) { - return shared ? engine.core.global : engine.global; - } -} - -/** - * Serialization proxy for various flavors of HopObjects/Nodes - */ -class HopObjectProxy implements SerializationProxy { - private static final long serialVersionUID = -4808579296683836009L; - - Object ref; - boolean wrapped = false; - - HopObjectProxy(HopObject obj) { - INode n = obj.getNode(); - if (n == null) { - ref = obj.getClassName(); - } else { - if (n instanceof Node) { - ref = ((Node) n).getHandle(); - } else { - ref = n; - } - } - wrapped = true; - } - - HopObjectProxy(Node node) { - ref = node.getHandle(); - } - - /** - * Lookup the actual object in the current scope - * - * @return the object represented by this proxy - */ - public Object getObject(RhinoEngine engine) { - if (ref instanceof String) - return engine.core.getPrototype((String) ref); - else if (ref instanceof NodeHandle) { - Object n = ((NodeHandle) ref).getNode(engine.app.getWrappedNodeManager()); - return wrapped ? Context.toObject(n, engine.global) : n; - } - return Context.toObject(ref, engine.global); - } - -} diff --git a/src/main/java/helma/scripting/rhino/SkinKey.java b/src/main/java/helma/scripting/rhino/SkinKey.java deleted file mode 100644 index 58893e1f..00000000 --- a/src/main/java/helma/scripting/rhino/SkinKey.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino; - -/** - * A helper class to serve as Map key for two strings - */ -final class SkinKey { - - private final String type; - - private final String id; - - // lazily initialized hashcode - private transient int hashcode = 0; - - /** - * make a key for a persistent Object, describing its datasource and id. - */ - public SkinKey(String type, String id) { - this.type = type == null ? "" : type; - this.id = id; - } - - /** - * - * - * @param what the other key to be compared with this one - * - * @return true if both keys are identical - */ - public boolean equals(Object what) { - - if (!(what instanceof SkinKey)) { - return false; - } - - SkinKey k = (SkinKey) what; - - return (type.equals(k.type)) && (id.equals(k.id)); - } - - /** - * - * - * @return this key's hash code - */ - public int hashCode() { - if (hashcode == 0) { - hashcode = (17 + (37 * type.hashCode()) + - (+37 * id.hashCode())); - } - - return hashcode; - } - -} diff --git a/src/main/java/helma/scripting/rhino/debug/HelmaDebugger.java b/src/main/java/helma/scripting/rhino/debug/HelmaDebugger.java deleted file mode 100644 index c623284e..00000000 --- a/src/main/java/helma/scripting/rhino/debug/HelmaDebugger.java +++ /dev/null @@ -1,314 +0,0 @@ -/* -* Helma License Notice -* -* The contents of this file are subject to the Helma License -* Version 2.0 (the "License"). You may not use this file except in -* compliance with the License. A copy of the License is available at -* http://adele.helma.org/download/helma/license.txt -* -* Copyright 1998-2003 Helma Software. All Rights Reserved. -* -* $RCSfile$ -* $Author$ -* $Revision$ -* $Date$ -*/ - -package helma.scripting.rhino.debug; - -import org.mozilla.javascript.tools.debugger.SwingGui; -import org.mozilla.javascript.tools.debugger.Dim; - -import javax.swing.tree.*; -import javax.swing.*; -import javax.swing.event.TreeSelectionListener; -import javax.swing.event.TreeSelectionEvent; -import java.util.*; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.KeyAdapter; -import java.awt.*; - -import helma.util.StringUtils; - - -public class HelmaDebugger extends Dim implements TreeSelectionListener { - - DebugGui gui; - JTree tree; - JList list; - DebuggerTreeNode treeRoot; - DefaultTreeModel treeModel; - HashMap treeNodes = new HashMap(); - HashMap scriptNames = new HashMap(); - - - public HelmaDebugger(String title) { - gui = new DebugGui(this, title); - gui.pack(); - gui.setVisible(true); - } - - void createTreeNode(String sourceName, Dim.SourceInfo sourceInfo) { - String[] path = StringUtils.split(sourceName, ":/\\"); - DebuggerTreeNode node = treeRoot; - DebuggerTreeNode newNode = null; - int start = Math.max(0, path.length - 3); - for (int i = start; i < path.length; i++) { - DebuggerTreeNode n = node.get(path[i]); - if (n == null) { - n = new DebuggerTreeNode(path[i]); - node.add(n); - if (newNode == null) newNode = n; - } - node = n; - } - treeNodes.put(sourceName, node); - scriptNames.put(node, sourceName); - if (newNode != null) { - SwingUtilities.invokeLater(new NodeInserter(newNode)); - } - } - - void openScript(TreePath path) { - if (path == null) - return; - Object node = path.getLastPathComponent(); - if (node == null) - return; - String sourceName = (String) scriptNames.get(node); - if (sourceName == null) - return; - gui.showFileWindow(sourceName, -1); - } - - void openFunction(FunctionItem function) { - if (function == null) - return; - FunctionSource src = function.src; - if (src != null) { - SourceInfo si = src.sourceInfo(); - String url = si.url(); - int lineNumber = src.firstLine(); - gui.showFileWindow(url, lineNumber); - } - } - - - - public void valueChanged(TreeSelectionEvent e) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode) - tree.getLastSelectedPathComponent(); - - if (node == null) return; - - Object script = scriptNames.get(node); - if (script != null) { - // openScript(script); - } - } - - public void setVisible(boolean visible) { - gui.setVisible(visible); - } - - public void dispose() { - super.dispose(); - gui.setVisible(false); - // Calling dispose() on the gui causes shutdown hook to hang on windows - - // see http://helma.org/bugs/show_bug.cgi?id=586#c2 - // gui.dispose(); - } - - class DebuggerTreeNode extends DefaultMutableTreeNode { - - private static final long serialVersionUID = -5881442554351749706L; - - public DebuggerTreeNode(Object obj) { - super(obj); - } - - public DebuggerTreeNode get(String name) { - Enumeration children = this.children(); - while (children.hasMoreElements()) { - DebuggerTreeNode node = (DebuggerTreeNode) children.nextElement(); - if (node != null && name.equals(node.getUserObject())) - return node; - } - return null; - } - } - - class NodeInserter implements Runnable { - MutableTreeNode node; - - NodeInserter(MutableTreeNode node) { - this.node = node; - } - - public void run() { - MutableTreeNode parent = (MutableTreeNode) node.getParent(); - if (parent == treeRoot && treeRoot.getChildCount() == 1) { - tree.makeVisible(new TreePath(new Object[]{parent, node})); - } - treeModel.insertNodeInto(node, parent, parent.getIndex(node)); - } - } - - class DebugGui extends SwingGui { - - private static final long serialVersionUID = 8930558796272502640L; - - String currentSourceUrl; - - public DebugGui(Dim dim, String title) { - super(dim, title); - Container contentPane = getContentPane(); - Component main = contentPane.getComponent(1); - contentPane.remove(main); - - treeRoot = new DebuggerTreeNode(title); - tree = new JTree(treeRoot); - treeModel = new DefaultTreeModel(treeRoot); - tree.setModel(treeModel); - tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - tree.addTreeSelectionListener(HelmaDebugger.this); - // tree.setRootVisible(false); - // track double clicks - tree.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent evt) { - openScript(tree.getSelectionPath()); - } - }); - // track enter key - tree.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent evt) { - if (evt.getKeyCode() == KeyEvent.VK_ENTER) - openScript(tree.getSelectionPath()); - } - }); - JScrollPane treeScroller = new JScrollPane(tree); - treeScroller.setPreferredSize(new Dimension(180, 300)); - - list = new JList(); - // no bold font lists for me, thanks - list.setFont(list.getFont().deriveFont(Font.PLAIN)); - list.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent evt) { - openFunction((FunctionItem) list.getSelectedValue()); - } - }); - list.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent evt) { - if (evt.getKeyCode() == KeyEvent.VK_ENTER) - openFunction((FunctionItem) list.getSelectedValue()); - } - }); - JScrollPane listScroller = new JScrollPane(list); - listScroller.setPreferredSize(new Dimension(180, 200)); - - JSplitPane split1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT); - split1.setTopComponent(treeScroller); - split1.setBottomComponent(listScroller); - split1.setOneTouchExpandable(true); - split1.setResizeWeight(0.66); - - JSplitPane split2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); - split2.setLeftComponent(split1); - split2.setRightComponent(main); - split2.setOneTouchExpandable(true); - contentPane.add(split2, BorderLayout.CENTER); - } - - public void updateSourceText(final Dim.SourceInfo sourceInfo) { - // super.updateSourceText(sourceInfo); - String filename = sourceInfo.url(); - if (!treeNodes.containsKey(filename)) { - createTreeNode(filename, sourceInfo); - } - SwingUtilities.invokeLater(new Runnable() { - public void run() { - updateFileWindow(sourceInfo); - } - }); - } - - protected void showFileWindow(String sourceName, int lineNumber) { - if (!isVisible()) - setVisible(true); - if (!sourceName.equals(currentSourceUrl)) { - updateFunctionList(sourceName); - DebuggerTreeNode node = (DebuggerTreeNode) treeNodes.get(sourceName); - if (node != null) { - TreePath path = new TreePath(node.getPath()); - tree.setSelectionPath(path); - tree.scrollPathToVisible(path); - } - } - super.showFileWindow(sourceName, lineNumber); - } - - private void updateFunctionList(String sourceName) { - // display functions for opened script file - currentSourceUrl = sourceName; - Vector functions = new Vector(); - SourceInfo si = sourceInfo(sourceName); - String[] lines = si.source().split("\\r\\n|\\r|\\n"); - int length = si.functionSourcesTop(); - for (int i = 0; i < length; i++) { - FunctionSource src = si.functionSource(i); - if (sourceName.equals(src.sourceInfo().url())) { - functions.add(new FunctionItem(src, lines)); - } - } - // Collections.sort(functions); - list.setListData(functions); - } - } - - class FunctionItem implements Comparable { - - FunctionSource src; - String name; - String line = ""; - - FunctionItem(FunctionSource src, String[] lines) { - this.src = src; - name = src.name(); - if ("".equals(name)) { - try { - line = lines[src.firstLine() - 1]; - int f = line.indexOf("function") - 1; - StringBuffer b = new StringBuffer(); - boolean assignment = false; - while (f-- > 0) { - char c = line.charAt(f); - if (c == ':' || c == '=') - assignment = true; - else if (assignment && Character.isJavaIdentifierPart(c) - || c == '$' || c == '.') - b.append(c); - else if (!Character.isWhitespace(c) || b.length() > 0) - break; - } - name = b.length() > 0 ? b.reverse().toString() : ""; - } catch (Exception x) { - // fall back to default name - name = ""; - } - } - } - - public int compareTo(Object o) { - FunctionItem other = (FunctionItem) o; - return name.compareTo(other.name); - } - - public String toString() { - return name; - } - - } -} - diff --git a/src/main/java/helma/scripting/rhino/debug/Profiler.java b/src/main/java/helma/scripting/rhino/debug/Profiler.java deleted file mode 100644 index cd6d5c96..00000000 --- a/src/main/java/helma/scripting/rhino/debug/Profiler.java +++ /dev/null @@ -1,157 +0,0 @@ -package helma.scripting.rhino.debug; - -import org.mozilla.javascript.debug.Debugger; -import org.mozilla.javascript.debug.DebuggableScript; -import org.mozilla.javascript.debug.DebugFrame; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.Scriptable; - -import java.util.*; - -import helma.util.StringUtils; - -public class Profiler implements Debugger { - - HashMap frames = new HashMap(); - - /** - * Create a new profiler. - */ - public Profiler() {} - - /** - * Implementws handleCompilationDone in interface org.mozilla.javascript.debug.Debugger - */ - public void handleCompilationDone(Context cx, DebuggableScript script, String source) {} - - /** - * Implements getFrame() in interface org.mozilla.javascript.debug.Debugger - */ - public DebugFrame getFrame(Context cx, DebuggableScript script) { - if (script.isFunction()) { - String name = getFunctionName(script); - ProfilerFrame frame = (ProfilerFrame) frames.get(name); - if (frame == null) { - frame = new ProfilerFrame(name); - frames.put(name, frame); - } - return frame; - } - return null; - } - - /** - * Get a string representation for the given script - * @param script a function or script - * @return the file and/or function name of the script - */ - static String getFunctionName(DebuggableScript script) { - if (script.isFunction()) { - StringBuffer b = new StringBuffer(script.getSourceName()).append(" #"); - b.append(script.getLineNumbers()[0]); - String funcName = script.getFunctionName(); - if (funcName != null && funcName.length() > 0) { - b.append(": ").append(script.getFunctionName()); - } - return b.toString(); - } else { - return script.getSourceName(); - } - } - - public String getResult() { - ProfilerFrame[] f = (ProfilerFrame[]) frames.values().toArray(new ProfilerFrame[0]); - Arrays.sort(f, new Comparator() { - public int compare(Object o1, Object o2) { - return ((ProfilerFrame)o2).runtime - ((ProfilerFrame)o1).runtime; - } - }); - int length = Math.min(100, f.length); - int prefixLength = length < 2 ? 0 : Integer.MAX_VALUE; - int maxLength = 0; - for (int i = 0; i < length; i++) { - maxLength = Math.max(maxLength, f[i].name.length()); - if (i < length - 1) { - prefixLength = Math.min(prefixLength, - StringUtils.getCommonPrefix(f[i].name, f[i+1].name).length()); - } - } - maxLength = maxLength + 30 - prefixLength; - StringBuffer buffer = new StringBuffer(" total average calls path\n"); - for (int i = 0; i < maxLength; i++) { - buffer.append('-'); - } - buffer.append('\n'); - for (int i = 0; i < length; i++) { - buffer.append(f[i].renderLine(prefixLength)); - } - return buffer.toString(); - } - - class ProfilerFrame implements DebugFrame { - - Stack timer = new Stack(); - int runtime, invocations, lineNumber; - String name; - - ProfilerFrame(String name) { - this.name = name; - } - - /** - * Called when execution is ready to start bytecode interpretation - * for entered a particular function or script. - */ - public void onEnter(Context cx, Scriptable activation, - Scriptable thisObj, Object[] args) { - - long time = System.nanoTime(); - timer.push(Long.valueOf(time)); - } - - /** - * Called when thrown exception is handled by the function or script. - */ - public void onExceptionThrown(Context cx, Throwable ex) { - // TODO: figure out if this is called in addition or in place of to onExit - } - - /** - * Called when the function or script for this frame is about to return. - */ - public void onExit(Context cx, boolean byThrow, Object resultOrException) { - invocations ++; - Long time = (Long) timer.pop(); - runtime += System.nanoTime() - time.longValue(); - } - - /** - * Called when the function or script executes a 'debugger' statement. - * - * @param cx current Context for this thread - */ - public void onDebuggerStatement(Context cx) { - // not implemented - } - - /** - * Called when executed code reaches new line in the source. - */ - public void onLineChange(Context cx, int lineNumber) { - this.lineNumber = lineNumber; - } - - public String renderLine(int prefixLength) { - long millis = Math.round(this.runtime / 1000000); - Formatter formatter = new java.util.Formatter(); - Object[] args = new Object[] { - Integer.valueOf((int) millis), - Integer.valueOf(Math.round(millis / invocations)), - Integer.valueOf(invocations), - name.substring(prefixLength) - }; - formatter.format("%1$7d ms %2$5d ms %3$6d %4$s%n", args); - return formatter.toString(); - } - } -} diff --git a/src/main/java/helma/scripting/rhino/debug/Tracer.java b/src/main/java/helma/scripting/rhino/debug/Tracer.java deleted file mode 100644 index 81a9d29a..00000000 --- a/src/main/java/helma/scripting/rhino/debug/Tracer.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile: Tracer.java,v $ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino.debug; - -import helma.framework.ResponseTrans; -import helma.util.HtmlEncoder; -import org.mozilla.javascript.*; -import org.mozilla.javascript.debug.*; -import java.util.ArrayList; - -public class Tracer implements Debugger { - - ResponseTrans res; - TracerFrame frame = null; - - /** - * Create a tracer that writes to this response object - * @param res the response object to write to - */ - public Tracer(ResponseTrans res) { - this.res = res; - } - - /** - * Implementws handleCompilationDone in interface org.mozilla.javascript.debug.Debugger - */ - public void handleCompilationDone(Context cx, DebuggableScript script, String source) {} - - /** - * Implements getFrame() in interface org.mozilla.javascript.debug.Debugger - */ - public DebugFrame getFrame(Context cx, DebuggableScript script) { - if (script.isFunction()) { - frame = new TracerFrame(script, frame); - return frame; - } - return null; - } - - /** - * Get a string representation for the given script - * @param script a function or script - * @return the file and/or function name of the script - */ - static String toString(DebuggableScript script) { - if (script.isFunction()) { - return script.getSourceName() + ": " + script.getFunctionName(); - } else { - return script.getSourceName(); - } - } - - class TracerFrame implements DebugFrame { - - TracerFrame parent; - ArrayList children = new ArrayList(); - DebuggableScript script; - int currentLine, depth = 0; - long time; - - TracerFrame(DebuggableScript script, TracerFrame parent) { - this.script = script; - this.parent = parent; - if (parent != null) { - parent.children.add(this); - depth = parent.depth + 1; - } - } - - /** - * Called when execution is ready to start bytecode interpretation - * for entered a particular function or script. - */ - public void onEnter(Context cx, Scriptable activation, - Scriptable thisObj, Object[] args) { - - time = System.currentTimeMillis(); - } - - /** - * Called when thrown exception is handled by the function or script. - */ - public void onExceptionThrown(Context cx, Throwable ex) { - res.debug("Exception Thrown: " + ex); - } - - /** - * Called when the function or script for this frame is about to return. - */ - public void onExit(Context cx, boolean byThrow, Object resultOrException) { - time = System.currentTimeMillis() - time; - frame = parent; - if (parent == null) - render(); - } - - /** - * Called when the function or script executes a 'debugger' statement. - * - * @param cx current Context for this thread - */ - public void onDebuggerStatement(Context cx) { - // not implemented - } - - /** - * Called when executed code reaches new line in the source. - */ - public void onLineChange(Context cx, int lineNumber) { - currentLine = lineNumber; - } - - public void render() { - // Simplify Trace by dropping fast invocations. May be useful when looking - // looking for bottlenecks, but not when trying to find out wtf is going on - // if (time <= 1) - // return; - StringBuffer b = new StringBuffer("Trace: "); - for (int i = 0; i < depth; i++) - b.append(". "); - b.append(Tracer.toString(script)); - b.append("("); - - /* for (int i = 0; i < args.length; i++) { - b.append(HtmlEncoder.encodeAll(ScriptRuntime.toString(args[i]))); - - if (i < args.length - 1) { - b.append(", "); - } - } */ - - b.append(")"); - - b.append(" "); - b.append(time); - b.append(" millis"); - - res.debug(b); - - for (int i = 0; i < children.size(); i++) - ((TracerFrame) children.get(i)).render(); - } - } -} - diff --git a/src/main/java/helma/scripting/rhino/extensions/DatabaseObject.java b/src/main/java/helma/scripting/rhino/extensions/DatabaseObject.java deleted file mode 100644 index 0a5c180e..00000000 --- a/src/main/java/helma/scripting/rhino/extensions/DatabaseObject.java +++ /dev/null @@ -1,651 +0,0 @@ -// Database.java -// FESI Copyright (c) Jean-Marc Lugrin, 1999 -// -// This program 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 of the License, or (at your option) any later version. - -// This program 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 - - -// Modified to use Helma database connections, Hannes Wallnoefer 2000-2003 - -package helma.scripting.rhino.extensions; - -import helma.objectmodel.db.DbSource; -import java.util.Enumeration; -import java.util.Vector; -import java.io.IOException; -import java.io.Reader; -import java.math.BigDecimal; -import java.sql.*; - - -/** - * A Database object, representing a connection to a JDBC Driver - */ -public class DatabaseObject { - - private transient Connection connection = null; // Null if not connected - private transient DatabaseMetaData databaseMetaData = null; - private transient String driverName = null; - private transient Exception lastError = null; - private transient boolean driverOK = false; - - /** - * Create a new database object based on a hop data source. - * - * @param dbsource The name of the DB source - */ - - public DatabaseObject(DbSource dbsource) { - try { - connection = dbsource.getConnection (); - driverName = dbsource.getDriverName (); - } catch (Exception e) { - // System.err.println("##Cannot find driver class: " + e); - // e.printStackTrace(); - lastError = e; - } - driverOK = true; - } - - /** - * Create a new database object based on a driver name, with driver on the classpath - * - * @param driverName The class name of the JDBC driver - */ - - DatabaseObject(String driverName) { - this.driverName = driverName; - try { - Class driverClass = Class.forName(driverName); - if (!Driver.class.isAssignableFrom(driverClass)) { - - // System.err.println("##Bad class " + driverClass); - lastError = new RuntimeException("Class " + driverClass + " is not a JDBC driver"); - } - driverClass.newInstance(); // may be needed by some drivers, harmless for others - } catch (ClassNotFoundException e) { - // System.err.println("##Cannot find driver class: " + e); - // e.printStackTrace(); - lastError = e; - } catch (InstantiationException e) { - - // System.err.println("##Cannot instantiate driver class: " + e); - // e.printStackTrace(); - lastError = e; - } catch (IllegalAccessException e) { - // ignore as this may happen depending on driver, it may not be severe - // for example because the instance was created at class initialization time - } - driverOK = true; - } - - - /** - * Create the database prototype object which cannot be connected - * - */ - - DatabaseObject() { - this.driverName = null; - driverOK = false; // Avoid usage of this object - } - - public String getClassName() { - return "DatabaseObject"; - } - - public String toString() { - if (driverName==null) return "[database protoype]"; - return "[Database: '" + driverName + - (driverOK ? - (connection==null ? "' - disconnected] " : " - connected]") - : " - in error]"); - } - - public String toDetailString() { - return "ES:[Object: builtin " + this.getClass().getName() + ":" + - this.toString() + "]"; - } - - public Object getLastError() { - if (lastError == null) { - return null; - } else { - return lastError; - } - } - - - /** - * Connect to the database, using the specific url, optional user name and password - * - * @param url the database URL - * @param userName the database user name - * @param password the database password - * @return true if successful, false otherwise - */ - public boolean connect(String url, String userName, String password) { - if (!driverOK) { - lastError = new SQLException("Driver not initialized properly - cannot connect"); - return false; - } - lastError = null; - try { - if (userName == null) { - connection = DriverManager.getConnection(url); - } else { - connection = DriverManager.getConnection(url,userName,password); - } - } catch(Exception e) { - // System.err.println("##Cannot connect: " + e); - // e.printStackTrace(); - lastError = e; - return false; - } - return true; - } - - - /** - * Disconnect from the database, nop if not conected - * - * @return true if successful, false if error during idsconnect - */ - public boolean disconnect() { - if (!driverOK) { - lastError = new SQLException("Driver not initialized properly - cannot disconnect"); - return false; - } - lastError = null; - if (connection != null) { - try { - connection.close(); - connection = null; - lastError = null; - } catch (SQLException e) { - // System.err.println("##Cannot disonnect: " + e); - // e.printStackTrace(); - lastError = e; - return false; - } - } - return true; - } - - public void release() { - if (driverOK) { - disconnect(); - } - } - - public RowSet executeRetrieval(String sql) { - if (connection==null) { - lastError = new SQLException("JDBC driver not connected"); - return null; - } - Statement statement = null; - ResultSet resultSet = null; - - try { - connection.setReadOnly(true); - statement = connection.createStatement(); - resultSet = statement.executeQuery(sql); // will return true if first result is a result set - - return new RowSet(sql, this, statement, resultSet); - } catch (SQLException e) { - // System.err.println("##Cannot retrieve: " + e); - // e.printStackTrace(); - lastError = e; - try { - if (statement != null) statement.close(); - } catch (Exception ignored) { - } - statement = null; - return null; - } - } - - public RowSet executePreparedRetrieval(PreparedStatement statement) { - ResultSet resultSet = null; - - try { - resultSet = statement.executeQuery(); - return new RowSet(statement.toString(), this, statement, resultSet); - } catch (SQLException e) { - lastError = e; - try { - if (statement != null) statement.close(); - } catch (Exception ignored) { - } - statement = null; - return null; - } - } - - public int executeCommand(String sql) { - int count = 0; - - if (connection==null) { - lastError = new SQLException("JDBC driver not connected"); - return -1; - } - - Statement statement = null; - try { - - connection.setReadOnly(false); - statement = connection.createStatement(); - count = statement.executeUpdate(sql); // will return true if first result is a result set - } catch (SQLException e) { - // System.err.println("##Cannot retrieve: " + e); - // e.printStackTrace(); - lastError = e; - try { - if (statement != null) statement.close(); - } catch (Exception ignored) { - } - statement = null; - return -1; - } - if (statement!=null) try { - statement.close(); - } catch (SQLException e) { - // ignored - } - return count; - } - - public Object getMetaData() - { - if (databaseMetaData == null) - try { - databaseMetaData = connection.getMetaData(); - } catch (SQLException e) { - // ignored - } - return databaseMetaData; - } - - /** - * A RowSet object - */ - public static class RowSet { - - private transient String sql = null; - private transient Statement statement = null; - private transient ResultSet resultSet = null; - private transient ResultSetMetaData resultSetMetaData = null; - private transient Vector colNames = null; - private transient boolean lastRowSeen = false; - private transient boolean firstRowSeen = false; - private transient Exception lastError = null; - - RowSet(String sql, - DatabaseObject database, - Statement statement, - ResultSet resultSet) throws SQLException { - this.sql = sql; - this.statement = statement; - this.resultSet = resultSet; - - if (sql==null) throw new NullPointerException("sql"); - if (resultSet==null) throw new NullPointerException("resultSet"); - if (statement==null) throw new NullPointerException("statement"); - if (database==null) throw new NullPointerException("database"); - - try { - - this.resultSetMetaData = resultSet.getMetaData(); - int numcols = resultSetMetaData.getColumnCount(); - //IServer.getLogger().log("$$NEXT : " + numcols); - colNames = new Vector(numcols); - for (int i=0; i0 && idx <=colNames.size()) { - return (String) colNames.elementAt(idx-1); // to base 0 - } else { - lastError = new SQLException("Column index (base 1) " + idx + - " out of range, max: " +colNames.size()); - return null; - } - } - - - public int getColumnDatatypeNumber(int idx) { - if (resultSet == null) { - lastError = new SQLException("Attempt to access a released result set"); - return -1; - } - if (idx>0 && idx <=colNames.size()) { - try { - return resultSetMetaData.getColumnType(idx); - } catch (SQLException e) { - lastError = e; - return -1; - } - } else { - lastError = new SQLException("Column index (base 1) " + idx + - " out of range, max: " +colNames.size()); - return -1; - } - } - - - public String getColumnDatatypeName(int idx) { - if (resultSet == null) { - lastError = new SQLException("Attempt to access a released result set"); - return null; - } - if (idx>0 && idx <=colNames.size()) { - try { - return resultSetMetaData.getColumnTypeName(idx); - } catch (SQLException e) { - lastError = e; - return null; - } - } else { - lastError = new SQLException("Column index (base 1) " + idx + - " out of range, max: " +colNames.size()); - return null; - } - } - - - public Object getColumnItem(String propertyName) { - if (resultSet == null) { - lastError = new SQLException("Attempt to access a released result set"); - return null; - } - if (!firstRowSeen) { - lastError = new SQLException("Attempt to access data before the first row is read"); - return null; - } - try { - try { - int index = Integer.parseInt(propertyName); - return getProperty(index); - } catch (NumberFormatException e) { - int index = resultSet.findColumn(propertyName); - return getProperty(index); - } - } catch (SQLException e) { - //System.err.println("##Cannot get property '" + propertyName + "' " + e); - //e.printStackTrace(); - lastError = e; - } - return null; - } - - /* FIXME: dunno if this method is still used somewhere - public Object getProperty(String propertyName, int hash) { - //System.err.println(" &&& Getting property '" + propertyName + "'"); - - // Length property is firsy checked - - // First return system or or prototype properties - if (propertyName.equals("length")) { - return Integer.valueOf(colNames.size()); - } else { - if (resultSet == null) { - lastError = new SQLException("Attempt to access a released result set"); - return null; - } - if (!firstRowSeen) { - lastError = new SQLException("Attempt to access data before the first row is read"); - return null; - } - try { - int index = -1; // indicates not a valid index value - try { - char c = propertyName.charAt(0); - if ('0' <= c && c <= '9') { - index = Integer.parseInt(propertyName); - } - } catch (NumberFormatException e) { - } catch (StringIndexOutOfBoundsException e) { // for charAt - } - if (index>=0) { - return getProperty(index); - } - Object value = resultSet.getObject(propertyName); - // IServer.getLogger().log("&& @VALUE : " + value); - lastError = null; - return value; - } catch (SQLException e) { - // System.err.println("##Cannot get property '" + propertyName + "' " + e); - // e.printStackTrace(); - lastError = e; - } - } - return null; - } - */ - - public Object getProperty(int index) { - if (!firstRowSeen) { - lastError = new SQLException("Attempt to access data before the first row is read"); - return null; - } - if (resultSet == null) { - lastError = new SQLException("Attempt to access a released result set"); - return null; - } - - lastError = null; - try { - int type = resultSetMetaData.getColumnType(index); - switch (type) { - case Types.BIT: - case Types.BOOLEAN: - return resultSet.getBoolean(index) ? Boolean.TRUE : Boolean.FALSE; - - case Types.TINYINT: - case Types.BIGINT: - case Types.SMALLINT: - case Types.INTEGER: - return Long.valueOf(resultSet.getLong(index)); - - case Types.REAL: - case Types.FLOAT: - case Types.DOUBLE: - return Double.valueOf(resultSet.getDouble(index)); - - case Types.DECIMAL: - case Types.NUMERIC: - BigDecimal num = resultSet.getBigDecimal(index); - if (num == null) { - break; - } - - if (num.scale() > 0) { - return Double.valueOf(num.doubleValue()); - } else { - return Long.valueOf(num.longValue()); - } - - case Types.VARBINARY: - case Types.BINARY: - return resultSet.getString(index); - - case Types.LONGVARBINARY: - case Types.LONGVARCHAR: - try { - return resultSet.getString(index); - } catch (SQLException x) { - Reader in = resultSet.getCharacterStream(index); - char[] buffer = new char[2048]; - int read = 0; - int r = 0; - - while ((r = in.read(buffer, read, buffer.length - read)) > -1) { - read += r; - - if (read == buffer.length) { - // grow input buffer - char[] newBuffer = new char[buffer.length * 2]; - - System.arraycopy(buffer, 0, newBuffer, 0, - buffer.length); - buffer = newBuffer; - } - } - return new String(buffer, 0, read); - } - - case Types.DATE: - case Types.TIME: - case Types.TIMESTAMP: - return resultSet.getTimestamp(index); - - case Types.NULL: - return null; - - case Types.CLOB: - Clob cl = resultSet.getClob(index); - if (cl == null) { - return null; - } - char[] c = new char[(int) cl.length()]; - Reader isr = cl.getCharacterStream(); - isr.read(c); - return String.copyValueOf(c); - - default: - return resultSet.getString(index); - } - } catch (SQLException e) { - // System.err.println("##Cannot get property: " + e); - // e.printStackTrace(); - lastError = e; - } catch (IOException ioe) { - lastError = ioe; - } - - return null; - } - - /* - * Returns an enumerator for the key elements of this object. - * - * @return the enumerator - may have 0 length of coulmn names where not found - */ - public Enumeration getProperties() { - if (resultSet == null) { - return (new Vector()).elements(); - } - return colNames.elements(); - } - - - public String[] getSpecialPropertyNames() { - return new String[] {"length"}; - } - - - public boolean next() { - boolean status = false; - if (lastRowSeen) { - lastError = new SQLException("Attempt to access a next row after last row has been returned"); - return false; - } - if (resultSet == null) { - lastError = new SQLException("Attempt to access a released result set"); - return false; - } - try { - status = resultSet.next(); - lastError = null; - } catch (SQLException e) { - // System.err.println("##Cannot do next:" + e); - // e.printStackTrace(); - lastError = e; - } - if (status) firstRowSeen = true; - else lastRowSeen = true; - return status; - } - - public String toString() { - return "[RowSet: '"+sql+"'" + - (resultSet==null ? " - released]" : - (lastRowSeen ? " - at end]" : - (firstRowSeen ? "]" : " - at start]"))); - } - - } - -} - - diff --git a/src/main/java/helma/scripting/rhino/extensions/FileObject.java b/src/main/java/helma/scripting/rhino/extensions/FileObject.java deleted file mode 100644 index 4876613f..00000000 --- a/src/main/java/helma/scripting/rhino/extensions/FileObject.java +++ /dev/null @@ -1,509 +0,0 @@ -// FileIO.java -// FESI Copyright (c) Jean-Marc Lugrin, 1999 -// -// This program 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 of the License, or (at your option) any later version. - -// This program 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 helma.scripting.rhino.extensions; - - -import java.io.BufferedReader; -import java.io.File; -import java.io.Reader; -import java.io.Writer; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.io.EOFException; -import java.io.IOException; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.Function; -import org.mozilla.javascript.FunctionObject; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; -import org.mozilla.javascript.Undefined; -import java.lang.reflect.Member; -import java.lang.reflect.Method; - -/** - * An EcmaScript FileIO 'File' object - */ -public class FileObject extends ScriptableObject { - private static final long serialVersionUID = -9098307162306984764L; - - File file = null; - Object readerWriter = null; - boolean atEOF = false; - String lastLine = null; - Throwable lastError = null; - - protected FileObject() { - } - - protected FileObject(String fileName) { - // always convert to absolute file straight away, since - // relative file name handling is pretty broken in java.io.File - file = new File(fileName).getAbsoluteFile(); - } - - protected FileObject(String pathName, String fileName) { - // always convert to absolute file straight away, since - // relative file name handling is pretty broken in java.io.File - file = new File(pathName, fileName).getAbsoluteFile(); - } - - public static FileObject fileObjCtor(Context cx, Object[] args, - Function ctorObj, boolean inNewExpr) { - if (args.length == 0 || args[0] == Undefined.instance) { - throw new IllegalArgumentException("File constructor called without argument"); - } - if (args.length < 2 || args[1] == Undefined.instance) { - return new FileObject(args[0].toString()); - } - return new FileObject(args[0].toString(), args[1].toString()); - } - - public static void init(Scriptable scope) { - Method[] methods = FileObject.class.getDeclaredMethods(); - ScriptableObject proto = new FileObject(); - proto.setPrototype(getObjectPrototype(scope)); - Member ctorMember = null; - for (int i=0; i"; - return file.toString(); - } - - public String toDetailString() { - return "ES:[Object: builtin " + this.getClass().getName() + ":" + - ((file == null) ? "null" : file.toString()) + "]"; - } - - protected void setError(Throwable e) { - lastError = e; - } - - public boolean exists() { - if (file == null) return false; - return file.exists(); - } - - public boolean open() { - if (readerWriter != null) { - setError(new IllegalStateException("File already open")); - return false; - } - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return false; - } - - // We assume that the BufferedReader and PrintWriter creation - // cannot fail except if the FileReader/FileWriter fails. - // Otherwise we have an open file until the reader/writer - // get garbage collected. - try{ - if (file.exists()) { - readerWriter = new BufferedReader(new FileReader(file)); - } else { - readerWriter = new PrintWriter(new FileWriter(file)); - } - return true; - } catch (IOException e) { - setError(e); - return false; - } - } - - public boolean isOpened() { - return (readerWriter != null); - } - - public boolean close() { - if (readerWriter == null) - return false; - try { - if (readerWriter instanceof Reader) { - ((Reader) readerWriter).close(); - } else { - ((Writer) readerWriter).close(); - } - readerWriter = null; - return true; - } catch (IOException e) { - setError(e); - readerWriter = null; - return false; - } - } - - public boolean write(Object what) { - if (readerWriter == null) { - setError(new IllegalStateException("File not opened")); - return false; - } - if (! (readerWriter instanceof PrintWriter)) { - setError(new IllegalStateException("File not opened for writing")); - return false; - } - PrintWriter writer = (PrintWriter) readerWriter; - if (what != null) { - writer.print(what.toString()); - } - // writer.println(); - return true; - } - - public boolean writeln(Object what) { - if (readerWriter == null) { - setError(new IllegalStateException("File not opened")); - return false; - } - if (! (readerWriter instanceof PrintWriter)) { - setError(new IllegalStateException("File not opened for writing")); - return false; - } - PrintWriter writer = (PrintWriter) readerWriter; - if (what != null) { - writer.print(what.toString()); - } - writer.println(); - return true; - } - - public String readln() { - if (readerWriter == null) { - setError(new IllegalStateException("File not opened")); - return null; - } - if (! (readerWriter instanceof BufferedReader)) { - setError(new IllegalStateException("File not opened for reading")); - return null; - } - if (atEOF) { - setError(new EOFException()); - return null; - } - if (lastLine!=null) { - String line = lastLine; - lastLine = null; - return line; - } - BufferedReader reader = (BufferedReader) readerWriter; - // Here lastLine is null, return a new line - try { - String line = reader.readLine(); - if (line == null) { - atEOF = true; - setError(new EOFException()); - } - return line; - } catch (IOException e) { - setError(e); - return null; - } - } - - public boolean eof() { - if (readerWriter == null) { - setError(new IllegalStateException("File not opened")); - return true; - } - if (! (readerWriter instanceof BufferedReader)) { - setError(new IllegalStateException("File not opened for read")); - return true; - } - if (atEOF) return true; - if (lastLine!=null) return false; - BufferedReader reader = (BufferedReader) readerWriter; - try { - lastLine = reader.readLine(); - if (lastLine == null) atEOF = true; - return atEOF; - } catch (IOException e) { - setError(e); - return true; - } - } - - public boolean isFile() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return false; - } - return file.isFile(); - } - - public boolean isDirectory() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return false; - } - return file.isDirectory(); - } - - public boolean flush() { - if (readerWriter == null) { - setError(new IllegalStateException("File not opened")); - return false; - } - if (readerWriter instanceof Writer) { - try { - ((Writer) readerWriter).flush(); - } catch (IOException e) { - setError(e); - return false; - } - } else { - setError(new IllegalStateException("File not opened for write")); - return false; // not supported by reader - } - return true; - } - - - public double getLength() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return -1; - } - return file.length(); - } - - public double lastModified() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return (double) 0L; - } - return (double) file.lastModified(); - } - - public String error() { - if (lastError == null) { - return ""; - } else { - String exceptionName = lastError.getClass().getName(); - int l = exceptionName.lastIndexOf("."); - if (l>0) exceptionName = exceptionName.substring(l+1); - return exceptionName +": " + lastError.getMessage(); - } - } - - public void clearError() { - lastError = null; - } - - public boolean remove() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return false; - } - if (readerWriter != null) { - setError(new IllegalStateException("An openened file cannot be removed")); - return false; - } - return file.delete(); - } - - public boolean renameTo(FileObject toFile) { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized source File object")); - return false; - } - if (toFile.file == null) { - setError(new IllegalArgumentException("Uninitialized target File object")); - return false; - } - if (readerWriter != null) { - setError(new IllegalStateException("An openened file cannot be renamed")); - return false; - } - if (toFile.readerWriter!=null) { - setError(new IllegalStateException("You cannot rename to an openened file")); - return false; - } - return file.renameTo(toFile.file); - } - - public boolean canRead() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return false; - } - return file.canRead(); - } - - public boolean canWrite() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return false; - } - return file.canWrite(); - } - - public String getParent() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return ""; - } - String parent = file.getParent(); - return (parent==null ? "" : parent); - } - - public String getName() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return ""; - } - String name = file.getName(); - return (name==null ? "" : name); - } - - public String getPath() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return ""; - } - String path = file.getPath(); - return (path==null ? "" : path); - } - - public String getAbsolutePath() { - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return ""; - } - String absolutPath = file.getAbsolutePath(); - return (absolutPath==null ? "" : absolutPath); - } - - public boolean isAbsolute() { - if (file == null) return false; - return file.isAbsolute(); - } - - public boolean mkdir() { - if (file == null) return false; - if(readerWriter != null) return false; - return file.mkdirs(); // Using multi directory version - } - - public Object list() { - if (file == null) return null; - if(readerWriter != null) return null; - if (!file.isDirectory()) return null; - return file.list(); - } - - - public String readAll() { - // Open the file for readAll - if (readerWriter != null) { - setError(new IllegalStateException("File already open")); - return null; - } - if (file == null) { - setError(new IllegalArgumentException("Uninitialized File object")); - return null; - } - try{ - if (file.exists()) { - readerWriter = new BufferedReader(new FileReader(file)); - } else { - setError(new IllegalStateException("File does not exist")); - return null; - } - if(!file.isFile()) { - setError(new IllegalStateException("File is not a regular file")); - return null; - } - - // read content line by line to setup properl eol - StringBuffer buffer = new StringBuffer((int) (file.length()*1.10)); - BufferedReader reader = (BufferedReader) readerWriter; - while (true) { - String line = reader.readLine(); - if (line == null) { - break; - } - buffer.append(line); - buffer.append("\n"); // EcmaScript EOL - } - - - // Close the file - ((Reader) readerWriter).close(); - readerWriter = null; - return buffer.toString(); - } catch (IOException e) { - readerWriter = null; - setError(e); - return null; - } - } - - protected File getFile() { - return file; - } - -} //class FileObject - diff --git a/src/main/java/helma/scripting/rhino/extensions/FtpObject.java b/src/main/java/helma/scripting/rhino/extensions/FtpObject.java deleted file mode 100644 index 1e624f71..00000000 --- a/src/main/java/helma/scripting/rhino/extensions/FtpObject.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino.extensions; - -import org.apache.commons.net.ftp.*; -import java.io.*; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.Function; -import org.mozilla.javascript.FunctionObject; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; -import org.mozilla.javascript.Undefined; -import java.lang.reflect.Member; -import java.lang.reflect.Method; - - -/** - * A FTP-client object that allows to do some FTP from HOP applications. - * FTP support is far from complete but can easily be extended if more - * functionality is needed. - * This uses the NetComponent classes from savarese.org (ex oroinc.com). - */ -public class FtpObject extends ScriptableObject { - private static final long serialVersionUID = 3470670009973887555L; - - private FTPClient ftpclient; - private String server; - private Exception lastError = null; - private File localDir = null; - - /** - * Create a new FTP Client - * - * @param srvstr the name of the server to connect to - */ - FtpObject(String srvstr) { - this.server = srvstr; - } - - FtpObject() { - } - - /** - * - * - * @return ... - */ - public String getClassName() { - return "FtpClient"; - } - - /** - * - * - * @return ... - */ - public String toString() { - return "[FtpClient]"; - } - - /** - * - * - * @return ... - */ - public String toDetailString() { - return "ES:[Object: builtin " + this.getClass().getName() + ":" + - this.toString() + "]"; - } - - Exception getLastError() { - if (lastError == null) { - return null; - } else { - return lastError; - } - } - - /** - * Login to the FTP server - * - * @param username the user name - * @param password the user's password - * @return true if successful, false otherwise - */ - public boolean login(String username, String password) { - if (server == null) { - return false; - } - - try { - ftpclient = new FTPClient(); - ftpclient.connect(server); - - return ftpclient.login(username, password); - } catch (Exception x) { - return false; - } catch (NoClassDefFoundError x) { - return false; - } - } - - public boolean cd(String path) { - if (ftpclient == null) { - return false; - } - - try { - ftpclient.changeWorkingDirectory(path); - - return true; - } catch (Exception wrong) { - } - - return false; - } - - public boolean mkdir(String dir) { - if (ftpclient == null) { - return false; - } - - try { - return ftpclient.makeDirectory(dir); - } catch (Exception wrong) { - } - - return false; - } - - public boolean lcd(String dir) { - try { - localDir = new File(dir); - - if (!localDir.exists()) { - localDir.mkdirs(); - } - - return true; - } catch (Exception wrong) { - } - - return false; - } - - public boolean putFile(String localFile, String remoteFile) { - if (ftpclient == null) { - return false; - } - - try { - File f = (localDir == null) ? new File(localFile) : new File(localDir, localFile); - InputStream fin = new BufferedInputStream(new FileInputStream(f)); - - ftpclient.storeFile(remoteFile, fin); - fin.close(); - - return true; - } catch (Exception wrong) { - } - - return false; - } - - public boolean putString(Object obj, String remoteFile) { - if (ftpclient == null || obj == null) { - return false; - } - - try { - byte[] bytes = null; - - // check if this already is a byte array - if (obj instanceof byte[]) { - bytes = (byte[]) obj; - } - - if (bytes == null) { - bytes = obj.toString().getBytes(); - } - - ByteArrayInputStream bin = new ByteArrayInputStream(bytes); - - ftpclient.storeFile(remoteFile, bin); - - return true; - } catch (Exception wrong) { - } - - return false; - } - - public boolean getFile(String remoteFile, String localFile) { - if (ftpclient == null) { - return false; - } - - try { - File f = (localDir == null) ? new File(localFile) : new File(localDir, localFile); - OutputStream out = new BufferedOutputStream(new FileOutputStream(f)); - - ftpclient.retrieveFile(remoteFile, out); - out.close(); - - return true; - } catch (Exception wrong) { - } - - return false; - } - - public Object getString(String remoteFile) { - if (ftpclient == null) { - return null; - } - - try { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - - ftpclient.retrieveFile(remoteFile, bout); - - return bout.toString(); - } catch (Exception wrong) { - } - - return null; - } - - /** - * Disconnect from FTP server - * - * @return true if successful, false otherwise - */ - public boolean logout() { - if (ftpclient != null) { - try { - ftpclient.logout(); - } catch (IOException ignore) { - } - - try { - ftpclient.disconnect(); - } catch (IOException ignore) { - } - } - - return true; - } - - public boolean binary() { - if (ftpclient != null) { - try { - ftpclient.setFileType(FTP.BINARY_FILE_TYPE); - - return true; - } catch (IOException ignore) { - } - } - - return false; - } - - public boolean ascii() { - if (ftpclient != null) { - try { - ftpclient.setFileType(FTP.ASCII_FILE_TYPE); - - return true; - } catch (IOException ignore) { - } - } - - return false; - } - - - - public static FtpObject ftpObjCtor(Context cx, Object[] args, - Function ctorObj, boolean inNewExpr) { - if (args.length != 1 || args[0] == Undefined.instance) { - throw new IllegalArgumentException("Ftp constructor called without argument"); - } - return new FtpObject(args[0].toString()); - } - - public static void init(Scriptable scope) { - Method[] methods = FtpObject.class.getDeclaredMethods(); - ScriptableObject proto = new FtpObject(); - proto.setPrototype(getObjectPrototype(scope)); - Member ctorMember = null; - for (int i=0; i -1) { - try { - URL url = new URL(str); - in = url.openStream(); - } catch (MalformedURLException mux) { - in = new FileInputStream(str); - } - } else { - in = new FileInputStream(str); - } - } - - if (in == null) { - String msg = "Unrecognized argument in Image.getInfo(): "; - msg += arg == null ? "null" : arg.getClass().toString(); - throw new IllegalArgumentException(msg); - } - - info.setInput(in); - if (info.check()) { - ret = Context.toObject(info, scope); - } - - } catch (IOException e) { - // do nothing, returns null later - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException ee) { - } - } - } - return ret; - } - } -} diff --git a/src/main/java/helma/scripting/rhino/extensions/MailObject.java b/src/main/java/helma/scripting/rhino/extensions/MailObject.java deleted file mode 100644 index 2b2eaf07..00000000 --- a/src/main/java/helma/scripting/rhino/extensions/MailObject.java +++ /dev/null @@ -1,488 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino.extensions; - -import helma.util.*; -import org.mozilla.javascript.*; -import java.io.*; -import java.util.*; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import javax.activation.*; -import javax.mail.Address; -import javax.mail.Message; -import javax.mail.Multipart; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; -import javax.mail.internet.MimeUtility; - -/** - * A JavaScript wrapper around a JavaMail message class to send - * mail via SMTP from Helma - */ -public class MailObject extends ScriptableObject implements Serializable { - - private static final long serialVersionUID = -4834981850233741039L; - - public static final int OK = 0; - public static final int SUBJECT = 10; - public static final int TEXT = 11; - public static final int MIMEPART = 12; - public static final int TO = 20; - public static final int CC = 21; - public static final int BCC = 22; - public static final int FROM = 23; - public static final int REPLYTO = 24; - public static final int SEND = 30; - - MimeMessage message; - Multipart multipart; - String multipartType = "mixed"; - StringBuffer buffer; - int status; - - // these are only set on the prototype object - Session session = null; - Properties props = null; - String host = null; - - /** - * Creates a new Mail object. - */ - MailObject(Session session) { - this.status = OK; - message = new MimeMessage(session); - } - - - /** - * Creates a new MailObject prototype. - * - * @param mprops the Mail properties - */ - MailObject(Properties mprops) { - this.status = OK; - this.props = mprops; - } - - /** - * Overrides abstract method in ScriptableObject - */ - public String getClassName() { - return "Mail"; - } - - /** - * Get the cached JavaMail session. This is similar to Session.getDefaultSession(), - * except that we check if the properties have changed. - */ - protected Session getSession() { - if (props == null) { - throw new NullPointerException("getSession() called on non-prototype MailObject"); - } - - // set the mail encoding system property if it isn't set. Necessary - // on Macs, where we otherwise get charset=MacLatin - // http://java.sun.com/products/javamail/javadocs/overview-summary.html - System.setProperty("mail.mime.charset", - props.getProperty("mail.charset", "ISO-8859-15")); - - // get the host property - first try "mail.host", then "smtp" property - String newHost = props.getProperty("mail.host"); - if (newHost == null) { - newHost = props.getProperty("smtp"); - } - - // has the host changed? - boolean hostChanged = (host == null && newHost != null) || - (host != null && !host.equals(newHost)); - - if (session == null || hostChanged) { - host = newHost; - - // create properties and for the Session. Only set mail host if it is - // explicitly set, otherwise we'll go with the system default. - Properties sessionProps = new Properties(); - if (host != null) { - sessionProps.put("mail.smtp.host", host); - } - - session = Session.getInstance(sessionProps); - } - - return session; - } - - /** - * JavaScript constructor, called by the Rhino runtime. - */ - public static MailObject mailObjCtor(Context cx, Object[] args, - Function ctorObj, boolean inNewExpr) { - MailObject proto = (MailObject) ctorObj.get("prototype", ctorObj); - return new MailObject(proto.getSession()); - } - - /** - * Initialize Mail extension for the given scope, called by RhinoCore. - */ - public static void init(Scriptable scope, Properties props) { - Method[] methods = MailObject.class.getDeclaredMethods(); - MailObject proto = new MailObject(props); - proto.setPrototype(getObjectPrototype(scope)); - Member ctorMember = null; - for (int i=0; i - */ -public class XmlObject { - RhinoCore core; - - /** - * Creates a new XmlObject object. - * - * @param core ... - */ - public XmlObject(RhinoCore core) { - this.core = core; - } - - /** - * Writes a HopObject to an XML file - * - * @param node the HopObject to encode - * @param file the file to write to - * @return true - * @throws IOException if something went wrong along the way - */ - public boolean write(INode node, String file) throws IOException { - return write(node, file, false); - } - - /** - * Writes a HopObject to an XML file, optionally using shallow/db mode - * - * @param node the HopObject to encode - * @param file the file to write to - * @param dbmode whether to write a shallow copy - * @return true - * @throws IOException if something went wrong along the way - */ - public boolean write(INode node, String file, boolean dbmode) - throws IOException { - // we definitly need a node - if (node == null) { - throw new RuntimeException("First argument in Xml.write() is not an hopobject"); - } - - if (file == null) { - throw new RuntimeException("Second argument file name must not be null"); - } - - File tmpFile = new File(file + ".tmp." + XmlWriter.generateID()); - XmlWriter writer = new XmlWriter(tmpFile, "UTF-8"); - - writer.setDatabaseMode(dbmode); - writer.write(node); - writer.close(); - File finalFile = new File(file); - - if (finalFile.exists()) { - finalFile.delete(); - } - tmpFile.renameTo(finalFile); - core.getApplication().logEvent("wrote xml to " + finalFile.getAbsolutePath()); - - return true; - } - - /** - * Transforms a HopObject to XML and returns the result as string - * - * @param node the HopObject to encode - * @return the XML representing the HopObject - * @throws IOException if something went wrong along the way - */ - public String writeToString(INode node) throws IOException { - return writeToString(node, false); - } - - /** - * Transforms a HopObject to XML and returns the result as string, - * optionally using shallow/db mode - * - * @param node the HopObject to encode - * @return the XML representing the HopObject - * @param dbmode whether to write a shallow copy - * @throws IOException if something went wrong - */ - public String writeToString(INode node, boolean dbmode) throws IOException { - // we definitly need a node - if (node == null) { - throw new RuntimeException("First argument in Xml.write() is not an hopobject"); - } - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - XmlWriter writer = new XmlWriter(out, "UTF-8"); - - // in case we ever want to limit serialization depth... - // if (arguments.length > 1 && arguments[1] instanceof ESNumber) - // writer.setMaxLevels(arguments[1].toInt32()); - writer.setDatabaseMode(dbmode); - writer.write(node); - writer.flush(); - return out.toString("UTF-8"); - } - - /** - * Reads an XML document from a file and creates a HopObject out of it - * - * @param file the file name - * @return the HopObject - * @throws RuntimeException ... - */ - public Object read(String file) throws RuntimeException { - return read(file, null); - } - - /** - * Reads an XML document from a file and reads it into the HopObject argument - * - * @param file the file name - * @param node the HopObject to use for conversion - * @return the HopObject - */ - public Object read(String file, INode node) throws RuntimeException { - if (file == null) { - throw new RuntimeException("Missing arguments in Xml.read()"); - } - - if (node == null) { - // make sure we have a node, even if 2nd arg doesn't exist or is not a node - node = new Node(null, null, core.getApplication().getWrappedNodeManager()); - } - - try { - XmlReader reader = new XmlReader(core.app.getWrappedNodeManager()); - INode result = reader.read(new File(file), node); - - return core.getNodeWrapper(result); - } catch (NoClassDefFoundError e) { - throw new RuntimeException("Can't load XML parser:" + e); - } catch (Exception f) { - throw new RuntimeException(f.toString()); - } - } - - /** - * Reads an XML document from an XML literal and creates a HopObject out of it - * - * @param str the XML string - * @return the HopObject - * @throws RuntimeException ... - */ - public Object readFromString(String str) throws RuntimeException { - return readFromString(str, null); - } - - /** - * Reads an XML document from an XML literal and creates a HopObject out of it - * - * @param str the XML string - * @param node the HopObject to use for conversion - * @return ... - * @throws RuntimeException ... - */ - public Object readFromString(String str, INode node) - throws RuntimeException { - if (str == null) { - throw new RuntimeException("Missing arguments in Xml.read()"); - } - - if (node == null) { - // make sure we have a node, even if 2nd arg doesn't exist or is not a node - node = new Node(null, null, core.getApplication().getWrappedNodeManager()); - } - - try { - XmlReader reader = new XmlReader(core.app.getWrappedNodeManager()); - INode result = reader.read(new StringReader(str), node); - - return core.getNodeWrapper(result); - } catch (NoClassDefFoundError e) { - throw new RuntimeException("Can't load XML parser:" + e); - } catch (Exception f) { - f.printStackTrace(); - throw new RuntimeException(f.toString()); - } - } - - - /** - * Retrieves an XML document from a given URL and transforms it into a HopObject - * - * @param url the URL containing the XML to be parsed - * @return a HopObject obtained from parsing the XML - */ - public Object get(String url) { - return get(url, null); - } - - - /** - * Retrieves an XML document from a given URL and transforms it into a HopObject - * - * @param url the URL containing the XML to be parsed - * @param conversionRules a file name pointing to the conversion rules - * @return a HopObject obtained from parsing the XML - * @see - */ - public Object get(String url, String conversionRules) { - if (url == null) { - throw new RuntimeException("Xml.get() needs a location as an argument"); - } - - try { - XmlConverter converter; - - if (conversionRules != null) { - converter = new XmlConverter(conversionRules); - } else { - converter = new XmlConverter(); - } - - INode node = new Node(null, null, - core.getApplication().getWrappedNodeManager()); - INode result = converter.convert(url, node); - - return core.getNodeWrapper(result); - } catch (NoClassDefFoundError e) { - throw new RuntimeException("Can't load dom-capable xml parser."); - } - } - - /** - * Transforms a XML literal into a HopObject - * - * @param str an XML literal - * @return a HopObject obtained from parsing the XML - */ - public Object getFromString(String str) { - return getFromString(str, null); - } - - - /** - * Transforms a XML literal into a HopObject according to the rules specified in - * the file defined by conversionRules - * - * @param str an XML literal - * @param conversionRules a file name pointing to the conversion rules - * @return a HopObject obtained from parsing the XML - * @see - */ - public Object getFromString(String str, String conversionRules) { - if (str == null) { - throw new RuntimeException("Xml.getFromString() needs an XML string as parameter"); - } - - try { - XmlConverter converter; - - if (conversionRules != null) { - converter = new XmlConverter(conversionRules); - } else { - converter = new XmlConverter(); - } - - INode node = new Node(null, null, core.getApplication().getWrappedNodeManager()); - INode result = converter.convertFromString(str, node); - - return core.getNodeWrapper(result); - } catch (NoClassDefFoundError e) { - throw new RuntimeException("Can't load dom-capable xml parser."); - } - } - - -} diff --git a/src/main/java/helma/scripting/rhino/extensions/XmlRpcObject.java b/src/main/java/helma/scripting/rhino/extensions/XmlRpcObject.java deleted file mode 100644 index e532bcc8..00000000 --- a/src/main/java/helma/scripting/rhino/extensions/XmlRpcObject.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.scripting.rhino.extensions; - -import helma.framework.core.Application; -import helma.scripting.rhino.RhinoCore; -import org.apache.xmlrpc.XmlRpcClient; -import org.mozilla.javascript.*; - -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.util.Vector; - -/** - * An extension to transparently call and serve XML-RPC from Rhino. - * The extension adds constructors for XML-RPC clients and servers to the Global Object. - * - * All argument conversion is done automatically. Currently the following argument and return - * types are supported: - *
      - *
    • plain objects (with all properties returned by ESObject.getProperties ())
    • - *
    • arrays
    • - *
    • strings
    • - *
    • date objects
    • - *
    • booleans
    • - *
    • integer and float numbers (long values are not supported!)
    • - *
    - * - */ -public class XmlRpcObject extends BaseFunction { - - private static final long serialVersionUID = 1479373761583135438L; - - String url = null; - String method = null; - - XmlRpcObject(String url) { - this.url = url; - this.method = null; - } - - XmlRpcObject(String url, String method) { - this.url = url; - this.method = method; - } - - /** - * This method is used as HopObject constructor from JavaScript. - */ - public static Object xmlrpcObjectConstructor(Context cx, Object[] args, - Function ctorObj, boolean inNewExpr) { - if (args.length == 0 || args.length > 2) { - throw new IllegalArgumentException("Wrong number of arguments in constructor for XML-RPC client"); - } - if (args.length == 1) { - String url = args[0].toString(); - return new XmlRpcObject(url); - } else { - String url = args[0].toString(); - String method = args[1].toString(); - return new XmlRpcObject(url, method); - } - - } - - /** - * Called by the evaluator after the extension is loaded. - */ - public static void init(Scriptable scope) { - Method[] methods = XmlRpcObject.class.getDeclaredMethods(); - Member ctorMember = null; - for (int i=0; i 0) { - CookieTrans[] resCookies = restrans.getCookies(); - - for (int i = 0; i < resCookies.length; i++) - try { - Cookie c = resCookies[i].getCookie("/", resCookieDomain); - - response.addCookie(c); - } catch (Exception x) { - getApplication().logEvent("Error adding cookie: " + x); - } - } - - // write response - writeResponse(request, response, reqtrans, restrans); - } catch (Exception x) { - log("Exception in execute", x); - try { - if (debug) { - sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, - "Server error: " + x); - } else { - sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, - "The server encountered an error while processing your request. " + - "Please check back later."); - } - } catch (IOException iox) { - log("Exception in sendError", iox); - } - } - } - - protected void writeResponse(HttpServletRequest req, HttpServletResponse res, - RequestTrans hopreq, ResponseTrans hopres) - throws IOException { - if (hopres.getForward() != null) { - sendForward(res, req, hopres); - return; - } - - if (hopres.getETag() != null) { - res.setHeader("ETag", hopres.getETag()); - } - - if (hopres.getRedirect() != null) { - sendRedirect(req, res, hopres.getRedirect(), hopres.getStatus()); - } else if (hopres.getNotModified()) { - res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); - } else { - if (!hopres.isCacheable() || !caching) { - // Disable caching of response. - if (isOneDotOne(req.getProtocol())) { - // for HTTP 1.1 - res.setHeader("Cache-Control", - "no-cache, no-store, must-revalidate, max-age=0"); - } else { - // for HTTP 1.0 - res.setDateHeader("Expires", System.currentTimeMillis() - 10000); - res.setHeader("Pragma", "no-cache"); - } - } - - if (hopres.getRealm() != null) { - res.setHeader("WWW-Authenticate", "Basic realm=\"" + hopres.getRealm() + "\""); - } - - if (hopres.getStatus() > 0) { - res.setStatus(hopres.getStatus()); - } - - // set last-modified header to now - long modified = hopres.getLastModified(); - if (modified > -1) { - res.setDateHeader("Last-Modified", modified); - } - - res.setContentLength(hopres.getContentLength()); - res.setContentType(hopres.getContentType()); - - if (!"HEAD".equalsIgnoreCase(req.getMethod())) { - byte[] content = hopres.getContent(); - if (content != null) { - try { - OutputStream out = res.getOutputStream(); - out.write(content); - out.flush(); - } catch (Exception iox) { - log("Exception in writeResponse: " + iox); - } - } - } - } - } - - void sendError(HttpServletResponse response, int code, String message) - throws IOException { - if (response.isCommitted()) { - return; - } - response.reset(); - response.setStatus(code); - response.setContentType("text/html"); - - if (!"true".equalsIgnoreCase(getApplication().getProperty("suppressErrorPage"))) { - Writer writer = response.getWriter(); - - writer.write("

    "); - writer.write("Error in application "); - try { - writer.write(getApplication().getName()); - } catch (Exception besafe) { - // ignore - } - writer.write("

    "); - writer.write(message); - writer.write(""); - writer.flush(); - } - } - - void sendRedirect(HttpServletRequest req, HttpServletResponse res, String url, int status) { - String location = url; - - if (url.indexOf("://") == -1) { - // need to transform a relative URL into an absolute one - String scheme = req.getScheme(); - StringBuffer loc = new StringBuffer(scheme); - - loc.append("://"); - loc.append(req.getServerName()); - - int p = req.getServerPort(); - - // check if we need to include server port - if ((p > 0) && - (("http".equals(scheme) && (p != 80)) || - ("https".equals(scheme) && (p != 443)))) { - loc.append(":"); - loc.append(p); - } - - if (!url.startsWith("/")) { - String requri = req.getRequestURI(); - int lastSlash = requri.lastIndexOf("/"); - - if (lastSlash == (requri.length() - 1)) { - loc.append(requri); - } else if (lastSlash > -1) { - loc.append(requri.substring(0, lastSlash + 1)); - } else { - loc.append("/"); - } - } - - loc.append(url); - location = loc.toString(); - } - - // if status code was explicitly set use that, or use 303 for HTTP 1.1, - // 302 for earlier protocol versions - if (status >= 301 && status <= 303) { - res.setStatus(status); - } else if (isOneDotOne(req.getProtocol())) { - res.setStatus(HttpServletResponse.SC_SEE_OTHER); - } else { - res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); - } - - res.setContentType("text/html"); - res.setHeader("Location", location); - } - - /** - * Forward the request to a static file. The file must be reachable via - * the context's protectedStatic resource base. - */ - void sendForward(HttpServletResponse res, HttpServletRequest req, - ResponseTrans hopres) throws IOException { - String forward = hopres.getForward(); - // Jetty 5.1 bails at forward paths without leading slash, so fix it - if (!forward.startsWith("/")) { - forward = "/" + forward; - } - ServletContext cx = getServletConfig().getServletContext(); - String path = cx.getRealPath(forward); - if (path == null) { - throw new IOException("Resource " + forward + " not found"); - } - - File file = new File(path); - // check if the client has an up-to-date copy so we can - // send a not-modified response - if (checkNotModified(file, req, res)) { - res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); - return; - } - int length = (int) file.length(); - res.setContentLength(length); - // Erase charset so content-type is not messed with. - hopres.setCharset(null); - res.setContentType(hopres.getContentType()); - // Define full Content-Range, as required by HTML5 video and audio - res.setHeader("Content-Range", "bytes 0-" + length + "/" + length); - - InputStream in = cx.getResourceAsStream(forward); - if (in == null) { - throw new IOException("Can't read " + path); - } - try { - OutputStream out = res.getOutputStream(); - - int bufferSize = 4096; - byte buffer[] = new byte[bufferSize]; - int l; - - while (length > 0) { - if (length < bufferSize) { - l = in.read(buffer, 0, length); - } else { - l = in.read(buffer, 0, bufferSize); - } - if (l == -1) { - break; - } - - length -= l; - out.write(buffer, 0, l); - } - } finally { - in.close(); - } - } - - private boolean checkNotModified(File file, HttpServletRequest req, HttpServletResponse res) { - // we do two rounds of conditional requests: - // first ETag based, then based on last modified date. - // calculate ETag checksum on last modified date and content length. - byte[] checksum = new byte[16]; - long n = file.lastModified(); - for (int i=0; i<8; i++) { - checksum[i] = (byte) (n); - n >>>= 8; - } - n = file.length(); - for (int i=8; i<16; i++) { - checksum[i] = (byte) (n); - n >>>= 8; - } - String etag = "\"" + new String(Base64.encodeBase64(checksum)) + "\""; //$NON-NLS-1$//$NON-NLS-2$ - res.setHeader("ETag", etag); //$NON-NLS-1$ - String etagHeader = req.getHeader("If-None-Match"); //$NON-NLS-1$ - if (etagHeader != null) { - StringTokenizer st = new StringTokenizer(etagHeader, ", \r\n"); - while (st.hasMoreTokens()) { - if (etag.equals(st.nextToken())) { - return true; - } - } - } - // as a fallback, since some browsers don't support ETag based - // conditional GET for embedded images and stuff, check last modified date. - // date headers don't do milliseconds, round to seconds - long lastModified = (file.lastModified() / 1000) * 1000; - long ifModifiedSince = req.getDateHeader("If-Modified-Since"); - if (lastModified == ifModifiedSince) { - return true; - } - res.setDateHeader("Last-Modified", lastModified); - return false; - } - - - /** - * Check if the session cookie is set and valid for this request. - * If not, create a new one. - */ - private void checkSessionCookie(HttpServletRequest request, - HttpServletResponse response, - RequestTrans reqtrans, - String domain) { - // check if we need to create a session id. - if (protectedSessionCookie) { - // If protected session cookies are enabled we also force a new session - // if the existing session id doesn't match the client's ip address - StringBuffer buffer = new StringBuffer(); - String ip = request.getHeader("X-Forwarded-For"); - if (ip != null && ip.length() != 0) { - addIPAddress(buffer, ip); - } else { - addIPAddress(buffer, request.getRemoteAddr()); - } - // Not sure, if this line can be removed - addIPAddress(buffer, request.getHeader("Client-ip")); - if (reqtrans.getSession() == null || !reqtrans.getSession().startsWith(buffer.toString())) { - createSession(response, buffer.toString(), reqtrans, domain); - } - } else if (reqtrans.getSession() == null) { - createSession(response, "", reqtrans, domain); - } - } - - /** - * Create a new session cookie. - * - * @param response the servlet response - * @param prefix the session id prefix - * @param reqtrans the request object - * @param domain the cookie domain - */ - private void createSession(HttpServletResponse response, - String prefix, - RequestTrans reqtrans, - String domain) { - Application app = getApplication(); - String id = null; - while (id == null || app.getSession(id) != null) { - long l = secureRandom ? - random.nextLong() : - random.nextLong() + Runtime.getRuntime().freeMemory() ^ hashCode(); - if (l < 0) - l = -l; - id = prefix + Long.toString(l, 36); - } - - reqtrans.setSession(id); - - StringBuffer buffer = new StringBuffer(sessionCookieName); - buffer.append("=").append(id).append("; Path=/"); - if (domain != null) { - // lowercase domain for IE - buffer.append("; Domain=").append(domain.toLowerCase()); - } - if (!"false".equalsIgnoreCase(app.getProperty("cookies.httpOnly"))) { - buffer.append("; HttpOnly"); - } - if ("true".equalsIgnoreCase(app.getProperty("cookies.secure"))) { - buffer.append("; Secure"); - } - response.addHeader("Set-Cookie", buffer.toString()); - } - - /** - * Adds an the 3 most significant bytes of an IP address header to the - * session cookie id. Some headers may contain a list of IP addresses - * separated by comma - in that case, care is taken that only the first - * one is considered. - */ - private void addIPAddress(StringBuffer b, String addr) { - if (addr != null) { - int cut = addr.indexOf(','); - if (cut > -1) { - addr = addr.substring(0, cut); - } - cut = addr.lastIndexOf('.'); - if (cut == -1) { - cut = addr.lastIndexOf(':'); - } - if (cut > -1) { - b.append(addr.substring(0, cut+1)); - } - } - } - - - /** - * Put name and value pair in map. When name already exist, add value - * to array of values. - */ - private static void putMapEntry(Map map, String name, String value) { - String[] newValues = null; - String[] oldValues = (String[]) map.get(name); - - if (oldValues == null) { - newValues = new String[1]; - newValues[0] = value; - } else { - newValues = new String[oldValues.length + 1]; - System.arraycopy(oldValues, 0, newValues, 0, oldValues.length); - newValues[oldValues.length] = value; - } - - map.put(name, newValues); - } - - protected List parseUploads(JakartaServletRequestContext reqcx, RequestTrans reqtrans, - final UploadStatus uploadStatus, String encoding) - throws FileUploadException, UnsupportedCharsetException, IOException { - // handle file upload - DiskFileItemFactory factory = DiskFileItemFactory.builder().get(); - JakartaServletFileUpload upload = new JakartaServletFileUpload(factory); - // use upload limit for individual file size, but also set a limit on overall size - upload.setFileSizeMax(uploadLimit * 1024); - upload.setSizeMax(totalUploadLimit * 1024); - - // register upload tracker with user's session - if (uploadStatus != null) { - upload.setProgressListener(new ProgressListener() { - public void update(long bytesRead, long contentLength, int itemsRead) { - uploadStatus.update(bytesRead, contentLength, itemsRead); - } - }); - } - - List uploads = upload.parseRequest(reqcx); - Iterator it = uploads.iterator(); - - while (it.hasNext()) { - FileItem item = (FileItem) it.next(); - String name = item.getFieldName(); - Object value; - // check if this is an ordinary HTML form element or a file upload - if (item.isFormField()) { - value = item.getString(Charset.forName(encoding)); - } else { - value = new MimePart(item); - } - // if multiple values exist for this name, append to _array - reqtrans.addPostParam(name, value); - } - return uploads; - } - - protected void parseParameters(HttpServletRequest request, RequestTrans reqtrans, - String encoding) - throws IOException { - // check if there are any parameters before we get started - String queryString = request.getQueryString(); - String contentType = request.getContentType(); - boolean isFormPost = "post".equals(request.getMethod().toLowerCase()) - && contentType != null - && contentType.toLowerCase().startsWith("application/x-www-form-urlencoded"); - - if (queryString == null && !isFormPost) { - return; - } - - HashMap parameters = new HashMap(); - - // Parse any query string parameters from the request - if (queryString != null) { - parseParameters(parameters, queryString.getBytes(), encoding, false); - if (!parameters.isEmpty()) { - reqtrans.setParameters(parameters, false); - parameters.clear(); - } - } - - // Parse any posted parameters in the input stream - if (isFormPost) { - int max = request.getContentLength(); - if (max > totalUploadLimit * 1024) { - throw new IOException("Exceeded Upload limit"); - } - int len = 0; - byte[] buf = new byte[max]; - ServletInputStream is = request.getInputStream(); - - while (len < max) { - int next = is.read(buf, len, max - len); - - if (next < 0) { - break; - } - - len += next; - } - - // is.close(); - parseParameters(parameters, buf, encoding, true); - if (!parameters.isEmpty()) { - reqtrans.setParameters(parameters, true); - parameters.clear(); - } - } - } - - /** - * Append request parameters from the specified String to the specified - * Map. It is presumed that the specified Map is not accessed from any - * other thread, so no synchronization is performed. - *

    - * IMPLEMENTATION NOTE: URL decoding is performed - * individually on the parsed name and value elements, rather than on - * the entire query string ahead of time, to properly deal with the case - * where the name or value includes an encoded {@code =} or {@code &} character - * that would otherwise be interpreted as a delimiter. - * - * NOTE: byte array data is modified by this method. Caller beware. - * - * @param map Map that accumulates the resulting parameters - * @param data Input string containing request parameters - * @param encoding Encoding to use for converting hex - * - * @exception UnsupportedEncodingException if the data is malformed - */ - public static void parseParameters(Map map, byte[] data, String encoding, boolean isPost) - throws UnsupportedEncodingException { - if ((data != null) && (data.length > 0)) { - int ix = 0; - int ox = 0; - String key = null; - String value = null; - - while (ix < data.length) { - byte c = data[ix++]; - - switch ((char) c) { - case '&': - value = new String(data, 0, ox, encoding); - - if (key != null) { - putMapEntry(map, key, value); - key = null; - } - - ox = 0; - - break; - - case '=': - if (key == null) { - key = new String(data, 0, ox, encoding); - ox = 0; - } else { - data[ox++] = c; - } - - break; - - case '+': - data[ox++] = (byte) ' '; - - break; - - case '%': - data[ox++] = (byte) ((convertHexDigit(data[ix++]) << 4) + - convertHexDigit(data[ix++])); - - break; - - default: - data[ox++] = c; - } - } - - if (key != null) { - // The last value does not end in '&'. So save it now. - value = new String(data, 0, ox, encoding); - putMapEntry(map, key, value); - } else if (ox > 0) { - // Store any residual bytes in req.data.http_post_remainder - value = new String(data, 0, ox, encoding); - if (isPost) { - putMapEntry(map, "http_post_remainder", value); - } else { - putMapEntry(map, "http_get_remainder", value); - } - } - } - } - - /** - * Convert a byte character value to hexidecimal digit value. - * - * @param b the character value byte - */ - private static byte convertHexDigit(byte b) { - if ((b >= '0') && (b <= '9')) { - return (byte) (b - '0'); - } - - if ((b >= 'a') && (b <= 'f')) { - return (byte) (b - 'a' + 10); - } - - if ((b >= 'A') && (b <= 'F')) { - return (byte) (b - 'A' + 10); - } - - return 0; - } - - boolean isOneDotOne(String protocol) { - if (protocol == null) { - return false; - } - return protocol.endsWith("1.1"); - } - - String getPathInfo(HttpServletRequest req) - throws UnsupportedEncodingException { - StringTokenizer t = new StringTokenizer(req.getContextPath(), "/"); - int prefixTokens = t.countTokens(); - - t = new StringTokenizer(req.getServletPath(), "/"); - prefixTokens += t.countTokens(); - - String uri = req.getRequestURI(); - t = new StringTokenizer(uri, "/"); - - int uriTokens = t.countTokens(); - StringBuffer pathbuffer = new StringBuffer(); - - String encoding = getApplication().getCharset(); - - for (int i = 0; i < uriTokens; i++) { - String token = t.nextToken(); - - if (i < prefixTokens) { - continue; - } - - if (i > prefixTokens) { - pathbuffer.append('/'); - } - - pathbuffer.append(UrlEncoded.decode(token, encoding)); - } - - // append trailing "/" if it is contained in original URI - if (uri.endsWith("/")) - pathbuffer.append('/'); - - return pathbuffer.toString(); - } - - /** - * Return servlet info - * @return the servlet info - */ - public String getServletInfo() { - return "Helma Servlet Client"; - } -} diff --git a/src/main/java/helma/servlet/EmbeddedServletClient.java b/src/main/java/helma/servlet/EmbeddedServletClient.java deleted file mode 100644 index 9f9a37cc..00000000 --- a/src/main/java/helma/servlet/EmbeddedServletClient.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.servlet; - -import helma.framework.*; -import helma.framework.core.Application; -import helma.main.*; -import jakarta.servlet.*; - -/** - * Servlet client that runs a Helma application for the embedded - * web server - */ -public final class EmbeddedServletClient extends AbstractServletClient { - private static final long serialVersionUID = -1716809853688477356L; - - private Application app = null; - private String appName; - - /** - * Creates a new EmbeddedServletClient object. - */ - public EmbeddedServletClient() { - super(); - } - - /** - * - * - * @param init ... - * - * @throws ServletException ... - */ - public void init(ServletConfig init) throws ServletException { - super.init(init); - appName = init.getInitParameter("application"); - - if (appName == null) { - throw new ServletException("Application name not set in init parameters"); - } - } - - /** - * Returns the {@link helma.framework.core.Application Applicaton} - * instance the servlet is talking to. - * - * @return this servlet's application instance - */ - public Application getApplication() { - if (app == null) { - app = Server.getServer().getApplication(appName); - } - - return app; - } -} diff --git a/src/main/java/helma/servlet/StandaloneServletClient.java b/src/main/java/helma/servlet/StandaloneServletClient.java deleted file mode 100644 index bdfeeeae..00000000 --- a/src/main/java/helma/servlet/StandaloneServletClient.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.servlet; - -import helma.framework.repository.Repository; -import helma.framework.core.Application; -import helma.framework.repository.FileRepository; -import helma.main.ServerConfig; -import helma.main.Server; - -import java.io.*; -import jakarta.servlet.*; -import java.util.*; - -/** - * Standalone servlet client that runs a Helma application all by itself - * in embedded mode without relying on a central instance of helma.main.Server - * to start and manage the application. - * - * StandaloneServletClient takes the following init parameters: - *

      - *
    • application - the application name
    • - *
    • appdir - the path of the application home directory
    • - *
    • dbdir - the path of the embedded XML data store
    • - *
    - */ -public final class StandaloneServletClient extends AbstractServletClient { - private static final long serialVersionUID = 6515895361950250466L; - - private Application app = null; - private String appName; - private String appDir; - private String dbDir; - private String hopDir; - private Repository[] repositories; - - /** - * - * - * @param init ... - * - * @throws ServletException ... - */ - public void init(ServletConfig init) throws ServletException { - super.init(init); - - hopDir = init.getInitParameter("hopdir"); - - if (hopDir == null) { - // assume helmaDir to be current directory - hopDir = "."; - } - - appName = init.getInitParameter("application"); - - if ((appName == null) || (appName.trim().length() == 0)) { - throw new ServletException("application parameter not specified"); - } - - appDir = init.getInitParameter("appdir"); - - dbDir = init.getInitParameter("dbdir"); - - if ((dbDir == null) || (dbDir.trim().length() == 0)) { - throw new ServletException("dbdir parameter not specified"); - } - - Class[] parameters = { String.class }; - ArrayList repositoryList = new ArrayList(); - - for (int i = 0; true; i++) { - String repositoryArgs = init.getInitParameter("repository." + i); - if (repositoryArgs != null) { - // lookup repository implementation - String repositoryImpl = init.getInitParameter("repository." + i + - ".implementation"); - if (repositoryImpl == null) { - // implementation not set manually, have to guess it - if (repositoryArgs.endsWith(".zip")) { - repositoryImpl = "helma.framework.repository.ZipRepository"; - } else if (repositoryArgs.endsWith(".js")) { - repositoryImpl = "helma.framework.repository.SingleFileRepository"; - } else { - repositoryImpl = "helma.framework.repository.FileRepository"; - } - } - - try { - Repository newRepository = (Repository) Class.forName(repositoryImpl) - .getConstructor(parameters) - .newInstance(new Object[] {repositoryArgs}); - repositoryList.add(newRepository); - log("adding repository: " + repositoryArgs); - } catch (Exception ex) { - log("Adding repository " + repositoryArgs + " failed. " + - "Will not use that repository. Check your initArgs!", ex); - } - } else { - // we always scan repositories 0-9, beyond that only if defined - if (i > 9) { - break; - } - } - } - - // add app dir - FileRepository appRep = new FileRepository(appDir); - log("adding repository: " + appDir); - if (!repositoryList.contains(appRep)) { - repositoryList.add(appRep); - } - - repositories = new Repository[repositoryList.size()]; - repositories = (Repository[]) repositoryList.toArray(repositories); - - } - - /** - * Returns the {@link helma.framework.core.Application Applicaton} - * instance the servlet is talking to. - * - * @return this servlet's application instance - */ - public Application getApplication() { - if (app == null) { - createApp(); - } - - return app; - } - - /** - * Create the application. Since we are synchronized only here, we - * do another check if the app already exists and immediately return if it does. - */ - protected synchronized void createApp() { - - if (app != null) { - return; - } - - try { - File dbHome = new File(dbDir); - File appHome = new File(appDir); - File hopHome = new File(hopDir); - - ServerConfig config = new ServerConfig(); - config.setHomeDir(hopHome); - Server server = new Server(config); - server.init(); - - app = new Application(appName, server, repositories, appHome, dbHome); - app.init(); - app.start(); - } catch (Exception x) { - log("Error starting Application " + appName + ": " + x); - x.printStackTrace(); - } - } - - /** - * The servlet is being destroyed. Close and release the application if - * it does exist. - */ - public void destroy() { - if (app != null) { - try { - app.stop(); - } catch (Exception x) { - log("Error shutting down app " + app.getName() + ": "); - x.printStackTrace(); - } - } - - app = null; - } -} diff --git a/src/main/java/helma/util/CacheMap.java b/src/main/java/helma/util/CacheMap.java deleted file mode 100644 index ebdb6c12..00000000 --- a/src/main/java/helma/util/CacheMap.java +++ /dev/null @@ -1,342 +0,0 @@ -// LruHashtable - a Hashtable that expires least-recently-used objects -// -// Copyright (C) 1996 by Jef Poskanzer . All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -// SUCH DAMAGE. -// -// Visit the ACME Labs Java page for up-to-date versions of this and other -// fine Java utilities: http://www.acme.com/java/ - -// Moved to helma.util to use java.util.HashMap instead of java.util.Hashtable -package helma.util; - -import java.util.Map; -import java.util.HashMap; -import java.util.Properties; - -import helma.framework.core.Application; -import helma.objectmodel.ObjectCache; - - -/// A Hashtable that expires least-recently-used objects. -//

    -// Use just like java.util.Hashtable, except that the initial-capacity -// parameter is required. Instead of growing bigger than that size, -// it will throw out objects that haven't been looked at in a while. -//

    -// Fetch the software.
    -// Fetch the entire Acme package. -//

    -// @see java.util.Hashtable - -public class CacheMap implements ObjectCache { - - // Load factor. - private float loadFactor; - - // When count exceeds this threshold, expires the old table. - private int threshold; - - // Capacity of each bucket. - private int eachCapacity; - - // The tables. - private Map oldTable; - private Map newTable; - - // the application to output messages to - private Application app = null; - - /** - * Zero argument constructor. Creates a CacheMap with capacity of 1000 - * and load factor 0.75 - */ - public CacheMap() { - this(1000, 0.75f); - } - - /// Constructs a new, empty hashtable with the specified initial - // capacity and the specified load factor. - // Unlike a plain Hashtable, an LruHashtable will never grow or - // shrink from this initial capacity. - // @param initialCapacity the initial number of buckets - // @param loadFactor a number between 0.0 and 1.0, it defines - // the threshold for expiring old entries - // @exception IllegalArgumentException If the initial capacity - // is less than or equal to zero. - // @exception IllegalArgumentException If the load factor is - // less than or equal to zero. - public CacheMap(int initialCapacity, float loadFactor) { - // We have to call a superclass constructor, but we're not actually - // going to use it at all. The only reason we want to extend Hashtable - // is for type conformance. So, make a parent hash table of minimum - // size and then ignore it. - if (initialCapacity <= 0 || loadFactor <= 0.0) - throw new IllegalArgumentException(); - this.loadFactor = loadFactor; - // table rotation threshold: we allow each table to gain - // initialCapacity/2 entries. - threshold = initialCapacity / 2; - // We deliberately choose the initial capacity of tables large - // enough that it can hold threshold entries without being rehashed, - // in other words, make sure our threshold for table rotation is lower - // than that of the underlying HashMap for table rehashing. - eachCapacity = (int) (threshold / loadFactor) + 2; - // create tables - we'll never insert into the initial oldTable, - // it's a dummy that will be lost on the first cache rotation. - oldTable = new HashMap(); - newTable = createTable(eachCapacity, loadFactor); - } - - /// Constructs a new, empty hashtable with the specified initial - // capacity. - // Unlike a plain Hashtable, an LruHashtable will never grow or - // shrink from this initial capacity. - // @param initialCapacity the initial number of buckets - public CacheMap(int initialCapacity) { - this(initialCapacity, 0.75F); - } - - /// Returns the number of elements contained in the hashtable. - public int size() { - return newTable.size() + oldTable.size(); - } - - /// Returns true if the hashtable contains no elements. - public boolean isEmpty() { - return size() == 0; - } - - - /// Set the capacity of the CacheMap - public void setCapacity(int capacity) { - // table rotation threshold: we allow each table to gain - // initialCapacity/2 entries. - int newThreshold = capacity / 2; - if (newThreshold != threshold) { - if (app != null) - app.logEvent("Setting cache capacity to " + capacity); - updateThreshold(newThreshold); - } - } - - private synchronized void updateThreshold(int newThreshold) { - threshold = newThreshold; - eachCapacity = (int) (threshold / loadFactor) + 2; - // if newtable is larger than threshold, rotate. - if (newTable.size() > threshold) { - oldTable = newTable; - newTable = createTable(eachCapacity, loadFactor); - } - } - - /// Returns true if the specified object is an element of the hashtable. - // This operation is more expensive than the containsKey() method. - // @param value the value that we are looking for - // @exception NullPointerException If the value being searched - // for is equal to null. - // @see LruHashtable#containsKey - public synchronized boolean containsValue(Object value) { - if (newTable.containsValue(value)) - return true; - if (oldTable.containsValue(value)) { - // We would like to move the object from the old table to the - // new table. However, we need keys to re-add the objects, and - // there's no good way to find all the keys for the given object. - // We'd have to enumerate through all the keys and check each - // one. Yuck. For now we just punt. Anyway, contains() is - // probably not a commonly-used operation. - return true; - } - return false; - } - - /// Returns true if the collection contains an element for the key. - // @param key the key that we are looking for - // @see LruHashtable#contains - public synchronized boolean containsKey(Object key) { - if (newTable.containsKey(key)) - return true; - if (oldTable.containsKey(key)) { - // Move object from old table to new table. - Object value = oldTable.get(key); - newTable.put(key, value); - oldTable.remove(key); - return true; - } - return false; - } - - /// Returns the number of keys in object array keys that - // were not found in the Map. - // Those keys that are contained in the Map are nulled out in the array. - // @param keys an array of key objects we are looking for - // @see LruHashtable#contains - public synchronized int containsKeys(Object[] keys) { - int notfound = 0; - for (int i = 0; i < keys.length; i++) { - if (newTable.containsKey(keys[i])) - keys[i] = null; - else if (oldTable.containsKey(keys[i])) { - // Move object from old table to new table. - Object value = oldTable.get(keys[i]); - newTable.put(keys[i], value); - oldTable.remove(keys[i]); - keys[i] = null; - } else - notfound++; - } - return notfound; - } - - /// Gets the object associated with the specified key in the - // hashtable. - // @param key the specified key - // @returns the element for the key or null if the key - // is not defined in the hash table. - // @see LruHashtable#put - public synchronized Object get(Object key) { - Object value; - value = newTable.get(key); - if (value != null) - return value; - value = oldTable.get(key); - if (value != null) { - // Move object from old table to new table. - newTable.put(key, value); - oldTable.remove(key); - return value; - } - return null; - } - - /// Puts the specified element into the hashtable, using the specified - // key. The element may be retrieved by doing a get() with the same key. - // The key and the element cannot be null. - // @param key the specified key in the hashtable - // @param value the specified element - // @exception NullPointerException If the value of the element - // is equal to null. - // @see LruHashtable#get - // @return the old value of the key, or null if it did not have one. - public synchronized Object put(Object key, Object value) { - - Object oldValue = newTable.put(key, value); - if (oldValue != null) - return oldValue; - oldValue = oldTable.get(key); - if (oldValue != null) - oldTable.remove(key); - // we put a key into newtable that wasn't there before. check if it - // grew beyond the threshold - if (newTable.size() >= threshold) { - // Rotate the tables. - if (app != null) - app.logEvent("Rotating Cache tables at " + newTable.size() + - "/" + oldTable.size() + " (new/old)"); - oldTable = newTable; - newTable = createTable(eachCapacity, loadFactor); - } - return oldValue; - } - - /// Removes the element corresponding to the key. Does nothing if the - // key is not present. - // @param key the key that needs to be removed - // @return the value of key, or null if the key was not found. - public synchronized Object remove(Object key) { - Object oldValue = newTable.remove(key); - if (oldValue == null) - oldValue = oldTable.remove(key); - return oldValue; - } - - /// Clears the hash table so that it has no more elements in it. - public synchronized boolean clear() { - newTable.clear(); - oldTable.clear(); - return true; - } - - /// Called when the application using this cache is stopped. We - // simply clear out our cache contents. - public synchronized void shutdown() { - clear(); - } - - /// Set the application to use for debug and profiling output - public void init(Application app) { - this.app = app; - if (app != null) { - updateProperties(app.getProperties()); - } - } - - /// The app properties have been modified, reload settings - public void updateProperties(Properties props) { - try { - int cacheSize = Integer.parseInt(props.getProperty("cachesize", "1000")); - setCapacity(cacheSize); - } catch (Exception x) { - String message = "Invalid cachesize setting: " + props.getProperty("cachesize"); - if (app != null) { - app.logError(message); - } else { - System.err.println(message); - } - } - } - - public synchronized Object[] getCachedObjects() { - Object[] k1 = newTable.keySet().toArray(); - Object[] k2 = oldTable.keySet().toArray(); - Object[] k = new Object[k1.length + k2.length]; - System.arraycopy(k1, 0, k, 0, k1.length); - System.arraycopy(k2, 0, k, k1.length, k2.length); - return k; - } - - public String toString() { - return newTable.toString() + oldTable.toString() + hashCode(); - } - - /** - * Override this method to use custom Map implementations. The - * default implementation returns a java.util.HashMap instance. - * - * @param capacity the initial capacity - * @param loadFactor the load factor - * @return a new Map used for internal caching - */ - protected Map createTable(int capacity, float loadFactor) { - return new HashMap(capacity, loadFactor); - } - - public Map getStatistics() { - Map stats = new HashMap(); - stats.put("size", size()); - stats.put("threshold", threshold); - return stats; - } -} - - diff --git a/src/main/java/helma/util/CopyOnWriteMap.java b/src/main/java/helma/util/CopyOnWriteMap.java deleted file mode 100644 index be6f4d30..00000000 --- a/src/main/java/helma/util/CopyOnWriteMap.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.util.Map; -import java.util.HashMap; -import java.util.Set; -import java.util.Collection; - -/** - * A Map that wraps another map and creates a new copy of the - * wrapped map if we try to modify it. This class is wrapped - * as a native scripted object in JavaScript rather than exposing - * them through Java reflection. - * - * All methods in this class are synchronized in order not - * to miss the switch between original and copied map. - */ -public class CopyOnWriteMap extends WrappedMap { - - boolean modified = false; - - /** - * Constructor - */ - public CopyOnWriteMap(Map map) { - super(map); - } - - public synchronized boolean wasModified() { - return modified; - } - - public synchronized int size() { - return wrapped.size(); - } - - public synchronized boolean isEmpty() { - return wrapped.isEmpty(); - } - - public synchronized boolean containsKey(Object key) { - return wrapped.containsKey(key); - } - - public synchronized boolean containsValue(Object value) { - return wrapped.containsValue(value); - } - - public synchronized Object get(Object key) { - return wrapped.get(key); - } - - // Modification Operations - check for readonly - - public synchronized Object put(Object key, Object value) { - if (!modified) { - wrapped = new HashMap(wrapped); - modified = true; - } - return wrapped.put(key, value); - } - - public synchronized Object remove(Object key) { - if (!modified) { - wrapped = new HashMap(wrapped); - modified = true; - } - return wrapped.remove(key); - } - - public synchronized void putAll(Map t) { - if (!modified) { - wrapped = new HashMap(wrapped); - modified = true; - } - wrapped.putAll(t); - } - - public synchronized void clear() { - if (!modified) { - wrapped = new HashMap(wrapped); - modified = true; - } - wrapped.clear(); - } - - // Views - - public synchronized Set keySet() { - return wrapped.keySet(); - } - - public synchronized Collection values() { - return wrapped.values(); - } - - public synchronized Set entrySet() { - return wrapped.entrySet(); - } - - // Comparison and hashing - - public synchronized boolean equals(Object o) { - return wrapped.equals(o); - } - - public synchronized int hashCode() { - return wrapped.hashCode(); - } - - // toString - - public synchronized String toString() { - return wrapped.toString(); - } - -} diff --git a/src/main/java/helma/util/CronJob.java b/src/main/java/helma/util/CronJob.java deleted file mode 100644 index 4f1de173..00000000 --- a/src/main/java/helma/util/CronJob.java +++ /dev/null @@ -1,747 +0,0 @@ -package helma.util; - -/** - * Modifications by Stefan Pollach, 2002-08, 2003-03 - * First, to compile without protomatter-library (we're only interested in the - * parsing functions for helma), second to encapsulate a function call and not - * a PASEvent - */ - -/** - * The Protomatter Software License, Version 1.0 - * derived from The Apache Software License, Version 1.1 - * - * Copyright (c) 1998-2002 Nate Sammons. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed for the - * Protomatter Software Project - * (http://protomatter.sourceforge.net/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Protomatter" and "Protomatter Software Project" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact support@protomatter.com. - * - * 5. Products derived from this software may not be called "Protomatter", - * nor may "Protomatter" appear in their name, without prior written - * permission of the Protomatter Software Project - * (support@protomatter.com). - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE PROTOMATTER SOFTWARE PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -import java.util.*; - - -/** - * A cron entry, derived from Protomatter's CronEntry class. - * This class encapsulates a function call, a timeout value - * and a specification for when the given event should be - * delivered to the given topics. The specification of when - * the event should be delivered is based on the UNIX cron - * facility. - */ - - -public class CronJob { - - private static HashSet all = new HashSet (2); - private static String ALL_VALUE = "*"; - static { - all.add (ALL_VALUE); - } - - private HashSet year; - private HashSet month; - private HashSet day; - private HashSet weekday; - private HashSet hour; - private HashSet minute; - - private String name = null; - private String function = null; - private long timeout = 600000; - - /** A method for parsing properties. It looks through the properties - * file for entries that look like this: - * - *

    -     *  cron.name1.function = functionname
    -     *
    -     *  cron.name1.year     = year-list
    -     *  cron.name1.month    = month-list
    -     *  cron.name1.day      = day-list
    -     *  cron.name1.weekday  = weekday-list
    -     *  cron.name1.hour     = hour-list
    -     *  cron.name1.minute   = minute-list
    -     *
    -     *  cron.name1.timeout  = timeout-value
    -     *
    -     *  

    - * - * And delivers corresponding CronJob objects in a collection. - * The specified lists from above are:

    - * - *

      - *
      year-list
      - **
      - ** This is a comma (,) separated list of individual - * years or of year ranges. Examples: "1999,2000" or - * "1999-2004,2005-2143,2650" - *

      - * - *

      month-list
      - *
      - * This is a comma (,) separated list of month - * names. Example: "january,march,may" - *

      - * - *

      day-list
      - *
      - * This is a comma (,) separated list of individual - * day-of-month numbers or of day-of-month ranges. - * Examples: "1,15" or "1-5,7,10-24" - *

      - * - *

      weekday-list
      - *
      - * This is a comma (,) separated list of weekday names - * names. Example: "monday,tuesday" - *

      - * - *

      hour-list
      - *
      - * This is a comma (,) separated list of individual - * hours-of-day (24-hour time) or of hour-of-day ranges. - * Examples: "12,15" or "8-17,19,20-22" - *

      - * - *

      minute-list
      - *
      - * This is a comma (,) separated list of individual - * minutes (during an hour) or of minute ranges. - * Examples: "0,15,30,45" or "0-5,8-14,23,28-32" - *

      - * - *

    - * - * The value of each of those lists can also be an asterisk (*), - * which tells the cron system to disregard the given list when - * determining if a cron entry applies to a specific time -- for instance - * setting the year-list to * would cause the system to - * not take the current year into consideration. If a given list is - * not specified at all, it's the same as specifying it and giving it - * a value of *.

    - */ - - - public static CronJob newJob (String functionName, String year, String month, - String day, String weekday, String hour, String minute) { - CronJob job = new CronJob (functionName); - job.setFunction (functionName); - if (year != null) - job.parseYear (year); - if (month != null) - job.parseMonth (month); - if (day != null) - job.parseDay (day); - if (weekday != null) - job.parseWeekDay (weekday); - if (hour != null) - job.parseHour (hour); - if (minute != null) - job.parseMinute (minute); - return job; - } - - - public static List parse(Properties props) { - Hashtable jobs = new Hashtable (); - Enumeration e = props.keys (); - while (e.hasMoreElements ()) { - String key = (String) e.nextElement (); - try { - StringTokenizer st = new StringTokenizer (key.trim(), "."); - String jobName = st.nextToken (); - if (jobName == null || jobName.equals("")) - continue; - String jobSpec = st.nextToken (); - if (jobSpec==null || jobSpec.equals("")) // might happen with cron.testname. = XXX - continue; - CronJob job = (CronJob) jobs.get (jobName); - if (job==null) { - job = new CronJob (jobName); - jobs.put (jobName, job); - } - String value = props.getProperty (key); - if (jobSpec.equalsIgnoreCase("function")) { - job.setFunction(value); - } else if (jobSpec.equalsIgnoreCase("year")) { - job.parseYear (value); - } else if (jobSpec.equalsIgnoreCase("month")) { - job.parseMonth (value); - } else if (jobSpec.equalsIgnoreCase("day")) { - job.parseDay (value); - } else if (jobSpec.equalsIgnoreCase("weekday")) { - job.parseWeekDay (value); - } else if (jobSpec.equalsIgnoreCase("hour")) { - job.parseHour (value); - } else if (jobSpec.equalsIgnoreCase("minute")) { - job.parseMinute (value); - } else if (jobSpec.equalsIgnoreCase("timeout")) { - job.parseTimeout (value); - } - } catch (NoSuchElementException nsee) { - } - } - Iterator it = jobs.values().iterator(); - while (it.hasNext()) { - CronJob job = (CronJob) it.next(); - if (job.getFunction() == null) { - it.remove(); - } - } - List jobVec = new ArrayList (jobs.values()); - return sort (jobVec); - } - - public static List sort (List list) { - Collections.sort (list, new Comparator() { - public int compare (Object o1, Object o2) { - CronJob cron1 = (CronJob) o1; - CronJob cron2 = (CronJob) o2; - if (cron1.getTimeout () > cron2.getTimeout ()) - return 1; - else if (cron1.getTimeout () < cron2.getTimeout ()) - return -1; - else - return 0; - } - public boolean equals (Object o1, Object o2) { - if (o1!=null) { - return o1.equals (o2); - } else { - return false; - } - } - - }); - return list; - } - - - public void parseYear (String value) { - if (value.equals("*")) { - setAllYears(true); - } else { - StringTokenizer st = new StringTokenizer(value.trim(), ", \t\r\n"); - while (st.hasMoreTokens()) { - String s = st.nextToken(); - if (s.indexOf("-") != -1) { - int start = Integer.parseInt(s.substring(0, s.indexOf("-"))); - int finish = Integer.parseInt(s.substring(s.indexOf("-") +1)); - for (int i=start; i<=finish; i++) { - addYear(i); - } - } else { - int y = Integer.parseInt(s); - addYear(y); - } - } - } - } - - public void parseMonth (String value) { - if (value.equals("*")) { - setAllMonths(true); - } else { - StringTokenizer st = new StringTokenizer(value.trim(), ", \t\r\n"); - while (st.hasMoreTokens()) { - String m = st.nextToken(); - if (m.equalsIgnoreCase("january")) - addMonth(Calendar.JANUARY); - if (m.equalsIgnoreCase("february")) - addMonth(Calendar.FEBRUARY); - if (m.equalsIgnoreCase("march")) - addMonth(Calendar.MARCH); - if (m.equalsIgnoreCase("april")) - addMonth(Calendar.APRIL); - if (m.equalsIgnoreCase("may")) - addMonth(Calendar.MAY); - if (m.equalsIgnoreCase("june")) - addMonth(Calendar.JUNE); - if (m.equalsIgnoreCase("july")) - addMonth(Calendar.JULY); - if (m.equalsIgnoreCase("august")) - addMonth(Calendar.AUGUST); - if (m.equalsIgnoreCase("september")) - addMonth(Calendar.SEPTEMBER); - if (m.equalsIgnoreCase("october")) - addMonth(Calendar.OCTOBER); - if (m.equalsIgnoreCase("november")) - addMonth(Calendar.NOVEMBER); - if (m.equalsIgnoreCase("december")) - addMonth(Calendar.DECEMBER); - } - } - } - - public void parseDay (String day) { - if (day.equals("*")) { - setAllDays(true); - } else { - StringTokenizer st = new StringTokenizer(day.trim(), ", \t\r\n"); - while (st.hasMoreTokens()) { - String s = st.nextToken(); - if (s.indexOf("-") != -1) { - int start = Integer.parseInt(s.substring(0, s.indexOf("-"))); - int finish = Integer.parseInt(s.substring(s.indexOf("-") +1)); - for (int i=start; i<=finish; i++) { - addDay(i); - } - } else { - int d = Integer.parseInt(s); - addDay(d); - } - } - } - } - - - public void parseWeekDay (String weekday) { - if (weekday.equals("*")) { - setAllWeekdays(true); - } else { - StringTokenizer st = new StringTokenizer(weekday.trim(), ", \t\r\n"); - while (st.hasMoreTokens()) { - String d = st.nextToken(); - if (d.equalsIgnoreCase("monday")) - addWeekday(Calendar.MONDAY); - if (d.equalsIgnoreCase("tuesday")) - addWeekday(Calendar.TUESDAY); - if (d.equalsIgnoreCase("wednesday")) - addWeekday(Calendar.WEDNESDAY); - if (d.equalsIgnoreCase("thursday")) - addWeekday(Calendar.THURSDAY); - if (d.equalsIgnoreCase("friday")) - addWeekday(Calendar.FRIDAY); - if (d.equalsIgnoreCase("saturday")) - addWeekday(Calendar.SATURDAY); - if (d.equalsIgnoreCase("sunday")) - addWeekday(Calendar.SUNDAY); - } - } - } - - - public void parseHour (String hour) { - if (hour.equals("*")) { - setAllHours(true); - } else { - StringTokenizer st = new StringTokenizer(hour.trim (), ", \t\r\n\""); - while (st.hasMoreTokens()) { - String s = st.nextToken(); - if (s.indexOf("-") != -1) { - int start = Integer.parseInt(s.substring(0, s.indexOf("-"))); - int finish = Integer.parseInt(s.substring(s.indexOf("-") +1)); - for (int i=start; i<=finish; i++) { - addHour(i); - } - } else { - int h = Integer.parseInt(s); - addHour(h); - } - } - } - } - - - public void parseMinute (String minute) { - if (minute.equals("*")) { - setAllMinutes(true); - } else { - StringTokenizer st = new StringTokenizer(minute.trim (), ", \t\r\n"); - while (st.hasMoreTokens()) { - String s = st.nextToken(); - if (s.indexOf("-") != -1) { - int start = Integer.parseInt(s.substring(0, s.indexOf("-"))); - int finish = Integer.parseInt(s.substring(s.indexOf("-") +1)); - for (int i=start; i<=finish; i++) { - addMinute(i); - } - } else { - int m = Integer.parseInt(s); - addMinute(m); - } - } - } - } - - public void parseTimeout (String timeout) { - long timeoutValue = 1000 * Long.valueOf(timeout).longValue (); - setTimeout (timeoutValue); - } - - public static long nextFullMinute () { - long now = System.currentTimeMillis(); - long millisAfterMinute = (now % 60000); - return (now + 60000 - millisAfterMinute); - } - - public static long millisToNextFullMinute () { - long now = System.currentTimeMillis(); - long millisAfterMinute = (now % 60000); - // We return the interval to one second past the next full minute - // to avoid the case where the scheduler wakes up slightly before the minute - // and finishes so fast that the next call to this method returns the - // interval to the same minute instead of the next one. This happened - // sometimes with the old code and caused the scheduler to run twice in - // immediate succession. - return (61000 - millisAfterMinute); - } - - /** - * Create an empty CronJob. - */ - public CronJob (String name) { - this.name = name; - year = new HashSet (all); - month = new HashSet (all); - day = new HashSet (all); - weekday = new HashSet (all); - hour = new HashSet (all); - minute = new HashSet (all); - } - - /** - * Determines if this CronJob applies to the given date. - * Seconds and milliseconds in the date are ignored. - */ - public boolean appliesToDate(Date date) - { - GregorianCalendar cal = new GregorianCalendar(); - cal.setTime(date); - - // try and short-circuit as fast as possible. - Integer theYear = Integer.valueOf(cal.get(Calendar.YEAR)); - if (!year.contains(ALL_VALUE) && !year.contains(theYear)) - return false; - - Integer theMonth = Integer.valueOf(cal.get(Calendar.MONTH)); - if (!month.contains(ALL_VALUE) && !month.contains(theMonth)) - return false; - - Integer theDay = Integer.valueOf(cal.get(Calendar.DAY_OF_MONTH)); - if (!day.contains(ALL_VALUE) && !day.contains(theDay)) - return false; - - Integer theWeekDay = Integer.valueOf(cal.get(Calendar.DAY_OF_WEEK)); - if (!weekday.contains(ALL_VALUE) && !weekday.contains(theWeekDay)) - return false; - - Integer theHour = Integer.valueOf(cal.get(Calendar.HOUR_OF_DAY)); - if (!hour.contains(ALL_VALUE) && !hour.contains(theHour)) - return false; - - Integer theMinute = Integer.valueOf(cal.get(Calendar.MINUTE)); - if (!minute.contains(ALL_VALUE) && !minute.contains(theMinute)) - return false; - - return true; - } - - - /** - * Add a year to the list of years this entry applies to. - */ - public void addYear(int year) - { - this.year.remove(ALL_VALUE); - this.year.add(Integer.valueOf(year)); - } - - /** - * Remove a year from the list of years this entry applies to. - */ - public void removeYear(int year) - { - this.year.remove(Integer.valueOf(year)); - } - - /** - * Should the current year be taken into consideration when - * deciding if this entry is applicable? - * If this is set to false (the default) then the values set with - * the addYear() and removeYear() are taken - * into consideration. If this is set to true then the current - * year is not taken into consideration. - */ - public void setAllYears(boolean set) - { - if (set) - this.year.add(ALL_VALUE); - else - this.year.remove(ALL_VALUE); - } - - - /** - * Add a month to the list of years this entry applies to. - * Month numbers are taken from the constants on the - * java.util.Calendar class. - */ - public void addMonth(int month) - { - this.month.remove(ALL_VALUE); - this.month.add(Integer.valueOf(month)); - } - - /** - * Remove a month from the list of years this entry applies to. - * Month numbers are taken from the constants on the - * java.util.Calendar class. - */ - public void removeMonth(int month) - { - this.month.remove(Integer.valueOf(month)); - } - - /** - * Should the current month be taken into consideration when - * deciding if this entry is applicable? - * If this is set to false (the default) then the values set with - * the addMonth() and removeMonth() are taken - * into consideration. If this is set to true then the current - * month is not taken into consideration. - */ - public void setAllMonths(boolean set) - { - if (set) - this.month.add(ALL_VALUE); - else - this.month.remove(ALL_VALUE); - } - - - /** - * Add a day of the month to the list of years this entry applies to. - */ - public void addDay(int day) - { - this.day.remove(ALL_VALUE); - this.day.add(Integer.valueOf(day)); - } - - /** - * Remove a day of the month from the list of years this entry applies to. - */ - public void removeDay(int day) - { - this.day.remove(Integer.valueOf(day)); - } - - /** - * Should the current day of the month be taken into consideration when - * deciding if this entry is applicable? - * If this is set to false (the default) then the values set with - * the addDay() and removeDay() are taken - * into consideration. If this is set to true then the current - * year is not taken into consideration. - */ - public void setAllDays(boolean set) - { - if (set) - this.day.add(ALL_VALUE); - else - this.day.remove(ALL_VALUE); - } - - - /** - * Add a weekday to the list of years this entry applies to. - * Weekday numbers are taken from the constants on the - * java.util.Calendar class. - */ - public void addWeekday(int weekday) - { - this.weekday.remove(ALL_VALUE); - this.weekday.add(Integer.valueOf(weekday)); - } - - /** - * Remove a weekday from the list of years this entry applies to. - * Weekday numbers are taken from the constants on the - * java.util.Calendar class. - */ - public void removeWeekday(int weekday) - { - this.weekday.remove(Integer.valueOf(weekday)); - } - - /** - * Should the current weekday be taken into consideration when - * deciding if this entry is applicable? - * If this is set to false (the default) then the values set with - * the addWeekday() and removeWeekday() are taken - * into consideration. If this is set to true then the current - * weekday is not taken into consideration. - */ - public void setAllWeekdays(boolean set) - { - if (set) - this.weekday.add(ALL_VALUE); - else - this.weekday.remove(ALL_VALUE); - } - - - /** - * Add an hour to the list of years this entry applies to. - */ - public void addHour(int hour) - { - this.hour.remove(ALL_VALUE); - this.hour.add(Integer.valueOf(hour)); - } - - /** - * Remove an hour from the list of years this entry applies to. - */ - public void removeHour(int hour) - { - this.hour.remove(Integer.valueOf(hour)); - } - - /** - * Should the current hour be taken into consideration when - * deciding if this entry is applicable? - * If this is set to false (the default) then the values set with - * the addHour() and removeHour() are taken - * into consideration. If this is set to true then the current - * hour is not taken into consideration. - */ - public void setAllHours(boolean set) - { - if (set) - this.hour.add(ALL_VALUE); - else - this.hour.remove(ALL_VALUE); - } - - - /** - * Add a minute to the list of years this entry applies to. - */ - public void addMinute(int minute) - { - this.minute.remove(ALL_VALUE); - this.minute.add(Integer.valueOf(minute)); - } - - /** - * Remove a minute from the list of years this entry applies to. - */ - public void removeMinute(int minute) - { - this.minute.remove(Integer.valueOf(minute)); - } - - /** - * Should the current minute be taken into consideration when - * deciding if this entry is applicable? - * If this is set to false (the default) then the values set with - * the addMinute() and removeMinute() are taken - * into consideration. If this is set to true then the current - * minute is not taken into consideration. - */ - public void setAllMinutes(boolean set) - { - if (set) - this.minute.add(ALL_VALUE); - else - this.minute.remove(ALL_VALUE); - } - - /** - * Set this entry's name - */ - public void setName(String name) - { - this.name = name; - } - - /** - * Get this entry's name - */ - public String getName() - { - return this.name; - } - - /** - * Set this entry's function - */ - public void setFunction(String function) - { - this.function = function; - } - - /** - * Get this entry's function - */ - public String getFunction() - { - return this.function; - } - - - /** - * Set this entry's timeout - */ - public void setTimeout(long timeout) - { - this.timeout = timeout; - } - - - /** - * Get this entry's timeout - */ - public long getTimeout() - { - return this.timeout; - } - - public String toString () - { - return "[CronJob " + name + "]"; - } - -} diff --git a/src/main/java/helma/util/Crypt.java b/src/main/java/helma/util/Crypt.java deleted file mode 100644 index f2f7952a..00000000 --- a/src/main/java/helma/util/Crypt.java +++ /dev/null @@ -1,629 +0,0 @@ -/**************************************************************************** - * jcrypt.java - * - * Java-based implementation of the unix crypt command - * - * Based upon C source code written by Eric Young, eay@psych.uq.oz.au - * - ****************************************************************************/ - -package helma.util; - - -public class Crypt { - - private static final int ITERATIONS = 16; - - private static final int con_salt[] = - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x0A, 0x0B, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, - 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, - 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, - 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, - 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, - 0x3D, 0x3E, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, - }; - - private static final boolean shifts2[] = - { - false, false, true, true, true, true, true, true, - false, true, true, true, true, true, true, false - }; - - private static final int skb[][] = - { - { - /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ - 0x00000000, 0x00000010, 0x20000000, 0x20000010, - 0x00010000, 0x00010010, 0x20010000, 0x20010010, - 0x00000800, 0x00000810, 0x20000800, 0x20000810, - 0x00010800, 0x00010810, 0x20010800, 0x20010810, - 0x00000020, 0x00000030, 0x20000020, 0x20000030, - 0x00010020, 0x00010030, 0x20010020, 0x20010030, - 0x00000820, 0x00000830, 0x20000820, 0x20000830, - 0x00010820, 0x00010830, 0x20010820, 0x20010830, - 0x00080000, 0x00080010, 0x20080000, 0x20080010, - 0x00090000, 0x00090010, 0x20090000, 0x20090010, - 0x00080800, 0x00080810, 0x20080800, 0x20080810, - 0x00090800, 0x00090810, 0x20090800, 0x20090810, - 0x00080020, 0x00080030, 0x20080020, 0x20080030, - 0x00090020, 0x00090030, 0x20090020, 0x20090030, - 0x00080820, 0x00080830, 0x20080820, 0x20080830, - 0x00090820, 0x00090830, 0x20090820, 0x20090830, - }, - { - /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */ - 0x00000000, 0x02000000, 0x00002000, 0x02002000, - 0x00200000, 0x02200000, 0x00202000, 0x02202000, - 0x00000004, 0x02000004, 0x00002004, 0x02002004, - 0x00200004, 0x02200004, 0x00202004, 0x02202004, - 0x00000400, 0x02000400, 0x00002400, 0x02002400, - 0x00200400, 0x02200400, 0x00202400, 0x02202400, - 0x00000404, 0x02000404, 0x00002404, 0x02002404, - 0x00200404, 0x02200404, 0x00202404, 0x02202404, - 0x10000000, 0x12000000, 0x10002000, 0x12002000, - 0x10200000, 0x12200000, 0x10202000, 0x12202000, - 0x10000004, 0x12000004, 0x10002004, 0x12002004, - 0x10200004, 0x12200004, 0x10202004, 0x12202004, - 0x10000400, 0x12000400, 0x10002400, 0x12002400, - 0x10200400, 0x12200400, 0x10202400, 0x12202400, - 0x10000404, 0x12000404, 0x10002404, 0x12002404, - 0x10200404, 0x12200404, 0x10202404, 0x12202404, - }, - { - /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */ - 0x00000000, 0x00000001, 0x00040000, 0x00040001, - 0x01000000, 0x01000001, 0x01040000, 0x01040001, - 0x00000002, 0x00000003, 0x00040002, 0x00040003, - 0x01000002, 0x01000003, 0x01040002, 0x01040003, - 0x00000200, 0x00000201, 0x00040200, 0x00040201, - 0x01000200, 0x01000201, 0x01040200, 0x01040201, - 0x00000202, 0x00000203, 0x00040202, 0x00040203, - 0x01000202, 0x01000203, 0x01040202, 0x01040203, - 0x08000000, 0x08000001, 0x08040000, 0x08040001, - 0x09000000, 0x09000001, 0x09040000, 0x09040001, - 0x08000002, 0x08000003, 0x08040002, 0x08040003, - 0x09000002, 0x09000003, 0x09040002, 0x09040003, - 0x08000200, 0x08000201, 0x08040200, 0x08040201, - 0x09000200, 0x09000201, 0x09040200, 0x09040201, - 0x08000202, 0x08000203, 0x08040202, 0x08040203, - 0x09000202, 0x09000203, 0x09040202, 0x09040203, - }, - { - /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */ - 0x00000000, 0x00100000, 0x00000100, 0x00100100, - 0x00000008, 0x00100008, 0x00000108, 0x00100108, - 0x00001000, 0x00101000, 0x00001100, 0x00101100, - 0x00001008, 0x00101008, 0x00001108, 0x00101108, - 0x04000000, 0x04100000, 0x04000100, 0x04100100, - 0x04000008, 0x04100008, 0x04000108, 0x04100108, - 0x04001000, 0x04101000, 0x04001100, 0x04101100, - 0x04001008, 0x04101008, 0x04001108, 0x04101108, - 0x00020000, 0x00120000, 0x00020100, 0x00120100, - 0x00020008, 0x00120008, 0x00020108, 0x00120108, - 0x00021000, 0x00121000, 0x00021100, 0x00121100, - 0x00021008, 0x00121008, 0x00021108, 0x00121108, - 0x04020000, 0x04120000, 0x04020100, 0x04120100, - 0x04020008, 0x04120008, 0x04020108, 0x04120108, - 0x04021000, 0x04121000, 0x04021100, 0x04121100, - 0x04021008, 0x04121008, 0x04021108, 0x04121108, - }, - { - /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ - 0x00000000, 0x10000000, 0x00010000, 0x10010000, - 0x00000004, 0x10000004, 0x00010004, 0x10010004, - 0x20000000, 0x30000000, 0x20010000, 0x30010000, - 0x20000004, 0x30000004, 0x20010004, 0x30010004, - 0x00100000, 0x10100000, 0x00110000, 0x10110000, - 0x00100004, 0x10100004, 0x00110004, 0x10110004, - 0x20100000, 0x30100000, 0x20110000, 0x30110000, - 0x20100004, 0x30100004, 0x20110004, 0x30110004, - 0x00001000, 0x10001000, 0x00011000, 0x10011000, - 0x00001004, 0x10001004, 0x00011004, 0x10011004, - 0x20001000, 0x30001000, 0x20011000, 0x30011000, - 0x20001004, 0x30001004, 0x20011004, 0x30011004, - 0x00101000, 0x10101000, 0x00111000, 0x10111000, - 0x00101004, 0x10101004, 0x00111004, 0x10111004, - 0x20101000, 0x30101000, 0x20111000, 0x30111000, - 0x20101004, 0x30101004, 0x20111004, 0x30111004, - }, - { - /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */ - 0x00000000, 0x08000000, 0x00000008, 0x08000008, - 0x00000400, 0x08000400, 0x00000408, 0x08000408, - 0x00020000, 0x08020000, 0x00020008, 0x08020008, - 0x00020400, 0x08020400, 0x00020408, 0x08020408, - 0x00000001, 0x08000001, 0x00000009, 0x08000009, - 0x00000401, 0x08000401, 0x00000409, 0x08000409, - 0x00020001, 0x08020001, 0x00020009, 0x08020009, - 0x00020401, 0x08020401, 0x00020409, 0x08020409, - 0x02000000, 0x0A000000, 0x02000008, 0x0A000008, - 0x02000400, 0x0A000400, 0x02000408, 0x0A000408, - 0x02020000, 0x0A020000, 0x02020008, 0x0A020008, - 0x02020400, 0x0A020400, 0x02020408, 0x0A020408, - 0x02000001, 0x0A000001, 0x02000009, 0x0A000009, - 0x02000401, 0x0A000401, 0x02000409, 0x0A000409, - 0x02020001, 0x0A020001, 0x02020009, 0x0A020009, - 0x02020401, 0x0A020401, 0x02020409, 0x0A020409, - }, - { - /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */ - 0x00000000, 0x00000100, 0x00080000, 0x00080100, - 0x01000000, 0x01000100, 0x01080000, 0x01080100, - 0x00000010, 0x00000110, 0x00080010, 0x00080110, - 0x01000010, 0x01000110, 0x01080010, 0x01080110, - 0x00200000, 0x00200100, 0x00280000, 0x00280100, - 0x01200000, 0x01200100, 0x01280000, 0x01280100, - 0x00200010, 0x00200110, 0x00280010, 0x00280110, - 0x01200010, 0x01200110, 0x01280010, 0x01280110, - 0x00000200, 0x00000300, 0x00080200, 0x00080300, - 0x01000200, 0x01000300, 0x01080200, 0x01080300, - 0x00000210, 0x00000310, 0x00080210, 0x00080310, - 0x01000210, 0x01000310, 0x01080210, 0x01080310, - 0x00200200, 0x00200300, 0x00280200, 0x00280300, - 0x01200200, 0x01200300, 0x01280200, 0x01280300, - 0x00200210, 0x00200310, 0x00280210, 0x00280310, - 0x01200210, 0x01200310, 0x01280210, 0x01280310, - }, - { - /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */ - 0x00000000, 0x04000000, 0x00040000, 0x04040000, - 0x00000002, 0x04000002, 0x00040002, 0x04040002, - 0x00002000, 0x04002000, 0x00042000, 0x04042000, - 0x00002002, 0x04002002, 0x00042002, 0x04042002, - 0x00000020, 0x04000020, 0x00040020, 0x04040020, - 0x00000022, 0x04000022, 0x00040022, 0x04040022, - 0x00002020, 0x04002020, 0x00042020, 0x04042020, - 0x00002022, 0x04002022, 0x00042022, 0x04042022, - 0x00000800, 0x04000800, 0x00040800, 0x04040800, - 0x00000802, 0x04000802, 0x00040802, 0x04040802, - 0x00002800, 0x04002800, 0x00042800, 0x04042800, - 0x00002802, 0x04002802, 0x00042802, 0x04042802, - 0x00000820, 0x04000820, 0x00040820, 0x04040820, - 0x00000822, 0x04000822, 0x00040822, 0x04040822, - 0x00002820, 0x04002820, 0x00042820, 0x04042820, - 0x00002822, 0x04002822, 0x00042822, 0x04042822, - }, - }; - - private static final int SPtrans[][] = - { - { - /* nibble 0 */ - 0x00820200, 0x00020000, 0x80800000, 0x80820200, - 0x00800000, 0x80020200, 0x80020000, 0x80800000, - 0x80020200, 0x00820200, 0x00820000, 0x80000200, - 0x80800200, 0x00800000, 0x00000000, 0x80020000, - 0x00020000, 0x80000000, 0x00800200, 0x00020200, - 0x80820200, 0x00820000, 0x80000200, 0x00800200, - 0x80000000, 0x00000200, 0x00020200, 0x80820000, - 0x00000200, 0x80800200, 0x80820000, 0x00000000, - 0x00000000, 0x80820200, 0x00800200, 0x80020000, - 0x00820200, 0x00020000, 0x80000200, 0x00800200, - 0x80820000, 0x00000200, 0x00020200, 0x80800000, - 0x80020200, 0x80000000, 0x80800000, 0x00820000, - 0x80820200, 0x00020200, 0x00820000, 0x80800200, - 0x00800000, 0x80000200, 0x80020000, 0x00000000, - 0x00020000, 0x00800000, 0x80800200, 0x00820200, - 0x80000000, 0x80820000, 0x00000200, 0x80020200, - }, - { - /* nibble 1 */ - 0x10042004, 0x00000000, 0x00042000, 0x10040000, - 0x10000004, 0x00002004, 0x10002000, 0x00042000, - 0x00002000, 0x10040004, 0x00000004, 0x10002000, - 0x00040004, 0x10042000, 0x10040000, 0x00000004, - 0x00040000, 0x10002004, 0x10040004, 0x00002000, - 0x00042004, 0x10000000, 0x00000000, 0x00040004, - 0x10002004, 0x00042004, 0x10042000, 0x10000004, - 0x10000000, 0x00040000, 0x00002004, 0x10042004, - 0x00040004, 0x10042000, 0x10002000, 0x00042004, - 0x10042004, 0x00040004, 0x10000004, 0x00000000, - 0x10000000, 0x00002004, 0x00040000, 0x10040004, - 0x00002000, 0x10000000, 0x00042004, 0x10002004, - 0x10042000, 0x00002000, 0x00000000, 0x10000004, - 0x00000004, 0x10042004, 0x00042000, 0x10040000, - 0x10040004, 0x00040000, 0x00002004, 0x10002000, - 0x10002004, 0x00000004, 0x10040000, 0x00042000, - }, - { - /* nibble 2 */ - 0x41000000, 0x01010040, 0x00000040, 0x41000040, - 0x40010000, 0x01000000, 0x41000040, 0x00010040, - 0x01000040, 0x00010000, 0x01010000, 0x40000000, - 0x41010040, 0x40000040, 0x40000000, 0x41010000, - 0x00000000, 0x40010000, 0x01010040, 0x00000040, - 0x40000040, 0x41010040, 0x00010000, 0x41000000, - 0x41010000, 0x01000040, 0x40010040, 0x01010000, - 0x00010040, 0x00000000, 0x01000000, 0x40010040, - 0x01010040, 0x00000040, 0x40000000, 0x00010000, - 0x40000040, 0x40010000, 0x01010000, 0x41000040, - 0x00000000, 0x01010040, 0x00010040, 0x41010000, - 0x40010000, 0x01000000, 0x41010040, 0x40000000, - 0x40010040, 0x41000000, 0x01000000, 0x41010040, - 0x00010000, 0x01000040, 0x41000040, 0x00010040, - 0x01000040, 0x00000000, 0x41010000, 0x40000040, - 0x41000000, 0x40010040, 0x00000040, 0x01010000, - }, - { - /* nibble 3 */ - 0x00100402, 0x04000400, 0x00000002, 0x04100402, - 0x00000000, 0x04100000, 0x04000402, 0x00100002, - 0x04100400, 0x04000002, 0x04000000, 0x00000402, - 0x04000002, 0x00100402, 0x00100000, 0x04000000, - 0x04100002, 0x00100400, 0x00000400, 0x00000002, - 0x00100400, 0x04000402, 0x04100000, 0x00000400, - 0x00000402, 0x00000000, 0x00100002, 0x04100400, - 0x04000400, 0x04100002, 0x04100402, 0x00100000, - 0x04100002, 0x00000402, 0x00100000, 0x04000002, - 0x00100400, 0x04000400, 0x00000002, 0x04100000, - 0x04000402, 0x00000000, 0x00000400, 0x00100002, - 0x00000000, 0x04100002, 0x04100400, 0x00000400, - 0x04000000, 0x04100402, 0x00100402, 0x00100000, - 0x04100402, 0x00000002, 0x04000400, 0x00100402, - 0x00100002, 0x00100400, 0x04100000, 0x04000402, - 0x00000402, 0x04000000, 0x04000002, 0x04100400, - }, - { - /* nibble 4 */ - 0x02000000, 0x00004000, 0x00000100, 0x02004108, - 0x02004008, 0x02000100, 0x00004108, 0x02004000, - 0x00004000, 0x00000008, 0x02000008, 0x00004100, - 0x02000108, 0x02004008, 0x02004100, 0x00000000, - 0x00004100, 0x02000000, 0x00004008, 0x00000108, - 0x02000100, 0x00004108, 0x00000000, 0x02000008, - 0x00000008, 0x02000108, 0x02004108, 0x00004008, - 0x02004000, 0x00000100, 0x00000108, 0x02004100, - 0x02004100, 0x02000108, 0x00004008, 0x02004000, - 0x00004000, 0x00000008, 0x02000008, 0x02000100, - 0x02000000, 0x00004100, 0x02004108, 0x00000000, - 0x00004108, 0x02000000, 0x00000100, 0x00004008, - 0x02000108, 0x00000100, 0x00000000, 0x02004108, - 0x02004008, 0x02004100, 0x00000108, 0x00004000, - 0x00004100, 0x02004008, 0x02000100, 0x00000108, - 0x00000008, 0x00004108, 0x02004000, 0x02000008, - }, - { - /* nibble 5 */ - 0x20000010, 0x00080010, 0x00000000, 0x20080800, - 0x00080010, 0x00000800, 0x20000810, 0x00080000, - 0x00000810, 0x20080810, 0x00080800, 0x20000000, - 0x20000800, 0x20000010, 0x20080000, 0x00080810, - 0x00080000, 0x20000810, 0x20080010, 0x00000000, - 0x00000800, 0x00000010, 0x20080800, 0x20080010, - 0x20080810, 0x20080000, 0x20000000, 0x00000810, - 0x00000010, 0x00080800, 0x00080810, 0x20000800, - 0x00000810, 0x20000000, 0x20000800, 0x00080810, - 0x20080800, 0x00080010, 0x00000000, 0x20000800, - 0x20000000, 0x00000800, 0x20080010, 0x00080000, - 0x00080010, 0x20080810, 0x00080800, 0x00000010, - 0x20080810, 0x00080800, 0x00080000, 0x20000810, - 0x20000010, 0x20080000, 0x00080810, 0x00000000, - 0x00000800, 0x20000010, 0x20000810, 0x20080800, - 0x20080000, 0x00000810, 0x00000010, 0x20080010, - }, - { - /* nibble 6 */ - 0x00001000, 0x00000080, 0x00400080, 0x00400001, - 0x00401081, 0x00001001, 0x00001080, 0x00000000, - 0x00400000, 0x00400081, 0x00000081, 0x00401000, - 0x00000001, 0x00401080, 0x00401000, 0x00000081, - 0x00400081, 0x00001000, 0x00001001, 0x00401081, - 0x00000000, 0x00400080, 0x00400001, 0x00001080, - 0x00401001, 0x00001081, 0x00401080, 0x00000001, - 0x00001081, 0x00401001, 0x00000080, 0x00400000, - 0x00001081, 0x00401000, 0x00401001, 0x00000081, - 0x00001000, 0x00000080, 0x00400000, 0x00401001, - 0x00400081, 0x00001081, 0x00001080, 0x00000000, - 0x00000080, 0x00400001, 0x00000001, 0x00400080, - 0x00000000, 0x00400081, 0x00400080, 0x00001080, - 0x00000081, 0x00001000, 0x00401081, 0x00400000, - 0x00401080, 0x00000001, 0x00001001, 0x00401081, - 0x00400001, 0x00401080, 0x00401000, 0x00001001, - }, - { - /* nibble 7 */ - 0x08200020, 0x08208000, 0x00008020, 0x00000000, - 0x08008000, 0x00200020, 0x08200000, 0x08208020, - 0x00000020, 0x08000000, 0x00208000, 0x00008020, - 0x00208020, 0x08008020, 0x08000020, 0x08200000, - 0x00008000, 0x00208020, 0x00200020, 0x08008000, - 0x08208020, 0x08000020, 0x00000000, 0x00208000, - 0x08000000, 0x00200000, 0x08008020, 0x08200020, - 0x00200000, 0x00008000, 0x08208000, 0x00000020, - 0x00200000, 0x00008000, 0x08000020, 0x08208020, - 0x00008020, 0x08000000, 0x00000000, 0x00208000, - 0x08200020, 0x08008020, 0x08008000, 0x00200020, - 0x08208000, 0x00000020, 0x00200020, 0x08008000, - 0x08208020, 0x00200000, 0x08200000, 0x08000020, - 0x00208000, 0x00008020, 0x08008020, 0x08200000, - 0x00000020, 0x08208000, 0x00208020, 0x00000000, - 0x08000000, 0x08200020, 0x00008000, 0x00208020 - } - }; - - private static final int cov_2char[] = - { - 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, - 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, - 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, - 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, - 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, - 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, - 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, - 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A - }; - - private static final int byteToUnsigned(byte b) - { - int value = (int)b; - - return(value >= 0 ? value : value + 256); - } - - private static int fourBytesToInt(byte b[], int offset) - { - int value; - - value = byteToUnsigned(b[offset++]); - value |= (byteToUnsigned(b[offset++]) << 8); - value |= (byteToUnsigned(b[offset++]) << 16); - value |= (byteToUnsigned(b[offset++]) << 24); - - return(value); - } - - private static final void intToFourBytes(int iValue, byte b[], int offset) - { - b[offset++] = (byte)((iValue) & 0xff); - b[offset++] = (byte)((iValue >>> 8 ) & 0xff); - b[offset++] = (byte)((iValue >>> 16) & 0xff); - b[offset++] = (byte)((iValue >>> 24) & 0xff); - } - - private static final void PERM_OP(int a, int b, int n, int m, int results[]) - { - int t; - - t = ((a >>> n) ^ b) & m; - a ^= t << n; - b ^= t; - - results[0] = a; - results[1] = b; - } - - private static final int HPERM_OP(int a, int n, int m) - { - int t; - - t = ((a << (16 - n)) ^ a) & m; - a = a ^ t ^ (t >>> (16 - n)); - - return(a); - } - - private static int [] des_set_key(byte key[]) - { - int schedule[] = new int[ITERATIONS * 2]; - - int c = fourBytesToInt(key, 0); - int d = fourBytesToInt(key, 4); - - int results[] = new int[2]; - - PERM_OP(d, c, 4, 0x0f0f0f0f, results); - d = results[0]; c = results[1]; - - c = HPERM_OP(c, -2, 0xcccc0000); - d = HPERM_OP(d, -2, 0xcccc0000); - - PERM_OP(d, c, 1, 0x55555555, results); - d = results[0]; c = results[1]; - - PERM_OP(c, d, 8, 0x00ff00ff, results); - c = results[0]; d = results[1]; - - PERM_OP(d, c, 1, 0x55555555, results); - d = results[0]; c = results[1]; - - d = (((d & 0x000000ff) << 16) | (d & 0x0000ff00) | - ((d & 0x00ff0000) >>> 16) | ((c & 0xf0000000) >>> 4)); - c &= 0x0fffffff; - - int s, t; - int j = 0; - - for(int i = 0; i < ITERATIONS; i ++) - { - if(shifts2[i]) - { - c = (c >>> 2) | (c << 26); - d = (d >>> 2) | (d << 26); - } - else - { - c = (c >>> 1) | (c << 27); - d = (d >>> 1) | (d << 27); - } - - c &= 0x0fffffff; - d &= 0x0fffffff; - - s = skb[0][ (c ) & 0x3f ]| - skb[1][((c >>> 6) & 0x03) | ((c >>> 7) & 0x3c)]| - skb[2][((c >>> 13) & 0x0f) | ((c >>> 14) & 0x30)]| - skb[3][((c >>> 20) & 0x01) | ((c >>> 21) & 0x06) | - ((c >>> 22) & 0x38)]; - - t = skb[4][ (d ) & 0x3f ]| - skb[5][((d >>> 7) & 0x03) | ((d >>> 8) & 0x3c)]| - skb[6][ (d >>>15) & 0x3f ]| - skb[7][((d >>>21) & 0x0f) | ((d >>> 22) & 0x30)]; - - schedule[j++] = ((t << 16) | (s & 0x0000ffff)) & 0xffffffff; - s = ((s >>> 16) | (t & 0xffff0000)); - - s = (s << 4) | (s >>> 28); - schedule[j++] = s & 0xffffffff; - } - return(schedule); - } - - private static final int D_ENCRYPT - ( - int L, int R, int S, int E0, int E1, int s[] - ) - { - int t, u, v; - - v = R ^ (R >>> 16); - u = v & E0; - v = v & E1; - u = (u ^ (u << 16)) ^ R ^ s[S]; - t = (v ^ (v << 16)) ^ R ^ s[S + 1]; - t = (t >>> 4) | (t << 28); - - L ^= SPtrans[1][(t ) & 0x3f] | - SPtrans[3][(t >>> 8) & 0x3f] | - SPtrans[5][(t >>> 16) & 0x3f] | - SPtrans[7][(t >>> 24) & 0x3f] | - SPtrans[0][(u ) & 0x3f] | - SPtrans[2][(u >>> 8) & 0x3f] | - SPtrans[4][(u >>> 16) & 0x3f] | - SPtrans[6][(u >>> 24) & 0x3f]; - - return(L); - } - - private static final int [] body(int schedule[], int Eswap0, int Eswap1) - { - int left = 0; - int right = 0; - int t = 0; - - for(int j = 0; j < 25; j ++) - { - for(int i = 0; i < ITERATIONS * 2; i += 4) - { - left = D_ENCRYPT(left, right, i, Eswap0, Eswap1, schedule); - right = D_ENCRYPT(right, left, i + 2, Eswap0, Eswap1, schedule); - } - t = left; - left = right; - right = t; - } - - t = right; - - right = (left >>> 1) | (left << 31); - left = (t >>> 1) | (t << 31); - - left &= 0xffffffff; - right &= 0xffffffff; - - int results[] = new int[2]; - - PERM_OP(right, left, 1, 0x55555555, results); - right = results[0]; left = results[1]; - - PERM_OP(left, right, 8, 0x00ff00ff, results); - left = results[0]; right = results[1]; - - PERM_OP(right, left, 2, 0x33333333, results); - right = results[0]; left = results[1]; - - PERM_OP(left, right, 16, 0x0000ffff, results); - left = results[0]; right = results[1]; - - PERM_OP(right, left, 4, 0x0f0f0f0f, results); - right = results[0]; left = results[1]; - - int out[] = new int[2]; - - out[0] = left; out[1] = right; - - return(out); - } - - public static final String crypt(String salt, String original) - { - while(salt.length() < 2) - salt += "A"; - - StringBuffer buffer = new StringBuffer(" "); - - char charZero = salt.charAt(0); - char charOne = salt.charAt(1); - - buffer.setCharAt(0, charZero); - buffer.setCharAt(1, charOne); - - int Eswap0 = con_salt[(int)charZero]; - int Eswap1 = con_salt[(int)charOne] << 4; - - byte key[] = new byte[8]; - - for(int i = 0; i < key.length; i ++) - key[i] = (byte)0; - - for(int i = 0; i < key.length && i < original.length(); i ++) - { - int iChar = (int)original.charAt(i); - - key[i] = (byte)(iChar << 1); - } - - int schedule[] = des_set_key(key); - int out[] = body(schedule, Eswap0, Eswap1); - - byte b[] = new byte[9]; - - intToFourBytes(out[0], b, 0); - intToFourBytes(out[1], b, 4); - b[8] = 0; - - for(int i = 2, y = 0, u = 0x80; i < 13; i ++) - { - for(int j = 0, c = 0; j < 6; j ++) - { - c <<= 1; - - if(((int)b[y] & u) != 0) - c |= 1; - - u >>>= 1; - - if(u == 0) - { - y++; - u = 0x80; - } - buffer.setCharAt(i, (char)cov_2char[c]); - } - } - return(buffer.toString()); - } - - public static void main(String args[]) - { - if(args.length >= 2) - { - System.out.println - ( - "[" + args[0] + "] [" + args[1] + "] => [" + - Crypt.crypt(args[0], args[1]) + "]" - ); - } - } -} diff --git a/src/main/java/helma/util/CryptResource.java b/src/main/java/helma/util/CryptResource.java deleted file mode 100644 index 7a7d5ab4..00000000 --- a/src/main/java/helma/util/CryptResource.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.io.BufferedReader; -import java.io.StringReader; -import java.util.Properties; -import java.util.StringTokenizer; - -import org.apache.commons.codec.digest.DigestUtils; - -import helma.framework.repository.Resource; -import helma.framework.repository.Resource; - -/** - * This file authenticates against a passwd source - */ -public class CryptResource { - - private Properties users; - private CryptResource parentResource; - private Resource resource; - private long lastRead = 0; - - /** - * Creates a new CryptSource object. - * - * @param resource ... - * @param parentResource ... - */ - public CryptResource(Resource resource, CryptResource parentResource) { - this.resource = resource; - this.parentResource = parentResource; - users = new Properties(); - } - - /** - * - * - * @param username ... - * @param pw ... - * - * @return ... - */ - public boolean authenticate(String username, String pw) { - if (resource.exists() && (resource.lastModified() > lastRead)) { - readFile(); - } else if (!resource.exists() && (users.size() > 0)) { - users.clear(); - } - - String realpw = users.getProperty(username); - - if (realpw != null) { - try { - // check if password matches - // first we try with unix crypt algorithm - String cryptpw = Crypt.crypt(realpw, pw); - - if (realpw.equals(cryptpw)) { - return true; - } - - // then try MD5 - if (realpw.equals(DigestUtils.md5(pw))) { - return true; - } - } catch (Exception x) { - return false; - } - } else { - if (parentResource != null) { - return parentResource.authenticate(username, pw); - } - } - - return false; - } - - private synchronized void readFile() { - BufferedReader reader = null; - - users = new Properties(); - - try { - reader = new BufferedReader(new StringReader(resource.getContent())); - - String line = reader.readLine(); - - while (line != null) { - StringTokenizer st = new StringTokenizer(line, ":"); - - if (st.countTokens() > 1) { - users.put(st.nextToken(), st.nextToken()); - } - - line = reader.readLine(); - } - } catch (Exception ignore) { - } finally { - if (reader != null) { - try { - reader.close(); - } catch (Exception x) { - } - } - - lastRead = System.currentTimeMillis(); - } - } - -} - diff --git a/src/main/java/helma/util/Diff.java b/src/main/java/helma/util/Diff.java deleted file mode 100644 index 4d815fd4..00000000 --- a/src/main/java/helma/util/Diff.java +++ /dev/null @@ -1,659 +0,0 @@ -/* -Copyright (c) 2009, incava.org -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - - * Neither the name of incava.org nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package helma.util; - -import java.util.*; - - -/** - * Compares two lists, returning a list of the additions, changes, and deletions - * between them. A Comparator may be passed as an argument to the - * constructor, and will thus be used. If not provided, the initial value in the - * a ("from") list will be looked at to see if it supports the - * Comparable interface. If so, its equals and - * compareTo methods will be invoked on the instances in the "from" - * and "to" lists; otherwise, for speed, hash codes from the objects will be - * used instead for comparison. - * - *

    The file FileDiff.java shows an example usage of this class, in an - * application similar to the Unix "diff" program.

    - */ -public class Diff -{ - /** - * The source list, AKA the "from" values. - */ - protected List a; - - /** - * The target list, AKA the "to" values. - */ - protected List b; - - /** - * The list of differences, as Difference instances. - */ - protected List diffs = new ArrayList(); - - /** - * The pending, uncommitted difference. - */ - private Difference pending; - - /** - * The comparator used, if any. - */ - private Comparator comparator; - - /** - * The thresholds. - */ - private TreeMap thresh; - - /** - * Constructs the Diff object for the two arrays, using the given comparator. - */ - public Diff(Object[] a, Object[] b, Comparator comp) - { - this(Arrays.asList(a), Arrays.asList(b), comp); - } - - /** - * Constructs the Diff object for the two arrays, using the default - * comparison mechanism between the objects, such as equals and - * compareTo. - */ - public Diff(Object[] a, Object[] b) - { - this(a, b, null); - } - - /** - * Constructs the Diff object for the two lists, using the given comparator. - */ - public Diff(List a, List b, Comparator comp) - { - this.a = a; - this.b = b; - this.comparator = comp; - this.thresh = null; - } - - /** - * Constructs the Diff object for the two lists, using the default - * comparison mechanism between the objects, such as equals and - * compareTo. - */ - public Diff(List a, List b) - { - this(a, b, null); - } - - /** - * Runs diff and returns the results. - */ - public Change diff() - { - traverseSequences(); - - // add the last difference, if pending: - if (pending != null) { - diffs.add(pending); - } - - return Change.fromList(diffs); - } - - /** - * Traverses the sequences, seeking the longest common subsequences, - * invoking the methods finishedA, finishedB, - * onANotB, and onBNotA. - */ - protected void traverseSequences() - { - Integer[] matches = getLongestCommonSubsequences(); - - int lastA = a.size() - 1; - int lastB = b.size() - 1; - int bi = 0; - int ai; - - int lastMatch = matches.length - 1; - - for (ai = 0; ai <= lastMatch; ++ai) { - Integer bLine = matches[ai]; - - if (bLine == null) { - onANotB(ai, bi); - } - else { - while (bi < bLine.intValue()) { - onBNotA(ai, bi++); - } - - onMatch(ai, bi++); - } - } - - boolean calledFinishA = false; - boolean calledFinishB = false; - - while (ai <= lastA || bi <= lastB) { - - // last A? - if (ai == lastA + 1 && bi <= lastB) { - if (!calledFinishA && callFinishedA()) { - finishedA(lastA); - calledFinishA = true; - } - else { - while (bi <= lastB) { - onBNotA(ai, bi++); - } - } - } - - // last B? - if (bi == lastB + 1 && ai <= lastA) { - if (!calledFinishB && callFinishedB()) { - finishedB(lastB); - calledFinishB = true; - } - else { - while (ai <= lastA) { - onANotB(ai++, bi); - } - } - } - - if (ai <= lastA) { - onANotB(ai++, bi); - } - - if (bi <= lastB) { - onBNotA(ai, bi++); - } - } - } - - /** - * Override and return true in order to have finishedA invoked - * at the last element in the a array. - */ - protected boolean callFinishedA() - { - return false; - } - - /** - * Override and return true in order to have finishedB invoked - * at the last element in the b array. - */ - protected boolean callFinishedB() - { - return false; - } - - /** - * Invoked at the last element in a, if - * callFinishedA returns true. - */ - protected void finishedA(int lastA) - { - } - - /** - * Invoked at the last element in b, if - * callFinishedB returns true. - */ - protected void finishedB(int lastB) - { - } - - /** - * Invoked for elements in a and not in b. - */ - protected void onANotB(int ai, int bi) - { - if (pending == null) { - pending = new Difference(ai, ai, bi, -1); - } - else { - pending.setDeleted(ai); - } - } - - /** - * Invoked for elements in b and not in a. - */ - protected void onBNotA(int ai, int bi) - { - if (pending == null) { - pending = new Difference(ai, -1, bi, bi); - } - else { - pending.setAdded(bi); - } - } - - /** - * Invoked for elements matching in a and b. - */ - protected void onMatch(int ai, int bi) - { - if (pending == null) { - // no current pending - } - else { - diffs.add(pending); - pending = null; - } - } - - /** - * Compares the two objects, using the comparator provided with the - * constructor, if any. - */ - protected boolean equals(Object x, Object y) - { - return comparator == null ? x.equals(y) : comparator.compare(x, y) == 0; - } - - /** - * Returns an array of the longest common subsequences. - */ - public Integer[] getLongestCommonSubsequences() - { - int aStart = 0; - int aEnd = a.size() - 1; - - int bStart = 0; - int bEnd = b.size() - 1; - - TreeMap matches = new TreeMap(); - - while (aStart <= aEnd && bStart <= bEnd && equals(a.get(aStart), b.get(bStart))) { - matches.put(Integer.valueOf(aStart++), Integer.valueOf(bStart++)); - } - - while (aStart <= aEnd && bStart <= bEnd && equals(a.get(aEnd), b.get(bEnd))) { - matches.put(Integer.valueOf(aEnd--), Integer.valueOf(bEnd--)); - } - - Map bMatches = null; - if (comparator == null) { - if (a.size() > 0 && a.get(0) instanceof Comparable) { - // this uses the Comparable interface - bMatches = new TreeMap(); - } - else { - // this just uses hashCode() - bMatches = new HashMap(); - } - } - else { - // we don't really want them sorted, but this is the only Map - // implementation (as of JDK 1.4) that takes a comparator. - bMatches = new TreeMap(comparator); - } - - for (int bi = bStart; bi <= bEnd; ++bi) { - Object element = b.get(bi); - Object key = element; - List positions = (List) bMatches.get(key); - - if (positions == null) { - positions = new ArrayList(); - bMatches.put(key, positions); - } - - positions.add(Integer.valueOf(bi)); - } - - thresh = new TreeMap(); - Map links = new HashMap(); - - for (int i = aStart; i <= aEnd; ++i) { - Object aElement = a.get(i); - List positions = (List) bMatches.get(aElement); - - if (positions != null) { - Integer k = Integer.valueOf(0); - ListIterator pit = positions.listIterator(positions.size()); - while (pit.hasPrevious()) { - Integer j = (Integer) pit.previous(); - - k = insert(j, k); - - if (k == null) { - // nothing - } - else { - Object value = k.intValue() > 0 ? links.get(Integer.valueOf(k.intValue() - 1)) : null; - links.put(k, new Object[] { value, Integer.valueOf(i), j }); - } - } - } - } - - if (thresh.size() > 0) { - Integer ti = (Integer) thresh.lastKey(); - Object[] link = (Object[])links.get(ti); - while (link != null) { - Integer x = (Integer)link[1]; - Integer y = (Integer)link[2]; - matches.put(x, y); - link = (Object[])link[0]; - } - } - - int size = matches.size() == 0 ? 0 : 1 + ((Integer) matches.lastKey()).intValue(); - Integer[] ary = new Integer[size]; - for (Iterator it = matches.keySet().iterator(); it.hasNext();) { - Integer idx = (Integer) it.next(); - Integer val = (Integer) matches.get(idx); - ary[idx.intValue()] = val; - } - return ary; - } - - /** - * Returns whether the integer is not zero (including if it is not null). - */ - protected static boolean isNonzero(Integer i) - { - return i != null && i.intValue() != 0; - } - - /** - * Returns whether the value in the map for the given index is greater than - * the given value. - */ - protected boolean isGreaterThan(Integer index, Integer val) - { - Integer lhs = (Integer) thresh.get(index); - return lhs != null && val != null && lhs.compareTo(val) > 0; - } - - /** - * Returns whether the value in the map for the given index is less than - * the given value. - */ - protected boolean isLessThan(Integer index, Integer val) - { - Integer lhs = (Integer) thresh.get(index); - return lhs != null && (val == null || lhs.compareTo(val) < 0); - } - - /** - * Returns the value for the greatest key in the map. - */ - protected Integer getLastValue() - { - return (Integer) thresh.get(thresh.lastKey()); - } - - /** - * Adds the given value to the "end" of the threshold map, that is, with the - * greatest index/key. - */ - protected void append(Integer value) - { - Integer addIdx = null; - if (thresh.size() == 0) { - addIdx = Integer.valueOf(0); - } - else { - Integer lastKey = (Integer) thresh.lastKey(); - addIdx = Integer.valueOf(lastKey.intValue() + 1); - } - thresh.put(addIdx, value); - } - - /** - * Inserts the given values into the threshold map. - */ - protected Integer insert(Integer j, Integer k) - { - if (isNonzero(k) && isGreaterThan(k, j) && isLessThan(Integer.valueOf(k.intValue() - 1), j)) { - thresh.put(k, j); - } - else { - int high = -1; - - if (isNonzero(k)) { - high = k.intValue(); - } - else if (thresh.size() > 0) { - high = ((Integer) thresh.lastKey()).intValue(); - } - - // off the end? - if (high == -1 || j.compareTo(getLastValue()) > 0) { - append(j); - k = Integer.valueOf(high + 1); - } - else { - // binary search for insertion point: - int low = 0; - - while (low <= high) { - int index = (high + low) / 2; - Integer val = (Integer) thresh.get(Integer.valueOf(index)); - int cmp = j.compareTo(val); - - if (cmp == 0) { - return null; - } - else if (cmp > 0) { - low = index + 1; - } - else { - high = index - 1; - } - } - - thresh.put(Integer.valueOf(low), j); - k = Integer.valueOf(low); - } - } - - return k; - } - - /** - * This is the orignal class used for representation of a single change. - * We replace this with our own {@link Change} class for reasons of compatibility - * and easier scripting. - */ - class Difference - { - public static final int NONE = -1; - - /** - * The point at which the deletion starts. - */ - private int delStart = NONE; - - /** - * The point at which the deletion ends. - */ - private int delEnd = NONE; - - /** - * The point at which the addition starts. - */ - private int addStart = NONE; - - /** - * The point at which the addition ends. - */ - private int addEnd = NONE; - - /** - * Creates the difference for the given start and end points for the - * deletion and addition. - */ - public Difference(int delStart, int delEnd, int addStart, int addEnd) - { - this.delStart = delStart; - this.delEnd = delEnd; - this.addStart = addStart; - this.addEnd = addEnd; - } - - /** - * The point at which the deletion starts, if any. A value equal to - * NONE means this is an addition. - */ - public int getDeletedStart() - { - return delStart; - } - - /** - * The point at which the deletion ends, if any. A value equal to - * NONE means this is an addition. - */ - public int getDeletedEnd() - { - return delEnd; - } - - /** - * The point at which the addition starts, if any. A value equal to - * NONE means this must be an addition. - */ - public int getAddedStart() - { - return addStart; - } - - /** - * The point at which the addition ends, if any. A value equal to - * NONE means this must be an addition. - */ - public int getAddedEnd() - { - return addEnd; - } - - /** - * Sets the point as deleted. The start and end points will be modified to - * include the given line. - */ - public void setDeleted(int line) - { - delStart = Math.min(line, delStart); - delEnd = Math.max(line, delEnd); - } - - /** - * Sets the point as added. The start and end points will be modified to - * include the given line. - */ - public void setAdded(int line) - { - addStart = Math.min(line, addStart); - addEnd = Math.max(line, addEnd); - } - - /** - * Compares this object to the other for equality. Both objects must be of - * type Difference, with the same starting and ending points. - */ - public boolean equals(Object obj) - { - if (obj instanceof Difference) { - Difference other = (Difference)obj; - - return (delStart == other.delStart && - delEnd == other.delEnd && - addStart == other.addStart && - addEnd == other.addEnd); - } - else { - return false; - } - } - - /** - * Returns a string representation of this difference. - */ - public String toString() - { - StringBuffer buf = new StringBuffer(); - buf.append("del: [" + delStart + ", " + delEnd + "]"); - buf.append(" "); - buf.append("add: [" + addStart + ", " + addEnd + "]"); - return buf.toString(); - } - - } - - - /** - * A legacy adapter that is compatible to the interface of the old GPL licenced Diff. - */ - public static class Change { - - public final Change link; - public final int line0; - public final int line1; - public final int inserted; - public final int deleted; - - public static Change fromList(List diffs) { - Iterator iter = diffs.iterator(); - return iter.hasNext() ? new Change(iter, 0, 0) : null; - } - - private Change(Iterator iter, int prev0, int prev1) { - Difference diff = (Difference) iter.next(); - if (diff.getDeletedEnd() == Difference.NONE) { - line0 = prev0 + diff.getAddedStart() - prev1; - deleted = 0; - } else { - line0 = diff.getDeletedStart(); - deleted = diff.getDeletedEnd() - line0 + 1; - } - if (diff.getAddedEnd() == Difference.NONE) { - line1 = prev1 + diff.getDeletedStart() - prev0; - inserted = 0; - } else { - line1 = diff.getAddedStart(); - inserted = diff.getAddedEnd() - line1 + 1; - } - this.link = iter.hasNext() ? new Change(iter, line0 + deleted, line1 + inserted) : null; - } - } -} - diff --git a/src/main/java/helma/util/EmptyEnumeration.java b/src/main/java/helma/util/EmptyEnumeration.java deleted file mode 100644 index 36765c1e..00000000 --- a/src/main/java/helma/util/EmptyEnumeration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.util.Enumeration; - -/** - * Utility class for empty enum - */ -public class EmptyEnumeration implements Enumeration { - /** - * - * - * @return ... - */ - public boolean hasMoreElements() { - return false; - } - - /** - * - * - * @return ... - */ - public Object nextElement() { - return null; - } -} diff --git a/src/main/java/helma/util/FileLogger.java b/src/main/java/helma/util/FileLogger.java deleted file mode 100644 index 29090e47..00000000 --- a/src/main/java/helma/util/FileLogger.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import org.apache.commons.logging.Log; - -import java.io.*; -import java.text.*; -import java.util.*; -import java.util.zip.GZIPOutputStream; - -/** - * An extended Logger that writes to a file and rotates files each midnight. - * - * @author Stefan Pollach - * @author Daniel Ruthardt - * @author Hannes Wallnoefer - */ -public class FileLogger extends Logger implements Log { - - // fields used for logging to files - private String name; - private File logdir; - private File logfile; - - // number format for log file rotation - DecimalFormat nformat = new DecimalFormat("000"); - DateFormat aformat = new SimpleDateFormat("yyyy-MM-dd"); - - /** - * Create a file logger. The actual file names do have numbers appended and are - * rotated every x bytes. - * @param directory the directory - * @param name the log file base name - */ - protected FileLogger(String directory, String name) { - this.name = name; - logdir = new File(directory); - // make logdir have an absolute path in case it doesn't already - if (!logdir.isAbsolute()) - logdir = logdir.getAbsoluteFile(); - logfile = new File(logdir, name + ".log"); - - if (!logdir.exists()) { - logdir.mkdirs(); - } - } - - /** - * Open the file and get a writer to it. If the file already exists, this will - * return a writer that appends to an existing file if it is from today, or - * otherwise rotate the old log file and start a new one. - */ - private synchronized void openFile() { - try { - if (logfile.exists() && (logfile.lastModified() < Logging.lastMidnight())) { - // rotate if a log file exists and is NOT from today - File archive = rotateLogFile(); - // gzip rotated log file in a separate thread - if (archive != null) { - new GZipper(archive).start(); - } - } - // create a new log file, appending to an existing file - writer = new PrintWriter(new FileWriter(logfile.getAbsolutePath(), true), - false); - } catch (IOException iox) { - System.err.println("Error creating log " + name + ": " + iox); - } - } - - /** - * Actually closes the file writer of a log. - */ - synchronized void closeFile() { - if (writer != null) { - try { - writer.close(); - } catch (Exception ignore) { - // ignore - } finally { - writer = null; - } - } - } - - /** - * This is called by the runner thread to to make sure we have an open writer. - */ - protected synchronized void ensureOpen() { - // open a new writer if writer is null or the log file has been deleted - if (writer == null || !logfile.exists()) { - openFile(); - } - } - - /** - * Rotate log files, closing the file writer and renaming the old - * log file. Returns the renamed log file for zipping, or null if - * the log file couldn't be rotated. - * - * @return the old renamed log file, or null - * @throws IOException if an i/o error occurred - */ - protected synchronized File rotateLogFile() throws IOException { - // if the logger is not file based do nothing. - if (logfile == null) { - return null; - } - - closeFile(); - - // only backup/rotate if the log file is not empty, - if (logfile.exists() && (logfile.length() > 0)) { - String today = aformat.format(new Date()); - int ct = 0; - - // first append just the date - String archname = name + "-" + today + ".log"; - File archive = new File(logdir, archname); - File zipped = new File(logdir, archname + ".gz"); - - // increase counter until we find an unused log archive name, checking - // both unzipped and zipped file names - while (archive.exists() || zipped.exists()) { - // for the next try we append a counter - String archidx = (ct > 999) ? Integer.toString(ct) : nformat.format(++ct); - - archname = name + "-" + today + "-" + archidx + ".log"; - archive = new File(logdir, archname); - zipped = new File(logdir, archname + ".gz"); - } - - if (logfile.renameTo(archive)) { - return archive; - } else { - System.err.println("Error rotating log file " + canonicalName + - ". Will append to old file."); - } - } - - // no log file rotated - return null; - } - - /** - * Return a string representation of this Logger - */ - public String toString() { - return "FileLogger[" + name + "]"; - } - - /** - * Return an object which identifies this logger. - * @return the logger's name - */ - public String getName() { - return name; - } - - /** - * a Thread class that zips up a file, filename will stay the same. - */ - static class GZipper extends Thread { - List files; - final static int BUFFER_SIZE = 8192; - - public GZipper(List files) { - this.files = files; - setPriority(MIN_PRIORITY); - } - - public GZipper(File file) { - files = new ArrayList(1); - files.add(file); - setPriority(MIN_PRIORITY); - } - - public void run() { - Iterator it = files.iterator(); - File file = null; - - while (it.hasNext()) { - try { - file = (File) it.next(); - File zipped = new File(file.getAbsolutePath() + ".gz"); - GZIPOutputStream zip = new GZIPOutputStream(new FileOutputStream(zipped)); - BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); - byte[] b = new byte[BUFFER_SIZE]; - int len; - - while ((len = in.read(b, 0, BUFFER_SIZE)) != -1) { - zip.write(b, 0, len); - } - - zip.close(); - in.close(); - file.delete(); - } catch (Exception e) { - System.err.println("Error gzipping " + file); - System.err.println(e.toString()); - } - } - } - } - -} diff --git a/src/main/java/helma/util/HtmlEncoder.java b/src/main/java/helma/util/HtmlEncoder.java deleted file mode 100644 index dee0e2a0..00000000 --- a/src/main/java/helma/util/HtmlEncoder.java +++ /dev/null @@ -1,755 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.util.*; - -/** - * This is a utility class to encode special characters and do formatting - * for HTML output. - */ -public final class HtmlEncoder { - // HTML block tags need to suppress automatic newline to
    - // conversion around them to look good. However, they differ - // in how many newlines around them should ignored. These sets - // help to treat each tag right in newline conversion. - static final HashSet internalTags = new HashSet(); - static final HashSet blockTags = new HashSet(); - static final HashSet semiBlockTags = new HashSet(); - - static { - // actual block level elements - semiBlockTags.add("address"); - blockTags.add("article"); - blockTags.add("aside"); - blockTags.add("blockquote"); - blockTags.add("details"); - blockTags.add("dialog"); - blockTags.add("dd"); - semiBlockTags.add("div"); - blockTags.add("dl"); - blockTags.add("dt"); - blockTags.add("fieldset"); - blockTags.add("figcaption"); - blockTags.add("figure"); - blockTags.add("footer"); - blockTags.add("form"); - blockTags.add("h1"); - blockTags.add("h2"); - blockTags.add("h3"); - blockTags.add("h4"); - blockTags.add("h5"); - blockTags.add("h6"); - blockTags.add("header"); - blockTags.add("hgroup"); - blockTags.add("hr"); - blockTags.add("li"); - blockTags.add("main"); - blockTags.add("nav"); - blockTags.add("ol"); - blockTags.add("p"); - blockTags.add("pre"); - blockTags.add("section"); - semiBlockTags.add("table"); - blockTags.add("ul"); - - // additional semi/block elements - blockTags.add("br"); - blockTags.add("center"); - semiBlockTags.add("dir"); - blockTags.add("frameset"); - blockTags.add("isindex"); - blockTags.add("td"); - semiBlockTags.add("th"); - - internalTags.add("menu"); - internalTags.add("noframes"); - internalTags.add("noscript"); - internalTags.add("tbody"); - internalTags.add("tfoot"); - internalTags.add("thead"); - internalTags.add("tr"); - } - - // set of tags that are always empty - static final HashSet emptyTags = new HashSet(); - - static { - // actual empty elements - emptyTags.add("area"); - emptyTags.add("base"); - emptyTags.add("br"); - emptyTags.add("col"); - emptyTags.add("embed"); - emptyTags.add("hr"); - emptyTags.add("img"); - emptyTags.add("input"); - emptyTags.add("keygen"); - emptyTags.add("link"); - emptyTags.add("meta"); - emptyTags.add("param"); - emptyTags.add("source"); - emptyTags.add("track"); - emptyTags.add("wbr"); - - // Obsolete or deprecated - emptyTags.add("basefont"); - emptyTags.add("frame"); - emptyTags.add("isindex"); - } - - static final byte TAG_NAME = 0; - static final byte TAG_SPACE = 1; - static final byte TAG_ATT_NAME = 2; - static final byte TAG_ATT_VAL = 3; - - static final byte TEXT = 0; - static final byte SEMIBLOCK = 1; - static final byte BLOCK = 2; - static final byte INTERNAL = 3; - - static final String newLine = System.getProperty("line.separator"); - - /** - * Do "smart" encodging on a string. This means that valid HTML entities and tags, - * Helma macros and HTML comments are passed through unescaped, while - * other occurrences of {@code <}, {@code >} and {@code &} are encoded to HTML entities. - */ - public final static String encode(String str) { - if (str == null) { - return null; - } - - int l = str.length(); - - if (l == 0) { - return ""; - } - - // try to make stringbuffer large enough from the start - StringBuffer ret = new StringBuffer(Math.round(l * 1.4f)); - - encode(str, ret, false, null); - - return ret.toString(); - } - - /** - * Do "smart" encodging on a string. This means that valid HTML entities and tags, - * Helma macros and HTML comments are passed through unescaped, while - * other occurrences of {@code <}, {@code >} and {@code &} are encoded to HTML entities. - */ - public final static void encode(String str, StringBuffer ret) { - encode(str, ret, false, null); - } - - /** - * Do "smart" encodging on a string. This means that valid HTML entities and tags, - * Helma macros and HTML comments are passed through unescaped, while - * other occurrences of {@code <}, {@code >} and {@code &} are encoded to HTML entities. - * - * @param str the string to encode - * @param ret the string buffer to encode to - * @param paragraphs if true use p tags for paragraphs, otherwise just use br's - * @param allowedTags a set containing the names of allowed tags as strings. All other - * tags will be escaped - */ - public final static void encode(String str, StringBuffer ret, - boolean paragraphs, Set allowedTags) { - if (str == null) { - return; - } - - int l = str.length(); - - // where to insert the

    tag in case we want to create a paragraph later on - int paragraphStart = ret.length(); - - // what kind of element/text are we leaving and entering? - // this is one of TEXT|SEMIBLOCK|BLOCK|INTERNAL - // depending on this information, we decide whether and how to insert - // paragraphs and line breaks. "entering" a tag means we're at the '<' - // and exiting means we're at the '>', not that it's a start or close tag. - byte entering = TEXT; - byte exiting = TEXT; - - Stack openTags = new Stack(); - - // are we currently within a < and a > that consitute some kind of tag? - // we use tag balancing to know whether we are inside a tag (and should - // pass things through unchanged) or outside (and should encode stuff). - boolean insideTag = false; - - // are we inside an HTML tag? - boolean insideHtmlTag = false; - boolean insideCloseTag = false; - byte htmlTagMode = TAG_NAME; - - // if we are inside a tag, we encode everything to make - // documentation work easier - boolean insideCodeTag = false; - boolean insidePreTag = false; - - // are we within a Helma <% macro %> tag? We treat macro tags and - // comments specially, since we can't rely on tag balancing - // to know when we leave a macro tag or comment. - boolean insideMacroTag = false; - - // are we inside an HTML comment? - boolean insideComment = false; - - // the quotation mark we are in within an HTML or Macro tag, if any - char htmlQuoteChar = '\u0000'; - char macroQuoteChar = '\u0000'; - - // number of newlines met since the last non-whitespace character - int linebreaks = 0; - - // did we meet a backslash escape? - boolean escape = false; - - boolean triggerBreak = false; - - for (int i = 0; i < l; i++) { - char c = str.charAt(i); - - // step one: check if this is the beginning of an HTML tag, comment or - // Helma macro. - if (c == '<') { - if (i < (l - 2)) { - if (!insideMacroTag && ('%' == str.charAt(i + 1))) { - // this is the beginning of a Helma macro tag - if (!insideCodeTag) { - insideMacroTag = insideTag = true; - macroQuoteChar = '\u0000'; - } - } else if ('!' == str.charAt(i + 1)) { - // the beginning of an HTML comment or !doctype? - if (!insideCodeTag) { - if (str.regionMatches(i + 2, "--", 0, 2)) { - insideComment = insideTag = true; - } else if (str.regionMatches(true, i+2, "doctype", 0, 7)) { - insideHtmlTag = insideTag = true; - } - } - } else if (!insideTag) { - // check if this is a HTML tag. - insideCloseTag = ('/' == str.charAt(i + 1)); - int tagStart = insideCloseTag ? (i + 2) : (i + 1); - int j = tagStart; - - while ((j < l) && Character.isLetterOrDigit(str.charAt(j))) - j++; - - if ((j > tagStart) && (j < l)) { - String tagName = str.substring(tagStart, j).toLowerCase(); - - if ("code".equals(tagName) && insideCloseTag && - insideCodeTag) { - insideCodeTag = false; - } - - if (((allowedTags == null) || allowedTags.contains(tagName)) && !insideCodeTag) { - insideHtmlTag = insideTag = true; - htmlQuoteChar = '\u0000'; - htmlTagMode = TAG_NAME; - - exiting = entering; - entering = TEXT; - - if (internalTags.contains(tagName)) { - entering = INTERNAL; - } else if (blockTags.contains(tagName)) { - entering = BLOCK; - } else if (semiBlockTags.contains(tagName)) { - entering = paragraphs ? BLOCK : SEMIBLOCK; - } - - if (entering > 0) { - triggerBreak = !insidePreTag; - } - - if (insideCloseTag) { - int t = openTags.search(tagName); - - if (t == -1) { - i = j; - insideHtmlTag = insideTag = false; - - continue; - } else if (t > 1) { - for (int k = 1; k < t; k++) { - Object tag = openTags.pop(); - if (!emptyTags.contains(tag)) { - ret.append(""); - } - } - } - - openTags.pop(); - } else { - openTags.push(tagName); - } - - if ("code".equals(tagName) && !insideCloseTag) { - insideCodeTag = true; - } - - if ("pre".equals(tagName)) { - insidePreTag = !insideCloseTag; - } - } - } - } - } // if (i < l-2) - } - - if ((triggerBreak || linebreaks > 0) && !Character.isWhitespace(c)) { - - if (!insideTag) { - exiting = entering; - entering = TEXT; - if (exiting >= SEMIBLOCK) { - paragraphStart = ret.length(); - } - } - - if (entering != INTERNAL && exiting != INTERNAL) { - int swallowBreaks = 0; - /*if (paragraphs && - (entering != BLOCK || exiting != BLOCK) && - (exiting < BLOCK) && - (linebreaks > 1) && - paragraphStart < ret.length()) { - ret.insert(paragraphStart, "

    "); - ret.append("

    "); - swallowBreaks = 2; - }*/ - - // treat entering a SEMIBLOCK as entering a TEXT - int _entering = entering == SEMIBLOCK ? TEXT : entering; - for (int k = linebreaks-1; k>=0; k--) { - if (k >= swallowBreaks && k >= _entering && k >= exiting) { - ret.append("
    "); - } - ret.append(newLine); - } - if (exiting >= SEMIBLOCK || linebreaks > 1) { - paragraphStart = ret.length(); - } - - } - - linebreaks = 0; - triggerBreak = false; - } - - switch (c) { - case '<': - - if (insideTag) { - ret.append('<'); - } else { - ret.append("<"); - } - - break; - - case '&': - - // check if this is an HTML entity already, - // in which case we pass it though unchanged - if ((i < (l - 3)) && !insideCodeTag) { - // is this a numeric entity? - if (str.charAt(i + 1) == '#') { - int j = i + 2; - - while ((j < l) && Character.isDigit(str.charAt(j))) - j++; - - if ((j < l) && (str.charAt(j) == ';')) { - ret.append("&"); - - break; - } - } else { - int j = i + 1; - - while ((j < l) && Character.isLetterOrDigit(str.charAt(j))) - j++; - - if ((j < l) && (str.charAt(j) == ';')) { - ret.append("&"); - - break; - } - } - } - - // we didn't reach a break, so encode as entity unless inside a tag - if (insideMacroTag) { - ret.append('&'); - } else { - ret.append("&"); - } - break; - - case '\\': - ret.append(c); - - if (insideTag && !insideComment) { - escape = !escape; - } - - break; - - case '"': - case '\'': - ret.append(c); - - if (!insideComment) { - // check if the quote is escaped - if (insideMacroTag) { - if (escape) { - escape = false; - } else if (macroQuoteChar == c) { - macroQuoteChar = '\u0000'; - } else if (macroQuoteChar == '\u0000') { - macroQuoteChar = c; - } - } else if (insideHtmlTag) { - if (escape) { - escape = false; - } else if (htmlQuoteChar == c) { - htmlQuoteChar = '\u0000'; - htmlTagMode = TAG_SPACE; - } else if (htmlQuoteChar == '\u0000') { - htmlQuoteChar = c; - } - } - } - - break; - - case '\n': - if (insideTag || insidePreTag) { - ret.append('\n'); - } else { - linebreaks++; - } - - break; - case '\r': - if (insideTag || insidePreTag) { - ret.append('\r'); - } - break; - - case '>': - - // For Helma macro tags and comments, we overrule tag balancing, - // i.e. we don't require that '<' and '>' be balanced within - // macros and comments. Rather, we check for the matching closing tag. - if (insideComment) { - ret.append('>'); - insideComment = !((str.charAt(i - 2) == '-') && - (str.charAt(i - 1) == '-')); - } else if (insideMacroTag) { - ret.append('>'); - insideMacroTag = !((str.charAt(i - 1) == '%') && - (macroQuoteChar == '\u0000')); - } else if (insideHtmlTag) { - ret.append('>'); - - // only leave HTML tag if quotation marks are balanced - // within that tag. - insideHtmlTag = htmlQuoteChar != '\u0000'; - - // Check if this is an empty tag so we don't generate an - // additional tag. - if (str.charAt(i - 1) == '/') { - // this is to avoid misinterpreting tags like - // as empty - if (!openTags.empty() && htmlTagMode != TAG_ATT_VAL && - htmlTagMode != TAG_ATT_NAME) { - openTags.pop(); - } - } - - exiting = entering; - if (exiting > 0) { - triggerBreak = !insidePreTag; - } - - } else { - ret.append(">"); - } - - // check if we still are inside any kind of tag - insideTag = insideComment || insideMacroTag || insideHtmlTag; - insideCloseTag = insideTag; - - break; - - default: - - if (insideHtmlTag && !insideCloseTag) { - switch(htmlTagMode) { - case TAG_NAME: - if (!Character.isLetterOrDigit(c)) { - htmlTagMode = TAG_SPACE; - } - break; - case TAG_SPACE: - if (Character.isLetterOrDigit(c)) { - htmlTagMode = TAG_ATT_NAME; - } - break; - case TAG_ATT_NAME: - if (c == '=') { - htmlTagMode = TAG_ATT_VAL; - } else if (c == ' ') { - htmlTagMode = TAG_SPACE; - } - break; - case TAG_ATT_VAL: - if (Character.isWhitespace(c) && htmlQuoteChar == '\u0000') { - htmlTagMode = TAG_SPACE; - } - break; - } - } - - ret.append(c); - escape = false; - } - } - - // if tags were opened but not closed, close them. - int o = openTags.size(); - - if (o > 0) { - for (int k = 0; k < o; k++) { - Object tag = openTags.pop(); - if (!emptyTags.contains(tag)) { - ret.append(""); - } - } - } - - // add remaining newlines we may have collected - int swallowBreaks = 0; - /*if (paragraphs && entering < BLOCK) { - ret.insert(paragraphStart, "

    "); - ret.append("

    "); - swallowBreaks = 2; - }*/ - - if (linebreaks > 0) { - for (int i = linebreaks-1; i>=0; i--) { - if (i >= swallowBreaks && i > exiting) { - ret.append("
    "); - } - ret.append(newLine); - } - } - } - - /** - * - */ - public final static String encodeFormValue(String str) { - if (str == null) { - return null; - } - - int l = str.length(); - - if (l == 0) { - return ""; - } - - StringBuffer ret = new StringBuffer(Math.round(l * 1.2f)); - - encodeAll(str, ret, false); - - return ret.toString(); - } - - /** - * - */ - public final static void encodeFormValue(String str, StringBuffer ret) { - encodeAll(str, ret, false); - } - - /** - * - */ - public final static String encodeAll(String str) { - if (str == null) { - return null; - } - - int l = str.length(); - - if (l == 0) { - return ""; - } - - StringBuffer ret = new StringBuffer(Math.round(l * 1.2f)); - - encodeAll(str, ret, true); - - return ret.toString(); - } - - /** - * - */ - public final static void encodeAll(String str, StringBuffer ret) { - encodeAll(str, ret, true); - } - - /** - * - */ - public final static void encodeAll(String str, StringBuffer ret, boolean encodeNewline) { - if (str == null) { - return; - } - - int l = str.length(); - - for (int i = 0; i < l; i++) { - char c = str.charAt(i); - - switch (c) { - case '<': - ret.append("<"); - break; - - case '>': - ret.append(">"); - break; - - case '&': - ret.append("&"); - break; - - case '"': - ret.append("""); - break; - - case '\n': - if (encodeNewline) { - ret.append("
    "); - } - ret.append('\n'); - break; - - default: - ret.append (c); - } - } - } - - /** - * - * - * @param str ... - * - * @return ... - */ - public final static String encodeXml(String str) { - if (str == null) { - return null; - } - - int l = str.length(); - if (l == 0) { - return ""; - } - - StringBuffer ret = new StringBuffer(Math.round(l * 1.2f)); - encodeXml(str, ret); - return ret.toString(); - } - - /** - * - * - * @param str ... - * @param ret ... - */ - public final static void encodeXml(String str, StringBuffer ret) { - if (str == null) { - return; - } - - int l = str.length(); - - for (int i = 0; i < l; i++) { - char c = str.charAt(i); - - switch (c) { - case '<': - ret.append("<"); - break; - - case '>': - ret.append(">"); - break; - - case '&': - ret.append("&"); - break; - - case '"': - ret.append("""); - break; - - case '\'': - ret.append("'"); - break; - - default: - - if (c < 0x20) { - // sort out invalid XML characters below 0x20 - all but 0x9, 0xA and 0xD. - // The trick is an adaption of java.lang.Character.isSpace(). - if (((((1L << 0x9) | (1L << 0xA) | (1L << 0xD)) >> c) & 1L) != 0) { - ret.append(c); - } - } else { - ret.append(c); - } - } - } - } - - // for testing... - public static void main(String[] args) { - for (int i = 0; i < args.length; i++) - System.err.println(encode(args[i])); - } -} - // end of class diff --git a/src/main/java/helma/util/InetAddressFilter.java b/src/main/java/helma/util/InetAddressFilter.java deleted file mode 100644 index 1bbc2138..00000000 --- a/src/main/java/helma/util/InetAddressFilter.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.io.*; -import java.net.*; -import java.util.*; - -/** - * A class for paranoid servers to filter IP addresses. - */ -public class InetAddressFilter { - private Vector patterns; - - /** - * Creates a new InetAddressFilter object. - */ - public InetAddressFilter() { - patterns = new Vector(); - } - - /** - * Addes an address template to the address filter. - * - * @param address The string representation of the IP address, either version 4 or 6. - * - * @throws IOException if the parameter does not represent a valid IP address - */ - public void addAddress(String address) throws IOException { - boolean v6 = false; - String separator = "."; - int length = 4; - int loop = 4; - - // check if this is a v4 or v6 IP address - if (address.indexOf(":") > -1) { - v6 = true; - separator = ":."; - length = 16; - loop = 8; - } - - int[] pattern = new int[length]; - - StringTokenizer st = new StringTokenizer(address, separator); - - if (st.countTokens() != loop) { - throw new IOException("\"" + address + - "\" does not represent a valid IP address"); - } - - for (int i = 0; i < loop; i++) { - String next = st.nextToken(); - - if (v6) { - if ("*".equals(next)) { - pattern[i*2] = pattern[i*2+1] = 256; - } else if (next.length() == 0) { - pattern[i*2] = pattern[i*2+1] = 0; - } else { - int n = Integer.parseInt(next, 16); - pattern[i*2] = (byte) ((n & 0xff00) >> 8); - pattern[i*2+1] = (byte) (n & 0xff); - } - } else { - if ("*".equals(next)) { - pattern[i] = 256; - } else { - pattern[i] = (byte) Integer.parseInt(next); - } - } - } - patterns.addElement(pattern); - } - - /** - * Check if the given address matches any of our patterns - * - * @param address the ip address to match - * - * @return true if we find a match - */ - public boolean matches(InetAddress address) { - if (address == null) { - return false; - } - - byte[] add = address.getAddress(); - - if (add == null) { - return false; - } - - int l = patterns.size(); - - for (int k = 0; k < l; k++) { - int[] pattern = (int[]) patterns.elementAt(k); - - // is the address different version than pattern? - if (pattern.length != add.length) - continue; - - for (int i = 0; i < add.length; i++) { - if ((pattern[i] < 255) && (pattern[i] != add[i])) { - // not wildcard and doesn't match - break; - } - - if (i == add.length-1) { - return true; - } - } - } - - return false; - } -} diff --git a/src/main/java/helma/util/Logger.java b/src/main/java/helma/util/Logger.java deleted file mode 100644 index 3d02a2ab..00000000 --- a/src/main/java/helma/util/Logger.java +++ /dev/null @@ -1,427 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import org.apache.commons.logging.Log; - -import java.io.*; -import java.text.*; -import java.util.*; - -/** - * A simple logger that writes to a PrintStream such as System.out. - */ -public class Logger implements Log { - - // buffer for log items; create a synchronized list for log entries since - // different threads may attempt to modify the list at the same time - List entries = Collections.synchronizedList(new LinkedList()); - - // Writer for log output - PrintWriter writer; - - // the canonical name for this logger - String canonicalName; - - // fields for date rendering and caching - static DateFormat dformat = new SimpleDateFormat("[yyyy/MM/dd HH:mm:ss] "); - static long dateLastRendered; - static String dateCache; - - public final static int TRACE = 1; - public final static int DEBUG = 2; - public final static int INFO = 3; - public final static int WARN = 4; - public final static int ERROR = 5; - public final static int FATAL = 6; - - int logLevel = INFO; - - // timestamp of last log message, used to close file loggers after longer - // periods of inactivity - long lastMessage = System.currentTimeMillis(); - - // sedated log instance for jetty - private Log sedatedLog = new SedatedLog(); - - /** - * zero argument constructor, only here for FileLogger subclass - */ - Logger() { - init(); - } - - /** - * Create a logger for a PrintStream, such as System.out. - * @param out the output stream - */ - protected Logger(PrintStream out) { - init(); - writer = new PrintWriter(out); - canonicalName = out.toString(); - } - - /** - * Get loglevel from System properties - */ - private void init() { - String level = System.getProperty("helma.loglevel"); - if ("trace".equalsIgnoreCase(level)) - logLevel = TRACE; - else if ("debug".equalsIgnoreCase(level)) - logLevel = DEBUG; - else if ("info".equalsIgnoreCase(level)) - logLevel = INFO; - else if ("warn".equalsIgnoreCase(level)) - logLevel = WARN; - else if ("error".equalsIgnoreCase(level)) - logLevel = ERROR; - else if ("fatal".equalsIgnoreCase(level)) - logLevel = FATAL; - } - - /** - * Get the current log level. - * @return the current log level - */ - public int getLogLevel() { - return logLevel; - } - - /** - * Set the log level for this logger. - * @param logLevel the new log level - */ - public void setLogLevel(int logLevel) { - this.logLevel = logLevel; - } - - /** - * Return a string representation of this Logger - */ - public String toString() { - return new StringBuffer(getClass().getName()).append("[") - .append(canonicalName).append(",").append(logLevel) - .append("]").toString(); - } - - /** - * Return an object which identifies this logger. - * @return the canonical name of this logger - */ - public String getCanonicalName() { - return canonicalName; - } - - /** - * Append a message to the log. - * @param level a string representing the log level - * @param msg the log message - * @param exception an exception, or null - */ - protected void log(String level, Object msg, Throwable exception) { - lastMessage = System.currentTimeMillis(); - // it's enough to render the date every second - if ((lastMessage - 1000) > dateLastRendered) { - renderDate(); - } - // add a safety net so we don't grow indefinitely even if writer thread - // has gone. the 2000 entries threshold is somewhat arbitrary. - if (entries.size() < 2000) { - String message = msg == null ? "null" : msg.toString(); - Thread thread = Thread.currentThread(); - String threadId = "[" + thread.getName() + "] "; - entries.add(new Entry(dateCache, level, message, threadId, exception)); - } - } - - /** - * This is called by the runner thread to perform actual output. - */ - protected synchronized void write() { - if (entries.isEmpty()) { - return; - } - - try { - // make sure we have a valid writer - ensureOpen(); - - String color; - int l = entries.size(); - - for (int i = 0; i < l; i++) { - Entry entry = (Entry) entries.remove(0); - - if (entry.level == "[TRACE] " || entry.level == "[DEBUG] ") { - color = "\u001B[0m"; - } else if (entry.level == "[INFO] ") { - color = "\u001B[0m"; - } else if (entry.level == "[WARN] ") { - color = "\u001B[0;33m"; - } else if (entry.level == "[ERROR] ") { - color = "\u001B[0;31m"; - } else if (entry.level == "[FATAL] ") { - color = "\033[1;31m"; - } else { - color = "\u001B[32m"; - } - - writer.print(color); - writer.print(entry.date); - writer.print(entry.level); - writer.print(entry.threadId); - writer.println(entry.message); - - if (entry.exception != null) - entry.exception.printStackTrace(writer); - - writer.print("\033[0m"); - } - writer.flush(); - - } catch (Exception x) { - int size = entries.size(); - - if (size > 1000) { - // more than 1000 entries queued plus exception - something - // is definitely wrong with this logger. Write a message to std err and - // discard queued log entries. - System.err.println("Error writing log file " + this + ": " + x); - System.err.println("Discarding " + size + " log entries."); - entries.clear(); - } - } - } - - /** - * This is called by the runner thread to to make sure we have an open writer. - */ - protected void ensureOpen() { - // nothing to do for console logger - } - - // Pre-render the date to use for log messages. Called about once a second. - protected static synchronized void renderDate() { - Date date = new Date(); - dateCache = dformat.format(date); - dateLastRendered = date.getTime(); - } - - // methods to implement org.apache.commons.logging.Log interface - - public boolean isTraceEnabled() { - return logLevel <= TRACE; - } - - public boolean isDebugEnabled() { - return logLevel <= DEBUG; - } - - public boolean isInfoEnabled() { - return logLevel <= INFO; - } - - public boolean isWarnEnabled() { - return logLevel <= WARN; - } - - public boolean isErrorEnabled() { - return logLevel <= ERROR; - } - - public boolean isFatalEnabled() { - return logLevel <= FATAL; - } - - public void trace(Object parm1) { - if (logLevel <= TRACE) - log("[TRACE] ", parm1, null); - } - - public void trace(Object parm1, Throwable parm2) { - if (logLevel <= TRACE) - log("[TRACE] ", parm1, parm2); - } - - public void debug(Object parm1) { - if (logLevel <= DEBUG) - log("[DEBUG] ", parm1, null); - } - - public void debug(Object parm1, Throwable parm2) { - if (logLevel <= DEBUG) - log("[DEBUG] ", parm1, parm2); - } - - public void info(Object parm1) { - if (logLevel <= INFO) - log("[INFO] ", parm1, null); - } - - public void info(Object parm1, Throwable parm2) { - if (logLevel <= INFO) - log("[INFO] ", parm1, parm2); - } - - public void warn(Object parm1) { - if (logLevel <= WARN) - log("[WARN] ", parm1, null); - } - - public void warn(Object parm1, Throwable parm2) { - if (logLevel <= WARN) - log("[WARN] ", parm1, parm2); - } - - public void error(Object parm1) { - if (logLevel <= ERROR) - log("[ERROR] ", parm1, null); - } - - public void error(Object parm1, Throwable parm2) { - if (logLevel <= ERROR) - log("[ERROR] ", parm1, parm2); - } - - public void fatal(Object parm1) { - if (logLevel <= FATAL) - log("[FATAL] ", parm1, null); - } - - public void fatal(Object parm1, Throwable parm2) { - if (logLevel <= FATAL) - log("[FATAL] ", parm1, parm2); - } - - // utility method to get the stack trace from a Throwable as string - public static String getStackTrace(Throwable t) { - StringWriter stringWriter = new StringWriter(); - PrintWriter writer = new PrintWriter(stringWriter); - t.printStackTrace(writer); - writer.close(); - return stringWriter.toString(); - } - - class Entry { - final String date, level, message, threadId; - final Throwable exception; - - Entry(String date, String level, String message, String threadId, Throwable exception) { - this.date = date; - this.level = level; - this.message = message; - this.threadId = threadId; - this.exception = exception; - } - } - - /** - * return a "quiet" version of this log that routes debug() output to trace() - * @return a possibly less verbose version of this log. - */ - protected Log getSedatedLog() { - return sedatedLog; - } - - /* - * A inner class that "calms down" logging output by routing debug() output - * to trace(). This is useful for software like Jetty, which has really - * verbose output at DEBUG level (dumps whole HTTP request and response headers). - * You can enable that output by setting the log level to TRACE. - */ - class SedatedLog implements Log { - - public void debug(Object o) { - // Route debug() to trace() - Logger.this.trace(o); - } - - public void debug(Object o, Throwable t) { - // Route debug() to trace() - Logger.this.trace(o, t); - } - - public void error(Object o) { - Logger.this.error(o); - } - - public void error(Object o, Throwable t) { - Logger.this.error(o, t); - } - - public void fatal(Object o) { - Logger.this.fatal(o); - } - - public void fatal(Object o, Throwable t) { - Logger.this.fatal(o, t); - } - - public void info(Object o) { - Logger.this.info(o); - } - - public void info(Object o, Throwable t) { - Logger.this.info(o, t); - } - - public void trace(Object o) { - // swallow trace() - } - - public void trace(Object o, Throwable t) { - // swallow trace() - } - - public void warn(Object o) { - Logger.this.warn(o); - } - - public void warn(Object o, Throwable t) { - Logger.this.warn(o, t); - } - - public boolean isDebugEnabled() { - // Route debug() to trace() - return Logger.this.isTraceEnabled(); - } - - public boolean isErrorEnabled() { - return Logger.this.isErrorEnabled(); - } - - public boolean isFatalEnabled() { - return Logger.this.isFatalEnabled(); - } - - public boolean isInfoEnabled() { - return Logger.this.isInfoEnabled(); - } - - public boolean isTraceEnabled() { - // swallow trace() - return false; - } - - public boolean isWarnEnabled() { - return Logger.this.isWarnEnabled(); - } - - } - -} diff --git a/src/main/java/helma/util/Logging.java b/src/main/java/helma/util/Logging.java deleted file mode 100644 index 4a233f0b..00000000 --- a/src/main/java/helma/util/Logging.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import org.apache.commons.logging.*; -import java.io.*; -import java.util.*; - -/** - * Implementation of Jakarta Commons LogFactory that supports both - * simple console logging and logging to files that are rotated and - * gzipped each night. - * - * @author Stefan Pollach - * @author Daniel Ruthardt - * @author Hannes Wallnoefer - */ -public class Logging extends LogFactory { - - // we use one static thread for all Loggers - static Runner runner; - - // the list of active loggers - static ArrayList loggers = new ArrayList(); - - // hash map of loggers - static HashMap loggerMap = new HashMap(); - - // log directory - String logdir; - - // static console logger - static Logger consoleLog = new Logger(System.out); - - /** - * Constructs a log factory, getting the base logging directory from the - * helma.logdir system property. - */ - public Logging() { - logdir = System.getProperty("helma.logdir", "log"); - } - - /** - * Get a logger for a file name. The log file is created in the - * directory specified by the "log.dir" System property. If the - * logname is "console" a log that writes to System.out is returned. - */ - public Log getInstance(String logname) { - if (logname == null) { - throw new LogConfigurationException("No logname specified!"); - } - // normalize log name - logname = logname.replaceAll("[^\\w\\d\\.]", ""); - if ("console".equals(logdir)) { - if (logname.startsWith("org.eclipse.jetty.")) - return getConsoleLog().getSedatedLog(); - else - return getConsoleLog(); - } else { - if (logname.startsWith("org.eclipse.jetty.")) - return getFileLog(logname).getSedatedLog(); - else - return getFileLog(logname); - } - } - - /** - * Get a logger to System.out. - * @return a logger that writes to System.out - */ - public static Logger getConsoleLog() { - ensureRunning(); - return consoleLog; - } - - - /** - * Get a file logger, creating it if it doesn't exist yet. - * @param logname the base name for the file logger - * @return a file logger - */ - public synchronized Logger getFileLog(String logname) { - Logger log = (Logger) loggerMap.get(logname); - - if (log == null) { - log = new FileLogger(logdir, logname); - loggerMap.put(logname, log); - loggers.add(log); - } - - ensureRunning(); - return log; - } - - public synchronized Log getInstance (Class clazz) { - return getInstance(clazz.getPackage().getName()); - } - - public void setAttribute(String name, Object value) { - // FIXME: make log dir changeable at runtime - } - - public Object getAttribute(String name) { - if ("logdir".equals(name)) { - return logdir; - } - return null; - } - - public String[] getAttributeNames() { - return new String[] {}; - } - - public void removeAttribute(String parm1) { - // nothing to do - } - - /** - * Flush all logs and shut down. - */ - public void release() { - shutdown(); - } - - /** - * Make sure logger thread is active. - */ - public synchronized static void ensureRunning() { - if ((runner == null) || !runner.isAlive()) { - runner = new Runner(); - runner.setDaemon(true); - runner.start(); - } - } - - /** - * Shut down logging, stopping the logger thread and closing all logs. - */ - public synchronized static void shutdown() { - if (runner != null && runner.isAlive()) { - runner.interrupt(); - } - runner = null; - Thread.yield(); - closeAll(); - } - - /** - * Close all open logs. - */ - static void closeAll() { - - consoleLog.write(); - - int nloggers = loggers.size(); - - for (int i = nloggers - 1; i >= 0; i--) { - FileLogger log = (FileLogger) loggers.get(i); - - log.write(); - log.closeFile(); - } - - loggers.clear(); - loggerMap.clear(); - consoleLog = null; - } - - /** - * Rotate log files on all registered logs - */ - static void rotateLogs() { - int nloggers = loggers.size(); - ArrayList files = new ArrayList(nloggers); - - for (int i = nloggers - 1; i >= 0; i--) { - FileLogger log = (FileLogger) loggers.get(i); - - try { - File file = log.rotateLogFile(); - if (file != null) { - files.add(file); - } - } catch (IOException io) { - System.err.println("Error rotating log " + log.getName() + ": " + - io.toString()); - } - } - - if (!files.isEmpty()) { - new FileLogger.GZipper(files).start(); - } - } - - /** - * Returns the timestamp for the next Midnight - * - * @return next midnight timestamp in milliseconds - */ - static long nextMidnight() { - Calendar cal = Calendar.getInstance(); - - cal.set(Calendar.DATE, 1 + cal.get(Calendar.DATE)); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 1); - - // for testing, rotate the logs every minute: - // cal.set (Calendar.MINUTE, 1 + cal.get(Calendar.MINUTE)); - return cal.getTime().getTime(); - } - - /** - * Returns the timestamp for the last Midnight - * - * @return last midnight timestamp in milliseconds - */ - static long lastMidnight() { - return nextMidnight() - 86400000; - } - - /** - * The static runner class that loops through all loggers. - */ - static class Runner extends Thread { - - public synchronized void run() { - long nextMidnight = nextMidnight(); - - while ((runner == this) && !isInterrupted()) { - - long now = System.currentTimeMillis(); - - if (nextMidnight < now) { - rotateLogs(); - nextMidnight = nextMidnight(); - } - - // write the stdout console log - consoleLog.write(); - - int nloggers = loggers.size(); - - for (int i = nloggers-1; i >= 0; i--) { - try { - FileLogger log = (FileLogger) loggers.get(i); - - // write out the log entries - log.write(); - - // if log hasn't been used in the last 30 minutes, close it - if (now - log.lastMessage > 1800000) { - log.closeFile(); - } - } catch (Exception x) { - System.err.println("Error in Logger main loop: " + x); - } - } - - try { - wait(333); - } catch (InterruptedException ix) { - break; - } - } - } - - } -} - diff --git a/src/main/java/helma/util/Logo.java b/src/main/java/helma/util/Logo.java deleted file mode 100644 index bbddbab8..00000000 --- a/src/main/java/helma/util/Logo.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.io.FileInputStream; - -/** - * class with byte data of helma logo - */ -public class Logo { - public static final byte[] hop = { - 71, 73, 70, 56, 57, 97, -82, 0, 35, 0, -60, 0, 0, - -1, -1, -1, -17, -17, -17, -33, -33, -33, -52, - -52, -52, -67, -67, -67, -84, -84, -84, -103, - -103, -103, -119, -119, -119, 120, 120, 120, 102, - 102, 102, 84, 84, 84, 67, 67, 67, 51, 51, 51, 33, - 33, 33, 18, 18, 18, 0, 0, 0, -2, 1, 2, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 33, -7, 4, 4, 20, 0, -1, 0, - 44, 0, 0, 0, 0, -82, 0, 35, 0, 0, 5, -1, 32, 32, - -114, 100, 105, -98, 104, -86, -82, 108, -21, -66, - 112, 44, -49, 116, 109, -33, 120, -82, -45, -61, - -79, 52, -114, 96, 67, 113, 24, -20, -114, -56, - -92, -78, 21, 32, 32, 22, -63, -121, 116, 74, 109, - 44, -118, -127, -91, 118, -53, 125, 5, 122, 63, 7, - 117, 76, -106, 58, -84, -40, -82, 122, -83, 28, - 24, -62, -27, -72, -4, 113, 78, 20, -78, -20, -68, - -34, 21, 40, 36, 24, 98, 115, -126, -126, 14, 12, - 8, 4, 120, 123, -118, 122, 2, 5, 10, -127, -125, - -111, -111, 117, -120, -117, -106, 92, 5, -128, - -110, -101, -100, -123, 4, -105, -96, 72, 4, 64, - -100, -91, -110, 103, 70, -95, -86, 55, 9, -112, - 83, 12, 11, 12, -111, 86, 11, -90, 100, 14, 9, 47, - 4, 4, 2, 57, 77, -107, 55, -69, -67, 36, -65, - -119, 42, 2, -69, 54, -78, 100, -97, 4, -111, 8, - 34, -74, 100, 12, 47, 82, -48, 36, -50, 15, -97, - -70, 82, -37, 54, -42, 37, -39, -37, -75, 11, 40, - 8, 82, 54, -82, 83, 34, -25, -125, -51, -46, 99, - 14, 46, -30, 37, -19, -58, 44, -19, 56, -12, 36, - -7, -47, 15, -41, 38, -56, -91, -101, 38, 34, -63, - -126, 90, 85, -96, 76, -55, 114, 96, -116, -107, - 6, 15, -84, -72, 114, 112, 80, -99, -68, 19, -55, - 70, 52, 124, 48, -128, -41, 8, 100, -34, 0, 16, - 72, -11, 17, 24, 0, 5, 15, -88, -1, -91, 64, 118, - -49, -60, -58, -114, -61, 78, -90, 28, 33, -116, - -90, 55, 49, 9, 58, -34, 27, 105, -94, 35, 9, 117, - 15, 114, 1, -64, 51, -64, 76, 1, 17, 1, 106, 53, - 40, 40, -91, -41, -80, 0, 6, -112, 66, 124, 112, - -128, 4, -54, 41, 23, 73, 24, 8, -60, 0, 79, 2, - 51, 82, -114, 2, -112, -91, 64, 68, -127, 64, 101, - -121, 34, 116, 96, 100, -86, 20, -110, 34, 32, 78, - 117, -48, -53, 64, 83, 1, 82, -86, 126, -91, 19, - 54, 110, 80, 17, 118, 57, 2, 24, 48, 87, 0, 94, - -66, 116, -122, -99, -107, -110, 86, -82, -108, - 68, 64, -85, 2, 64, -112, 10, -30, 81, 3, -48, - -20, -90, -107, 117, -111, 64, 84, 0, 5, -60, -18, - 69, -96, 96, 65, -81, 108, 102, -62, -47, 41, 0, - 81, -78, -84, 6, 8, -60, -108, 3, 0, -82, -88, 3, - -42, 15, 122, -43, -6, -13, 15, -76, -75, -112, - 67, -91, 44, 24, 61, -103, -114, 111, 109, 99, 35, - -58, 126, 80, 46, 64, 94, 118, -24, 0, -120, 65, - 32, -117, 64, 1, 41, 9, -82, 70, -75, -115, 91, - -128, -13, -120, 7, 127, 50, 19, -39, -101, -10, - 108, -118, -28, -81, 9, 23, 17, 30, 64, 123, -124, - -122, 14, -111, -57, 90, -94, 22, 52, -5, -2, -96, - -111, -99, -1, 9, 127, -83, 93, -113, 61, 17, -43, - 62, -40, 116, -13, 93, 85, 2, -11, 3, -50, -1, - 126, -5, 8, -108, -51, 23, -120, -28, 67, -113, - 127, -38, 16, 56, 2, 80, 34, 52, -12, 73, 81, 81, - 5, 32, -33, 57, 27, -126, 35, -35, 53, 14, -112, - 72, 85, 9, 27, -91, -10, 81, 95, -32, 100, 115, - 20, 56, 27, 5, 112, -104, 2, -7, 124, -91, -46, 8, - -3, -44, -13, 24, 61, -32, -44, 66, -115, -117, - -76, -11, 102, 79, 126, -13, 1, -28, 99, 113, 15, - -56, -56, 88, 62, 67, -106, -96, -114, 74, 95, - 101, 97, 87, 76, 76, -43, -43, 23, 94, 71, 97, 9, - 0, 94, 42, 61, -63, 20, 125, 35, 4, -10, 69, 95, - 27, 9, 80, -44, 3, 71, 125, -75, 84, 96, 83, 44, - 5, -111, 80, 35, -96, 116, -93, 85, 17, 1, 16, - -29, -103, 71, -31, 100, 103, 83, 120, 2, -96, - -90, 8, 103, 118, 24, -56, 103, 122, -94, -76, - -90, 67, 50, 45, 101, -126, 58, 66, 49, -96, 104, - 108, -48, -127, -39, 78, 47, -41, 81, -102, -101, - 111, 85, 57, -41, 40, 21, 89, 21, 39, 79, 96, -67, - -4, 9, 106, 114, 101, -99, -45, -23, -127, 37, - -68, 121, 2, 68, 101, -119, 122, -41, 115, -82, - 94, -70, 31, 0, -127, -91, 18, 24, 93, -121, 85, - -59, -86, -89, -87, 62, -112, -106, -109, 99, 72, - -26, 43, 123, -77, 33, -76, -98, 123, -58, 77, - 118, 17, -92, -59, -67, -93, 30, -89, 36, 36, 88, - 39, -87, -59, 41, -38, 35, -1, 115, 5, 34, 55, 2, - -86, 37, 124, -89, -33, 95, -90, 30, -9, -55, 126, - -25, 88, 91, 94, -114, 72, 90, 103, -32, -75, -77, - 33, 37, 34, -80, 84, 56, 27, -51, 121, -80, -31, - 23, 100, -79, -8, -78, 119, 41, -120, -13, -127, - -87, 47, 52, 16, 61, -5, 109, 46, 19, -10, -122, - -39, 124, 125, 32, 112, 90, 55, 38, -120, -13, 93, - 84, -46, 62, 64, -92, 44, 4, 51, -116, 108, 57, 2, - 32, 16, 85, 55, 18, 50, -116, -33, -63, 22, 94, - 56, 70, -122, -56, -99, 41, 101, 91, 104, -118, - 32, 11, -119, 44, -117, 32, -58, 81, 61, 48, 20, - 15, 9, 13, 13, -111, 82, 22, -39, 40, -16, 21, 93, - 123, 38, -71, 39, 108, 127, 121, 123, -122, 8, - -39, 32, 112, 79, 59, 6, -51, -124, 44, 115, 98, - -4, -56, -40, -50, -67, 108, 36, 108, 111, -50, - -40, 76, -51, -111, 67, -42, 124, 78, 46, 77, -62, - 43, 5, -108, 62, 7, -106, 64, 22, 3, 92, -107, - -106, 93, 89, -90, -84, -27, 97, 12, -100, -106, - -59, 94, 109, 18, -77, -13, -40, 36, 59, -102, 82, - 42, 127, -86, 69, 7, -35, -76, -54, -106, 74, 82, - 77, -107, -128, 18, 90, -61, 108, -107, -46, 110, - 123, -38, -51, 64, 42, 2, -120, -79, 84, -96, 34, - -104, -99, 69, -95, -45, 2, -114, 75, 22, -122, - -94, -32, 22, 60, -100, -113, 49, 103, 12, -86, - -22, -80, -21, 125, 42, 48, 40, -44, -7, -23, 123, - -53, 32, 0, 3, -100, -63, 101, 3, -73, -92, -69, - 112, -64, -26, -88, -37, -30, -119, 12, 3, 28, - -108, -45, 14, -71, 47, -32, 122, -20, 43, 32, 64, - 74, -19, -90, 20, 34, 22, -16, -56, -65, -48, - -120, -23, -60, 15, 66, -111, 1, 45, 37, 47, -3, - 10, -115, 40, 48, 124, -13, 85, 40, 80, 0, -107, - -45, 119, -17, -123, 19, -102, -44, 94, -56, 33, - -47, 123, 111, -2, -9, -44, 69, 81, -54, -8, -37, - -97, -17, -66, 14, 77, 60, -95, 126, 28, 20, -111, - -1, -2, -3, 109, 28, -96, 0, 32, 66, 16, 49, 64, - -7, -8, 11, -96, 0, 7, -56, -122, 16, 0, 0, 59 - }; - - /** - * utitilty function to create byte array from file - */ - public static void main(String[] args) throws Exception { - FileInputStream fis = new FileInputStream(args[0]); - byte[] b = new byte[256]; - int linect = 0; - int ct = 0; - - System.out.print("\n\n\n static byte[] image = {\n "); - - while (ct > -1) { - ct = fis.read(b); - - for (int i = 0; i < ct; i++) { - System.out.print(b[i] + ","); - linect++; - - if (linect > 30) { - linect = 0; - System.out.print("\n "); - } - } - } - - System.out.print(" };\n\n\n"); - } -} diff --git a/src/main/java/helma/util/MarkdownProcessor.java b/src/main/java/helma/util/MarkdownProcessor.java deleted file mode 100644 index e6a1512d..00000000 --- a/src/main/java/helma/util/MarkdownProcessor.java +++ /dev/null @@ -1,1333 +0,0 @@ -package helma.util; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.*; - -public class MarkdownProcessor { - - private HashMap links = new HashMap(); - private int state; - private int i; - private int length; - private char[] chars; - private StringBuilder buffer; - private int lineMarker = 0; - private int paragraphStartMarker = 0; - private boolean listParagraphs = false; - private int codeEndMarker = 0; - private ElementStack stack = new ElementStack(); - private Emphasis[] emph = new Emphasis[2]; - - private String result = null; - - // private Logger log = Logger.getLogger(MarkdownProcessor.class); - private int line; - - private final int - // stage 1 states - NONE = 0, NEWLINE = 1, LINK_ID = 2, LINK_URL = 3, - // stage 2 states - HEADER = 4, PARAGRAPH = 5, LIST = 6, HTML_BLOCK = 7, CODE = 8; - - static final Set blockTags = new HashSet(); - - static { - blockTags.add("p"); - blockTags.add("div"); - blockTags.add("h1"); - blockTags.add("h2"); - blockTags.add("h3"); - blockTags.add("h4"); - blockTags.add("h5"); - blockTags.add("h6"); - blockTags.add("blockquote"); - blockTags.add("pre"); - blockTags.add("table"); - blockTags.add("tr"); // handle as block tag for pragmatical reasons - blockTags.add("dl"); - blockTags.add("ol"); - blockTags.add("ul"); - blockTags.add("script"); - blockTags.add("noscript"); - blockTags.add("form"); - blockTags.add("fieldset"); - blockTags.add("iframe"); - blockTags.add("math"); - } - - public MarkdownProcessor() {} - - public MarkdownProcessor(String text) { - init(text); - } - - public MarkdownProcessor(File file) throws IOException { - length = (int) file.length(); - chars = new char[length + 2]; - FileReader reader = new FileReader(file); - int read = 0; - try { - while (read < length) { - int r = reader.read(chars, read, length - read); - if (r == -1) - break; - read += r; - } - } finally { - reader.close(); - } - length = read; - chars[length] = chars[length + 1] = '\n'; - } - - public synchronized String process(String text) { - init(text); - return process(); - } - - public synchronized String process() { - if (result == null) { - length = chars.length; - firstPass(); - secondPass(); - result = buffer.toString(); - cleanup(); - } - return result; - } - - public synchronized String processLinkText(String text) { - init(text); - return processLinkText(); - } - - private void init(String text) { - length = text.length(); - chars = new char[length + 2]; - text.getChars(0, length, chars, 0); - chars[length] = chars[length + 1] = '\n'; - } - - /** - * Retrieve a link defined in the source text. If the link is not found, we call - * lookupLink(String) to retrieve it from an external source. - * @param linkId the link id - * @return a String array with the url as first element and the link title as second. - */ - protected String[] getLink(String linkId) { - String[] link = (String[]) links.get(linkId); - if (link == null) { - link = lookupLink(linkId); - } - return link; - } - - /** - * Method to override for extended link lookup, e.g. for integration into a wiki - * @param linkId the link id - * @return a String array with the url as first element and the link title as second. - */ - protected String[] lookupLink(String linkId) { - return null; - } - - /** - * Method to override to create custom HTML tags. - * @param tag the html tag to generate - * @param builder the java.lang.StringBuilder to generate the string - */ - protected void openTag(String tag, StringBuilder builder) { - builder.append('<').append(tag).append('>'); - } - - /** - * First pass: extract links definitions and remove them from the source text. - */ - private synchronized void firstPass() { - int state = NEWLINE; - int linestart = 0; - int indentation = 0; - int indentationChars = 0; - String linkId = null; - String[] linkValue = null; - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < length; i++) { - // convert \r\n and \r newlines to \n - if (chars[i] == '\r') { - if (i < length && chars[i + 1] == '\n') { - System.arraycopy(chars, i + 1, chars, i, (length - i) - 1); - length -= 1; - } else { - chars[i] = '\n'; - } - } - } - - for (int i = 0; i < length; i++) { - char c = chars[i]; - - switch (state) { - case NEWLINE: - if (c == '[' && indentation < 4) { - state = LINK_ID; - } else if (isSpace(c)) { - indentationChars += 1; - indentation += (c == '\t') ? 4 : 1; - } else if (c == '\n' && indentationChars > 0) { - System.arraycopy(chars, i, chars, i - indentationChars, length - i); - i -= indentationChars; - length -= indentationChars; - } else { - state = NONE; - } - break; - case LINK_ID: - if (c == ']') { - if (i < length - 1 && chars[i + 1] == ':') { - linkId = buffer.toString(); - linkValue = new String[2]; - state = LINK_URL; - i++; - } else { - state = NONE; - } - buffer.setLength(0); - } else { - buffer.append(c); - } - break; - case LINK_URL: - if (c == '<' && buffer.length() == 0) { - continue; - } else if ((Character.isWhitespace(c) || c == '>') && buffer.length() > 0) { - linkValue[0] = buffer.toString().trim(); - buffer.setLength(0); - int j = i + 1; - int newlines = c == '\n' ? 1 : 0; - while (j < length && Character.isWhitespace(chars[j])) { - if (chars[j] == '\n') { - newlines += 1; - if (newlines > 1) { - break; - } else { - i = j; - c = chars[j]; - } - } - j += 1; - } - if (j < length && newlines <= 1 && isLinkQuote(chars[j])) { - char quoteChar = chars[j] == '(' ? ')' : chars[j]; - int start = j = j + 1; - int len = -1; - while (j < length && chars[j] != '\n') { - if (chars[j] == quoteChar) { - len = j - start; - } else if (len > -1 && !isSpace(chars[j])) { - len = -1; - } - j += 1; - } - if (len > -1) { - linkValue[1] = new String(chars, start, len); - i = j; - c = chars[j]; - } - } - if (c == '\n' && state != NONE) { - links.put(linkId.toLowerCase(), linkValue); - System.arraycopy(chars, i, chars, linestart, length - i); - length -= (i - linestart); - i = linestart; - buffer.setLength(0); - linkId = null; - } else { - // no valid link title - escape - state = NONE; - } - } else if (!isSpace(c) || buffer.length() > 0) { - buffer.append(c); - } - } - - if (c == '\n') { - state = NEWLINE; - linestart = i; - indentation = indentationChars = 0; - } - - } - } - - private synchronized void secondPass() { - state = NEWLINE; - stack.add(new BaseElement()); - buffer = new StringBuilder((int) (length * 1.2)); - line = 1; - boolean escape = false; - - for (i = 0; i < length; ) { - char c; - - if (state == NEWLINE) { - checkBlock(0); - } - - boolean leadingSpaceChars = true; - - while (i < length && chars[i] != '\n') { - - c = chars[i]; - leadingSpaceChars = leadingSpaceChars && isSpace(c); - - if (state == HTML_BLOCK) { - buffer.append(c); - i += 1; - continue; - } - - if (escape) { - buffer.append(c); - escape = false; - i += 1; - continue; - } else if (c == '\\') { - escape = true; - i += 1; - continue; - } - - switch (c) { - case '*': - case '_': - if (checkEmphasis(c)) { - continue; - } - break; - - case '`': - if (checkCodeSpan(c)) { - continue; - } - break; - - case '[': - if (checkLink(c)) { - continue; - } - break; - - case '!': - if (checkImage()) { - continue; - } - break; - - case '<': - if (checkHtmlLink(c)) { - continue; - } - break; - } - - if (state == HEADER) { - if (c == '#') { - ((Element) stack.peek()).mod++; - } else { - ((Element) stack.peek()).mod = 0; - } - } - - if (!leadingSpaceChars) { - buffer.append(c); - } - i += 1; - - } - - while (i < length && chars[i] == '\n') { - - c = chars[i]; - line += 1; - - if (state == HTML_BLOCK && - (i >= length - 1 || chars[i + 1] != '\n')) { - buffer.append(c); - i += 1; - continue; - } - if (state == HEADER) { - Element header = (Element) stack.pop(); - if (header.mod > 0) { - buffer.setLength(buffer.length() - header.mod); - } - header.close(); - } - - int bufLen = buffer.length(); - boolean markParagraph = bufLen > 0 && buffer.charAt(bufLen - 1) == '\n'; - - if (state == LIST && i < length) { - checkParagraph(listParagraphs); - } - if (state == PARAGRAPH && i < length) { - checkParagraph(true); - checkHeader(); - } - - buffer.append(c); - state = NEWLINE; - lineMarker = buffer.length(); - - if (markParagraph) { - paragraphStartMarker = lineMarker; - } - i += 1; - - } - - } - while (!stack.isEmpty()) { - ((Element) stack.pop()).close(); - } - } - - private boolean checkBlock(int blockquoteNesting) { - int indentation = 0; - int j = i; - while (j < length && isSpace(chars[j])) { - indentation += chars[j] == '\t' ? 4 : 1; - j += 1; - } - - if (j < length) { - char c = chars[j]; - - if (checkBlockquote(c, j, indentation, blockquoteNesting)) { - return true; - } - - if (checkCodeBlock(c, j, indentation, blockquoteNesting)) { - return true; - } - - if (checkList(c, j, indentation, blockquoteNesting)) { - return true; - } - - if (checkAtxHeader(c, j)) { - return true; - } - - if (!checkHtmlBlock(c, j)) { - state = stack.search(ListElement.class) != null ? LIST : PARAGRAPH; - } - } - return false; - } - - private boolean checkEmphasis(char c) { - for (int l = 1; l >= 0; l--) { - if (emph[l] != null && emph[l].end == i) { - emph[l].close(); - i += emph[l].mod; - emph[l] = null; - return true; - } - } - if (c == '*' || c == '_') { - int n = 1; - int j = i + 1; - while(j < length && chars[j] == c && n <= 3) { - n += 1; - j += 1; - } - int found = n; - boolean isStartTag = j < length - 1 && !Character.isWhitespace(chars[j]); - if (isStartTag && (emph[0] == null || emph[1] == null)) { - List possibleEndTags = new ArrayList(); - char lastChar = 0; - int count = 0; - boolean escape = false; - for (int k = j; k <= length; k++) { - if (chars[k] == '\n' && lastChar == '\n') { - break; - } - lastChar = chars[k]; - - if (escape) { - escape = false; - } else { - if (chars[k] == '\\') { - escape = true; - } else if (chars[k] == '`') { - k = skipCodeSpan(k); - } else if (chars[k] == '[') { - k = skipLink(k); - } else if (chars[k] == c) { - count += 1; - } else { - if (count > 0 && !Character.isWhitespace(chars[k - count - 1])) { - // add an int array to possible end tags: [position, nuberOfTokens] - possibleEndTags.add(new int[] {k - count, count}); - } - count = 0; - } - } - } - - for (int l = 1; l >= 0; l--) { - if (emph[l] == null && n > l) { - emph[l] = checkEmphasisInternal(l + 1, possibleEndTags); - if (emph[l] != null) { - n -= l + 1; - } - } - } - } - if (n == found) { - return false; - } - // write out remaining token chars - for (int m = 0; m < n; m++) { - buffer.append(c); - } - i = j; - return true; - } - return false; - } - - private Emphasis checkEmphasisInternal(int length, List possibleEndTags) { - for (int k = 0; k < possibleEndTags.size(); k++) { - int[] possibleEndTag = (int[]) possibleEndTags.get(k); - if (possibleEndTag[1] >= length) { - Emphasis elem = new Emphasis(length, possibleEndTag[0]); - elem.open(); - possibleEndTag[0] += length; - possibleEndTag[1] -= length; - return elem; - } - } - return null; - } - - private boolean checkCodeSpan(char c) { - if (c != '`') { - return false; - } - int n = 0; // additional backticks to match - int j = i + 1; - StringBuffer code = new StringBuffer(); - while(j < length && chars[j] == '`') { - n += 1; - j += 1; - } - outer: while(j < length) { - if (chars[j] == '`') { - if (n == 0) { - break; - } else { - if (j + n >= length) { - return false; - } - for (int k = j + 1; k <= j + n; k++) { - if (chars[k] != '`') { - break; - } else if (k == j + n) { - j = k; - break outer; - } - } - - } - } - if (chars[j] == '&') { - code.append("&"); - } else if (chars[j] == '<') { - code.append("<"); - } else if (chars[j] == '>') { - code.append(">"); - } else { - code.append(chars[j]); - } - j += 1; - } - openTag("code", buffer); - buffer.append(code.toString().trim()).append("
    "); - i = j + 1; - return true; - } - - // find the end of a code span starting at start - private int skipCodeSpan(int start) { - int n = 0; // additional backticks to match - int j = start + 1; - while(j < length && chars[j] == '`') { - n += 1; - j += 1; - } - outer: while(j < length) { - if (chars[j] == '`') { - if (n == 0) { - break; - } else { - if (j + n >= length) { - return start + 1; - } - for (int k = j + 1; k <= j + n; k++) { - if (chars[k] != '`') { - break; - } else if (k == j + n) { - j = k; - break outer; - } - } - } - } - j += 1; - } - return j; - } - - private int skipLink(int start) { - boolean escape = false; - int nesting = 0; - int j = start + 1; - char c; - while (j < length && (escape || chars[j] != ']' || nesting != 0)) { - c = chars[j]; - if (c == '\n' && chars[j - 1] == '\n') { - return start; - } - - if (escape) { - escape = false; - } else { - escape = c == '\\'; - if (!escape) { - if (c == '[') { - nesting += 1; - } else if (c == ']') { - nesting -= 1; - } - } - } - j += 1; - } - int k = j; - j += 1; - boolean extraSpace = false; - if (j < length && Character.isWhitespace(chars[j])) { - j += 1; - extraSpace = true; - } - c = chars[j++]; - if (c == '[') { - while (j < length && chars[j] != ']') { - if (chars[j] == '\n') { - return start; - } - j += 1; - } - } else if (c == '(' && !extraSpace) { - while (j < length && chars[j] != ')' && !isSpace(chars[j])) { - if (chars[j] == '\n') { - return start; - } - j += 1; - } - if (j < length && chars[j] != ')') { - while (j < length && chars[j] != ')' && Character.isWhitespace(chars[j])) { - j += 1; - } - if (chars[j] == '"') { - int quoteStart = j = j + 1; - int len = -1; - while (j < length && chars[j] != '\n') { - if (chars[j] == '"') { - len = j - quoteStart; - } else if (len > -1) { - if (chars[j] == ')') { - break; - } else if (!isSpace(chars[j])) { - len = -1; - } - } - j += 1; - } - } - if (chars[j] != ')') { - return start; - } - } - } else { - j = k; - } - return j; - } - - private boolean checkLink(char c) { - return checkLinkInternal(c, i + 1, false); - } - - private boolean checkImage() { - return checkLinkInternal(chars[i + 1], i + 2, true); - } - - private boolean checkLinkInternal(char c, int j, boolean isImage) { - if (c != '[') { - return false; - } - StringBuffer b = new StringBuffer(); - boolean escape = false; - boolean space = false; - int nesting = 0; - boolean needsEncoding = false; - while (j < length && (escape || chars[j] != ']' || nesting != 0)) { - c = chars[j]; - if (c == '\n' && chars[j - 1] == '\n') { - return false; - } - - if (escape) { - b.append(c); - escape = false; - } else { - escape = c == '\\'; - if (!escape) { - if (c == '[') { - nesting += 1; - } else if (c == ']') { - nesting -= 1; - } - if (c == '*' || c == '_' || c == '`' || c == '[') { - needsEncoding = true; - } - boolean s = Character.isWhitespace(chars[j]); - if (!space || !s) { - b.append(s ? ' ' : c); - } - space = s; - } - } - j += 1; - } - String text = b.toString(); - b.setLength(0); - String[] link; - String linkId; - int k = j; - j += 1; - // this is weird, but we follow the official markup implementation here: - // only accept space between link text and link target for [][], not for []() - boolean extraSpace = false; - if (j < length && Character.isWhitespace(chars[j])) { - j += 1; - extraSpace = true; - } - c = chars[j++]; - if (c == '[') { - while (j < length && chars[j] != ']') { - if (chars[j] == '\n') { - return false; - } - b.append(chars[j]); - j += 1; - } - linkId = b.toString().toLowerCase(); - if (linkId.length() > 0) { - link = getLink(linkId); - if (link == null) { - return false; - } - } else { - linkId = text.toLowerCase(); - link = getLink(linkId); - if (link == null) { - return false; - } - } - } else if (c == '(' && !extraSpace) { - link = new String[2]; - while (j < length && chars[j] != ')' && !isSpace(chars[j])) { - if (chars[j] == '\n') { - return false; - } - b.append(chars[j]); - j += 1; - } - link[0] = b.toString(); - if (j < length && chars[j] != ')') { - while (j < length && chars[j] != ')' && Character.isWhitespace(chars[j])) { - j += 1; - } - if (chars[j] == '"') { - int start = j = j + 1; - int len = -1; - while (j < length && chars[j] != '\n') { - if (chars[j] == '"') { - len = j - start; - } else if (len > -1) { - if (chars[j] == ')') { - link[1] = new String(chars, start, len); - break; - } else if (!isSpace(chars[j])) { - len = -1; - } - } - j += 1; - } - } - if (chars[j] != ')') { - return false; - } - } - } else { - j = k; - linkId = text.toLowerCase(); - link = getLink(linkId); - if (link == null) { - return false; - } - } - b.setLength(0); - if (isImage) { - buffer.append("\"").append(escapeHtml(text)).append("\"");"); - - } else { - buffer.append(""); - if (needsEncoding) { - MarkdownProcessor wrapped = new MarkdownProcessor(); - buffer.append(wrapped.processLinkText(text)).append(""); - } else { - buffer.append(escapeHtml(text)).append(""); - } - } - i = j + 1; - return true; - } - - private boolean checkHtmlLink(char c) { - if (c != '<') { - return false; - } - int k = i + 1; - int j = k; - while (j < length && !Character.isWhitespace(chars[j]) && chars[j] != '>') { - j += 1; - } - if (chars[j] == '>') { - String href = new String(chars, k, j - k); - if (href.matches("\\w+:\\S*")) { - String text = href; - if (href.startsWith("mailto:")) { - text = href.substring(7); - href = escapeMailtoUrl(href); - } - buffer.append("") - .append(text).append(""); - i = j + 1; - return true; - } else if (href.matches("^.+@.+\\.[a-zA-Z]+$")) { - buffer.append("") - .append(href).append(""); - i = j + 1; - return true; - } - } - return false; - } - - private boolean checkList(char c, int j, int indentation, int blockquoteNesting) { - int nesting = indentation / 4 + blockquoteNesting; - if (c >= '0' && c <= '9') { - while (j < length && chars[j] >= '0' && chars[j] <= '9' ) { - j += 1; - } - if (j < length && chars[j] == '.') { - checkCloseList("ol", nesting); - checkOpenList("ol", nesting); - i = j + 1; - return true; - } - } else if (c == '*' || c == '+' || c == '-') { - if (c != '+' && checkHorizontalRule(c, j, nesting)) { - return true; - } - j += 1; - if (j < length && isSpace(chars[j])) { - checkCloseList("ul", nesting); - checkOpenList("ul", nesting); - i = j; - return true; - } - } - if (isParagraphStart()) { - // never close list unless there's an empty line - checkCloseList(null, nesting - 1); - } - return false; - } - - private void checkOpenList(String tag, int nesting) { - Element list = stack.search(ListElement.class); - if (list == null || !tag.equals(list.tag) || nesting != list.nesting) { - list = new ListElement(tag, nesting); - stack.push(list); - list.open(); - } else { - stack.closeElementsExclusive(list); - buffer.insert(getBufferEnd(), ""); - } - openTag("li", buffer); - listParagraphs = isParagraphStart(); - lineMarker = paragraphStartMarker = buffer.length(); - state = LIST; - } - - private void checkCloseList(String tag, int nesting) { - Element elem = stack.search(ListElement.class); - while (elem != null && - (elem.nesting > nesting || - (elem.nesting == nesting && tag != null && !elem.tag.equals(tag)))) { - stack.closeElements(elem); - elem = stack.peekNestedElement(); - lineMarker = paragraphStartMarker = buffer.length(); - } - } - - private boolean checkCodeBlock(char c, int j, int indentation, int blockquoteNesting) { - int nesting = indentation / 4; - int nestedLists = stack.countNestedLists(null); - Element code; - if (nesting - nestedLists <= 0) { - code = stack.findNestedElement(CodeElement.class, blockquoteNesting + nestedLists); - if (code != null) { - stack.closeElements(code); - lineMarker = paragraphStartMarker = buffer.length(); - } - return false; - } - code = stack.isEmpty() ? null : (Element) stack.peek(); - if (!(code instanceof CodeElement)) { - code = new CodeElement(blockquoteNesting + nestedLists); - code.open(); - stack.push(code); - } - int sub = 4 + nestedLists * 4; - for (int k = sub; k < indentation; k++) { - buffer.append(' '); - } - while(j < length && chars[j] != '\n') { - if (chars[j] == '&') { - buffer.append("&"); - } else if (chars[j] == '<') { - buffer.append("<"); - } else if (chars[j] == '>') { - buffer.append(">"); - } else if (chars[j] == '\t') { - buffer.append(" "); - } else { - buffer.append(chars[j]); - } - j += 1; - } - codeEndMarker = buffer.length(); - i = j; - state = CODE; - return true; - } - - private boolean checkBlockquote(char c, int j, int indentation, int blockquoteNesting) { - int nesting = indentation / 4; - Element elem = stack.findNestedElement(BlockquoteElement.class, nesting + blockquoteNesting); - if (c != '>' && isParagraphStart() || nesting > stack.countNestedLists(elem)) { - elem = stack.findNestedElement(BlockquoteElement.class, blockquoteNesting); - if (elem != null) { - stack.closeElements(elem); - lineMarker = paragraphStartMarker = buffer.length(); - } - return false; - } - nesting += blockquoteNesting; - elem = stack.findNestedElement(BlockquoteElement.class, nesting); - if (c == '>') { - stack.closeElementsUnlessExists(BlockquoteElement.class, nesting); - if (elem != null && !(elem instanceof BlockquoteElement)) { - stack.closeElements(elem); - elem = null; - } - if (elem == null || elem.nesting < nesting) { - elem = new BlockquoteElement(nesting); - elem.open(); - stack.push(elem); - lineMarker = paragraphStartMarker = buffer.length(); - } else { - lineMarker = buffer.length(); - } - i = isSpace(chars[j+ 1]) ? j + 2 : j + 1; - state = NEWLINE; - checkBlock(nesting + 1); - return true; - } else { - return elem instanceof BlockquoteElement; - } - } - - - private void checkParagraph(boolean paragraphs) { - int paragraphEndMarker = getBufferEnd(); - if (paragraphs && paragraphEndMarker > paragraphStartMarker && - (chars[i + 1] == '\n' || buffer.charAt(buffer.length() - 1) == '\n')) { - buffer.insert(paragraphEndMarker, "

    "); - buffer.insert(paragraphStartMarker, "

    "); - } else if (i > 1 && chars[i-1] == ' ' && chars[i-2] == ' ') { - buffer.append("
    "); - } - } - - private boolean checkAtxHeader(char c, int j) { - if (c == '#') { - int nesting = 1; - int k = j + 1; - while (k < length && chars[k++] == '#') { - nesting += 1; - } - HeaderElement header = new HeaderElement(nesting); - header.open(); - stack.push(header); - state = HEADER; - i = k - 1; - return true; - } - return false; - } - - private boolean checkHtmlBlock(char c, int j) { - if (c == '<') { - j += 1; - int k = j; - while (k < length && Character.isLetterOrDigit(chars[k])) { - k += 1; - } - String tag = new String(chars, j, k - j).toLowerCase(); - if (blockTags.contains(tag)) { - state = HTML_BLOCK; - return true; - } - } - return false; - } - - private void checkHeader() { - char c = chars[i + 1]; - if (c == '-' || c == '=') { - int j = i + 1; - while (j < length && chars[j] == c) { - j++; - } - if (j < length && chars[j] == '\n') { - if (c == '=') { - buffer.insert(lineMarker, "

    "); - buffer.append("

    "); - } else { - buffer.insert(lineMarker, "

    "); - buffer.append("

    "); - } - i = j; - } - } - } - - private boolean checkHorizontalRule(char c, int j, int nesting) { - if (c != '*' && c != '-') { - return false; - } - int count = 1; - int k = j; - while (k < length && (isSpace(chars[k]) || chars[k] == c)) { - k += 1; - if (chars[k] == c) { - count += 1; - } - } - if (count >= 3 && chars[k] == '\n') { - checkCloseList(null, nesting - 1); - buffer.append("
    "); - i = k; - return true; - } - return false; - } - - private void cleanup() { - links = null; - chars = null; - buffer = null; - stack = null; - } - - private String escapeHtml(String str) { - if (str.indexOf('"') > -1) { - str = str.replace("\"", """); - } - if (str.indexOf('<') > -1) { - str = str.replace("\"", "<"); - } - if (str.indexOf('>') > -1) { - str = str.replace("\"", ">"); - } - return str; - } - - private String escapeMailtoUrl(String str) { - StringBuffer b = new StringBuffer(); - char[] chars = str.toCharArray(); - for (int i = 0; i < chars.length; i++) { - double random = Math.random(); - if (random < 0.5) { - b.append("&#x").append(Integer.toString(chars[i], 16)).append(";"); - } else if (random < 0.9) { - b.append("&#").append(Integer.toString(chars[i], 10)).append(";"); - } else { - b.append(chars[i]); - } - } - return b.toString(); - } - - private synchronized String processLinkText() { - buffer = new StringBuilder((int) (length * 1.2)); - line = 1; - boolean escape = false; - - for (i = 0; i < length; ) { - char c = chars[i]; - - if (escape) { - buffer.append(c); - escape = false; - i += 1; - continue; - } else if (c == '\\') { - escape = true; - i += 1; - continue; - } - switch (c) { - case '*': - case '_': - if (checkEmphasis(c)) { - continue; - } - break; - - case '`': - if (checkCodeSpan(c)) { - continue; - } - break; - - case '!': - if (checkImage()) { - continue; - } - break; - } - - buffer.append(c); - i += 1; - } - return buffer.toString().trim(); - } - - boolean isLinkQuote(char c) { - return c == '"' || c == '\'' || c == '('; - } - - boolean isSpace(char c) { - return c == ' ' || c == '\t'; - } - - boolean isParagraphStart() { - return paragraphStartMarker == lineMarker; - } - - int getBufferEnd() { - int l = buffer.length(); - while(l > 0 && buffer.charAt(l - 1) == '\n') { - l -= 1; - } - return l; - } - - class ElementStack extends Stack { - private static final long serialVersionUID = 8514510754511119691L; - - private Element search(Class clazz) { - for (int i = size() - 1; i >= 0; i--) { - Element elem = (Element) get(i); - if (clazz.isInstance(elem)) { - return elem; - } - } - return null; - } - - private int countNestedLists(Element startFromElement) { - int count = 0; - for (int i = size() - 1; i >= 0; i--) { - Element elem = (Element) get(i); - if (startFromElement != null) { - if (startFromElement == elem) { - startFromElement = null; - } - continue; - } - if (elem instanceof ListElement) { - count += 1; - } else if (elem instanceof BlockquoteElement) { - break; - } - } - return count; - } - - private Element peekNestedElement() { - for (int i = size() - 1; i >= 0; i--) { - Element elem = (Element) get(i); - if (elem instanceof ListElement || elem instanceof BlockquoteElement) { - return elem; - } - } - return null; - } - - private Element findNestedElement(Class type, int nesting) { - for (Iterator it = iterator(); it.hasNext();) { - Element elem = (Element) it.next(); - if (nesting == elem.nesting && type.isInstance(elem)) { - return elem; - } - } - return null; - } - - private void closeElements(Element element) { - do { - ((Element) peek()).close(); - } while (pop() != element); - } - - private void closeElementsExclusive(Element element) { - while(peek() != element) { - ((Element) pop()).close(); - } - } - - private void closeElementsUnlessExists(Class type, int nesting) { - Element elem = this.findNestedElement(type, nesting); - if (elem == null) { - while(stack.size() > 0) { - elem = (Element) this.peek(); - if (elem != null && elem.nesting >= nesting) { - ((Element) stack.pop()).close(); - } else { - break; - } - } - } - } - } - - class Element { - String tag; - int nesting, mod; - - void open() { - openTag(tag, buffer); - } - - void close() { - buffer.insert(getBufferEnd(), ""); - } - } - - class BaseElement extends Element { - void open() {} - void close() {} - } - - class BlockquoteElement extends Element { - BlockquoteElement(int nesting) { - tag = "blockquote"; - this.nesting = nesting; - } - } - - class CodeElement extends Element { - CodeElement(int nesting) { - this.nesting = nesting; - } - - void open() { - openTag("pre", buffer); - openTag("code", buffer); - } - - void close() { - buffer.insert(codeEndMarker, "
    "); - } - } - - class HeaderElement extends Element { - HeaderElement(int nesting) { - this.nesting = nesting; - this.tag = "h" + nesting; - } - } - - class ListElement extends Element { - ListElement(String tag, int nesting) { - this.tag = tag; - this.nesting = nesting; - } - - void close() { - buffer.insert(getBufferEnd(), ""); } - } - - class Emphasis extends Element { - int end; - Emphasis(int mod, int end) { - this.mod = mod; - this.end = end; - this.tag = mod == 1 ? "em" : "strong"; - } - } - - public static void main(String[] args) throws IOException { - if (args.length != 1) { - System.out.println("Usage: java org.helma.util.MarkdownProcessor FILE"); - return; - } - MarkdownProcessor processor = new MarkdownProcessor(new File(args[0])); - System.out.println(processor.process()); - } - - -} - diff --git a/src/main/java/helma/util/MimePart.java b/src/main/java/helma/util/MimePart.java deleted file mode 100644 index e4ed29d8..00000000 --- a/src/main/java/helma/util/MimePart.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import org.apache.commons.fileupload2.core.FileItem; - -import java.io.*; -import java.util.Date; -import java.util.StringTokenizer; - -/** - * This represents a MIME part of a HTTP file upload - */ -public class MimePart implements Serializable { - private static final long serialVersionUID = 7800159441938112415L; - - private final String name; - private int contentLength; - private String contentType; - private byte[] content; - private Date lastModified; - private String eTag; - private FileItem fileItem; - private File file; - - /** - * Creates a new MimePart object. - * @param name the file name - * @param content the mime part content - * @param contentType the content type - */ - public MimePart(String name, byte[] content, String contentType) { - this.name = normalizeFilename(name); - this.content = (content == null) ? new byte[0] : content; - this.contentType = contentType; - contentLength = (content == null) ? 0 : content.length; - } - - /** - * Creates a new MimePart object from a file upload. - * @param fileItem a commons fileupload file item - */ - public MimePart(FileItem fileItem) { - name = normalizeFilename(fileItem.getName()); - contentType = fileItem.getContentType(); - contentLength = (int) fileItem.getSize(); - if (fileItem.isInMemory()) { - content = fileItem.get(); - } else { - this.fileItem = fileItem; - } - } - - /** - * @return the content type - */ - public String getContentType() { - return contentType; - } - - /** - * Get the number of bytes in the mime part's content - * @return the content length - */ - public int getContentLength() { - return contentLength; - } - - /** - * Get the mime part's name - * @return the file name - */ - public String getName() { - return name; - } - - /** - * Return the content of the mime part as byte array. - * @return the mime part content as byte array - */ - public byte[] getContent() { - if (content == null && (fileItem != null || file != null)) { - loadContent(); - } - return content; - } - - private synchronized void loadContent() { - content = new byte[contentLength]; - try { - InputStream in = getInputStream(); - int read = 0; - while (read < contentLength) { - int r = in.read(content, read, contentLength - read); - if (r == -1) - break; - read += r; - } - in.close(); - } catch (Exception x) { - System.err.println("Error in MimePart.loadContent(): " + x); - content = new byte[0]; - } - } - - /** - * Return an InputStream to read the content of the mime part - * @return an InputStream for the mime part content - * @throws IOException an I/O related error occurred - */ - public InputStream getInputStream() throws IOException { - if (file != null && file.canRead()) { - return new FileInputStream(file); - } else if (fileItem != null) { - return fileItem.getInputStream(); - } else if (content != null) { - return new ByteArrayInputStream(content); - } else { - return null; - } - } - - /** - * Return the content of the mime part as string, if its content type is - * null, text/* or application/text. Otherwise, return null. - * - * @return the content of the mime part as string - */ - public String getText() { - if ((contentType == null) || contentType.startsWith("text/") - || contentType.startsWith("application/text")) { - String charset = getSubHeader(contentType, "charset"); - byte[] content = getContent(); - if (charset != null) { - try { - return new String(content, charset); - } catch (UnsupportedEncodingException uee) { - return new String(content); - } - } else { - return new String(content); - } - } else { - return null; - } - } - - - /** - * Get the last modified date - * @return the last modified date - */ - public Date getLastModified() { - return lastModified; - } - - /** - * Set the last modified date - * @param lastModified the last modified date - */ - public void setLastModified(Date lastModified) { - this.lastModified = lastModified; - } - - /** - * Get the ETag of the mime part - * @return the ETag - */ - public String getETag() { - return eTag; - } - - /** - * Set the ETag for the mime part - * @param eTag the ETag - */ - public void setETag(String eTag) { - this.eTag = eTag; - } - - /** - * Write the mimepart to a directory, using its name as file name. - * - * @param dir the directory to write the file to - * @return the absolute path name of the file written, or null if an error occurred - */ - public String writeToFile(String dir) { - return writeToFile(dir, null); - } - - /** - * Write the mimepart to a file. - * - * @param dir the directory to write the file to - * @return the name of the file written, or null if an error occurred - */ - public String writeToFile(String dir, String fname) { - try { - File base = new File(dir).getAbsoluteFile(); - - // make directories if they don't exist - if (!base.exists()) { - base.mkdirs(); - } - - String filename = name; - - if (fname != null) { - if (fname.indexOf(".") < 0) { - // check if we can use extension from name - int ndot = (name == null) ? (-1) : name.lastIndexOf("."); - - if (ndot > -1) { - filename = fname + name.substring(ndot); - } else { - filename = fname; - } - } else { - filename = fname; - } - } - - // set instance variable to the new file - file = new File(base, filename); - - if (fileItem != null) { - fileItem.write(file.toPath()); - // null out fileItem, since calling write() may have moved the temp file - fileItem = null; - } else { - FileOutputStream fout = new FileOutputStream(file); - fout.write(getContent()); - fout.close(); - } - // return file name - return filename; - } catch (Exception x) { - System.err.println("Error in MimePart.writeToFile(): " + x); - return null; - } - } - - /** - * Get a sub-header from a header, e.g. the charset from - * Content-Type: text/plain; charset="UTF-8" - */ - public static String getSubHeader(String header, String subHeaderName) { - if (header == null) { - return null; - } - - StringTokenizer headerTokenizer = new StringTokenizer(header, ";"); - - while (headerTokenizer.hasMoreTokens()) { - String token = headerTokenizer.nextToken().trim(); - int i = token.indexOf("="); - - if (i > 0) { - String hname = token.substring(0, i).trim(); - - if (hname.equalsIgnoreCase(subHeaderName)) { - String value = token.substring(i + 1); - return value.replace('"', ' ').trim(); - } - } - } - - return null; - } - - /** - * Normalize a upload file name. Internet Explorer on Windows sends - * the whole path, so we cut off everything before the actual name. - */ - public static String normalizeFilename(String filename) { - if (filename == null) - return null; - int idx = filename.lastIndexOf('/'); - if (idx > -1) - filename = filename.substring(idx + 1); - idx = filename.lastIndexOf('\\'); - if (idx > -1) - filename = filename.substring(idx + 1); - return filename; - } - -} diff --git a/src/main/java/helma/util/MimePartDataSource.java b/src/main/java/helma/util/MimePartDataSource.java deleted file mode 100644 index ac270309..00000000 --- a/src/main/java/helma/util/MimePartDataSource.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.io.*; -import javax.activation.*; - -/** - * Makes MimeParts usable as Datasources in the Java Activation Framework (JAF) - */ -public class MimePartDataSource implements DataSource { - private MimePart part; - private String name; - - /** - * Creates a new MimePartDataSource object. - * - * @param part ... - */ - public MimePartDataSource(MimePart part) { - this.part = part; - this.name = part.getName(); - } - - /** - * Creates a new MimePartDataSource object. - * - * @param part ... - * @param name ... - */ - public MimePartDataSource(MimePart part, String name) { - this.part = part; - this.name = name; - } - - /** - * - * - * @return ... - * - * @throws IOException ... - */ - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(part.getContent()); - } - - /** - * - * - * @return ... - * - * @throws IOException ... - */ - public OutputStream getOutputStream() throws IOException { - throw new IOException("Can't write to MimePart object."); - } - - /** - * - * - * @return ... - */ - public String getContentType() { - return part.getContentType(); - } - - /** - * - * - * @return ... - */ - public String getName() { - return name; - } -} diff --git a/src/main/java/helma/util/ParanoidServerSocket.java b/src/main/java/helma/util/ParanoidServerSocket.java deleted file mode 100644 index 30044d86..00000000 --- a/src/main/java/helma/util/ParanoidServerSocket.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.io.IOException; -import java.net.*; - -/** - * A server socket that can allow connections to only a few selected hosts. - */ -public class ParanoidServerSocket extends ServerSocket { - private InetAddressFilter filter; - - /** - * Creates a new ParanoidServerSocket object. - * - * @param port ... - * - * @throws IOException ... - */ - public ParanoidServerSocket(int port) throws IOException { - super(port); - } - - /** - * Creates a new ParanoidServerSocket object. - * - * @param port ... - * @param filter ... - * - * @throws IOException ... - */ - public ParanoidServerSocket(int port, InetAddressFilter filter) - throws IOException { - super(port); - this.filter = filter; - } - - /** - * - * - * @return ... - * - * @throws IOException ... - */ - public Socket accept() throws IOException { - Socket s = null; - - while (s == null) { - s = super.accept(); - - if ((filter != null) && !filter.matches(s.getInetAddress())) { - System.err.println("Refusing connection from " + s.getInetAddress()); - - try { - s.close(); - } catch (IOException ignore) { - } - - s = null; - } - } - - return s; - } - - /** - * - * - * @param filter ... - */ - public void setFilter(InetAddressFilter filter) { - this.filter = filter; - } - - /** - * - * - * @return ... - */ - public InetAddressFilter getFilter() { - return this.filter; - } -} diff --git a/src/main/java/helma/util/ResourceProperties.java b/src/main/java/helma/util/ResourceProperties.java deleted file mode 100644 index cf3d92be..00000000 --- a/src/main/java/helma/util/ResourceProperties.java +++ /dev/null @@ -1,591 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.io.IOException; -import java.io.InputStream; -import java.util.*; -import helma.framework.core.*; -import helma.framework.repository.Resource; -import helma.framework.repository.Repository; - -/** - * A property dictionary that is updated from property resources - */ -public class ResourceProperties extends Properties { - - private static final long serialVersionUID = -2258056784572269727L; - - // Delay between checks - private final long CACHE_TIME = 1500L; - - // Default properties. Note that in contrast to java.util.Properties, - // defaultProperties are copied statically to ourselves in update(), so - // there's no need to check them in retrieval methods. - protected ResourceProperties defaultProperties; - - // Defines wether keys are case-sensitive or not - private boolean ignoreCase = true; - - // Cached checksum of last check - private long lastChecksum = 0; - - // Time of last check - private long lastCheck = 0; - - // Time porperties were last modified - private long lastModified = System.currentTimeMillis(); - - // Application where to fetch additional resources - private Application app; - - // Name of possible resources to fetch from the applications's repositories - private String resourceName; - - // Sorted map of resources - private Set resources; - - // lower case key to original key mapping for case insensitive lookups - private Properties keyMap = new Properties(); - - // prefix for sub-properties - private String prefix; - - // parent properties for sub-properties - private ResourceProperties parentProperties; - - /** - * Constructs an empty ResourceProperties - * Resources must be added manually afterwards - */ - public ResourceProperties() { - // TODO: we can't use TreeSet because we don't have the app's resource comparator - // Since resources don't implement Comparable, we can't add them to a "naked" TreeSet - // As a result, resource ordering is random when updating. - resources = new LinkedHashSet(); - } - - /** - * Constructs an empty ResourceProperties - * Resources must be added manually afterwards - */ - public ResourceProperties(Application app) { - resources = new TreeSet(app.getResourceComparator()); - } - - /** - * Constructs a ResourceProperties retrieving resources from the given - * application using the given name to fetch resources - * @param app application to fetch resources from - * @param resourceName name to use when fetching resources from the application - */ - public ResourceProperties(Application app, String resourceName) { - this.app = app; - this.resourceName = resourceName; - resources = new TreeSet(app.getResourceComparator()); - } - - /** - * Constructs a ResourceProperties retrieving resources from the given - * application using the given name to fetch resources and falling back - * to the given default properties - * @param app application to fetch resources from - * @param resourceName name to use when fetching resources from the application - * @param defaultProperties default properties - */ - public ResourceProperties(Application app, String resourceName, - ResourceProperties defaultProperties) { - this(app, resourceName); - this.defaultProperties = defaultProperties; - forceUpdate(); - } - - /** - * Constructs a ResourceProperties retrieving resources from the given - * application using the given name to fetch resources and falling back - * to the given default properties - * @param app application to fetch resources from - * @param resourceName name to use when fetching resources from the application - * @param defaultProperties default properties - * @param ignoreCase ignore case for property keys, setting all keys to lower case - */ - public ResourceProperties(Application app, String resourceName, - ResourceProperties defaultProperties, - boolean ignoreCase) { - this(app, resourceName); - this.defaultProperties = defaultProperties; - this.ignoreCase = ignoreCase; - forceUpdate(); - } - - /** - * Constructs a properties object containing all entries where the key matches - * the given string prefix from the source map to the target map, cutting off - * the prefix from the original key. - * @see #getSubProperties(String) - * @param parentProperties the parent properties - * @param prefix the property name prefix - */ - private ResourceProperties(ResourceProperties parentProperties, String prefix) { - this.parentProperties = parentProperties; - this.prefix = prefix; - resources = new LinkedHashSet(); - setIgnoreCase(parentProperties.ignoreCase); - forceUpdate(); - } - - /** - * Updates the properties regardless of an actual need - */ - private void forceUpdate() { - lastChecksum = -1; - update(); - } - - /** - * Sets the default properties and updates all properties - * @param defaultProperties default properties - */ - public void setDefaultProperties(ResourceProperties defaultProperties) { - this.defaultProperties = defaultProperties; - update(); - } - - /** - * Adds a resource to the list of resources and updates all properties if - * needed - * @param resource resource to add - */ - public void addResource(Resource resource) { - if (resource != null && !resources.contains(resource)) { - resources.add(resource); - forceUpdate(); - } - } - - /** - * Removes a resource from the list of resources and updates all properties - * if needed - * @param resource resource to remove - */ - public void removeResource(Resource resource) { - if (resources.contains(resource)) { - resources.remove(resource); - forceUpdate(); - } - } - - /** - * Get an iterator over the properties' resources - * @return iterator over the properties' resources - */ - public Iterator getResources() { - return resources.iterator(); - } - - /** - * Updates all properties if there is a need to update - */ - public synchronized void update() { - // set lastCheck first to reduce risk of recursive calls - lastCheck = System.currentTimeMillis(); - if (getChecksum() != lastChecksum) { - // First collect properties into a temporary collection, - // in a second step copy over new properties, - // and in the final step delete properties which have gone. - ResourceProperties temp = new ResourceProperties(); - temp.setIgnoreCase(ignoreCase); - - // first of all, properties are load from default properties - if (defaultProperties != null) { - defaultProperties.update(); - temp.putAll(defaultProperties); - } - - // next we try to load properties from the application's - // repositories, if we belong to any application - if (resourceName != null) { - Iterator iterator = app.getRepositories().iterator(); - while (iterator.hasNext()) { - try { - Repository repository = (Repository) iterator.next(); - Resource res = repository.getResource(resourceName); - if (res != null && res.exists()) { - InputStream in = res.getInputStream(); - temp.load(in); - in.close(); - } - } catch (IOException iox) { - iox.printStackTrace(); - } - } - } - - // if these are subproperties, reload them from the parent properties - if (parentProperties != null && prefix != null) { - parentProperties.update(); - Iterator it = parentProperties.entrySet().iterator(); - int prefixLength = prefix.length(); - while (it.hasNext()) { - Map.Entry entry = (Map.Entry) it.next(); - String key = entry.getKey().toString(); - if (key.regionMatches(ignoreCase, 0, prefix, 0, prefixLength)) { - temp.put(key.substring(prefixLength), entry.getValue()); - } - } - - } - - // at last we try to load properties from the resource list - if (resources != null) { - Iterator iterator = resources.iterator(); - while (iterator.hasNext()) { - try { - Resource res = (Resource) iterator.next(); - if (res.exists()) { - InputStream in = res.getInputStream(); - temp.load(in); - in.close(); - } - } catch (IOException iox) { - iox.printStackTrace(); - } - } - } - - // Copy over new properties ... - putAll(temp); - // ... and remove properties which have been removed. - Iterator it = super.keySet().iterator(); - while (it.hasNext()) { - if (!temp.containsKey(it.next())) { - it.remove(); - } - } - // copy new up-to-date keyMap to ourself - keyMap = temp.keyMap; - - lastChecksum = getChecksum(); - lastCheck = lastModified = System.currentTimeMillis(); - } - } - - /** - * Extract all entries where the key matches the given string prefix from - * the source map to the target map, cutting off the prefix from the original key. - * The ignoreCase property is inherited and also considered when matching keys - * against the prefix. - * - * @param prefix the string prefix to match against - * @return a new subproperties instance - */ - public ResourceProperties getSubProperties(String prefix) { - if (prefix == null) { - throw new NullPointerException("prefix"); - } - return new ResourceProperties(this, prefix); - } - - /** - * Checks wether the given object is in the value list - * @param value value to look for - * @return true if the value is found in the value list - */ - public synchronized boolean contains(Object value) { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - return super.contains(value.toString()); - } - - /** - * Checks wether the given object is in the key list - * @param key key to look for - * @return true if the key is found in the key list - */ - public synchronized boolean containsKey(Object key) { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - if (ignoreCase) { - return keyMap.containsKey(key.toString().toLowerCase()); - } else { - return super.containsKey(key.toString()); - } - } - - /** - * Returns an enumeration of all values - * @return values enumeration - */ - public synchronized Enumeration elements() { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - return super.elements(); - } - - /** - * Returns a value in this list fetched by the given key - * @param key key to use for fetching the value - * @return value belonging to the given key - */ - public synchronized Object get(Object key) { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - String strkey = key.toString(); - if (ignoreCase) { - strkey = keyMap.getProperty(strkey.toLowerCase()); - if (strkey == null) - return null; - } - return super.get(strkey); - } - - /** - * Returns the date the resources were last modified - * @return last modified date - */ - public long lastModified() { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - return lastModified; - } - - /** - * Returns a checksum for all resources - * @return checksum - */ - public long getChecksum() { - long checksum = 0; - - if (resourceName != null) { - Iterator iterator = app.getRepositories().iterator(); - while (iterator.hasNext()) { - Repository repository = (Repository) iterator.next(); - Resource resource = repository.getResource(resourceName); - if (resource != null) { - checksum += resource.lastModified(); - } - } - } - - if (resources != null) { - Iterator iterator = resources.iterator(); - while (iterator.hasNext()) { - checksum += ((Resource) iterator.next()).lastModified(); - } - } - - if (defaultProperties != null) { - checksum += defaultProperties.getChecksum(); - } - - return checksum; - } - - /** - * Returns a value in the list fetched by the given key or a default value - * if no corresponding key is found - * @param key key to use for fetching the value - * @param defaultValue default value to return if key is not found - * @return spiecific value or default value if not found - */ - public String getProperty(String key, String defaultValue) { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - if (ignoreCase) { - key = keyMap.getProperty(key.toLowerCase()); - if (key == null) - return defaultValue; - } - return super.getProperty(key, defaultValue); - } - - /** - * Returns a value in this list fetched by the given key - * @param key key to use for fetching the value - * @return value belonging to the given key - */ - public String getProperty(String key) { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - if (ignoreCase) { - key = keyMap.getProperty(key.toLowerCase()); - if (key == null) - return null; - } - return super.getProperty(key); - } - - /** - * Checks wether the properties list is empty - * @return true if the properties list is empty - */ - public synchronized boolean isEmpty() { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - return super.isEmpty(); - } - - /** - * Checks wether case-sensitivity is ignored for keys - * @return true if case-sensitivity is ignored for keys - */ - public boolean isIgnoreCase() { - return ignoreCase; - } - - /** - * Returns an enumeration of all keys - * @return keys enumeration - */ - public synchronized Enumeration keys() { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - return super.keys(); - } - - /** - * Returns a set of all keys - * @return keys set - */ - public Set keySet() { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - return super.keySet(); - } - - /** - * Puts a new key-value pair into the properties list - * @param key key - * @param value value - * @return the old value, if an old value got replaced - */ - public synchronized Object put(Object key, Object value) { - if (value instanceof String) { - value = ((String) value).trim(); - } - String strkey = key.toString(); - if (ignoreCase) { - keyMap.put(strkey.toLowerCase(), strkey); - } - return super.put(strkey, value); - } - - /** - * Removes a key-value pair from the properties list - * @param key key - * @return the old value - */ - public synchronized Object remove(Object key) { - String strkey = key.toString(); - if (ignoreCase) { - strkey = (String) keyMap.remove(strkey.toLowerCase()); - if (strkey == null) - return null; - } - return super.remove(strkey); - } - - /** - * Changes how keys are handled - * @param ignore true if to ignore case-sensitivity for keys - */ - public void setIgnoreCase(boolean ignore) { - if (!super.isEmpty()) { - throw new RuntimeException("setIgnoreCase() can only be called on empty Properties"); - } - ignoreCase = ignore; - } - - /** - * Returns the number of peroperties in the list - * @return number of properties - */ - public synchronized int size() { - if ((System.currentTimeMillis() - lastCheck) > CACHE_TIME) { - update(); - } - return super.size(); - } - - /** - * Overwrite clear() to also empty the key map. - */ - public synchronized void clear() { - keyMap.clear(); - super.clear(); - } - - /** - * Compares this ResourceProperties instance to the one passed - * as argument. Note that in contrast to Hashtable.equals this method - * isn't synchronized to avoid deadlocks (which can happen in eg. - * DbSource.equals), and the comparison might return a wrong result - * if one of the two instances is modified during this method call. This - * method however doesn't throw a ConcurrentModificationException. - * - * @param o object to be compared for equality with this instance - * @return true if the specified Object is equal to this instance - * @see Hashtable#equals(Object) - */ - public boolean equals(Object o) { - if (o == this) { - return true; - } - - if (!(o instanceof ResourceProperties)) { - return false; - } - ResourceProperties t = (ResourceProperties) o; - if (t.size() != size()) { - return false; - } - - try { - Object[] keys = keySet().toArray(); - for (Object key : keys) { - Object value = get(key); - if (value == null) { - if (!(t.get(key) == null && t.containsKey(key))) { - return false; - } - } else { - if (!value.equals(t.get(key))) { - return false; - } - } - } - } catch (ClassCastException unused) { - return false; - } catch (NullPointerException unused) { - return false; - } - - return true; - } - - -} diff --git a/src/main/java/helma/util/StringUtils.java b/src/main/java/helma/util/StringUtils.java deleted file mode 100644 index e23ef35b..00000000 --- a/src/main/java/helma/util/StringUtils.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - - -import java.util.StringTokenizer; -import java.util.Enumeration; -import java.util.List; -import java.util.ArrayList; - -/** - * Utility class for String manipulation. - */ -public class StringUtils { - - - /** - * Split a string into an array of strings. Use comma and space - * as delimiters. - */ - public static String[] split(String str) { - return split(str, ", \t\n\r\f"); - } - - /** - * Split a string into an array of strings. - */ - public static String[] split(String str, String delim) { - if (str == null) { - return new String[0]; - } - StringTokenizer st = new StringTokenizer(str, delim); - String[] s = new String[st.countTokens()]; - for (int i=0; i lastread)) { - reload(); - } - - lastcheck = System.currentTimeMillis(); - } - - /** - * Get the properties file - * - * @return the properties file - */ - public File getFile() { - return file; - } - - /** - * Reload properties. This clears out the existing entries, - * loads the main properties file and then adds any additional - * properties there may be (usually from zip files). This is used - * internally by addProps() and removeProps(). - */ - private synchronized void reload() { - // clear out old entries - clear(); - - // read from the primary file - if (file != null && file.exists()) { - FileInputStream bpin = null; - - try { - bpin = new FileInputStream(file); - load(bpin); - } catch (Exception x) { - System.err.println("Error reading properties from file " + file + ": " + x); - } finally { - try { - bpin.close(); - } catch (Exception ignore) { - // ignored - } - } - } - - // read additional properties from zip files, if available - if (additionalProps != null) { - for (Iterator i = additionalProps.values().iterator(); i.hasNext();) - putAll((Properties) i.next()); - } - - lastread = System.currentTimeMillis(); - } - - /** - * Similar to load(), but adds to the existing properties instead - * of discarding them. - */ - public synchronized void addProps(String key, InputStream in) - throws IOException { - Properties newProps = new SystemProperties(); - newProps.load(in); - in.close(); - - if (additionalProps == null) { - additionalProps = new HashMap(); - } - additionalProps.put(key, newProps); - - // fully reload properties and mark as updated - reload(); - lastadd = System.currentTimeMillis(); - } - - /** - * Remove an additional properties dictionary. - */ - public synchronized void removeProps(String key) { - if (additionalProps != null) { - // remove added properties for this key. If we had - // properties associated with the key, mark props as updated. - Object p = additionalProps.remove(key); - - if (p != null) { - // fully reload properties and mark as updated - reload(); - lastadd = System.currentTimeMillis(); - } - } - } - - /* - * This should not be used directly if properties are read from file, - * otherwise changes will be lost whe the file is next modified. - */ - public synchronized Object put(Object key, Object value) { - // cut off trailing whitespace - if (value != null) { - value = value.toString().trim(); - } - - return super.put(ignoreCase ? key.toString().toLowerCase() : key, value); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public synchronized Object get(Object key) { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.get(ignoreCase ? key.toString().toLowerCase() : key); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public synchronized Object remove(Object key) { - return super.remove(ignoreCase ? key.toString().toLowerCase() : key); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public synchronized boolean contains(Object obj) { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.contains(obj); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public synchronized boolean containsKey(Object key) { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.containsKey(ignoreCase ? key.toString().toLowerCase() : key); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public synchronized boolean isEmpty() { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.isEmpty(); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public String getProperty(String name) { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.getProperty(ignoreCase ? name.toLowerCase() : name); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public String getProperty(String name, String defaultValue) { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.getProperty(ignoreCase ? - name.toLowerCase() : name.toLowerCase(), defaultValue); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public synchronized Enumeration keys() { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.keys(); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public Set keySet() { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.keySet(); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public synchronized Enumeration elements() { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.elements(); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public synchronized int size() { - if ((System.currentTimeMillis() - lastcheck) > cacheTime) { - checkFile(); - } - - return super.size(); - } - - /** - * Overrides method to act on the wrapped properties object. - */ - public synchronized String toString() { - return super.toString(); - } - - /** - * Turns case sensitivity for keys in this Map on or off. - */ - public void setIgnoreCase(boolean ignore) { - if (!super.isEmpty()) { - throw new RuntimeException("setIgnoreCase() can only be called on empty Properties"); - } - ignoreCase = ignore; - } - - /** - * Returns true if this property map ignores key case - */ - public boolean isIgnoreCase() { - return ignoreCase; - } - -} diff --git a/src/main/java/helma/util/Timer.java b/src/main/java/helma/util/Timer.java deleted file mode 100644 index c59a5ee5..00000000 --- a/src/main/java/helma/util/Timer.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.io.PrintStream; -import java.util.*; - -/** - * Utility class for timing a series of events - */ -public class Timer { - private Vector timeline; - private Hashtable events; - - /** - * Creates a new Timer object. - */ - public Timer() { - timeline = new Vector(); - events = new Hashtable(); - } - - /** - * - */ - public void reset() { - timeline.setSize(0); - events.clear(); - } - - /** - * - * - * @param name ... - */ - public void beginEvent(String name) { - timeline.addElement(name); - events.put(name, new Event(name)); - } - - /** - * - * - * @param name ... - */ - public void endEvent(String name) { - Event event = (Event) events.get(name); - - if (event != null) { - event.terminate(); - } - } - - /** - * - * - * @param out ... - */ - public void dump(PrintStream out) { - for (int i = 0; i < timeline.size(); i++) { - String name = (String) timeline.elementAt(i); - Event event = (Event) events.get(name); - - out.println(event); - } - } - - class Event { - String name; - long start; - long end; - - Event(String name) { - this.name = name; - start = System.currentTimeMillis(); - } - - void terminate() { - end = System.currentTimeMillis(); - } - - public String toString() { - long now = System.currentTimeMillis(); - - if (end == 0L) { - return (" + " + (now - start) + " " + name); - } else { - return (" " + (end - start) + " " + name); - } - } - } -} diff --git a/src/main/java/helma/util/UrlEncoded.java b/src/main/java/helma/util/UrlEncoded.java deleted file mode 100644 index 7600f7a3..00000000 --- a/src/main/java/helma/util/UrlEncoded.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.util.BitSet; - -/** - * A proxy to java.net.URLEncoder which only encodes when there is actual work - * to do. This is necessary because URLEncoder is quite inefficient (e.g. it - * preallocates buffers and stuff), and we call it often with short string that - * don't need encoding. - */ -public final class UrlEncoded { - - static BitSet dontNeedEncoding; - - static { - dontNeedEncoding = new BitSet(256); - int i; - for (i = 'a'; i <= 'z'; i++) - dontNeedEncoding.set(i); - for (i = 'A'; i <= 'Z'; i++) - dontNeedEncoding.set(i); - for (i = '0'; i <= '9'; i++) - dontNeedEncoding.set(i); - dontNeedEncoding.set(' '); // encoded separately - dontNeedEncoding.set('-'); - dontNeedEncoding.set('_'); - dontNeedEncoding.set('.'); - dontNeedEncoding.set('*'); - } - - /** - * URL-encodes a string using the given encoding, or return it unchanged if - * no encoding was necessary. - * - * @param str The string to be URL-encoded - * @param encoding the encoding to use - * @return the URL-encoded string, or str if no encoding necessary - * @throws UnsupportedEncodingException encoding is not supported - */ - public static String encode(String str, String encoding) - throws UnsupportedEncodingException { - int l = str.length(); - boolean needsSpaceEncoding = false; - - for (int i = 0; i < l; i++) { - char c = str.charAt(i); - - if (c == ' ') { - needsSpaceEncoding = true; - } else if (!dontNeedEncoding.get(c)) { - return URLEncoder.encode(str, encoding); - } - } - - if (needsSpaceEncoding) { - return str.replace(' ', '+'); - } - - return str; - } - - /** - * URL-decode a string using the given encoding, or return it unchanged if - * no encoding was necessary. - * - * @param str The string to be URL-decoded - * @param encoding the encoding to use - * @return the URL-decoded string, or str if no decoding necessary - * @throws UnsupportedEncodingException encoding is not supported - */ - public static String decode(String str, String encoding) - throws UnsupportedEncodingException { - if ((str.indexOf('+') == -1) && (str.indexOf('%') == -1)) { - return str; - } else { - return URLDecoder.decode(str, encoding); - } - } - -} \ No newline at end of file diff --git a/src/main/java/helma/util/WeakCacheMap.java b/src/main/java/helma/util/WeakCacheMap.java deleted file mode 100644 index fd3c635f..00000000 --- a/src/main/java/helma/util/WeakCacheMap.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.util.Map; -import java.util.WeakHashMap; - -/** - * A CacheMap subclass that uses WeakHashMaps internally for its - * rotating tables. - */ -public class WeakCacheMap extends CacheMap { - - public WeakCacheMap(int capacity) { - super(capacity); - } - - public WeakCacheMap(int capacity, float loadFactor) { - super(capacity, loadFactor); - } - - /** - * Overridden to return a java.util.WeakHashMap instance. - * - * @param capacity the initial capacity - * @param loadFactor the load factor - * @return a new Map used for internal caching - */ - protected Map createTable(int capacity, float loadFactor) { - return new WeakHashMap(capacity, loadFactor); - } -} diff --git a/src/main/java/helma/util/WrappedMap.java b/src/main/java/helma/util/WrappedMap.java deleted file mode 100644 index d8b40a66..00000000 --- a/src/main/java/helma/util/WrappedMap.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.util.Map; -import java.util.Set; -import java.util.Collection; - -/** - * A Map that wraps another map. We use this class to be able to - * wrap maps as native objects within a scripting engine rather - * than exposing them through Java reflection. - * Additionally, instances of this class can be set to readonly - * so that the original map can't be modified. - */ -public class WrappedMap implements Map { - - // the wrapped map - protected Map wrapped = null; - - // is this map readonly? - protected boolean readonly = false; - - /** - * Constructor - */ - public WrappedMap(Map map) { - this(map, false); - } - - /** - * Constructor - */ - public WrappedMap(Map map, boolean readonly) { - if (map == null) { - throw new NullPointerException( - "null Map passed to WrappedMap constructor"); - } - wrapped = map; - this.readonly = readonly; - } - - /** - * Set the readonly flag on or off - */ - public void setReadonly(boolean readonly) { - this.readonly = readonly; - } - - /** - * Is this map readonly? - */ - public boolean isReadonly() { - return readonly; - } - - // Methods from interface java.util.Map - - // these are just proxies to the wrapped map, except for - // readonly checks on modifiers. - - public int size() { - return wrapped.size(); - } - - public boolean isEmpty() { - return wrapped.isEmpty(); - } - - public boolean containsKey(Object key) { - return wrapped.containsKey(key); - } - - public boolean containsValue(Object value) { - return wrapped.containsValue(value); - } - - public Object get(Object key) { - return wrapped.get(key); - } - - // Modification Operations - check for readonly - - public Object put(Object key, Object value) { - if (readonly) { - throw new RuntimeException("Attempt to modify readonly map"); - } - return wrapped.put(key, value); - } - - public Object remove(Object key) { - if (readonly) { - throw new RuntimeException("Attempt to modify readonly map"); - } - return wrapped.remove(key); - } - - public void putAll(Map t) { - if (readonly) { - throw new RuntimeException("Attempt to modify readonly map"); - } - wrapped.putAll(t); - } - - public void clear() { - if (readonly) { - throw new RuntimeException("Attempt to modify readonly map"); - } - wrapped.clear(); - } - - - // Views - - public Set keySet() { - return wrapped.keySet(); - } - - public Collection values() { - return wrapped.values(); - } - - public Set entrySet() { - return wrapped.entrySet(); - } - - - // Comparison and hashing - - public boolean equals(Object o) { - return wrapped.equals(o); - } - - public int hashCode() { - return wrapped.hashCode(); - } - - // toString - - public String toString() { - return wrapped.toString(); - } - -} diff --git a/src/main/java/helma/util/XmlUtils.java b/src/main/java/helma/util/XmlUtils.java deleted file mode 100644 index da85e62e..00000000 --- a/src/main/java/helma/util/XmlUtils.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import org.w3c.dom.Document; -import org.w3c.dom.html.HTMLDocument; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.XMLReaderAdapter; -import org.ccil.cowan.tagsoup.Parser; -import org.apache.html.dom.HTMLBuilder; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.net.MalformedURLException; -import java.net.URL; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -/** - * - */ -public class XmlUtils { - private static DocumentBuilderFactory domBuilderFactory = null; - - /** - * - * - * @param obj ... - * - * @return ... - * - * @throws SAXException ... - * @throws IOException ... - * @throws ParserConfigurationException ... - */ - public static Document parseXml(Object obj) - throws SAXException, IOException, - ParserConfigurationException { - if (domBuilderFactory == null) { - domBuilderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); - } - - DocumentBuilder parser = domBuilderFactory.newDocumentBuilder(); - Document doc; - - if (obj instanceof String) { - try { - // first try to interpret string as URL - new URL(obj.toString()); - - doc = parser.parse(obj.toString()); - } catch (MalformedURLException nourl) { - // if not a URL, maybe it is the XML itself - doc = parser.parse(new InputSource(new StringReader(obj.toString()))); - } - } else if (obj instanceof InputStream) { - doc = parser.parse(new InputSource((InputStream) obj)); - } else if (obj instanceof Reader) { - doc = parser.parse(new InputSource((Reader) obj)); - } else { - throw new RuntimeException("Unrecognized argument to parseXml: " + obj); - } - - doc.normalize(); - return doc; - } - - /** - * - * - * @param obj ... - * - * @return ... - * - * @throws IOException ... - */ - public static HTMLDocument parseHtml(Object obj) - throws IOException, SAXException { - try { - Class.forName("org.apache.html.dom.HTMLDocumentImpl"); - } catch (Throwable notfound) { - throw new RuntimeException("Couldn't load Xerces HTML DOM classes. " + - "Make sure you have xercesImpl.jar and xml-apis.jar in your classpath."); - } - - if (obj instanceof String) { - try { - // first try to interpret string as URL - URL url = new URL(obj.toString()); - return getHtmlDocument(new InputStreamReader(url.openStream())); - } catch (MalformedURLException nourl) { - // if not a URL, maybe it is the XML itself - return getHtmlDocument(new StringReader(obj.toString())); - } - } else if (obj instanceof InputStream) { - return getHtmlDocument(new InputStreamReader((InputStream) obj)); - } else if (obj instanceof Reader) { - return getHtmlDocument((Reader) obj); - } else { - throw new RuntimeException("Unrecognized argument to parseHtml: " + obj); - } - } - - private static HTMLDocument getHtmlDocument(Reader reader) - throws IOException, SAXException { - XMLReaderAdapter parser = new XMLReaderAdapter(new Parser()); - HTMLBuilder builder = new HTMLBuilder(); - parser.setDocumentHandler(builder); - parser.parse(new InputSource(reader)); - return builder.getHTMLDocument(); - } -} diff --git a/src/main/resources/META-INF/services/javax.imageio.spi.ImageWriterSpi b/src/main/resources/META-INF/services/javax.imageio.spi.ImageWriterSpi deleted file mode 100644 index f628ec24..00000000 --- a/src/main/resources/META-INF/services/javax.imageio.spi.ImageWriterSpi +++ /dev/null @@ -1 +0,0 @@ -helma.image.imageio.gif.GIFImageWriterSpi diff --git a/src/main/resources/helma/objectmodel/dom/helma.xsl b/src/main/resources/helma/objectmodel/dom/helma.xsl deleted file mode 100644 index efdc5896..00000000 --- a/src/main/resources/helma/objectmodel/dom/helma.xsl +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - - - - - - - - - <xsl:value-of select="$id"/>.xml (Hop XML Database File) - - - - - -

    - root - - root : HopObject - -

    - - - - - - - - - - - - _name - - - - - - _prototype - - - - - - _parent - - HopObject - - - .xml - - - - - - - - - - - - - - - - - - - - - - - - - HopObject - - - .xml - - - - - - - - - - - - - - -
    NameValue
    _children - - - - - - , - - -
    - - -
    - - - - - - - root - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -