[opencms-dev] Java class to retrieve html page from VFS

Massimiliano massyc at mclink.it
Mon Nov 3 17:05:02 CET 2003


Thanks Jesus,
I modified my java code and now I obtain as output the XML template code
that contains the source of my HTML file.

This is the output:
<?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>

How can I substitute the template tags with the HTML template source
code to obtain the complete HTML code of my page?

Thanks again.

Massimiliano.

Jesus Montero wrote:

> Hi.
> 
> I think you must write C_VFS_PATH_BODIES constant ( /system/bodies/
> directory by default ). Here a example:
> 
> CmsFile bodyFile = cms.readFile(C_VFS_PATH_BODIES +
>     currentFilelist.substring(1,currentFilelist.length()),newFile);
> bodyFile.setContents(bodyBytes);
> cms.writeFile(bodyFile);
>                                         
> Regards.
> J. Montero
> 
> At 12:53 03/11/2003, you wrote:
> 
>> Hi to all.
>> I'm trying to write a java class to retrieve the content of an HTML page
>> stored in the VFS using che opencms java API.
>>
>> I wrote a class that get the CmsFile content, but the CmsFile object
>> contains an XML descriptor and not the HTML source code.
>>
>> Someone can help me?
>>
>> Thank you in advance and sorry for my poor english.
>>
>> Massimiliano.
>>
>> -----
>> This is the java code I wrote.
>>
>> OpenCms m_openCms;
>> CmsObject m_cms;
>> //A_OpenCms.initVersion(this);
>> 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, C_USER_GUEST, C_GROUP_GUEST,
>> C_PROJECT_ONLINE_ID, null);
>>                         
>>         CmsFile file = m_cms.readFile("/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 is the output:
>>
>> [Resource]:/default/vfs/MyFirstProject/Index.html ID: 913 ParentID: 911
>> , Project=1 , User=2 , Group=2 : Access=rwvrwvr-v- : Resource-type=1 :
>> Locked=-1 : length=379 : state=0
>>
>> <?xml version="1.0" encoding="ISO-8859-1"?>
>> <PAGE>
>>     <class>com.opencms.template.CmsXmlTemplate</class>
>>
>> <masterTemplate>/system/modules/org.opencms.default/templates/empty</masterTemplate>
>>     <ELEMENTDEF name="body">
>>         <CLASS>com.opencms.template.CmsXmlTemplate</CLASS>
>>         <TEMPLATE>/system/bodies/MyFirstProject/index.html</TEMPLATE>
>>     </ELEMENTDEF>
>> </PAGE>
>>
>> _______________________________________________
>> 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)




More information about the opencms-dev mailing list