List of usage examples for org.apache.commons.lang StringUtils endsWithIgnoreCase
public static boolean endsWithIgnoreCase(String str, String suffix)
Case insensitive check if a String ends with a specified suffix.
From source file:com.tesora.dve.sql.parser.TranslatorUtils.java
public SetExpression buildSetVariableExpression(VariableInstance v, List<ExpressionNode> l) { if (StringUtils.endsWithIgnoreCase(v.getVariableName().get(), "NAMES")) { // validate NAME variable is one of our supported ones // should only be one item in l if (l.get(0) instanceof LiteralExpression) { LiteralExpression le = (LiteralExpression) l.get(0); if (le.isNullLiteral()) { throw new SchemaException(Pass.FIRST, "Must specify a character set"); }//from w w w . jav a2s. c om String value = (String) le.getValue(pc.getValues()); if (Singletons.require(CharSetNative.class).getCharSetCatalog().findCharSetByName(value) == null) { // character set not supported throw new SchemaException(Pass.FIRST, "Cannot set an unsupported character set: " + value); } } } if (l.size() == 1) return new SetVariableExpression(v, l.get(0)); return new SetVariableExpression(v, l); }
From source file:net.triptech.metahive.model.KeyValue.java
/** * Gets the formatted value./*w ww.ja va 2s.c o m*/ * * @param includeUnits the include units flag * @return the value */ private String getValue(final boolean includeUnits) { if (this.getDefinition() == null) { throw new NullPointerException("A valid definition is required"); } if (this.getContext() == null) { throw new NullPointerException("A valid application context is required"); } // The default value is authorisation required String value = context.getMessage("label_net_triptech_metahive_model_keyvalue_access_restricted", null, LocaleContextHolder.getLocale()); if (UserRole.allowAccess(this.getUserRole(), definition.getKeyValueAccess())) { value = context.getMessage("label_net_triptech_metahive_model_keyvalue_no_data", null, LocaleContextHolder.getLocale()); if (this.getDefinition().getDataType() == DataType.TYPE_STRING) { if (this.getStringValue() != null) { value = this.getStringValue(); if (includeUnits) { value += appendUnitOfMeasure(); } } } if (this.getDefinition().getDataType() == DataType.TYPE_BOOLEAN) { if (this.getBooleanValue() != null && this.getContext() != null) { value = context.getMessage(this.getBooleanValue().getMessageKey(), null, LocaleContextHolder.getLocale()); } } if (this.getDefinition().getDataType() == DataType.TYPE_NUMBER || this.getDefinition().getDataType() == DataType.TYPE_PERCENTAGE) { if (this.getDoubleValue() != null) { DecimalFormat df = new DecimalFormat("#.######"); value = df.format(this.getDoubleValue()); if (StringUtils.endsWithIgnoreCase(value, ".000000")) { value = StringUtils.substring(value, 0, value.length() - 6); } if (this.getDefinition().getDataType() == DataType.TYPE_PERCENTAGE) { value += "%"; } if (includeUnits) { value += appendUnitOfMeasure(); } } } if (this.getDefinition().getDataType() == DataType.TYPE_CURRENCY) { if (this.getDoubleValue() != null) { DecimalFormat df = new DecimalFormat("$###,###,###,##0.00"); value = df.format(this.getDoubleValue()) + appendUnitOfMeasure(); } } } return value; }
From source file:net.triptech.metahive.model.SubmittedField.java
/** * Gets the formatted value./*from ww w .jav a2 s. co m*/ * * @return the formatted value */ public final String getFormattedValue() { String unformattedValue = ""; String formattedValue = ""; if (this.getDefinition() == null) { throw new NullPointerException("A valid definition is required"); } if (StringUtils.isNotBlank(this.getValue())) { unformattedValue = this.getValue(); } if (this.getDefinition().getDataType() == DataType.TYPE_STRING) { formattedValue = unformattedValue + appendUnitOfMeasure(); } if (this.getDefinition().getDataType() == DataType.TYPE_BOOLEAN) { formattedValue = unformattedValue; } if (this.getDefinition().getDataType() == DataType.TYPE_NUMBER || this.getDefinition().getDataType() == DataType.TYPE_PERCENTAGE) { double dblValue = 0; try { dblValue = Double.parseDouble(unformattedValue); } catch (NumberFormatException nfe) { // Error parsing double } DecimalFormat df = new DecimalFormat("#.######"); formattedValue = df.format(dblValue); if (StringUtils.endsWithIgnoreCase(formattedValue, ".000000")) { formattedValue = StringUtils.substring(formattedValue, 0, formattedValue.length() - 6); } if (this.getDefinition().getDataType() == DataType.TYPE_PERCENTAGE) { formattedValue += "%"; } formattedValue += appendUnitOfMeasure(); } if (this.getDefinition().getDataType() == DataType.TYPE_CURRENCY) { double dblValue = 0; try { dblValue = Double.parseDouble(unformattedValue); } catch (NumberFormatException nfe) { // Error parsing double } DecimalFormat df = new DecimalFormat("$###,###,###,##0.00"); formattedValue = df.format(dblValue) + appendUnitOfMeasure(); } return formattedValue; }
From source file:net.ymate.framework.core.util.WebUtils.java
public static IView buildErrorView(IWebMvc owner, int code, String msg, String redirectUrl, int timeInterval, Map<String, Object> data) { IView _view = null;//from ww w. j av a 2s . c om String _errorViewPath = StringUtils .defaultIfEmpty(owner.getOwner().getConfig().getParam(Optional.ERROR_VIEW), "error.jsp"); if (StringUtils.endsWithIgnoreCase(_errorViewPath, ".ftl")) { _view = View.freemarkerView(owner, _errorViewPath); } else if (StringUtils.endsWithIgnoreCase(_errorViewPath, ".vm")) { _view = View.velocityView(owner, _errorViewPath); } else { _view = View.jspView(owner, _errorViewPath); } _view.addAttribute("ret", code); _view.addAttribute("msg", msg); if (data != null && !data.isEmpty()) { _view.addAttribute("data", data); } // if (StringUtils.isNotBlank(redirectUrl) && timeInterval > 0) { _view.addHeader("REFRESH", timeInterval + ";URL=" + redirectUrl); } // return _view; }
From source file:ninja.text.TextImpl.java
@Override public boolean endsWithAnyIgnoreCase(Text... candidate) { String str = data.toString(); for (Text candidate1 : candidate) { if (StringUtils.endsWithIgnoreCase(str, String.valueOf(candidate1))) { return true; }/* ww w . j ava2 s . c o m*/ } return false; }
From source file:ninja.text.TextImpl.java
@Override public boolean endsWithAnyIgnoreCase(CharSequence... candidate) { String str = data.toString(); for (CharSequence candidate1 : candidate) { if (StringUtils.endsWithIgnoreCase(str, String.valueOf(candidate1))) { return true; }//from ww w. j a va2 s . c om } return false; }
From source file:ninja.text.TextImpl.java
@Override public boolean endsWithIgnoreCase(CharSequence text) { return StringUtils.endsWithIgnoreCase(data.toString(), text.toString()); }
From source file:nl.nn.adapterframework.webcontrol.api.SendJmsMessage.java
@POST @Path("jms/message") @Produces(MediaType.APPLICATION_JSON)/*from w w w . j ava 2 s . c o m*/ @Consumes(MediaType.MULTIPART_FORM_DATA) public Response putJmsMessage(MultipartFormDataInput input) throws ApiException { initBase(servletConfig); String jmsRealm = null, destinationName = null, destinationType = null, replyTo = null, message = null, fileName = null; InputStream file = null; boolean persistent = false; Map<String, List<InputPart>> inputDataMap = input.getFormDataMap(); if (inputDataMap == null) { throw new ApiException("Missing post parameters"); } try { if (inputDataMap.get("realm") != null) jmsRealm = inputDataMap.get("realm").get(0).getBodyAsString(); else throw new ApiException("JMS realm not defined", 400); if (inputDataMap.get("destination") != null) destinationName = inputDataMap.get("destination").get(0).getBodyAsString(); else throw new ApiException("Destination name not defined", 400); if (inputDataMap.get("type") != null) destinationType = inputDataMap.get("type").get(0).getBodyAsString(); else throw new ApiException("Destination type not defined", 400); if (inputDataMap.get("replyTo") != null) replyTo = inputDataMap.get("replyTo").get(0).getBodyAsString(); else throw new ApiException("ReplyTo not defined", 400); if (inputDataMap.get("message") != null) message = inputDataMap.get("message").get(0).getBodyAsString(); if (inputDataMap.get("persistent") != null) persistent = inputDataMap.get("persistent").get(0).getBody(boolean.class, null); if (inputDataMap.get("file") != null) file = inputDataMap.get("file").get(0).getBody(InputStream.class, null); } catch (IOException e) { throw new ApiException("Failed to parse one or more parameters!"); } try { if (file != null) { MultivaluedMap<String, String> headers = inputDataMap.get("file").get(0).getHeaders(); String[] contentDispositionHeader = headers.getFirst("Content-Disposition").split(";"); for (String name : contentDispositionHeader) { if ((name.trim().startsWith("filename"))) { String[] tmp = name.split("="); fileName = tmp[1].trim().replaceAll("\"", ""); } } if (StringUtils.endsWithIgnoreCase(fileName, ".zip")) { processZipFile(file, jmsBuilder(jmsRealm, destinationName, persistent, destinationType), replyTo); message = null; } else { message = XmlUtils.readXml(Misc.streamToBytes(file), Misc.DEFAULT_INPUT_STREAM_ENCODING, false); } } else { message = new String(message.getBytes(), Misc.DEFAULT_INPUT_STREAM_ENCODING); } } catch (Exception e) { throw new ApiException("Failed to read message: " + e.getMessage()); } if (message != null && message.length() > 0) { JmsSender qms = jmsBuilder(jmsRealm, destinationName, persistent, destinationType); if ((replyTo != null) && (replyTo.length() > 0)) qms.setReplyToName(replyTo); processMessage(qms, "testmsg_" + Misc.createUUID(), message); return Response.status(Response.Status.OK).build(); } else { return Response.status(Response.Status.BAD_REQUEST).build(); } }
From source file:nl.nn.adapterframework.webcontrol.api.TestPipeline.java
@POST @RolesAllowed({ "ObserverAccess", "IbisTester" }) @Path("/test-pipeline") @Produces(MediaType.APPLICATION_JSON)//from ww w . j a va 2 s . co m @Consumes(MediaType.MULTIPART_FORM_DATA) public Response postTestPipeLine(MultipartFormDataInput input) throws ApiException, PipeRunException { Map<String, Object> result = new HashMap<String, Object>(); IbisManager ibisManager = getIbisManager(); if (ibisManager == null) { throw new ApiException("Config not found!"); } boolean writeSecLogMessage = (Boolean) (secLogEnabled && secLogMessage); String message = null, fileEncoding = null, fileName = null; InputStream file = null; IAdapter adapter = null; Map<String, List<InputPart>> inputDataMap = input.getFormDataMap(); try { if (inputDataMap.get("message") != null) message = inputDataMap.get("message").get(0).getBodyAsString(); if (inputDataMap.get("encoding") != null) fileEncoding = inputDataMap.get("encoding").get(0).getBodyAsString(); if (inputDataMap.get("adapter") != null) { String adapterName = inputDataMap.get("adapter").get(0).getBodyAsString(); adapter = ibisManager.getRegisteredAdapter(adapterName); } if (inputDataMap.get("file") != null) { file = inputDataMap.get("file").get(0).getBody(InputStream.class, null); MultivaluedMap<String, String> headers = inputDataMap.get("file").get(0).getHeaders(); String[] contentDispositionHeader = headers.getFirst("Content-Disposition").split(";"); for (String name : contentDispositionHeader) { if ((name.trim().startsWith("filename"))) { String[] tmp = name.split("="); fileName = tmp[1].trim().replaceAll("\"", ""); } } if (fileEncoding == null || fileEncoding.isEmpty()) fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING; if (StringUtils.endsWithIgnoreCase(fileName, ".zip")) { try { processZipFile(result, file, fileEncoding, adapter, writeSecLogMessage); } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(null) + "exception on processing zip file", e); } } else { message = Misc.streamToString(file, "\n", fileEncoding, false); } } } catch (IOException e) { return Response.status(Response.Status.BAD_REQUEST).build(); } if (fileEncoding == null || StringUtils.isEmpty(fileEncoding)) fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING; if (adapter == null && (message == null && file == null)) { return Response.status(Response.Status.BAD_REQUEST).build(); } if (StringUtils.isNotEmpty(message)) { try { PipeLineResult plr = processMessage(adapter, message, writeSecLogMessage); result.put("state", plr.getState()); result.put("result", plr.getResult()); } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(null) + "exception on sending message", e); } } return Response.status(Response.Status.CREATED).entity(result).build(); }
From source file:nl.nn.adapterframework.webcontrol.pipes.TestIfsaService.java
private String doPost(IPipeLineSession session) throws PipeRunException { Object form_file = session.get("file"); String form_message = null;/* ww w . j a va 2s .co m*/ form_message = (String) session.get("message"); if (form_file == null && (StringUtils.isEmpty(form_message))) { throw new PipeRunException(this, getLogPrefix(session) + "Nothing to send or test"); } String form_applicationId = (String) session.get("applicationId"); String form_serviceId = (String) session.get("serviceId"); String form_messageProtocol = (String) session.get("messageProtocol"); if (form_file != null) { if (form_file instanceof InputStream) { InputStream inputStream = (InputStream) form_file; String form_fileName = (String) session.get("fileName"); String form_fileEncoding = (String) session.get("fileEncoding"); try { if (inputStream.available() > 0) { String fileEncoding; if (StringUtils.isNotEmpty(form_fileEncoding)) { fileEncoding = form_fileEncoding; } else { fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING; } if (StringUtils.endsWithIgnoreCase(form_fileName, ".zip")) { try { form_message = processZipFile(session, inputStream, fileEncoding, form_applicationId, form_serviceId, form_messageProtocol); } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(session) + "exception on processing zip file", e); } } else { form_message = Misc.streamToString(inputStream, "\n", fileEncoding, false); } } } catch (IOException e) { throw new PipeRunException(this, getLogPrefix(session) + "exception on converting stream to string", e); } } else { form_message = form_file.toString(); } session.put("message", form_message); } if (StringUtils.isNotEmpty(form_message)) { try { String result = processMessage(form_applicationId, form_serviceId, form_messageProtocol, form_message); session.put("result", result); } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(session) + "exception on sending message", e); } } return "<dummy/>"; }