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

Massimiliano massyc at mclink.it
Mon Nov 3 13:24:01 CET 2003


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>




More information about the opencms-dev mailing list