[opencms-dev] Using OpenCms objects in external Java application?

Jonathan Woods jonathan.woods at scintillance.com
Fri Oct 6 09:37:57 CEST 2006


Andreas -

Yes, it's all possible.  You can access multiple instances of OpenCms in
this way by ensuring that for each one you specify the location of the
instance's WEB-INF folder.  The fact that you weren't doing that for your
single instance may explain the NullPointerException - not sure.

Anyway, a good place to start is in the source code of CmsShell.  CmsShell
is an OpenCms class which allows you to create command shell which accepts a
number of scripting-like commands mapped directly to core OpenCms methods
(e.g. on CmsObject).  I don't think using a shell-like environment is
appropriate here, even though it does allow you to manipulate the VFS,
because you already have a full-blown Java environment which is capable of
much more.  So instead of using CmsShell for its shell-like capabilities,
you could hack some source code from it to do what you want.

Take a look at the constructor CmsShell(String webInfPath, String
servletMapping, String defaultWebAppName, String prompt, I_CmsShellCommands
additionalShellCommands).  Forgetting about all the message bundle stuff,
you should be able to crib from this code in your own Java class, starting
with your own values for webInfPath, servletMapping and defaultWebAppName.

If you haven't got the source code from anywhere yet, it's all over the web
and downloadable from opencms.org.  You can also see it at Google's sexy new
(but not yet extraordinarily useful) source code search tool,
www.google.com/codesearch.  The URL I get is 

http://www.google.com/codesearch?q=show:NJ4tiUK11-E:FjoCM2e3bdg:7YXjTsMx0L4&
sa=N&ct=rd&cs_p=http://www.opencms.org/export/download/opencms/opencms_6.2.2
_src.zip&cs_f=src/org/opencms/main/CmsShell.java

Jon
 

-----Original Message-----
From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of Andreas Haumer
Sent: 05 October 2006 19:11
To: The OpenCms mailing list
Subject: [opencms-dev] Using OpenCms objects in external Java application?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

I'm working on a Java application which periodically generates a HTML file
which I then automatically want to place in some OpenCMS VFS folder. This
Java application is executed outside any servlet container or application
server context, i.e. it's a typical Unix application running on the same
Linux box as OpenCms.

The OpenCMS API doc (JavaDoc) tells me, that this should be possible with an
object of class org.opencms.file.CmsObject

The JavaDoc explains how to get a CmsObject using OpenCms.initCmsObject()
and all methods available with this object.

The idea is at follows:
[...]
// prepare the new HTML data as byte[] array

// get the CmsObject
CmsObject cms = OpenCms.initCmsObject("Guest");

// log into OpenCms
cms.loginUser(username, password);

// set project, upload and publish the new file, etc.
cms.createResource();
cms.unlockResource();
cms.publishResource();
[...]

This all would be quite fine, alas I already get a NullPointerException in
OpenCms.initCmsObject()  :-(

What am I missing here?


Also, on some installations we might have several OpenCms instances running
on the same servlet container (as different webapps). Each OpenCms instance
uses it's own database.
How can I select a specific OpenCms instance, i.e. a specific OpenCms VFS,
using the OpenCms API in my Java application?

Is this possible at all?

Thanks!

- - andreas

- --
Andreas Haumer                     | mailto:andreas at xss.co.at
*x Software + Systeme              | http://www.xss.co.at/
Karmarschgasse 51/2/20             | Tel: +43-1-6060114-0
A-1100 Vienna, Austria             | Fax: +43-1-6060114-71
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFJUq0xJmyeGcXPhERAjDNAJ0VO6Q8NXcV1CCcvc7PtsJE1yJLRACfan+5
lb58SsfCgomVkxkaPLZnZGU=
=ivaR
-----END PGP SIGNATURE-----

_______________________________________________
This mail is sent to you from the opencms-dev mailing list To change your
list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev





More information about the opencms-dev mailing list