<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
<p class="ecxMsoNoSpacing">Hi,<br>
<br>
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.</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing">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.</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing">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.</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing">By following the changes described here:</p>
<p class="ecxMsoNoSpacing">http://mail.opencms.org/pipermail/opencms-dev/2009q3/032605.html<br>
I was able to allow the "CustomSourceSelectWidget " to read from the
currently open file.</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing">After adding in an element of type
OpenCmsVfsFile I then
used it to place the location of the external file used by the
"CustomSourceSelectWidget". </p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing">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:</p>
<p class="ecxMsoNoSpacing"><layout element="Role" widget="
CustomSourceSelectWidget
"
configuration="source=path.to.class.widgets.sources.ContentFieldListDS'|contenttype='AdminRoles'|location='TypesOfRolesFileLocation/'|fieldpath='/Role'|fieldname='/Name'"
/></p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing">An example of what the getValues() function
now looks
like:</p>
<p class="ecxMsoNoSpacing">/**</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>* Returns the list
of Values for our data source</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>*/</p>
<p class="ecxMsoNoSpacing">public List getValues(CmsObject cms,
I_CmsWidgetParameter
param) {</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>ArrayList<SelectOptionValue> lstVals = new
ArrayList<SelectOptionValue>();</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing"><span style=""> </span>if (false ==
isConfigValid()) {</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>lstVals.add(new SelectOptionValue("Missing or invalid
configuration
options!", "null"));</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>} else {</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>// read the
resource containing the values, in the specified location</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>try {</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>I_CmsXmlContentValue contentValue = ((I_CmsXmlContentValue)
param);</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing"><span style=""> </span>// Get
Locale</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>Locale
defaultLocale = OpenCms.getLocaleManager().getDefaultLocale();</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>Locale
dialogContentLocale = contentValue.getLocale();</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>Locale
locale = null == dialogContentLocale ? defaultLocale :
dialogContentLocale;</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing"><span style=""> </span>// Read
opened Document to get the Node that specifies the file</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>I_CmsXmlDocument contentTest = contentValue.getDocument();</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>String
FileLocation
= contentTest.getStringValue(cms, m_strLocation, locale);</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>CmsResource res = cms.readResource(FileLocation);</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>//
check it against the desired type</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>if
(m_strContentType.equalsIgnoreCase(OpenCms.getResourceManager().getResourceType(res).getTypeName()))
{</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>//
retrieve the values</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms,
cms.readFile(res));</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing"><span style=""> </span>//
Get the values using the specified fieldpath and locale</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>List lVals = content.getValues(m_strFieldpath, locale);</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>Iterator j = lVals.iterator();</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>String path, value = "";</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>while (j.hasNext()) {</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>I_CmsXmlContentValue iVal = (I_CmsXmlContentValue) j.next();</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>path = iVal.getPath();</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>value = content.getStringValue(cms, path + m_strFieldname,
locale);</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>// add the value</p>
<p class="ecxMsoNoSpacing"><span style="">
</span>lstVals.add(new SelectOptionValue(value, value));</p>
<p class="ecxMsoNoSpacing"><span style=""> </span>}</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing">...</p>
<p class="ecxMsoNoSpacing"> </p>
<p class="ecxMsoNoSpacing">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.</p>
<p class="ecxMsoNoSpacing"><br></p>Hopefully that might help you in your
situation.<br><br>
<p class="ecxMsoNoSpacing">Graeme</p>
<br><br>>
Subject: Re: [opencms-dev] Get file currently being edited<br>>
From: ruben@disk0.de<br>> Date: Fri, 12 Mar 2010 10:00:58 +0800<br>>
To: opencms-dev@opencms.org; coolkidd3@hotmail.com<br>> <br>> <br>>
hi,<br>> <br>> i did a similar thing here ... and one thing would
be to get the path <br>> from a property. in my case:<br>> <br>>
- i have a content type that includes a field called "headline style"<br>>
- i have a content type that defines font styles<br>> - i have a
property on called "_fontstyles"<br>> <br>> for editing:<br>> -
i have a custom source select widget that does a lookup on the <br>>
property, then looks into the font style content xml and displays a <br>>
list of available font styles to select from<br>> <br>> for
rendering:<br>> - the font renderer does the same thing to look up
the right font <br>> style and render the text accordingly<br>> <br>>
now, this doesn't help with the deletion thing, but it will a.) give <br>>
you more flexibility, because you can define the property on higher-up
<br>> folders and override it below and b.) you can get rid of
hardcoding <br>> the path.<br>> <br>> hth<br>> <br>> .rm<br>>
<br>> <br>> <br>> On 12 Mar 2010, at 9:44 AM, Graeme Kidd
wrote:<br>> <br>> ><br>> > Another alternative that might
work is if the data is not placed in <br>> > a separate file but
instead placed in the same file, under a <br>> > separate tab.
Would I then be able to create a data source class <br>> > that
could read from the file that is currently open. This should <br>>
> mean I no longer need to specify a file location in the schema
since <br>> > I just need to tell it to read data from itself.<br>>
><br>> > My first hurdle is getting at the currently opened
file, I tried <br>> > getURI in the CmsRequestContex class but it
simply returned the <br>> > editor JSP found in the browser
address bar. Does anyone know what <br>> > part of the API would
be able to get the current file being edited?
<br> <br /><hr />Get a new e-mail account with Hotmail - Free. <a href='http://clk.atdmt.com/UKM/go/197222280/direct/01/' target='_new'>Sign-up now.</a></body>
</html>