001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.uilib.util;
016:
017: /**
018: * This class is a general helper, which is used throughout UiLib to parse <code>String</code>s like
019: * events and hierarchical names.
020: *
021: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
022: *
023: */
024: public class NameUtil {
025:
026: /**
027: * Returns the fullname concatenated from the <code>prefix</code>
028: * and the <code>name</code>. If prefix isn't empty, a dot
029: * is added after it.
030: *
031: * @param prefix the full name prefix.
032: * @param name the current name.
033: * @return full name.
034: */
035: public static String getFullName(String prefix, String name) {
036: return "".equals(prefix) || prefix == null ? name : prefix
037: + "." + name;
038: }
039:
040: /**
041: * Returns the prefix of the full name (prefix is part before the first
042: * dot, or the whole full name if it contains no dots).
043: *
044: * @param fullName the full name.
045: * @return prefix of the full name.
046: */
047: public static String getNamePrefix(String fullName) {
048: int dotIndex = fullName.indexOf(".");
049: return (dotIndex == -1 ? fullName : fullName.substring(0,
050: dotIndex));
051: }
052:
053: /**
054: * Returns the full prefix of given full name. That is, the part before
055: * the last dot, or NULL when fullName is not nested).
056: *
057: * @param fullName the full name.
058: * @return full prefix of the full name.
059: * @since 1.0.9
060: */
061: public static String getLongestPrefix(String fullName) {
062: int dotIndex = fullName.lastIndexOf(".");
063: return (dotIndex == -1 ? null : fullName.substring(0, dotIndex));
064: }
065:
066: /**
067: * Returns the shortest suffix of given full name. That is, the part after
068: * the last dot, or fullName when fullName is not nested).
069: *
070: * @param fullName the full name.
071: * @return full prefix of the full name.
072: * @since 1.0.9
073: */
074: public static String getShortestSuffix(String fullName) {
075: int dotIndex = fullName.lastIndexOf(".");
076: return (dotIndex == -1 ? fullName : fullName.substring(
077: dotIndex + 1, fullName.length()));
078: }
079:
080: /**
081: * Returns suffix of the fullname(suffix is part after the first
082: * dot, or an empty <code>String</code> if full name
083: * contains no dots).
084: *
085: * @param fullName full name.
086: * @return suffix of the full name.
087: */
088: public static String getNameSuffix(String fullName) {
089: int dotIndex = fullName.indexOf(".");
090: return (dotIndex == -1 ? "" : fullName.substring(dotIndex + 1));
091: }
092:
093: /**
094: * Returns the event name extracted from the action parameter of the
095: * <code>"Event"</code> action. It is the part in the action parameter before the first <code>"$"</code>.
096: *
097: * @param eventActionParam the action parameter of the <code>"Event"</code> action
098: * @return the event name.
099: */
100: public static String getEventName(String eventActionParam) {
101: int dollarIndex = eventActionParam.indexOf("$");
102: return (dollarIndex == -1 ? eventActionParam : eventActionParam
103: .substring(0, dollarIndex));
104: }
105:
106: /**
107: * Returns the event parameter extracted from the action parameter of the
108: * <code>"Event"</code> action. It is the part in the action parameter after the first <code>"$"</code>.
109: *
110: * @param eventActionParam the action parameter of the <code>"Event"</code> action
111: * @return the event parameter.
112: */
113: public static String getEventParam(String eventActionParam) {
114: int dollarIndex = eventActionParam.indexOf("$");
115: return (dollarIndex == -1 ? "" : eventActionParam
116: .substring(dollarIndex + 1));
117: }
118: }
|