[opencms-dev] New API and CmsExceptions in Version 6.x..?
Achim Westermann
Achim.Westermann at gmx.de
Wed Dec 14 19:32:42 CET 2005
Hi Chris,
in OpenCms 6.0 CmsException has been localized. It only accept some
CmsMesageContainer instance. You could try to throw a normal java
exception if the integration allows.
Or you could get a message container:
1 Create a messages.properties file within your package.
2 Copy one of the various Messages.java to your package.
3 Delete all the constants for Messages and define your message key like
the ones you deleted.
4 Change the bundle name constant to <your package>/messages.
5 Create an entry in your messages.properties matching the constant
value you defined and the value "Cannot create XSLT transformer.".
6 Do steps 3,5 for the 2nd exception.
7 In the code where you throw the CmsException write:
throw new CmsException(Messages.get().container(Messages.<constantName>,
<Message argument>, <Message argument>,...));
where Message argument are the arguments that match the values to fill
in your messages.properties values "{0}", "{1}",...
In your case there are no message arguments to implant to the exception
messages.
Search the OpenCms codebase for the points where exceptions are thrown.
happy coding,
Achim
Chris Stephens wrote:
> Hi folks,
>
> I am trying to port some of Matt Butcher's code from "Building Websites
> with OpenCms" (which was written for Version 5.x) to Version 6.0 code.
>
> A lot of the API has changed and I have managed to get that all fine
> (as far as I can tell) but the code has problems with CmsExceptions.
>
> Specifically, I get this when I compile:
>
> CmsXslTransformer.java:59: cannot resolve symbol
> symbol : constructor CmsException
> (java.lang.String,javax.xml.transform.TransformerConfigurationException)
> location: class org.OpenCms.main.CmsException
> throw new CmsException( "Cannot create XSLT transformer.", tce );
> ^
> CmsXslTransformer.java:61: cannot resolve symbol
> symbol : constructor CmsException
> (java.lang.String,javax.xml.transform.TransformerException)
> location: class org.OpenCms.main.CmsException
> throw new CmsException( "Cannot use XSLT transformer.", te );
> ^
> 2 errors
>
>
> The relvant bits of code are as follows:
>
> import org.OpenCms.main.CmsException;
>
> and
>
> public CmsXslTransformer( String xsltStylesheet, CmsObject cms )
> throws CmsException {
> this.cms = cms;
> try {
> TransformerFactory tf = TransformerFactory.newInstance();
> CmsFile xsltFile = cms.readFile( xsltStylesheet );
> Source s = this.getCmsFileSource( xsltFile );
> this.transformer = tf.newTransformer( s );
> } catch ( TransformerConfigurationException tce ) {
> throw new CmsException( "Cannot create XSLT transformer.", tce );
> } catch ( TransformerException te ) {
> throw new CmsException( "Cannot use XSLT transformer.", te );
> }
> }
>
>
> Can anyone help me? I've tried to glean how exceptions are done in 6.0
> from the Javadoc but it's not coming clear to me yet...
>
> Thanks in advance,
>
> Chris
> PS the book is fantastic even though it's a version old. I hope Matt
> does a new version for 6 - I will buy it immediately when he does...
> Thanks, Matt!
>
>
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev
>
>
--
---------------------------------
Achim Westermann
Martinsfeld 32
50676 Köln
Telefon: +49(0)221/7886546
Mobil: +49(0)179/7627762
E-mail: Achim.Westermann at gmx.de
More information about the opencms-dev
mailing list