[opencms-dev] Creating Java Bean Classes....

srinivas voleti srini_2105 at hotmail.com
Thu Oct 30 10:03:02 CET 2003


Hi All,

I could able to create a Folder programatically in OpenCms by creating a JSP 
file in OpenCms and calling that JSP from custom program.

Is it not possible to write a bean class outside OpenCms and call the bean. 
I have tried it out and got java.lang.NullPointerException at 
cmsObject.loginUser("Admin", "admin").

My code snippet is as follows::::

Waiting for the earliest reply.


package com.trx.kms.hierarchy;

import com.opencms.core.*;
import com.opencms.flex.jsp.*;
import com.opencms.file.*;
/**
* @author voleti
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class CreateFolder {

	public String createFol(String parentFolder, String folderName) {

	// initialise Cms Action Element
	// com.opencms.flex.jsp.CmsJspActionElement cms = new 
CmsJspActionElement(pageContext, request, response);
	com.opencms.flex.jsp.CmsJspActionElement cms = new CmsJspActionElement();

	// Collect the objects required to access the OpenCms VFS from therequest
	com.opencms.file.CmsObject cmsObject = cms.getCmsObject();

//	   The folder where to create the new folder in
//	   User / Password to use, must have permissions to create a folder in 
the parent folder
	String username = "Admin";
	String password = "admin";

	boolean login = false;

	try {
//	   Log in the user
		cmsObject.loginUser("Admin", "admin");
		login = true;
	} catch (Exception e) {
		System.out.println("OpenCms was unable to login the user, possibly because 
of password error<br>"+e.toString());
	}

	if (login) {
		int projectIdToUse = 7;

		try {
			cmsObject.getRequestContext().setCurrentProject(projectIdToUse);
			String createdFolder = parentFolder.trim() + folderName.trim();

			cmsObject.createFolder(parentFolder, folderName);
			cmsObject.chgrp(createdFolder, "designer", true);
			cmsObject.unlockResource(createdFolder);
			cmsObject.publishResource(createdFolder);
		//if no exception in thrown the folder was created
			System.out.println("Sucessfully created folder " + parentFolder + 
folderName);
		} catch (Exception e) {
			System.out.println("OpenCms was unable to create the 
folder<br>"+e.toString());
		}
	}

	return "";
	}
}


Thanks,
Srini.

_________________________________________________________________
Access Hotmail from your mobile now. 
http://server1.msn.co.in/sp03/mobilesms/ Click here.




More information about the opencms-dev mailing list