List of usage examples for org.apache.commons.lang3 StringUtils endsWith
public static boolean endsWith(final CharSequence str, final CharSequence suffix)
Check if a CharSequence ends with a specified suffix.
null s are handled without exceptions.
From source file:org.kuali.rice.xml.ingest.IngestXmlExecutable.java
protected List<XmlDocCollection> getXmlDocCollectionList(List<String> locationListings) { List<XmlDocCollection> list = Lists.newArrayList(); List<String> locations = LocationUtils.getLocations(locationListings); for (String location : locations) { Preconditions.checkState(StringUtils.endsWith(location.toLowerCase(), XML_SUFFIX), "[%s] is not an XML document", location); Preconditions.checkState(LocationUtils.exists(location), "[%s] does not exist", location); logger.info("[{}]", location); XmlDocCollection element = new LocationXmlDocCollection(location); list.add(element);//from w ww . ja v a2s .co m } return list; }
From source file:org.lazulite.boot.autoconfigure.core.utils.excel.ImportExcel.java
/** * ??/*from ww w.jav a 2 s .co m*/ * * @param cls * @param groups */ public <E> List<E> getDataList(Class<E> cls, int... groups) throws InstantiationException, IllegalAccessException { List<Object[]> annotationList = Lists.newArrayList(); // Get annotation field Field[] fs = cls.getDeclaredFields(); for (Field f : fs) { ExcelField ef = f.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, f }); break; } } } } else { annotationList.add(new Object[] { ef, f }); } } } // Get annotation method Method[] ms = cls.getDeclaredMethods(); for (Method m : ms) { ExcelField ef = m.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, m }); break; } } } } else { annotationList.add(new Object[] { ef, m }); } } } // Field sorting Collections.sort(annotationList, new Comparator<Object[]>() { public int compare(Object[] o1, Object[] o2) { return new Integer(((ExcelField) o1[0]).sort()).compareTo(new Integer(((ExcelField) o2[0]).sort())); } ; }); //log.debug("Import column count:"+annotationList.size()); // Get excel data List<E> dataList = Lists.newArrayList(); for (int i = this.getDataRowNum(); i < this.getLastDataRowNum(); i++) { E e = (E) cls.newInstance(); int column = 0; Row row = this.getRow(i); StringBuilder sb = new StringBuilder(); for (Object[] os : annotationList) { Object val = this.getCellValue(row, column++); if (val != null) { ExcelField ef = (ExcelField) os[0]; // Get param type and type cast Class<?> valType = Class.class; if (os[1] instanceof Field) { valType = ((Field) os[1]).getType(); } else if (os[1] instanceof Method) { Method method = ((Method) os[1]); if ("get".equals(method.getName().substring(0, 3))) { valType = method.getReturnType(); } else if ("set".equals(method.getName().substring(0, 3))) { valType = ((Method) os[1]).getParameterTypes()[0]; } } //log.debug("Import value type: ["+i+","+column+"] " + valType); try { if (valType == String.class) { String s = String.valueOf(val.toString()); if (StringUtils.endsWith(s, ".0")) { val = StringUtils.substringBefore(s, ".0"); } else { val = String.valueOf(val.toString()); } } else if (valType == Integer.class) { val = Double.valueOf(val.toString()).intValue(); } else if (valType == Long.class) { val = Double.valueOf(val.toString()).longValue(); } else if (valType == Double.class) { val = Double.valueOf(val.toString()); } else if (valType == Float.class) { val = Float.valueOf(val.toString()); } else if (valType == Date.class) { val = DateUtil.getJavaDate((Double) val); } else { if (ef.fieldType() != Class.class) { val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString()); } else { val = Class .forName(this.getClass().getName().replaceAll( this.getClass().getSimpleName(), "fieldtype." + valType.getSimpleName() + "Type")) .getMethod("getValue", String.class).invoke(null, val.toString()); } } } catch (Exception ex) { log.info("Get cell value [" + i + "," + column + "] error: " + ex.toString()); val = null; } // set entity value if (os[1] instanceof Field) { ReflectUtils.invokeSetter(e, ((Field) os[1]).getName(), val); } else if (os[1] instanceof Method) { String mthodName = ((Method) os[1]).getName(); if ("get".equals(mthodName.substring(0, 3))) { mthodName = "set" + StringUtils.substringAfter(mthodName, "get"); } ReflectUtils.invokeMethod(e, mthodName, new Class[] { valType }, new Object[] { val }); } } sb.append(val + ", "); } dataList.add(e); log.debug("Read success: [" + i + "] " + sb.toString()); } return dataList; }
From source file:org.ligoj.app.plugin.prov.aws.in.ProvAwsPriceImportResource.java
private Double toPercent(String raw) { if (StringUtils.endsWith(raw, "%")) { return Double.valueOf(raw.substring(0, raw.length() - 1)); }//w w w. ja v a 2 s .com // Not a valid percent return null; }
From source file:org.maodian.flyingcat.netty.handler.XMLFragmentDecoder.java
@Override protected Object decode(ChannelHandlerContext ctx, String msg) throws Exception { if (StringUtils.endsWithAny(msg, INVALID_ELEMENT_TAILS)) { throw new XmppException(StreamError.RESTRICTED_XML).set("xml", msg); }//from ww w .jav a2s .c o m if (StringUtils.endsWith(msg, PROCESS_INSTRUCTION_TAIL) && !StringUtils.startsWith(msg, "<?xml ")) { throw new XmppException(StreamError.RESTRICTED_XML).set("xml", msg); } if (StringUtils.startsWithAny(msg, INVALID_ELEMENT_HEADS)) { throw new XmppException(StreamError.RESTRICTED_XML).set("xml", msg); } // always accept xml declaration to improve compability with some client if (StringUtils.startsWith(msg, "<?xml ")) { return msg; /*if (acceptXMLDeclaration) { acceptXMLDeclaration = false; return msg; } else { throw new XmppException("XML declaration has been already received before", StreamError.NOT_WELL_FORMED).set("xml", msg); }*/ } // deal with stream tag if (StringUtils.contains(msg, ":stream") && (StringUtils.contains(msg, "<") || StringUtils.contains(msg, "</"))) { if (depth != 0) { throw new XmppException("Stream Open/Close Tag can only be root element", StreamError.INVALID_XML); } return msg; } // deal with empty element at first level if (depth == 0 && StringUtils.endsWith(msg, "/>")) { return msg; } if (xml == null) { xml = new StringBuilder(msg); } else { xml.append(msg); } // deal with nested empty element if (StringUtils.endsWith(msg, "/>")) { return null; } if (StringUtils.contains(msg, "</")) { depth--; } else if (StringUtils.contains(msg, "<")) { depth++; } if (depth == 0) { String fragment = xml.toString(); xml = null; return fragment; } return null; }
From source file:org.meruvian.yama.service.jpa.JpaFileInfoManager.java
@Value("${upload.path}") public void setDefaultLocation(String defaultLocation) { defaultLocation = StringUtils.endsWith(defaultLocation, "/") ? defaultLocation : (defaultLocation + "/"); this.defaultLocation = defaultLocation; }
From source file:org.nanoframework.orm.jedis.AbstractRedisClient.java
protected Map<String, String> info0(final String info) { final String[] attributes = info.split("\n"); final Map<String, String> decodeInfo = Maps.newLinkedHashMap(); for (final String attribute : attributes) { if (!StringUtils.isEmpty(StringUtils.trim(attribute)) && !StringUtils.startsWith(attribute, "#")) { final String[] keyvalue = attribute.substring(0, attribute.length() - 1).split(":"); if (keyvalue.length == 2) { final String key = keyvalue[0]; final String value = StringUtils.endsWith(keyvalue[1], "\r") ? StringUtils.substring(keyvalue[1], 0, keyvalue[1].length() - 1) : keyvalue[1];/*from w w w . jav a2s .c om*/ decodeInfo.put(key, value); } else { decodeInfo.put(keyvalue[0], ""); } } } return decodeInfo; }
From source file:org.openmrs.module.openhmis.commons.api.CustomizedOrderBy.java
public static Order asc(String sqlFormula) { if (!StringUtils.endsWith(sqlFormula, " asc")) { sqlFormula += " asc"; }/*from ww w. j a v a 2s . co m*/ return new CustomizedOrderBy(sqlFormula); }
From source file:org.openmrs.module.openhmis.commons.api.CustomizedOrderBy.java
public static Order desc(String sqlFormula) { if (!StringUtils.endsWith(sqlFormula, " desc")) { sqlFormula += " desc"; }/*from w ww .j av a2 s . com*/ return new CustomizedOrderBy(sqlFormula); }
From source file:org.opensilk.music.App.java
boolean isServiceProcess() { return StringUtils.endsWith(getProcName(), ":service"); }
From source file:org.opensilk.music.App.java
boolean isUiProcess() { return StringUtils.endsWith(getProcName(), ":ui"); }