[opencms-dev] How to add a new resource type

Olli Aro olli_aro at yahoo.co.uk
Sun Feb 15 13:11:01 CET 2004


Hi Matt,

This was the conclusion I got to as well, when trying to do this on Friday.
However I did get a step further. I did managed to create my own types. The
process I followed was as below: - 

1) Add our new type in register.xml

2) Create your new type class extending the CmsResourceTypePlain, but as
part of the package com.opencms.file - so that the protected methods work:)

This approach allows me to create new files based on my resource type and
overwrite all methods for locking, copying, moving... However it does not
allow me to include the new resource type as part of the workplace view and
customize the pop-up menu accordingly. I have a feeling that the resource
types are hardcoded somewhere else for the workplace presentation:(

I have come up with another idea that I will try on Monday. The pop-up menu
is generated by a JavaScript file, so it should be possible to modify this
with a JSP template and generate the menu based on resource properties. So
the idea is to initiate content_type property, when creating the file and
then the JSP template will read that property and generate the pop-up
accordingly. 

I will let you know, if this hack works;D

Olli  

-----Original Message-----
From: opencms-dev-admin at opencms.org [mailto:opencms-dev-admin at opencms.org]
On Behalf Of M Butcher
Sent: 13 February 2004 19:33
To: opencms-dev at opencms.org
Subject: Re: [opencms-dev] How to add a new resource type


I should have been more specific.... Here's the code (with imports and 
comments cut out):

class GenericXmlResourceType extends CmsResourceTypePlain {

     public static final String C_TYPE_RESOURCE_NAME = "GenericXML";

      public CmsResource createResource(CmsObject cms, String name, Map 
props,
             byte[] contents, Object param)
             throws CmsException {
         CmsResource res =
             cms.doCreateFile(name, contents, C_TYPE_RESOURCE_NAME, props);
         cms.lockResource(name);
         cvs.writerProperty(name, C_PROPERTY_EXPORT, "true");
         return res;
      }
}

As you can see, it extends com.opencms.file.CmsResourceTypePlain. The 
problem is, the cms.doCreateFile() method is also protected. Since 
CmsObject is in the same package as CmsResourceTypePlain, it works. 
However, my module is in a different package.

Interestingly enough, if I remove the createResource method, it 
compiles. Then, of course, I get a runtime error (access violation) when 
the dynamic classloader loads it at startup. Besudes that, it kinda 
makes it difficult to do anything new when I can't override any of the 
methods that get called. ;-)

I've since moved on to creating a ContentDefinition, but I'm really 
unhappy with that route, as it makes life difficult for the editor (and 
me). In the end, I'll probably hack something together using Plain 
documents.

I'm not really interested in forking the core code, but I am interested 
in finding another way around the problem. Thanks for your suggestion -- 
let me know if you see a way out of this problem.

Matt

reed.mccauley at us.abb.com wrote:
> 
> 
> 
> 
> Matt,
> Have you tried extending the class to get access to these protected
> methods and add new ones?
> Thanks,
> Reed
> 
> 
> Message from M Butcher <mbutcher at grcomputing.net>@opencms.org received
> on
> 02/13/2004 09:40 AM
> 
> 02/13/2004 09:40 AM
> 
> 
> 
> M Butcher <mbutcher at grcomputing.net>@opencms.org
> 
> Please respond to opencms-dev at opencms.org
> Sent by opencms-dev-admin at opencms.org
> 
> 
> 
>         To:     opencms-dev at opencms.org
>         cc:
>         Subject:        Re: [opencms-dev] How to add a new resource type
> 
> 
> 
> I worked on this for a long time -- I wanted to create a module that
> provided generic XML and XSLT types. Unfortunately, too many of the
> important methods are 'protected', and I never figured out a way to add
> one without getting either compile errors or access violations.
> 
> If anyone else knows of a workaround, please tell me.
> 
> Matt
> 
> Olli Aro wrote:
> 
>>Hi all,
>>
>>Does anyone know if there is a standard way to add a new resource type
> 
> as
> 
>>part of the explorer view? Maybe similar to the ContentDefinitions
> 
> with
> the
> 
>>back office modules. I would like to add a new resource type similar
> 
> to
> the
> 
>>standard text resource, but the edit option would go to my JSP
> 
> template.
> 
>>Olli
>>
>>---
>>Outgoing mail is certified Virus Free.
>>Checked by AVG anti-virus system (http://www.grisoft.com).
>>Version: 6.0.580 / Virus Database: 367 - Release Date: 06/02/2004
>>
>>
>>_______________________________________________
>>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
> 
> 
> _______________________________________________
> 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
> 
> 
> (See attached file: C.htm)
> 
> 
> ------------------------------------------------------------------------
> 
> 
> Matt,
> Have you tried extending the class to get access to these protected 
> methods and add new ones?
> Thanks,
> Reed
> 
> 
> Message from M Butcher <mbutcher at grcomputing.net>@opencms.org received 
> on 02/13/2004 09:40 AM
> 	02/13/2004 09:40 AM
> 
> 		*M Butcher <mbutcher at grcomputing.net>@opencms.org*
> 
> Please respond to opencms-dev at opencms.org
> Sent by opencms-dev-admin at opencms.org
> 
> 
> 
> 	        To:        opencms-dev at opencms.org
>         cc:        
>         Subject:        Re: [opencms-dev] How to add a new resource type
> 
> 
> 
> 
> 
> I worked on this for a long time -- I wanted to create a module that
> provided generic XML and XSLT types. Unfortunately, too many of the
> important methods are 'protected', and I never figured out a way to add
> one without getting either compile errors or access violations.
> 
> If anyone else knows of a workaround, please tell me.
> 
> Matt
> 
> Olli Aro wrote:
>  > Hi all,
>  >
>  > Does anyone know if there is a standard way to add a new resource type
as
>  > part of the explorer view? Maybe similar to the ContentDefinitions 
> with the
>  > back office modules. I would like to add a new resource type similar 
> to the
>  > standard text resource, but the edit option would go to my JSP
template.
>  >
>  > Olli
>  >
>  > ---
>  > Outgoing mail is certified Virus Free.
>  > Checked by AVG anti-virus system (http://www.grisoft.com).
>  > Version: 6.0.580 / Virus Database: 367 - Release Date: 06/02/2004
>  >
>  >
>  > _______________________________________________
>  > 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
> 
> _______________________________________________
> 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
> 

_______________________________________________
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

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 06/02/2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 06/02/2004
 




More information about the opencms-dev mailing list