|
From: David G. <dg...@co...> - 2003-10-02 15:46:00
|
Hi Qin,
Here's a stage that I use to load values from a properties file. You should
be able to do something similar in your case:
######
# Get the next document ID
######
get-next-doc-id.stageType=Scripting
get-next-doc-id.nextStage=perl-post-doc
get-next-doc-id.failOnError=true
get-next-doc-id.language=javascript
get-next-doc-id.script=\
var document_id;\
var propertiesFile = new
java.io.File(${document.get("merchant_properties")});\
var properties = new java.util.Properties();\
if (propertiesFile.exists()) {properties.load(new
java.io.FileInputStream(propertiesFile));}\
document_id = properties.getProperty("next_document_id", "10001");\
document_id++;\
properties.setProperty("next_document_id", document_id);\
properties.store(new java.io.FileOutputStream(propertiesFile),null);\
document.put("document_id", document_id);
Note that you cannot import in Javascript. This is why you have to use the
fully-qualified class name.
Hope this helps,
David
On Thursday 02 October 2003 8:19 am, Qin Ding wrote:
> David, Good morning:
>
> I checked the scripting examples. I did not see any examples that shows
> how I can extract the original file as type java.io.File. The closest one
> is md5 example, which shows how to get Inputstream out of the document. I
> assume this is the inputstream of the original file. So, I changed my
> script like this:
> initialize.script=\
> importClass(Packages.longlegs.core.filevalidation.TestManager);\
> TestManager.validate(document.get("file_name"),
> document.getInputStream());\
>
> I deployed my file validation jar into babeldoc/lib directory, of course.
>
> When I ran the pipeline, I got this error stating my TestManager is not
> defined.
>
> <2003-10-02 09:57:37,517> INFO [main] : PipelineStage name: initialize
> <2003-10-02 09:57:37,978> ERROR [main] :
> [DefaultPipelineStageErrorHandler.handlePipelineStageError] PipelineStage
> name: initialize Error: com.babeldoc.core.pipeline.PipelineException:
> Script processing failed
> <2003-10-02 09:57:37,978> ERROR [main] : [PipelineFeeder.process]
> com.babeldoc.core.pipeline.PipelineException: Script processing failed
> at
> com.babeldoc.core.pipeline.stage.ScriptingPipelineStage.process(Unknown
> Source)
> at com.babeldoc.core.pipeline.PipelineStage.processStage(Unknown
> Source)
> at
> com.babeldoc.core.pipeline.processor.SyncPipelineStageProcessor.processPipe
>lineStage(Unknown Source)
> at
> com.babeldoc.core.pipeline.processor.SyncPipelineStageProcessor.process(Unk
>nown Source)
> at com.babeldoc.core.pipeline.PipelineStageFactory.process(Unknown
> Source)
> at com.babeldoc.core.pipeline.PipelineFactory.process(Unknown Source)
> at com.babeldoc.core.pipeline.PipelineFactoryFactory.process(Unknown
> Source)
> at
> com.babeldoc.core.pipeline.feeder.SynchronousFeeder.process(Unknown Source)
> at com.babeldoc.core.pipeline.feeder.FeederFactory.process(Unknown
> Source)
> at com.babeldoc.core.pipeline.command.PipelineFeeder.process(Unknown
> Source)
> at com.babeldoc.core.pipeline.command.PipelineFeeder.execute(Unknown
> Source)
> at com.babeldoc.core.BabeldocCommand.executeCommand(Unknown Source)
> at com.babeldoc.core.BabeldocCommand.<init>(Unknown Source)
> at com.babeldoc.core.pipeline.command.PipelineFeeder.<init>(Unknown
> Source)
> at com.babeldoc.core.pipeline.command.PipelineFeeder.main(Unknown
> Source)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
>9) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
>l.java:25) at java.lang.reflect.Method.invoke(Method.java:324)
> at com.babeldoc.core.Main.handleCommand(Unknown Source)
> at com.babeldoc.core.Main.main(Unknown Source)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
>9) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
>l.java:25) at java.lang.reflect.Method.invoke(Method.java:324)
> at com.babeldoc.init.Main.runBabeldocMain(Unknown Source)
> at com.babeldoc.init.Main.main(Unknown Source)
> Caused by: org.apache.bsf.BSFException: JavaScript Error: Internal Error:
> ReferenceError: "TestManager" is not defined.
> at
> org.apache.bsf.engines.javascript.JavaScriptEngine.handleError(Unknown
> Source)
> at org.apache.bsf.engines.javascript.JavaScriptEngine.eval(Unknown
> Source)
> at org.apache.bsf.util.BSFEngineImpl.exec(Unknown Source)
> at org.apache.bsf.BSFManager$6.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
> at org.apache.bsf.BSFManager.exec(Unknown Source)
> ... 27 more
>
>
> ---------------------------------------------------------------------------
>-------------
>
> This is a PRIVATE message. If you are not the intended recipient, please
> delete without copying and kindly advise us by e-mail of the mistake in
> delivery. NOTE: Regardless of content, this e-mail shall not operate to
> bind CSC to any order or other contract unless pursuant to explicit written
> agreement or government initiative expressly permitting the use of e-mail
> for such purpose.
> ---------------------------------------------------------------------------
>-------------
--
David Glick
Transmit Consulting, Inc
619-475-4052
dg...@tr...
|