[opencms-dev] Programatically loading Structured Content

Robert Read r.read at auckland.ac.nz
Tue Nov 14 05:22:14 CET 2006


Hi All,

I am attempting to write an interface that will load data rows from an external system as Structured Content via the OpenCms API.

So far I have done this (the lines prefixed '+' are my actual code lines):

+ CmsDefaultUsers cdu = new CmsDefaultUsers();
+ String guestUser = cdu.getUserGuest();
+ CmsObject cmso = OpenCms.initCmsObject(guestUser);
+ cmso.loginUser("User", "password");
	 :
       :
loop over all rows {
		:
       do stuff to format rows ready to create a resource
		:
		:
       + resource = cmso.createResource(cp.getCatalogueNumber(), 600, content, propertyList);

	 + file = new CmsFile(resource);

	 + file.setContents(content);  // is this required?

	 // persist document as CmsFile to VFS
	 + cmso.writeFile(file);
	
} // end loop


On the line that calls cmso.createResource(...) I get the following exception: 


org.opencms.file.CmsVfsException: Error creating the resource "/ 789A".
	at org.opencms.file.CmsVfsException.createException(CmsVfsException.java:79)
	at org.opencms.db.CmsDbContext.throwException(CmsDbContext.java:213)
	at org.opencms.db.CmsDbContext.report(CmsDbContext.java:197)
	at org.opencms.db.CmsSecurityManager.createResource(CmsSecurityManager.java:1094)
	at org.opencms.file.types.A_CmsResourceType.createResource(A_CmsResourceType.java:291)
	at org.opencms.file.types.CmsResourceTypeXmlContent.createResource(CmsResourceTypeXmlContent.java:110)
	at org.opencms.file.CmsObject.createResource(CmsObject.java:621)
	at nz.ac.auckland.onlinecalendar.util.Loader.load(Loader.java:102)
	at nz.ac.auckland.onlinecalendar.util.Loader.<init>(Loader.java:32)
	at org.apache.jsp.course_005fload_005faction_jsp._jspService(course_005fload_005faction_jsp.java:44)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
	at 

org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.opencms.file.CmsVfsException: This operation is not allowed in the "Online" project.
	at org.opencms.db.CmsSecurityManager.checkOfflineProject(CmsSecurityManager.java:533)
	at org.opencms.db.CmsSecurityManager.createResource(CmsSecurityManager.java:1091)
	... 26 more



Right near the bottom of the stack trace it says 'This operation is not allowed in the "Online" project.' - which makes perfect sense.  

So I am thinking...
1) I need to create an "Offline Project" to work on
2) create my resource in that project 


Does anyone have any simple ideas of how to achieve this or what steps I may have missed?

Cheers,
Robert


Robert Read
Analyst-Programmer
Group Applications
Information Technology Systems & Services
University of Auckland
Telephone: +64 9 373 7599 ext 82475
 
Email: r.read at auckland.ac.nz
Web:  http://www.auckland.ac.nz/

________________________________________
The information contained in this email message is intended only for the named recipient(s). 
If you are not the intended recipient(s), you must not peruse, use, disseminate, distribute or copy this email or attachments. 
If you receive this email in error please immediately notify the sender and delete the original message.




More information about the opencms-dev mailing list