You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Lionel Crine <cr...@4dconcept.fr> on 2003/12/25 13:43:02 UTC

[A SOLUTION] Validating a document with an action.

I wrote an action which can validate an xml document according a DTD.

Here an example :

The ACTION :
In the act method you can write :

StrDocument = source; --> representing the * of the sitemap.

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
dbf.setValidating(true);
ErrorHandler handler = (ErrorHandler) new ValidationException();
db.setErrorHandler(handler);
db.parse(new InputSource(new 
ByteArrayInputStream(strDocument.getBytes("UTF-8"))));
return EMPTY_MAP;
}
catch (ParserConfigurationException pce) {
Debugger.println("ValidatingDTD.endElement : Validation Exception");
pce.printStackTrace();
return null;
}

catch (SAXParseException spe) {
//This Exception is thrown from the ValidationException class.
Debugger.println("ValidatingDTD.endElement : Validation Exception");
spe.printStackTrace();
return null;
}

the SITEMAP :

<!--*** Finish the declaration ***-->
       <map:match pattern="validate/*.xml">
         <map:act type="validateModif" src="{1}.xml">
              <map:parameter name="url_dtd"
            value="modification.dtd" /> --> be sure the DTD will be find.
           <map:generate type="GetDocument" src="{../1}.xml" />
           <map:serialize type="xml" />
         </map:act>
        <map:redirect-to uri="cocoon:/validationFailed"/>
       </map:match>


The ValidationException class

it should implements ErrorHandler and you should set three methods :

warning, error, fatalError.
Here an example of one :

/**
  * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
  */
