269c3766c7b51dc108941b2ab4d5b2e452be25cd
[ccsdk/sli/core.git] / sliPluginUtils / provider / src / main / java / org / onap / ccsdk / sli / core / slipluginutils / SliStringUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Modifications Copyright (C) 2018 IBM.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.ccsdk.sli.core.slipluginutils;
25
26 import java.io.UnsupportedEncodingException;
27 import java.net.URLEncoder;
28 import java.util.Map;
29 import org.apache.commons.lang3.StringEscapeUtils;
30 import org.apache.commons.lang3.StringUtils;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 /**
38  * A SvcLogicJavaPlugin that exposes java.lang.String functions to DirectedGraph
39  */
40 public class SliStringUtils implements SvcLogicJavaPlugin {
41         private static final Logger LOG = LoggerFactory.getLogger(SliStringUtils.class);
42         public static final String INPUT_PARAM_KEY = "key";
43         public static final String INPUT_PARAM_SOURCE = "source";
44         public static final String INPUT_PARAM_TARGET = "target";
45     public static final String TRUE_CONSTANT = "true";
46     public static final String FALSE_CONSTANT = "false";
47
48         public SliStringUtils() {}
49
50         /**
51          * Provides split functionality to Directed Graphs.
52          * @param parameters HashMap<String,String> of parameters passed by the DG to this function
53          * <table border="1">
54          *      <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
55          *      <tbody>
56          *              <tr><td>original_string</td><td>Mandatory</td><td>String to perform split on</td></tr>
57          *              <tr><td>regex</td><td>Mandatory</td><td>the delimiting regular expression</td></tr>
58          *              <tr><td>limit</td><td>Optional</td><td>result threshold. See String.split method for further description. Defaults to 0</td></tr>
59          *              <tr><td>ctx_memory_result_key</td><td>Mandatory</td><td>Key in context memory to populate the resulting array of strings under</td></tr>
60          *      </tbody>
61          * </table>
62          * @param ctx Reference to context memory
63          * @throws SvcLogicException
64          * @since 11.0.2
65          * @see String#split(String, int)
66          */
67         public void split( Map<String, String> parameters, SvcLogicContext ctx ) throws SvcLogicException {
68                 final String original_string = parameters.get("original_string");
69                 LOG.trace("original_string = " + original_string);
70                 final String regex = parameters.get("regex");
71                 LOG.trace("regex = " + regex);
72                 final String limit_str = parameters.get("limit");
73                 LOG.trace("limit_str = " + limit_str);
74                 final String ctx_memory_result_key = parameters.get("ctx_memory_result_key");
75                 LOG.trace("ctx_memory_result_key = " + ctx_memory_result_key);
76
77                 try {
78                         // Validation that parameters are not null
79                         SliPluginUtils.checkParameters( parameters, new String[]{"original_string","regex","ctx_memory_result_key"}, LOG );
80
81                         // Read limit from context memory. Default to 0 if null/empty
82                         int limit = 0;
83                         if( StringUtils.isNotEmpty(limit_str) ) {
84                                 try {
85                                         limit = Integer.parseInt(limit_str);
86                                 }
87                                 catch( NumberFormatException e ) {
88                                         throw new IllegalArgumentException( "The limit parameter of the SliStringUtils.split() function must be a number, empty string, or null", e );
89                                 }
90                         }
91
92                         // Call String.split(regex,limit) on string passed in
93                         String[] split_string = original_string.split(regex, limit);
94
95                         // Populate context memory with results
96                         for( int i = 0; i < split_string.length; i++ ) {
97                                 SliPluginUtils.ctxSetAttribute(ctx, ctx_memory_result_key + '[' + i + ']', split_string[i], LOG, SliPluginUtils.LogLevel.DEBUG);
98                         }
99                         SliPluginUtils.ctxSetAttribute(ctx, ctx_memory_result_key + "_length", new Integer(split_string.length), LOG, SliPluginUtils.LogLevel.DEBUG);
100                 }
101                 catch( Exception e ) {
102                         // Have error message print parameters
103                         throw new SvcLogicException( "An error occurred during SliStringUtils.split() where original_string = " + quotedOrNULL(regex) +
104                                         " regex = " + quotedOrNULL(regex) +
105                                         " limit = " + quotedOrNULL(regex) +
106                                         " ctx_memory_result_key = " + quotedOrNULL(regex), e );
107                 }
108         }
109
110         public static String quotedOrNULL( String str ) {
111                 return (str == null) ? "NULL" : '"' + str + '"';
112         }
113
114     /**
115      * exposes equalsIgnoreCase to directed graph
116      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
117      * emits a true or false outcome
118      * <table border="1">
119      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
120      *  <tbody>
121      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
122      *      <tr><td>target</td><td>Mandatory</td><td>target string</td></tr>
123      *  </tbody>
124      * </table>
125      * @param ctx Reference to context memory
126      * @throws SvcLogicException
127      * @since 11.0.2
128      */
129     public static String equalsIgnoreCase(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
130         SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
131         if (parameters.get(INPUT_PARAM_SOURCE).equalsIgnoreCase(parameters.get(INPUT_PARAM_TARGET))) {
132             return TRUE_CONSTANT;
133         }
134         return FALSE_CONSTANT;
135     }
136
137     /**
138      * exposes toUpperCase to directed graph
139      * writes an upperCase version of source to outputPath
140      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
141      * <table border="1">
142      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
143      *  <tbody>
144      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
145      *      <tr><td>outputPath</td><td>Mandatory</td><td>the location in context memory the result is written to</td></tr>
146      *  </tbody>
147      * </table>
148      * @param ctx Reference to context memory
149      * @throws SvcLogicException
150      * @since 11.0.2
151      */
152     public static void toUpper(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
153         SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"outputPath"}, LOG);
154         ctx.setAttribute(parameters.get("outputPath"), parameters.get(INPUT_PARAM_SOURCE).toUpperCase());
155     }
156
157     /**
158      * exposes toLowerCase to directed graph
159      * writes a lowerCase version of source to outputPath
160      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
161      * <table border="1">
162      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
163      *  <tbody>
164      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
165      *      <tr><td>outputPath</td><td>Mandatory</td><td>the location in context memory the result is written to</td></tr>
166      *  </tbody>
167      * </table>
168      * @param ctx Reference to context memory
169      * @throws SvcLogicException
170      * @since 11.0.2
171      */
172     public static void toLower(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
173         SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"outputPath"}, LOG);
174         ctx.setAttribute(parameters.get("outputPath"), parameters.get(INPUT_PARAM_SOURCE).toLowerCase());
175     }
176
177     /**
178      * exposes contains to directed graph to test if one string contains another
179      * tests if the source contains the target
180      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
181      * emits a true or false outcome
182      * <table border="1">
183      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
184      *  <tbody>
185      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
186      *      <tr><td>target</td><td>Mandatory</td><td>target string</td></tr>
187      *  </tbody>
188      * </table>
189      * @param ctx Reference to context memory
190      * @throws SvcLogicException
191      * @since 11.0.2
192      */
193     public static String contains(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
194         SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
195         if (parameters.get(INPUT_PARAM_SOURCE).contains(parameters.get(INPUT_PARAM_TARGET))) {
196             return TRUE_CONSTANT;
197         }
198         return FALSE_CONSTANT;
199     }
200
201     /**
202      * exposes endsWith to directed graph to test if one string endsWith another string
203      * tests if the source ends with the target
204      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
205      * emits a true or false outcome
206      * <table border="1">
207      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
208      *  <tbody>
209      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
210      *      <tr><td>target</td><td>Mandatory</td><td>target string</td></tr>
211      *  </tbody>
212      * </table>
213      * @param ctx Reference to context memory
214      * @throws SvcLogicException
215      * @since 11.0.2
216      */
217     public static String endsWith(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
218         SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
219         if (parameters.get(INPUT_PARAM_SOURCE).endsWith(parameters.get(INPUT_PARAM_TARGET))) {
220             return TRUE_CONSTANT;
221         }
222         return FALSE_CONSTANT;
223     }
224
225     /**
226      * exposes startsWith to directed graph to test if one string endsWith another string
227      * tests if the source ends with the target
228      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
229      * emits a true or false outcome
230      * <table border="1">
231      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
232      *  <tbody>
233      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
234      *      <tr><td>target</td><td>Mandatory</td><td>target string</td></tr>
235      *  </tbody>
236      * </table>
237      * @param ctx Reference to context memory
238      * @throws SvcLogicException
239      * @since 11.0.2
240      */
241     public static String startsWith(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
242         SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
243         if (parameters.get(INPUT_PARAM_SOURCE).startsWith(parameters.get(INPUT_PARAM_TARGET))) {
244             return TRUE_CONSTANT;
245         }
246         return FALSE_CONSTANT;
247     }
248
249     /**
250      * exposes trim to directed graph
251      * writes a trimmed version of the string to the outputPath
252      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
253      * <table border="1">
254      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
255      *  <tbody>
256      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
257      *      <tr><td>outputPath</td><td>Mandatory</td><td>the location in context memory the result is written to</td></tr>
258      *  </tbody>
259      * </table>
260      * @param ctx Reference to context memory
261      * @throws SvcLogicException
262      * @since 11.0.2
263      */
264     public static void trim(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
265         SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"outputPath"}, LOG);
266         ctx.setAttribute(parameters.get("outputPath"), parameters.get(INPUT_PARAM_SOURCE).trim());
267     }
268
269     /**
270      * exposes String.length() to directed graph
271      * writes the length of source to outputPath
272      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
273      * <table border="1">
274      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
275      *  <tbody>
276      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
277      *      <tr><td>outputPath</td><td>Mandatory</td><td>the location in context memory the result is written to</td></tr>
278      *  </tbody>
279      * </table>
280      * @param ctx Reference to context memory
281      * @throws SvcLogicException
282      * @since 11.0.2
283      */
284     public static void getLength(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
285         SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"outputPath"}, LOG);
286         ctx.setAttribute(parameters.get("outputPath"), String.valueOf(parameters.get(INPUT_PARAM_SOURCE).length()));
287     }
288
289     /**
290      * exposes replace to directed graph
291      * writes the length of source to outputPath
292      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
293      * <table border="1">
294      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
295      *  <tbody>
296      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
297      *      <tr><td>target</td><td>Mandatory</td><td>The sequence of char values to be replaced</td></tr>
298      *      <tr><td>replacement</td><td>Mandatory</td><td>The replacement sequence of char values</td></tr>
299      *      <tr><td>outputPath</td><td>Mandatory</td><td>the location in context memory the result is written to</td></tr>
300      *  </tbody>
301      * </table>
302      * @param ctx Reference to context memory
303      * @throws SvcLogicException
304      * @since 11.0.2
305      */
306     public static void replace(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
307         SliPluginUtils.checkParameters(parameters,
308                 new String[] {INPUT_PARAM_SOURCE, "outputPath", INPUT_PARAM_TARGET, "replacement"}, LOG);
309         ctx.setAttribute(parameters.get("outputPath"), (parameters.get(INPUT_PARAM_SOURCE)
310                 .replace(parameters.get(INPUT_PARAM_TARGET), parameters.get("replacement"))));
311     }
312
313     /**
314      * exposes replaceAll to directed graph
315      * writes the length of source to outputPath
316      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
317      * <table border="1">
318      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
319      *  <tbody>
320      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
321      *      <tr><td>target</td><td>Mandatory</td><td>This should be a valid regular expression</td></tr>
322      *      <tr><td>replacement</td><td>Mandatory</td><td>The replacement sequence of char values</td></tr>
323      *      <tr><td>outputPath</td><td>Mandatory</td><td>the location in context memory the result is written to</td></tr>
324      *  </tbody>
325      * </table>
326      * @param ctx Reference to context memory
327      * @throws SvcLogicException
328      * @since 11.0.2
329      */
330     public static void replaceAll(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
331         SliPluginUtils.checkParameters(parameters,
332                 new String[] {INPUT_PARAM_SOURCE, "outputPath", INPUT_PARAM_TARGET, "replacement"}, LOG);
333         ctx.setAttribute(parameters.get("outputPath"), parameters.get(INPUT_PARAM_SOURCE)
334                 .replaceAll(parameters.get(INPUT_PARAM_TARGET), parameters.get("replacement")));
335     }
336     
337     /**
338      * Provides substring functionality to Directed Graphs.
339      * <p>
340      * Calls either String.substring(String beginIndex) or
341      * String.substring(String beginInded, String endIndex) if the end-index
342      * is present or not.
343      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
344      * <table border="1">
345      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
346      *  <tbody>
347      *      <tr><td>string</td><td>Mandatory</td><td>String to perform substring on</td></tr>
348      *      <tr><td>result</td><td>Mandatory</td><td>Key in context memory to populate the resulting string in</td></tr>
349      *      <tr><td>begin-index</td><td>Mandatory</td><td>Beginning index to pass to Java substring function</td></tr>
350      *      <tr><td>end-index</td><td>Optional</td><td>Ending index to pass to Java substring function. If not included, String.substring(begin) will be called.</td></tr>
351      *  </tbody>
352      * </table>
353      * @param ctx Reference to context memory
354      * @throws SvcLogicException
355      * @since 11.0.2
356      */
357     public void substring( Map<String, String> parameters, SvcLogicContext ctx ) throws SvcLogicException {
358         try {
359             SliPluginUtils.checkParameters( parameters, new String[]{"string","begin-index","result"}, LOG );
360             final String string = parameters.get("string");
361             final String result = parameters.get("result");
362             final String begin = parameters.get("begin-index");
363             final String end = parameters.get("end-index");
364             if( StringUtils.isEmpty(end) ) {
365                 ctx.setAttribute( result, string.substring(Integer.parseInt(begin)) );
366             }
367             else {
368                 ctx.setAttribute( result, string.substring(Integer.parseInt(begin), Integer.parseInt(end)) );
369             }
370         }
371         catch( Exception e ) {
372             throw new SvcLogicException( "An error occurred while the Directed Graph was performing a substring", e );
373         }
374     }
375
376     /**
377      * Provides concat functionality to Directed Graphs.
378      * <p>
379      * Will concat target to source and write the result to outputPath
380      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
381      * <table border="1">
382      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
383      *  <tbody>
384      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
385      *      <tr><td>target</td><td>Mandatory</td><td>The sequence of char values to be replaced</td></tr>
386      *      <tr><td>outputPath</td><td>Mandatory</td><td>the location in context memory the result is written to</td></tr>
387      *  </tbody>
388      * </table>
389      * @param ctx Reference to context memory
390      * @throws SvcLogicException
391      * @since 11.0.2
392      */
393     public static void concat( Map<String, String> parameters, SvcLogicContext ctx ) throws SvcLogicException {
394         SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET, "outputPath"},
395                 LOG);
396         String result = parameters.get(INPUT_PARAM_SOURCE).concat(parameters.get(INPUT_PARAM_TARGET));
397             ctx.setAttribute(parameters.get("outputPath"), result);
398     }
399
400     /**
401      * Provides url encoding functionality to Directed Graphs.
402      * <p>
403      * Will url encode the source and write the result to outputPath
404      * @param parameters HashMap<String,String> of parameters passed by the DG to this function
405      * <table border="1">
406      *  <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
407      *  <tbody>
408      *      <tr><td>source</td><td>Mandatory</td><td>source string</td></tr>
409      *      <tr><td>encoding</td><td>Optional</td><td>the name of a supported character encoding, defaulted to UTF-8 if not supplied</td></tr>
410      *      <tr><td>outputPath</td><td>Mandatory</td><td>the location in context memory the result is written to</td></tr>
411      *  </tbody>
412      * </table>
413      * @param ctx Reference to context memory
414      * @throws SvcLogicException
415      */
416     public static void urlEncode(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
417         SliPluginUtils.checkParameters(parameters, new String[] { INPUT_PARAM_SOURCE, "outputPath" }, LOG);
418         String encoding = parameters.get("encoding");
419         if (encoding == null) {
420             encoding = "UTF-8";
421         }
422         try {
423             String result = URLEncoder.encode(parameters.get(INPUT_PARAM_SOURCE), encoding);
424             ctx.setAttribute(parameters.get("outputPath"), result);
425         } catch (UnsupportedEncodingException e) {
426             throw new SvcLogicException("Url encode failed.", e);
427         }
428     }
429
430         /**
431          * xmlEscapeText() will be used to format input xml with text.
432          *
433          * @param inParams
434          *            accepts the instance of {@link Map} holds the input xml in string
435          *            format.
436          * @param ctx
437          *            accepts the instance of {@link SvcLogicContext} holds the service
438          *            logic context.
439          *
440          */
441         public static void xmlEscapeText(Map<String, String> inParams, SvcLogicContext ctx) {
442                 String source = inParams.get(INPUT_PARAM_SOURCE);
443                 String target = inParams.get(INPUT_PARAM_TARGET);
444                 source = StringEscapeUtils.escapeXml(source);
445                 ctx.setAttribute(target, source);
446         }
447
448         /**
449         * unescapeJsonString takes an escaped json string stored as a single property in context memory and unescapes it storing it as a single property
450         * @param parameters - requires source and outputPath to not be null.
451         * @param ctx Reference to context memory
452         * @throws SvcLogicException if a required parameter is missing an exception is thrown
453         */
454     public static void unescapeJsonString(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
455         SliPluginUtils.checkParameters(parameters, new String[] { INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET }, LOG);
456         try {
457             String source = parameters.get(INPUT_PARAM_SOURCE);
458             String target = parameters.get(INPUT_PARAM_TARGET);
459             String unescapedJson = StringEscapeUtils.unescapeJson(source);
460             ctx.setAttribute(target, unescapedJson);
461         } catch (Exception ex) {
462             ex.printStackTrace();
463             throw new SvcLogicException("problem with unescapeJsonString", ex);
464         }
465     }
466
467         /**
468         * escapeJsonString takes json stored as a single string in context memory and escapes it storing it as a single property
469         * @param parameters - requires source and outputPath to not be null.
470         * @param ctx Reference to context memory
471         * @throws SvcLogicException if a required parameter is missing an exception is thrown
472         */
473     public static void escapeJsonString(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
474         SliPluginUtils.checkParameters(parameters, new String[] { INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET }, LOG);
475         try {
476             String source = parameters.get(INPUT_PARAM_SOURCE);
477             String target = parameters.get(INPUT_PARAM_TARGET);
478             String unescapedJson = StringEscapeUtils.escapeJson(source);
479             ctx.setAttribute(target, unescapedJson);
480         } catch (Exception ex) {
481             ex.printStackTrace();
482             throw new SvcLogicException("problem with escapeJsonString", ex);
483         }
484     }
485
486     public static String isBlank(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
487         String ctxLocation = parameters.get(INPUT_PARAM_KEY);
488         String str = ctx.getAttribute(ctxLocation);
489         if (str == null || str.isEmpty() || " ".equals(str)) {
490             return TRUE_CONSTANT;
491         }
492         return FALSE_CONSTANT;
493     }
494
495     public static String isEmpty(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
496         String ctxLocation = parameters.get(INPUT_PARAM_KEY);
497         String str = ctx.getAttribute(ctxLocation);
498         if (str == null || str.isEmpty()) {
499             return TRUE_CONSTANT;
500         }
501         return FALSE_CONSTANT;
502     }
503
504     public static String isNull(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
505         String ctxLocation = parameters.get(INPUT_PARAM_KEY);
506         String str = ctx.getAttribute(ctxLocation);
507         if (str == null) {
508             return TRUE_CONSTANT;
509         }
510         return FALSE_CONSTANT;
511     }
512 }