[opencms-dev] Get file currently being edited

Graeme Kidd coolkidd3 at hotmail.com
Mon Apr 19 01:52:03 CEST 2010


Hi,



Just thought I would update you that I managed to customise the 
"CustomSourceSelectWidget"
further so it could read from an external file, where the location of 
that file was specified
from inside the same XML document.

 

For example you may want to display a select 
box
containing data from another filse stored somewhere else on the VFS. In
the version given in the "OpenCms 7 Development" book you specify
this external file via the widgets configuration string in the XSD file.

 

If the external file is then made available 
to a lot of
users you run the risk of it being moved, deleted or renamed. In all
cases the XSD file will need to be updated to point to the new location.

 

By following the changes described here:

http://mail.opencms.org/pipermail/opencms-dev/2009q3/032605.html

I was able to allow the "CustomSourceSelectWidget " to read from the
currently open file.

 

After adding in an element of type 
OpenCmsVfsFile I then
used it to place the location of the external file used by the 
"CustomSourceSelectWidget". 

 

In the configuration string I now specify the
 element
where the location of the external file is stored.
Then the path and name of the field that needs to be read from the 
external
file:

<layout element="Role" widget=" 
CustomSourceSelectWidget
" 
configuration="source=path.to.class.widgets.sources.ContentFieldListDS'|contenttype='AdminRoles'|location='TypesOfRolesFileLocation/'|fieldpath='/Role'|fieldname='/Name'"
/>

 

An example of what the getValues() function 
now looks
like:

/**

 * Returns the list
of Values for our data source

 */

public List getValues(CmsObject cms, 
I_CmsWidgetParameter
param) {

   
ArrayList<SelectOptionValue> lstVals = new 
ArrayList<SelectOptionValue>();

 

    if (false ==
isConfigValid()) {

       
lstVals.add(new SelectOptionValue("Missing or invalid 
configuration
options!", "null"));

    } else {

        // read the
resource containing the values, in the specified location

        try {

           
I_CmsXmlContentValue contentValue = ((I_CmsXmlContentValue) 
param);

 

            // Get
Locale

            Locale
defaultLocale = OpenCms.getLocaleManager().getDefaultLocale();

            Locale
dialogContentLocale = contentValue.getLocale();

            Locale
locale = null == dialogContentLocale ? defaultLocale : 
dialogContentLocale;

 

            // Read
opened Document to get the Node that specifies the file

           
I_CmsXmlDocument contentTest = contentValue.getDocument();

            String 
FileLocation
= contentTest.getStringValue(cms, m_strLocation, locale);

           
CmsResource res = cms.readResource(FileLocation);

            //
check it against the desired type

            if
(m_strContentType.equalsIgnoreCase(OpenCms.getResourceManager().getResourceType(res).getTypeName()))
{

                //
retrieve the values

               
CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms,
cms.readFile(res));

 

                //
Get the values using the specified fieldpath and locale

               
List lVals = content.getValues(m_strFieldpath, locale);

               
Iterator j = lVals.iterator();

               
String path, value = "";

               
while (j.hasNext()) {

                   
I_CmsXmlContentValue iVal = (I_CmsXmlContentValue) j.next();

                   
path = iVal.getPath();

                   
value = content.getStringValue(cms, path + m_strFieldname, 
locale);

                   
// add the value

                   
lstVals.add(new SelectOptionValue(value, value));

                }

 

...

 

Now that the file is specified via an 
OpenCmsVfsFile
widget I can add a relation  in XSD file so that if the file is moved or
 renamed the XML is
updated automatically. Then if someone tries to delete the external file
 they
will at least get a warning.


Hopefully that might help you in your
 situation.



Graeme



>
 Subject: Re: [opencms-dev] Get file currently being edited
> 
From: ruben at disk0.de
> Date: Fri, 12 Mar 2010 10:00:58 +0800
>


 To: opencms-dev at opencms.org; coolkidd3 at hotmail.com
> 
> 
>


 hi,
> 
> i did a similar thing here ... and one thing would
 be to get the path  
> from a property. in my case:
> 
>


 - i have a content type that includes a field called "headline style"
>


 - i have a content type that defines font styles
> - i have a 
property on called "_fontstyles"
> 
> for editing:
> -
 i have a custom source select widget that does a lookup on the  
>


 property, then looks into the font style content xml and displays a  
>


 list of available font styles to select from
> 
> for 
rendering:
> - the font renderer does the same thing to look up 
the right font  
> style and render the text accordingly
> 
>


 now, this doesn't help with the deletion thing, but it will a.) give  
>


 you more flexibility, because you can define the property on higher-up 
 
> folders and override it below and b.) you can get rid of 
hardcoding  
> the path.
> 
> hth
> 
> .rm
>


 
> 
> 
> On 12 Mar 2010, at 9:44 AM, Graeme Kidd 
wrote:
> 
> >
> > Another alternative that might
 work is if the data is not placed in  
> > a separate file but
 instead placed in the same file, under a  
> > separate tab. 
Would I then be able to create a data source class  
> > that 
could read from the file that is currently open. This should  
> 
> mean I no longer need to specify a file location in the schema 
since  
> > I just need to tell it to read data from itself.
>


 >
> > My first hurdle is getting at the currently opened 
file, I tried  
> > getURI in the CmsRequestContex class but it
 simply returned the  
> > editor JSP found in the browser 
address bar. Does anyone know what  
> > part of the API would 
be able to get the current file being edited?


     		 	   		  
 		 	   		  
_________________________________________________________________
http://clk.atdmt.com/UKM/go/195013117/direct/01/
We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20100419/b51db4c6/attachment.htm>


More information about the opencms-dev mailing list