List of usage examples for org.apache.commons.lang3 StringUtils endsWithIgnoreCase
public static boolean endsWithIgnoreCase(final CharSequence str, final CharSequence suffix)
Case insensitive check if a CharSequence ends with a specified suffix.
null s are handled without exceptions.
From source file:com.nridge.core.base.io.xml.DocumentListXML.java
/** * Parses an XML DOM element and loads it into a bag list. * * @param anElement DOM element.//from w ww. j av a 2s .c o m * @throws java.io.IOException I/O related exception. */ @Override public void load(Element anElement) throws IOException { Node nodeItem; String nodeName; Document document; Element nodeElement; DocumentXML documentXML; nodeName = anElement.getNodeName(); if (StringUtils.endsWithIgnoreCase(nodeName, IO.XML_LIST_NODE_NAME)) { NodeList nodeList = anElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { nodeItem = nodeList.item(i); if (nodeItem.getNodeType() != Node.ELEMENT_NODE) continue; // We really do not know how the node was named, so we will just accept it. nodeElement = (Element) nodeItem; documentXML = new DocumentXML(); documentXML.load(nodeElement); document = documentXML.getDocument(); if (document != null) mDocumentList.add(document); } } }
From source file:com.nridge.core.base.io.xml.DataBagListXML.java
/** * Parses an XML DOM element and loads it into a bag list. * * @param anElement DOM element./*from www.j av a2s . c om*/ * @throws java.io.IOException I/O related exception. */ @Override public void load(Element anElement) throws IOException { Node nodeItem; String nodeName; DataBag dataBag; Element nodeElement; DataBagXML dataBagXML; nodeName = anElement.getNodeName(); if (StringUtils.endsWithIgnoreCase(nodeName, "List")) { NodeList nodeList = anElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { nodeItem = nodeList.item(i); if (nodeItem.getNodeType() != Node.ELEMENT_NODE) continue; nodeName = nodeItem.getNodeName(); if (StringUtils.endsWithIgnoreCase(nodeName, "DataBag")) { nodeElement = (Element) nodeItem; dataBagXML = new DataBagXML(); dataBagXML.load(nodeElement); dataBag = dataBagXML.getBag(); if (dataBag != null) mDataBagList.add(dataBag); } } } }
From source file:com.mnxfst.stream.pipeline.PipelineRoot.java
/** * @see akka.actor.UntypedActor#preStart() *//* w ww. j av a2s . com*/ public void preStart() throws Exception { context().system().log().info("init start [pipeline=" + pipelineConfiguration.getPipelineId() + "]"); boolean failed = false; String pipelineId = pipelineConfiguration.getPipelineId(); PipelineElementReferenceUpdateMessage refUpdateMessage = new PipelineElementReferenceUpdateMessage( pipelineId); // iterate through pipeline element configurations and instantiate a new node for each for (final PipelineElementConfiguration cfg : pipelineConfiguration.getElements()) { // extract required values into variables for faster access ... obviously, ehhh ;-) String elementId = cfg.getElementId(); String description = cfg.getDescription(); String elementClassName = cfg.getElementClass(); ////////////////////////////////////////////////////////////////////////////////////// // ensure that the element does not exist if (this.pipelineElements.containsKey(elementId)) { reportInitError(pipelineId, elementId, elementClassName, PipelineElementSetupFailedMessage.NON_UNIQUE_ELEMENT_ID, "Element id '" + elementId + "' already in use"); failed = true; break; } // ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// // initialize element context().system().log().info("init start [pipeline=" + pipelineId + ", element=" + elementId + ", description=" + description + ", class=" + elementClassName + "]"); try { final ActorRef elementRef = context().actorOf(Props.create(Class.forName(elementClassName), cfg), elementId); this.pipelineElements.put(elementId, elementRef); refUpdateMessage.addElementReference(elementId, elementRef); if (this.initialMessageReceiverRef == null && StringUtils.endsWithIgnoreCase(elementId, pipelineConfiguration.getInitialReceiverId())) this.initialMessageReceiverRef = elementRef; } catch (ClassNotFoundException e) { reportInitError(pipelineId, elementId, elementClassName, PipelineElementSetupFailedMessage.CLASS_NOT_FOUND, "Class not found"); failed = true; break; } catch (Exception e) { reportInitError(pipelineId, elementId, elementClassName, PipelineElementSetupFailedMessage.GENERAL, e.getMessage()); failed = true; break; } context().system().log().info("init done [pipeline=" + pipelineId + ", element=" + elementId + ", description=" + description + ", class=" + elementClassName + "]"); } if (this.initialMessageReceiverRef == null) { reportInitError(pipelineId, pipelineConfiguration.getInitialReceiverId(), "null", PipelineElementSetupFailedMessage.INITIAL_MESSAGE_RECEIVER_NOT_FOUND, "Referenced initial message receiver not found"); failed = true; } if (failed) context().system().log().info("init failed [pipeline=" + pipelineId + "]"); else { context().system().log().info( "init done [pipeline=" + pipelineId + ", elementCount=" + this.pipelineElements.size() + "]"); context().parent().tell(new PipelineRootInitializedMessage(pipelineId), getSelf()); // notify all children about each other for (final ActorRef pipelineElementRef : this.pipelineElements.values()) { pipelineElementRef.tell(refUpdateMessage, getSelf()); } } }
From source file:com.nridge.core.app.mgr.ServiceTimer.java
private Date getNextTS(String aFieldName, Date aTS) { String timeString = getAppString(aFieldName); if (StringUtils.isNotEmpty(timeString)) { if (StringUtils.endsWithIgnoreCase(timeString, "m")) { String minuteString = StringUtils.stripEnd(timeString, "m"); if ((StringUtils.isNotEmpty(minuteString)) && (StringUtils.isNumeric(minuteString))) { int minuteAmount = Integer.parseInt(minuteString); return DateUtils.addMinutes(aTS, minuteAmount); }//from w ww. j a va 2s. c om } else if (StringUtils.endsWithIgnoreCase(timeString, "h")) { String hourString = StringUtils.stripEnd(timeString, "h"); if ((StringUtils.isNotEmpty(hourString)) && (StringUtils.isNumeric(hourString))) { int hourAmount = Integer.parseInt(hourString); return DateUtils.addHours(aTS, hourAmount); } } else // we assume days { String dayString = StringUtils.stripEnd(timeString, "d"); if ((StringUtils.isNotEmpty(dayString)) && (StringUtils.isNumeric(dayString))) { int dayAmount = Integer.parseInt(dayString); return DateUtils.addDays(aTS, dayAmount); } } } // Push 1 hour ahead to avoid triggering a match with TS return DateUtils.addHours(new Date(), 1); }
From source file:com.sketchy.utils.image.SketchyImage.java
public static SketchyImage load(File file) throws Exception { SketchyImage sketchyImage = null;//www .java 2s. c om if (!file.exists() || !file.canRead()) { throw new Exception("Can not find or read File: " + file.getPath() + "!"); } if (!StringUtils.endsWithIgnoreCase(file.getName(), ".png")) { throw new Exception("Can not load SketchyImage! Must be a .png file!"); } Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByFormatName("png"); ImageReader imageReader = null; if (imageReaders.hasNext()) { // Just get first one imageReader = imageReaders.next(); } if (imageReader == null) { // this should never happen!! if so.. we got problems throw new Exception("Can not find ImageReader for .png Files!"); } ImageInputStream is = null; try { is = ImageIO.createImageInputStream(file); imageReader.setInput(is, true); IIOMetadata metaData = imageReader.getImageMetadata(0); // always get first image IIOMetadataNode metaDataNode = (IIOMetadataNode) metaData .getAsTree(metaData.getNativeMetadataFormatName()); if (metaDataNode == null) { throw new Exception("Error retreiving MetaData properties from .png File!"); } NodeList childNodes = metaDataNode.getElementsByTagName("pHYs"); // only look in the first node if (childNodes.getLength() == 0) { throw new Exception("Invalid SketchyImage file. It must contain 'pixelsPerUnit' MetaData!"); } IIOMetadataNode physNode = (IIOMetadataNode) childNodes.item(0); String pixelsPerUnitXAxisAttribute = physNode.getAttribute("pixelsPerUnitXAxis"); String pixelsPerUnitYAxisAttribute = physNode.getAttribute("pixelsPerUnitYAxis"); // String unitSpecifierAttribute = physNode.getAttribute("unitSpecifier"); Just assuming meter if (StringUtils.isBlank(pixelsPerUnitXAxisAttribute)) { throw new Exception("Invalid SketchyImage file. It must contain 'pixelsPerUnitXAxis' MetaData!"); } if (StringUtils.isBlank(pixelsPerUnitYAxisAttribute)) { throw new Exception("Invalid SketchyImage file. It must contain 'pixelsPerUnitYAxis' MetaData!"); } int pixelsPerUnitXAxis; try { pixelsPerUnitXAxis = Integer.parseInt(pixelsPerUnitXAxisAttribute); if (pixelsPerUnitXAxis <= 0) throw new Exception("Value must be > 0"); } catch (Exception e) { throw new Exception("Invalid 'pixelsPerUnitXAxis' MetaData Attribute! " + e.getMessage()); } int pixelsPerUnitYAxis; try { pixelsPerUnitYAxis = Integer.parseInt(pixelsPerUnitYAxisAttribute); if (pixelsPerUnitYAxis <= 0) throw new Exception("Value must be > 0"); } catch (Exception e) { throw new Exception("Invalid 'pixelsPerUnitYAxis' MetaData Attribute! " + e.getMessage()); } // We successfully processed the MetaData.. now read/set the image BufferedImage bufferedImage = imageReader.read(0); // always get first image double xPixelsPerMM = pixelsPerUnitXAxis / 1000.0; double yPixelsPerMM = pixelsPerUnitYAxis / 1000.0; sketchyImage = new SketchyImage(bufferedImage, xPixelsPerMM, yPixelsPerMM); } catch (Exception e) { throw new Exception("Error Loading SketchyImage File: " + file.getPath() + "! " + e.getMessage()); } finally { IOUtils.closeQuietly(is); } return sketchyImage; }
From source file:forge.gui.ImportSourceAnalyzer.java
private void analyzeDecksDir(final File root) { analyzeDir(root, new Analyzer() { @Override//from w ww . java 2s .c o m void onFile(final File file) { // we don't really expect any files in here, but if we find a .dck file, add it to the unknown list final String filename = file.getName(); if (StringUtils.endsWithIgnoreCase(filename, ".dck")) { final File targetFile = new File(lcaseExt(filename)); cb.addOp(OpType.UNKNOWN_DECK, file, targetFile); } } @Override boolean onDir(final File dir) { final String dirname = dir.getName(); if ("constructed".equalsIgnoreCase(dirname)) { analyzeConstructedDeckDir(dir); } else if ("cube".equalsIgnoreCase(dirname)) { return false; } else if ("draft".equalsIgnoreCase(dirname)) { analyzeDraftDeckDir(dir); } else if ("plane".equalsIgnoreCase(dirname) || "planar".equalsIgnoreCase(dirname)) { analyzePlanarDeckDir(dir); } else if ("scheme".equalsIgnoreCase(dirname)) { analyzeSchemeDeckDir(dir); } else if ("sealed".equalsIgnoreCase(dirname)) { analyzeSealedDeckDir(dir); } else { analyzeKnownDeckDir(dir, null, OpType.UNKNOWN_DECK); } return true; } }); }
From source file:com.evolveum.polygon.connector.hcm.FilterHandler.java
private Boolean evaluateAttributeFilter(AttributeFilter filter, String filterType, String p) { // LOGGER.ok("Processing trough {0} ", filter); if (p == null || p.isEmpty()) { return true; } else {/*from w w w. j a v a 2 s .com*/ String endTagName = ""; String evaluatedValue = ""; String uidAttributeName = ""; String heplerVariableParts[] = p.split(DELIMITER); if (heplerVariableParts.length != 3) { return true; } else { endTagName = heplerVariableParts[0]; evaluatedValue = heplerVariableParts[1]; uidAttributeName = heplerVariableParts[2]; } Attribute attribute = filter.getAttribute(); String attributeValue = AttributeUtil.getAsStringValue(attribute); String attributeName = attribute.getName(); if ((attributeName.equals(UID) && uidAttributeName.equals(endTagName)) || attributeName.equals(endTagName)) { if (EQUALS.equals(filterType)) { if (!attributeValue.equals(evaluatedValue)) { return false; } } else if (CONTAINS.equals(filterType)) { if (!StringUtils.containsIgnoreCase(evaluatedValue, attributeValue)) { return false; } } else if (STARTSWITH.equals(filterType)) { if (!StringUtils.startsWithIgnoreCase(evaluatedValue, attributeValue)) { return false; } } else if (ENDSWITH.equals(filterType)) { if (!StringUtils.endsWithIgnoreCase(evaluatedValue, attributeValue)) { return false; } } } } return true; }
From source file:com.glaf.core.web.springmvc.MxSystemDbTableController.java
@ResponseBody @RequestMapping("/exportData") public void exportData(HttpServletRequest request, HttpServletResponse response) throws IOException { StringBuffer sb = new StringBuffer(); String tables = request.getParameter("exportTables"); String dbType = request.getParameter("dbType"); if (StringUtils.isNotEmpty(dbType) && StringUtils.isNotEmpty(tables)) { List<String> list = StringTools.split(tables); for (String tablename : list) { if (StringUtils.isNotEmpty(tablename)) { if (StringUtils.endsWithIgnoreCase(tablename, "log")) { continue; }/* w ww . j a v a 2 s . c o m*/ logger.debug("process table:" + tablename); List<ColumnDefinition> columns = DBUtils.getColumnDefinitions(tablename); TablePageQuery query = new TablePageQuery(); query.tableName(tablename); query.firstResult(0); query.maxResults(20000); int count = tablePageService.getTableCount(query); if (count <= 20000) { List<Map<String, Object>> rows = tablePageService.getTableData(query); if (rows != null && !rows.isEmpty()) { for (Map<String, Object> dataMap : rows) { Map<String, Object> lowerMap = QueryUtils.lowerKeyMap(dataMap); sb.append(" insert into ").append(tablename).append(" ("); for (int i = 0, len = columns.size(); i < len; i++) { ColumnDefinition column = columns.get(i); sb.append(column.getColumnName().toLowerCase()); if (i < columns.size() - 1) { sb.append(", "); } } sb.append(" ) values ("); for (int i = 0, len = columns.size(); i < len; i++) { ColumnDefinition column = columns.get(i); Object value = lowerMap.get(column.getColumnName().toLowerCase()); if (value != null) { if (value instanceof Short) { sb.append(value); } else if (value instanceof Integer) { sb.append(value); } else if (value instanceof Long) { sb.append(value); } else if (value instanceof Double) { sb.append(value); } else if (value instanceof String) { String str = (String) value; str = StringTools.replace(str, "'", "''"); sb.append("'").append(str).append("'"); } else if (value instanceof Date) { Date date = (Date) value; if (StringUtils.equalsIgnoreCase(dbType, "oracle")) { sb.append(" to_date('").append(DateUtils.getDateTime(date)) .append("', 'yyyy-mm-dd hh24:mi:ss')"); } else if (StringUtils.equalsIgnoreCase(dbType, "db2")) { sb.append(" TO_DATE('").append(DateUtils.getDateTime(date)) .append("', ''YYY-MM-DD HH24:MI:SS')"); } else { sb.append("'").append(DateUtils.getDateTime(date)).append("'"); } } else { String str = value.toString(); str = StringTools.replace(str, "'", "''"); sb.append("'").append(str).append("'"); } } else { sb.append("null"); } if (i < columns.size() - 1) { sb.append(", "); } } sb.append(");"); sb.append(FileUtils.newline); } } } sb.append(FileUtils.newline); sb.append(FileUtils.newline); } } } try { ResponseUtils.download(request, response, sb.toString().getBytes(), "insert_" + DateUtils.getDate(new Date()) + "." + dbType + ".sql"); } catch (ServletException ex) { ex.printStackTrace(); } }
From source file:net.sf.jsignpdf.Signer.java
/** * Sign the files/*from www.j a v a2 s. co m*/ * * @param anOpts */ private static void signFiles(SignerOptionsFromCmdLine anOpts) { final SignerLogic tmpLogic = new SignerLogic(anOpts); if (ArrayUtils.isEmpty(anOpts.getFiles())) { // we've used -lp (loadproperties) parameter if (!tmpLogic.signFile()) { exit(Constants.EXIT_CODE_ALL_SIG_FAILED); } return; } int successCount = 0; int failedCount = 0; for (final String wildcardPath : anOpts.getFiles()) { final File wildcardFile = new File(wildcardPath); File[] inputFiles; if (StringUtils.containsAny(wildcardFile.getName(), '*', '?')) { final File inputFolder = wildcardFile.getAbsoluteFile().getParentFile(); final FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(wildcardFile.getName())); inputFiles = inputFolder.listFiles(fileFilter); if (inputFiles == null) { continue; } } else { inputFiles = new File[] { wildcardFile }; } for (File inputFile : inputFiles) { final String tmpInFile = inputFile.getPath(); if (!inputFile.canRead()) { failedCount++; System.err.println(RES.get("file.notReadable", new String[] { tmpInFile })); continue; } anOpts.setInFile(tmpInFile); String tmpNameBase = inputFile.getName(); String tmpSuffix = ".pdf"; if (StringUtils.endsWithIgnoreCase(tmpNameBase, tmpSuffix)) { tmpSuffix = StringUtils.right(tmpNameBase, 4); tmpNameBase = StringUtils.left(tmpNameBase, tmpNameBase.length() - 4); } final StringBuilder tmpName = new StringBuilder(anOpts.getOutPath()); tmpName.append(anOpts.getOutPrefix()); tmpName.append(tmpNameBase).append(anOpts.getOutSuffix()).append(tmpSuffix); String outFile = anOpts.getOutFile(); if (outFile == null) anOpts.setOutFile(tmpName.toString()); if (tmpLogic.signFile()) { successCount++; } else { failedCount++; } } } if (failedCount > 0) { exit(successCount > 0 ? Constants.EXIT_CODE_SOME_SIG_FAILED : Constants.EXIT_CODE_ALL_SIG_FAILED); } }
From source file:forge.gui.ImportSourceAnalyzer.java
private void analyzeKnownDeckDir(final File root, final String targetDir, final OpType opType) { analyzeDir(root, new Analyzer() { @Override//from w w w . j a v a2 s . c o m void onFile(final File file) { final String filename = file.getName(); if (StringUtils.endsWithIgnoreCase(filename, ".dck")) { final File targetFile = new File(targetDir, lcaseExt(filename)); if (!file.equals(targetFile)) { cb.addOp(opType, file, targetFile); } } } @Override boolean onDir(final File dir) { // if there's a dir beneath a known directory, assume the same kind of decks are in there analyzeKnownDeckDir(dir, targetDir, opType); return true; } }); }