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

Ivan Biddles ivanb at scientology.net
Sat Dec 21 18:22:06 CET 2002


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