List of usage examples for org.apache.commons.lang StringUtils indexOfAny
public static int indexOfAny(String str, String[] searchStrs)
Find the first index of any of a set of potential substrings.
From source file:org.apache.directory.studio.common.core.jobs.StudioProgressMonitor.java
/** * Gets the error status.//from w ww . j a v a2 s. c o m * * @param message the message * * @return the error status */ public IStatus getErrorStatus(String message) { if ((errorStatusList == null) || errorStatusList.isEmpty()) { if (isCanceled()) { return Status.CANCEL_STATUS; } else { return Status.OK_STATUS; } } else { StringBuilder buffer = new StringBuilder(); buffer.append(message); // append status messages to message for (Status status : errorStatusList) { String statusMessage = status.getMessage(); Throwable exception = status.getException(); String exceptionMessage = null; if (exception != null) { exceptionMessage = exception.getMessage(); } // append explicit status message if (!StringUtils.isEmpty(statusMessage)) { buffer.append("\n - ").append(statusMessage); } // append exception message if different to status message if ((exception != null) && (exceptionMessage != null) && !exceptionMessage.equals(statusMessage)) { // strip control characters int indexOfAny = StringUtils.indexOfAny(exceptionMessage, "\n\r\t"); //$NON-NLS-1$ if (indexOfAny > -1) { exceptionMessage = exceptionMessage.substring(0, indexOfAny - 1); } buffer.append("\n - ").append(exceptionMessage); //$NON-NLS-1$ } } // create main status MultiStatus multiStatus = new MultiStatus(pluginId, IStatus.ERROR, buffer.toString(), null); // append child status for (Status status : errorStatusList) { String statusMessage = status.getMessage(); if (status.getException() != null) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); status.getException().printStackTrace(printWriter); statusMessage = stringWriter.toString(); } multiStatus.add(new Status(status.getSeverity(), status.getPlugin(), status.getCode(), statusMessage, status.getException())); } return multiStatus; } }
From source file:org.apache.ojb.broker.util.SqlHelper.java
/** * Split a path into column , prefix and suffix, the prefix contains all * info up to the column <br>/*www .j a va 2 s . com*/ * ie: avg(amount) -> amount , avg( , )<br> * ie: sum (accounts.amount) as theSum -> accounts.amount , sum( , ) as * theSum <br> * ie: count( distinct id ) as bla -> id , count(distinct , ) as bla <br> * Supports simple expressions ie: price * 1.05 * * TODO: cannot resolve multiple attributes in expression * ie: price - bonus * * @param aPath * @return PathInfo */ public static PathInfo splitPath(String aPath) { String prefix = null; String suffix = null; String colName = aPath; if (aPath == null) { return new PathInfo(null, null, null, null); } // ignore leading ( and trailing ) ie: sum(avg(col1)) int braceBegin = aPath.lastIndexOf("("); int braceEnd = aPath.indexOf(")"); int opPos = StringUtils.indexOfAny(aPath, "+-/*"); if (braceBegin >= 0 && braceEnd >= 0 && braceEnd > braceBegin) { int colBegin; int colEnd; String betweenBraces; betweenBraces = aPath.substring(braceBegin + 1, braceEnd).trim(); // look for ie 'distinct name' colBegin = betweenBraces.indexOf(" "); // look for multiarg function like to_char(col,'format_mask') colEnd = betweenBraces.indexOf(","); colEnd = colEnd > 0 ? colEnd : betweenBraces.length(); prefix = aPath.substring(0, braceBegin + 1) + betweenBraces.substring(0, colBegin + 1); colName = betweenBraces.substring(colBegin + 1, colEnd); suffix = betweenBraces.substring(colEnd) + aPath.substring(braceEnd); } else if (opPos >= 0) { colName = aPath.substring(0, opPos).trim(); suffix = aPath.substring(opPos); } return new PathInfo(aPath, prefix, colName.trim(), suffix); }
From source file:org.apache.torque.ColumnImpl.java
/** * Constructor which tries to guess schema, table and column names from * an SQL expression. If a schema name can be identified in the * SQL expression, it is removed from the SQL expression in the column. * * @param sqlExpression the SQL expression, not null, not blank. * * @throws NullPointerException if sqlExpression is null. * @throws IllegalArgumentException if table or column name cannot be * guessed from sqlExpression.//from w w w. java2s. co m */ public ColumnImpl(String sqlExpression) { setSqlExpression(sqlExpression); // Find Table.Column int dotIndex = sqlExpression.lastIndexOf(DOT); if (dotIndex == -1) { if (StringUtils.contains(sqlExpression, "*")) { return; } if (StringUtils.indexOfAny(sqlExpression, FUNCTION_DELIMITERS) != -1) { throw new IllegalArgumentException("sqlExpression " + sqlExpression + " is unparseable, it does not contain a dot (.) " + " but function delimiters."); } setColumnName(sqlExpression); return; } String pre = sqlExpression.substring(0, dotIndex); String post = sqlExpression.substring(dotIndex + 1, sqlExpression.length()); if (StringUtils.isBlank(pre)) { throw new IllegalArgumentException("sqlExpression " + sqlExpression + " is blank before the dot (.)"); } int startIndex = StringUtils.lastIndexOfAny(pre, FUNCTION_DELIMITERS); int endIndex = StringUtils.indexOfAny(post, FUNCTION_DELIMITERS); if (endIndex < 0) { endIndex = sqlExpression.length(); } else { // relative to sqlExpression not to post endIndex += dotIndex + 1; } if (startIndex + 1 == dotIndex) { throw new IllegalArgumentException( "sqlExpression " + sqlExpression + " is blank between the last function delimiter (" + StringUtils.join(FUNCTION_DELIMITERS) + ") and the dot"); } setColumnName(sqlExpression.substring(dotIndex + 1, endIndex)); // if startIndex == -1 the formula is correct String fullTableName = sqlExpression.substring(startIndex + 1, dotIndex); setTableName(fullTableName); if (fullTableName.contains(DOT)) { int fullTableNameDotIndex = fullTableName.lastIndexOf(DOT); String extractedSchemaName = fullTableName.substring(0, fullTableNameDotIndex); setSchemaName(extractedSchemaName); StringBuilder sqlExpressionBuilder = new StringBuilder(); if (startIndex != -1) { sqlExpressionBuilder.append(sqlExpression.substring(0, startIndex + 1)); } sqlExpressionBuilder.append(getTableName()).append(DOT).append(post); setSqlExpression(sqlExpressionBuilder.toString()); } }
From source file:org.apache.torque.util.SQLBuilder.java
/** * Removes a possible function name or clause from a column name * * @param name The column name, possibly containing a clause * * @return The column name/*from w ww . java 2s .c o m*/ * * @throws TorqueException If the column name was malformed */ private static String removeSQLFunction(final String name) throws TorqueException { // Empty name => return it if (StringUtils.isEmpty(name)) { return name; } // Find Table.Column int dotIndex = name.indexOf('.'); if (dotIndex == -1) { dotIndex = name.indexOf("*"); } if (dotIndex == -1) { throw new TorqueException("removeSQLFunction() : Column name " + name + " does not contain a . or a *"); } String pre = name.substring(0, dotIndex); String post = name.substring(dotIndex + 1, name.length()); int startIndex = StringUtils.lastIndexOfAny(pre, DELIMITERS); int endIndex = StringUtils.indexOfAny(post, DELIMITERS); if (startIndex < 0 && endIndex < 0) { return name; } else { if (endIndex < 0) { endIndex = post.length(); } // if startIndex == -1 the formula is correct return name.substring(startIndex + 1, dotIndex + 1 + endIndex); } }
From source file:org.eclipse.smarthome.binding.homematic.internal.type.HomematicTypeGeneratorImpl.java
/** * Returns true, if the given datapoint is a Thing status. *//*w w w. j a v a2s . com*/ public static boolean isStatusDatapoint(HmDatapoint dp) { return StringUtils.indexOfAny(dp.getName(), STATUS_DATAPOINT_NAMES) != -1; }
From source file:org.eclipse.smarthome.binding.homematic.internal.type.HomematicTypeGeneratorImpl.java
/** * Returns true, if the given datapoint can be ignored for metadata generation. *//*from ww w .ja va 2 s .co m*/ public static boolean isIgnoredDatapoint(HmDatapoint dp) { return StringUtils.indexOfAny(dp.getName(), IGNORE_DATAPOINT_NAMES) != -1; }
From source file:org.eclipse.wb.tests.designer.XML.AbstractXmlObjectTest.java
/** * "Decorates" given lines of XML. By default adds required namespace declarations, see * {@link #getTestSource_namespaces()}./*from w w w . j a v a 2s . c o m*/ */ protected final String[] getTestSource_decorate(String... lines) { // try to find line where name spaces should be inserted for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line.startsWith("<?xml")) { continue; } // prepare position for namespaces int index = StringUtils.indexOfAny(line, " />"); if (index > 0) { if (line.charAt(index - 1) == '-') { continue; } } // insert namespaces into line line = getXMLSource_insertNameSpaces_intoGivenLine(line, index); // modify copy lines = lines.clone(); lines[i] = line; // done break; } return lines; }
From source file:org.geoserver.security.iride.util.xml.transform.XmlTransformerUtils.java
/** * Returns {@code true} if the given string contains any one * of the escaped <code>XML</code> character entities, {@code false} otherwise. * * @param input the given string//from w w w .ja v a2 s. c o m * @return {@code true} if the given string contains any one * of the escaped <code>XML</code> character entities, {@code false} otherwise */ public static boolean hasEscapedXml(String input) { return StringUtils.indexOfAny(input, XML_ESCAPED_ENTITIES) > -1; }
From source file:org.jasig.portlet.courses.mvc.wrapper.CourseSectionMeetingWrapper.java
private Map<LocationWrapper, List<CourseMeeting>> setClassMeetingMap(CourseSection courseSection) { String displayName = ""; String roomNo = ""; String streetAddress = ""; List<CourseMeeting> courseMeetings = null; logger.debug("Setting ClassMeeting Map......"); Map<LocationWrapper, List<CourseMeeting>> locationMeetMap = new HashMap<LocationWrapper, List<CourseMeeting>>(); for (CourseMeeting courseMeetingObj : courseSection.getCourseMeetings()) { logger.debug("CourseMeeting Type........" + courseMeetingObj.getType()); if (courseMeetingObj.getType().toUpperCase().equals("CLASS")) { if (logger.isDebugEnabled()) { logger.debug("courseMeetingObj.getLocation().getDisplayName()........" + courseMeetingObj.getLocation().getDisplayName()); logger.debug("courseMeetingObj.getLocation().getStreetAddress()........" + courseMeetingObj.getLocation().getStreetAddress()); logger.debug("courseMeetingObj.getLocation().getRoom()........" + courseMeetingObj.getLocation().getRoom()); logger.debug("courseMeetingObj.getLocation().getIdentifier()........" + courseMeetingObj.getLocation().getIdentifier()); logger.debug("courseMeetingObj.getLocation().getLatitude()........" + courseMeetingObj.getLocation().getLatitude()); logger.debug("courseMeetingObj.getLocation().getLongitude()........" + courseMeetingObj.getLocation().getLongitude()); logger.debug("TermCode........" + getTermCode()); logger.debug("isMobile........" + isMobile()); }//from ww w . j ava2 s. c o m if ((!courseMeetingObj.getLocation().getDisplayName().equals(displayName)) || (!courseMeetingObj.getLocation().getStreetAddress().equals(streetAddress)) || (!courseMeetingObj.getLocation().getRoom().equals(roomNo))) { logger.debug("Class Location Not Matching......"); LocationWrapper locationWrapper = null; if (StringUtils.indexOfAny(courseMeetingObj.getLocation().getDisplayName(), meetingTypesWithNoLocation) == 0) { logger.debug("Location DisplayName is " + courseMeetingObj.getLocation().getDisplayName()); locationWrapper = new LocationWrapper(courseMeetingObj.getLocation().getDisplayName(), "", "", 0, 0, "", ""); } else { String locationUrl = ""; if (!isMobile()) { Map<String, String> params = new HashMap<String, String>(); params.put("pP_term", getTermCode()); params.put("pP_buildingName", courseMeetingObj.getLocation().getDisplayName()); locationUrl = this.getUrlService().getOtherPortletURL(getPortletPreferences(), ENROLLEDCLASSESGRADESFNAME_PREF, ENROLLEDCLASSESWINDOWSTATE_PREF, ENROLLEDCLASSESFIXEDPARAM_PREF, params); } else { locationUrl = this.getUrlService().getNativeMapUrl(getPortletPreferences(), ENROLLEDCLASSESNATIVEMAPBASESURL_PREF, courseMeetingObj.getLocation().getRoom(), courseMeetingObj.getLocation().getDisplayName(), courseMeetingObj.getLocation().getStreetAddress(), new Double(courseMeetingObj.getLocation().getLongitude()).toString(), new Double(courseMeetingObj.getLocation().getLatitude()).toString(), ENROLLEDCLASSESNATIVEMAPZOOMINDEX_PREF); } logger.debug("Location URL.....in CLASS" + locationUrl); locationWrapper = new LocationWrapper(courseMeetingObj.getLocation().getDisplayName(), courseMeetingObj.getLocation().getIdentifier(), courseMeetingObj.getLocation().getStreetAddress(), courseMeetingObj.getLocation().getLatitude(), courseMeetingObj.getLocation().getLongitude(), courseMeetingObj.getLocation().getRoom(), locationUrl); } courseMeetings = new ArrayList<CourseMeeting>(); locationMeetMap.put(locationWrapper, courseMeetings); displayName = courseMeetingObj.getLocation().getDisplayName(); streetAddress = courseMeetingObj.getLocation().getStreetAddress(); roomNo = courseMeetingObj.getLocation().getRoom(); courseMeetings.add(courseMeetingObj); logger.debug("Class Location Not Matching......Done"); } else { logger.debug("Class Location Matching......"); courseMeetings.add(courseMeetingObj); } } } if (locationMeetMap.isEmpty()) logger.debug("CLASS MAP IS EMPTY !!!!!"); return locationMeetMap; }
From source file:org.jasig.portlet.courses.mvc.wrapper.CourseSectionMeetingWrapper.java
private Map<LocationWrapper, List<CourseMeeting>> setExamMeetingMap(CourseSection courseSection) { String displayName = null;//from w w w . java2 s . co m String roomNo = null; String streetAddress = null; List<CourseMeeting> courseMeetings = null; courseMeetings = new ArrayList<CourseMeeting>(); logger.debug("Setting ExamMeeting Map......"); Map<LocationWrapper, List<CourseMeeting>> locationMeetMap = new HashMap<LocationWrapper, List<CourseMeeting>>(); for (CourseMeeting courseMeetingObj : courseSection.getCourseMeetings()) { logger.debug("CourseMeeting Type........" + courseMeetingObj.getType()); if (courseMeetingObj.getType().toUpperCase().equals("EXAM")) { logger.debug("courseMeetingObj.getLocation().getDisplayName()........" + courseMeetingObj.getLocation().getDisplayName()); logger.debug("courseMeetingObj.getLocation().getStreetAddress()........" + courseMeetingObj.getLocation().getStreetAddress()); logger.debug("courseMeetingObj.getLocation().getRoom()........" + courseMeetingObj.getLocation().getRoom()); logger.debug("courseMeetingObj.getLocation().getIdentifier()........" + courseMeetingObj.getLocation().getIdentifier()); logger.debug("courseMeetingObj.getLocation().getLatitude()........" + courseMeetingObj.getLocation().getLatitude()); logger.debug("courseMeetingObj.getLocation().getLongitude()........" + courseMeetingObj.getLocation().getLongitude()); logger.debug("isMobile........" + isMobile()); if ((courseMeetingObj.getLocation() != null) && (courseMeetingObj.getLocation().getStreetAddress() != null) && (courseMeetingObj.getLocation().getRoom() != null) && (!courseMeetingObj.getLocation().getDisplayName().equals(displayName)) && (!courseMeetingObj.getLocation().getStreetAddress().equals(streetAddress)) && (!courseMeetingObj.getLocation().getRoom().equals(roomNo))) { logger.debug("Exam Location Not Matching......"); LocationWrapper locationWrapper = null; if (StringUtils.indexOfAny(courseMeetingObj.getLocation().getDisplayName(), meetingTypesWithNoLocation) == 0) { logger.debug("Location DisplayName is " + courseMeetingObj.getLocation().getDisplayName()); locationWrapper = new LocationWrapper(courseMeetingObj.getLocation().getDisplayName(), "", "", 0, 0, "", ""); } else { String locationUrl = ""; locationUrl = this.getUrlService().getNativeMapUrl(getPortletPreferences(), ENROLLEDCLASSESNATIVEMAPBASESURL_PREF, courseMeetingObj.getLocation().getRoom(), courseMeetingObj.getLocation().getDisplayName(), courseMeetingObj.getLocation().getStreetAddress(), new Double(courseMeetingObj.getLocation().getLongitude()).toString(), new Double(courseMeetingObj.getLocation().getLatitude()).toString(), ENROLLEDCLASSESNATIVEMAPZOOMINDEX_PREF); logger.debug("Location URL.....in EXAM" + locationUrl); locationWrapper = new LocationWrapper(courseMeetingObj.getLocation().getDisplayName(), courseMeetingObj.getLocation().getIdentifier(), courseMeetingObj.getLocation().getStreetAddress(), courseMeetingObj.getLocation().getLatitude(), courseMeetingObj.getLocation().getLongitude(), courseMeetingObj.getLocation().getRoom(), locationUrl); } courseMeetings = new ArrayList<CourseMeeting>(); locationMeetMap.put(locationWrapper, courseMeetings); displayName = courseMeetingObj.getLocation().getDisplayName(); streetAddress = courseMeetingObj.getLocation().getStreetAddress(); roomNo = courseMeetingObj.getLocation().getRoom(); logger.debug("Exam Location Not Matching......Done"); courseMeetings.add(courseMeetingObj); } else { logger.debug("Exam Location Matching......"); courseMeetings.add(courseMeetingObj); } } } if (locationMeetMap.isEmpty()) logger.debug("EXAM MAP IS EMPTY !!!!!"); return locationMeetMap; }