You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by dl...@apache.org on 2004/05/08 19:55:25 UTC

cvs commit: jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregistry PortletRegistryHelper.java PortletRegistryComponentImpl.java

dlestrat    2004/05/08 10:55:25

  Modified:    components/registry/src/java/org/apache/jetspeed/components/portletregistry
                        PortletRegistryComponentImpl.java
  Added:       components/registry/src/java/org/apache/jetspeed/components/portletregistry
                        PortletRegistryHelper.java
  Log:
  Refactor code to get portlet application / portlet name from unique name.
  Added helper class.
  
  Revision  Changes    Path
  1.8       +10 -9     jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregistry/PortletRegistryComponentImpl.java
  
  Index: PortletRegistryComponentImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregistry/PortletRegistryComponentImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PortletRegistryComponentImpl.java	7 May 2004 13:41:37 -0000	1.7
  +++ PortletRegistryComponentImpl.java	8 May 2004 17:55:25 -0000	1.8
  @@ -75,7 +75,15 @@
    */
   public class PortletRegistryComponentImpl implements PortletRegistryComponent
   {
  +    /** The logger. */
       private static final Log log = LogFactory.getLog(PortletRegistryComponentImpl.class);
  +    
  +    /** 
  +     * The separator used to create a unique portlet name as
  +     * {portletApplication}::{portlet}
  +     */
  +    static final String PORTLET_UNIQUE_NAME_SEPARATOR = "::";
  +
       protected static final String KEY_STORE_NAME = "persistence.store.name";
       private PersistenceStoreContainer storeContainer;
       private String jetspeedStoreName;
  @@ -278,15 +286,8 @@
           PersistenceStore store = getPersistenceStore();
           prepareTransaction(store);
   
  -        //parse out names
  -        int split = name.indexOf("::");
  -        if (split < 1)
  -        {
  -            throw new IllegalArgumentException(
  -                "The unique portlet name, \"" + name + "\";  is not well formed.  No \"::\" delimiter was found.");
  -        }
  -        String appName = name.substring(0, split);
  -        String portletName = name.substring((split + 2), name.length());
  +        String appName = PortletRegistryHelper.parseAppName(name);
  +        String portletName = PortletRegistryHelper.parsePortletName(name);
   
           // build filter
           Filter filter = store.newFilter();
  
  
  
  1.1                  jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/components/portletregistry/PortletRegistryHelper.java
  
  Index: PortletRegistryHelper.java
  ===================================================================
  /* Copyright 2004 Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.components.portletregistry;
  
  import org.apache.jetspeed.components.portletregistry.PortletRegistryComponentImpl;
  
  /**
   * <p>Helper class for the portlet registry.</p>
   * @author <a href="dlestrat@apache.org">David Le Strat</a>
   */
  public class PortletRegistryHelper
  {
  
      /**
       * <p>Parses the portlet application name from the portlet
       * unique name.</p>
       * @param uniqueName The portlet unique name.
       */
      public static String parseAppName(String uniqueName)
      {
          int split = splitUniqueName(uniqueName);
          return uniqueName.substring(0, split);
      }
  
      /**
       * <p>Parses the portlet name from the portlet
       * unique name.</p>
       * @param uniqueName The portlet unique name.
       */
      public static String parsePortletName(String uniqueName)
      {
          int split = splitUniqueName(uniqueName);
          return uniqueName.substring((split + 2), uniqueName.length());
      }
  
      /**
       * <p>Utility method to split the unique name given the
       * PORTLET_UNIQUE_NAME_SEPARATOR.</p>
       * @param uniqueName
       * @return
       */
      private static int splitUniqueName(String uniqueName)
      {
          int split = uniqueName.indexOf(PortletRegistryComponentImpl.PORTLET_UNIQUE_NAME_SEPARATOR);
          if (split < 1)
          {
              throw new IllegalArgumentException(
                  "The unique portlet name, \""
                      + uniqueName
                      + "\";  is not well formed.  No "
                      + PortletRegistryComponentImpl.PORTLET_UNIQUE_NAME_SEPARATOR
                      + " delimiter was found.");
          }
          return split;
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org