[opencms-dev] Inherit a parameter over several pages?

Alexander Kandzior alex at opencms.org
Sat Dec 21 18:45:04 CET 2002


Ivan,

that excat functionality is in fact a core feature now (at least since
5.0rc1, maybe it also was in 5.0b2 already, I forgot). 

There are now 3 methods

CmsObject.readProperty(String resourceName, String propertyName) 
CmsObject.readProperty(String resourceName, String propertyName, boolean
search)
CmsObject.readProperty(String resourceName, String propertyName, boolean
search, String defaultValue)

The JavaDoc of this methods has all the information, but basically you
can just set "search" to "true" and the CmsObject will try to "search
upwards" for the selected property. 

Best Regards,
Alex.

Alexander Kandzior
OpenCms Group / Alkacon Software

> -----Original Message-----
> From: owner-opencms-dev at www.opencms.org 
> [mailto:owner-opencms-dev at www.opencms.org] On Behalf Of Ivan Biddles
> Sent: Saturday, December 21, 2002 6:22 PM
> To: opencms-dev at www.opencms.org
> Subject: RE: [opencms-dev] Inherit a parameter over several pages?
> 
> 
> Hi Thomas,
> 
> I had this same issue and so I wrote a getInheritedProperty 
> method which goes on up the tree until it finds a defined 
> value. I added the capability of saying "none" at any level 
> in the tree to override a parameter defined at a parent level.
> 
> I have pasted the code below, with my custom logging code removed.
> 
> I don't know if this is the best way to do it but it definitely works.
> 
> Best wishes,
>               Ivan
> 
> (The StringHelper.isNullOrEmpty method is just a utility 
> method that returns true if the supplied string is either 
> null or an empty string. SITE_ROOT is a constant that defines 
> how far up the tree I want to go.
> 
> -------------------------------------------------------------------
>    public  static  final  String  SITE_ROOT     = "/myroot/";
> 
>    private  String  getParentUri (
>                                   String  aRequestedUri
>                                  )
>    {
>       String myParentUri     = "";
>       int    myLength        = aRequestedUri.length ();
>       int    myLastDelimiter = (aRequestedUri.substring (0, 
> (myLength -
> 1))).lastIndexOf ("/");
> 
>       if (myLastDelimiter >= 0) {
>          myParentUri = aRequestedUri.substring (0, (myLastDelimiter +
> 1));
>          if (myParentUri.endsWith (SITE_ROOT)) {
>             myParentUri = "";
>          }
>       }
>       return (myParentUri);
>    }
>         
>    public  String  readProperty (
>                                  CmsObject  aCmsObject,
>                                  String     aRequestedUri,
>                                  String     aPropertyKey
>                                 )
>    {
>       String myValue = null;
>       try {
>          myValue = aCmsObject.readProperty (aRequestedUri,
> aPropertyKey);
>       }
> 
>       catch (Throwable myThrowable) {
> //       LOG
>       }
>       return ((myValue == null) ? "" : myValue);
>    }
> 
>    public  String  getProperty (
>                                 CmsObject  aCmsObject,
>                                 String     aPropertyKey
>                                )
>    {
>       String myRequestedUri = (aCmsObject.getRequestContext ()).getUri
> ();
>       String myValue = readProperty (aCmsObject, myRequestedUri,
> aPropertyKey);
>       return ((myValue == null) ? "" : myValue);
>    }
> 
>    public  String  getInheritedProperty (
>                                          CmsObject  aCmsObject,
>                                          String     aPropertyKey
>                                         )
>    {
>       String myRequestedUri = (aCmsObject.getRequestContext ()).getUri
> ();
>       String myValue        = null;
>       while (StringHelper.isNullOrEmpty (myValue)) {
>          myValue = readProperty (aCmsObject, myRequestedUri,
> aPropertyKey);
>          if (StringHelper.isNullOrEmpty (myValue)) {
>             myRequestedUri = getParentUri (myRequestedUri);
>          }
>          if (StringHelper.isNullOrEmpty (myRequestedUri)) {
>             break;
>          }
>       }
>       if ("NONE".equalsIgnoreCase (myValue)) {
>          return ("");
>       }
>       return ((myValue == null) ? "" : myValue);
>    }
> 
> -----Original Message-----
> From: owner-opencms-dev at www.opencms.org 
> [mailto:owner-opencms-dev at www.opencms.org] On > Behalf Of 
> Thomas Gick
> Sent: Saturday, December 21, 2002 06:00
> To: opencms-dev at www.opencms.org
> Subject: [opencms-dev] Inherit a parameter over several pages?
> 
> Hi,
> 
> to display pages i extended a own class from CmsXmlTemplate.
> In this class i would like to have control over a language 
> parameter which should be inherited to all following choosen 
> pages. To do this this parameter must be added to all 
> internal links automatically too.
> 
> Does anyone knows a solution?
> 
> regards,
> Thomas
> 





More information about the opencms-dev mailing list