[opencms-dev] Java class to translate XML code contained in the VFS in HTML page source code

Stephan Hartmann beffe at beffe.de
Tue Nov 4 22:02:01 CET 2003


Hi Massimiliano,

the launcher mechanism calls a getContent method of an instance of
com.opencms.template.CmsXmlTemplate and writes the result (a byte[])
directly into the http response.
You should try something like this:

CmsXmlTemplate cxl = new CmsXmlTemplate();
byte[] result = cxl.getContent(cmso, "/vfs/path/to/file", null, new
Hashtable(), null);

Bye,
Stephan

----- Original Message -----
From: "Massimiliano" <massyc at mclink.it>
To: <opencms-dev at opencms.org>
Sent: Tuesday, November 04, 2003 3:36 PM
Subject: Re: [opencms-dev] Java class to translate XML code contained in the
VFS in HTML page source code


> Thanks to all for help me!
> I read the com.opencms.launcher.CmsXmlLauncher javadoc documentation, I
> don't understand exactly how to use this class to parse the template.
> There are only three public methods in the class and only initLaunch()
> seems to be userful to start parsing.
> My question is: the initLaunch method returns void, how can I got the
> generated html?
> Notice that the class I'm writing will not be used in the opencms webapp
> but in another one.. Is this scenario possible?
>
> Thank you again and sorry for my poor english.
>
> Massimiliano.
>
>
> Olli Aro wrote:
>
> > How about calling the page via HttpURLConnection? I know it goes through
the
> > web server that way, not directly from OpenCms API, but local web call
> > should not be too expensive... Other option would be to call directly
> > com.opencms.launcher.CmlXmlLauncher class - this is the class that
parses
> > the templates and content together.
> >
> > Regards,
> >
> > Olli
> >
> >
> >
> >>-----Original Message-----
> >>From: opencms-dev-admin at opencms.org
> >>[mailto:opencms-dev-admin at opencms.org]On Behalf Of Kwok Peng Tuck
> >>Sent: 04 November 2003 08:43
> >>To: opencms-dev at opencms.org
> >>Subject: Re: [opencms-dev] Java class to translate XML code contained in
> >>the VFS in HTML page source code
> >>
> >>
> >>Hmm, maybe you can transform it to html by writing  your own xslt ?
> >>Just a suggestion.
> >>
> >>Massimiliano wrote:
> >>
> >>
> >>>As I post yesterday I'm writing a java class to retrieve HTML pages
> >>
> >>>from the VFS.
> >>
> >>>The result obtained yesterday is this XML template that contains the
> >>>text I wrote in the page:
> >>>
> >>><?xml version="1.0" encoding="ISO-8859-1"?>
> >>><XMLTEMPLATE>
> >>>   <TEMPLATE><![CDATA[<p><strong>Questa è la homepage del Mio Primo
> >>>progetto OpenCMS!</strong></p>]]></TEMPLATE>
> >>>   <edittemplate><![CDATA[<P><STRONG>Questa è la homepage del Mio Primo
> >>>progetto
> >>>OpenCMS!</STRONG></P>]]></edittemplate>
> >>></XMLTEMPLATE>
> >>>
> >>>The XML contains the text I wrote in the page, but what I need is the
> >>>complete html code like the code generated by opencms when I call the
> >>>page from the web browser.
> >>>How can I translate the XML code to obtain the complete HTML code using
> >>>the openCMS Java API?
> >>>
> >>>Thank you again.
> >>>
> >>>Massimiliano.
> >>>
> >>>------
> >>>This is my java source code:
> >>>
> >>>OpenCms m_openCms;
> >>>CmsObject m_cms;
> >>>
> >>>try {
> >>> CmsBase.setBasePath("c:\\Program Files\\Apache Group\\Tomcat
> >>>4.1\\webapps\\opencms\\WEB-INF");
> >>> String propsPath = CmsBase.getPropertiesPath(true);
> >>> System.out.println("%%% props: " + propsPath);
> >>> Configurations conf = new Configurations(new
> >>>ExtendedProperties(propsPath));
> >>> m_openCms = new OpenCms(conf);
> >>> m_cms = new CmsObject();
> >>>
> >>> //log in default user.
> >>> m_openCms.initUser(m_cms, null, null, CmsXmlTemplate.C_USER_GUEST,
> >>>CmsXmlTemplate.C_GROUP_GUEST, CmsXmlTemplate.C_PROJECT_ONLINE_ID,
null);
> >>>
> >>> CmsFile file =
> >>
> >>m_cms.readFile(CmsWorkplaceDefault.C_VFS_PATH_BODIES +
> >>
> >>>"MyFirstProject/Index.html");
> >>> if ( file != null )
> >>> {
> >>> System.out.println(file);
> >>>
> >>> byte [] fileContent = file.getContents();
> >>>
> >>> ByteArrayOutputStream bA = new ByteArrayOutputStream();
> >>> bA.write(fileContent);
> >>> System.out.println (bA.toString());
> >>> }
> >>> else
> >>> throw new NullPointerException ("Oggetto file
> >>
> >>nullo");
> >>
> >>
> >>> }
> >>> catch(Exception exc) {
> >>> exc.printStackTrace();
> >>> }
> >>>
> >>>_______________________________________________
> >>>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
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>_______________________________________________
> >>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
> >>---
> >>Incoming mail is certified Virus Free.
> >>Checked by AVG anti-virus system (http://www.grisoft.com).
> >>Version: 6.0.532 / Virus Database: 326 - Release Date: 27/10/2003
> >>
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.532 / Virus Database: 326 - Release Date: 27/10/2003
> >
> > _______________________________________________
> > 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
> >
> >
>
> --
>
> Il Sopra e il Sotto sono concetti relativi...
> relativi alla lotta che bisogna fare per sovvertirli
>
> (Subcomandante Marcos)
>
> _______________________________________________
> 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
>




More information about the opencms-dev mailing list