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

Jesus Montero jmontero at jccm.es
Mon Nov 3 13:49:01 CET 2003


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20031103/dd322ebc/attachment.htm>


More information about the opencms-dev mailing list