01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.components.portletregistry;
18:
19: /**
20: * <p>Helper class for the portlet registry.</p>
21: * @author <a href="dlestrat@apache.org">David Le Strat</a>
22: */
23: public class PortletRegistryHelper {
24:
25: /**
26: * <p>Parses the portlet application name from the portlet
27: * unique name.</p>
28: * @param uniqueName The portlet unique name.
29: */
30: public static String parseAppName(String uniqueName) {
31: int split = splitUniqueName(uniqueName);
32: return uniqueName.substring(0, split);
33: }
34:
35: /**
36: * <p>Parses the portlet name from the portlet
37: * unique name.</p>
38: * @param uniqueName The portlet unique name.
39: */
40: public static String parsePortletName(String uniqueName) {
41: int split = splitUniqueName(uniqueName);
42: return uniqueName.substring((split + 2), uniqueName.length());
43: }
44:
45: /**
46: * <p>Utility method to split the unique name given the
47: * PORTLET_UNIQUE_NAME_SEPARATOR.</p>
48: * @param uniqueName
49: * @return
50: */
51: private static int splitUniqueName(String uniqueName) {
52: int split = 0;
53: if (null != uniqueName) {
54: split = uniqueName
55: .indexOf(PersistenceBrokerPortletRegistry.PORTLET_UNIQUE_NAME_SEPARATOR);
56: }
57: if (split < 1) {
58: throw new IllegalArgumentException(
59: "The unique portlet name, \""
60: + uniqueName
61: + "\"; is not well formed. No "
62: + PersistenceBrokerPortletRegistry.PORTLET_UNIQUE_NAME_SEPARATOR
63: + " delimiter was found.");
64: }
65: return split;
66: }
67:
68: }
|