public void fatalError(SAXParseException exception) throws SAXException {
Debugger.println("SAXParseException : Fatal Error");
Debugger.println("Fatal Error: " + exception.getMessage());
Debugger.println(" at line " + exception.getLineNumber() + ", column " + 
exception.getColumnNumber());
Debugger.println(" in entity " + exception.getSystemId());
exception.printStackTrace();
throw exception;



Hope that help..

Lionel





Lionel CRINE
Ingénieur Systèmes documentaires
Société : 4DConcept
22 rue Etienne de Jouy 78353 JOUY EN JOSAS
Tel : 01.34.58.70.70 Fax : 01.39.58.70.70


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Problems building 2.1.2

Posted by Tony Edwards <te...@civica.com.au>.
Hi Joerg,
I'll check that out. Thanks!

Tony

Joerg Heinicke wrote:

>Hello Tony,
>
>I guess nobody had such an error, so nobody can help you. The only thing
>
>I guess is a non-Cocoon Rhino on the classpath.
>
>Chris, can you confirm my guess from a look on the code?
>
>Regards,
>
>Joerg
>
>On 07.11.2003 00:09, Tony Edwards wrote:
>  
>
>>Hello again,
>>Still no joy compiling 2.1.2 obtained from cocoon-latest-srs.zip in
>>    
>>
>the 
>  
>
>>downloads section of the web site.
>>Previous version built without incident. The difficulty is I'm not a 
>>java programmer and I get a little nervous when things don't work 
>>straight off the bat as they usually do!
>>Can anyone shed some light as to what's happening?
>>I'm running JDK 1.4.1 on XP.
>>The error I get is this:
>>
>>
>>    
>>
>C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\fo
>m\FOM_JavaScriptInterpreter.java:199: 
>  
>
>>cannot resolve symbol
>>symbol  : method setOptimizationLevel (int)
>>location: class org.mozilla.javascript.tools.debugger.Main
>>           db.setOptimizationLevel(OPTIMIZATION_LEVEL);
>>             ^
>>
>>    
>>
>C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\Ja
>vaScriptInterpreter.java:198: 
>  
>
>>cannot resolve symbol
>>symbol  : method setOptimizationLevel (int)
>>location: class org.mozilla.javascript.tools.debugger.Main
>>           db.setOptimizationLevel(OPTIMIZATION_LEVEL);
>>             ^
>>2 errors
>>
>>Thanks,
>>Tony
>>
>>Tony Edwards wrote:
>>
>>    
>>
>>>Good Morning People,
>>>I downloaded the latest release (version 2.1.2) last night and tried 
>>>to build the war file but it returned the following error:
>>>
>>>      
>>>
>"C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\J
>  
>
>>>avaScriptInterpreter.java:198: cannot resolve symbol
>>>symbol  : method setOptimizationLevel (int)
>>>location: class org.mozilla.javascript.tools.debugger.Main
>>>           db.setOptimizationLevel(OPTIMIZATION_LEVEL);"
>>>Does anyone have any clue as to what I'm missing?
>>>Thanks for your help.
>>>
>>>Tony
>>>      
>>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Problems building 2.1.2

Posted by Joerg Heinicke <jh...@virbus.de>.
Hello Tony,

I guess nobody had such an error, so nobody can help you. The only thing 
I guess is a non-Cocoon Rhino on the classpath.

Chris, can you confirm my guess from a look on the code?

Regards,

Joerg

On 07.11.2003 00:09, Tony Edwards wrote:
> Hello again,
> Still no joy compiling 2.1.2 obtained from cocoon-latest-srs.zip in the 
> downloads section of the web site.
> Previous version built without incident. The difficulty is I'm not a 
> java programmer and I get a little nervous when things don't work 
> straight off the bat as they usually do!
> Can anyone shed some light as to what's happening?
> I'm running JDK 1.4.1 on XP.
> The error I get is this:
> 
> C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\fom\FOM_JavaScriptInterpreter.java:199: 
> cannot resolve symbol
> symbol  : method setOptimizationLevel (int)
> location: class org.mozilla.javascript.tools.debugger.Main
>            db.setOptimizationLevel(OPTIMIZATION_LEVEL);
>              ^
> C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\JavaScriptInterpreter.java:198: 
> cannot resolve symbol
> symbol  : method setOptimizationLevel (int)
> location: class org.mozilla.javascript.tools.debugger.Main
>            db.setOptimizationLevel(OPTIMIZATION_LEVEL);
>              ^
> 2 errors
> 
> Thanks,
> Tony
> 
> Tony Edwards wrote:
> 
>> Good Morning People,
>> I downloaded the latest release (version 2.1.2) last night and tried 
>> to build the war file but it returned the following error:
>> "C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\J
>> avaScriptInterpreter.java:198: cannot resolve symbol
>> symbol  : method setOptimizationLevel (int)
>> location: class org.mozilla.javascript.tools.debugger.Main
>>            db.setOptimizationLevel(OPTIMIZATION_LEVEL);"
>> Does anyone have any clue as to what I'm missing?
>> Thanks for your help.
>>
>> Tony


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Problems building 2.1.2

Posted by Tony Edwards <te...@civica.com.au>.
Hello again,
Still no joy compiling 2.1.2 obtained from cocoon-latest-srs.zip in the 
downloads section of the web site.
Previous version built without incident. The difficulty is I'm not a 
java programmer and I get a little nervous when things don't work 
straight off the bat as they usually do!
Can anyone shed some light as to what's happening?
I'm running JDK 1.4.1 on XP.
The error I get is this:

C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\fom\FOM_JavaScriptInterpreter.java:199: 
cannot resolve symbol
symbol  : method setOptimizationLevel (int)
location: class org.mozilla.javascript.tools.debugger.Main
            db.setOptimizationLevel(OPTIMIZATION_LEVEL);
              ^
C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\JavaScriptInterpreter.java:198: 
cannot resolve symbol
symbol  : method setOptimizationLevel (int)
location: class org.mozilla.javascript.tools.debugger.Main
            db.setOptimizationLevel(OPTIMIZATION_LEVEL);
              ^
2 errors

Thanks,
Tony

Tony Edwards wrote:

>Good Morning People,
>I downloaded the latest release (version 2.1.2) last night and tried to 
>build the war file but it returned the following error:
>"C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\J
>avaScriptInterpreter.java:198: 
>cannot resolve symbol
>symbol  : method setOptimizationLevel (int)
>location: class org.mozilla.javascript.tools.debugger.Main
>            db.setOptimizationLevel(OPTIMIZATION_LEVEL);"
>Does anyone have any clue as to what I'm missing?
>Thanks for your help.
>
>Tony
>
>  
>
>> 
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Problems building 2.1.2

Posted by Tony Edwards <te...@civica.com.au>.
Good Morning People,
I downloaded the latest release (version 2.1.2) last night and tried to 
build the war file but it returned the following error:
"C:\cocoon-2.1.2\src\java\org\apache\cocoon\components\flow\javascript\JavaScriptInterpreter.java:198: 
cannot resolve symbol
symbol  : method setOptimizationLevel (int)
location: class org.mozilla.javascript.tools.debugger.Main
            db.setOptimizationLevel(OPTIMIZATION_LEVEL);"
Does anyone have any clue as to what I'm missing?
Thanks for your help.

Tony

>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org