List of usage examples for org.apache.commons.lang BooleanUtils toBoolean
public static boolean toBoolean(String str)
Converts a String to a boolean (optimised for performance).
'true'
, 'on'
or 'yes'
(case insensitive) will return true
.
From source file:org.sipfoundry.sipxconfig.site.openacd.EditOpenAcdLine.java
@Override public void pageBeginRender(PageEvent event) { super.pageEndRender(event); List<FreeswitchAction> actions = null; if (getOpenAcdLineId() == null) { actions = OpenAcdLine.getDefaultActions(getLocationsManager().getPrimaryLocation()); } else {/*w w w . ja va 2 s . c om*/ OpenAcdLine line = (OpenAcdLine) getOpenAcdContext().getExtensionById(getOpenAcdLineId()); actions = line.getLineActions(); setName(line.getName()); setDescription(line.getDescription()); setLineNumber(line.getNumberCondition().getExtension()); setAlias(line.getAlias()); setDid(line.getDid()); setRegex(line.getNumberCondition().isRegex()); } List<ActionBean> actionBeans = new LinkedList<ActionBean>(); boolean isFsSet = false; boolean isAgentSet = false; for (FreeswitchAction action : actions) { String application = action.getApplication(); String data = action.getData(); if (StringUtils.equals(application, FreeswitchAction.PredefinedAction.answer.toString())) { isFsSet = true; } else if (StringUtils.contains(data, OpenAcdLine.ERLANG_ANSWER)) { isAgentSet = true; } else if (StringUtils.contains(data, OpenAcdLine.Q)) { if (getSelectedQueue() == null) { String queueName = StringUtils.removeStart(data, OpenAcdLine.Q); OpenAcdQueue queue = getOpenAcdContext().getQueueByName(queueName); setSelectedQueue(queue); } } else if (StringUtils.contains(data, OpenAcdLine.BRAND)) { if (getSelectedClient() == null) { String clientIdentity = StringUtils.removeStart(data, OpenAcdLine.BRAND); OpenAcdClient client = getOpenAcdContext().getClientByIdentity(clientIdentity); setSelectedClient(client); } } else if (StringUtils.contains(data, OpenAcdLine.ALLOW_VOICEMAIL)) { setAllowVoicemail( BooleanUtils.toBoolean(StringUtils.removeStart(data, OpenAcdLine.ALLOW_VOICEMAIL))); } else if (StringUtils.equals(application, FreeswitchAction.PredefinedAction.playback.toString())) { if (getWelcomeMessage() == null) { setWelcomeMessage(StringUtils.removeStart(data, getSettings().getAudioDirectory() + SLASH)); } } else { actionBeans.add(new ActionBean(action)); } } if (isFsSet) { setAnswerSupervisionType(FS); } else if (isAgentSet) { setAnswerSupervisionType(AGENT); } else { setAnswerSupervisionType(ACD); } if (getActions() == null) { setActions(actionBeans); } if (getRemoveAction() != null) { getActions().remove(getRemoveAction()); } }
From source file:org.soaplab.clients.ClientConfig.java
/************************************************************************** * For the property values 'true', 'on', 'yes' (case insensitive), * and for an empty value it returns true. For other values, false * is returned. If the property does not exist at all, the * 'defaultValue' is returned. <p> **************************************************************************/ public static boolean isEnabled(String key, boolean defaultValue) { String strValue = get().getString(key, null); if (strValue == null) return defaultValue; if (StringUtils.isBlank(strValue)) return true; return BooleanUtils.toBoolean(strValue); }
From source file:org.soaplab.clients.spinet.Service.java
/************************************************************************* * It returns a map of several parts of a service panel - which is * an HTML representation how this service can be controlled * (started, explored, etc.). These parts are included into an * HTML page using the JSP mechanism (that understands this * returned map)./*from w w w. j a v a 2 s . c om*/ *************************************************************************/ public Map<String, String> getPanelMap() throws SoaplabException { log.debug("Panel requested for " + getName()); try { // get metadata Analysis client = getClient(); Map<String, Object>[] inputs = SoaplabMap.toMaps(client.getInputSpec()); // Map<String,Object>[] outputs = SoaplabMap.toMaps (client.getResultSpec()); Map<String, Object> app = SoaplabMap.toMap(client.getAnalysisType()); if (BooleanUtils.toBoolean((String) app.get(SoaplabConstants.ANALYSIS_EMBOSS))) { fetchDBNames(); } // pack everything into a resulting Map Map<String, String> valuesMap = new HashMap<String, String>(); valuesMap.put("service.name", getName()); valuesMap.put("inputs", getInputsPanel(app, inputs)); // valuesMap.put ("outputs", getOutputsPanel (app, outputs)); valuesMap.put("apphelp", getHelpPanel(app)); return valuesMap; } catch (Throwable e) { throw new SoaplabException(e.getMessage(), e); } }
From source file:org.soaplab.clients.spinet.Service.java
/************************************************************************* * *************************************************************************/ protected String getInputsPanel(Map<String, Object> app, Map<String, Object>[] inputs) { consolidate(inputs);/* w ww . jav a2s . c om*/ sort(inputs); int indexOfFirstOptional = 0; List<String> names = new ArrayList<String>(); List<String> classes = new ArrayList<String>(); List<String> uis = new ArrayList<String>(); StringBuilder tooltips = new StringBuilder(); StringBuilder js = new StringBuilder(); // init js (for input validation) js.append(h.gen(SCRIPT, TYPE, "text/javascript", null)); js.append("\nTESTS ['"); js.append(getName()); js.append("']=[\n"); // first add all mandatory inputs for (Map<String, Object> input : inputs) { if (input == null) continue; if (BooleanUtils.toBoolean((String) input.get(SoaplabConstants.INPUT_MANDATORY))) { createInput(app, input, names, classes, uis, tooltips, js); indexOfFirstOptional++; } } if (indexOfFirstOptional == 0) indexOfFirstOptional = -1; // if no mandatory input // then add all remaining inputs for (Map<String, Object> input : inputs) { if (input == null) continue; if (!BooleanUtils.toBoolean((String) input.get(SoaplabConstants.INPUT_MANDATORY))) { createInput(app, input, names, classes, uis, tooltips, js); } } // finish js js.append("];\n"); js.append(h.end(SCRIPT)); js.append("\n"); return createInputTable(names, classes, uis, indexOfFirstOptional) + "\n\n" + tooltips.toString() + "\n\n" + js.toString(); }
From source file:org.soaplab.clients.spinet.Service.java
/************************************************************************* * *************************************************************************/ protected void createInput(Map<String, Object> app, Map<String, Object> input, List<String> names, List<String> classes, List<String> uis, StringBuilder tooltips, StringBuilder js) { boolean emboss = BooleanUtils.toBoolean((String) app.get(SoaplabConstants.ANALYSIS_EMBOSS)); String name = (String) input.get(SoaplabConstants.INPUT_NAME); String type = (String) input.get(SoaplabConstants.INPUT_TYPE); String defaultValue = (String) input.get(SoaplabConstants.INPUT_DEFAULT_VALUE); String[] allowedValues = (String[]) input.get(SoaplabConstants.INPUT_ALLOWED_VALUES); String format = (String) input.get(SoaplabConstants.INPUT_FORMAT); String datatype = (String) input.get(SoaplabConstants.DATA_TYPE); boolean mandatory = BooleanUtils.toBoolean((String) input.get(SoaplabConstants.INPUT_MANDATORY)); // something only for EMBOSS if (emboss) { if (name.startsWith("send_") || name.startsWith("sbegin_")) { format = "%d"; }//from w w w.ja v a 2 s. c o m } if (ArrayUtils.getLength(allowedValues) > 0) { // allowed values => SELECT names.add(Html.esc(name)); classes.add(createInputTooltipAndClass(name, input, tooltips)); // it's never used but initiates creation of a special select option if (!mandatory && StringUtils.isEmpty(defaultValue)) { defaultValue = "something"; } uis.add(createSelect(name + S_INPUT, defaultValue, allowedValues)); } else if (type.equals(SoaplabConstants.TYPE_BOOLEAN_SIMPLE)) { // boolean type => RADIO GROUP names.add(Html.esc(name)); classes.add(createInputTooltipAndClass(name, input, tooltips)); uis.add(createRadioPair(name + S_INPUT, defaultValue)); } else if (isInputFile(input)) { // input file names.add(Html.esc(name)); classes.add(createInputTooltipAndClass(name, input, tooltips)); uis.add(createDataInput(name, js, input)); } else if (format != null) { // formatted field (requiring some validation) names.add(Html.esc(name)); classes.add(createInputTooltipAndClass(name, input, tooltips)); uis.add(createValidText(name + S_INPUT, input, mandatory, js, format, defaultValue)); } else if ("filelist".equals(datatype)) { // filelist is not supported in Spinet, inform about it names.add(Html.esc(name)); classes.add(createInputTooltipAndClass(name, input, tooltips)); uis.add(createTextWithWarning(name + S_INPUT, mandatory, js, FILELIST_WARNING, VALUE, defaultValue, CLASS, "input-text")); } else { // ...and the rest names.add(Html.esc(name)); classes.add(createInputTooltipAndClass(name, input, tooltips)); uis.add(createText(name + S_INPUT, mandatory, js, VALUE, defaultValue, CLASS, "input-text")); } }
From source file:org.soaplab.clients.spinet.Service.java
/************************************************************************* * *************************************************************************/ protected String createDataInput(String name, StringBuilder js, Map<String, Object> input) { if (input.containsKey(TMP_PROP_BOTH_INPUTS)) { // for URL and direct data String defaultValue = (String) input.get(SoaplabConstants.INPUT_DEFAULT_VALUE); boolean defaultForDirect = BooleanUtils .toBoolean((String) input.get(SoaplabConstants.DEFAULT_FOR_DIRECT)); boolean checkedForDirect = (StringUtils.isEmpty(defaultValue) || defaultForDirect); StringBuilder buf = new StringBuilder(); buf.append(h.gen(TABLE, new String[] { CELLPADDING, "0", CLASS, "data-input-box" })); // ...this is a row for URL data String refSuffix = (input.containsKey(TMP_PROP_EMBOSS_INPUT) ? SoaplabConstants.USA_SUFFIX : SoaplabConstants.URL_SUFFIX); String elementName = name + refSuffix; String onFocus = "checkRadio(this.form, '" + name + S_TOGGLE + refSuffix + "')"; String togglePrompt = null; if (refSuffix.equals(SoaplabConstants.USA_SUFFIX)) { togglePrompt = "as USA or<br>as URL"; // add EMBOSS databases buf.append(h.gen(TR,/* w ww.j a v a 2 s .c o m*/ h.gen(TD, new String[] { COLSPAN, "3" }, createShowDB(elementName + S_INPUTDATA)))); buf.append("\n"); } else { togglePrompt = "as URL"; } buf.append(h.gen(TR)); buf.append(h.gen(TD, createText(elementName + S_INPUTDATA, false, // mandatorness is tested elsewhere js, // but no need for JavaScript tests VALUE, (defaultForDirect ? null : defaultValue), SIZE, "30", ONFOCUS, onFocus, CLASS, "input-text"))); buf.append(h.gen(TD, createRadio(name + S_TOGGLE, name + S_TOGGLE + refSuffix, refSuffix, !checkedForDirect))); buf.append(h.gen(TD, new String[] { CLASS, "data-input-toggle" }, togglePrompt)); buf.append(h.end(TR)); // ...this is a row for direct data buf.append(h.gen(TR)); buf.append(h.gen(TD, createDirectDataInput(name, js, input) + createErrorMessageField(name))); buf.append(h.gen(TD, createRadio(name + S_TOGGLE, name + S_TOGGLE + SoaplabConstants.DIRECT_DATA_SUFFIX, SoaplabConstants.DIRECT_DATA_SUFFIX, checkedForDirect))); buf.append(h.gen(TD, new String[] { CLASS, "data-input-toggle" }, "direct data<br>or local file")); buf.append(h.end(TR)); buf.append(h.end(TABLE)); return buf.toString(); } else { // only for direct data return classWrap("data-input-box", createDirectDataInputAlone(name, js, input) + createErrorMessageField(name)); } }
From source file:org.soaplab.clients.spinet.Service.java
/************************************************************************* * *************************************************************************/ protected String createDirectDataInput(String name, StringBuilder js, Map<String, Object> input) { boolean mandatory = BooleanUtils.toBoolean((String) input.get(SoaplabConstants.INPUT_MANDATORY)); String defaultValue = (String) input.get(SoaplabConstants.INPUT_DEFAULT_VALUE); boolean defaultForDirect = BooleanUtils.toBoolean((String) input.get(SoaplabConstants.DEFAULT_FOR_DIRECT)); StringBuilder buf = new StringBuilder(); buf.append(h.gen(TABLE, new String[] { CLASS, "direct-input-box" })); String onFocus = "checkRadio(this.form, '" + name + S_TOGGLE + SoaplabConstants.DIRECT_DATA_SUFFIX + "')"; buf.append(h.gen(TR,//from w w w . j a v a 2 s. c o m h.gen(TD, createTextArea(name + SoaplabConstants.DIRECT_DATA_SUFFIX + S_INPUTDATA, VALUE, (defaultForDirect ? defaultValue : null), ROWS, "3", COLS, "30", ONFOCUS, onFocus, CLASS, "input-text")))); // hack: onFocus on type=file does not work in all browsers, but onClick does String onClick = "checkRadio(this.form, '" + name + S_TOGGLE + SoaplabConstants.DIRECT_DATA_SUFFIX + "')"; buf.append(h.gen(TR, h.gen(TD, h.gen(INPUT, new String[] { NAME, name + SoaplabConstants.DIRECT_DATA_SUFFIX + S_UPLOAD, TYPE, "file", ONCLICK, onClick, CLASS, "input-upload" }, "")))); buf.append(h.end(TABLE)); if (mandatory) { js.append("\"isInputMandatory (form,'" + name + "')\",\n"); } return buf.toString(); }
From source file:org.soaplab.clients.spinet.Service.java
/************************************************************************* * The same as createDirectDataInput - but for a standalone direct * data (not joined with a field for a URL data). *************************************************************************/ protected String createDirectDataInputAlone(String name, StringBuilder js, Map<String, Object> input) { boolean mandatory = BooleanUtils.toBoolean((String) input.get(SoaplabConstants.INPUT_MANDATORY)); String defaultValue = (String) input.get(SoaplabConstants.INPUT_DEFAULT_VALUE); boolean defaultForDirect = BooleanUtils.toBoolean((String) input.get(SoaplabConstants.DEFAULT_FOR_DIRECT)); StringBuilder buf = new StringBuilder(); buf.append(h.gen(TABLE, new String[] { CLASS, "direct-input-box" })); buf.append(h.gen(TR, h.gen(TD, createTextArea(name + S_INPUTDATAALONE, VALUE, (defaultForDirect ? defaultValue : null), ROWS, "3", COLS, "30", CLASS, "input-text")))); buf.append(h.gen(TR, h.gen(TD,/* w w w. j a va2 s.c o m*/ h.gen(INPUT, new String[] { NAME, name + S_UPLOAD, TYPE, "file", CLASS, "input-upload" }, "")))); buf.append(h.end(TABLE)); if (mandatory) { js.append("\"isInputMandatory (form,'" + name + "')\",\n"); } return buf.toString(); }
From source file:org.soaplab.clients.spinet.Service.java
/************************************************************************* * *************************************************************************/ protected String createRadioPair(String name, String defaultValue) { StringBuilder buf = new StringBuilder(); boolean checked = BooleanUtils.toBoolean(defaultValue); buf.append("yes "); buf.append(createRadio(name, null, "yes", checked)); buf.append(" no "); buf.append(createRadio(name, null, "no", !checked)); String strippedName = name.substring(0, name.indexOf(S_S)); if (checked) { buf.append(h.hidden(strippedName + S_DEFAULTVALUE, "yes")); } else {// w w w . j ava2 s . c om buf.append(h.hidden(strippedName + S_DEFAULTVALUE, "no")); } return buf.toString(); }
From source file:org.soaplab.services.cmdline.BaseParameter.java
/************************************************************************* * Extract and return value for this parameter from 'inputs', or * from default. If there is no input for this parameter, return * false./*from ww w .j av a 2 s . c o m*/ * * TBD: Perhaps it should be changed to String[] getValues(...), * returning an empty array if none inputs, and one element of a * boolean character if an input found (as it is with other types * of parameters). *************************************************************************/ protected boolean getValue(Map<String, Object> inputs) throws ParameterException { // get value (real or from default) Object objValue = ignoreArray(inputs.get(paramDef.id)); if (objValue != null && StringUtils.isNotBlank(objValue.toString())) { return BooleanUtils.toBoolean(objValue.toString()); } else { return BooleanUtils.toBoolean(getDefaultValue()); } }