01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package org.pentaho.designstudio.controls;
14:
15: import java.util.regex.Pattern;
16:
17: import org.pentaho.designstudio.messages.Messages;
18:
19: public class ActionUtil {
20: private static final String PARAM_START = "<"; //$NON-NLS-1$
21: private static final String PARAM_END = ">"; //$NON-NLS-1$
22: public static final String INPUT_PARAM_PREFIX = Messages
23: .getString("ActionUtil.UI_INPUT_PARAM_PREFIX"); //$NON-NLS-1$
24: public static final String NEW_IO_PLACEHOLDER = Messages
25: .getString("ActionUtil.UI_ADD_PLACEHOLDER"); //$NON-NLS-1$
26:
27: // No one should be able to create one
28: private ActionUtil() {
29: super ();
30: }
31:
32: /*
33: * returns a string like "Document:REGION"
34: */
35: public static String parameterToSourceDisplayText(String source,
36: String parameter) {
37: return (source + ":" + parameter); //$NON-NLS-1$
38: }
39:
40: /*
41: * returns REGION froma string like "Document:REGION"
42: */
43: public static String parameterFromSourceDisplayText(String dispText) {
44: int delimIdx = dispText.indexOf(":"); //$NON-NLS-1$
45: if ((delimIdx >= 0) && ((delimIdx + 1) < dispText.length())) {
46: return (dispText.substring(delimIdx + 1).trim());
47: }
48: return (dispText);
49: }
50:
51: /*
52: * returns a string like "<REGION>"
53: */
54: public static String parameterToDisplayText(String parameter) {
55: if (parameter != null) {
56: parameter = parameter.trim();
57: if (parameter.length() > 0) {
58: return (PARAM_START + parameter + PARAM_END);
59: }
60: }
61: return (""); //$NON-NLS-1$
62: }
63:
64: /*
65: * returns REGION froma string like "<REGION>"
66: */
67: public static String parameterFromDisplayText(String displayText) {
68: if (isParamDispText(displayText)) {
69: return (displayText.substring(1, displayText.length() - 1));
70: }
71: return (displayText);
72: }
73:
74: /*
75: * true if the name is a parameter (begins and ends with "<>" )
76: */
77: public static boolean isParamDispText(String txtString) {
78: return Pattern.matches("<[a-zA-Z_0-9\\-]*>", txtString); //$NON-NLS-1$
79: }
80:
81: }
|