|
From: Qin D. <qd...@cs...> - 2003-10-02 17:22:51
|
Thank, David. I'll talk to you tomorrow.
Yes, the validate(String fileName, InputStream is) in TestManager is static
method.
Bruce: What should I do in order for my jar visible to the scripting code.
Right now, I just drop it into %BABELDOC_HOME%/lib directory along with all
the jars that BabelDoc depends on.
David, I don't follow what you said about batch file and
externalApplication Stage. I'll try to see if there are some examples and
talk to you later. Thank you.
Qin
----------------------------------------------------------------------------------------
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
<dglick To: "Qin Ding" <qd...@cs...>
@cox.net> cc: bab...@li...
Subject: Re: [Babeldoc-devel] Re: [Babeldoc-user]
10/02/03 12:06 Questions. Please Help
PM
Hi Qin,
Please see my responses below:
On Thursday 02 October 2003 9:12 am, Qin Ding wrote:
> David:
> I see what you did. However, what I try to achieve is different. After
the
> scanner picks up the file, I believe that original file is wrapped up
into
> babeldoc's internal document. Now all I want to do is to get that file
out
> from the document wrapper so that I can pass it to my validation routine.
> The question I have is:
>
> Do you have a method like this:
> document.getFile("file_name") which should return java.io.File
>
Nope. The best you can do is take document.get("file_name"), which will
return the file name as a String, and use it to instantiate your own File
class.
> I saw babeldoc has a method: document.getInputStream(). Does this
> inputStream represent the original file?
>
I haven't used this one, but I'm guessing that it represents the internal
document. If you haven't changed the original document through some type
of
transformation, then it should represent the original file.
> Why when I do the following (pass the file name and file's Inputstream to
> my validation routine), I got TestManager not defined error? The class is
> in %babeldoc_home%/lib directory?
>
> initialize.script=\
> longlegs.core.filevalidation.TestManager.validate(document.get
> ("file_name"),\ document.getInputStream());\
>
Is validate() a static method? If not, you'll need to instantiate the
TestManager class first. Also, I'm not sure if simply placing the class
into
the %babeldoc_home%/lib directory is sufficient. You may need to put it
into
the CLASSPATH, as well. Perhaps Bruce can comment on this?
> May I give you a call? I guess I am not very good to make myself
> understood in writing. I appreciated it very much.
>
I'm happy to talk to you, however I'm leaving the office for most of the
day
in a minute. You may want to consider an alternative way to get this going
for now:
1. Create a batch file that you can run from the command line, passing the
name of a file, that will run your validation routine.
2. Use the ExternalApplication stage to run your batch file. Be sure to
set
the pipeInResponse attribute to true.
3. The output of the external program will placed in an attribute called
ExternalApplicationResponse. From there, you can place it into the main
document, test it, slice it, dice it, etc.
Hope this helps. If not, I'll be available later this evening or tomorrow.
David
> Qin
>
>
>
>
---------------------------------------------------------------------------
>-------------
>
> 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
> <dglick To: "Qin Ding"
> <qd...@cs...> @cox.net> cc:
> bab...@li... Subject: Re: [Babeldoc-devel] Re:
> [Babeldoc-user] 10/02/03 10:59 Questions. Please Help AM
>
>
>
>
>
>
> Oops! I told an untruth. You CAN use imports in Javascript, as you've
> done.
> Remember this when you trust what I say... :-)
>
> David
>
> On Thursday 02 October 2003 8:50 am, David Glick wrote:
> > 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.processPi
>
> > >pe lineStage(Unknown Source)
> > > at
>
> com.babeldoc.core.pipeline.processor.SyncPipelineStageProcessor.process(U
>
> > >nk 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(DelegatingMethodAccessorI
>
> > >mp 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(DelegatingMethodAccessorI
>
> > >mp 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...
|